<commit_before>package org.agmip.translators.apsim.core;

import org.agmip.translators.apsim.util.Converter;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;

/**
 * @author <NAME>, CSIRO
 * @author <NAME>, DUTh
 * @since Jul 13, 2012
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class InitialCondition {
    
    // date
    @JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)
    @JsonProperty("icdat")
    private String date = "?";
    public String getDate() { return date; }
    
    // residueWeight
    @JsonProperty("icrag")
    private String residueWeight = "?";
    public String getResidueWeight() { return residueWeight; }
    
    // residueNConc
    @JsonProperty("icrn")
    private String residueNConc = "?";
    public String getResidueNConc() { return residueNConc; }
    
    // residueNConc
    @JsonProperty("icrn")
    private String nconc = "?";
    public String getNConc() { return nconc; }    
    
    // cropCode
    @JsonProperty("icpcr")
    private String cropCode = "?";

    // residueType
    public String getResidueType() { return Converter.cropCodeToName(cropCode); }
    
    // soilLayers
    @JsonProperty("soilLayer")
    private InitialConditionLayer[] soilLayers = new InitialConditionLayer[0];
    public InitialConditionLayer[] getSoilLayers() { return soilLayers; }

    // log
    private String log = "";
    public String getLog() { return log; }
    
    // cnr
    private String cnr = "0";
    public String getCnr() {return cnr;}
    
    // Needed for Jackson
    public InitialCondition() {}
    
    
    
    // Initialise this instance.
    public void initialise(SoilLayer[] layersFromSoil) {
        double cumThickness = 0.0;
        if (soilLayers.length == 0) {
            log = "  * Initial conditions ERROR: Missing NO3, NH4 and SW. An empty table has been set up under soil with '-99' entries \r\n";
            soilLayers = new InitialConditionLayer[layersFromSoil.length];
            for (int i = 0; i < soilLayers.length; i++) {
                soilLayers[i] = new InitialConditionLayer(layersFromSoil[i].getThickness());
            }
        }
        else {
            boolean missingFound = false;
            for (int i = 0; i < soilLayers.length; i++) {
                cumThickness = soilLayers[i].initialise(cumThickness);
                if ("-99".equals(soilLayers[i].getNo3()) ||
                    "-99".equals(soilLayers[i].getNh4()) ||
                    "-99".equals(soilLayers[i].getSoilWater()))
                    missingFound = true;
            } 
            if (missingFound)
                log = "  * Initial conditions ERROR: Some missing values were found. Please check the table initial conditions table under the soil\r\n";
        }
        
        if ("?".equals(getResidueType()))
            log += "  * SurfaceOrganicMatter ERROR: Missing residue type.\r\n";
        
        if ("?".equals(residueWeight))
            log += "  * SurfaceOrganicMatter ERROR: Missing residue weight.\r\n";
        else {
            if ("?".equals(nconc))
                log += "  * SurfaceOrganicMatter ERROR: Missing residue nitrogen concentration. Cannot calculate CNR.\r\n";
            
            else {
                double carbon = 0.4 * Double.valueOf(residueWeight);
                double nitrogen = Double.valueOf(nconc) / 100.0 * Double.valueOf(residueWeight);
                if (nitrogen == 0)
                    log += "  * SurfaceOrganicMatter ERROR: Residue nitrogen concentration = 0.\r\n";
                else
                    cnr = String.valueOf(carbon / nitrogen);
                }
                
            }
        }
                
    }

<commit_msg>Fixed icrn bug.<commit_after>package org.agmip.translators.apsim.core;

import org.agmip.translators.apsim.util.Converter;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;

/**
 * @author <NAME>, CSIRO
 * @author <NAME>, DUTh
 * @since Jul 13, 2012
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class InitialCondition {
    
    // date
    @JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)
    @JsonProperty("icdat")
    private String date = "?";
    public String getDate() { return date; }
    
    // residueWeight
    @JsonProperty("icrag")
    private String residueWeight = "?";
    public String getResidueWeight() { return residueWeight; }
    
    // residueNConc
    @JsonProperty("icrn")
    private String residueNConc = "?";
    public String getResidueNConc() { return residueNConc; }
    
 
    
    // cropCode
    @JsonProperty("icpcr")
    private String cropCode = "?";

    // residueType
    public String getResidueType() { return Converter.cropCodeToName(cropCode); }
    
    // soilLayers
    @JsonProperty("soilLayer")
    private InitialConditionLayer[] soilLayers = new InitialConditionLayer[0];
    public InitialConditionLayer[] getSoilLayers() { return soilLayers; }

    // log
    private String log = "";
    public String getLog() { return log; }
    
    // cnr
    private String cnr = "0";
    public String getCnr() {return cnr;}
    
    // Needed for Jackson
    public InitialCondition() {}
    
    
    
    // Initialise this instance.
    public void initialise(SoilLayer[] layersFromSoil) {
        double cumThickness = 0.0;
        if (soilLayers.length == 0) {
            log = "  * Initial conditions ERROR: Missing NO3, NH4 and SW. An empty table has been set up under soil with '-99' entries \r\n";
            soilLayers = new InitialConditionLayer[layersFromSoil.length];
            for (int i = 0; i < soilLayers.length; i++) {
                soilLayers[i] = new InitialConditionLayer(layersFromSoil[i].getThickness());
            }
        }
        else {
            boolean missingFound = false;
            for (int i = 0; i < soilLayers.length; i++) {
                cumThickness = soilLayers[i].initialise(cumThickness);
                if ("-99".equals(soilLayers[i].getNo3()) ||
                    "-99".equals(soilLayers[i].getNh4()) ||
                    "-99".equals(soilLayers[i].getSoilWater()))
                    missingFound = true;
            } 
            if (missingFound)
                log = "  * Initial conditions ERROR: Some missing values were found. Please check the table initial conditions table under the soil\r\n";
        }
        
        if ("?".equals(getResidueType()))
            log += "  * SurfaceOrganicMatter ERROR: Missing residue type.\r\n";
        
        if ("?".equals(residueWeight))
            log += "  * SurfaceOrganicMatter ERROR: Missing residue weight.\r\n";
        else {
            if ("?".equals(residueNConc))
                log += "  * SurfaceOrganicMatter ERROR: Missing residue nitrogen concentration. Cannot calculate CNR.\r\n";
            
            else {
                double carbon = 0.4 * Double.valueOf(residueWeight);
                double nitrogen = Double.valueOf(residueNConc) / 100.0 * Double.valueOf(residueWeight);
                if (nitrogen == 0)
                    log += "  * SurfaceOrganicMatter ERROR: Residue nitrogen concentration = 0.\r\n";
                else
                    cnr = String.valueOf(carbon / nitrogen);
                }
                
            }
        }
                
    }


{'fraction_non_alphanumeric': 0.11233567919267029, 'fraction_numerical': 0.00876377639091754, 'mean_word_length': 2.103419859909353, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4940831', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2118, 'n_words': 502}