Skip to content

Commit 56a7052

Browse files
committed
intermediate pre-processing
1 parent 57f1f2b commit 56a7052

File tree

13 files changed

+226
-9
lines changed

13 files changed

+226
-9
lines changed

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/preproc/AirtProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void open(File airtFile) {
2424
}
2525

2626
final AIRTRecord airtRecord = new AIRTRecord();
27-
final String[] tokens = StringUtils.split(line, new char[]{' '}, true);
27+
final String[] tokens = TaoPreProcessor.tokenize(line);
2828
airtRecord.date = TaoPreProcessor.toUnixEpoch(tokens[0], tokens[1]);
2929
airtRecord.AIRT = tokens[2];
3030
airtRecord.Q = tokens[3];
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.bc.fiduceo.reader.insitu.tao.preproc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.util.HashMap;
8+
9+
class BAROProvider {
10+
11+
private HashMap<Integer, BARORecord> baroMap;
12+
13+
void open(File baroFile) {
14+
baroMap = new HashMap<>();
15+
16+
try (final FileReader fileReader = new FileReader(baroFile)) {
17+
final BufferedReader bufferedReader = new BufferedReader(fileReader);
18+
String line;
19+
while ((line = bufferedReader.readLine()) != null) {
20+
if (!Character.isDigit(line.charAt(0))) {
21+
continue;
22+
}
23+
24+
final BARORecord baroRecord = new BARORecord();
25+
final String[] tokens = TaoPreProcessor.tokenize(line);
26+
baroRecord.date = TaoPreProcessor.toUnixEpoch(tokens[0], tokens[1]);
27+
baroRecord.BARO = tokens[2];
28+
baroRecord.Q = tokens[3];
29+
baroRecord.M = tokens[4];
30+
31+
baroMap.put(baroRecord.date, baroRecord);
32+
}
33+
} catch (IOException e) {
34+
throw new RuntimeException(e);
35+
}
36+
}
37+
38+
BARORecord get(int date) {
39+
BARORecord baroRecord = baroMap.get(date);
40+
if (baroRecord == null) {
41+
baroRecord = new BARORecord();
42+
baroRecord.date = date;
43+
baroRecord.BARO = "-9.9";
44+
baroRecord.Q = "9";
45+
baroRecord.M = "D";
46+
}
47+
48+
return baroRecord;
49+
}
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.bc.fiduceo.reader.insitu.tao.preproc;
2+
3+
class BARORecord {
4+
5+
int date;
6+
String BARO;
7+
String Q;
8+
String M;
9+
}

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/preproc/Configuration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ class Configuration {
88
String sstFileName;
99
String airtFileName;
1010
String rhFileName;
11+
String windFileName;
12+
String baroFileName;
1113
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.bc.fiduceo.reader.insitu.tao.preproc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.util.ArrayList;
8+
import java.util.Comparator;
9+
10+
class POSProvider {
11+
12+
private POSRecord[] posArray;
13+
14+
void open(File posFile) {
15+
final ArrayList<POSRecord> posRecords = new ArrayList<>();
16+
17+
try (final FileReader fileReader = new FileReader(posFile)) {
18+
final BufferedReader bufferedReader = new BufferedReader(fileReader);
19+
String line;
20+
while ((line = bufferedReader.readLine()) != null) {
21+
if (!Character.isDigit(line.charAt(0))) {
22+
continue;
23+
}
24+
25+
final POSRecord posRecord = new POSRecord();
26+
final String[] tokens = TaoPreProcessor.tokenize(line);
27+
posRecord.date = TaoPreProcessor.toUnixEpoch(tokens[0], tokens[1]);
28+
posRecord.lon = Float.parseFloat(tokens[2]);
29+
posRecord.lat = Float.parseFloat(tokens[3]);
30+
31+
posRecords.add(posRecord);
32+
}
33+
34+
posRecords.sort(Comparator.comparing(POSRecord::getDate));
35+
posArray = posRecords.toArray(new POSRecord[0]);
36+
} catch (IOException e) {
37+
throw new RuntimeException(e);
38+
}
39+
}
40+
41+
POSRecord get(int date) {
42+
return null;
43+
// todo 1 tb/tb continue here
44+
}
45+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.bc.fiduceo.reader.insitu.tao.preproc;
2+
3+
class POSRecord {
4+
5+
int date;
6+
float lon;
7+
float lat;
8+
9+
public int getDate() {
10+
return date;
11+
}
12+
}

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/preproc/RHProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void open(File rhFile) {
2424
}
2525

2626
final RHRecord rhRecord = new RHRecord();
27-
final String[] tokens = StringUtils.split(line, new char[]{' '}, true);
27+
final String[] tokens = TaoPreProcessor.tokenize(line);
2828
rhRecord.date = TaoPreProcessor.toUnixEpoch(tokens[0], tokens[1]);
2929
rhRecord.RH = tokens[2];
3030
rhRecord.Q = tokens[3];

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/preproc/SSTProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void open(File sstFile) {
2424
}
2525

2626
final SSTRecord sstRecord = new SSTRecord();
27-
final String[] tokens = StringUtils.split(line, new char[]{' '}, true);
27+
final String[] tokens = TaoPreProcessor.tokenize(line);
2828
sstRecord.date = TaoPreProcessor.toUnixEpoch(tokens[0], tokens[1]);
2929
sstRecord.SST = tokens[2];
3030
sstRecord.Q = tokens[3];

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/preproc/TAORecord.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ class TAORecord {
66
String SST;
77
String AIRT;
88
String RH;
9+
String WSPD;
10+
String WDIR;
11+
String BARO;
912
String Q;
1013
String M;
1114

1215
String toLine() {
13-
return date + " " + SSS + " " + SST + " " + AIRT + " " + RH + " " + Q + " " + M;
16+
return date + " " + SSS + " " + SST + " " + AIRT + " " + RH + " " + WSPD + " " + WDIR + " " + BARO + " " +Q + " " + M;
1417
}
1518
}

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/preproc/TaoPreProcessor.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public static void main(String[] args) throws IOException {
1818
configuration.sstFileName = "TAO_T0N110W_D_SST_10min.ascii";
1919
configuration.airtFileName = "TAO_T0N110W_D_AIRT_10min.ascii";
2020
configuration.rhFileName = "TAO_T0N110W_D_RH_10min.ascii";
21+
configuration.windFileName = "TAO_T0N110W_D_WIND_10min.ascii";
22+
configuration.baroFileName = "TAO_T0N110W_D_BARO_hourly.ascii";
2123

2224
// --- read all we need ---
2325
final File sourceDir = new File(configuration.sourceDir);
@@ -33,6 +35,12 @@ public static void main(String[] args) throws IOException {
3335
final RHProvider rhProvider = new RHProvider();
3436
rhProvider.open(new File(sourceDir, configuration.rhFileName));
3537

38+
final WINDProvider windProvider = new WINDProvider();
39+
windProvider.open(new File(sourceDir, configuration.windFileName));
40+
41+
final BAROProvider baroProvider = new BAROProvider();
42+
baroProvider.open(new File(sourceDir, configuration.baroFileName));
43+
3644
final HashMap<String, List<TAORecord>> taoMap = new HashMap<>();
3745

3846
// --- assemble final records ---
@@ -70,6 +78,19 @@ public static void main(String[] args) throws IOException {
7078
M = M.concat(rhRecord.M);
7179
Q = Q.concat(rhRecord.Q);
7280

81+
// wind
82+
final WINDRecord windRecord = windProvider.get(sssRecord.date);
83+
taoRecord.WSPD = windRecord.WSPD;
84+
taoRecord.WDIR = windRecord.WDIR;
85+
M = M.concat(windRecord.M);
86+
Q = Q.concat(windRecord.Q);
87+
88+
// barometric pressure
89+
final BARORecord baroRecord = baroProvider.get(sssRecord.date);
90+
taoRecord.BARO = baroRecord.BARO;
91+
M = M.concat(baroRecord.M);
92+
Q = Q.concat(baroRecord.Q);
93+
7394
taoRecord.M = M;
7495
taoRecord.Q = Q;
7596

@@ -94,7 +115,7 @@ public static void main(String[] args) throws IOException {
94115
for (final TAORecord taoRecord : taoRecords) {
95116
utcCalendar.setTimeInMillis(taoRecord.date * 1000L);
96117
int year = utcCalendar.get(Calendar.YEAR);
97-
int month = utcCalendar.get(Calendar.MONTH);
118+
int month = utcCalendar.get(Calendar.MONTH) + 1;
98119
if (year != currentYear || month != currentMonth) {
99120
currentYear = year;
100121
currentMonth = month;
@@ -156,7 +177,7 @@ private static HashMap<String, List<SSSRecord>> parseSSSFile(File sssFile) {
156177
continue;
157178
}
158179

159-
final String[] tokens = StringUtils.split(line, new char[]{' '}, true);
180+
final String[] tokens = TaoPreProcessor.tokenize(line);
160181
final SSSRecord sssRecord = new SSSRecord();
161182
sssRecord.date = toUnixEpoch(tokens[0], tokens[1]);
162183
sssRecord.SSS = tokens[2];
@@ -221,4 +242,9 @@ static int toUnixEpoch(String yyyymmdd, String hhmmss) {
221242
long timeInMillis = calendar.getTime().getTime();
222243
return (int) (timeInMillis / 1000);
223244
}
245+
246+
static String[] tokenize(String line) {
247+
line = line.replaceAll(" +", " "); // some fields are separated by two or more blanks (sigh) tb 2023-04-12
248+
return StringUtils.split(line, new char[]{' '}, true);
249+
}
224250
}

0 commit comments

Comments
 (0)