diff --git a/src/main/java/species/WriteNutrientExportFluxes.java b/src/main/java/species/WriteNutrientExportFluxes.java index adf39b394d52a0d03021c169e8d85e792e6b63ad..b9c863a62c56b0d317701c14f313c2629d4936ae 100644 --- a/src/main/java/species/WriteNutrientExportFluxes.java +++ b/src/main/java/species/WriteNutrientExportFluxes.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; @@ -17,42 +16,43 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; public class WriteNutrientExportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { - private String fileName= "nutrientExportFluxes"; + private String fileName = "nutrientExportFluxes"; + public static void main(String[] args) { - System.out.println((new XStream(new DomDriver())) - .toXML(new WriteNutrientExportFluxes())); + System.out.println((new XStream(new DomDriver())).toXML(new WriteNutrientExportFluxes())); } + @Override public void doProcess(DiadromousFishGroup group) { BufferedWriter bW; - String outputPath = "data/output/" ; - String sep = ";"; + String outputPath = group.getOutputPath(); + String sep = ";"; new File(outputPath + fileName).getParentFile().mkdirs(); try { - bW = new BufferedWriter(new FileWriter(new File(outputPath+ - fileName + group.getSimulationId() + ".csv"))); + bW = new BufferedWriter(new FileWriter(new File(outputPath + fileName + group.getSimulationId() + ".csv"))); - bW.write("year"+sep+"nutrient" + sep + "originBasin" + sep + "value" + "\n"); + bW.write("year" + sep + "nutrient" + sep + "originBasin" + sep + "value" + "\n"); - Map<Long, Map <String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine().getNutrientExportFluxesCollection().getExportFluxesCollection(); + Map<Long, Map<String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine() + .getNutrientExportFluxesCollection().getExportFluxesCollection(); // to iterate on sorted years - List<Long> years = new ArrayList<Long>(fluxesCollection.keySet()); + List<Long> years = new ArrayList<Long>(fluxesCollection.keySet()); Collections.sort(years); - for (long year :years) { + for (long year : years) { if (year >= group.getMinYearToWrite()) { for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { for (String originBasinName : group.getEnvironment().getRiverBasinNames()) { - bW.write(year+ sep+ nutrient + sep + originBasinName ); - bW.write( sep + fluxesCollection.get(year).get(nutrient).get(originBasinName) + '\n'); + bW.write(year + sep + nutrient + sep + originBasinName); + bW.write(sep + fluxesCollection.get(year).get(nutrient).get(originBasinName) + '\n'); } } diff --git a/src/main/java/species/WriteNutrientImportFluxes.java b/src/main/java/species/WriteNutrientImportFluxes.java index 4d957775845d353bd0c2acf0aa3967c956fdcb16..5418cf1bbdeca05423585abd04a63c2354c83dbd 100644 --- a/src/main/java/species/WriteNutrientImportFluxes.java +++ b/src/main/java/species/WriteNutrientImportFluxes.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; @@ -17,57 +16,55 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; public class WriteNutrientImportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { - private String fileName= "fluxes"; - + private String fileName = "fluxes"; public static void main(String[] args) { - System.out.println((new XStream(new DomDriver())) - .toXML(new WriteNutrientImportFluxes())); + System.out.println((new XStream(new DomDriver())).toXML(new WriteNutrientImportFluxes())); } + @Override public void doProcess(DiadromousFishGroup group) { BufferedWriter bW; - String outputPath = "data/output/" ; - String sep = ";"; + String outputPath = group.getOutputPath(); + String sep = ";"; new File(outputPath + fileName).getParentFile().mkdirs(); try { - bW = new BufferedWriter(new FileWriter(new File(outputPath+ - fileName + group.getSimulationId() + ".csv"))); + bW = new BufferedWriter(new FileWriter(new File(outputPath + fileName + group.getSimulationId() + ".csv"))); - bW.write("year"+sep+"nutrient" + sep + "originBasin"); + bW.write("year" + sep + "nutrient" + sep + "originBasin"); for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { - bW.write(sep + birthBasinName); // write each basin name in the file + bW.write(sep + birthBasinName); // write each basin name in the file } bW.write("\n"); - Map<Long, Map <String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine().getNutrientImportFluxesCollection().getImportFluxesCollection(); + Map<Long, Map<String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine() + .getNutrientImportFluxesCollection().getImportFluxesCollection(); // to iterate on sorted years - List<Long> years = new ArrayList<Long>(fluxesCollection.keySet()); + List<Long> years = new ArrayList<Long>(fluxesCollection.keySet()); Collections.sort(years); - - for (long year :years) { + for (long year : years) { if (year >= group.getMinYearToWrite()) { - Map <String, Map<String, Map<String, Double>>> yearsMap = fluxesCollection.get(year); + Map<String, Map<String, Map<String, Double>>> yearsMap = fluxesCollection.get(year); for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { - Map<String, Map<String, Double>> originsMap = yearsMap.get(nutrient); + Map<String, Map<String, Double>> originsMap = yearsMap.get(nutrient); for (String originBasinName : group.getEnvironment().getRiverBasinNames()) { - bW.write(year+ sep+ nutrient + sep + originBasinName ); - Map<String, Double> destinationsMap = originsMap.get(originBasinName); + bW.write(year + sep + nutrient + sep + originBasinName); + Map<String, Double> destinationsMap = originsMap.get(originBasinName); for (String destinationBasinName : group.getEnvironment().getRiverBasinNames()) { - Double aFlux = destinationsMap.get(destinationBasinName); - bW.write( sep + aFlux); + Double aFlux = destinationsMap.get(destinationBasinName); + bW.write(sep + aFlux); } bW.write("\n"); @@ -83,5 +80,4 @@ public class WriteNutrientImportFluxes extends AquaNismsGroupProcess<DiadromousF } } - }