from tradssat.tmpl.output import FinalOutFile
from tradssat.tmpl.var import IntegerVar, CharacterVar, FloatVar


class SummaryOut(FinalOutFile):
    """
    Reader for DSSAT run summary (SUMMARY.OUT) output files.
    """
    filename = 'Summary.OUT'

    def _get_var_info(self):
        return _vars


_vars = {
    IntegerVar('RUNNO', 5, spc=4, info='Run number'),
    IntegerVar('TRNO', 5, spc=2, info='Run number'),
    IntegerVar('R#', 2, info='Repetition number'),
    IntegerVar('O#', 2, info=''),
    IntegerVar('C#', 2, info=''),
    CharacterVar('CR', 2, info='Crop code'),
    CharacterVar('MODEL', 8, header_fill='.', info='DSSAT crop model used'),
    CharacterVar('EXNAME', 8, header_fill='.', info='Experiment file name'),
    CharacterVar('TNAM', 25, header_fill='.', info='Treatment name'),
    CharacterVar('FNAM', 8, header_fill='.', info='Field name'),
    CharacterVar('WSTA', 8, header_fill='.', info='Weather station name'),
    IntegerVar('WYEAR', 4, info=''),
    CharacterVar('SOIL_ID', 10, header_fill='.', info='Soil name'),
    FloatVar('XLAT', 16, 9, info=''),
    FloatVar('LONG', 15, 9, info=''),
    IntegerVar('ELEV', 9, info=''),
    IntegerVar('SDAT', 7, info='Start date, YYYYDDD'),
    IntegerVar('PDAT', 7, info='Planting date, YYYYDDD'),
    IntegerVar('EDAT', 7, info='Emergence date, YYYYDDD'),
    IntegerVar('ADAT', 7, info='Anthesis date, start, YYYYDDD'),
    IntegerVar('MDAT', 7, info='Maturity (physiological) date, YYYYDDD'),
    IntegerVar('HDAT', 7, info='Harvest date, YYYYDDD'),
    IntegerVar('HYEAR', 7, info=''),
    IntegerVar('DWAP', 5, info='Planting material dry weight, kg ha-1'),
    IntegerVar('CWAM', 7, info='Canopy dry weight at maturity, kg ha-1'),
    IntegerVar('HWAM', 7, info='Yield at maturity, kg ha-1'),
    IntegerVar('HWAH', 7, info='Yield at harvest, kg ha-1'),
    IntegerVar('BWAH', 7, info='Harvested byproduct dry weight, kg ha-1'),
    IntegerVar('PWAM', 5, info=''),
    FloatVar('HWUM', 7, 3, info='Harvest product individual dry wt., mg or g '),
    IntegerVar('H#AM', 7, info='Harvest product number per m2 at maturity'),
    FloatVar('H#UM', 7, 1, info='Harvest product number per unit at maturity'),
    FloatVar('HIAM', 5, 3, info=''),
    FloatVar('LAIX', 5, 1, info=''),
    IntegerVar('FCWAM', 7, info=''),
    IntegerVar('FHWAM', 7, info=''),
    IntegerVar('HWAHF', 7, info=''),
    IntegerVar('FBWAH', 7, info=''),
    IntegerVar('FPWAM', 7, info=''),
    IntegerVar('IR#M', 5, info='Irrigation applications, number'),
    IntegerVar('IRCM', 5, info='Irrigation applied, cumulative, mm'),
    IntegerVar('PRCM', 5, info='Precipitation cumulative, mm'),
    IntegerVar('ETCM', 5, info='Evapotranspiration in season, cumulative, mm'),
    IntegerVar('EPCM', 5, info=''),
    IntegerVar('ESCM', 5, info=''),
    IntegerVar('ROCM', 5, info='Runoff, cumulative, mm'),
    IntegerVar('DRCM', 5, info='Cumulative drainage from profile, mm'),
    IntegerVar('SWXM', 5, info='Water remaining in soil, available, mm'),
    IntegerVar('NI#M', 5, info='Nitrogen applications, number'),
    IntegerVar('NICM', 5, info='Nitrogen applied, cumulative, kg ha-1'),
    IntegerVar('NFXM', 5, info='Nitrogen fixed, cumulative, kg ha-1'),
    IntegerVar('NUCM', 5, info='Total N uptake during season, kg/ha'),
    IntegerVar('NLCM', 5, info='Nitrogen leached, cumulative, kg ha-1'),
    IntegerVar('NIAM', 5, info='Inorganic N in soil at maturity, kg/ha'),
    IntegerVar('CNAM', 5, info='Tops N at maturity, kg ha-1 '),
    IntegerVar('GNAM', 5, info='Nitrogen in harvest product (seed), kg ha-1 '),
    FloatVar('N2OEC', 5, 3, info=''),
    IntegerVar('PI#M', 5, info=''),
    IntegerVar('PICM', 5, info=''),
    IntegerVar('PUPC', 5, info=''),
    IntegerVar('SPAM', 5, info='Cumulative plant P uptake, kg/ha'),
    IntegerVar('KI#M', 5, info=''),
    IntegerVar('KICM', 5, info=''),
    IntegerVar('KUPC', 5, info=''),
    IntegerVar('SKAM', 5, info=''),
    IntegerVar('RECM', 5, info='Residue, etc. applied, cumulative, kg ha-1'),
    IntegerVar('ONTAM', 6, info=''),
    IntegerVar('ONAM', 6, info='Soil organic N at end of season, kg ha-1'),
    IntegerVar('OPTAM', 6, info=''),
    IntegerVar('OPAM', 6, info=''),
    IntegerVar('OCTAM', 7, info=''),
    IntegerVar('OCAM', 7, info='Soil C at end of season, t ha-1'),
    IntegerVar('CO2EC', 7, info=''),
    FloatVar('CH4EC', 6, 1, info=''),
    FloatVar('DMPPM', 8, 1, info=''),
    FloatVar('DMPEM', 8, 1, info=''),
    FloatVar('DMPTM', 8, 1, info=''),
    FloatVar('DMPIM', 8, 1, info=''),
    FloatVar('YPPM', 8, 1, info=''),
    FloatVar('YPEM', 8, 1, info=''),
    FloatVar('YPTM', 8, 1, info=''),
    FloatVar('YPIM', 8, 1, info=''),
    FloatVar('DPNAM', 8, 1, info=''),
    FloatVar('DPNUM', 8, 1, info=''),
    FloatVar('YPNAM', 8, 1, info=''),
    FloatVar('YPNUM', 8, 1, info=''),
    IntegerVar('NDCH', 5, info=''),
    FloatVar('TMAXA', 5, 1, info=''),
    FloatVar('TMINA', 5, 1, info=''),
    FloatVar('SRADA', 5, 1, info=''),
    FloatVar('DAYLA', 5, 1, info=''),
    FloatVar('CO2A', 6, 1, info=''),
    FloatVar('PRCP', 6, 1, info=''),
    FloatVar('ETCP', 6, 1, info=''),
    FloatVar('ESCP', 6, 1, info=''),
    FloatVar('EPCP', 6, 1, info=''),

    # Recently added (#19)
    IntegerVar('P#', 2, info=''),
    IntegerVar('NMINC', 5, info=''),
}
