d3f3a75f by Roger Marquez

Added Soil Depth Profile File to UPGM

- Added profile soil depths as input to UPGM.
- New file replaces assumed maximum layer of 1 and depth of 1 meter. This was causing issues with maximum rooting depth calculations.
1 parent b7079e70
......@@ -53,6 +53,9 @@ public class JupgmInitGen {
@Input public String upgmmgmtfile;
@Description("Upgm_mgmt.dat file")
@Input public String upgmsoilfile;
@Description("Upgm_mgmt.dat file")
@Input public String canopyhtoutfile;
@Description("Upgm_mgmt.dat file")
......@@ -84,9 +87,11 @@ public class JupgmInitGen {
public void exec() throws Exception {
lib.jupgminit_(
new IntByReference(hruid),
cropxmlfile, cropxmlfile.length(),
upgmcropfile, upgmcropfile.length(),
upgmmgmtfile, upgmmgmtfile.length(),
upgmsoilfile, upgmsoilfile.length(),
canopyhtoutfile, canopyhtoutfile.length(),
cdbugoutfile, cdbugoutfile.length(),
cropoutfile, cropoutfile.length(),
......@@ -94,7 +99,6 @@ public class JupgmInitGen {
inptoutfile, inptoutfile.length(),
phenoloutfile, phenoloutfile.length(),
seasonoutfile, seasonoutfile.length(),
shootoutfile, shootoutfile.length(),
new IntByReference(hruid));
shootoutfile, shootoutfile.length());
}
}
......
......@@ -21,6 +21,7 @@
package upgm;
import ages.types.SoilType;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import crop.Crop;
......@@ -57,6 +58,7 @@ public class Upgm {
public double co2;
public int hruID;
public Crop crop;
public SoilType soil;
public boolean plantExisting;
public boolean doHarvest;
public double tmin;
......@@ -161,9 +163,13 @@ public class Upgm {
Path upgmMgmt = outParent.resolve("Upgm_mgmt" + idString + ".dat");
writeUpgmManagement(upgmMgmt);
Path upgmSoil = outParent.resolve("upgm_soil_profile" + idString + ".dat");
writeUpgmSoil(upgmSoil);
Jupgminit.cropxmlfile = cropXML.toString();
Jupgminit.upgmcropfile = upgmCrop.toString();
Jupgminit.upgmmgmtfile = upgmMgmt.toString();
Jupgminit.upgmsoilfile = upgmSoil.toString();
Jupgminit.canopyhtoutfile = outParent.resolve("canopyht" + idString + ".out").toString();
Jupgminit.cdbugoutfile = outParent.resolve("cdbug" + idString + ".out").toString();
......@@ -360,6 +366,16 @@ public class Upgm {
}
}
private void writeUpgmSoil(Path path) {
try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(path, Charset.defaultCharset()))) {
for (double d : soil.depth_h) {
writer.println(d * 10); // convert cm to mm
}
} catch (IOException ex) {
Logger.getLogger(Upgm.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void reset() {
BioAct = 0;
BioagAct = 0;
......
......@@ -22,6 +22,7 @@
package upgm;
import ages.types.HRU;
import ages.types.SoilType;
import annotations.Author;
import annotations.Bibliography;
import annotations.Documentation;
......@@ -71,6 +72,9 @@ public class UpgmAdapter extends AnnotatedAdapter {
@Description("Current Crop")
@Input public Crop crop;
@Description("Current Soil")
@Input public SoilType soil;
@Description("flag for crop existence")
@Input public boolean cropExists;
......@@ -163,6 +167,7 @@ public class UpgmAdapter extends AnnotatedAdapter {
component.co2 = co2;
component.hruID = hru.ID;
component.crop = crop;
component.soil = soil;
component.plantExisting = cropExists;
component.doHarvest = doHarvest();
component.tmin = tmin;
......
......@@ -98,12 +98,12 @@
integer upgmco2atmos
! output for debugging
integer cdbugfile
integer soilprofile
common /filehandles/ cropxml, luicli, upgmmgt, upgmstress, & !Input file handles
& upgmcli, upgmcrop, upgmco2, upgmco2atmos, & !Input file handles
& luocrop, luoshoot, luoseason, luoinpt, luoemerge, luophenol, & !Output file handles
& luocanopyht, luoallcrop, cdbugfile
& luocanopyht, luoallcrop, cdbugfile, soilprofile
!
!Roger Marquez - > not used as far as I can tell.
......
......@@ -28,12 +28,13 @@
! Documentation ("src/upgm/Upgm.xml")
! @Execute
subroutine jupgminit(cropxmlfile,cropxmlfile_len,upgmcropfile, &
& upgmcropfile_len,upgmmgmtfile,upgmmgmtfile_len,canopyhtoutfile, &
subroutine jupgminit(hruID, cropxmlfile,cropxmlfile_len,upgmcropfile, &
& upgmcropfile_len,upgmmgmtfile,upgmmgmtfile_len, &
& upgmsoilfile,upgmsoilfile_len,canopyhtoutfile, &
& canopyhtoutfile_len,cdbugoutfile,cdbugoutfile_len,cropoutfile, &
& cropoutfile_len,emergeoutfile,emergeoutfile_len,inptoutfile, &
& inptoutfile_len,phenoloutfile,phenoloutfile_len,seasonoutfile, &
& seasonoutfile_len,shootoutfile,shootoutfile_len, hruID)
& seasonoutfile_len,shootoutfile,shootoutfile_len)
use, intrinsic :: ISO_C_BINDING
implicit none
......@@ -67,68 +68,74 @@ subroutine jupgminit(cropxmlfile,cropxmlfile_len,upgmcropfile, &
include 'upgmmain.inc'
integer(C_INT), value, intent(in) :: cropxmlfile_len
! @Description("HRU ID")
! @In
integer(C_INT) :: hruID
integer(C_INT), value, intent(in) :: cropxmlfile_len
! @Description("Cropxml.dat file")
! @In
character(kind=C_CHAR, len=cropxmlfile_len) :: cropxmlfile
integer(C_INT), value, intent(in) :: upgmcropfile_len
integer(C_INT), value, intent(in) :: upgmcropfile_len
! @Description("Upgm_crop.dat file")
! @In
character(kind=C_CHAR, len=upgmcropfile_len) :: upgmcropfile
integer(C_INT), value, intent(in) :: upgmmgmtfile_len
integer(C_INT), value, intent(in) :: upgmmgmtfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=upgmmgmtfile_len) :: upgmmgmtfile
integer(C_INT), value, intent(in) :: canopyhtoutfile_len
integer(C_INT), value, intent(in) :: upgmsoilfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=upgmsoilfile_len) :: upgmsoilfile
integer(C_INT), value, intent(in) :: canopyhtoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=canopyhtoutfile_len) :: canopyhtoutfile
integer(C_INT), value, intent(in) :: cdbugoutfile_len
integer(C_INT), value, intent(in) :: cdbugoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=cdbugoutfile_len) :: cdbugoutfile
integer(C_INT), value, intent(in) :: cropoutfile_len
integer(C_INT), value, intent(in) :: cropoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=cropoutfile_len) :: cropoutfile
integer(C_INT), value, intent(in) :: emergeoutfile_len
integer(C_INT), value, intent(in) :: emergeoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=emergeoutfile_len) :: emergeoutfile
integer(C_INT), value, intent(in) :: inptoutfile_len
integer(C_INT), value, intent(in) :: inptoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=inptoutfile_len) :: inptoutfile
integer(C_INT), value, intent(in) :: phenoloutfile_len
integer(C_INT), value, intent(in) :: phenoloutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=phenoloutfile_len) :: phenoloutfile
integer(C_INT), value, intent(in) :: seasonoutfile_len
integer(C_INT), value, intent(in) :: seasonoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=seasonoutfile_len) :: seasonoutfile
integer(C_INT), value, intent(in) :: shootoutfile_len
integer(C_INT), value, intent(in) :: shootoutfile_len
! @Description("Upgm_mgmt.dat file")
! @In
character(kind=C_CHAR, len=shootoutfile_len) :: shootoutfile
! @Description("HRU ID")
! @In
integer(C_INT) :: hruID
integer :: phenolfilehandle
!Rmarquez 2.10.17 -> Added new variables for soil profile information
double precision :: current_depth = 0
integer :: max_depth = 1
integer :: io = 0
!
! Method
!
......@@ -151,7 +158,9 @@ subroutine jupgminit(cropxmlfile,cropxmlfile_len,upgmcropfile, &
luocanopyht = 140000 + hruID
luoallcrop = 150000 + hruID
cdbugfile = 160000 + hruID
!Rmarquez 2.10.17 -> added new offset value
soilprofile = 180000 + hruID
row = 4
i = 0
elrate = 0.0
......@@ -172,6 +181,8 @@ subroutine jupgminit(cropxmlfile,cropxmlfile_len,upgmcropfile, &
!call fopenk(upgmstress,'upgm_stress.dat','old') ! open water stress file
!call fopenk(upgmcli,'upgm_cli.dat','old') ! open historical climate file
call fopenk(upgmcrop,upgmcropfile,'old') ! open upgm crop file
!Rmarquez 2.10.17 -> added new profile file
call fopenk(soilprofile, upgmsoilfile, 'old') ! open soil profile file to initialize profile
!
!debe added these variables to be initialized. added canopyflg for determining
! which method of calculating canopy height will be used. added dayhtinc to get
......@@ -204,16 +215,43 @@ subroutine jupgminit(cropxmlfile,cropxmlfile_len,upgmcropfile, &
!debe turned it on
acxrow(1) = 0.76 ! row spacing (m)
ahfwsf(1) = 1.0 ! water stress factor
!
! number of soil layers
!
nslay(1) = 1
!Rmarquez 2.10.17 -> Added read code for the new soil layer profile file.
! intent: provide actual profile layer data (depth, thickness) for the weps/upgm code
!
!set thickness and depth of first layer (defaulting to a value deeper than
! roots will reach)
!
aszlyt(1,1) = 1000.0
aszlyd(1,1) = 1000.0
max_depth = 0
do
! start max depth at 1
max_depth = max_depth + 1
read (soilprofile, *, IOSTAT=io) aszlyt(max_depth,1)
if (io > 0) then
! error, exit
exit
else if (io < 0) then
! eof, exit
exit
else
! thickness for layer max_depth read in,
! accumulate into current_depth
current_depth = current_depth + aszlyt(max_depth, 1)
! set depth for max_depth to be current_depth
aszlyd(max_depth, 1) = current_depth
end if
enddo
!
!aszlyt(1,1) = 1000.0
!aszlyd(1,1) = 1000.0
!
!Rmarquez 2.10.17 -> updated # layers to actual value read from new file.
!
! number of soil layers
!
nslay(1) = max_depth - 1 !Overshoot by 1 in read soil profile loop
!nslay(1) = 1
!
! assign values to some soil layer properties
!
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!