Author: loic Date: 2013-05-02 18:56:05 +0200 (Thu, 02 May 2013) New Revision: 35 Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revisions... Log: sensitivityexport_spawning_biomass_janvier Added: trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java Added: trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java =================================================================== --- trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java (rev 0) +++ trunk/sensitivityexports/SensitivitySpawningBiomassJanvierY2.java 2013-05-02 16:56:05 UTC (rev 35) @@ -0,0 +1,101 @@ +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ +package sensitivityexports; + +import fr.ifremer.isisfish.datastore.ResultStorage; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.PopulationGroup; +import fr.ifremer.isisfish.export.SensitivityExport; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.util.Doc; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixIterator; +import org.nuiton.math.matrix.MatrixND; + +import scripts.ResultName; + +import java.io.Writer; + +import static org.nuiton.i18n.I18n._; + +public class SensitivitySpawningBiomassJanvierY2 implements SensitivityExport { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory + .getLog(SensitivitySpawningBiomassJanvierY2.class); + + protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS }; + + @Doc("Population") + public Population param_pop; + + @Override + public void export(SimulationStorage simulation, Writer out) + throws Exception { + TimeStep lastStep = simulation.getResultStorage().getLastStep(); + TimeStep janvierLastYear = new TimeStep(12 * lastStep.getYear()); + double biomass = 0.0; + + for (Population pop : simulation.getParameter().getPopulations()) { + if (pop.getName().equals(param_pop.getName())) { + ResultStorage resultStorage = simulation.getResultStorage(); + + //Get the biomass of the last time step + MatrixND matlastJan = resultStorage.getMatrix(pop, + ResultName.MATRIX_BIOMASS); + for (MatrixIterator i = matlastJan.iterator(); i.hasNext();) { + i.next(); + Object[] sems = i.getSemanticsCoordinates(); + TimeStep step = (TimeStep) sems[0]; + PopulationGroup group = (PopulationGroup) sems[1]; + if (step.equals(janvierLastYear)) { + biomass += i.getValue() * group.getMaturityOgive(); + } + } + } + } + out.write(Double.toString(biomass)); + } + + @Override + public String getDescription() { + return _("Biomass of genitors for January of the last year. Biomass is the sum on the groups and zones"); + } + + @Override + public String getExportFilename() { + return "SensitivityGenitorBiomassJanvierY2_" + param_pop.getName(); + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + +}