# Modify a HYPE Parameter File

## Setup

Load HYPEtools Package and Import Files

    # Load Package
    library(HYPEtools)

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

    # Import HYPE Model Files
    gd <- ReadGeoData(file.path(model_path, "GeoData.txt"))
    gcl <- ReadGeoClass(file.path(model_path, "GeoClass.txt"))
    prf <- ReadPar(file.path(model_path, "par.txt"), encoding = "latin1")

## Import Checks

    # Exaimine parameter structure
    str(prf)
    #> List of 57
    #>  $ !!       : chr "Parameter Values"
    #>  $ !!       : num(0)
    #>  $ !!       : chr "General"
    #>  $ cevpam   : num 0.25
    #>  $ cevpph   : num 67.5
    #>  $ damp     : num 0.5
    #>  $ 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
    #>  $ !!       : num(0)
    #>  $ !!       : chr "Landuses 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
    #>  $ ttmp     : num [1:3] 0.2 0.3 0.2
    #>  $ !!       : num(0)
    #>  $ !!       : chr "Soils 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
    #>  $ wcep1    : num [1:2] 0.01 0.07
    #>  $ wcep2    : num [1:2] 0.01 0.0595
    #>  $ wcep3    : num [1:2] 0.01 0.049
    #>  $ wcfc1    : num [1:2] 0.15 0.15
    #>  $ wcfc2    : num [1:2] 0.15 0.15
    #>  $ wcfc3    : num [1:2] 0.15 0.15
    #>  $ wcwp1    : num [1:2] 0.15 0.05
    #>  $ wcwp2    : num [1:2] 0.15 0.05
    #>  $ wcwp3    : num [1:2] 0.15 0.05
    #>  $ !!       : num(0)
    #>  $ !!       : chr "PARREG 1"
    #>  $ preccorr : num -0.24
    #>  $ cevpcorr : num -0.29
    #>  $ tempcorr : num -0.4
    #>  $ ratcorr  : num -0.813
    #>  $ rrcscorr : num -0.79

    # Display without the comment items
    prf[sapply(prf, function(x) is.numeric(x) & length(x) > 0)]
    #> $cevpam
    #> [1] 0.25
    #>
    #> $cevpph
    #> [1] 67.5
    #>
    #> $damp
    #> [1] 0.5
    #>
    #> $epotdist
    #> [1] 3
    #>
    #> $gldepi
    #> [1] 3.6
    #>
    #> $grata
    #> [1] 0.6
    #>
    #> $gratk
    #> [1] 0.283
    #>
    #> $gratp
    #> [1] 2
    #>
    #> $lp
    #> [1] 0.95
    #>
    #> $qmean
    #> [1] 200
    #>
    #> $rcgrw
    #> [1] 0
    #>
    #> $rivvel
    #> [1] 1
    #>
    #> $rrcs3
    #> [1] 2e-04
    #>
    #> $sdnsnew
    #> [1] 0.09
    #>
    #> $sdnsmax
    #> [1] 0.5
    #>
    #> $sdnsrate
    #> [1] 0.015
    #>
    #> $sdnsradd
    #> [1] 0.026
    #>
    #> $tcalt
    #> [1] 0.6
    #>
    #> $ttpi
    #> [1] 3
    #>
    #> $pcelevth
    #> [1] 500
    #>
    #> $pcelevadd
    #> [1] 0.04
    #>
    #> $pcelevmax
    #> [1] 0.04
    #>
    #> $cevp
    #> [1] 0.175 0.220 0.215
    #>
    #> $cmlt
    #> [1] 2.8 1.9 3.5
    #>
    #> $frost
    #> [1] 2 2 2
    #>
    #> $srrcs
    #> [1] 0.4 0.2 0.3
    #>
    #> $ttmp
    #> [1] 0.2 0.3 0.2
    #>
    #> $mperc1
    #> [1] 20 25
    #>
    #> $mperc2
    #> [1] 20 25
    #>
    #> $rrcs1
    #> [1] 0.6 0.1
    #>
    #> $rrcs2
    #> [1] 0.04 0.03
    #>
    #> $sfrost
    #> [1] 1 1
    #>
    #> $srrate
    #> [1] 0.050 0.025
    #>
    #> $trrcs
    #> [1] 0.30 0.15
    #>
    #> $wcep1
    #> [1] 0.01 0.07
    #>
    #> $wcep2
    #> [1] 0.0100 0.0595
    #>
    #> $wcep3
    #> [1] 0.010 0.049
    #>
    #> $wcfc1
    #> [1] 0.15 0.15
    #>
    #> $wcfc2
    #> [1] 0.15 0.15
    #>
    #> $wcfc3
    #> [1] 0.15 0.15
    #>
    #> $wcwp1
    #> [1] 0.15 0.05
    #>
    #> $wcwp2
    #> [1] 0.15 0.05
    #>
    #> $wcwp3
    #> [1] 0.15 0.05
    #>
    #> $preccorr
    #> [1] -0.24
    #>
    #> $cevpcorr
    #> [1] -0.29
    #>
    #> $tempcorr
    #> [1] -0.4
    #>
    #> $ratcorr
    #> [1] -0.813
    #>
    #> $rrcscorr
    #> [1] -0.79

    # Show values for a parameter "rrcs1" - Note it has 2 values, i.e. it is soil-dependent
    prf$rrcs1
    #> [1] 0.6 0.1

## Update Model Parameters by a Constant Fraction

Here we increase the “cmlt” parameter by 50% (i.e. multiply the original value by 1.5)

    # Fraction by which the original value will by multiplied
    mult <- 1.5

    # Display the current values (3, i.e. landuse-dependent)
    prf$cmlt
    #> [1] 2.8 1.9 3.5

    # Create a new paramater list
    prf.150 <- prf

    # Multiply by a specified fraction and display again
    prf.150$cmlt <- prf$cmlt * mult
    prf.150$cmlt
    #> [1] 4.20 2.85 5.25

## Update Model Parameters by a Constant Fraction for a Selected Land Use Group

Here we increase the “cmlt” parameter by 50%, but only for SLCs with “Forest” as a land use.

    # Forest is Land Use Class 2
    comment(gcl)
    #> [1] "!Landuses: 1=Water; 2=Coniferous forest; 3=Agricultural land\t\t\t\t\t\t\t\t\t\t\t\t\t"
    #> [2] "!Soils: 1=Fine soil; 2=Coarse soil\t\t\t\t\t\t\t\t\t\t\t\t\t"
    #> [3] "!Combination\tLanduse\tSoil\tCropid-main\tCropid-2nd\tRotation\tVegetationstyp\tSpecial-class\tTile-depth\tDrain-depth\t#Soil-layers\tDepth1\tDepth2\tDepth3"

    # Specify multiplication factors
    mult <- c(1, 1.5, 1)

    # Create a new parameter list
    prf.150.for <- prf

    # Multiply values for the selected landuse by a specified fraction and display again
    prf.150.for$cmlt <- prf$cmlt * mult
    prf.150.for$cmlt
    #> [1] 2.80 2.85 3.50

    # See a ratio of the new vs. the original parameters
    prf.150.for$cmlt / prf$cmlt
    #> [1] 1.0 1.5 1.0