简洁的想法

仁爱、喜乐、和平、忍耐、恩慈、良善、信实、温柔、节制

Simufact: 全自动模拟任务托管

| Comments

前不久我发了这篇博文:Simufact: 自动生成批处理需要的.xml和.bat文件, 基本上可以满足批量提交模拟的任务。 最近因为有多个人在不同时候想提交多任务,那原来的代码就有些不够用了。

经过一些改动,我把代码升级了,取名 Simufact Helper, 用法很简单,直接把下面的代码保存为bat文件,比如说 batchv2.bat, 放到存放模拟文件的文件夹下, 双击就可以执行了。如果别人想把任务加进来,只需直接把那些.sfp文件和对应目录全Copy过来就好了。

以下是代码:

自动生成批处理需要的.xml和.bat文件 (Batch_V2_1.bat) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@echo off
setlocal ENABLEDELAYEDEXPANSION
set FormingPath="C:\Program Files\simufact\forming\10.0\sfForming\bin\sfForming.exe"
set SourceDir=%cd%

echo           ==========================================================
echo           =                                                        =
echo           =                Simufact Helper v2.1                    =
echo           =                                                        =
echo           ==========================================================
echo.
echo.

:: creat dir "batch" to save xml files
if exist ".\batch" (
    echo Dir "batch" exist, resuming...
  echo.
) else (
  echo Dir "batch" does not exist, creating...
    md batch
  echo Done^^!^^!^^!
  echo.
  echo.
)

:: creat .\batch\creat_xml.bat
if exist ".\batch\creat_xml.bat" (
  echo Batch File ".\batch\creat_xml.bat" exist, resuming...
  echo.
) else (
  echo the File ".\batch\creat_xml.bat" does not exist, creating...
  echo :: creat xml files >.\batch\creat_xml.bat
  echo @echo off>>.\batch\creat_xml.bat
  echo setlocal ENABLEDELAYEDEXPANSION>>.\batch\creat_xml.bat
  echo FOR %%%%i in ^(*.sfp^) DO ^(>>.\batch\creat_xml.bat
  echo set name=%%%%i>>.\batch\creat_xml.bat
  echo set shortname=^^!name:~0,-4^^!>>.\batch\creat_xml.bat
  echo echo Creating ^^!shortname^^!.xml ...>>.\batch\creat_xml.bat
  echo echo ^^^^^<Batch^^^^^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo   ^^^^^<File^^^^^>%%cd%%\^^!name^^!^^^^^</File^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo   ^^^^^<Process^^^^^>forming^^^^^</Process^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo   ^^^^^<Log^^^^^>%%cd%%\^^!name:~0,-4^^!\PROJECT\^^!name:~0,-4^^!\batch.log^^^^^</Log^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo   ^^^^^<Window^^^^^>true^^^^^</Window^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo   ^^^^^<CreateResultImages^^^^^>false^^^^^</CreateResultImages^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo   ^^^^^<OnlyClearResults^^^^^>false^^^^^</OnlyClearResults^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo ^^^^^</Batch^^^^^>^>^> .\batch\^^!shortname^^!.xml>>.\batch\creat_xml.bat
  echo echo Done^^^^^^^^^^!^^^^^^^^^^!^^^^^^^^^^!>>.\batch\creat_xml.bat
  echo echo.>>.\batch\creat_xml.bat
  echo ^)>>.\batch\creat_xml.bat
  echo Done^^!^^!^^!
  echo.
)

call .\batch\creat_xml.bat>nul

:_Simufact
FOR %%z in (.\batch\*.xml) DO (
  set name=%%z
  set shortname=!name:~8,-4!
  set finished=!shortname!.fin
  set running=!shortname!.run
  if not exist .\batch\!finished! (
      if not exist .\batch\!running! (
          echo running !shortname!.sfp ...
          echo running>".\batch\!running!"
          echo.

          set time_begin=!time:~0,-3!
          set date_begin=!date!
          echo ===== Begin: !date_begin! !time_begin! =====
          :: get rid of the blank like 09
          for /f "tokens=1,2,3 delims=:" %%i in ("!time_begin!") do (
              set /a hour_b=%%i
              set /a munite_b=%%j
              set /a second_b=%%k
          )
          ::!FormingPath! -batch !SourceDir!\batch\!shortname!.xml
          ping 127.0.0.1 -n 5 -w 1000 > nul
          del ".\batch\!running!"
          echo finished>.\batch\!finished!

          set time_end=!time:~0,-3!
          set date_end=!date!
          echo ===== End  : !date_end! !time_end! =====
          for /f "tokens=1,2,3 delims=:" %%i in ("!time_end!") do (
              set /a hour_e=%%i
              set /a munite_e=%%j
              set /a second_e=%%k
          )
          call :time_lapse
          echo.
          echo used: !hour_! h !munite_! min !second_! sec
          echo.
          echo Done^^!^^!^^!
          call .\batch\creat_xml.bat > nul
          echo.
          echo.
          echo.
          goto _Simufact
      )
  )
)
pause




:time_lapse
if !second_e! lss !second_b! (
    set /a munite_e=!munite_e!-1
    set /a second_e=!second_e!+60
)
set /a second_=!second_e!-!second_b!

if !munite_e! lss !munite_b! (
    set /a hour_e=!hour_e!-1
    set /a munite_e=!munite_e!+60
)
set /a munite_=!munite_e!-!munite_b!

if !hour_e! lss !hour_b! (
    set /a hour_e=!hour_e!+24
)
set /a hour_=!hour_e!-!hour_b!
goto :eof

Comments