@@ -20,6 +20,9 @@ |
import java.io.File; |
import java.io.FileWriter; |
import java.io.IOException; |
+import java.text.SimpleDateFormat; |
+import java.util.Calendar; |
+import java.util.Date; |
import java.util.logging.Level; |
import javax.ws.rs.Path; |
import static m.wrfhydro.V1_0.*; |
@@ -34,9 +37,9 @@ |
* @author od |
*/ |
@Name("WRF-Hydro") |
-@Description("WRF-Hydro is a model for flash flood prediction, regional hydroclimate impacts " |
- + "assessment, seasonal forecasting of water resources, and " |
- + "land-atmosphere coupling studies.") |
+@Description("WRF-Hydro is a model for flash flood prediction, " |
+ + "regional hydroclimate impacts assessment, seasonal forecasting " |
+ + "of water resources, and land-atmosphere coupling studies.") |
@Documentation("https://ral.ucar.edu/projects/wrf_hydro/overview") |
@State(State.STABLE) |
@VersionInfo("$Id$") |
@@ -49,13 +52,42 @@ |
public static final String MPIRUN = "mpirun"; |
|
// in case the exe path needs adjustment. |
- static String noahMP = Config.getString("wrf_hydro_exe", |
+ static String noahMP = Config.getString("wrf.hydro.noahMP.exe", |
"/usr/local/tomcat/WRF/wrf_hydro_NoahMP.exe"); |
|
static VelocityEngine velocity = new VelocityEngine(); |
|
static final String NAMELIST_HRLDAS = "namelist.hrldas"; |
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"); |
+ |
+ String kday_or_hour; |
+ |
+ |
+ @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)); |
+ |
+ int kday = parameter().getInt("KDAY", -1); |
+ int khour = parameter().getInt("KHOUR", -1); |
+ |
+ if (kday == -1) { |
+ if (khour == -1) { |
+ throw new ServiceException("KHOUR or KDAY expected."); |
+ } |
+ kday_or_hour = "KHOUR = " + khour; |
+ } else { |
+ kday_or_hour = "KDAY = " + kday; |
+ } |
+ } |
|
|
@Override |
@@ -64,9 +96,11 @@ |
throw new ServiceException("Not found: " + noahMP); |
} |
|
+ createNamelist(); |
+ |
// allow for np configuration |
- int np = metainfo().getInt("mpirun.np", 2); |
- np = Config.getInt("mpirun.np", np); |
+ int np = metainfo().getInt(MPIRUN_NP, 2); |
+ np = Config.getInt(MPIRUN_NP, np); |
|
Executable mpirun = resources().getExe(MPIRUN); |
mpirun.addArguments( |
@@ -82,13 +116,12 @@ |
} |
|
|
- private String createNametlist() throws IOException { |
+ private String createNamelist() throws IOException { |
VelocityContext context = new VelocityContext(); |
context.put("service", this); |
FileWriter w = new FileWriter(getWorkspaceFile(NAMELIST_HRLDAS)); |
velocity.getTemplate(NAMELIST_HRLDAS_VM, "utf-8").merge(context, w); |
w.close(); |
- |
if (LOG.isLoggable(Level.INFO)) { |
LOG.info("Created: " + NAMELIST_HRLDAS); |
LOG.info(FileUtils.readFileToString(getWorkspaceFile(NAMELIST_HRLDAS))); |
@@ -103,4 +136,45 @@ |
velocity.init(); |
} |
|
+ |
+ // public properties for velocity |
+ public String getOutdir() { |
+ return outdir; |
+ } |
+ |
+ |
+ public String getIndir() { |
+ return indir; |
+ } |
+ |
+ |
+ public int getStartyear() { |
+ return cal.get(Calendar.YEAR); |
+ } |
+ |
+ |
+ public int getStartmonth() { |
+ return cal.get(Calendar.MONTH) + 1; |
+ } |
+ |
+ |
+ public int getStartday() { |
+ return cal.get(Calendar.DAY_OF_MONTH); |
+ } |
+ |
+ |
+ public int getStarthour() { |
+ return cal.get(Calendar.HOUR_OF_DAY); |
+ } |
+ |
+ |
+ public int getStartmin() { |
+ return cal.get(Calendar.MINUTE); |
+ } |
+ |
+ |
+ public String getkinfo() { |
+ return kday_or_hour; |
+ } |
+ |
} |