diff --git a/src/main/java/species/WriteBiomassFluxes.java b/src/main/java/species/WriteBiomassFluxes.java index a98b28ab10a8cf73a76ee646bf226f1e69d0d069..16e1f5d0bae2fd1f7dc1399e181717f8658b3c33 100644 --- a/src/main/java/species/WriteBiomassFluxes.java +++ b/src/main/java/species/WriteBiomassFluxes.java @@ -5,8 +5,6 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; import java.util.Map; import com.thoughtworks.xstream.XStream; @@ -17,55 +15,57 @@ import environment.Time; import environment.Time.Season; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.pilot.Pilot; -import miscellaneous.Miscellaneous; import species.DiadromousFish.Stage; -import species.ReproduceAndSurviveAfterReproductionWithDiagnose; /** * */ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { - private Season exportSeason = Season.SPRING; private String fileNameOutput = "biomassFluxes"; private transient BufferedWriter bW; - private transient String sep=";"; + private transient String sep = ";"; public static void main(String[] args) { - System.out.println((new XStream(new DomDriver())) - .toXML(new WriteBiomassFluxes())); + System.out.println((new XStream(new DomDriver())).toXML(new WriteBiomassFluxes())); } - /* (non-Javadoc) - * @see fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife.pilot.Pilot) + + /* + * (non-Javadoc) + * + * @see + * fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife. + * pilot.Pilot) */ @Override public void initTransientParameters(Pilot pilot) { super.initTransientParameters(pilot); - sep=";"; - } + @Override public void doProcess(DiadromousFishGroup group) { - if (bW==null){ - if (fileNameOutput != null){ - new File(group.getOutputPath()+fileNameOutput).getParentFile().mkdirs(); + if (bW == null) { + sep = ";"; + if (fileNameOutput != null) { + new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs(); try { - bW = new BufferedWriter(new FileWriter(new File(group.getOutputPath()+ - fileNameOutput +group.getSimulationId()+ ".csv"))); + bW = new BufferedWriter( + new FileWriter(new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv"))); - bW.write("year"+sep+"migrationBasin" ); //create the field of the column + bW.write("year" + sep + "migrationBasin"); // create the field of the column 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"); + bW.flush(); } catch (IOException e) { e.printStackTrace(); @@ -75,17 +75,19 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di try { Time time = group.getEnvironment().getTime(); - if (time.getSeason(pilot) == exportSeason & time.getYear(pilot) >= group.getMinYearToWrite()) { - + System.out.println(time.getSeason(group.getPilot())); + System.out.println(time.getYear(group.getPilot())); + if (time.getSeason(group.getPilot()) == exportSeason & time.getYear(group.getPilot()) >= group.getMinYearToWrite()) { for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) { - //Create the map to get the biomass in each birth basin - Map<String, Double> spawnerAbundancesPerOrigin = new HashMap<String, Double>(group.getEnvironment().getRiverBasinNames().length); - for (String basinName : group.getEnvironment().getRiverBasinNames()){ - spawnerAbundancesPerOrigin.put(basinName, 0.); + // Create the map to get the biomass in each birth basin + Map<String, Double> spawnerAbundancesPerOrigin = new HashMap<String, Double>( + group.getEnvironment().getRiverBasinNames().length); + for (String basinName : group.getEnvironment().getRiverBasinNames()) { + spawnerAbundancesPerOrigin.put(basinName, 0.); } - double biomass=0.; - //compute the cumulative effective per birth basin + double biomass = 0.; + // compute the cumulative effective per birth basin if (migrationBasin.getFishs(group) != null) { for (DiadromousFish fish : migrationBasin.getFishs(group)) { @@ -93,24 +95,28 @@ public class WriteBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, Di if (fish.getStage() == Stage.MATURE) { biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount(); String birthBasinName = fish.getBirthBasin().getName(); - spawnerAbundancesPerOrigin.put(birthBasinName, spawnerAbundancesPerOrigin.get(birthBasinName) + biomass); + spawnerAbundancesPerOrigin.put(birthBasinName, + spawnerAbundancesPerOrigin.get(birthBasinName) + biomass); } } } - //write the first two fields of the line - bW.write(time.getYear(pilot)+sep+migrationBasin.getName()); + // write the first two fields of the line + bW.write(time.getYear(group.getPilot()) + sep + migrationBasin.getName()); - //write the cumulative effective from birth basin + // write the cumulative effective from birth basin for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { - bW.write(sep+spawnerAbundancesPerOrigin.get(birthBasinName)); + bW.write(sep + spawnerAbundancesPerOrigin.get(birthBasinName)); } - //write an end-of(line + // write an end-of(line bW.write("\n"); } } - 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.close(); + } + } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/species/WriteEffectiveAndBiomassImportFluxes.java b/src/main/java/species/WriteEffectiveAndBiomassImportFluxes.java index 2146f10ef91ba70df240be83f9f09bd3a12e5303..4d19b1702af27f1ec932eb2b4ef0627e6f999bc0 100644 --- a/src/main/java/species/WriteEffectiveAndBiomassImportFluxes.java +++ b/src/main/java/species/WriteEffectiveAndBiomassImportFluxes.java @@ -76,8 +76,8 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< if (fileNameOutput != null) { new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs(); try { - bW = new BufferedWriter(new FileWriter( - new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv"))); + bW = new BufferedWriter( + new FileWriter(new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv"))); bW.write("year" + sep + "type" + sep + "originBasin"); // create the field of the column for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { @@ -93,7 +93,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< Time time = group.getEnvironment().getTime(); - if (time.getSeason(pilot) == exportSeason & time.getYear(pilot) >= group.getMinYearToWrite()) { + if (time.getSeason(group.getPilot()) == exportSeason & time.getYear(group.getPilot()) >= group.getMinYearToWrite()) { // Create the map to get the biomass in each migration basin and birth basin Map<String, Map<String, Long>> spawnerEffectivePerDestination = new HashMap<String, Map<String, Long>>( @@ -130,8 +130,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< double biomass = group.getNutrientRoutine().getWeight(fish) * fish.getAmount(); spawnerBiomassPerDestination.get(destinationBasin.getName()).put(originBasinName, - spawnerBiomassPerDestination.get(destinationBasin.getName()).get(originBasinName) - + biomass); + spawnerBiomassPerDestination.get(destinationBasin.getName()).get(originBasinName) + biomass); } } } @@ -160,8 +159,7 @@ public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess< bW.write("\n"); } - 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.close(); }