@echo off
setLocal EnableDelayedExpansion

cd ..
set WRK=%CD%

set DIR=c:
set PGM=%DIR%\hysplit4
cd %PGM%\working
SET INP=hysplit2

IF EXIST INFILE DEL INFILE
for %%M in (001 002 003 004 005) do (
   IF NOT EXIST %INP%.%%M (
      echo Missing input file %INP%.%%M
      echo Re-run ens_data to create output file!
      pause
      exit
   )
   echo %INP%.%%M >>INFILE
)

REM --------------------------------------------------------------

set RUN=1
set OUT=temp1

IF EXIST INFILE (
      FOR /F %%N IN (INFILE) do (

      IF !RUN! == 1 (
         set in1=%%N
      ) ELSE (
         set in2=%%N
         %PGM%\exec\concadd -i!in1! -b!in2! -o!out! -p0

         IF !OUT! == temp1 (
            set in1=temp1
            set out=temp2
         ) ELSE ( 
            set in1=temp2
            set out=temp1
         )
      )
      set /a RUN=!RUN!+1
      )
)
%PGM%\exec\conlight -i!out! -ohysplit2.006 -m0.20

REM ----------------------------------------------------------

IF EXIST sumstat.txt DEL sumstat.txt
for %%M in (001 002 003 004 005 006) do (  
    %PGM%\exec\c2datem -i%INP%.%%M -odatem.%%M -c1.0E+12 -m%WRK%\captex\captex2_meas.txt -xi -s
    %PGM%\exec\statmain -t0 -rdatem.%%M -d%WRK%\captex\captex2_meas.txt -l10.0 -o1 -ssumstat.txt
)
type sumstat.txt
pause
