Skip to content

Commit d1120d2

Browse files
committed
performance boost - move writing from inner loop
1 parent 799a7ba commit d1120d2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

post-processing-tool/src/main/java/com/bc/fiduceo/post/plugin/era5/MatchupFields.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,12 @@ void compute(Configuration config, NetcdfFile reader, NetcdfFileWriter writer) t
139139
targetArray.setFloat(targetIndex, (float) interpolated);
140140
}
141141
}
142+
}
142143

144+
for (final String variableKey : variableKeys) {
143145
final TemplateVariable templateVariable = variables.get(variableKey);
144146
final Variable targetVariable = writer.findVariable(NetCDFUtils.escapeVariableName(templateVariable.getName()));
147+
final Array targetArray = targetArrays.get(variableKey);
145148
writer.write(targetVariable, targetArray);
146149
}
147150
} finally {

post-processing-tool/src/main/java/com/bc/fiduceo/post/plugin/era5/SatelliteFields.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,17 @@ void compute(Configuration config, NetcdfFile reader, NetcdfFileWriter writer) t
300300
} else {
301301
throw new IllegalStateException("Unexpected variable rank: " + rank + " " + variableKey);
302302
}
303-
304-
final TemplateVariable templateVariable = variables.get(variableKey);
305-
final Variable targetVariable = writer.findVariable(NetCDFUtils.escapeVariableName(templateVariable.getName()));
306-
writer.write(targetVariable, targetArray);
307303
}
308304
}
305+
306+
final Set<String> variableKeys = variables.keySet();
307+
for (final String variableKey : variableKeys) {
308+
final TemplateVariable templateVariable = variables.get(variableKey);
309+
final Array targetArray = targetArrays.get(variableKey);
310+
final Variable targetVariable = writer.findVariable(NetCDFUtils.escapeVariableName(templateVariable.getName()));
311+
writer.write(targetVariable, targetArray);
312+
}
313+
309314
} finally {
310315
variableCache.close();
311316
}

0 commit comments

Comments
 (0)