X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2FFieldGuesser.java;h=970926ba14bcdf9d22ece3cbc6bac2d45846efdc;hb=92dad5df664287acb51728e9ea599f150765d34a;hp=eb40756b5ede82fbd2eae1ef1902d201e260063b;hpb=140e9d165f85c3d4f0435a311e091209313faa2a;p=GpsPrune.git diff --git a/tim/prune/load/FieldGuesser.java b/tim/prune/load/FieldGuesser.java index eb40756..970926b 100644 --- a/tim/prune/load/FieldGuesser.java +++ b/tim/prune/load/FieldGuesser.java @@ -4,7 +4,7 @@ import tim.prune.I18nManager; import tim.prune.data.Field; import tim.prune.data.Latitude; import tim.prune.data.Longitude; -import tim.prune.data.Timestamp; +import tim.prune.data.TimestampUtc; /** * Class to try to match data with field names, @@ -19,20 +19,42 @@ public abstract class FieldGuesser */ private static boolean isHeaderRow(String[] inValues) { - // Loop over values looking for a Latitude value + // Loop over values seeing if any are mostly numeric if (inValues != null) { - for (int v=0; v= '0' && currChar <= '9') {numNums++;} + } + // Return true if more than half the characters are numeric + return numNums > (numChars/2); + } + /** * Try to guess the fields for the given values from the file * @param inValues array of values from first non-blank line of file @@ -108,12 +130,24 @@ public abstract class FieldGuesser else if (!checkArrayHasField(fields, Field.LONGITUDE)) { fields[f] = Field.LONGITUDE; } - else { - customFieldNum++; - fields[f] = new Field(customPrefix + (customFieldNum)); + else + { + // Can we use the field name given? + Field customField = null; + if (isHeader && inValues[f] != null && inValues[f].length() > 0) { + customField = new Field(inValues[f]); + } + // Find an unused field number + while (customField == null || checkArrayHasField(fields, customField)) + { + customFieldNum++; + customField = new Field(customPrefix + (customFieldNum)); + } + fields[f] = customField; } } } + // Do a final check to make sure lat and long are in there if (!checkArrayHasField(fields, Field.LATITUDE)) { fields[0] = Field.LATITUDE; @@ -211,6 +245,7 @@ public abstract class FieldGuesser String upperValue = inValue.toUpperCase(); return (upperValue.equals("ALTITUDE") || upperValue.equals("ALT") + || upperValue.equals("HMSL") // height above mean sea level || upperValue.equals(I18nManager.getText("fieldname.altitude").toUpperCase())); } else @@ -282,7 +317,7 @@ public abstract class FieldGuesser { // must be at least 7 characters long if (inValue.length() < 7) {return false;} - Timestamp stamp = new Timestamp(inValue); + TimestampUtc stamp = new TimestampUtc(inValue); return stamp.isValid(); } }