Index: applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java
===================================================================
--- applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java	(revision 30185)
+++ applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java	(revision 30186)
@@ -19,7 +19,9 @@
 public class Js57toosm {
 	
+	public static int rnum = 0;
+
 	public static void main(String[] args) throws IOException {
 
-		FileInputStream in = new FileInputStream("/Users/mherring/boatsw/oseam/openseamap/renderer/js57toosm/tst.000");
+		FileInputStream in = new FileInputStream("/Users/mherring/boatsw/oseam/josm/plugins/smed2/js57toosm/tst.000");
 		PrintStream out = System.out;
 
@@ -36,5 +38,7 @@
 		double somf = 1;
 		long name = 0;
-		S57map map = new S57map();;
+		S57map.Nflag nflag = Nflag.ANON;
+		S57map map = new S57map();
+		double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180;
 
 		while (in.read(leader) == 24) {
@@ -55,5 +59,10 @@
 				if (!ddr) switch (tag) {
 				case "0001":
-					out.println("Record: " + (long)S57dat.getSubf(record, fields+pos, S57field.I8RI, S57subf.I8RN));
+					int i8rn = (int)(long)S57dat.getSubf(record, fields+pos, S57field.I8RI, S57subf.I8RN);
+					if (i8rn != ++rnum) {
+						out.println("Out of order record ID");
+						in.close();
+						System.exit(-1);
+					}
 					break;
 				case "DSID":
@@ -82,7 +91,22 @@
 					break;
 				case "VRID":
-					name = (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCNM) << 32;
+					name = (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCNM);
+					switch ((int)name) {
+					case 110:
+						nflag = Nflag.ISOL;
+						break;
+					case 120:
+						nflag = Nflag.CONN;
+						break;
+					default:
+						nflag = Nflag.ANON;
+						break;
+					}
+					name <<= 32;
 					name += (long)S57dat.getSubf(record, fields+pos, S57field.VRID, S57subf.RCID);
 					name <<= 16;
+					if (nflag == Nflag.ANON) {
+						map.newEdge(name);
+					}
 					break;
 				case "ATTV":
@@ -91,4 +115,10 @@
 					break;
 				case "VRPT":
+					name = (long)S57dat.getSubf(record, fields+pos, S57field.VRPT, S57subf.NAME) << 16;
+					int topi = (int)((long)S57dat.getSubf(S57subf.TOPI));
+					map.addConn(name, topi);
+					name = (long)S57dat.getSubf(S57subf.NAME) << 16;
+					topi = (int)((long)S57dat.getSubf(S57subf.TOPI));
+					map.addConn(name, topi);
 					break;
 				case "SGCC":
@@ -99,5 +129,13 @@
 						double lat = (double) ((long) S57dat.getSubf(S57subf.YCOO)) / comf;
 						double lon = (double) ((long) S57dat.getSubf(S57subf.XCOO)) / comf;
-						map.addNode(name++, lat, lon);
+						if (nflag == Nflag.ANON) {
+							map.newNode(++name, lat, lon, nflag);
+						} else {
+							map.newNode(name, lat, lon, nflag);
+						}
+						if (lat < minlat) minlat = lat;
+						if (lat > maxlat) maxlat = lat;
+						if (lon < minlon) minlon = lon;
+						if (lon > maxlon) maxlon = lon;
 					}
 					break;
@@ -108,5 +146,9 @@
 						double lon = (double) ((long) S57dat.getSubf(S57subf.XCOO)) / comf;
 						double depth = (double) ((long) S57dat.getSubf(S57subf.VE3D)) / somf;
-						map.addNode(name++, lat, lon, depth);
+						map.newNode(name++, lat, lon, depth);
+						if (lat < minlat) minlat = lat;
+						if (lat > maxlat) maxlat = lat;
+						if (lon < minlon) minlon = lon;
+						if (lon > maxlon) maxlon = lon;
 					}
 					break;
@@ -114,18 +156,34 @@
 			}
 		}
-		int a = 0; int i = 0; int c = 0; int d = 0;
-		for (Snode node : map.nodes.values()) {
-			switch (node.flg) {
-			case ANON: a++; break;
-			case ISOL: i++; break;
-			case CONN: c++; break;
-			case DPTH: d++; break;
+		in.close();
+		
+		out.println("<?xml version='1.0' encoding='UTF-8'?>");
+		out.println("<osm version='0.6' generator='js57toosm'>");
+		out.println("<bounds minlat='" + minlat +"' minlon='" + minlon + "' maxlat='" + maxlat + "' maxlon='" + maxlon + "'/>");
+		
+		for (long id : map.nodes.keySet()) {
+			Snode node = map.nodes.get(id);
+			if (node.flg == S57map.Nflag.DPTH) {
+				out.format("  <node id='%d' lat='%f' lon='%f' version='1'>%n", -id, Math.toDegrees(node.lat), Math.toDegrees(node.lon));
+				out.format("    <tag k='seamark:type' v='sounding'/>%n");
+				out.format("    <tag k='seamark:sounding:depth' v='%.1f'/>%n", ((Dnode)node).val);
+				out.format("  </node>%n");
+			} else {
+				out.format("  <node id='%d' lat='%f' lon='%f' version='1'/>%n",-id,  Math.toDegrees(node.lat), Math.toDegrees(node.lon));
 			}
 		}
-		out.println("Anon " + a);
-		out.println("Isol " + i);
-		out.println("Conn " + c);
-		out.println("Dpth " + d);
-		in.close();
+		
+		for (long id : map.edges.keySet()) {
+			Edge edge = map.edges.get(id);
+			out.format("  <way id='%d' version='1'>%n", -id);
+			out.format("    <nd ref='%d'/>%n", -edge.first);
+			for (long anon : edge.nodes) {
+				out.format("    <nd ref='%d'/>%n", -anon);
+			}
+			out.format("    <nd ref='%d'/>%n", -edge.last);
+			out.format("  </way>%n");
+		}
+		
+		out.println("</osm>\n");
 	}
 
Index: applications/editors/josm/plugins/smed2/src/render/Renderer.java
===================================================================
--- applications/editors/josm/plugins/smed2/src/render/Renderer.java	(revision 30185)
+++ applications/editors/josm/plugins/smed2/src/render/Renderer.java	(revision 30186)
@@ -198,10 +198,10 @@
 		switch (feature.flag) {
 		case LINE:
-			Edge edge = map.edges.get(feature.id);
+			Edge edge = map.edges.get(feature.refs);
 			area = map.new Area();
 			area.add(map.new Bound(map.new Side(edge, true), true));
 			break;
 		case AREA:
-			area = map.areas.get(feature.id);
+			area = map.areas.get(feature.refs);
 			break;
 		default:
@@ -288,5 +288,5 @@
 		switch (feature.flag) {
 		case LINE:
-			EdgeIterator eit = map.new EdgeIterator(map.edges.get(feature.id), true);
+			EdgeIterator eit = map.new EdgeIterator(map.edges.get(feature.refs), true);
 			point = context.getPoint(eit.next());
 			p.moveTo(point.getX(), point.getY());
@@ -297,5 +297,5 @@
 			break;
 		case AREA:
-			for (Bound bound : map.areas.get(feature.id)) {
+			for (Bound bound : map.areas.get(feature.refs)) {
 				BoundIterator bit = map.new BoundIterator(bound);
 				point = context.getPoint(bit.next());
@@ -373,5 +373,5 @@
 			break;
 		case AREA:
-			for (Bound bound : map.areas.get(feature.id)) {
+			for (Bound bound : map.areas.get(feature.refs)) {
 				BoundIterator bit = map.new BoundIterator(bound);
 				point = context.getPoint(bit.next());
@@ -506,10 +506,10 @@
 		switch (feature.flag) {
 		case LINE:
-			Edge edge = map.edges.get(feature.id);
+			Edge edge = map.edges.get(feature.refs);
 			area = map.new Area();
 			area.add(map.new Bound(map.new Side(edge, true), true));
 			break;
 		case AREA:
-			area = map.areas.get(feature.id);
+			area = map.areas.get(feature.refs);
 			break;
 		default:
Index: applications/editors/josm/plugins/smed2/src/s57/S57dat.java
===================================================================
--- applications/editors/josm/plugins/smed2/src/s57/S57dat.java	(revision 30185)
+++ applications/editors/josm/plugins/smed2/src/s57/S57dat.java	(revision 30186)
@@ -4,4 +4,6 @@
 import java.util.Arrays;
 import java.util.EnumMap;
+
+import js57toosm.Js57toosm;
 
 public class S57dat {
@@ -27,5 +29,5 @@
 	static {
 		convs.put(S57subf.I8RN, new S57conv(5,2,Dom.INT));
-		convs.put(S57subf.RCNM, new S57conv(2,1,Dom.AN)); convs.put(S57subf.RCID, new S57conv(10,4,Dom.INT)); convs.put(S57subf.EXPP, new S57conv(1,1,Dom.AN));
+		convs.put(S57subf.RCNM, new S57conv(2,1,Dom.AN)); convs.put(S57subf.RCID, new S57conv(10,32,Dom.INT)); convs.put(S57subf.EXPP, new S57conv(1,1,Dom.AN));
 		convs.put(S57subf.INTU, new S57conv(1,1,Dom.INT)); convs.put(S57subf.DSNM, new S57conv(0,0,Dom.BT)); convs.put(S57subf.EDTN, new S57conv(0,0,Dom.BT));
 		convs.put(S57subf.UPDN, new S57conv(0,0,Dom.BT)); convs.put(S57subf.UADT, new S57conv(8,0,Dom.DATE)); convs.put(S57subf.ISDT, new S57conv(8,0,Dom.DATE));
@@ -49,6 +51,6 @@
 		convs.put(S57subf.LFIL, new S57conv(0,0,Dom.BT)); convs.put(S57subf.VOLM, new S57conv(0,0,Dom.BT)); convs.put(S57subf.IMPL, new S57conv(3,0,Dom.AN));
 		convs.put(S57subf.SLAT, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.WLON, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.NLAT, new S57conv(0,0,Dom.REAL));
-		convs.put(S57subf.ELON, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.CRCS, new S57conv(0,0,Dom.HEX)); convs.put(S57subf.NAM1, new S57conv(12,5,Dom.AN));
-		convs.put(S57subf.NAM2, new S57conv(12,5,Dom.AN)); convs.put(S57subf.OORA, new S57conv(1,1,Dom.AN)); convs.put(S57subf.OAAC, new S57conv(6,0,Dom.BT));
+		convs.put(S57subf.ELON, new S57conv(0,0,Dom.REAL)); convs.put(S57subf.CRCS, new S57conv(0,0,Dom.HEX)); convs.put(S57subf.NAM1, new S57conv(12,40,Dom.AN));
+		convs.put(S57subf.NAM2, new S57conv(12,40,Dom.AN)); convs.put(S57subf.OORA, new S57conv(1,1,Dom.AN)); convs.put(S57subf.OAAC, new S57conv(6,0,Dom.BT));
 		convs.put(S57subf.OACO, new S57conv(5,2,Dom.INT)); convs.put(S57subf.OALL, new S57conv(0,0,Dom.BT)); convs.put(S57subf.OATY, new S57conv(1,1,Dom.AN));
 		convs.put(S57subf.DEFN, new S57conv(0,0,Dom.BT)); convs.put(S57subf.AUTH, new S57conv(2,2,Dom.AN)); convs.put(S57subf.RFTP, new S57conv(2,1,Dom.AN));
@@ -60,7 +62,7 @@
 		convs.put(S57subf.FIDN, new S57conv(10,4,Dom.INT)); convs.put(S57subf.FIDS, new S57conv(5,2,Dom.INT)); convs.put(S57subf.ATTL, new S57conv(5,2,Dom.INT));
 		convs.put(S57subf.ATVL, new S57conv(0,0,Dom.GT)); convs.put(S57subf.FFUI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.FFIX, new S57conv(0,2,Dom.INT));
-		convs.put(S57subf.NFPT, new S57conv(0,2,Dom.INT)); convs.put(S57subf.LNAM, new S57conv(17,8,Dom.AN)); convs.put(S57subf.RIND, new S57conv(0,1,Dom.AN));
+		convs.put(S57subf.NFPT, new S57conv(0,2,Dom.INT)); convs.put(S57subf.LNAM, new S57conv(17,64,Dom.AN)); convs.put(S57subf.RIND, new S57conv(0,1,Dom.AN));
 		convs.put(S57subf.FSUI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.FSIX, new S57conv(0,2,Dom.INT)); convs.put(S57subf.NSPT, new S57conv(0,2,Dom.INT));
-		convs.put(S57subf.NAME, new S57conv(12,5,Dom.AN)); convs.put(S57subf.ORNT, new S57conv(1,1,Dom.AN)); convs.put(S57subf.USAG, new S57conv(1,1,Dom.AN));
+		convs.put(S57subf.NAME, new S57conv(12,40,Dom.AN)); convs.put(S57subf.ORNT, new S57conv(1,1,Dom.AN)); convs.put(S57subf.USAG, new S57conv(1,1,Dom.AN));
 		convs.put(S57subf.MASK, new S57conv(1,1,Dom.AN)); convs.put(S57subf.VPUI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.VPIX, new S57conv(0,2,Dom.INT));
 		convs.put(S57subf.NVPT, new S57conv(0,2,Dom.INT)); convs.put(S57subf.TOPI, new S57conv(1,1,Dom.AN)); convs.put(S57subf.CCUI, new S57conv(1,1,Dom.AN));
@@ -166,36 +168,53 @@
 	public static Object getSubf(S57subf subf) {
 		ArrayList<S57subf> subs = fields.get(field);
-		if (index == subs.size())
-			index = 0;
-		while (index < subs.size()) {
+		boolean wrap = false;
+		while (true) {
+			if (index == subs.size()) {
+				if (!wrap) {
+					index = 0;
+					wrap = true;
+				} else {
+					System.out.println("ERROR: Subfield not found " + subf.name() + " in " + field.name() + " in record " + Js57toosm.rnum);
+					System.exit(-1);
+				}
+			}
 			S57subf sub = subs.get(index++);
 			S57conv conv = convs.get(sub);
 			if (sub == subf) {
 				if (conv.bin == 0) {
+					String str = "";
 					if (conv.asc == 0) {
-						String str = "";
 						while (buffer[offset] != 0x1f) {
 							str += buffer[offset++];
 						}
-						offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;
-						return str;
-					} else
-						return new String(buffer, offset, conv.asc);
+					} else {
+						str = new String(buffer, offset, conv.asc);
+						offset += conv.asc;
+					}
+					return str;
 				} else {
-					int i = Math.abs(conv.bin);
-					long val = buffer[offset + --i];
-					if (conv.bin > 0)
-						val &= 0xff;
-					while (i > 0) {
-						val = (val << 8) + (buffer[offset + --i] & 0xff);
+					int f = Math.abs(conv.bin);
+					if (f < 8) {
+						long val = buffer[offset + --f];
+						if (conv.bin > 0)
+							val &= 0xff;
+						while (f > 0) {
+							val = (val << 8) + (buffer[offset + --f] & 0xff);
+						}
+						offset += Math.abs(conv.bin);
+						return val;
+					} else {
+						f /= 8;
+						long val = 0;
+						for (int i = 0; i < f; i++) {
+							val = (val << 8) + (buffer[offset++] & 0xff);
+						}
+						return val;
 					}
-					offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;
-					return val;
 				}
 			} else {
-				offset += (conv.bin != 0) ? Math.abs(conv.bin) : conv.asc;
+				offset += (conv.bin != 0) ? ((conv.bin < 8) ? Math.abs(conv.bin) : conv.bin / 8) : conv.asc;
 			}
 		}
-		return null;
 	}
 
Index: applications/editors/josm/plugins/smed2/src/s57/S57map.java
===================================================================
--- applications/editors/josm/plugins/smed2/src/s57/S57map.java	(revision 30185)
+++ applications/editors/josm/plugins/smed2/src/s57/S57map.java	(revision 30186)
@@ -174,5 +174,5 @@
 	public class Feature {
 		public Fflag flag;
-		public long id;
+		public long refs;
 		public Obj type;
 		public AttMap atts;
@@ -184,5 +184,5 @@
 		Feature() {
 			flag = Fflag.UNKN;
-			id = 0;
+			refs = 0;
 			type = Obj.UNKOBJ;
 			atts = new AttMap();
@@ -304,20 +304,36 @@
 		nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon)));
 		feature = new Feature();
-		feature.id = id;
+		feature.refs = id;
 		feature.flag = Fflag.POINT;
 		edge = null;
 	}
 
-	public void addNode(long id, double lat, double lon, double depth) {
+	public void newNode(long id, double lat, double lon, Nflag flag) {
+		nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon), flag));
+		if (flag == Nflag.ANON) {
+			edge.nodes.add(id);
+		}
+	}
+
+	public void newNode(long id, double lat, double lon, double depth) {
 		nodes.put(id, new Dnode(Math.toRadians(lat), Math.toRadians(lon), depth));
-		feature = new Feature();
-		feature.id = id;
-		feature.flag = Fflag.POINT;
-		edge = null;
+	}
+
+	public void newEdge(long id) {
+		edge = new Edge();
+		edges.put(id, edge);
+	}
+
+	public void addConn(long id, int topi) {
+		if (topi == 1) {
+			edge.first = id;
+		} else {
+			edge.last = id;
+		}
 	}
 
 	public void addEdge(long id) {
 		feature = new Feature();
-		feature.id = id;
+		feature.refs = id;
 		feature.flag = Fflag.LINE;
 		edge = new Edge();
@@ -337,5 +353,5 @@
 	public void addArea(long id) {
 		feature = new Feature();
-		feature.id = id;
+		feature.refs = id;
 		feature.flag = Fflag.AREA;
 		outers = new ArrayList<Long>();
@@ -530,7 +546,7 @@
 		switch (feature.flag) {
 		case POINT:
-			return nodes.get(feature.id);
+			return nodes.get(feature.refs);
 		case LINE:
-			Edge edge = edges.get(feature.id);
+			Edge edge = edges.get(feature.refs);
 			EdgeIterator eit = new EdgeIterator(edge, true);
 			while (eit.hasNext()) {
@@ -567,5 +583,5 @@
 			return new Snode(llat + ((lat - llat) * harc / sarc), llon + ((lon - llon) * harc / sarc));
 		case AREA:
-			Bound bound = areas.get(feature.id).get(0);
+			Bound bound = areas.get(feature.refs).get(0);
 			BoundIterator bit = new BoundIterator(bound);
 			while (bit.hasNext()) {
