diff --git a/data/input/fishTryRealBV_CC.xml b/data/input/fishTryRealBV_CC.xml index 3cbb97ae8ddaacea54d3db8e380b55a25aff5fb8..8dfc85d26ce78d9fa3e2c30c313fb9fce14c8cd5 100644 --- a/data/input/fishTryRealBV_CC.xml +++ b/data/input/fishTryRealBV_CC.xml @@ -279,6 +279,7 @@ <standardDeviationOfSpawnersLengthAtRepro>2.0</standardDeviationOfSpawnersLengthAtRepro> <weightOfDeathBasin>0.4</weightOfDeathBasin> </species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin> + <species.Survive> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <tempMinMortGenInRiv>10.0</tempMinMortGenInRiv> @@ -289,6 +290,13 @@ <mortalityRateInSea>0.4</mortalityRateInSea> <mortalityRateInOffshore>0.4</mortalityRateInOffshore> </species.Survive> + + <species.ExportFluxes> + <synchronisationMode>ASYNCHRONOUS</synchronisationMode> + <exportSeason>SPRING</exportSeason> + <fileNameOutput>EffectiveFluxes</fileNameOutput> + </species.ExportFluxes> + <species.ReproduceAndSurviveAfterReproductionWithDiagnose> <synchronisationMode>ASYNCHRONOUS</synchronisationMode> <reproductionSeason>SPRING</reproductionSeason> diff --git a/src/main/java/species/DiadromousFishGroup.java b/src/main/java/species/DiadromousFishGroup.java index 6cb3acfad0d24d85a70448e63849bbcef830144b..bd6fb457c0a1cdef793d1e930414139caef05194 100644 --- a/src/main/java/species/DiadromousFishGroup.java +++ b/src/main/java/species/DiadromousFishGroup.java @@ -412,7 +412,7 @@ public class DiadromousFishGroup extends AquaNismsGroup< DiadromousFish, BasinNe fileNameFluxes +this.getSimulationId() + ".csv"))); bWForFluxes.write("timestep"+sep+"year"+sep+"season"+sep+"basin" - +sep+"abundance" + sep + "fluxType"+sep+"origine"+sep+"biomass"); + +sep+"abundance" + sep + "fluxType"+ sep + "origin" +sep+"biomass"); for (String nutrient : nutrientRoutine.getNutrientsOfInterest()) { bWForFluxes.write(sep+nutrient); } diff --git a/src/main/java/species/ExportFluxes.java b/src/main/java/species/ExportFluxes.java new file mode 100644 index 0000000000000000000000000000000000000000..da3a2940de2c31bf40bb1cf865680cf07ba9118b --- /dev/null +++ b/src/main/java/species/ExportFluxes.java @@ -0,0 +1,110 @@ + +package species; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomDriver; + +import environment.RiverBasin; +import environment.Time; +import environment.Time.Season; +import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; +import fr.cemagref.simaqualife.pilot.Pilot; +import species.DiadromousFish.Stage; + +/** + * + */ +public class ExportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> { + + private Season exportSeason = Season.SPRING; + + private String fileNameOutput = "EffectiveFluxes"; + + private transient BufferedWriter bW; + private transient String sep=";"; + + public static void main(String[] args) { + System.out.println((new XStream(new DomDriver())) + .toXML(new ExportFluxes())); + } + + /* (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(); + try { + bW = new BufferedWriter(new FileWriter(new File(group.getOutputPath()+ + fileNameOutput +group.getSimulationId()+ ".csv"))); + + 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 + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + try { + if (Time.getSeason(pilot) == exportSeason & Time.getYear(pilot)>1900) { + + + for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) { + //Create the map to get the abundance in each birth basin + Map<String, Long> spawnerOriginsBeforeReproduction = new HashMap<String, Long>(group.getEnvironment().getRiverBasinNames().length); + for (String basinName : group.getEnvironment().getRiverBasinNames()){ + spawnerOriginsBeforeReproduction.put(basinName, 0L); + } + + //compute the cumulative effective per birth basin + if (migrationBasin.getFishs(group) != null) { + for (DiadromousFish fish : migrationBasin.getFishs(group)) { + if (fish.getStage() == Stage.MATURE) { + String birthBasinName = fish.getBirthBasin().getName(); + spawnerOriginsBeforeReproduction.put(birthBasinName, spawnerOriginsBeforeReproduction.get(birthBasinName) + fish.getAmount()); + + + } + + } + } + + //write the first two fields of the line + bW.write(Time.getYear(pilot)+sep+migrationBasin.getName()); + + //write the cumulative effective from birth basin + for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) { + bW.write(sep+spawnerOriginsBeforeReproduction.get(birthBasinName)); + } + //write an end-of(line + bW.write("\n"); + } + } + if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1) + bW.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java index 3d54e84fe305847ebcdcc4ea97fe8656ff2d37d6..7b508000fbdfd7f8aac5507ce98ecc7d831df782 100644 --- a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java +++ b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java @@ -3,6 +3,7 @@ package species; import java.io.BufferedWriter; import java.io.IOException; +import java.io.ObjectInputStream.GetField; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; @@ -169,7 +170,7 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG // age of autochnonous spawnser Map<Integer, Long> ageOfNativeSpawners = new TreeMap<Integer, Long>(); - + // compute the number of spawners and keep the origines of the spawners for (DiadromousFish fish : fishInBasin){ @@ -410,9 +411,9 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG try { for (fluxOrigin origin : totalInputFluxes.keySet()) { bW.write(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) - +";"+ riverBasin.getName() + ";" + riverBasin.getSpawnerNumber() + ";" + ";IMPORT;"+origin); + +";"+ riverBasin.getName() + ";" + riverBasin.getSpawnerNumber() + ";" + "IMPORT"+ ";" + origin); bW.write(";" + totalInputFluxes.get(origin).get("biomass")); - + for (String nutrient : group.getNutrientRoutine().getNutrientsOfInterest()) { bW.write(";" + totalInputFluxes.get(origin).get(nutrient)); } @@ -434,8 +435,8 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG riverBasin.getSpawnerOrigins().push(spawnerOriginsDuringReproduction); //System.out.println(" AFTER " +riverBasin.getSpawnerOrigins().keySet()); } - - + + // -------------------------------------------------------------------------------------------------- // update the observers // --------------------------------------------------------------------------------------------------