Displaying differences for changeset
 
display as  

src/java/m/wrfhydro/V1_0.java

@@ -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;
+  }
+
 }

src/java/m/wrfhydro/V1_0.json

@@ -2,5 +2,30 @@
  "metainfo": {
  },
  "parameter": [
+  {
+   "name": "OUTDIR",
+   "value": "./",
+   "description": ""
+  },
+  {
+   "name": "INDIR",
+   "value": "./FORCING",
+   "description": ""
+  },
+  {
+   "name": "START",
+   "value": "2011-08-26 00:00",
+   "description": ""
+  },
+  {
+   "name": "KDAY",
+   "value": "8",
+   "description": ""
+  },
+  {
+   "name": "KHOUR",
+   "value": "7",
+   "description": ""
+  }
  ]
 }
\ No newline at end of file

src/java/m/wrfhydro/namelist.hrldas.vm

@@ -1,19 +1,20 @@
 &NOAHLSM_OFFLINE
 
 HRLDAS_SETUP_FILE = "./DOMAIN/wrfinput_d01.nc"
-INDIR = "./FORCING"
+INDIR = "${service.indir}"
 SPATIAL_FILENAME = "./DOMAIN/soil_properties.nc"
-OUTDIR = "./"
+OUTDIR = "${service.outdir}"
 
-START_YEAR  = 2011
-START_MONTH = 08
-START_DAY   = 26
-START_HOUR  = 00
-START_MIN   = 00
+START_YEAR  = ${service.startyear}
+START_MONTH = ${service.startmonth}
+START_DAY   = ${service.startday}
+START_HOUR  = ${service.starthour}
+START_MIN   = ${service.startmin}
 
 RESTART_FILENAME_REQUESTED = "RESTART/RESTART.2011082600_DOMAIN1"
 
-KDAY = 7
+${service.kinfo}
+!KDAY = 7
 ! KHOUR = 8
 
 DYNAMIC_VEG_OPTION                = 4