Commit fb60514b authored by Lambert Patrick's avatar Lambert Patrick
Browse files

with right output path

parent 957c9e54
...@@ -13,41 +13,40 @@ import environment.Time; ...@@ -13,41 +13,40 @@ import environment.Time;
import environment.Time.Season; import environment.Time.Season;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
public class WriteCurrentNutrientExportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { public class WriteCurrentNutrientExportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private String fileName= "currentNutrientExportFluxes"; private String fileName = "currentNutrientExportFluxes";
private Season writeSeason = Season.SPRING; private Season writeSeason = Season.SPRING;
private transient BufferedWriter bW; private transient BufferedWriter bW;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())) System.out.println((new XStream(new DomDriver())).toXML(new WriteCurrentNutrientExportFluxes()));
.toXML(new WriteCurrentNutrientExportFluxes()));
} }
@Override @Override
public void doProcess(DiadromousFishGroup group) { public void doProcess(DiadromousFishGroup group) {
String sep = ";"; String sep = ";";
Time time = group.getEnvironment().getTime(); Time time = group.getEnvironment().getTime();
// initialise the bW the first time // initialise the bW the first time
try { try {
if ( bW == null) { if (bW == null) {
String outputPath = "data/output/" ; String outputPath = group.getOutputPath();
new File(outputPath + fileName).getParentFile().mkdirs(); new File(outputPath + fileName).getParentFile().mkdirs();
bW = new BufferedWriter(new FileWriter(new File(outputPath+ bW = new BufferedWriter(
fileName + group.getSimulationId() + ".csv"))); 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");
} }
// write information for the current year // write information for the current year
Map<Long, Map <String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine().getNutrientExportFluxesCollection().getExportFluxesCollection(); Map<Long, Map<String, Map<String, Double>>> fluxesCollection = group.getNutrientRoutine()
.getNutrientExportFluxesCollection().getExportFluxesCollection();
long year = time.getYear(group.getPilot()); long year = time.getYear(group.getPilot());
...@@ -55,15 +54,16 @@ public class WriteCurrentNutrientExportFluxes extends AquaNismsGroupProcess<Diad ...@@ -55,15 +54,16 @@ public class WriteCurrentNutrientExportFluxes extends AquaNismsGroupProcess<Diad
for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) {
for (String originBasinName : group.getEnvironment().getRiverBasinNames()) { for (String originBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(year+ sep+ nutrient + sep + originBasinName ); bW.write(year + sep + nutrient + sep + originBasinName);
bW.write( sep + fluxesCollection.get(year).get(nutrient).get(originBasinName) ); bW.write(sep + fluxesCollection.get(year).get(nutrient).get(originBasinName));
} }
bW.write("\n"); bW.write("\n");
} }
} }
// close the bW // close the bW
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1){ if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() + group.getPilot().getSimDuration()
- 1) {
bW.flush(); bW.flush();
bW.close(); bW.close();
} }
......
...@@ -4,11 +4,7 @@ import java.io.BufferedWriter; ...@@ -4,11 +4,7 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomDriver;
...@@ -19,60 +15,60 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; ...@@ -19,60 +15,60 @@ import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
public class WriteCurrentNutrientImportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { public class WriteCurrentNutrientImportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private String fileName= "currentNutrientImporttFluxes"; private String fileName = "currentNutrientImporttFluxes";
private Season writeSeason = Season.SPRING; private Season writeSeason = Season.SPRING;
private transient BufferedWriter bW; private transient BufferedWriter bW;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())) System.out.println((new XStream(new DomDriver())).toXML(new WriteCurrentNutrientImportFluxes()));
.toXML(new WriteCurrentNutrientImportFluxes()));
} }
@Override @Override
public void doProcess(DiadromousFishGroup group) { public void doProcess(DiadromousFishGroup group) {
String sep = ";"; String sep = ";";
Time time = group.getEnvironment().getTime(); Time time = group.getEnvironment().getTime();
try { try {
// initialise the bW the first time // initialise the bW the first time
if ( bW == null) { if (bW == null) {
String outputPath = "data/output/" ; String outputPath = group.getOutputPath();
new File(outputPath + fileName).getParentFile().mkdirs(); new File(outputPath + fileName).getParentFile().mkdirs();
bW = new BufferedWriter(new FileWriter(new File(outputPath+ bW = new BufferedWriter(
fileName + group.getSimulationId() + ".csv"))); 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()) { 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"); bW.write("\n");
} }
Map<Long, Map<String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine()
Map<Long, Map <String, Map<String, Map<String, Double>>>> fluxesCollection = group.getNutrientRoutine(). .getNutrientImportFluxesCollection().getImportFluxesCollection();
getNutrientImportFluxesCollection().getImportFluxesCollection();
long year = time.getYear(group.getPilot()); long year = time.getYear(group.getPilot());
if (year >= group.getMinYearToWrite() & time.getSeason(group.getPilot()) == writeSeason) { if (year >= group.getMinYearToWrite() & time.getSeason(group.getPilot()) == writeSeason) {
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()) { 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()) { for (String originBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(year+ sep+ nutrient + sep + originBasinName ); bW.write(year + sep + nutrient + sep + originBasinName);
Map<String, Double> destinationsMap = originsMap.get(originBasinName); Map<String, Double> destinationsMap = originsMap.get(originBasinName);
for (String destinationBasinName : group.getEnvironment().getRiverBasinNames()) { for (String destinationBasinName : group.getEnvironment().getRiverBasinNames()) {
Double aFlux = destinationsMap.get(destinationBasinName); Double aFlux = destinationsMap.get(destinationBasinName);
bW.write( sep + aFlux); bW.write(sep + aFlux);
} }
bW.write("\n"); bW.write("\n");
} }
...@@ -80,7 +76,8 @@ public class WriteCurrentNutrientImportFluxes extends AquaNismsGroupProcess<Diad ...@@ -80,7 +76,8 @@ public class WriteCurrentNutrientImportFluxes extends AquaNismsGroupProcess<Diad
} }
// close the bW // close the bW
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1){ if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() + group.getPilot().getSimDuration()
- 1) {
bW.flush(); bW.flush();
bW.close(); bW.close();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment