X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fload%2FFieldGuesser.java;h=c76318d16bfb0be060e315a52a2a35a9eeade06e;hp=9b2bdc787a9c9a0833d7d5efd08380535b5dcc21;hb=7f5ed2be62905bd37717376dc22d09e5ea7edb4d;hpb=b361869e590bbca32664c16ac24d6296926594a5 diff --git a/tim/prune/load/FieldGuesser.java b/tim/prune/load/FieldGuesser.java index 9b2bdc7..c76318d 100644 --- a/tim/prune/load/FieldGuesser.java +++ b/tim/prune/load/FieldGuesser.java @@ -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;