Displaying differences for changeset
 
display as  

nbproject/build-impl.xml

@@ -1008,12 +1008,14 @@
     <target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest">
         <copyfiles files="${libs.CSIP-Jersey-2.16.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${reference.csip-core.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
+        <copyfiles files="${file.reference.velocity-engine-core-2.0.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
         <mkdir dir="${build.web.dir}/META-INF"/>
         <manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
     </target>
     <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
         <copyfiles files="${libs.CSIP-Jersey-2.16.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
         <copyfiles files="${reference.csip-core.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
+        <copyfiles files="${file.reference.velocity-engine-core-2.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
     </target>
     <target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
         <delete dir="${build.web.dir}/WEB-INF/lib"/>

nbproject/genfiles.properties

@@ -3,8 +3,8 @@
 build.xml.stylesheet.CRC32=651128d4@1.65.1.1
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=8c5d81d4
-nbproject/build-impl.xml.script.CRC32=85d2e40f
+nbproject/build-impl.xml.data.CRC32=78298753
+nbproject/build-impl.xml.script.CRC32=e007bdca
 nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1
 nbproject/rest-build.xml.data.CRC32=bff4a8fe
 nbproject/rest-build.xml.script.CRC32=4734534b

nbproject/project.properties

@@ -1,3 +1,4 @@
+file.reference.velocity-engine-core-2.0.jar=lib/velocity-engine-core-2.0.jar
 j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.1.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-spdy.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
 #Mon Nov 09 10:36:44 MST 2015
 javadoc.splitindex=true
@@ -51,7 +52,8 @@
 javadoc.additionalparam=
 javac.classpath=\
     ${libs.CSIP-Jersey-2.16.classpath}:\
-    ${reference.csip-core.jar}
+    ${reference.csip-core.jar}:\
+    ${file.reference.velocity-engine-core-2.0.jar}
 javadoc.noindex=false
 webinf.dir=web/WEB-INF
 annotation.processing.enabled.in.editor=true

nbproject/project.xml

@@ -19,6 +19,10 @@
                     <file>${reference.csip-core.jar}</file>
                     <path-in-war>WEB-INF/lib</path-in-war>
                 </library>
+                <library dirs="200">
+                    <file>${file.reference.velocity-engine-core-2.0.jar}</file>
+                    <path-in-war>WEB-INF/lib</path-in-war>
+                </library>
             </web-module-libraries>
             <web-module-additional-libraries/>
             <source-roots>

src/java/m/wrfhydro/V1_0.java

@@ -18,8 +18,15 @@
 import csip.annotations.State;
 import csip.annotations.VersionInfo;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.logging.Level;
 import javax.ws.rs.Path;
 import static m.wrfhydro.V1_0.*;
+import org.apache.commons.io.FileUtils;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 
 /**
  * WRF-Hydro model.
@@ -27,48 +34,73 @@
  * @author od
  */
 @Name("WRF-Hydro")
-@Description(" flash flood prediction, regional hydroclimate impacts "
+@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$")
 @Category("Hydrology")
-
-@Path("m/5.0.3")
-@Resource(file = MPI, type = REFERENCE, id = MPI)
-@Resource(file = "diag_hydro.* *.txt", type = OUTPUT)
+@Path("m/NoahMP/5.0.3")
+@Resource(file = MPIRUN, type = REFERENCE, id = MPIRUN)
+@Resource(file = "diag_hydro.* *stdout.txt *stderr.txt", type = OUTPUT)
 public class V1_0 extends ModelDataService {
 
-  public static final String MPI = "mpirun";
+  public static final String MPIRUN = "mpirun";
 
   // in case the exe path needs adjustment.
-  static String wrf_hydro = Config.getString("wrf_hydro_exe",
+  static String noahMP = Config.getString("wrf_hydro_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";
+
 
   @Override
   protected void doProcess() throws Exception {
+    if (!new File(noahMP).exists()) {
+      throw new ServiceException("Not found: " + noahMP);
+    }
 
-    // allow for num cores configuration
+    // allow for np configuration
     int np = metainfo().getInt("mpirun.np", 2);
     np = Config.getInt("mpirun.np", np);
 
-    if (!new File(wrf_hydro).exists()) {
-      throw new ServiceException("Not found: " + wrf_hydro);
-    }
-
-    Executable mpi = resources().getExe(MPI);
-    mpi.addArguments(
+    Executable mpirun = resources().getExe(MPIRUN);
+    mpirun.addArguments(
         "-wdir", getWorkspaceDir(),
         "-np", np,
-        wrf_hydro
+        noahMP
     );
 
-    int ret = mpi.exec();
+    int ret = mpirun.exec();
     if (ret != 0) {
       throw new ServiceException("Error running mpi wrf_hydro: " + ret);
     }
   }
 
+
+  private String createNametlist() 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)));
+    }
+    return NAMELIST_HRLDAS;
+  }
+
+
+  public static void onContextInit() {
+    velocity.setProperty("file.resource.loader.class",
+        ClasspathResourceLoader.class.getName());
+    velocity.init();
+  }
+
 }