# HG changeset patch # User Sascha L. Teichmann # Date 1310049712 0 # Node ID cc8f770796cb05f7bde000441967fceab12978e5 # Parent 661a9304f2f5c81ee503713a64ebbf050b5175c7 PRFParser: Extract the year of sounding and description from file names. flys-backend/trunk@2302 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 661a9304f2f5 -r cc8f770796cb flys-backend/ChangeLog --- a/flys-backend/ChangeLog Thu Jul 07 14:09:54 2011 +0000 +++ b/flys-backend/ChangeLog Thu Jul 07 14:41:52 2011 +0000 @@ -1,3 +1,10 @@ +2011-07-07 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/importer/PRFParser.java: + Extract the year of sounding from file names. If not found + from the name of th containing directory. Description is made + of file name and parent directory file name. + 2011-07-07 Sascha L. Teichmann * src/main/java/de/intevation/flys/importer/PRFParser.java: diff -r 661a9304f2f5 -r cc8f770796cb flys-backend/src/main/java/de/intevation/flys/importer/PRFParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/PRFParser.java Thu Jul 07 14:09:54 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/PRFParser.java Thu Jul 07 14:41:52 2011 +0000 @@ -33,6 +33,12 @@ public static final Pattern KM_PATTERN = Pattern.compile("\\((\\d+)x\\s*,\\s*f(\\d+)\\.(\\d+)\\s*\\)?"); + public static final Pattern YEAR_PATTERN = + Pattern.compile("(\\d{4})"); + + public static final int MIN_YEAR = 1800; + public static final int MAX_YEAR = 2100; + public static final double X_EPSILON = 1e-4; public static final class XY @@ -188,16 +194,56 @@ protected Map> data; + protected Integer year; + + protected String description; + + public PRFParser() { data = new TreeMap>(); } + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map> getData() { + return data; + } + + public void setData(Map> data) { + this.data = data; + } + protected void sortLists() { for (List xy: data.values()) { Collections.sort(xy); } } + public static final Integer findYear(String s) { + Matcher m = YEAR_PATTERN.matcher(s); + while (m.find()) { + int year = Integer.parseInt(m.group(1)); + if (year >= MIN_YEAR && year <= MAX_YEAR) { + return Integer.valueOf(year); + } + } + return null; + } + public boolean parse(File file) { if (!(file.isFile() && file.canRead())) { @@ -207,6 +253,22 @@ log.info("parsing PRF file: '" + file + "'"); + description = file.getName(); + + year = findYear(file.getName()); + + if (year == null) { + File parent = file.getParentFile(); + if (parent != null) { + description = parent.getName() + "/" + description; + year = findYear(parent.getName()); + } + } + + if (year != null) { + log.info("year of sounding: " + year); + } + LineNumberReader in = null; try { @@ -338,6 +400,8 @@ public void reset() { data.clear(); + year = null; + description = null; } public static void parsePRFs(File root) {