Index: applications/editors/josm/plugins/seachart/src/s57/S57att.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57att.java	(revision 31722)
+++ applications/editors/josm/plugins/seachart/src/s57/S57att.java	(revision 31731)
@@ -86,14 +86,4 @@
   AttIENC.put(Att.LC_DR1, 18022); AttIENC.put(Att.LC_DR2, 18023); AttIENC.put(Att.LC_SP1, 18024); AttIENC.put(Att.LC_SP2, 18025); AttIENC.put(Att.LC_WD1, 18026);
   AttIENC.put(Att.LC_WD2, 18027); AttIENC.put(Att.SHPTYP, 33066); AttIENC.put(Att.UPDMSG, 40000); AttIENC.put(Att.BNKWTW, 17999);
- }
- 
- private static final HashMap<Integer, Att> S57Att = new HashMap<Integer, Att>();
- static {
-  for (Map.Entry<Att, Integer> entry : AttS57.entrySet()) {
-   S57Att.put(entry.getValue(), entry.getKey());
-  }
-  for (Map.Entry<Att, Integer> entry : AttIENC.entrySet()) {
-   S57Att.put(entry.getValue(), entry.getKey());
-  }
  }
  
@@ -354,7 +344,12 @@
  }
 
- public static Att decodeAttribute(long attribute) { // Convert S57 attribute code to SCM attribute enumeration
-  Att att = S57Att.get((int)attribute);
-  return (att != null) ? att : Att.UNKATT;
+ public static Att decodeAttribute(long attl) { // Convert S57 attribute code to SCM attribute enumeration
+		for (Att att : AttS57.keySet()) {
+			if (AttS57.get(att) == attl) return att;
+		}
+		for (Att att : AttIENC.keySet()) {
+			if (AttIENC.get(att) == attl) return att;
+		}
+  return Att.UNKATT;
  }
  
Index: applications/editors/josm/plugins/seachart/src/s57/S57dat.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57dat.java	(revision 31722)
+++ applications/editors/josm/plugins/seachart/src/s57/S57dat.java	(revision 31731)
@@ -54,6 +54,6 @@
 		convs.put(S57subf.LFIL, new S57conv(0,0)); convs.put(S57subf.VOLM, new S57conv(0,0)); convs.put(S57subf.IMPL, new S57conv(3,0));
 		convs.put(S57subf.SLAT, new S57conv(0,0)); convs.put(S57subf.WLON, new S57conv(0,0)); convs.put(S57subf.NLAT, new S57conv(0,0));
-		convs.put(S57subf.ELON, new S57conv(0,0)); convs.put(S57subf.CRCS, new S57conv(0,0)); convs.put(S57subf.NAM1, new S57conv(12,40));
-		convs.put(S57subf.NAM2, new S57conv(12,40)); convs.put(S57subf.OORA, new S57conv(1,1)); convs.put(S57subf.OAAC, new S57conv(6,0));
+		convs.put(S57subf.ELON, new S57conv(0,0)); convs.put(S57subf.CRCS, new S57conv(0,0)); convs.put(S57subf.NAM1, new S57conv(12,5));
+		convs.put(S57subf.NAM2, new S57conv(12,5)); convs.put(S57subf.OORA, new S57conv(1,1)); convs.put(S57subf.OAAC, new S57conv(6,0));
 		convs.put(S57subf.OACO, new S57conv(5,2)); convs.put(S57subf.OALL, new S57conv(0,0)); convs.put(S57subf.OATY, new S57conv(1,1));
 		convs.put(S57subf.DEFN, new S57conv(0,0)); convs.put(S57subf.AUTH, new S57conv(2,2)); convs.put(S57subf.RFTP, new S57conv(2,1));
@@ -65,7 +65,7 @@
 		convs.put(S57subf.FIDN, new S57conv(10,4)); convs.put(S57subf.FIDS, new S57conv(5,2)); convs.put(S57subf.ATTL, new S57conv(5,2));
 		convs.put(S57subf.ATVL, new S57conv(0,0)); convs.put(S57subf.FFUI, new S57conv(1,1)); convs.put(S57subf.FFIX, new S57conv(0,2));
-		convs.put(S57subf.NFPT, new S57conv(0,2)); convs.put(S57subf.LNAM, new S57conv(17,64)); convs.put(S57subf.RIND, new S57conv(0,1));
+		convs.put(S57subf.NFPT, new S57conv(0,2)); convs.put(S57subf.LNAM, new S57conv(17,8)); convs.put(S57subf.RIND, new S57conv(0,1));
 		convs.put(S57subf.FSUI, new S57conv(1,1)); convs.put(S57subf.FSIX, new S57conv(0,2)); convs.put(S57subf.NSPT, new S57conv(0,2));
-		convs.put(S57subf.NAME, new S57conv(12,40)); convs.put(S57subf.ORNT, new S57conv(1,1)); convs.put(S57subf.USAG, new S57conv(1,1));
+		convs.put(S57subf.NAME, new S57conv(12,5)); convs.put(S57subf.ORNT, new S57conv(1,1)); convs.put(S57subf.USAG, new S57conv(1,1));
 		convs.put(S57subf.MASK, new S57conv(1,1)); convs.put(S57subf.VPUI, new S57conv(1,1)); convs.put(S57subf.VPIX, new S57conv(0,2));
 		convs.put(S57subf.NVPT, new S57conv(0,2)); convs.put(S57subf.TOPI, new S57conv(1,1)); convs.put(S57subf.CCUI, new S57conv(1,1));
@@ -138,36 +138,4 @@
 		fields.put(S57field.ARCC, S57arcc); fields.put(S57field.AR2D, S57ar2d); fields.put(S57field.EL2D, S57el2d); fields.put(S57field.CT2D, S57ct2d); 
 	}
-
-	public enum S57record { DS, DP, DH, DA, CD, CR, ID, IO, IS, FE, VS, VI, VC, VE }
-	
-	private static ArrayList<S57field> S57ds = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSID, S57field.DSSI ));
-	private static ArrayList<S57field> S57dp = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSPM, S57field.DSPR, S57field.DSRC ));
-	private static ArrayList<S57field> S57dh = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSHT ));
-	private static ArrayList<S57field> S57da = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSAC ));
-	private static ArrayList<S57field> S57cd = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.CATD ));
-	private static ArrayList<S57field> S57cr = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.CATX ));
-	private static ArrayList<S57field> S57id = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDDF, S57field.DDDR ));
-	private static ArrayList<S57field> S57io = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDDI, null, S57field.DDOM, S57field.DDRF, null ));
-	private static ArrayList<S57field> S57is = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDSI, S57field.DDSC ));
-	private static ArrayList<S57field> S57fe = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.FRID, S57field.FOID, null, S57field.ATTF, null,
-			null, S57field.NATF, null, null, S57field.FFPT, null, null, S57field.FSPT, null ));
-	private static ArrayList<S57field> S57vs = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, null, S57field.SG3D, null));
-	private static ArrayList<S57field> S57vi = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, S57field.SG2D));
-	private static ArrayList<S57field> S57vc = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, S57field.SG2D));
-	private static ArrayList<S57field> S57ve = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, null, S57field.VRPT, null, null, S57field.SG3D, null));
-	
-	private static final EnumMap<S57record, ArrayList<S57field>> records = new EnumMap<S57record, ArrayList<S57field>>(S57record.class);
-	static {
-		records.put(S57record.DS, S57ds); records.put(S57record.DP, S57dp); records.put(S57record.DH, S57dh); records.put(S57record.DA, S57da); records.put(S57record.CD, S57cd);
-		records.put(S57record.CR, S57cr); records.put(S57record.ID, S57id); records.put(S57record.IO, S57io); records.put(S57record.IS, S57is); records.put(S57record.FE, S57fe);
-		records.put(S57record.VS, S57vs); records.put(S57record.VI, S57vi); records.put(S57record.VC, S57vc); records.put(S57record.VE, S57ve);
-	}
-	
-	private static final EnumMap<S57record, Integer> rcnms = new EnumMap<S57record, Integer>(S57record.class);
-	static {
-		rcnms.put(S57record.DS, 10); rcnms.put(S57record.DP, 20); rcnms.put(S57record.DH, 30); rcnms.put(S57record.DA, 40); rcnms.put(S57record.CD, 50);
-		rcnms.put(S57record.CR, 60); rcnms.put(S57record.ID, 70); rcnms.put(S57record.IO, 80); rcnms.put(S57record.IS, 90); rcnms.put(S57record.FE, 100);
-		rcnms.put(S57record.VS, 110); rcnms.put(S57record.VI, 110); rcnms.put(S57record.VC, 120); rcnms.put(S57record.VE, 130);
-	}
 	
 	private static byte[] leader = {'0', '0', '0', '0', '0', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '0', '0', ' ', ' ', ' ', '0', '0', '0', '4'};
@@ -293,5 +261,4 @@
 
 	public static byte[] encSubf(S57subf subf, Object val) {
-		if (val instanceof S57record) val = rcnms.get(val);
 		S57conv conv = convs.get(subf);
 		if (conv.bin == 0) {
@@ -332,17 +299,8 @@
 				lval = (long) val;
 			}
-			if (f < 8) {
-				buffer = new byte[f];
-				for (int i = 0; i < f; i++) {
-					buffer[i] = (byte) (lval & 0xff);
-					lval >>= 8;
-				}
-			} else {
-				f /= 8;
-				buffer = new byte[f];
-				for (int i = f-1; i >= 0; i--) {
-					buffer[i] = (byte) (lval & 0xff);
-					lval >>= 8;
-				}
+			buffer = new byte[f];
+			for (int i = 0; i < f; i++) {
+				buffer[i] = (byte) (lval & 0xff);
+				lval >>= 8;
 			}
 		}
@@ -361,27 +319,33 @@
 	}
 	
-	public static byte[] encRecord(Object...params) {
+	public static class Fparams {
+		public S57field field;
+		public Object[] params;
+		public Fparams(S57field f, Object[] p) {
+			field = f;
+			params = p;
+		}
+	};
+
+	public static byte[] encRecord(int i8rn, ArrayList<Fparams> fparams) {
 		ArrayList<Index> index = new ArrayList<Index>();
-		offset = 0;
-		int maxlen = 0;
-		ArrayList<S57field> record = records.get(params[1]);
-		byte[] buf = new byte[0];
-		int ip = 0;
-		for (S57field field : record) {
-			for (S57subf subf : fields.get(field)) {
-				byte[] next = encSubf(subf, params[ip++]);
-				buf = Arrays.copyOf(buf, (buf.length + next.length));
-				System.arraycopy(next, 0, buf, (buf.length - next.length), next.length);
-				if (ip >= params.length)
-					break;
+		int offset = 3;
+		int maxlen = 3;
+		byte[] buf = encSubf(S57subf.I8RN, i8rn);
+		buf = Arrays.copyOf(buf, 3);
+		buf[2] = 0x1e;
+		index.add(new Index("0001".getBytes(), 3, 0));
+		for (Fparams sfparams : fparams) {
+			for (int ip = 0; ip < sfparams.params.length; ) {
+				for (S57subf subf : fields.get(sfparams.field)) {
+					byte[] next = encSubf(subf, sfparams.params[ip++]);
+					buf = Arrays.copyOf(buf, (buf.length + next.length));
+					System.arraycopy(next, 0, buf, (buf.length - next.length), next.length);
+				}
 			}
 			buf = Arrays.copyOf(buf, (buf.length + 1));
 			buf[buf.length-1] = 0x1e;
 			int flen = buf.length - offset;
-			if (field == S57field.I8RI) {
-				index.add(new Index("0001".getBytes(), flen, offset));
-			} else {
-				index.add(new Index(field.toString().getBytes(), flen, offset));
-			}
+			index.add(new Index(sfparams.field.toString().getBytes(), flen, offset));
 			maxlen = (flen > maxlen) ? flen : maxlen;
 			offset += flen;
Index: applications/editors/josm/plugins/seachart/src/s57/S57enc.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57enc.java	(revision 31722)
+++ applications/editors/josm/plugins/seachart/src/s57/S57enc.java	(revision 31731)
@@ -11,154 +11,102 @@
 
 import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
-
+import java.util.Map.Entry;
+import java.util.zip.CRC32;
+
+import s57.S57obj.*;
+import s57.S57val.AttVal;
+import s57.S57att.Att;
 import s57.S57dat.*;
 import s57.S57map.*;
 
 public class S57enc { // S57 ENC file generation
-	
-	private static byte[] header = {
-		// Record 0
-		'0', '1', '9', '5', '9', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '2', '4', '5', ' ', '!', ' ', '3', '4', '0', '4', // Leader
-		'0', '0', '0', '0', '1', '6', '7', '0', '0', '0', '0',    '0', '0', '0', '1', '0', '4', '3', '0', '1', '6', '7', // Directory
-		'D', 'S', 'I', 'D', '1', '6', '5', '0', '2', '1', '0',    'D', 'S', 'S', 'I', '1', '1', '3', '0', '3', '7', '5',
-		'D', 'S', 'P', 'M', '1', '3', '0', '0', '4', '8', '8',    'F', 'R', 'I', 'D', '1', '0', '0', '0', '6', '1', '8',
-		'F', 'O', 'I', 'D', '0', '7', '0', '0', '7', '1', '8',    'A', 'T', 'T', 'F', '0', '5', '9', '0', '7', '8', '8',
-		'N', 'A', 'T', 'F', '0', '6', '8', '0', '8', '4', '7',    'F', 'F', 'P', 'C', '0', '9', '0', '0', '9', '1', '5',
-		'F', 'F', 'P', 'T', '0', '8', '6', '1', '0', '0', '5',    'F', 'S', 'P', 'C', '0', '9', '0', '1', '0', '9', '1',
-		'F', 'S', 'P', 'T', '0', '8', '9', '1', '1', '8', '1',    'V', 'R', 'I', 'D', '0', '7', '8', '1', '2', '7', '0',
-		'A', 'T', 'T', 'V', '0', '5', '8', '1', '3', '4', '8',    'V', 'R', 'P', 'C', '0', '7', '1', '1', '4', '0', '6',
-		'V', 'R', 'P', 'T', '0', '7', '6', '1', '4', '7', '7',    'S', 'G', 'C', 'C', '0', '6', '0', '1', '5', '5', '3',
-		'S', 'G', '2', 'D', '0', '4', '8', '1', '6', '1', '3',    'S', 'G', '3', 'D', '0', '5', '3', '1', '6', '6', '1', 0x1e,
-		 // File control field
-		'0', '0', '0', '0', ';', '&', ' ', ' ', ' ',
-		//*** 254
-		'0', 'S', '0', '0', '0', '0', '0', '0', '.', '0', '0', '0', 0x1f, // Filename
-		'0', '0', '0', '1', 'D', 'S', 'I', 'D',  'D', 'S', 'I', 'D', 'D', 'S', 'S', 'I',  '0', '0', '0', '1', 'D', 'S', 'P', 'M',
-		'0', '0', '0', '1', 'F', 'R', 'I', 'D',  'F', 'R', 'I', 'D', 'F', 'O', 'I', 'D',  'F', 'R', 'I', 'D', 'A', 'T', 'T', 'F',
-		'F', 'R', 'I', 'D', 'N', 'A', 'T', 'F',  'F', 'R', 'I', 'D', 'F', 'F', 'P', 'C',  'F', 'R', 'I', 'D', 'F', 'F', 'P', 'T',
-		'F', 'R', 'I', 'D', 'F', 'S', 'P', 'C',  'F', 'R', 'I', 'D', 'F', 'S', 'P', 'T',  '0', '0', '0', '1', 'V', 'R', 'I', 'D',
-		'V', 'R', 'I', 'D', 'A', 'T', 'T', 'V',  'V', 'R', 'I', 'D', 'V', 'R', 'P', 'C',  'V', 'R', 'I', 'D', 'V', 'R', 'P', 'T',
-		'V', 'R', 'I', 'D', 'S', 'G', 'C', 'C',  'V', 'R', 'I', 'D', 'S', 'G', '2', 'D',  'V', 'R', 'I', 'D', 'S', 'G', '3', 'D', 0x1e,
-		 // Record identifier fields
-		'0', '5', '0', '0', ';', '&', ' ', ' ', ' ', 'I', 'S', 'O', ' ', '8', '2', '1', '1', ' ', 'R', 'e', 'c', 'o', 'r', 'd',
-		' ', 'I', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 0x1f, 0x1f, '(', 'b', '1', '2', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'I', 'd', 'e', 'n', 't', 'i', 'f',
-		'i', 'c', 'a', 't', 'i', 'o', 'n', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'E',
-		'X', 'P', 'P', '!', 'I', 'N', 'T', 'U', '!', 'D', 'S', 'N', 'M', '!', 'E', 'D', 'T', 'N', '!', 'U', 'P', 'D', 'N', '!', 'U',
-		'A', 'D', 'T', '!', 'I', 'S', 'D', 'T', '!', 'S', 'T', 'E', 'D', '!', 'P', 'R', 'S', 'P', '!', 'P', 'S', 'D', 'N', '!', 'P',
-		'R', 'E', 'D', '!', 'P', 'R', 'O', 'F', '!', 'A', 'G', 'E', 'N', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'b', '1', '1', ',', 'b',
-		'1', '4', ',', '2', 'b', '1', '1', ',', '3', 'A', ',', '2', 'A', '(', '8', ')', ',', 'R', '(', '4', ')', ',', 'b', '1', '1',
+
+	private static final byte[] header = {
+		'0', '1', '5', '7', '6', '3', 'L', 'E', '1', ' ', '0', '9', '0', '0', '2', '0', '1', ' ', '!', ' ', '3', '4', '0', '4', // Leader
+		'0', '0', '0', '0', '1', '2', '3', '0', '0', '0', '0', '0', '0', '0', '1', '0', '4', '7', '0', '1', '2', '3',
+		'D', 'S', 'I', 'D', '1', '5', '9', '0', '1', '7', '0', 'D', 'S', 'S', 'I', '1', '1', '3', '0', '3', '2', '9',
+		'D', 'S', 'P', 'M', '1', '3', '0', '0', '4', '4', '2', 'F', 'R', 'I', 'D', '1', '0', '0', '0', '5', '7', '2',
+		'F', 'O', 'I', 'D', '0', '7', '0', '0', '6', '7', '2', 'A', 'T', 'T', 'F', '0', '5', '9', '0', '7', '4', '2',
+		'N', 'A', 'T', 'F', '0', '6', '8', '0', '8', '0', '1', 'F', 'F', 'P', 'T', '0', '8', '6', '0', '8', '6', '9',
+		'F', 'S', 'P', 'T', '0', '9', '0', '0', '9', '5', '5', 'V', 'R', 'I', 'D', '0', '7', '8', '1', '0', '4', '5',
+		'A', 'T', 'T', 'V', '0', '5', '8', '1', '1', '2', '3', 'V', 'R', 'P', 'T', '0', '7', '6', '1', '1', '8', '1',
+		'S', 'G', '2', 'D', '0', '4', '8', '1', '2', '5', '7', 'S', 'G', '3', 'D', '0', '7', '0', '1', '3', '0', '5', 0x1e,
+		// File control field
+		'0', '0', '0', '0', ';', '&', ' ', ' ', ' ', 0x1f,
+		'0', '0', '0', '1', 'D', 'S', 'I', 'D', 'D', 'S', 'I', 'D', 'D', 'S', 'S', 'I', '0', '0', '0', '1', 'D', 'S', 'P', 'M',
+		'0', '0', '0', '1', 'F', 'R', 'I', 'D', 'F', 'R', 'I', 'D', 'F', 'O', 'I', 'D', 'F', 'R', 'I', 'D', 'A', 'T', 'T', 'F',
+		'F', 'R', 'I', 'D', 'N', 'A', 'T', 'F', 'F', 'R', 'I', 'D', 'F', 'F', 'P', 'T', 'F', 'R', 'I', 'D', 'F', 'S', 'P', 'T',
+		'0', '0', '0', '1', 'V', 'R', 'I', 'D', 'V', 'R', 'I', 'D', 'A', 'T', 'T', 'V', 'V', 'R', 'I', 'D', 'V', 'R', 'P', 'T',
+		'V', 'R', 'I', 'D', 'S', 'G', '2', 'D', 'V', 'R', 'I', 'D', 'S', 'G', '3', 'D', 0x1e,
+		// Record identifier fields
+		'0', '5', '0', '0', ';', '&', ' ', ' ', ' ', 'I', 'S', 'O', '/', 'I', 'E', 'C', ' ', '8', '2', '1', '1', ' ',
+		'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 0x1f, 0x1f, '(', 'b', '1', '2', ')', 0x1e,
+		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'I', 'd', 'e', 'n', 't', 'i',
+		'f', 'i', 'c', 'a', 't', 'i', 'o', 'n', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'E', 'X', 'P', 'P', '!',
+		'I', 'N', 'T', 'U', '!', 'D', 'S', 'N', 'M', '!', 'E', 'D', 'T', 'N', '!', 'U', 'P', 'D', 'N', '!', 'U', 'A', 'D', 'T',
+		'!', 'I', 'S', 'D', 'T', '!', 'S', 'T', 'E', 'D', '!', 'P', 'R', 'S', 'P', '!', 'P', 'S', 'D', 'N', '!', 'P', 'R', 'E',
+		'D', '!', 'P', 'R', 'O', 'F', '!', 'A', 'G', 'E', 'N', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'b', '1', '1', ',', 'b', '1',
+		'4', ',', '2', 'b', '1', '1', ',', '3', 'A', ',', '2', 'A', '(', '8', ')', ',', 'R', '(', '4', ')', ',', 'b', '1', '1',
 		',', '2', 'A', ',', 'b', '1', '1', ',', 'b', '1', '2', ',', 'A', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'S', 't', 'r', 'u', 'c', 't', 'u',
-		'r', 'e', ' ', 'I', 'n', 'f', 'o', 'r', 'm', 'a', 't', 'i', 'o', 'n', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'D', 'S', 'T', 'R',
-		'!', 'A', 'A', 'L', 'L', '!', 'N', 'A', 'L', 'L', '!', 'N', 'O', 'M', 'R', '!', 'N', 'O', 'C', 'R', '!', 'N', 'O', 'G', 'R',
-		'!', 'N', 'O', 'L', 'R', '!', 'N', 'O', 'I', 'N', '!', 'N', 'O', 'C', 'N', '!', 'N', 'O', 'E', 'D', '!', 'N', 'O', 'F', 'A', 0x1f,
-		'(', '3', 'b', '1', '1', ',', '8', 'b', '1', '4', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 'S', 'e', 't', ' ', 'P', 'a', 'r', 'a', 'm', 'e', 't',
-		'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'H', 'D', 'A', 'T', '!', 'V',
-		'D', 'A', 'T', '!', 'S', 'D', 'A', 'T', '!', 'C', 'S', 'C', 'L', '!', 'D', 'U', 'N', 'I', '!', 'H', 'U', 'N', 'I', '!', 'P',
-		'U', 'N', 'I', '!', 'C', 'O', 'U', 'N', '!', 'C', 'O', 'M', 'F', '!', 'S', 'O', 'M', 'F', '!', 'C', 'O', 'M', 'T', 0x1f,
-		'(', 'b', '1', '1', ',', 'b', '1', '4', ',', '3', 'b', '1', '1', ',', 'b', '1', '4', ',', '4', 'b', '1', '1', ',', '2', 'b',
-		'1', '4', ',', 'A', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I',
-		'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D',
+		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 's', 'e', 't', ' ', 's', 't', 'r', 'u', 'c', 't',
+		'u', 'r', 'e', ' ', 'i', 'n', 'f', 'o', 'r', 'm', 'a', 't', 'i', 'o', 'n', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f,
+		'D', 'S', 'T', 'R', '!', 'A', 'A', 'L', 'L', '!', 'N', 'A', 'L', 'L', '!', 'N', 'O', 'M', 'R', '!', 'N', 'O', 'C', 'R',
+		'!', 'N', 'O', 'G', 'R', '!', 'N', 'O', 'L', 'R', '!', 'N', 'O', 'I', 'N', '!', 'N', 'O', 'C', 'N', '!', 'N', 'O', 'E',
+		'D', '!', 'N', 'O', 'F', 'A', 0x1f, '(', '3', 'b', '1', '1', ',', '8', 'b', '1', '4', ')', 0x1e,
+		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'D', 'a', 't', 'a', ' ', 's', 'e', 't', ' ', 'p', 'a', 'r', 'a', 'm', 'e',
+		't', 'e', 'r', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'H', 'D', 'A', 'T',
+		'!', 'V', 'D', 'A', 'T', '!', 'S', 'D', 'A', 'T', '!', 'C', 'S', 'C', 'L', '!', 'D', 'U', 'N', 'I', '!', 'H', 'U', 'N',
+		'I', '!', 'P', 'U', 'N', 'I', '!', 'C', 'O', 'U', 'N', '!', 'C', 'O', 'M', 'F', '!', 'S', 'O', 'M', 'F', '!', 'C', 'O',
+		'M', 'T', 0x1f, '(', 'b', '1', '1', ',', 'b', '1', '4', ',', '3', 'b', '1', '1', ',', 'b', '1', '4', ',', '4', 'b', '1',
+		'1', ',', '2', 'b', '1', '4', ',', 'A', ')', 0x1e,
+		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'i',
+		'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D',
 		'!', 'P', 'R', 'I', 'M', '!', 'G', 'R', 'U', 'P', '!', 'O', 'B', 'J', 'L', '!', 'R', 'V', 'E', 'R', '!', 'R', 'U', 'I', 'N', 0x1f,
 		'(', 'b', '1', '1', ',', 'b', '1', '4', ',', '2', 'b', '1', '1', ',', '2', 'b', '1', '2', ',', 'b', '1', '1', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'O', 'b', 'j', 'e', 'c', 't', ' ', 'I',
-		'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'A', 'G', 'E', 'N', '!', 'F', 'I', 'D', 'N',
+		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'o', 'b', 'j', 'e', 'c', 't', ' ', 'i',
+		'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, 'A', 'G', 'E', 'N', '!', 'F', 'I', 'D', 'N',
 		'!', 'F', 'I', 'D', 'S', 0x1f, '(', 'b', '1', '2', ',', 'b', '1', '4', ',', 'b', '1', '2', ')', 0x1e,
-		'2', '6', '0', '0', ';', '&', '-', 'A', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'A',
-		't', 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f,
+		'2', '6', '0', '0', ';', '&', '-', 'A', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'a',
+		't', 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f,
 		'(', 'b', '1', '2', ',', 'A', ')', 0x1e,
-		'2', '6', '0', '0', ';', '&', '-', 'A', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'N',
-		'a', 't', 'i', 'o', 'n', 'a', 'l', ' ', 'A', 't', 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f,
-		'*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f, '(', 'b', '1', '2', ',', 'A', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
-		'o', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'O', 'b', 'j', 'e', 'c', 't', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ',
-		'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'F', 'F', 'U', 'I', '!', 'F', 'F', 'I', 'X', '!', 'N',
-		'F', 'P', 'T', 0x1f, '(', 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
-		'2', '0', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
-		'o', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'O', 'b', 'j', 'e', 'c', 't', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ', 
-		'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'L', 'N', 'A', 'M', '!', 'R', 'I', 'N', 'D', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'B', '(',
-		'6', '4', ')', ',', 'b', '1', '1', ',', 'A', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ',	' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T',
-		'o', ' ', 'S', 'p', 'a', 't', 'i', 'a', 'l', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ',
-		'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'F', 'S', 'U', 'I', '!', 'F', 'S', 'I', 'X', '!', 'N',
-		'S', 'P', 'T', 0x1f, '(', 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
-		'2', '0', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'T', 
-		'o', ' ', 'S', 'p', 'a', 't', 'i', 'a', 'l', ' ', 'R', 'e', 'c', 'o', 'r', ' ', 'P', 'o', 'i', 'n', 't', 'e', 'r', ' ', 'F',
-		'i', 'e', 'l', 'd', 0x1f, '*', 'N', 'A', 'M', 'E', '!', 'O', 'R', 'N', 'T', '!', 'U', 'S', 'A', 'G', '!', 'M', 'A', 'S', 'K', 0x1f,
+		'2', '6', '0', '0', ';', '&', '-', 'A', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'n', 'a',
+		't', 'i', 'o', 'n', 'a', 'l', ' ', 'a', 't', 't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T',
+		'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f, '(', 'b', '1', '2', ',', 'A', ')', 0x1e,
+		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 't', 'o',
+		' ', 'f', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'o', 'b', 'j', 'e', 'c', 't', ' ', 'p', 'o', 'i', 'n', 't', 'e', 'r', ' ', 'f', 'i',
+		'e', 'l', 'd', 0x1f, '*', 'L', 'N', 'A', 'M', '!', 'R', 'I', 'N', 'D', '!', 'C', 'O', 'M', 'T', 0x1f, '(', 'B', '(', '6', '4',
+		')', ',', 'b', '1', '1', ',', 'A', ')', 0x1e,
+		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'F', 'e', 'a', 't', 'u', 'r', 'e', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 't', 'o',
+		' ', 's', 'p', 'a', 't', 'i', 'a', 'l', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'p', 'o', 'i', 'n', 't', 'e', 'r', ' ', 'f', 'i',
+		'e', 'l', 'd', 0x1f, '*', 'N', 'A', 'M', 'E', '!', 'O', 'R', 'N', 'T', '!', 'U', 'S', 'A', 'G', '!', 'M', 'A', 'S', 'K', 0x1f,
 		'(', 'B', '(', '4', '0', ')', ',', '3', 'b', '1', '1', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'I', 'd',
-		'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!',
-		'R', 'V', 'E', 'R', '!', 'R', 'U', 'I', 'N', 0x1f, '(', 'b', '1', '1', ',', 'b', '1', '4', ',', 'b', '1', '2', ',', 'b', '1',
-		'1', ')', 0x1e,
-		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'A', 't',
-		't', 'r', 'i', 'b', 'u', 't', 'e', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f,
-		'(', 'b', '1', '2', ',', 'A', ')', 0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'P', 'o',
-		'i', 'n', 't', 'e', 'r', ' ', 'C', 'o', 'n', 't', 'r', 'o', 'l', ' ', 'F', 'i', 'e', 'l', 's', 0x1f, 'V', 'P', 'U', 'I', '!',
-		'V', 'P', 'I', 'X', '!', 'N', 'V', 'P', 'T', 0x1f, '(', 'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
-		'2', '0', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'R', 'e', 'c', 'o', 'r', 'd', ' ', 'P', 'o',
-		'i', 'n', 't', 'e', 'r', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, '*', 'N', 'A', 'M', 'E', '!', 'O', 'R', 'N', 'T', '!', 'U', 'S',
-		'A', 'G', '!', 'T', 'O', 'P', 'I', '!', 'M', 'A', 'S', 'K', 0x1f, '(', 'B', '(', '4', '0', ')', ',', '4', 'b', '1', '1', ')',
-		0x1e,
-		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'C', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'C', 'o', 'n', 't', 'r',
-		'o', 'l', ' ', 'F', 'i', 'e', 'l', 'd', 0x1f, 'C', 'C', 'U', 'I', '!', 'C', 'C', 'I', 'X', '!', 'C', 'C', 'N', 'C', 0x1f, '(',
-		'b', '1', '1', ',', '2', 'b', '1', '2', ')', 0x1e,
-		'2', '2', '0', '0', ';', '&', ' ', ' ', ' ', '2', '-', 'D', ' ', 'C', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'F', 
-		'i', 'e', 'l', 'd', 0x1f, '*', 'Y', 'C', 'O', 'O', '!', 'X', 'C', 'O', 'O', 0x1f, '(', '2', 'b', '2', '4', ')',
-		0x1e,
-		'2', '2', '0', '0', ';', '&', ' ', ' ', ' ', '3', '-', 'D', ' ', 'C', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'F',
-		'i', 'e', 'l', 'd', 0x1f, '*', 'Y', 'C', 'O', 'O', '!', 'X', 'C', 'O', 'O', '!', 'V', 'E', '3', 'D', 0x1f, '(', '3', 'b', '2',
-		'4', ')', 0x1e,
-
-		// Record 1
-		'0', '0', '1', '6', '7', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '4', '9', ' ', ' ', ' ', '2', '2', '0', '4', // Leader
-		// Directory
-		'0', '0', '0', '1', '0', '3', '0', '0',   'D', 'S', 'I', 'D', '7', '9', '0', '3',   'D', 'S', 'S', 'I', '3', '6', '8', '2', 0x1e,
-		'1', '0', 0x1e, // Field 0001
-		// Field DSID
-		0x0a, 0x01, 0x00, 0x00, 0x00, 0x01,
-		//*** 2017
-		0x00, '0', 'S', '0', '0', '0', '0', '0', '0', '.', '0', '0', '0', 0x1f, // INTU & Filename
-		'1', 0x1f, '0', 0x1f,
-		//*** 2035
-		'0', '0', '0', '0', '0', '0', '0', '0',   '0', '0', '0', '0', '0', '0', '0', '0', // Date x2 (from system)
-		'0', '3', '.', '1', 0x14, 0x1f, 0x1f, 0x01, 0x26, 0x0f, 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', ' ', 'b', 'y', ' ', 
-		'O', 'p', 'e', 'n', 'S', 'e', 'a', 'M', 'a', 'p', '.', 'o', 'r', 'g', 0x1f, 0x1e,
-		// Field DSSI
-		0x02, 0x01, 0x02,
-		//*** 2093
-		0x00, 0x00, 0x00, 0x00, // # of meta records (from metas counter)
-		0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, // # of geo records (from geos counter)
-		0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, // # of isolated node records (from isols counter)
-		0x00, 0x00, 0x00, 0x00, // # of connected node records (from conns counter)
-		0x00, 0x00, 0x00, 0x00, // # of edge records (from edges counter)
-		0x00, 0x00, 0x00, 0x00, 0x1e,
-
-		// Record 2
-		'0', '0', '0', '6', '8', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '3', '9', ' ', ' ', ' ', '2', '1', '0', '4',
-		'0', '0', '0', '1', '0', '3', '0', 'D', 'S', 'P', 'M', '2', '6', '3', 0x1e,
-		// Field 0001
-		0x02, 0x00, 0x1e,
-		// Field DSPM
-		0x14, 0x01, 0x00, 0x00, 0x00, 0x02, 0x17, 0x17,
-		//*** 2176
-		0x00, 0x00, 0x00, 0x00, // Scale (from meta list)
-		0x01, // Depth units (from meta list)
-		0x01, // Height units (from meta list)
-		0x01, 0x01,
-		(byte)0x80, (byte)0x96, (byte)0x98, 0x00, // COMF=10000000
-		0x0a, // SOMF=10
-		0x00, 0x00, 0x00, 0x1f, 0x1e
+		'1', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'i', 'd', 'e',
+		'n', 't', 'i', 'f', 'i', 'e', 'r', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, 'R', 'C', 'N', 'M', '!', 'R', 'C', 'I', 'D', '!', 'R', 'V',
+		'E', 'R', '!', 'R', 'U', 'I', 'N', 0x1f, '(', 'b', '1', '1', ',', 'b', '1', '4', ',', 'b', '1', '2', ',', 'b', '1', '1', ')', 0x1e,
+		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'a', 't', 't',
+		'r', 'i', 'b', 'u', 't', 'e', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, '*', 'A', 'T', 'T', 'L', '!', 'A', 'T', 'V', 'L', 0x1f, '(', 'b',
+		'1', '2', ',', 'A', ')', 0x1e,
+		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', 'V', 'e', 'c', 't', 'o', 'r', ' ', 'r', 'e', 'c', 'o', 'r', 'd', ' ', 'p', 'o', 'i',
+		'n', 't', 'e', 'r', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, '*', 'N', 'A', 'M', 'E', '!', 'O', 'R', 'N', 'T', '!', 'U', 'S', 'A', 'G',
+		'!', 'T', 'O', 'P', 'I', '!', 'M', 'A', 'S', 'K', 0x1f, '(', 'B', '(', '4', '0', ')', ',', '4', 'b', '1', '1', ')', 0x1e,
+		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', '2', '-', 'D', ' ', 'c', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', 'f', 'i',
+		'e', 'l', 'd', 0x1f, '*', 'Y', 'C', 'O', 'O', '!', 'X', 'C', 'O', 'O', 0x1f, '(', '2', 'b', '2', '4', ')', 0x1e,
+		'2', '6', '0', '0', ';', '&', ' ', ' ', ' ', '3', '-', 'D', ' ', 'c', 'o', 'o', 'r', 'd', 'i', 'n', 'a', 't', 'e', ' ', '(', 's',
+		'o', 'u', 'n', 'd', 'i', 'n', 'g', ' ', 'a', 'r', 'r', 'a', 'y', ')', ' ', 'f', 'i', 'e', 'l', 'd', 0x1f, '*', 'Y', 'C', 'O', 'O',
+		'!', 'X', 'C', 'O', 'O', '!', 'V', 'E', '3', 'D', 0x1f, '(', '3', 'b', '2', '4', ')', 0x1e
 	};
 	
 	static final double COMF=10000000;
 	static final double SOMF=10;
+	
+	static int agen = 3878;
+	static int cscl = 10000;
 	
 	static int idx;
@@ -168,37 +116,199 @@
 	static int metas;
 	static int geos;
-	static int rcid;
+	static int edges;
+	
+	static long hash(long val) {
+		byte[] bval = ByteBuffer.allocate(Long.SIZE).putLong(val).array();
+		CRC32 crc = new CRC32();
+		crc.update(bval);
+		return crc.getValue();
+	}
 
 	public static int encodeChart(S57map map, HashMap<String, String> meta, byte[] buf) throws IndexOutOfBoundsException, UnsupportedEncodingException {
 
-		/*
-		 * Encoding order:
-		 * 1. Copy records 0-3 & fill in meta attributes.
-		 * 2. Depth isolated nodes.
-		 * 3. All other isolated nodes.
-		 * 4. Connected nodes.
-		 * 5. Edges.
-		 * 6. Meta objects.
-		 * 7. Geo objects.
-		 */
-		
-		recs = rcid = 3;
-		isols = conns = metas = geos = 0;
-		for (idx = 0; idx < header.length; idx++) {
-			buf[idx] = header[idx];
-		}
-//		byte[] file = S57dat.encSubf(S57subf.FILE, meta.get("FILE"));
-		
+		byte[] record;
+		ArrayList<Fparams> fields;
+
+		String date = new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime());
+		ArrayList<Fparams> ds = new ArrayList<Fparams>();
+		ds.add(new Fparams(S57field.DSID, new Object[]{ 10, 1, 1, 4, "0S000000.000", 1, 0, date, date, "03.1", 1, "ENC", "", 1, agen, "Generated by OpenSeaMap.org" }));
+		ds.add(new Fparams(S57field.DSSI, new Object[]{ 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 }));
+		ArrayList<Fparams> dp = new ArrayList<Fparams>();
+		dp.add(new Fparams(S57field.DSPM, new Object[]{ 20, 2, 2, 23, 23, cscl, 1, 1, 1, 1, 10000000, 10, "" }));
+		
+		isols = conns = metas = geos = edges = 0;
+		System.arraycopy(header, 0, buf, 0, header.length);
+		idx = header.length;
+		record = S57dat.encRecord(1, ds);
+		System.arraycopy(record, 0, buf, idx, record.length);
+		idx += record.length;
+		record = S57dat.encRecord(2, dp);
+		System.arraycopy(record, 0, buf, idx, record.length);
+		idx += record.length;
+		recs = 3;
+		
+		// Depths
+		Object[] depths = new Object[0];
+		for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) {
+			S57map.Snode node = entry.getValue();
+			if (node.flg == Nflag.DPTH) {
+				Object[] dval = new Object[]{ (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF), (node.val * SOMF) };
+				depths = Arrays.copyOf(depths, (depths.length + dval.length));
+				System.arraycopy(dval, 0, depths, (depths.length - dval.length), dval.length);
+			}
+		}
+		if (depths.length > 0) {
+			fields = new ArrayList<Fparams>();
+			fields.add(new Fparams(S57field.VRID, new Object[]{ 110, -2, 1, 1 }));
+			fields.add(new Fparams(S57field.SG3D, depths));
+			record = S57dat.encRecord(recs++, fields);
+			System.arraycopy(record, 0, buf, idx, record.length);
+			idx += record.length;
+			isols++;
+		}
+
+		// Isolated nodes
 		for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) {
 			S57map.Snode node = entry.getValue();
 			if (node.flg == Nflag.ISOL) {
-				byte[] record = S57dat.encRecord(recs++, S57record.VI, rcid++, 1, 1, (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF));
+				fields = new ArrayList<Fparams>();
+				fields.add(new Fparams(S57field.VRID, new Object[]{ 110, hash(entry.getKey()), 1, 1 }));
+				fields.add(new Fparams(S57field.SG2D, new Object[]{ (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF) }));
+				record = S57dat.encRecord(recs++, fields);
 				System.arraycopy(record, 0, buf, idx, record.length);
 				idx += record.length;
 				isols++;
-				recs++;
-			}
-		}
-
+			}
+		}
+		
+		// Connected nodes
+		for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) {
+			S57map.Snode node = entry.getValue();
+			if (node.flg == Nflag.CONN) {
+				fields = new ArrayList<Fparams>();
+				fields.add(new Fparams(S57field.VRID, new Object[]{ 120, hash(entry.getKey()), 1, 1 }));
+				fields.add(new Fparams(S57field.SG2D, new Object[]{ (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF) }));
+				record = S57dat.encRecord(recs++, fields);
+				System.arraycopy(record, 0, buf, idx, record.length);
+				idx += record.length;
+				conns++;
+			}
+		}
+		
+		// Edges
+		for (Map.Entry<Long, S57map.Edge> entry : map.edges.entrySet()) {
+			S57map.Edge edge = entry.getValue();
+			fields = new ArrayList<Fparams>();
+			fields.add(new Fparams(S57field.VRID, new Object[]{ 130, hash(entry.getKey()), 1, 1 }));
+			fields.add(new Fparams(S57field.VRPT, new Object[]{ (((hash(edge.first) & 0xffffffff) << 8) + 120l), 255, 255, 1, 255, (((hash(edge.last) & 0xffffffff) << 8) + 120l), 255, 255, 2, 255 }));
+			Object[] nodes = new Object[0];
+			for (long ref : edge.nodes) {
+				Object[] nval = new Object[]{ (Math.toDegrees(map.nodes.get(ref).lat) * COMF), (Math.toDegrees(map.nodes.get(ref).lon) * COMF) };
+				nodes = Arrays.copyOf(nodes, (nodes.length + nval.length));
+				System.arraycopy(nval, 0, nodes, (nodes.length - nval.length), nval.length);
+			}
+			if (nodes.length > 0) {
+				fields.add(new Fparams(S57field.SG2D, nodes));
+			}
+			record = S57dat.encRecord(recs++, fields);
+			System.arraycopy(record, 0, buf, idx, record.length);
+			idx += record.length;
+			edges++;
+		}
+		
+		// Meta & Geo objects
+		for (Entry<Obj, ArrayList<Feature>> entry : map.features.entrySet()) {
+			Obj obj = entry.getKey();
+			for (Feature feature : entry.getValue()) {
+				int prim = feature.geom.prim.ordinal();
+				prim = (prim == 0) ? 255 : prim;
+				int grup = ((obj == Obj.DEPARE) || (obj == Obj.DRGARE) || (obj == Obj.FLODOC) || (obj == Obj.HULKES) || (obj == Obj.LNDARE) || (obj == Obj.PONTON) || (obj == Obj.UNSARE)) ? 1 : 2;
+				
+				ArrayList<Fparams> geom = new ArrayList<Fparams>();
+				int outers = feature.geom.outers;
+				for (Prim elem : feature.geom.elems) {
+					if (feature.geom.prim == Pflag.POINT) {
+						geom.add(new Fparams(S57field.FSPT, new Object[] { ((hash(elem.id) << 8) + ((map.nodes.get(elem.id).flg == Nflag.CONN) ? 120l : 110l)), 255, 255, 255 }));
+					} else {
+						geom.add(new Fparams(S57field.FSPT, new Object[] { ((hash(elem.id) << 8) + 130l), (elem.forward ? 1 : 2), ((outers-- > 0) ? 1 : 2), 2 }));
+					}
+				}
+
+				ArrayList<ArrayList<Fparams>> objects = new ArrayList<ArrayList<Fparams>>();
+				ArrayList<Long> slaves = new ArrayList<Long>();
+				long slaveid = feature.id & 0x01ffffffffffffffl;
+				for (Entry<Obj, ObjTab> objs : feature.objs.entrySet()) {
+					Obj objobj = objs.getKey();
+					for (Entry<Integer, AttMap> object : objs.getValue().entrySet()) {
+						ArrayList<Fparams> objatts = new ArrayList<Fparams>();
+						boolean master = (feature.type == objobj) && ((object.getKey() == 0) || (object.getKey() == 1));
+						long id = hash(master ? feature.id : slaveid);
+						objatts.add(new Fparams(S57field.FRID, new Object[] { 100, id, prim, grup, S57obj.encodeType(objobj), 1, 1 }));
+						objatts.add(new Fparams(S57field.FOID, new Object[] { agen, id, 1 }));
+						Object[] attf = new Object[0];
+						Object[] natf = new Object[0];
+						for (Entry<Att, AttVal<?>> att : object.getValue().entrySet()) {
+							if (!((obj == Obj.SOUNDG) && (att.getKey() == Att.VALSOU))) {
+								long attl = S57att.encodeAttribute(att.getKey());
+								Object[] next = new Object[] { attl, S57val.encodeValue(att.getValue(), att.getKey()) };
+								if ((attl < 300) || (attl > 304)) {
+									attf = Arrays.copyOf(attf, (attf.length + next.length));
+									System.arraycopy(next, 0, attf, (attf.length - next.length), next.length);
+								} else {
+									natf = Arrays.copyOf(natf, (natf.length + next.length));
+									System.arraycopy(next, 0, natf, (natf.length - next.length), next.length);
+								}
+							}
+						}
+						if (attf.length > 0) {
+							objatts.add(new Fparams(S57field.ATTF, attf));
+						}
+						if (natf.length > 0) {
+							objatts.add(new Fparams(S57field.NATF, attf));
+						}
+						if (master) {
+							objects.add(objatts);
+						} else {
+							slaves.add(id);
+							objects.add(0, objatts);
+							slaveid += 0x0100000000000000l;
+						}
+					}
+				}
+
+				if (!slaves.isEmpty()) {
+					ArrayList<Fparams> refs = new ArrayList<Fparams>();
+					Object[] params = new Object[0];
+					while (!slaves.isEmpty()) {
+						long id = slaves.remove(0);
+						Object[] next = new Object[]{ (long)((((id & 0xffffffff) + 0x100000000l) << 16) + (agen & 0xffff)) , 2, "" };
+						params = Arrays.copyOf(params, (params.length + next.length));
+						System.arraycopy(next, 0, params, (params.length - next.length), next.length);
+					}
+					refs.add(new Fparams(S57field.FFPT, params));
+					objects.get(objects.size() - 1).addAll(refs);
+				}
+				
+				for (ArrayList<Fparams> object : objects) {
+					object.addAll(geom);
+					record = S57dat.encRecord(recs++, object);
+					System.arraycopy(record, 0, buf, idx, record.length);
+					idx += record.length;
+					if ((obj == Obj.M_COVR) || (obj == Obj.M_NSYS)) {
+						metas++;
+					} else {
+						geos++;
+					}
+				}
+			}
+		}
+		
+		// Re-write DSID/DSSI with final totals
+		ds = new ArrayList<Fparams>();
+		ds.add(new Fparams(S57field.DSID, new Object[]{ 10, 1, 1, 4, "0S000000.000", 1, 0, date, date, "03.1", 1, "ENC", "", 1, agen, "Generated by OpenSeaMap.org" }));
+		ds.add(new Fparams(S57field.DSSI, new Object[]{ 2, 1, 2, metas, 0, geos, 0, isols, conns, edges, 0 }));
+		record = S57dat.encRecord(1, ds);
+		System.arraycopy(record, 0, buf, header.length, record.length);
+		
 	return idx;
 }
Index: applications/editors/josm/plugins/seachart/src/s57/S57map.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57map.java	(revision 31722)
+++ applications/editors/josm/plugins/seachart/src/s57/S57map.java	(revision 31731)
@@ -47,4 +47,5 @@
 		public double lon;	// Longitude in radians
 		public Nflag flg;		// Role of node
+		public double val;	// Optional value
 
 		public Snode() {
@@ -52,4 +53,5 @@
 			lat = 0;
 			lon = 0;
+			val = 0;
 		}
 		public Snode(double ilat, double ilon) {
@@ -57,4 +59,5 @@
 			lat = ilat;
 			lon = ilon;
+			val = 0;
 		}
 		public Snode(double ilat, double ilon, Nflag iflg) {
@@ -62,17 +65,7 @@
 			lon = ilon;
 			flg = iflg;
-		}
-	}
-
-	public class Dnode extends Snode {	// All depth soundings
-		public double val;	// Sounding value
-
-		public Dnode() {
-			flg = Nflag.DPTH;
-			lat = 0;
-			lon = 0;
 			val = 0;
 		}
-		public Dnode(double ilat, double ilon, double ival) {
+		public Snode(double ilat, double ilon, double ival) {
 			flg = Nflag.DPTH;
 			lat = ilat;
@@ -81,5 +74,5 @@
 		}
 	}
-	
+
 	public class Edge {		// A polyline segment
 		public long first;	// First CONN node
@@ -207,4 +200,5 @@
 	
 	public class Feature {
+		public long id;				// Ref for this feature
 		public Rflag reln;		// Relationship status
 		public Geom geom;			// Geometry data
@@ -215,4 +209,5 @@
 
 		Feature() {
+			id = 0;
 			reln = Rflag.UNKN;
 			geom = new Geom(Pflag.NOSP);
@@ -261,5 +256,5 @@
 
 	public void newNode(long id, double lat, double lon, double depth) {
-		nodes.put(id, new Dnode(Math.toRadians(lat), Math.toRadians(lon), depth));
+		nodes.put(id, new Snode(Math.toRadians(lat), Math.toRadians(lon), depth));
 	}
 
@@ -271,10 +266,9 @@
 		if (obj == Obj.BOYWTW)
 			obj = Obj.BOYLAT;
-		if (obj == Obj.C_AGGR)
-			feature.reln = Rflag.UNKN;
 		feature.geom = new Geom(p);
 		feature.type = obj;
 		if (obj != Obj.UNKOBJ) {
 			index.put(id, feature);
+			feature.id = id;
 		}
 	}
@@ -378,4 +372,5 @@
 		nodes.put(id, node);
 		feature = new Feature();
+		feature.id = id;
 		feature.reln = Rflag.UNKN;
 		feature.geom.prim = Pflag.POINT;
@@ -387,4 +382,5 @@
 	public void addEdge(long id) {
 		feature = new Feature();
+		feature.id = id;
 		feature.reln = Rflag.UNKN;
 		feature.geom.prim = Pflag.LINE;
@@ -408,4 +404,5 @@
 	public void addArea(long id) {
 		feature = new Feature();
+		feature.id = id;
 		feature.reln = Rflag.UNKN;
 		feature.geom.prim = Pflag.AREA;
@@ -445,6 +442,11 @@
 				}
 				AttVal<?> attval = S57val.convertValue(val, att);
-				if (attval.val != null)
+				if (attval.val != null) {
+					if (att == Att.VALSOU) {
+						Snode node = nodes.get(feature.geom.elems.get(0).id);
+						node.val = (double) attval.val;
+					}
 					atts.put(att, attval);
+				}
 			} else {
 				if (subkeys[1].equals("type")) {
@@ -461,4 +463,8 @@
 						objs.put(0, atts);
 					}
+					if ((obj == Obj.SOUNDG) && (feature.geom.prim == Pflag.POINT)) {
+						Snode node = nodes.get(feature.geom.elems.get(0).id);
+						node.flg = Nflag.DPTH;
+					}
 				} else {
 					Att att = S57att.enumAttribute(subkeys[1], Obj.UNKOBJ);
@@ -485,5 +491,5 @@
 		case POINT:
 			Snode node = nodes.get(id);
-			if (node.flg != Nflag.CONN) {
+			if ((node.flg != Nflag.CONN) && (node.flg != Nflag.DPTH) && (!feature.objs.isEmpty())) {
 				node.flg = Nflag.ISOL;
 			}
Index: applications/editors/josm/plugins/seachart/src/s57/S57obj.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57obj.java	(revision 31722)
+++ applications/editors/josm/plugins/seachart/src/s57/S57obj.java	(revision 31731)
@@ -15,16 +15,16 @@
 	
 	public enum Obj {
-		UNKOBJ, AIRARE, ACHBRT, ACHARE, BCNCAR, BCNISD, BCNLAT, BCNSAW, BCNSPP, BERTHS, BRIDGE, BUISGL, BUAARE, BOYCAR, BOYINB, BOYISD,
-		BOYLAT, BOYSAW, BOYSPP, CBLARE, CBLOHD, CBLSUB, CANALS, CTSARE, CAUSWY, CTNARE, CHKPNT, CGUSTA, COALNE, CONZNE, COSARE, CTRPNT,
-		CONVYR, CRANES, CURENT, CUSZNE, DAMCON, DAYMAR, DWRTCL, DWRTPT, DEPARE, DEPCNT, DISMAR, DOCARE, DRGARE, DRYDOC, DMPGRD, DYKCON,
-		EXEZNE, FAIRWY, FNCLNE, FERYRT, FSHZNE, FSHFAC, FSHGRD, FLODOC, FOGSIG, FORSTC, FRPARE, GATCON, GRIDRN, HRBARE, HRBFAC, HULKES,
-		ICEARE, ICNARE, ISTZNE, LAKARE, LNDARE, LNDELV, LNDRGN, LNDMRK, LIGHTS, LITFLT, LITVES, LOCMAG, LOKBSN, LOGPON, MAGVAR, MARCUL,
-		MIPARE, MORFAC, MPAARE, NAVLNE, OBSTRN, OFSPLF, OSPARE, OILBAR, PILPNT, PILBOP, PIPARE, PIPOHD, PIPSOL, PONTON, PRCARE, PRDARE,
-		PYLONS, RADLNE, RADRNG, RADRFL, RADSTA, RTPBCN, RDOCAL, RDOSTA, RAILWY, RAPIDS, RCRTCL, RECTRC, RCTLPT, RSCSTA, RESARE, RETRFL,
-		RIVERS, ROADWY, RUNWAY, SNDWAV, SEAARE, SPLARE, SBDARE, SLCONS, SISTAT, SISTAW, SILTNK, SLOTOP, SLOGRD, SMCFAC, SOUNDG, SPRING,
-		STSLNE, SUBTLN, SWPARE, TESARE, TS_PRH, TS_PNH, TS_PAD, TS_TIS, T_HMON, T_NHMN, T_TIMS, TIDEWY, TOPMAR, TSELNE, TSSBND, TSSCRS,
-		TSSLPT, TSSRON, TSEZNE, TUNNEL, TWRTPT, UWTROC, UNSARE, VEGATN, WATTUR, WATFAL, WEDKLP, WRECKS, TS_FEB, NOTMRK, WTWAXS, WTWPRF,
-		BRGARE, BUNSTA, COMARE, HRBBSN, LOKARE, LKBSPT, PRTARE, BCNWTW, BOYWTW, REFDMP, RTPLPT, TERMNL, TRNBSN, WTWARE, WTWGAG, TISDGE,
-		VEHTRF, EXCNST, LG_SDM, LG_VSP, LITMIN, LITMAJ, C_AGGR, M_COVR, M_NSYS
+		UNKOBJ, M_COVR, M_NSYS, AIRARE, ACHBRT, ACHARE, BCNCAR, BCNISD, BCNLAT, BCNSAW, BCNSPP, BERTHS, BRIDGE, BUISGL, BUAARE, BOYCAR,
+		BOYINB, BOYISD, BOYLAT, BOYSAW, BOYSPP, CBLARE, CBLOHD, CBLSUB, CANALS, CTSARE, CAUSWY, CTNARE, CHKPNT, CGUSTA, COALNE, CONZNE,
+		COSARE, CTRPNT, CONVYR, CRANES, CURENT, CUSZNE, DAMCON, DAYMAR, DWRTCL, DWRTPT, DEPARE, DEPCNT, DISMAR, DOCARE, DRGARE, DRYDOC,
+		DMPGRD, DYKCON, EXEZNE, FAIRWY, FNCLNE, FERYRT, FSHZNE, FSHFAC, FSHGRD, FLODOC, FOGSIG, FORSTC, FRPARE, GATCON, GRIDRN, HRBARE,
+		HRBFAC, HULKES, ICEARE, ICNARE, ISTZNE, LAKARE, LNDARE, LNDELV, LNDRGN, LNDMRK, LIGHTS, LITFLT, LITVES, LOCMAG, LOKBSN, LOGPON,
+		MAGVAR, MARCUL, MIPARE, MORFAC, MPAARE, NAVLNE, OBSTRN, OFSPLF, OSPARE, OILBAR, PILPNT, PILBOP, PIPARE, PIPOHD, PIPSOL, PONTON,
+		PRCARE, PRDARE, PYLONS, RADLNE, RADRNG, RADRFL, RADSTA, RTPBCN, RDOCAL, RDOSTA, RAILWY, RAPIDS, RCRTCL, RECTRC, RCTLPT, RSCSTA,
+		RESARE, RETRFL, RIVERS, ROADWY, RUNWAY, SNDWAV, SEAARE, SPLARE, SBDARE, SLCONS, SISTAT, SISTAW, SILTNK, SLOTOP, SLOGRD, SMCFAC,
+		SOUNDG, SPRING, STSLNE, SUBTLN, SWPARE, TESARE, TS_PRH, TS_PNH, TS_PAD, TS_TIS, T_HMON, T_NHMN, T_TIMS, TIDEWY, TOPMAR, TSELNE,
+		TSSBND, TSSCRS, TSSLPT, TSSRON, TSEZNE, TUNNEL, TWRTPT, UWTROC, UNSARE, VEGATN, WATTUR, WATFAL, WEDKLP, WRECKS, TS_FEB, NOTMRK,
+		WTWAXS, WTWPRF, BRGARE, BUNSTA, COMARE, HRBBSN, LOKARE, LKBSPT, PRTARE, BCNWTW, BOYWTW, REFDMP, RTPLPT, TERMNL, TRNBSN, WTWARE,
+		WTWGAG, TISDGE, VEHTRF, EXCNST, LG_SDM, LG_VSP, LITMIN, LITMAJ
 	}
 
@@ -63,5 +63,5 @@
 		ObjS57.put(Obj.TUNNEL,151);	ObjS57.put(Obj.TWRTPT,152);	ObjS57.put(Obj.UWTROC,153);	ObjS57.put(Obj.UNSARE,154); ObjS57.put(Obj.VEGATN,155);
 		ObjS57.put(Obj.WATTUR,156);	ObjS57.put(Obj.WATFAL,157);	ObjS57.put(Obj.WEDKLP,158);	ObjS57.put(Obj.WRECKS,159); ObjS57.put(Obj.TS_FEB,160);
-		ObjS57.put(Obj.MPAARE,199); ObjS57.put(Obj.C_AGGR,400); ObjS57.put(Obj.M_COVR,302); ObjS57.put(Obj.M_NSYS,306);
+		ObjS57.put(Obj.MPAARE,199); ObjS57.put(Obj.M_COVR,302); ObjS57.put(Obj.M_NSYS,306); ObjS57.put(Obj.LITMAJ,74); ObjS57.put(Obj.LITMIN,90);
 	}
 
@@ -82,14 +82,4 @@
 	}
 
-	private static final HashMap<Integer, Obj> S57Obj = new HashMap<Integer, Obj>();
-	static {
-		for (Map.Entry<Obj, Integer> entry : ObjS57.entrySet()) {
-			S57Obj.put(entry.getValue(), entry.getKey());
-		}
-		for (Map.Entry<Obj, Integer> entry : ObjIENC.entrySet()) {
-			S57Obj.put(entry.getValue(), entry.getKey());
-		}
-	}
-	
 	private static final EnumMap<Obj, String> ObjStr = new EnumMap<Obj, String>(Obj.class);
 	static {
@@ -139,5 +129,5 @@
 		ObjStr.put(Obj.TRNBSN, "turning_basin"); ObjStr.put(Obj.WTWARE, "waterway_area"); ObjStr.put(Obj.WTWGAG, "waterway_gauge"); ObjStr.put(Obj.TISDGE, "time_schedule");
 		ObjStr.put(Obj.VEHTRF, "vehicle_transfer"); ObjStr.put(Obj.EXCNST, "exceptional_structure"); ObjStr.put(Obj.MPAARE, "protected_area");
-		ObjStr.put(Obj.LITMAJ, "light_major"); ObjStr.put(Obj.LITMIN, "light_minor"); ObjStr.put(Obj.M_COVR, "coverage"); ObjStr.put(Obj.M_NSYS, "navigational_system");
+		ObjStr.put(Obj.LITMAJ, "light_major"); ObjStr.put(Obj.LITMIN, "light_minor"); ObjStr.put(Obj.M_COVR, "coverage"); ObjStr.put(Obj.M_NSYS, "system");
 	}
 	
@@ -151,6 +141,11 @@
 	
 	public static Obj decodeType(long objl) { // Convert S57 feature code to SCM object enumeration
-		Obj obj = S57Obj.get((int)objl);
-		return (obj != null) ? obj : Obj.UNKOBJ;
+		for (Obj obj : ObjS57.keySet()) {
+			if (ObjS57.get(obj) == objl) return obj;
+		}
+		for (Obj obj : ObjIENC.keySet()) {
+			if (ObjIENC.get(obj) == objl) return obj;
+		}
+		return Obj.UNKOBJ;
 	}
 
Index: applications/editors/josm/plugins/seachart/src/s57/S57val.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57val.java	(revision 31722)
+++ applications/editors/josm/plugins/seachart/src/s57/S57val.java	(revision 31731)
@@ -1150,14 +1150,25 @@
  }
 
- public static Integer encodeValue(String val, Att att) { // Convert OSM attribute value string to S57 attribute value
-  EnumMap<?, ?> map = keys.get(att).map;
-  for (Object item : map.keySet()) {
-   if (((S57enum)map.get(item)).val.equals(val))
-    return ((S57enum)map.get(item)).atvl;
-  }
-  return 0;
- }
-
- public static String stringValue(AttVal<?> attval, Att att) { // Convert SCM value object to OSM attribute value string
+ public static String encodeValue(AttVal<?> attval, Att att) { // Convert SCM attribute value to S57 attribute value string
+	  if (attval != null) {
+	  	String str = stringValue(attval, att);
+	  	if ((attval.conv == Conv.E) || (attval.conv == Conv.L)) {
+	  		String[] vals = str.split(";");
+	  		str = "";
+	  		for (String val : vals) {
+	  			if (!str.isEmpty()) str += ",";
+	  			EnumMap<?, ?> map = keys.get(att).map;
+	  			for (Object item : map.keySet()) {
+	  				if (((S57enum)map.get(item)).val.equals(val))
+		        str += ((S57enum)map.get(item)).atvl.toString();
+		      }
+	  		}
+	  	}
+  		return str;
+	  }
+  return "";
+ }
+
+ public static String stringValue(AttVal<?> attval, Att att) { // Convert SCM attribute value to OSM attribute value string
   if (attval != null) {
    switch (attval.conv) {
