270de7a3 by Nathan Lighthart

Merge branch 'feature/UPGM' into develop

2 parents 398481c8 d3f3a75f
......@@ -29,6 +29,7 @@ import annotations.Status;
import annotations.Author;
import annotations.Documentation;
import annotations.Keywords;
import com.sun.jna.ptr.IntByReference;
import gov.usda.jcf.annotations.Input;
import gov.usda.jcf.annotations.Description;
......@@ -52,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")
......@@ -75,13 +79,19 @@ public class JupgmInitGen {
@Description("Upgm_mgmt.dat file")
@Input public String shootoutfile;
@Description("HRU ID")
@Input
public int hruid;
public nap.Libupgm lib;
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(),
......
......@@ -21,6 +21,7 @@
package upgm;
import ages.types.SoilType;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import crop.Crop;
......@@ -32,15 +33,12 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDate;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Upgm {
private static double acycon = 10000.0;
private static final Path tempLibDir;
private static final Lock initLock = new ReentrantLock();
static {
Path tempDir;
......@@ -60,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;
......@@ -164,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();
......@@ -176,15 +179,12 @@ public class Upgm {
Jupgminit.phenoloutfile = outParent.resolve("phenol" + idString + ".out").toString();
Jupgminit.seasonoutfile = outParent.resolve("season" + idString + ".out").toString();
Jupgminit.shootoutfile = outParent.resolve("shoot" + idString + ".out").toString();
Jupgminit.hruid = hruID;
initLock.lock();
try {
Jupgminit.exec();
} catch (Exception ex) {
Logger.getLogger(Upgm.class.getName()).log(Level.SEVERE, null, ex);
return;
} finally {
initLock.unlock();
}
}
......@@ -271,7 +271,6 @@ public class Upgm {
String libName = "upgm" + hruID;
NativeLibrary.addSearchPath(libName, tempLibDir.toString());
lib = (nap.Libupgm) Native.loadLibrary(libName, nap.Libupgm.class);
lib = (nap.Libupgm) Native.synchronizedLibrary(lib);
Jupgm.lib = lib;
Jupgminit.lib = lib;
......@@ -367,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;
......
......@@ -2,6 +2,8 @@ subroutine cdbug(isr,slay)
!
implicit none
!
include 'file.fi'
include 'p1werm.inc'
include 'm1flag.inc'
include 's1layr.inc'
......@@ -84,40 +86,40 @@ call caldatw(cd,cm,cy)
! write weather cligen and windgen variables
if ((cd==tday).and.(cm==tmo).and.(cy==tyr).and.(isr==tisr)) then
write (27,1000) cd,cm,cy,isr
write (cdbugfile,1000) cd,cm,cy,isr
else
write (27,1100) cd,cm,cy,isr
write (cdbugfile,1100) cd,cm,cy,isr
end if
write (27,1200)
write (27,1300) awzdpt,awtdmx,awtdmn,aweirr,awudmx,awudmn,awtdpt,awadir,awhrmx, &
write (cdbugfile,1200)
write (cdbugfile,1300) awzdpt,awtdmx,awtdmn,aweirr,awudmx,awudmn,awtdpt,awadir,awhrmx, &
& awrrh
! write(27,2045) isr
write (27,1400) isr,isr,isr,isr,isr,isr,isr
write (cdbugfile,1400) isr,isr,isr,isr,isr,isr,isr
! admf(isr) is not dimensioned correctly anymore - lew 04/23/99
! just commenting it out for now since it is a debug routine
! write(27,2051) amrslp(isr), acftcv(isr), acrlai(isr), aczrtd(isr),
! & admf(isr), ahfwsf(isr), ac0nam(isr)
write (27,1600) isr,isr,isr,isr
write (27,1700) actdtm(isr),acthucum(isr),acmst(isr),acmrt(isr),ahzeta,ahzetp, &
write (cdbugfile,1600) isr,isr,isr,isr
write (cdbugfile,1700) actdtm(isr),acthucum(isr),acmst(isr),acmrt(isr),ahzeta,ahzetp, &
& ahzpta
! write (27,1800) isr,isr,isr,isr
write (27,1800) isr,isr,isr
!write (27,1900) ahzea,ahzep,ahzptp,actmin(isr),actopt(isr),as0rrk(isr), &
! write (cdbugfile,1800) isr,isr,isr,isr
write (cdbugfile,1800) isr,isr,isr
!write (cdbugfile,1900) ahzea,ahzep,ahzptp,actmin(isr),actopt(isr),as0rrk(isr), &
! & aslrr(isr)
write (27,1900) ahzea,ahzep,ahzptp,actmin(isr),actopt(isr),as0rrk(isr)
write (27,2000)
write (cdbugfile,1900) ahzea,ahzep,ahzptp,actmin(isr),actopt(isr),as0rrk(isr)
write (cdbugfile,2000)
do l = 1,slay
write (27,2100) l,aszlyt(l,isr),ahrsk(l,isr),ahrwc(l,isr),ahrwcs(l,isr), &
write (cdbugfile,2100) l,aszlyt(l,isr),ahrsk(l,isr),ahrwc(l,isr),ahrwcs(l,isr), &
& ahrwca(l,isr),ahrwcf(l,isr),ahrwcw(l,isr),ah0cb(l,isr), &
& aheaep(l,isr),ahtsmx(l,isr),ahtsmn(l,isr)
end do
write (27,2200)
write (cdbugfile,2200)
do l = 1,slay
write (27,2300) l,asfsan(l,isr),asfsil(l,isr),asfcla(l,isr),asfom(l,isr), &
write (cdbugfile,2300) l,asfsan(l,isr),asfsil(l,isr),asfcla(l,isr),asfom(l,isr), &
& asdblk(l,isr),aslagm(l,isr),as0ags(l,isr),aslagn(l,isr), &
& aslagx(l,isr),aseags(l,isr)
end do
......
......@@ -41,6 +41,7 @@ subroutine cinit(bnslay,bszlyt,bszlyd,bsdblk,bsfcce,bsfcec,bsfsmb,bsfom,bsfcla,
!
implicit none
!
include 'file.fi'
include 'p1werm.inc'
include 'p1solar.inc'
include 'm1flag.inc'
......@@ -646,7 +647,7 @@ else
end if
! print out heat average heat unit and days to maturity
if (am0cfl>0) write (60,1100) pdate,hdate,bcthudf,dtm,bctdtm,phu,bcthum
if (am0cfl>0) write (luoinpt,1100) pdate,hdate,bcthudf,dtm,bctdtm,phu,bcthum
! after printing the value, set the global parameter for maximum
! heat units to the new calculated value (this database value is
......
......@@ -90,15 +90,15 @@ if (icli==1) then ! read from cligen data file
!
else ! read in historical data
!debe add reading in climate file name
read (7,*) cliname
read (upgmcli,*) cliname
!
! read monthy average of daily maximum temperature
!
read (7,*) (awtmxav(idx),idx=1,12)
read (upgmcli,*) (awtmxav(idx),idx=1,12)
!
! read monthy average of daily minimum temperature
!
read (7,*) (awtmnav(idx),idx=1,12)
read (upgmcli,*) (awtmnav(idx),idx=1,12)
!
! find yearly average temperature
!
......@@ -116,7 +116,7 @@ else ! read in historical data
!debe i think the above comment should read: "read average monthly
! total precipitation"
!
read (7,*) (awzmpt(idx),idx=1,12)
read (upgmcli,*) (awzmpt(idx),idx=1,12)
!
end if
!
......
......@@ -92,7 +92,7 @@ data dayidx/0/
if (icli==0) then ! read in historical precip, tmax, tmin, and solar radiation
! if ((ccd.eq.29).and.(ccm.eq.2)) then
! dayidx = ccd
! read (7,*) wcd(dayidx),wcm(dayidx),wcy(dayidx),wwzdpt(dayidx),wwtdmx(dayidx), &
! read (upgmcli,*) wcd(dayidx),wcm(dayidx),wcy(dayidx),wwzdpt(dayidx),wwtdmx(dayidx), &
! & wwtdmn(dayidx),wgrad(dayidx)
!
! ccd = 1
......@@ -102,18 +102,18 @@ if (icli==0) then ! read in historical precip, tmax, tmin, and solar radiatio
dayidx = ccd
!
read (7,*) wcd(dayidx),wcm(dayidx),wcy(dayidx),wwzdpt(dayidx),wwtdmx(dayidx), &
read (upgmcli,*) wcd(dayidx),wcm(dayidx),wcy(dayidx),wwzdpt(dayidx),wwtdmx(dayidx), &
& wwtdmn(dayidx),wgrad(dayidx)
! print*, ' in if statement checking for leap year'
if ((wcd(dayidx)==29).and.(wcm(dayidx)==2)) read (7,*) wcd(dayidx),wcm(dayidx)&
if ((wcd(dayidx)==29).and.(wcm(dayidx)==2)) read (upgmcli,*) wcd(dayidx),wcm(dayidx)&
& ,wcy(dayidx),wwzdpt(dayidx),wwtdmx(dayidx),wwtdmn(dayidx),wgrad(dayidx)
! if ((wcm(dayidx).lt.4).and.(wcy(dayidx).eq.2)) then
! print*, 'day= ', wcd(dayidx), 'month= ', wcm(dayidx), 'tmax= ', wwtdmx(dayidx)
! endif
!
! read (7,*) wcd(dayidx),wcm(dayidx),wcy(dayidx), &
! read (upgmcli,*) wcd(dayidx),wcm(dayidx),wcy(dayidx), &
! & wwzdpt(dayidx),wwdurpt(dayidx),wwpeaktpt(dayidx) &
! & ,wwpeakipt(dayidx),wwtdmx(dayidx),wwtdmn(dayidx) &
! & ,wgrad(dayidx),dummy,dummy,wwtdpt(dayidx)
......
......@@ -3,169 +3,192 @@
!$Revision: 1.25 $
!$Source: /weru/cvs/weps/weps.src/inc/file.fi,v $
!
integer lui1
parameter (lui1=141)
!
integer lui2
parameter (lui2=102)
!
integer lui3
parameter (lui3=103)
!
integer lui4
parameter (lui4=104)
!
integer lui5
parameter (lui5=105)
!
integer luicli
parameter (luicli=146)
!
integer luiwin
parameter (luiwin=147)
!
integer luiwsd
parameter (luiwsd=148)
! Roger Marquez - > these files are not used as far as I can tell.
! integer lui1
! parameter (lui1=141)
!!
! integer lui2
! parameter (lui2=102)
!!
! integer lui3
! parameter (lui3=103)
!!
! integer lui4
! parameter (lui4=104)
!!
! integer lui5
! parameter (lui5=105)
!Logical Unit number for "mandate.man" (MCREW management) file
integer luimandate
parameter (luimandate=149)
!
integer luo1
parameter (luo1=111)
!
integer luo2
parameter (luo2=112)
!
integer luo3
parameter (luo3=113)
!
integer luo4
parameter (luo4=114)
!
integer luo5
parameter (luo5=115)
!
integer luolog
parameter (luolog=116)
!
integer luodbg
parameter (luodbg=117)
!
integer luoplt
parameter (luoplt=118)
integer luicli
! parameter (luicli=146)
!
! ! Roger Marquez - > not used as far as I can tell.
! integer luiwin
! parameter (luiwin=147)
!!
! integer luiwsd
! parameter (luiwsd=148)
!
! !Logical Unit number for "mandate.man" (MCREW management) file
! integer luimandate
! parameter (luimandate=149)
!!
! integer luo1
! parameter (luo1=111)
!!
! integer luo2
! parameter (luo2=112)
!!
! integer luo3
! parameter (luo3=113)
!!
! integer luo4
! parameter (luo4=114)
!!
! integer luo5
! parameter (luo5=115)
!!
! integer luolog
! parameter (luolog=116)
!!
! integer luodbg
! parameter (luodbg=117)
!!
! integer luoplt
! parameter (luoplt=118)
! these are for debugging the crop and decomp biomass variables - LEW
integer luocrop
parameter (luocrop=17)
! parameter (luocrop=17)
integer luoshoot
parameter (luoshoot=62)
! parameter (luoshoot=62)
integer luoseason
parameter (luoseason=59)
! parameter (luoseason=59)
integer luoinpt
parameter (luoinpt=60)
! parameter (luoinpt=60)
integer luoallcrop
parameter (luoallcrop=61)
!parameter (luoallcrop=61)
! debe 090408 added for emergence output
integer luoemerge
parameter (luoemerge=63)
! parameter (luoemerge=63)
!
! debe 091108 added for phenology output
integer luophenol
parameter (luophenol=64)
! parameter (luophenol=64)
!
! debe 033111 added for canopy height output
integer luocanopyht
parameter (luocanopyht=65)
!
integer luod_above !Above ground decomp output
parameter (luod_above=18)
!
integer luod_below !Below ground decomp output
parameter (luod_below=19)
! parameter (luocanopyht=65)
! RMarquez - Added these files as input file handles to be initialized by "init" subroutines.
integer cropxml
integer upgmmgt
integer upgmstress
integer upgmcli
integer upgmcrop
integer upgmco2
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, soilprofile
!
!Roger Marquez - > not used as far as I can tell.
! integer luod_above !Above ground decomp output
! parameter (luod_above=18)
!!
! integer luod_below !Below ground decomp output
! parameter (luod_below=19)
!!
! integer luocrp1
! parameter (luocrp1=121)
!!
! integer luodec1
! parameter (luodec1=122)
!!
! integer luodec2
! parameter (luodec2=123)
!!
! integer luodec3
! parameter (luodec3=124)
!!
! integer luobio1
! parameter (luobio1=125)
!
! ! logical unit number for soil conditioning index out files
! integer luosci
! parameter (luosci=153)
! integer luostir
! parameter (luostir=154)
!
!! these are for debugging the hydrology variables
!
! integer luohydro
! parameter (luohydro=151)
!
! integer luohlayers
! parameter (luohlayers=152)
!
! integer luowater
! parameter (luowater=12)
! new output units for general information
! integer luoharvest_si
! parameter (luoharvest_si=126)
! integer luoharvest_en
! parameter (luoharvest_en=127)
!
integer luocrp1
parameter (luocrp1=121)
! integer luohydrobal
! parameter (luohydrobal=129)
!
integer luodec1
parameter (luodec1=122)
!! new output unit for calibration information
! integer luoharvest_calib
! parameter (luoharvest_calib=130)
!
integer luodec2
parameter (luodec2=123)
!! new output unit for GUI required calibration information
! integer luoharvest_calib_parm
! parameter (luoharvest_calib_parm=131)
!
integer luodec3
parameter (luodec3=124)
! !Logical Unit number for "gui1_data.out" file
! integer luogui1
! parameter (luogui1=52)
!
integer luobio1
parameter (luobio1=125)
! logical unit number for soil conditioning index out files
integer luosci
parameter (luosci=153)
integer luostir
parameter (luostir=154)
! these are for debugging the hydrology variables
integer luohydro
parameter (luohydro=151)
integer luohlayers
parameter (luohlayers=152)
integer luowater
parameter (luowater=12)
! new output units for general information
integer luoharvest_si
parameter (luoharvest_si=126)
integer luoharvest_en
parameter (luoharvest_en=127)
integer luohydrobal
parameter (luohydrobal=129)
! new output unit for calibration information
integer luoharvest_calib
parameter (luoharvest_calib=130)
! new output unit for GUI required calibration information
integer luoharvest_calib_parm
parameter (luoharvest_calib_parm=131)
!Logical Unit number for "gui1_data.out" file
integer luogui1
parameter (luogui1=52)
!Logical Unit number for "mandate.out" file
integer luomandate
parameter (luomandate=81)
! !Logical Unit number for "mandate.out" file
! integer luomandate
! parameter (luomandate=81)
! New output units for erosion submodel
integer luo_egrd ! For daily grid output
parameter (luo_egrd=201)
integer luo_erod ! For daily erosion summary output
parameter (luo_erod=202)
integer luo_emit ! For subdaily erosion summary output
parameter (luo_emit=203)
integer luo_sgrd ! For subdaily grid output
parameter (luo_sgrd=204)
! Logical Unit number for "soilsurf.out" file
integer luosoilsurf
parameter (luosoilsurf=160)
! Logical Unit number for "soilsurf.out" file
integer luosoillay
parameter (luosoillay=161)
!
!integer luo_egrd ! For daily grid output
!parameter (luo_egrd=201)
!integer luo_erod ! For daily erosion summary output
!parameter (luo_erod=202)
!integer luo_emit ! For subdaily erosion summary output
!parameter (luo_emit=203)
!integer luo_sgrd ! For subdaily grid output
!parameter (luo_sgrd=204)
!
!! Logical Unit number for "soilsurf.out" file
!integer luosoilsurf
!parameter (luosoilsurf=160)
!
!! Logical Unit number for "soilsurf.out" file
!integer luosoillay
!parameter (luosoillay=161)
! Note: One must check main/openfils.for to ensure unit numbers are unique.
! Not all files are using logical unit numbers yet.
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!