@@ -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"/> |
@@ -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(); |
+ } |
+ |
} |