In which part of this script should I insert/put the gdal_calculate command(use for subtracting images/raster)? I don't have any idea on where to insert the gdal_calculate command. And considering the leap year and regular year. Any idea?
The following are the goals for the batch file:
- Create an output directory to save the output files/images
- Create a proc_path directory for the processed files/images only
- Subtract image from the directory to another image from another directory using gdal_calculate command and save to the output directory
Filenames:
- T2010232034000.Q_WER.Tera.tif
- T2010232035000.Q_WER.Tera.tif
- T2010232036000.Q_WER.Tera.tif
- T2010232037000.Q_WER.Tera.tif
Note: T2010232034000 = Tera/Data Year/Julian Date/HHMMSS
gdal_calculate
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two))" --two=%two_path%\two_abc_jan.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
THE CODE:
@ECHO OFF >NUL
@SETLOCAL enableextensions enabledelayedexpansion
set "in_path=E:\Proc\Mer"
set "out_path=E:\Proc\Abcde"
set "two_path=E:\Proc\Me"
set "proc_path=E:\Proc\Proc_Mer_Fi"
md %in_path% 2> NUL
md %out_path% 2> NUL
md %two_path% 2> NUL
md %proc_path% 2> NUL
pushd "%in_path%\"
set "yearDay="
set "fileName="
::Get list of all YearDays in input path
set "yearDayList=x"
for /F "tokens=* delims=" %%Q in ('dir /B ????????*.tif') do (
set "fileName=%%Q"
set "yearDay=!fileName:~1,7!"
Call :ItemToList !yearDayList! !yearDay!
)
@set yearDayList=%yearDayList:x= %
@echo yearDayList=%yearDayList%
::Process all *.tif files in input path day by day
for %%p in ( %yearDayList%) Do (
set "yearDay=%%p"
@echo .
set /A "julYr=!yearDay:~0,4!"
set "julDayS=!yearDay:~4,3!"
set "month="
set "monthDay="
rem avoid octal conversions
if "!julDayS:~0,2!"=="00" (
set /A "julDn=!julDayS:~2,1!"
) else (
if "!julDayS:~0,1!"=="0" (
set /A "julDn=!julDayS:~1,2!"
) else (
set /A "julDn=!julDayS!"
)
)
call :months !julYr! !julDn!
set "mDay2=0!monthDay!"
set "mDay2=!mDay2:~-2!"
@echo p^: yearDay !yearDay! yyyy-mmm-dd !julYr!-!month!-!mDay2!
@rem p^: yearDay !yearDay! yyyy-mmm-d !julYr!-!month!-!monthDay!
rem Process all *.tif files of the same YearDay in input path
set "fileList="
for /F "tokens=* delims=" %%G in ('dir /B "?%%p*.tif"') do (
set "fileName=%%G"
set "fileList=!fileList!!fileName! "
@echo G^: !fileName!
)
REM @echo fileList=!fileList!
REM @echo Move processed files ^(one day^) to a different directory
REM for %%a in (!fileList!) do (
REM @echo move %%a "%proc_path%\"
REM )
)
popd
goto :allcommon
:allcommon
@ENDLOCAL
@goto :eof
:ItemToList
rem yearDayList yearDay
SETLOCAL enableextensions enabledelayedexpansion
set "myYDList=%1"
set "myYearDay=%2"
set "myYList="
call :myset "myYList=%%myYDList:%myYearDay%=%%"
if "%myYList%"=="%myYDList%" set "myYDList=%myYDList%x%myYearDay%"
ENDLOCAL & set "yearDayList=%myYDList%"
exit /B
:months
rem %1=julYr
rem %2=julDn
@SETLOCAL enableextensions enabledelayedexpansion
set "mymonth=XXX"
set /a "dayom=%2"
set "allmonths=Xjanfebmaraprmayjunjulaugsepoctnovdec"
set /a "ii=1"
rem leap year test makes use of integer only arithmetic
set /A "yearModi=(%1/4)*4"
If "%1"=="%yearModi%" (
rem leap year
set "daycounts=32 61 92 122 153 183 214 245 275 306 336 367"
) Else (
rem non-leap year
set "daycounts=32 60 91 121 152 182 213 244 274 305 335 366"
)
For %%G in (%daycounts%) do (
if %2 lss %%G (
call :myset "mymonth=%%allmonths:~!ii!,3%%"
rem set /a "dayom+=1"
goto :commmonths
)
set /a ii=!ii!+3
set /a "dayom=%2-%%G+1"
)
:commmonths
ENDLOCAL & (set "month=%mymonth%"
set "monthDay=%dayom%")
exit /B
:myset
rem procedure to set indirect variable replace/substring
rem i.e. dynamic %StrToFind% instead of literal StrToFind
rem common: set "varNew=%varOld:StrToFind=NewStr%"
rem call :myset "varNew=%%varOld:%varToFind%=NewStr%%"
rem call :myset "varNew=%%varOld:!varToFind!=NewStr%%"
rem applicable to %NewStr% as well
rem i.e. dynamic %CharsToSkip% instead of literal CharsToSkip
rem common: set "varNew=%varOld:~CharsToSkip,chars_to_keep%"
rem call :myset "varNew=%%varOld:~%CharsToSkip%,chars_to_keep%%"
rem call :myset "varNew=%%varOld:~!CharsToSkip!,chars_to_keep%%"
rem applicable to %chars_to_keep% as well
set %1
exit /B
Aucun commentaire:
Enregistrer un commentaire