| | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | |
| | | /** |
| | | * 内涝求解器服务类 |
| | | * |
| | | * @author WWW |
| | | * @date 2024-09-29 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | |
| | | @Resource |
| | | PropertiesConfig config; |
| | | |
| | | /** |
| | | * 创建降雨文件 |
| | | * <p> |
| | | * https://blog.csdn.net/Dark_Drgon/article/details/139739924 |
| | | * C:\Program Files\matlab\R2020a\runtime\win64 |
| | | */ |
| | | static Rainfall _rainfall = null; |
| | | |
| | | public static Rainfall getTainfall() throws Exception { |
| | | if (null == _rainfall) { |
| | | _rainfall = new Rainfall(); |
| | | } |
| | | |
| | | return _rainfall; |
| | | } |
| | | |
| | | public void createRainFile(DataPo data) throws Exception { |
| | | String filePath = config.getInPath() + File.separator + data.getInPath() + File.separator + config.getRaingage(); |
| | | String startTime = StringHelper.YMDHMS_FORMAT.format(data.getStartTime()); |
| | |
| | | //MWCharArray station = new MWCharArray(config.getRainStation()); |
| | | //MWCharArray time = new MWCharArray(startTime); |
| | | |
| | | Rainfall rainfall = new Rainfall(); |
| | | Rainfall rainfall = getTainfall(); |
| | | //rainfall('D:\simu\in\RainGage.dat','Tongzhou','2024-09-29 00:00:00',60,0.5,10) |
| | | Object[] rs = rainfall.rainfall(filePath, config.getRainStation(), startTime, |
| | | Double.valueOf(data.getDuration()), 0.5, config.getRainPeriod()); |
| | | //Object[] rs = rainfall.rainfall(filePath, config.getRainStation(), startTime, Double.valueOf(data.getDuration()), 0.5, config.getRainPeriod()); |
| | | |
| | | //rainfall('D:\simu\in\RainGage.dat','Tongzhou','2024-07-01 00:00:00',60,60) |
| | | Object[] rs = rainfall.rainfall(filePath, config.getRainStation(), startTime, Double.valueOf(data.getDuration()), data.getTotal()); |
| | | |
| | | // file.dispose(); |
| | | //station.dispose(); |
| | |
| | | public String callExe(DataPo data) throws Exception { |
| | | String cmd = String.format("%s %d %s", config.getSolverBat(), WebHelper.getCpuCores(), data.getInPath() + ".json"); |
| | | |
| | | return exec(cmd); |
| | | //return exec(cmd); |
| | | return execCmdLine(cmd); |
| | | } |
| | | |
| | | private String exec(String cmd) throws Exception { |
| | |
| | | nr = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK")); |
| | | er = new BufferedReader(new InputStreamReader(process.getErrorStream(), "GBK")); |
| | | |
| | | String errorLine; |
| | | while ((errorLine = er.readLine()) != null) { |
| | | log.warn(errorLine); |
| | | } |
| | | |
| | | String line; |
| | | StringBuilder sb = new StringBuilder(); |
| | | while ((line = nr.readLine()) != null) { |
| | | sb.append(line); |
| | | log.info(line); |
| | | } |
| | | |
| | | // 等待程序执行结束并输出状态 |
| | | String errorLine; |
| | | while ((errorLine = er.readLine()) != null) { |
| | | log.error(errorLine); |
| | | } |
| | | |
| | | int exitCode = process.waitFor(); |
| | | |
| | | return sb.toString(); |
| | |
| | | } |
| | | } |
| | | |
| | | public String getKeyFrame(DataPo data) throws Exception { |
| | | String cmd = config.getKeyFrameBat() + " " + config.getInPath() + File.separator + data.getInPath() + File.separator + ".save" + File.separator + data.getInPath() + ".sww"; |
| | | private String execCmdLine(String cmd) throws IOException, InterruptedException { |
| | | Process process = Runtime.getRuntime().exec(cmd); |
| | | |
| | | String str = exec(cmd); |
| | | if (StringHelper.isEmpty(str) || !str.contains("[")) { |
| | | throw new Exception("生成关键帧出错"); |
| | | } |
| | | new Thread(() -> { |
| | | InputStreamReader ir = null; |
| | | BufferedReader br = null; |
| | | try { |
| | | ir = new InputStreamReader(process.getErrorStream(), "GBK"); |
| | | br = new BufferedReader(ir); |
| | | |
| | | String rs = str.split("\\[", 2)[1].replace("]", "").replace(" ", ""); |
| | | if (StringHelper.isEmpty(rs)) { |
| | | throw new Exception("关键帧为空"); |
| | | } |
| | | String line; |
| | | while ((line = br.readLine()) != null) { |
| | | log.error(line); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (null != br) br.close(); |
| | | if (null != ir) ir.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | |
| | | return rs; |
| | | StringBuilder sb = new StringBuilder(); |
| | | //new Thread(() -> { |
| | | InputStreamReader ir = null; |
| | | BufferedReader br = null; |
| | | try { |
| | | ir = new InputStreamReader(process.getInputStream(), "GBK"); |
| | | br = new BufferedReader(ir); |
| | | |
| | | String line; |
| | | while ((line = br.readLine()) != null) { |
| | | log.info(line); |
| | | sb.append(line); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (null != br) br.close(); |
| | | if (null != ir) ir.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //}).start(); |
| | | |
| | | process.waitFor(); |
| | | process.destroy(); |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public void copeWaterFiles() { |
| | | // |
| | | } |
| | | |
| | | public void copeDrainFiles() { |
| | | // |
| | | public String copeDrainFiles(DataPo data) throws Exception { |
| | | String time = StringHelper.YMDHMS_FORMAT.format(data.getStartTime()); |
| | | String inPath = config.getInPath() + File.separator + data.getInPath(); |
| | | String sww = inPath + File.separator + ".save" + File.separator + data.getInPath() + ".sww"; |
| | | |
| | | String cmd = config.getSww2tifBat() + " " + sww + " \"" + time + "\" " + data.getEpsg() + " " + inPath; |
| | | |
| | | return exec(cmd); |
| | | } |
| | | public String copeSwwDrainFiles(DataPo data) throws Exception { |
| | | String time = StringHelper.YMDHMS_FORMAT.format(data.getStartTime()); |
| | | String inPath = "H:\\simu\\semout"; |
| | | String sww = "H:\\simu\\semout\\testsem\\.out\\" + "testsem.sww"; |
| | | |
| | | String cmd = config.getSww2tifBat() + " " + sww + " \"" + time + "\" " + data.getEpsg() + " " + inPath; |
| | | |
| | | return exec(cmd); |
| | | } |
| | | } |