# Import HYPE Files

## Setup

    # Load HYPEtools Package
    library(HYPEtools)

    # Get Path to HYPEtools Model Example Files
    model_path <- system.file("demo_model", package = "HYPEtools")

    # List HYPE Model Example Files
    list.files(model_path)
    #>  [1] "AquiferData_Example.txt" "ClassData.txt"
    #>  [3] "FloodData_Example.txt"   "ForcKey.txt"
    #>  [5] "GeoClass.txt"            "GeoData.txt"
    #>  [7] "LakeData.txt"            "Pobs.txt"
    #>  [9] "PointSourceData.txt"     "Qobs.txt"
    #> [11] "Tobs.txt"                "Xobs.txt"
    #> [13] "description.txt"         "filedir.txt"
    #> [15] "gis"                     "info.txt"
    #> [17] "optpar.txt"              "par.txt"
    #> [19] "pmsf.txt"                "results"

More information on the different types of HYPE model files can be found on the HYPE Wiki: http://hype.smhi.net/wiki/doku.php?id=start:hype_file_reference

## Import Some Model Setup Files

    # Import Files
    gd <- ReadGeoData(file.path(model_path, "GeoData.txt"))
    gc <- ReadGeoClass(file.path(model_path, "GeoClass.txt"))
    #> 14 data columns in imported file.

    # Some Import Checks
    summary(gd)
    #>
    #> Columns, except 'SLC_n', 'SCR_n', and 'DHSLC_n':
    #>
    #>  column       name   class    | column       name   class    | column
    #>       1      SUBID integer    |      5     PARREG integer    |     15
    #>       2   MAINDOWN integer    |      6     RIVLEN numeric    |     16
    #>       3 LAKEDATAID integer    |     13 SLOPE_MEAN numeric    |     17
    #>       4       AREA numeric    |     14     ICATCH numeric    |
    #>        name   class
    #>  LAKE_DEPTH numeric
    #>       POURX numeric
    #>       POURY numeric
    #>
    #>
    #>                                     mean median  minimum maximum
    #>              Sub-basin area (km2):  13.8   11.1   0.0721    62.6
    #>        Unit river length (km/km2): 0.518  0.246 0.000807    3.63
    #>  ilake drainage area fraction (-): 0.301    0.3      0.3   0.319
    #>
    #>              Number of sub-basins: 25
    #>    ID(s) of outlets in 'maindown': 3606
    #>             Number of SLC classes: 6
    #>             Number of SCR classes: 0
    #>           Number of DHSLC classes: 0
    #>                       SLC columns: c(7:12)

    str(gc)
    #> 'data.frame':    6 obs. of  14 variables:
    #>  $ slc        : int  1 2 3 4 5 6
    #>  $ landuse    : int  1 1 3 2 2 3
    #>  $ soil       : int  1 1 1 1 2 2
    #>  $ cropid1    : int  0 0 0 0 0 0
    #>  $ cropid2    : int  0 0 0 0 0 0
    #>  $ rotation   : int  0 0 0 0 0 0
    #>  $ vegtype    : int  1 1 1 1 1 1
    #>  $ special    : int  1 2 0 0 0 0
    #>  $ tiledepth  : int  0 0 0 0 0 0
    #>  $ streamdepth: num  0 0 0.6 1 1 0.75
    #>  $ nsoils     : int  1 1 3 3 3 3
    #>  $ depth1     : num  10 10 0.25 0.25 0.25 0.25
    #>  $ depth2     : num  NA NA 0.5 0.75 0.75 0.5
    #>  $ depth3     : num  NA NA 0.75 1.5 1.5 1
    #>  - attr(*, "comment")= chr [1:3] "!Landuses: 1=Water; 2=Coniferous forest; 3=Agricultural land\t\t\t\t\t\t\t\t\t\t\t\t\t" "!Soils: 1=Fine soil; 2=Coarse soil\t\t\t\t\t\t\t\t\t\t\t\t\t" "!Combination\tLanduse\tSoil\tCropid-main\tCropid-2nd\tRotation\tVegetationstyp\tSpecial-class\tTile-depth\tDrai"| __truncated__

    class(gd)
    #> [1] "HypeGeoData" "data.frame"

## Import Discharge Observations

    # Import Discharge Observations
    qobs <- ReadObs(file.path(model_path, "Qobs.txt"))

    str(qobs)
    #> 'data.frame':    365 obs. of  2 variables:
    #>  $ DATE : POSIXct, format: "2001-01-01" "2001-01-02" ...
    #>  $ X3587: num  5.09 5 5 5 5.01 ...
    #>  - attr(*, "obsid")= int 3587
    #>  - attr(*, "timestep")= chr "day"
    #>  - attr(*, "variable")= chr "rout"

    # Get SUBIDs with observations from attribute
    obsid(qobs)
    #> [1] 3587

## Import Parameter File

    # Import Parameter File
    par <- ReadPar(file.path(model_path, "par.txt"))

    str(par)
    #> List of 111
    #>  $ !!        : chr "======================================================================================================="
    #>  $ !!        : chr "GENERAL PARAMETERS"
    #>  $ !!        : chr "__________"
    #>  $ cevpam    : num 0.25
    #>  $ cevpph    : num 67.5
    #>  $ damp      : num 0.5
    #>  $ deepmem   : num 1000
    #>  $ epotdist  : num 3
    #>  $ gldepi    : num 3.6
    #>  $ grata     : num 0.6
    #>  $ gratk     : num 0.283
    #>  $ gratp     : num 2
    #>  $ lp        : num 0.95
    #>  $ qmean     : num 200
    #>  $ rcgrw     : num 0
    #>  $ rivvel    : num 1
    #>  $ rrcs3     : num 2e-04
    #>  $ sdnsnew   : num 0.09
    #>  $ sdnsmax   : num 0.5
    #>  $ sdnsrate  : num 0.015
    #>  $ sdnsradd  : num 0.026
    #>  $ tcalt     : num 0.6
    #>  $ ttpi      : num 3
    #>  $ pcelevth  : num 500
    #>  $ pcelevadd : num 0.04
    #>  $ pcelevmax : num 0.04
    #>  $ !!        : chr "======================================================================================================="
    #>  $ !!        : chr "LANDUSE"
    #>  $ !!        : chr "__________"
    #>  $ !!        : chr "Landuse Classes: 1=Water 2=Coniferous forest 3=Agricultural land"
    #>  $ cevp      : num [1:3] 0.175 0.22 0.215
    #>  $ cmlt      : num [1:3] 2.8 1.9 3.5
    #>  $ frost     : num [1:3] 2 2 2
    #>  $ srrcs     : num [1:3] 0.4 0.2 0.3
    #>  $ surfmem   : num [1:3] 17.8 5.15 5.15
    #>  $ ttmp      : num [1:3] 0.2 0.3 0.2
    #>  $ !!        : chr "======================================================================================================="
    #>  $ !!        : chr "SOILS"
    #>  $ !!        : chr "__________"
    #>  $ !!        : chr "Soil Classes: 1=Fine soil 2=Coarse soil"
    #>  $ mperc1    : num [1:2] 20 25
    #>  $ mperc2    : num [1:2] 20 25
    #>  $ rrcs1     : num [1:2] 0.6 0.1
    #>  $ rrcs2     : num [1:2] 0.04 0.03
    #>  $ sfrost    : num [1:2] 1 1
    #>  $ srrate    : num [1:2] 0.05 0.025
    #>  $ trrcs     : num [1:2] 0.3 0.15
    #>  $ wcep      : num [1:2] 0.01 0.07
    #>  $ wcfc      : num [1:2] 0.15 0.15
    #>  $ wcwp      : num [1:2] 0.15 0.05
    #>  $ !!        : chr "======================================================================================================="
    #>  $ !!        : chr "WATER TEMPERATURE"
    #>  $ !!        : chr "__________"
    #>  $ upper2deep: num 2.5
    #>  $ tcfriver  : num 30
    #>  $ scfriver  : num 0.3
    #>  $ ccfriver  : num -0.3
    #>  $ lcfriver  : num -0.1
    #>  $ tcflake   : num 40
    #>  $ scflake   : num 0.7
    #>  $ ccflake   : num 0
    #>  $ lcflake   : num 0
    #>  $ stbcorr1  : num 0.4
    #>  $ stbcorr2  : num 0.25
    #>  $ stbcorr3  : num 0
    #>  $ !!        : chr "======================================================================================================="
    #>  $ !!        : chr "LAKE AND RIVER ICE"
    #>  $ !!        : chr "__________"
    #>  $ licewme   : num 0.1
    #>  $ licetf    : num 0
    #>  $ licesndens: num 0.0024
    #>  $ licekika  : num 10
    #>  $ licekexp  : num 1.88
    #>  $ licetmelt : num 1.25
    #>  $ licewcorr : num 0.5
    #>  $ !!        : chr "__________"
    #>  $ ricewme   : num 0.2
    #>  $ ricetf    : num 0
    #>  $ ricesndens: num 0.0024
    #>  $ ricekika  : num 10
    #>  $ ricekexp  : num 1.88
    #>  $ ricetmelt : num 1.25
    #>  $ !!        : chr "======================================================================================================="
    #>  $ !!        : chr "TRACERS:"
    #>  $ !!        : chr "____________________________________"
    #>  $ !!        : chr "GENERAL PARAMETERS"
    #>  $ !!        : num(0)
    #>  $ !!        : chr "Initial concentrations in soil and water"
    #>  $ init1     : num 0
    #>  $ init1sw   : num 0
    #>  $ !!        : chr "Evaporation, proportion of the tracer that follows evaporating water"
    #>  $ t1evap    : num 0
    #>  $ !!        : chr "____________________________________"
    #>  $ !!        : chr "Exponential decay, half life of the tracer in days"
    #>  $ t1expdec  : num 0
    #>  $ !!        : chr "____________________________________"
    #>  $ !!        : chr "Adsorption/desorption to/from soil; equilibrium concentration coefficients"
    #>  $ !!        : chr "(\"unit\" adsorbed to 1 kg of soil in one liter of soil water, U/kg soil)"
    #>  $ t1freuc   : num 0
    #>   [list output truncated]