Skip to content

Commit

Permalink
fix config
Browse files Browse the repository at this point in the history
  • Loading branch information
alei committed Mar 20, 2017
1 parent 7c99782 commit 7ae0e4c
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 37 deletions.
2 changes: 1 addition & 1 deletion etc/instance.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
system.instance: "r0-rake"
system.instance: "r0"
2 changes: 1 addition & 1 deletion etc/r0/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ system {
sync: "/curr/jn/input" #同步数据
script: /home/modelcloud/modelcloud/model-driver #模式驱动脚本位置
wrf: /home/modelcloud/chengjing/WRF3.7 #WRF安装目录
cmaq: /home/modelcloud/chengjing/CMAQv5.1 #CMAQ安装目录
cmaq: /home/modelcloud/curr/build/build/CMAQv5.0.1 #CMAQ安装目录
meic: /home/modelcloud/modelcloud/meic
}
renv {
Expand Down
1 change: 1 addition & 0 deletions etc/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ system {
csh_megan = template/csh/megan.csh.vm
csh_cmaq = template/csh/cmaq.csh.vm
csh_header = template/csh/header.csh.vm
csh_ungrib = template/csh/ungrib.csv.vm

meic_jar_conf = template/conf/meic_jar.conf.vm
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.makenv.model.mc.cli.exception.InvalidParamsException;
import com.makenv.model.mc.cli.func.AbstractOperator;
import com.makenv.model.mc.core.config.McConfigManager;
import com.makenv.model.mc.core.config.TemplatePath;
import com.makenv.model.mc.core.constant.Constant;
import com.makenv.model.mc.core.util.FileUtil;
import com.makenv.model.mc.core.util.LocalTimeUtil;
Expand Down Expand Up @@ -183,27 +184,36 @@ private Map<String, Object> buildGfsEnv() throws IOException {
}

private void prepareExecScript() throws IOException {
String sourceSysRenv = String.format("source %s\necho $LD_LIBRARY_PATH\n\n",
configManager.getSystemConfig().getRenv().getSys());
String cdInvokeDir = String.format("cd %s\n", runPath);
String sb = Constant.CSH_HEADER + sourceSysRenv +
cdInvokeDir +
buildCmd(Constant.GLOBAL_TYPE_FNL) +
buildCmd(Constant.GLOBAL_TYPE_GFS);
TemplatePath template = configManager.getSystemConfig().getTemplate();
String headerContent = VelocityUtil.buildTemplate(template.getCsh_header(), "sys_renv", configManager.getSystemConfig().getRenv().getSys());
Map<String, String> params = new HashMap<>();
params.put("run_path", runPath);
params.put("ungrib_csh", configManager.getSystemConfig().getCsh().getModule_ungrib_csh());
params.put("renv_fnl", renvFnlFile);
params.put("renv_gfs", renvGfsFile);
String bodyContent = VelocityUtil.buildTemplate(template.getCsh_ungrib(), "sys_renv", configManager.getSystemConfig().getRenv().getSys());

// String sourceSysRenv = String.format("source %s\necho $LD_LIBRARY_PATH\n\n",
// configManager.getSystemConfig().getRenv().getSys());
// String cdInvokeDir = String.format("cd %s\n", runPath);
// String sb = Constant.CSH_HEADER + sourceSysRenv +
// cdInvokeDir +
// buildCmd(Constant.GLOBAL_TYPE_FNL) +
// buildCmd(Constant.GLOBAL_TYPE_GFS);
File file = new File(invokeScriptFile);
FileUtil.writeLocalFile(file, sb);
FileUtil.writeLocalFile(file, headerContent + bodyContent);
file.setExecutable(true);
}

private StringBuilder buildCmd(String type) {
StringBuilder sb = new StringBuilder();
// String driverScriptPath = String.format("%s%slevel_3%sModule_ungrib.csh", configManager.getSystemConfig().getRoot().getScript(), File.separator, File.separator);
sb.append(configManager.getSystemConfig().getCsh().getModule_ungrib_csh());
sb.append(" ");
sb.append(type.equals(Constant.GLOBAL_TYPE_GFS) ? renvGfsFile : renvFnlFile);
sb.append("\n");
return sb;
}
// private StringBuilder buildCmd(String type) {
// StringBuilder sb = new StringBuilder();
//// String driverScriptPath = String.format("%s%slevel_3%sModule_ungrib.csh", configManager.getSystemConfig().getRoot().getScript(), File.separator, File.separator);
// sb.append(configManager.getSystemConfig().getCsh().getModule_ungrib_csh());
// sb.append(" ");
// sb.append(type.equals(Constant.GLOBAL_TYPE_GFS) ? renvGfsFile : renvFnlFile);
// sb.append("\n");
// return sb;
// }

private void exec() throws IOException {
String qsub = configManager.getSystemConfig().getPbs().getQsub();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public class TemplatePath {
private String csh_megan;
private String csh_cmaq;
private String csh_header;
private String csh_ungrib;

public String getCsh_ungrib() {
return csh_ungrib;
}

public void setCsh_ungrib(String csh_ungrib) {
this.csh_ungrib = csh_ungrib;
}

public String getCsh_header() {
return csh_header;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public static void main(String[] args) throws IOException {
String queue = "receive_queue_name";
Jedis jedis = new Jedis("166.111.42.46", 16379);
jedis.auth("123456");
String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\start-model-all.json"));
// String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\start-model-wrf.json"));
// String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\start-model-meic.json"));
// String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\start-model-mcip.json"));
String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\start-model-cmaq.json"));
// String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\start-model-cmaq.json"));
// String content = FileUtil.readLocalFile(new File("samples\\api\\BM\\test\\create-domain-1.json"));
jedis.lpush(queue, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,48 +158,73 @@ private void buildGfsRenvBean() throws IOException {
private void buildFnlRenvBean() throws IOException {
boolean firsTime = modelStartBean.getWrf().isFirsttime();
int i = 0, j = 0;
LocalDate _current = startDate, lastDate = startDate;
LocalDate _start = LocalTimeUtil.minusHoursDiff(timeDiff, startDate);
LocalDate _end = LocalTimeUtil.minusHoursDiff(timeDiff, endDate);
LocalDate _current = _start, lastDate = _start;
WrfBean bean;
while (!_current.isAfter(endDate)) {
if (isReInitial(_current) && i != 0) {
while (!_current.isAfter(_end)) {
// if (isReInitial(_current) && i != 0) {
if (isReInitial(_current)) {
bean = buildFnlWrfBean(lastDate, _current);
wrfBeans.add(bean);
bean.setRun_days((int) LocalTimeUtil.between(_current, lastDate));
bean.setRun_hours(configManager.getSystemConfig().getModel().getWrf_run_hours());
bean.setRun_type(j++ == 0 ? (firsTime ? RUN_TYPE_INIT : RUN_TYPE_RESTART) : RUN_TYPE_REINIT);
lastDate = _current;
wrfBeans.add(bean);
}
i++;
_current = _current.plusDays(1);
}
bean = buildFnlWrfBean(lastDate, endDate);
_current = _current.plusDays(-1);
bean = buildFnlWrfBean(lastDate, _end);
bean.setRun_hours(0);
if (j == 0) {
bean.setRun_type(firsTime ? RUN_TYPE_INIT : RUN_TYPE_RESTART);
bean.setRun_days((int) LocalTimeUtil.between(_current, lastDate) + 1);
} else {
bean.setRun_type(RUN_TYPE_REINIT);
bean.setRun_days((int) LocalTimeUtil.between(_current, lastDate) + 1);
}
wrfBeans.add(bean);
}

public static void main(String[] args) {
String startDate = "20170301", endDate = "20170303";
String startDate = "20170211", endDate = "20170216";
String reinit_origin_date = "19800101";
int reinit_cycle_days = 5, timeDiff = 8;
boolean fisttime = false;
boolean firsTime = false;

LocalDate _start = LocalTimeUtil.minusHoursDiff(timeDiff, startDate, LocalTimeUtil.YMD_DATE_FORMAT);
LocalDate _end = LocalTimeUtil.minusHoursDiff(timeDiff, endDate, LocalTimeUtil.YMD_DATE_FORMAT);
LocalDate _current = _start;
long days = LocalTimeUtil.between(_start, _end) + 1;
LocalDate _current = _start, lastDate = _start;
LocalDate baseDate = LocalTimeUtil.parse(reinit_origin_date, LocalTimeUtil.YMD_DATE_FORMAT);
int i = 0, j = 0;
while (!_current.isAfter(_end)) {

if (LocalTimeUtil.needReInitial(baseDate, _current, reinit_cycle_days)) {
long runDays = LocalTimeUtil.between(_current, lastDate);
int runType = (j == 0 ? (firsTime ? RUN_TYPE_INIT : RUN_TYPE_RESTART) : RUN_TYPE_REINIT);
System.out.println(String.format("rundays=%s,runType=%s,runHours=22", runDays, runType));
lastDate = _current;
j++;
}
i++;
_current = _current.plusDays(1);
}

_current = _current.plusDays(-1);
long runDays, runType;
if (j == 0) {
runType = firsTime ? RUN_TYPE_INIT : RUN_TYPE_RESTART;
runDays = LocalTimeUtil.between(_current, lastDate) + 1;
} else {
runType = RUN_TYPE_REINIT;
runDays = LocalTimeUtil.between(_current, lastDate) + 1;
}
System.out.println(String.format("rundays=%s,runType=%s,runHours=0", runDays, runType));
}

private WrfBean buildFnlWrfBean(LocalDate startDate, LocalDate current) throws IOException {
WrfBean bean = createWrfBean();
bean.setStart_date(LocalTimeUtil.format(startDate, LocalTimeUtil.YMD_DATE_FORMAT));
bean.setRun_days((int) LocalTimeUtil.between(current, startDate) + 1);
bean.setRun_hours(configManager.getSystemConfig().getModel().getWrf_run_hours());
bean.setUngrib_output_path(configManager.getSystemConfig().getWorkspace().getShare().getInput().getUngrib_fnl().getDirPath());
String metgridOutPath = configManager.getSystemConfig().getWorkspace().getUserid().getDomainid().getCommon().getData().getGlobaldatasets().getMetgrid().getDirPath();
bean.setMetgrid_output_path(processPath(metgridOutPath));
Expand Down
6 changes: 3 additions & 3 deletions samples/api/BM/test/start-model-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"datatype": "gfs",
"simtype":"base",
"time": {
"start": "20170201",
"end": "20170201"
"start": "20170220",
"end": "20170220"
},
"pathdate":"20170201"
"pathdate":"20170203"
},
"emis": {
"sourceid": "1",
Expand Down
2 changes: 1 addition & 1 deletion template/csh/header.csh.vm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/csh
source ${sys_renv}
source ${sys_renv}
4 changes: 4 additions & 0 deletions template/csh/ungrib.csv.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

cd ${run_path}
${ungrib_csh} ${renv_fnl}
${ungrib_csh} ${renv_gfs}

0 comments on commit 7ae0e4c

Please sign in to comment.