@@ -22,7 +22,8 @@ |
import java.io.IOException; |
import java.text.SimpleDateFormat; |
import java.util.Calendar; |
-import java.util.Date; |
+import java.util.HashMap; |
+import java.util.Map; |
import java.util.logging.Level; |
import javax.ws.rs.Path; |
import static m.wrfhydro.V1_0.*; |
@@ -49,6 +50,60 @@ |
@Resource(file = "diag_hydro.* *stdout.txt *stderr.txt", type = OUTPUT) |
public class V1_0 extends ModelDataService { |
|
+ static final Map<String, String> def = new HashMap<String, String>() { |
+ private static final long serialVersionUID = 1L; |
+ |
+ |
+ { |
+ put("HRLDAS_SETUP_FILE", "./DOMAIN/wrfinput_d01.nc"); |
+ put("INDIR", "./FORCING"); |
+ put("SPATIAL_FILENAME", "./DOMAIN/soil_properties.nc"); |
+ put("OUTDIR", "./"); |
+ |
+ put("RESTART_FILENAME_REQUESTED", "RESTART/RESTART.2011082600_DOMAIN1"); |
+ |
+ put("DYNAMIC_VEG_OPTION", "4"); |
+ put("CANOPY_STOMATAL_RESISTANCE_OPTION", "1"); |
+ put("BTR_OPTION", "1"); |
+ put("RUNOFF_OPTION", "3"); |
+ put("SURFACE_DRAG_OPTION", "1"); |
+ put("FROZEN_SOIL_OPTION", "1"); |
+ put("SUPERCOOLED_WATER_OPTION", "1"); |
+ put("RADIATIVE_TRANSFER_OPTION", "3"); |
+ put("SNOW_ALBEDO_OPTION", "2"); |
+ put("PCP_PARTITION_OPTION", "1"); |
+ put("TBOT_OPTION", "2"); |
+ put("TEMP_TIME_SCHEME_OPTION", "3"); |
+ put("GLACIER_OPTION", "2"); |
+ put("SURFACE_RESISTANCE_OPTION", "4"); |
+ |
+ put("FORCING_TIMESTEP", "3600"); |
+ put("NOAH_TIMESTEP", "3600"); |
+ put("OUTPUT_TIMESTEP", "3600"); |
+ |
+ put("RESTART_FREQUENCY_HOURS", "24"); |
+ put("SPLIT_OUTPUT_COUNT", "1"); |
+ put("SOIL_THICK_INPUT_1", "0.10"); |
+ put("SOIL_THICK_INPUT_2", "0.30"); |
+ put("SOIL_THICK_INPUT_3", "0.60"); |
+ put("SOIL_THICK_INPUT_4", "1.00"); |
+ |
+ put("ZLVL", "10.0"); |
+ |
+ put("rst_bi_in", "0"); |
+ put("rst_bi_out", "0"); |
+ |
+ put("FORC_TYP", "1"); |
+ } |
+ }; |
+ |
+ public class Option { |
+ |
+ public String get(String option) throws ServiceException { |
+ return parameter().getString(option, def.get(option)); |
+ } |
+ } |
+ |
public static final String MPIRUN = "mpirun"; |
|
// in case the exe path needs adjustment. |
@@ -61,8 +116,6 @@ |
static final String NAMELIST_HRLDAS_VM = "m/wrfhydro/namelist.hrldas.vm"; |
static final String MPIRUN_NP = "mpirun.np"; |
|
- String outdir; |
- String indir; |
Calendar cal = Calendar.getInstance(); |
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm"); |
|
@@ -71,8 +124,6 @@ |
|
@Override |
protected void preProcess() throws Exception { |
- outdir = parameter().getString("OUTDIR", "./"); |
- indir = parameter().getString("INDIR", "./FORCING"); |
String start = parameter().getString("START", "2011-08-26 00:00"); |
cal.setTime(df.parse(start)); |
|
@@ -95,9 +146,7 @@ |
if (!new File(noahMP).exists()) { |
throw new ServiceException("Not found: " + noahMP); |
} |
- |
createNamelist(); |
- |
// allow for np configuration |
int np = metainfo().getInt(MPIRUN_NP, 2); |
np = Config.getInt(MPIRUN_NP, np); |
@@ -108,7 +157,6 @@ |
"-np", np, |
noahMP |
); |
- |
int ret = mpirun.exec(); |
if (ret != 0) { |
throw new ServiceException("Error running mpi wrf_hydro: " + ret); |
@@ -119,6 +167,7 @@ |
private String createNamelist() throws IOException { |
VelocityContext context = new VelocityContext(); |
context.put("service", this); |
+ context.put("option", new Option()); |
FileWriter w = new FileWriter(getWorkspaceFile(NAMELIST_HRLDAS)); |
velocity.getTemplate(NAMELIST_HRLDAS_VM, "utf-8").merge(context, w); |
w.close(); |
@@ -137,43 +186,32 @@ |
} |
|
|
- // public properties for velocity |
- public String getOutdir() { |
- return outdir; |
- } |
- |
- |
- public String getIndir() { |
- return indir; |
- } |
- |
- |
- public int getStartyear() { |
+ public int getSTART_YEAR() { |
return cal.get(Calendar.YEAR); |
} |
|
|
- public int getStartmonth() { |
+ public int getSTART_MONTH() { |
return cal.get(Calendar.MONTH) + 1; |
} |
|
|
- public int getStartday() { |
+ public int getSTART_DAY() { |
return cal.get(Calendar.DAY_OF_MONTH); |
} |
|
|
- public int getStarthour() { |
+ public int getSTART_HOUR() { |
return cal.get(Calendar.HOUR_OF_DAY); |
} |
|
|
- public int getStartmin() { |
+ public int getSTART_MIN() { |
return cal.get(Calendar.MINUTE); |
} |
|
|
- public String getkinfo() { |
+ public String getKINFO() { |
return kday_or_hour; |
} |
|
@@ -1,45 +1,45 @@ |
&NOAHLSM_OFFLINE |
|
-HRLDAS_SETUP_FILE = "./DOMAIN/wrfinput_d01.nc" |
-INDIR = "${service.indir}" |
-SPATIAL_FILENAME = "./DOMAIN/soil_properties.nc" |
-OUTDIR = "${service.outdir}" |
+HRLDAS_SETUP_FILE = "${option.HRLDAS_SETUP_FILE}" |
+INDIR = "${option.INDIR}" |
+SPATIAL_FILENAME = "${option.SPATIAL_FILENAME}" |
+OUTDIR = "${option.OUTDIR}" |
|
-START_YEAR = ${service.startyear} |
-START_MONTH = ${service.startmonth} |
-START_DAY = ${service.startday} |
-START_HOUR = ${service.starthour} |
-START_MIN = ${service.startmin} |
+START_YEAR = ${service.START_YEAR} |
+START_MONTH = ${service.START_MONTH} |
+START_DAY = ${service.START_DAY} |
+START_HOUR = ${service.START_HOUR} |
+START_MIN = ${service.START_MIN} |
|
-RESTART_FILENAME_REQUESTED = "RESTART/RESTART.2011082600_DOMAIN1" |
+RESTART_FILENAME_REQUESTED = "${option.RESTART_FILENAME_REQUESTED}" |
|
-${service.kinfo} |
+${service.KINFO} |
!KDAY = 7 |
! KHOUR = 8 |
|
-DYNAMIC_VEG_OPTION = 4 |
-CANOPY_STOMATAL_RESISTANCE_OPTION = 1 |
-BTR_OPTION = 1 |
-RUNOFF_OPTION = 3 |
-SURFACE_DRAG_OPTION = 1 |
-FROZEN_SOIL_OPTION = 1 |
-SUPERCOOLED_WATER_OPTION = 1 |
-RADIATIVE_TRANSFER_OPTION = 3 |
-SNOW_ALBEDO_OPTION = 2 |
-PCP_PARTITION_OPTION = 1 |
-TBOT_OPTION = 2 |
-TEMP_TIME_SCHEME_OPTION = 3 |
-GLACIER_OPTION = 2 |
-SURFACE_RESISTANCE_OPTION = 4 |
+DYNAMIC_VEG_OPTION = ${option.DYNAMIC_VEG_OPTION} |
+CANOPY_STOMATAL_RESISTANCE_OPTION = ${option.CANOPY_STOMATAL_RESISTANCE_OPTION} |
+BTR_OPTION = ${option.BTR_OPTION} |
+RUNOFF_OPTION = ${option.RUNOFF_OPTION} |
+SURFACE_DRAG_OPTION = ${option.SURFACE_DRAG_OPTION} |
+FROZEN_SOIL_OPTION = ${option.FROZEN_SOIL_OPTION} |
+SUPERCOOLED_WATER_OPTION = ${option.SUPERCOOLED_WATER_OPTION} |
+RADIATIVE_TRANSFER_OPTION = ${option.RADIATIVE_TRANSFER_OPTION} |
+SNOW_ALBEDO_OPTION = ${option.SNOW_ALBEDO_OPTION} |
+PCP_PARTITION_OPTION = ${option.PCP_PARTITION_OPTION} |
+TBOT_OPTION = ${option.TBOT_OPTION} |
+TEMP_TIME_SCHEME_OPTION = ${option.TEMP_TIME_SCHEME_OPTION} |
+GLACIER_OPTION = ${option.GLACIER_OPTION} |
+SURFACE_RESISTANCE_OPTION = ${option.SURFACE_RESISTANCE_OPTION} |
|
-FORCING_TIMESTEP = 3600 |
-NOAH_TIMESTEP = 3600 |
-OUTPUT_TIMESTEP = 3600 |
+FORCING_TIMESTEP = ${option.FORCING_TIMESTEP} |
+NOAH_TIMESTEP = ${option.NOAH_TIMESTEP} |
+OUTPUT_TIMESTEP = ${option.OUTPUT_TIMESTEP} |
|
-RESTART_FREQUENCY_HOURS = 24 |
+RESTART_FREQUENCY_HOURS = ${option.RESTART_FREQUENCY_HOURS} |
|
! Split output after split_output_count output times. |
-SPLIT_OUTPUT_COUNT = 1 |
+SPLIT_OUTPUT_COUNT = ${option.SPLIT_OUTPUT_COUNT} |
|
! XSTART = 1 |
! XEND = 1 |
@@ -47,16 +47,16 @@ |
! YEND = 1 |
|
NSOIL=4 |
-soil_thick_input(1) = 0.10 |
-soil_thick_input(2) = 0.30 |
-soil_thick_input(3) = 0.60 |
-soil_thick_input(4) = 1.00 |
+soil_thick_input(1) = ${option.SOIL_THICK_INPUT_1} |
+soil_thick_input(2) = ${option.SOIL_THICK_INPUT_2} |
+soil_thick_input(3) = ${option.SOIL_THICK_INPUT_3} |
+soil_thick_input(4) = ${option.SOIL_THICK_INPUT_4} |
|
-ZLVL = 10.0 |
+ZLVL = ${option.ZLVL} |
|
-rst_bi_in = 0 !0: use netcdf input restart file |
+rst_bi_in = ${option.rst_bi_in} !0: use netcdf input restart file |
!1: use parallel io for reading multiple restart files (1 per core) |
-rst_bi_out = 0 !0: use netcdf output restart file |
+rst_bi_out = ${option.rst_bi_out} !0: use netcdf output restart file |
!1: use parallel io for outputting multiple restart files (1 per core) |
|
/ |
@@ -65,7 +65,7 @@ |
|
! Specification of forcing data: 1=HRLDAS-hr format, 2=HRLDAS-min format, 3=WRF, |
! 4=Idealized, 5=Ideal w/ Spec.Precip., 6=HRLDAS-hrl y fomat w/ Spec. Precip, |
-FORC_TYP = 1 |
+FORC_TYP = ${option.FORC_TYP} |
|
/ |
|