diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java index 451012eceb1c6d5063d09f37085f12a2d1a66357..c1f29cee2928ebd02ca3a68b92171bb4899a7e71 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/HazardExport.java @@ -65,7 +65,7 @@ public final class HazardExport { private static final String CURVE_FILE_ASCII_TRUNCATED = "curves-truncated.csv"; private static final String VALUE_FMT = "%.8e"; - private final Path dir; + private final Path out; private final HazardModel model; private final CalcConfig config; private final boolean exportGmm; @@ -82,9 +82,9 @@ public final class HazardExport { HazardModel model, CalcConfig config, List<Site> sites, - OptionalDouble vs30) throws IOException { + Path out) throws IOException { - this.dir = createOutputDir(config.output.directory, vs30); + this.out = out; this.model = model; this.config = config; this.exportGmm = config.output.dataTypes.contains(DataType.GMM); @@ -107,16 +107,17 @@ public final class HazardExport { * @param model being run * @param config that specifies output options and formats * @param sites reference to the sites to be processed (not retained) - * @param vs30 optional vs30 value used when running multiple site classes + * @param out results directory; this may have been been modified from + * {@code config.output.directory} by calling program * @param log shared logging instance from calling class */ public static HazardExport create( HazardModel model, CalcConfig config, List<Site> sites, - OptionalDouble vs30) throws IOException { + Path out) throws IOException { - return new HazardExport(model, config, sites, vs30); + return new HazardExport(model, config, sites, out); } /* Initialize output directories. */ @@ -124,7 +125,7 @@ public final class HazardExport { for (Imt imt : config.hazard.imts) { - Path imtDir = dir.resolve(imt.name()); + Path imtDir = out.resolve(imt.name()); Files.createDirectory(imtDir); Path totalFile = imtDir.resolve(CURVE_FILE_ASCII); Path totalFileTruncated = imtDir.resolve(CURVE_FILE_ASCII_TRUNCATED); @@ -176,6 +177,7 @@ public final class HazardExport { } if (vs30.isPresent()) { String vs30dir = "vs30-" + ((int) vs30.getAsDouble()); + outDir = outDir.resolve(vs30dir); } Files.createDirectories(outDir); @@ -212,7 +214,7 @@ public final class HazardExport { * The target output directory established by this handler. */ public Path outputDir() { - return dir; + return out; } /* Write the supplied hazard results to file(s). */ @@ -240,7 +242,7 @@ public final class HazardExport { String emptyLine = locStr + "0.0" + ",0.0".repeat(totalCurve.size() - 1); Imt imt = imtEntry.getKey(); - Path imtDir = dir.resolve(imt.name()); + Path imtDir = out.resolve(imt.name()); String totalLine = locStr + valueStr(totalCurve, valueFormatter); String totalLineTrunc = locStr + truncValueStr(totalCurve, valueFormatter, TRUNCATION_LIMIT); diff --git a/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java b/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java index d7518714db457d7a47df746e2f3829df35acafe5..dffe8ea827dcd131be9dabba435eeb9d4135fe39 100644 --- a/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java +++ b/src/test/java/gov/usgs/earthquake/nshmp/model/LoaderTests.java @@ -214,7 +214,7 @@ class LoaderTests { List<Site> sites) throws IOException { ExecutorService exec = initExecutor(config.performance.threadCount); - HazardExport handler = HazardExport.create(model, config, sites, OptionalDouble.empty()); + HazardExport handler = HazardExport.create(model, config, sites, config.output.directory); for (Site site : sites) { Hazard hazard = HazardCalcs.hazard(model, config, site, exec); handler.write(hazard);