Computer Hope
Microsoft => Microsoft DOS => Topic started by: _unknown_ on November 05, 2014, 02:34:30 AM
-
I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process.
Here's what I need to do:
- Create the output directory
- Check automatically if there are new files added in the input directory, if there are new files subtract immediately
- Subtract one image from the directory to another image from another directory
LEAP YEARS: REGULAR YEARS:
*2000, 2004, 2008, 2012, 2016, 2020...* *2001-2003, 2005-2007, 2009-2011, 2013-2015...*
January - 1-31 January - 1-31
February - 32-60 February - 32-59
March - 61-91 March - 60-90
April - 92-121 April - 91-120
May - 122-152 May - 121-151
June - 153-182 June - 152-181
July - 183-213 July - 182-212
August - 214-244 August - 213-243
September - 245-274 September - 244-273
October - 275-305 October - 274-304
November - 306-335 November - 305-334
December - 336-366 December - 335-365
Here are the sample file name for the images(these will be the minuend):
:there will only be 12 subtrahend(sample_file_jan.tif, sample_file_feb.tif, sample_file_march.tif . . .)
C2000060.A1_ABC.ABCD.tif - sample_file_feb.tif ------------------> the file was subtracted to feb because 060 is a day included in February (leap year)
C2002152.A1_ABC.ABCD.tif - sample_file_june.tif------------------> the file was subtracted to june because 152 is a day included in June (regular year)
C2000032.A1_ABC.ABCD.tif - sample_file_feb.tif------------------> the file was subtracted to feb because 032 is a day included in February (leap year)
C2001060.A1_ABC.ABCD.tif - sample_file_march.tif------------------> the file was subtracted to march because 060 is a day included in March (regular year)
where:
C = data name
2000 - year (leap year or regular year)
001 - julian date (leap year or regular year)
A1_ABC.ABCD.tif - extension name
If the year specified in the file name is 2000, 2004, 2008... then the date would be based on leap year. If the year specified in the file name is 2001-2003, 2005-2007, 2009-2011... then the date would be based on regular year.
If the date from the file name is based on the date from the leap years, then subtract the image to its corresponding subtrahend/month to where it should be subtracted. Repeat this step if the date are from the regular years.
Here is the script in subtracting images:
gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1
+image2))" --image2=D:\path\to\subtrahend\sample_file_feb.tif image1=D:\path\to\minuend\C2001060.A1_ABC.ABCD.tif --extent=INTERSECT
-
You are really referring to an Ordinal Date not a Julian Date.
-
This will help you change your ordinal date to a Calendar date. Once you have the calendar date information you should then be able to figure out how to run your program.
http://www.commandline.co.uk/cmdfuncs/dandt/#ordinaltodate
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
Going to assume you will want to convert the month number to the month name, so that you can use the month name with the GDAL_CALCULATE command.
I have added that code.
@echo off&setlocal enabledelayedexpansion
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
:: Now convert the month number to month name abbreviation
set m=100
for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /A m+=1
set month[!m:~-2!]=%%m
)
set monthName=!month[%mm%]!
echo %monthName%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
Going to assume you will want to convert the month number to the month name, so that you can use the month name with the GDAL_CALCULATE command.
I have added that code.
@echo off&setlocal enabledelayedexpansion
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
:: Now convert the month number to month name abbreviation
set m=100
for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /A m+=1
set month[!m:~-2!]=%%m
)
set monthName=!month[%mm%]!
echo %monthName%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
How will I add the gdal_calculate command to the batch script you gave?
-
How will I add the gdal_calculate command to the batch script you gave?
Well I assumed you wanted to use the Month Name Abbreviation as part of your sample_file_feb.tif file. So use the month abbreviation variable that I created for you.
-
In which part of your script should I add the gdal_calculate command?
-
In which part of your script should I add the gdal_calculate command?
Well you are not even to that point yet. You still need the code to extract the Ordinal Date from the file name.
Look at the code that Aacini gave you on DosTips.com.
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.
-
Well you are not even to that point yet. You still need the code to extract the Ordinal Date from the file name.
Look at the code that Aacini gave you on DosTips.com.
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.
Sorry for this. But is it like this?
@echo off&setlocal EnableDelayedExpansion
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
:: Now convert the month number to month name abbreviation
set m=100
for %%m in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /A m+=1
set month[!m:~-2!]=%%m
)
set monthName=!month[%mm%]!
echo %monthName%
set "in_path=E:\Processed_Files\Merged\"
set "out_path=E:\Diff"
set "in_subtrahend=E:\sample_file_months\"
set "yearDay="
set "fileList="
md %out_path%
rem Process all *.tif files in input path
cd "%in_path%"
for %%a in (*.tif) do (
set "fileName=%%a"
rem If the YearDay in this file is the same of previous one
if "!fileName:~1,7!" equ "!yearDay!" (
rem Join this filename to previous list
set "fileList=!fileList! !fileName!"
) else (
rem Subtract the files in the list
if defined fileList gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2)/(image1+image2))" --
image2=%in_subtrahend% image1=%in_path% --extent=INTERSECT
)
)
rem Subtract the files in the list
gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2)/(image1+image2))" --image2=
%in_subtrahend% image1=%in_path% --extent=INTERSECT
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.
Am I doing the right thing? Please help! I'm just beginning to learn batch files and I don't know how to do it.
:( :(
-
Well you are not even to that point yet. You still need the code to extract the Ordinal Date from the file name.
Look at the code that Aacini gave you on DosTips.com.
That will show you the FOR command that will process all your files and it will show you how to get the ordinal date from the file name and then it basically shows you where you would put your GDAL command.
I have tried my very best with this. Please bear with me. :(
@echo on
setlocal 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"
::Don't modify the following variables
set "yearDay="
set "fileList="
md %out_path%
md %proc_path%
::Process all *.tif files in input path
cd /d "%in_path%"
for %%a in (*.tif) do (
set "fileName=%%a"
if %1 == 001-031 goto :condition1 ::reg/leap
if %2 == 032-059 goto :condition2 ::reg
if %3 == 032-060 goto :condition2 ::leap
if %4 == 060-090 goto :condition3 ::reg
if %5 == 061-091 goto :condition3 ::leap
if %6 == 091-120 goto :condition4 ::reg
if %7 == 092-121 goto :condition4 ::leap
if %8 == 121-151 goto :condition5 ::reg
if %9 == 122-152 goto :condition5 ::leap
if %10 == 152-181 goto :condition6 ::reg
if %11 == 153-182 goto :condition6 ::leap
if %12 == 182-212 goto :condition7 ::reg
if %13 == 183-213 goto :condition7 ::leap
if %14 == 213-243 goto :condition8 ::reg
if %15 == 214-244 goto :condition8 ::leap
if %16 == 244-273 goto :condition9 ::reg
if %17 == 245-274 goto :condition9 ::leap
if %18 == 274-304 goto :condition10 ::reg
if %19 == 275-305 goto :condition10 ::leap
if %20 == 305-334 goto :condition11 ::reg
if %21 == 306-335 goto :condition11 ::leap
if %22 == 335-365 goto :condition12 ::reg
if %23 == 336-366 goto :condition12 ::leap
:condition1
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_jan.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition2
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_feb.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition3
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_mar.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition4
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_apr.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition5
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_may.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition6
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_june.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition7
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition8
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_aug.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition9
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_sep.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition10
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_oct.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition11
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_nov.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:condition12
gdal_calculate --outfile=%out_path%\Abcde!yearDay!.Q_WER.Tera.tif !fileList! --calc="((one-two)/(one+two))" --two=%two_path%\two_abc_dec.tif --one=%in_path%\A!yearDay!.Q_WER.Tera.tif !fileList! --extent=INTERSECT
goto end
:: Move processed files to a different directory
for %%a in (!fileList!) do move %%a "%proc_path%" >nul
)
-
I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process.
Here's what I need to do:
- Create the output directory
- Check automatically if there are new files added in the input directory, if there are new files subtract immediately
Files have a modified date which can be used to see if they are new.
Do your files get modified so that the most recent file was the last one that was created, or modified?
-
Files have a modified date which can be used to see if they are new.
Do your files get modified so that the most recent file was the last one that was created, or modified?
Everyday there will be new files added to the input directory that's why I included that in my goals but now instead of that those processed files will just be moved to another directory. So that the input directory will not be confused of the newer files. I hope I'm explaining it well?
-
Everyday there will be new files added to the input directory that's why I included that in my goals but now instead of that those processed files will just be moved to another directory. So that the input directory will not be confused of the newer files. I hope I'm explaining it well?
Well nothing you said replied to the question I posed. :D
The task may be much simpler than the way your code looks to be - using the file dates rather than the numbers in the filename.
I don't follow the task too well though, as subtracted and subtrahend are your terms for something
but they make no sense in terms of describing what the task is.
To me it would make more sense to say "processing" or "process the file with programB and copy it to folder c:\widget\"
-
Well nothing you said replied to the question I posed. :D
The task may be much simpler than the way your code looks to be - using the file dates rather than the numbers in the filename.
I don't follow the task too well though, as subtracted and subtrahend are your terms for something
but they make no sense in terms of describing what the task is.
To me it would make more sense to say "processing" or "process the file with programB and copy it to folder c:\widget\"
Well sorry for me. I'm really not good in explaining. So you mean, I should replace the subtract with process?or processing? I'm using subtract and subtrahend because I thought that was the right term and because the batch will literally subtract one image to another.
-
Does to OP want to destroy or reduce? Subtract may imply destroy or remove.
Alternative ways to reduce something without using the word subtract.
depreciate
derogate
detract
discountenance
disesteem
disfavor
disparage
expostulate
frown
object
pooh-pooh
rip
disapprove of
discommend
mudsling
not go for
poor mouth
protest against
put down
run down
take dim view of
take down
take exception to
There are more. But the above is enough. :)
-
Does to OP want to destroy or reduce? Subtract may imply destroy or remove.
Alternative ways to reduce something without using the word subtract.There are more. But the above is enough. :)
Subtract in this case will be used mathematically. Means to take, deduct, take from, take out etc.
-
Well nothing you said replied to the question I posed. :D
My question wasn't very clear I have to say.
What I wanted to know is are the files created or changed in date order?
So Tuesday 2nd Dec file is created or changed on Tuesday 2nd Dec and is then processed when the code is run, and
Wednesday 3rd Dec file is created or changed on Wednesday 3rd Dec and is then processed when the code is run etc....
-
My question wasn't very clear I have to say.
What I wanted to know is are the files created or changed in date order?
So Tuesday 2nd Dec file is created or changed on Tuesday 2nd Dec and is then processed when the code is run, and
Wednesday 3rd Dec file is created or changed on Wednesday 3rd Dec and is then processed when the code is run etc....
The files were downloaded from an ftp site. So everyday there will be files added. I don't know if I'm getting your point.
-
.
-
Do your files get modified so that the most recent file was the last one that was created, or modified?
Anyway, these goal isn't included anymore. The goal now are:
- Create an output directory for the output files
- Create a proc_path directory for the processed files
- Subtract image from the in_path to another image from another directory(e.g. 2 - 1 = 1, image1 - image2 = difference(some part of the image2 that weren't on the image 1 were taken/deducted or vice versa)
I hope I explained it well. Hoping for your help |V|
-
What sort of real world application requites subtractive if one image from another?
Do these images represent 2 dimensional objects? Are the images abstractions? Do the represent some kind of matrix? Are these images' Fourier transformations?
http://en.wikipedia.org/wiki/Fourier_transform
If they are Fourier transformation, subtraction would make sense.
Fourier transformation is used in the process of MRI systems. An yes, they are called images. Is this what the topic is about?
-
What sort of real world application requites subtractive if one image from another?
Do these images represent 2 dimensional objects? Are the images abstractions? Do the represent some kind of matrix? Are these images' Fourier transformations?
http://en.wikipedia.org/wiki/Fourier_transform
If they are Fourier transformation, subtraction would make sense.
Fourier transformation is used in the process of MRI systems. An yes, they are called images. Is this what the topic is about?
These are raster images downloaded from NASA which contains specific data sets needed in subtraction. It represents the whole image of a country.
-
These are raster images downloaded from NASA which contains specific data sets needed in subtraction. It represents the whole image of a country.
Thank you! Now it all makes sense. NASA image subtraction is part of the
Fourier transformation algorithms. :)
https://cloud1.arc.nasa.gov/solve/payload/dc8/ftir.html
Measurement Description: The NCAR Fourier transform spectrometer will record high-resolution solar infrared absorption spectra of the atmosphere above the DC-8 aircraft. From these absorption spectra column abundances of a number of stratospheric gases important to polar ozone chemistry will be derived. The spectra also will be used to attempt to detect the infrared absorption signature of polar stratospheric clouds so that the phase and composition of those clouds can be determined. The instrument has flown successfully on the DC-8 on three polar programs since 1987. Details of the column retrieval method may be found in Mankin and Coffey, 1989; and Coffey et al., 1989. Stratospheric gases that have been retrieved during the airborne field programs are listed in Table 1.
That kind of thing can be used to make weather maps and other things that require sets of still images made over a period of time.
Now we understand what the name of the topic. He wants to order sets of images to be subtracted in an algorithm that yields the difference.
-
Sounds like you will need a Rocket Surgeon to do this. :)
You would assume that someone else has already scripted something like this. Have you asked around in your community field of work or even asked your NASA contacts.
-
The OP has to use
gdal_calculate
to subtract images. Possibly written in Python.
See here:
http://stackoverflow.com/questions/13439357/extract-point-from-raster-in-gdal
It is used in a batch script on
http:// Earthwithsun.com
It is beyond my training to explain how it works.
But maybe in a few years I will catch on.
-
For the benefit of all reading this thread.
The question about subtraction of images is also found here:
http://earthwithsun.com/questions/847009/batch-process-subtraction-of-images
I have numerous images from a directory that needs to be subtracted to another image(another directory) and I don't know how to do it automatically in batch process. Any idea?
The following are the goals for the batch file:
Create an output directory
Create a proc_path directory for the processed files only
Subtract image from the directory to another image from another directort
...
And yes, they use a batch file to order the files and make backups.
The is a library of stuff in GDAL.
GDAL is GDAL: GDAL - Geospatial Data Abstraction Library
http://www.gdal.org/
GDAL is a translator library for raster and vector geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation. As a library, it presents a single raster abstract data model and vector abstract data model to the calling application for all supported formats. It also comes with a variety of useful commandline utilities for data translation and processing. The NEWS page describes the September 2014 GDAL/OGR 1.11.1 release.
Traditionally GDAL used to design the raster part of the library, and OGR the vector part for Simple Features. Starting with GDAL 2.0, both sides have been more tightly integrated. You can still refer to the documentation of GDAL 1.X if needed.
Master: http://www.gdal.org
Download: ftp at remotesensing.org, http at download.osgeo.org
This use of two or more images to create a differential images is called subtraction. One might be tempted to call it a product or the result of a multiplication. But in Fourier vocabulary is is called subtraction. I think.
Please, anybody with a degree in differential calculus step in and save the thread.
I have to go back to bed and take some pills. :-[
-
I have to give up on this. I do not have any experience with the GDAL library. The GDAL library is a collection of functions that can be used to process images received from satellites. The images are in a form of digital information containing vector values along with Raster information. This type of mathematics is associated with a special set of calculus stuff.
The key issue is the original poster of this thread has a program that he can use from a command line, but cannot be used in a batch file. From what little research. I've been able to do on this, this seems to be typical of some script languages. One example could be Python. When using Python. One has a command line interface in Python that accepts Python programs. However, Python does not have a DOS shell that executes DOS programs for Windows. Well, at least not to my knowledge. The singular issue would be if one was using VBA, visual basic for applications, another script language that has power similar to that of Python and other interpretive languages.
My own limited experience is to use some kind of a hack. When I need to combine a DOS batch file with some kind of interpreter that does not have a usable DOS shell a hack usually means creating files that contain the parameters needed by the interpreter and having the interpreter get its parameters from the file and then passing it on to the function.
But I am not able to help the original poster with this. I don't know which is the script language being used here. I think it is Python. Buffett is Python, it would make more sense to the in entire job inside the Python rather than shelling out to the Windows DOS command.
So I'm kind of stuck here and I like anybody to step in and try to sort this out.
Another problem here is the original poster is making a big fuss about dating system. It should not be necessary to have to resort to copulating dates of leap years and ordinary years and that kind of stuff. Most programming languages have some way to deal with that without using a lot of script commands trying to figure out which days are leap you days in which years early. Pearson that kind of stuff.
In other words, this treaty should not be a batch program. The program that deals with image transformation should be written in that language, and not have to resort to DOS to create a list of objects to be processed. I have no idea why someone would have told him to do it in batch instead of doing it in the language of the interpreter.
About GDAL
http://en.wikipedia.org/wiki/GDAL
gdal_calculate
Extract Point From Raster in GDAL (http://stackoverflow.com/questions/13439357/extract-point-from-raster-in-gdal)
It is very annoying when people do not say what language the are using.
And even when you know which, there is the question of implementation and library.
version. Here is part of what I said to the OP in a PM.
Presently you can use
the gdal_calculate command directly on command line
... _right?
My research indicates that the command itself is a script and can not be executed in a batch file. Where is you get the bath file?
In windows a limited number of external commands are recognized. Such fhave to be in tghe directory or path and must be one of:
.COM
.EXE
.BAT
.VBS
.XML
Python is not a standard feature in Widows.
Sorry I can not solve this. My mental posers are not a sharp as the used to be.
-
Someone answered this one. Haven't tried this yet because I don't know in which part of this script should I add the gdal_calculate command. Any idea?
@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
-
Still finding ways to solve this. It's giving me a hard time.
-
Sometimes you just need to bite the bullet and hire a contractor to program what you need. We contract from a resource company for a lot of the projects we work on where I work.
-
Is the first post still relevant to the task, or has the task changed?
I had another look and tried to understand what you want to do.
In essence it seems that you have a day number in a year, and you want to figure out which month it corresponds to, for the year in question.
After doing that you have some other files - that have a month in the filename - and you want to run a command line using each file and the correct-month-file.
Is that the actual task, or has it morphed in the following pages?
-
Sometimes you just need to bite the bullet and hire a contractor to program what you need.
If the task can be explained simply then it may be doable. I found the first post quite hard to follow.
-
The tasks always change here in the DOS section...you should know that foxidrive.... ;D
-
The tasks always change here in the DOS section...you should know that foxidrive.... ;D
Hehe It was rather optimistic of me, wasn't it?!
-
Is the first post still relevant to the task, or has the task changed?
I had another look and tried to understand what you want to do.
In essence it seems that you have a day number in a year, and you want to figure out which month it corresponds to, for the year in question.
After doing that you have some other files - that have a month in the filename - and you want to run a command line using each file and the correct-month-file.
Is that the actual task, or has it morphed in the following pages?
Thank you foxidrive.
The task was never changed. I'll explain it again with my very best.
1. The main task/goal is to subtract(as in mathematics; to take, deduct, take from, take out etc.) two images using a gdal_calculate command and perform this in batch process.
- gdal_calculate Purpose: Perform simple tiled raster calculations (AKA "map algebra")from the commandline.
- raster - A raster image, also called a bitmap, is a way to represent digital images.The image is represented in a series of bits of information that translate into pixels on the screen. These pixels form points of color that create an overall finished image. When a raster image is created, the image on the screen is converted into pixels. Each pixel is assigned a specific value that determines its color. This format uses the red, green, blue (RGB) color system. An RGB value of 0,0,0 would be black, and the values go all the way through to 256 for each color, allowing the expression of a wide range of values. In photographs with subtle shading, this can be extremely valuable.
2. There should be an input directory for the input files, an output directory for the output files, second directory for the files that will subtracted from the input files and the processed directory for the files that we're only processed. The input directory and the second directory has numerous files already so this should be set only while the output directory and the processed directory should be made.
3. The template of the file names from the input directory is something like this: C2011060.A1_ABC.ABCD.tif where C represents the dataname, 2011 represents the year of the file either its a leap year or regular year, 060 represents the day/julian date deepending on the year whether its a leap year or regular year and A1_ABC.ABCD.tif is the extension name.
4. The template of the file names from the second directory is something like this: sample_file_month.tif where file represents the dataname and the month which represents the month of the file.
The following are the LEAP YEARS: 2000, 2004, 2008, 2012, 2016, 2020 and so on...
The following are the day/julian dates;
January - 1-31
February - 32-60
March - 61-91
April - 92-121
May - 122-152
June - 153-182
July - 183-213
August - 214-244
September - 245-274
October - 275-305
November - 306-335
December - 336-366
The following are the REGULAR YEARS: 2001-2003, 2005-2007, 2009-2011, 2013-2015 and so on....
The following are the day/julian dates;
January - 1-31
February - 32-59
March - 60-90
April - 91-120
May - 121-151
June - 152-181
July - 182-212
August - 213-243
September - 244-273
October - 274-304
November - 305-334
December - 335-365
For the subtraction/calculation process:
Input Directory: C2011060.A1_ABC.ABCD.tif
If the year in the file name falls on 2003 this means that these file is a regular year. If the julian date in the file name is 001, 002..031 these means that the file is a regular year for the month of january.
If the year in the file name falls on 2005 this means that these file is a regular year. If the julian date in the file name is 032, 033..59 these means that the file is a regular year for the month of february.
If the year in the file name falls on 2011 this means that these file is a regular year. If the julian date in the file name is 121, 122..151 these means that the file is a regular year for the month of may.
If the year in the file name falls on 2014 this means that these file is a regular year. If the julian date in the file name is 335, 336..365 these means that the file is a regular year for the month of december.
AND SO ON. . . . . . .
If the year in the file name falls on 2000 this means that these file is a leap year. If the julian date in the file name is 001, 002..031 these means that the file is a leap year for the month of january.
If the year in the file name falls on 2004 this means that these file is a leap year. If the julian date in the file name is 032, 033..060 these means that the file is a leap year for the month of february.
If the year in the file name falls on 2008 this means that these file is a leap year. If the julian date in the file name is 122, 123..152 these means that the file is a leap year for the month of february.
If the year in the file name falls on 2012 this means that these file is a leap year. If the julian date in the file name is 336, 337..366 these means that the file is a leap year for the month of march.
AND SO ON. . . . . .
Second Directory: sample_file_month.tif
sample_file_jan.tif
sample_file_feb.tif
sample_file_mar.tif
sample_file_apr.tif
sample_file_may.tif
sample_file_jun.tif
sample_file_jul.tif
sample_file_aug.tif
sample_file_sep.tif
sample_file_oct.tif
sample_file_nov.tif
sample_file_dec.tif
If the day in the file name(from input directory) is from 001-031 which belongs to january(leap year and regular year) this will be subtracted(gdal_calculate command) to the sample_file_jan.tif(from second directory).
If the day in the file name(from input directory) is from 032-060 which belongs to february(leap year) this will be subtracted(gdal_calculate command) to the sample_file_feb.tif(from second directory).
If the day in the file name(from input directory) is from 061-091 which belongs to march(leap year) this will be subtracted(gdal_calculate command) to the sample_file_mar.tif(from second directory).
If the day in the file name(from input directory) is from 092-121 which belongs to apri(leap year) this will be subtracted(gdal_calculate command) to the sample_file_apr.tif(from second directory).
If the day in the file name(from input directory) is from 122-152 which belongs to may(leap year) this will be subtracted(gdal_calculate command) to the sample_file_may.tif(from second directory).
AND SO ON. . . . . .
If the day in the file name(from input directory) is from 032-059 which belongs to february(regular year) this will be subtracted(gdal_calculate command) to the sample_file_feb.tif(from second directory).
If the day in the file name(from input directory) is from 060-090 which belongs to march(regular year) this will be subtracted(gdal_calculate command) to the sample_file_mar.tif(from second directory).
If the day in the file name(from input directory) is from 091-120 which belongs to april(regular year) this will be subtracted(gdal_calculate command) to the sample_file_apr.tif(from second directory).
If the day in the file name(from input directory) is from 121-151 which belongs to may(regular year) this will be subtracted(gdal_calculate command) to the sample_file_may.tif(from second directory).
AND SO ON. . . . . .
The result/output from this calculation will be saved to the output directory and those processed files only will be saved to the processed files directory.
Sorry for the longer explanation. I hope I explained it well.
-
Thank you foxidrive.
The task was never changed. I'll explain it again with my very best.
I'm curious why you wrote all that and made no comment on my synopsis?
If you can follow what I wrote in a couple of sentences - was it accurate?
-
For anybody following this, here is some relevant information.
The OP (original poster) is using data that is dated by day of year. He wants to hare a conversion to conventional year, m month and day notation.
This table shows how the conversion is done.
http://disc.gsfc.nasa.gov/julian_calendar.shtml
From PMs exchanged, then OP indicated he may be working in Oceanography with NASA images.
-
I'm curious why you wrote all that and made no comment on my synopsis?
If you can follow what I wrote in a couple of sentences - was it accurate?
I can't follow. Can you explain it again if its okay? Sorry.
For anybody following this, here is some relevant information.
The OP (original poster) is using data that is dated by day of year. He wants to hare a conversion to conventional year, m month and day notation.
This table shows how the conversion is done.
http://disc.gsfc.nasa.gov/julian_calendar.shtml
From PMs exchanged, then OP indicated he may be working in Oceanography with NASA images.
Thank you Geek-9pm for this info.
-
I can't follow. Can you explain it again if its okay? Sorry.
It is kinder to describe which part was hard to follow and which parts you did follow.
In essence it seems that you have a day number in a year, and you want to figure out which month it corresponds to, for the year in question.
After doing that you have some other files - that have a month in the filename - and you want to run a command line using each file and the correct-month-file.
What this means is that:
- You have files, and in the name they have a section which shows the day number in a year.
- You would like to determine the month that the day fell on.
- Then you have another 12 files and each one has the name of a month somewhere in the filename.
- The ultimate task is to match up each file with one of the 12 files - and run the command you showed using the correct pair of files.
Does this describe the task properly?
-
It is kinder to describe which part was hard to follow and which parts you did follow.
What this means is that:
- You have files, and in the name they have a section which shows the day number in a year.
- You would like to determine the month that the day fell on.
- Then you have another 12 files and each one has the name of a month somewhere in the filename.
- The ultimate task is to match up each file with one of the 12 files - and run the command you showed using the correct pair of files.
Does this describe the task properly?
Yes exactly. But I'm a little confused with this:
- You would like to determine the month that the day fell on.
Do you mean determine the month that the files fell on whether they fell on a month from leap year or regular year?
Can you explain it a little more. Sorry again.
-
Do you mean determine the month that the files fell on whether they fell on a month from leap year or regular year?
Your files have the portion that shows the day number of the year
but I don't follow your need to determine a leap year:
Do you want to process files that only fall on a leap year, or perhaps process files that do not fall on a leap year?
Or do you want to process all years?
-
Your files have the portion that shows the day number of the year
but I don't follow your need to determine a leap year:
Do you want to process files that only fall on a leap year, or perhaps process files that do not fall on a leap year?
Or do you want to process all years?
All the files should be process depending on the year day of the file name whether it falls on leap year or regular year. If the day of the file name corresponds to the day from the month where it falls regardless whether its a leap year or regular year then process the files. Maybe the leap year or regular year here will be discarded. Sorry I don't know how to explained it well.
-
All the files should be process depending on the year day of the file name whether it falls on leap year or regular year. If the day of the file name corresponds to the day from the month where it falls regardless whether its a leap year or regular year then process the files. Maybe the leap year or regular year here will be discarded. Sorry I don't know how to explained it well.
Just to clarify - for each file you want to determine the correct month in that year, using the day of year.
A high level computer language will automatically handle leap years and non leap years - and there are batch script that can also handle this.
-
A high level computer language will automatically handle leap years and non leap years - and there are batch script that can also handle this.
I think you are right. (http://www.computerhope.com/forum/index.php/topic,147160.msg918647.html#msg918647)
-
Just to clarify - for each file you want to determine the correct month in that year, using the day of year.
A high level computer language will automatically handle leap years and non leap years - and there are batch script that can also handle this.
All I know is that if the day from the file name(C2011061.A1_ABC.ABCD.tif) is 061, wherein the day 061 falls on the month of march it will be processed/subtracted also to the sample_file_march.tif. I really don't know can you help me?
-
I think you are right. (http://www.computerhope.com/forum/index.php/topic,147160.msg918647.html#msg918647)
Spot on Sqaushman! Ritchie Lawrence has done some fantastic work for scripters - a very talented fellow.
-
This is untested - it displays the command to the screen only.
It is right then you can thank Squashman for supplying the meat of the batch file on the 3rd post in this thread.
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b /on c*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !Month!==01 set Month=JAN
if !Month!==02 set Month=FEB
if !Month!==03 set Month=MAR
if !Month!==04 set Month=APR
if !Month!==05 set Month=MAY
if !Month!==06 set Month=JUN
if !Month!==07 set Month=JUL
if !Month!==08 set Month=AUG
if !Month!==09 set Month=SEP
if !Month!==10 set Month=OCT
if !Month!==11 set Month=NOV
if !Month!==12 set Month=DEC
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
pause
)
echo done
pause
goto :EOF
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
I suppose my month number to month abbreviation code wouldn't work because of the way the expansion works. But other than that, all the code that he needed was given to him here and on DosTips. From there it seemed pretty clear what needed to be done.
-
Foxidrive, I think you missed removing some of my code.
Right above the Ordinal date label.
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
Doesn't hurt anything as it will never be executed.
-
This is untested - it displays the command to the screen only.
It is right then you can thank Squashman for supplying the meat of the batch file on the 3rd post in this thread.
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b /on c*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !Month!==01 set Month=JAN
if !Month!==02 set Month=FEB
if !Month!==03 set Month=MAR
if !Month!==04 set Month=APR
if !Month!==05 set Month=MAY
if !Month!==06 set Month=JUN
if !Month!==07 set Month=JUL
if !Month!==08 set Month=AUG
if !Month!==09 set Month=SEP
if !Month!==10 set Month=OCT
if !Month!==11 set Month=NOV
if !Month!==12 set Month=DEC
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
pause
)
echo done
pause
goto :EOF
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Tried to run and it just says file not found.
By the way, I forgot to modify the gdal_calculate command since the directory has numerous files:
echo gdal_calculate --outfile=%out_path%\C!yearDay!.A1_ABC.ABCD.tif --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif image1=%in_path%\C!yearDay!.A1_ABC.ABCD.tif --extent=INTERSECT
From your script, where should the out_path, in_path, sample_path and processed_files_path directory be inserted?
-
From your script, where should the out_path, in_path, sample_path and processed_files_path directory be inserted?
Isn't that kind of self explanatory from the code that we gave you? It shows in three different places where you need to substitute the path to where your files are and will be going. It is up to you to put the correct paths into your GDAL command.
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
At some point you gotta start being clear on your instructions. None of us have ever used your program so you have to define how it needs to work and define where you where the input and the output is.
-
Isn't that kind of self explanatory from the code that we gave you? It shows in three different places where you need to substitute the path to where your files are and will be going. It is up to you to put the correct paths into your GDAL command.
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
I am pointing out the file names template. Because in this outfile, the output file name has already been set "difference.tif". What if the file names used from the input path will also be the file name of the output? Like the image1 a %%a was just inserted to the last "D:\path\to\minuend\%%a". The file name template should be (C2011061.A1_ABC.ABCD.tif) that is why I modified it into C!yearDay!.A1_ABC.ABCD.tif. Since I have numerous files from the input directory and they have different !yearDay!. The image1 and the outfile will have the same file name template they will just differ with their paths. I hope you're getting my point. And another thing, how will I set the processed files path and move only the processed files to the said directory?
At some point you gotta start being clear on your instructions. None of us have ever used your program so you have to define how it needs to work and define where you where the input and the output is.
I'm so sorry about that. My fault.
gdal_calculate Perform simple tiled raster calculations (AKA "map algebra")from the command line.
--calc : calculation in numpy syntax, rasters specified as using any legal python variable name syntax, band numbers are specified using square brackets (zero based indexing)
--outfile : output filepath
-
I predict 6 pages for this Topic...
-
Foxidrive, I think you missed removing some of my code.
Doesn't hurt anything as it will never be executed.
Yep, thanks, I wasn't paying close attention. This thread does that to you.
I predict 6 pages for this Topic...
I'll bet $2 on 8 pages. ;)
-
I am finding it hard to fathom that you still do not understand the code enough to make modifications to it. We already did the heavy lifting for you. I hate to quote religious sayings but God helps those who help themselves.
I really dont want to see another technical definition of what you are trying to do because it doesnt help at all. If you are smart enough to understand what your software does I think with a little learning and research of your own you should be able to modify the code.
-
This is untested - it displays the command to the screen only.
It is right then you can thank Squashman for supplying the meat of the batch file on the 3rd post in this thread.
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b /on c*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !Month!==01 set Month=JAN
if !Month!==02 set Month=FEB
if !Month!==03 set Month=MAR
if !Month!==04 set Month=APR
if !Month!==05 set Month=MAY
if !Month!==06 set Month=JUN
if !Month!==07 set Month=JUL
if !Month!==08 set Month=AUG
if !Month!==09 set Month=SEP
if !Month!==10 set Month=OCT
if !Month!==11 set Month=NOV
if !Month!==12 set Month=DEC
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
pause
)
echo done
pause
goto :EOF
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Hi sorry for bothering you again. I tried to modified the script and run but it only calculate one image the rest of the images wasn't processed and I can't seem to figure out what is the problem. But I know I'm getting close. Another thing how will I moved only the processed files to the processed_path? Thank you!
This is the error:
C:\Users\Name\Desktop> gdalcalc.bat
A2014336.L2_LAC.SeAHABS.tif matches to 2014-12-02
Running calculation
0...10..Saving output
.20...30...40...50...60...70...80...90...100 - done.
C:\Users\Name\Desktop>(
set "year= C2011060.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo C2011060.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
if !month! == 01 set Month=jan
if !month! == 02 set Month=feb
if !month! == 03 set Month=mar
if !month! == 04 set Month=apr
if !month! == 05 set Month=may
if !month! == 06 set Month=jun
if !month! == 07 set Month=jul
if !month! == 08 set Month=aug
if !month! == 09 set Month=sep
if !month! == 10 set Month=oct
if !month! == 11 set Month=nov
if !month! == 12 set Month=dec
gdal_calculate --outfile=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!month!.tif --image1=%in_path%\%%a --extent=INTERSECT
)
Invalid attempt to call batch label outside of batch script.
C2011060.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
Modified:
@echo off
setlocal enabledelayedexpansion
set "in_path=E:\Proc\Mer"
set "out_path=E:\Proc\Abcde"
set "sample_path=E:\Proc\Me"
set "proc_path=E:\Proc\Proc_Mer_Fi"
md %out_path%
md %proc_path%
cd /d "%in_path%"
for /f "tokens=* delims=" %%a in ('dir /b /on ????????*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !month!==01 set Month=jan
if !month!==02 set Month=feb
if !month!==03 set Month=mar
if !month!==04 set Month=apr
if !month!==05 set Month=may
if !month!==06 set Month=jun
if !month!==07 set Month=jul
if !month!==08 set Month=aug
if !month!==09 set Month=sep
if !month!==10 set Month=oct
if !month!==11 set Month=nov
if !month!==12 set Month=dec
gdal_calculate --outfile=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!month!.tif --image1=%in_path%\%%a --extent=INTERSECT
)
echo done
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
Error:
RuntimeError: `E:\Proc\Me\sample_file_!Month!.tif' does not exist in the file system,and is not recognised as a supported dataset name.
I think the !Month! is causing the error because it couldn't find a file with sample_file_!Month!.tif from the %sample_path% directory. When I tried to modify it with this %sample_path%\sample_file_!jan! it run(but with also an error which is the Invalid attempt thing) since I already changed the !Month! to a specific month which is January. How to fix that since I have 12 months?
-
How did you launch this batch file?
I often see people pasting batch code into the cmd prompt these days - it makes me weep. ;)
Is gdal_calculate a batch file too?
-
Another thing how will I moved only the processed files to the processed_path? Thank you!
http://lmgtfy.com/?q=batch+move+files
-
How did you launch this batch file?
I often see people pasting batch code into the cmd prompt these days - it makes me weep. ;)
Is gdal_calculate a batch file too?
It is a Python script.
https://pypi.python.org/pypi/gdal-calculations
Author: Luke Pinner
Home Page: https://code.google.com/p/gdal-calculations
Download URL: https://bintray.com/lukepinnerau/generic/gdal-calculations/_latestVersion
License: MIT
Requires numpy, gdal
-
I think what Foxidrive is inferring is that you can't name the batch file the same as the gdal_calculate command.
-
I wasn't very clear, sorry.
This error message from unknown's post is something that may be related to pasting batch code into a cmd prompt.
Invalid attempt to call batch label outside of batch script.
It is a Python script.
https://pypi.python.org/pypi/gdal-calculations
Thanks, that clarifies that it's not part of that problem.
-
How did you launch this batch file?
I often see people pasting batch code into the cmd prompt these days - it makes me weep. ;)
Is gdal_calculate a batch file too?
Pasted it into an editor and then saved it as sample.bat in the desktop and call the bat file there from the cmd prompt or sometimes from the windows powershell. Is batch strict with white spaces? Is that why I'm getting this error?
-
I predict 6 pages for this Topic...
Getting closer!
Pasted it into an editor and then saved it as sample.bat in the desktop and call the bat file there from the cmd prompt or sometimes from the windows powershell. Is batch strict with white spaces? Is that why I'm getting this error?
Batch code handles white space well in most of it, but not well at all in other places.
Did you ever say where the files were located? Are they on your desktop?
The fact that you add powershell into this thread (for the first time AFAIK) just insults everyone who has replied,
because you are doing things that you haven't revealed.
If you had to pay for this support then the person getting your munny would need to know every single detail about the files, locations, hard drives or network drives, how they were processed, have copies of the files to test, and know how they were being launched.
They would need access to the machine involved, or a copy of the data trees.
Here we only know what you choose to tell us - and without the information it's like baking a pie with no recipe.
-
I did get a bit annoyed, didn't I?
-
It's all good...
-
Here is what I propose.
1) Tell us where to download the software you use and tell us how to install and configure it.
2) Post a full compliment of test files that will handle every scenario on dropbox for us to test with.
3) Explain in exact detail what folder you have your input files in.
4) Explain in exact detail what folder the output files need to go into.
5) Explain in exact detail what folder the processed files need to go into.
6) Explain in exact detail how the program works for processing just a single file. Use one of the test files you provided as an example.
7) Explain in exact detail what your expected output should be based on the test files you have provided us.
If anyone else feels I have left anything out for this testing scenario please add to the list.
-
Getting closer!
Batch code handles white space well in most of it, but not well at all in other places.
Did you ever say where the files were located? Are they on your desktop?
The fact that you add powershell into this thread (for the first time AFAIK) just insults everyone who has replied,
because you are doing things that you haven't revealed.
I just answered based from what I understand in your question. Guessed I didn't get it. Sorry for insulting you I'm just getting a hard time understanding this. I'm really slow in understanding things.
How did you launch this batch file?
That's why powershell was added. Because every time I run, call or launch a batch file I can used either cmd prompt or windows powershell right? I saved the bat file to the desktop.
You said:
This error message from unknown's post is something that may be related to pasting batch code into a cmd prompt.
That is why I asked if the batch processing is strict with the white spaces. Because I got that "Invalid attempt to call batch label outside of batch script." And thought of maybe the pasting did that and white spaces has something to do with it.
-
Here is what I propose.
1) Tell us where to download the software you use and tell us how to install and configure it.
2) Post a full compliment of test files that will handle every scenario on dropbox for us to test with.
3) Explain in exact detail what folder you have your input files in.
4) Explain in exact detail what folder the output files need to go into.
5) Explain in exact detail what folder the processed files need to go into.
6) Explain in exact detail how the program works for processing just a single file. Use one of the test files you provided as an example.
7) Explain in exact detail what your expected output should be based on the test files you have provided us.
If anyone else feels I have left anything out for this testing scenario please add to the list.
Thanks squashman for this proposal but that would be too much. Honestly, I really want to learn. I want to help myself. I want to be like you here. Creating codes for you was that simple. I want to figure out what was the error, what should I do but I really just can't do it maybe I'm just really dumb. :'(
-
This is untested - it displays the command to the screen only.
It is right then you can thank Squashman for supplying the meat of the batch file on the 3rd post in this thread.
Yes. The code only displays the command to the screen only. Which says the file matches with this file. But never executed the calculation.
-
Thanks squashman for this proposal but that would be too much. Honestly, I really want to learn. I want to help myself. I want to be like you here. Creating codes for you was that simple. I want to figure out what was the error, what should I do but I really just can't do it maybe I'm just really dumb. :'(
We have basically spoon fed you basically everything. I am not sure how you are learning. I am sure you have heard the saying, "give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime".
-
Yes. The code only displays the command to the screen only. Which says the file matches with this file. But never executed the calculation.
Correct. And since you said you wanted to learn, tell me why it did not execute the command and only displayed it on the screen.
-
We have basically spoon fed you basically everything. I am not sure how you are learning. I am sure you have heard the saying, "give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime".
Yeah I've heard that saying. Thank you!
-
Correct. And since you said you wanted to learn, tell me why it did not execute the command and only displayed it on the screen.
Yes I really want to. Maybe because it's missing some command?A command which will make it execute? And it just call the ordinal date and echoed that is why it was displayed only on the screen.
-
Recent post elsewhere.
http://gis.stackexchange.com/questions/129487/how-to-subtract-rasters-using-the-gdal-calculate-command
Is this what the OP is doing?
just want to know how to subtract two raster using gdal_calculate command? Or what is the proper way of subtracting using this? Any idea would be greatly appreciated.
Note: gdal_calc is different from gdal_calculate.py. The raster I am using have different dimensions.
-
Yes I really want to. Maybe because it's missing some command?A command which will make it execute? And it just call the ordinal date and echoed that is why it was displayed only on the screen.
This just tells me that the several weeks we have been helping, you have not bothered to learn or understand any of the code we have supplied you on this forum or the other forums we have helped you on. At this point you have no other option but to accept my offer to do this for you by providing the information I requested in my previous post.
-
Look on the bright side...we made it to Page 6....
-
Look on the bright side...we made it to Page 6....
We might as well turn this website into a "Sports Betting" site. Then at least I could make some money for all my hard work. I will take the over on 8 pages.
-
OK...i'll take the Under....i can lock the Thread...:P
-
OK...i'll take the Under....i can lock the Thread...:P
You are just like Vegas. Stacking the odds in your favor. You should consider switching jobs. ;D
-
Not a bad idea...
-
This just tells me that the several weeks we have been helping, you have not bothered to learn or understand any of the code we have supplied you on this forum or the other forums we have helped you on. At this point you have no other option but to accept my offer to do this for you by providing the information I requested in my previous post.
Can you teach me more please? :'( I'm trying my best to understand the code you gave me. What should be answer to your question? What is the additional command to make the calculation execute instead of just displaying it on the screen? I can't understand codes that easy and immediately.
-
Show me the line of code that Foxidrive posted for you that runs your gdal_calculate command.
-
Show me the line of code that Foxidrive posted for you that runs your gdal_calculate command.
echo gdal_calculate --outfile=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
-
echo gdal_calculate --outfile=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
What is the first word in that line of code?
-
What is the first word on that line of code?
The first word is echo. It display a string of characters on screen.
-
The first word is echo. It display a string of characters on screen.
So if you want your gdal_calculate command to execute, what do you think you would need to remove from that line of code to make gdal_calculate execute?
-
So if you want your gdal_calculate command to execute, what do you think you would need to remove from that line of code to make gdal_calculate execute?
I think I would need to remove the echo to execute. Does echo really affect lines of code or command from executing whereas it just prints string of characters on screen?
-
I think I would need to remove the echo to execute. Does echo really affect lines of code or command from executing whereas it just prints string of characters on screen?
BINGO!
-
BINGO!
Removed the echo and run the batch file. It calculate the first image but the rest of the file was an error. It says:
C:\path\to\bat\file>test.bat
C2011060.A1_ABC.ABCD.tif matches to 2011-03-01
Running calculation
0...10..Saving output
.20...30...40...50...60...70...80...90. ..100 - done.
Press any key to continue . . .
C:\path\to\bat\file>(
set "year=C2011061.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo C2011061.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
gdal_calculate --out=%out_path%\C2011061.A1_ABC.ABCD.tif --calc="((image1-image2)" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\C2011061.A1_ABC.ABCD.tif --extent=INTERSECT
pause
)
Invalid attempt to call batch label outside of batch script.
C2011061.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
RuntimeError: `D:\Path\sample_file_!Month!.tif' does not exist in the file system
,
and is not recognised as a supported dataset name.
Press any key to continue . . .
C:\path\to\bat\file>(
set "year=C2011062.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo C2011062.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
gdal_calculate --out=%out_path%\C2011062.A1_ABC.ABCD.tif --calc="((image1-image2)" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\C2011062.A1_ABC.ABCD.tif --extent=INTERSECT
pause
)
Invalid attempt to call batch label outside of batch script.
C2011062.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
RuntimeError: `D:\Path\sample_file_!Month!.tif' does not exist in the file system
,
and is not recognised as a supported dataset name.
Press any key to continue . . .
-
Re-post the entire batch file you are using. I see you made some changes to the code Foxidrive posted.
-
Re-post the entire batch file you are using. I see you made some changes to the code Foxidrive posted.
This is what Foxidrive posted:
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b /on c*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !Month!==01 set Month=JAN
if !Month!==02 set Month=FEB
if !Month!==03 set Month=MAR
if !Month!==04 set Month=APR
if !Month!==05 set Month=MAY
if !Month!==06 set Month=JUN
if !Month!==07 set Month=JUL
if !Month!==08 set Month=AUG
if !Month!==09 set Month=SEP
if !Month!==10 set Month=OCT
if !Month!==11 set Month=NOV
if !Month!==12 set Month=DEC
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
pause
)
echo done
pause
goto :EOF
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
This is what I am using:
@echo off
setlocal enabledelayedexpansion
set "in_path=D:\Input"
set "out_path=D:\Output"
set "sample_path=D:\Sample"
set "proc_path=D:\Processed_Files"
md %out_path%
md %proc_path%
cd /d "%in_path%"
for /f "delims=" %%a in ('dir /b /on ????????*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !Month!==01 set Month=jan
if !Month!==02 set Month=feb
if !Month!==03 set Month=mar
if !Month!==04 set Month=apr
if !Month!==05 set Month=may
if !Month!==06 set Month=jun
if !Month!==07 set Month=jul
if !Month!==08 set Month=aug
if !Month!==09 set Month=sep
if !Month!==10 set Month=oct
if !Month!==11 set Month=nov
if !Month!==12 set Month=dec
gdal_calculate --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
pause
)
echo done
pause
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
All the error output you posted above really doesn't make any sense at all. I tried searching for any person who has ever tried to batch script the GDAL_CALCULATE command and nobody else has done it. The batch code is as sound as can be. I see no technical flaws in it. So it has to be something with the python script that is screwing things up. Since you don't want us trying to test this process for you on our own computers our hands are pretty much tied.
You might want to just try and have someone write a python program that does the same thing as the batch file above.
My last and final suggestions is to try and execute the python script using the full path to the python install and the full path to the gdal_calculate.py script. Make sure you use the .py extension for the script and the .exe extension for the python executable.
Try each of these one at a time.
gdal_calculate.py --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
"C:\path to script\gdal_calculate.py" --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
"C:\path to python\python.exe" "C:\path to script\gdal_calculate.py" --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
CALL "C:\path to script\gdal_calculate.py" --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
CALL "C:\path to python\python.exe" "C:\path to script\gdal_calculate.py" --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_!Month!.tif --image1=%in_path%\%%a --extent=INTERSECT
-
Here are my assumptions about the errors.
This error is coming from the cmd.exe processor. Which makes no sense. The only real way to replicate this error and the output that came before it would be to PIPE the contents of the batch file to CMD.EXE. How this is happening is beyond me. There is nothing in the batch file that would cause this.
Invalid attempt to call batch label outside of batch script.
C2011062.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
But this error is actually coming from the python interpreter.
RuntimeError: `D:\Path\sample_file_!Month!.tif' does not exist in the file system
,
and is not recognised as a supported dataset name.
I could be wrong but seems to make logical sense to me.
-
Here are my assumptions about the errors.
This error is coming from the cmd.exe processor. Which makes no sense. The only real way to replicate this error and the output that came before it would be to PIPE the contents of the batch file to CMD.EXE. How this is happening is beyond me. There is nothing in the batch file that would cause this.
But this error is actually coming from the python interpreter.
I could be wrong but seems to make logical sense to me.
I have tried to modified again the script into this:
@echo off
setlocal enabledelayedexpansion
set "in_path=D:\Input"
set "out_path=D:\Output"
set "sample_path=D:\Sample"
set "proc_path=D:\Processed_Files"
md %out_path%
md %proc_path%
cd /d "%in_path%"
for /f "delims=" %%a in ('dir /b /on ????????*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
gdal_calculate --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_mar.tif --image1=%in_path%\%%a --extent=INTERSECT
if !Month!==01 set Month=jan
if !Month!==02 set Month=feb
if !Month!==03 set Month=mar
if !Month!==04 set Month=apr
if !Month!==05 set Month=may
if !Month!==06 set Month=jun
if !Month!==07 set Month=jul
if !Month!==08 set Month=aug
if !Month!==09 set Month=sep
if !Month!==10 set Month=oct
if !Month!==11 set Month=nov
if !Month!==12 set Month=dec
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
And specify the sample_path_!Month!.tif into sample_path_mar.tif. The bat file run well without any error like Invalid attempt to call batch label outside of batch script. and RuntimeError: `D:\Path\sample_file_!Month!.tif' does not exist in the file system, and is not recognised as a supported dataset name. What does this mean? Does the problem lies within the !Month!? Though it doesn't based with the label :Ordinaltodate anymore.
Here is the output:
C:\path\to\bat\file>sample.bat
Running calculation
0...10...20...30...40...50...60...70...80...90Saving output
...100 - done.
C:\path\to\bat\file>(
set "year=C2011061.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
gdal_calculate --calc="((image1-image2))" --outfile=D:\Output\C2011061.A1_ABC.ABCD.tif --image1=D:\Input\C2011061.A1_ABC.ABCD.tif --image2=D:\sample\mean_chla_mar.tif --extent=INTERSECT
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
)
Running calculation
0...10...20...30...40...50...60...70...80..Saving output
.90...100 - done.
C:\path\to\bat\file>(
set "year=C2011062.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
gdal_calculate --calc="((image1-image2))" --outfile=D:\Output\C2011062.A1_ABC.ABCD.tif --image1=D:\Input\C2011062.A1_ABC.ABCD.tif --image2=D:\sample\mean_chla_mar.tif --extent=INTERSECT
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
)
Running calculation
0...10...20...30...40...50...60...70.Saving output
..80...90...100 - done.
C:\Users\Oogway\Desktop>test.bat
A subdirectory or file D:\Test\Anomaly already exists.
A subdirectory or file D:\Test\Processed_Merged already exists.
Running calculation
0...10...20...30...40...50...60...70...80...90Saving output
...100 - done.
C:\Users\Oogway\Desktop>(
set "year=A2014275.L2_LAC.SeAHABS"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
gdal_calculate --calc="((ds1.astype(numpy.float32))-(ds2.astype(numpy.float32)))" --outfile=D:
\Test\Anomaly\A2014275.L2_LAC.SeAHABS.tif --ds1=D:\Test\Merged\A2014275.L2_LAC.SeAHABS.tif --ds
2=D:\Test\Mean\mean_chla_oct.tif --extent=MAXOF --nodata --overwrite
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
)
Running calculation
0...10...20...30...40...50...60...70...80..Saving output
.90...100 - done.
C:\Users\Oogway\Desktop>(
set "year=A2014276.L2_LAC.SeAHABS"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
gdal_calculate --calc="((ds1.astype(numpy.float32))-(ds2.astype(numpy.float32)))" --outfile=D:
\Test\Anomaly\A2014276.L2_LAC.SeAHABS.tif --ds1=D:\Test\Merged\A2014276.L2_LAC.SeAHABS.tif --ds
2=D:\Test\Mean\mean_chla_oct.tif --extent=MAXOF --nodata --overwrite
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
)
Running calculation
0...10...20...30...40...50...60...70...80...90Saving output
...100 - done.
-
I have no idea how you are getting that much Verbose output from the Batch file when ECHO is OFF.
Your output is also not reflecting what is in the batch file either. So I have no idea what you are really doing.
You definitely removed stuff from the batch file that you should not have.
I am pretty much done helping you because I can't control what you are doing. I offered to literally do this for you. But you have refused that help. That is the only way it is going to get done because you obviously do not know what you are doing.
-
Someone suggested to try debugging the bat file using this: Debugging your batch files. (http://www.robvanderwoude.com/battech_debugging.php)
Tried and this is the result.
C:\path\to\bat\file>setlocal enabledelayedexpansion
C:\path\to\bat\file>set "in_path=D:\Input"
C:\path\to\bat\file>set "out_path=D:\Output"
C:\path\to\bat\file>set "sample_path=D:\Sample"
C:\path\to\bat\file>set "proc_path=D:\Processed_Files"
C:\path\to\bat\file>md D:\Output
C:\Users\Oogway\Desktop>md D:\Processed_Files
C:\path\to\bat\file>>cd /d "D:\Output"
D:\Output>for /F "delims=" %a in ('dir /b /on ????????*.tif') do (
set "year=%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %a matches to !yy!-!month!-!dd!
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
gdal_calculate --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_mar.tif --image1=%in_path%\%%a --extent=INTERSECT
)
D:\Output>(
set "year=C2014274.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo C2014274.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
gdal_calculate --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_mar.tif --image1=%in_path%\%%a --extent=INTERSECT
)
D:\Output>setlocal ENABLEEXTENSIONS
D:\Output>for /F "tokens=1-2" %a in ('echo/2014 274') do set /a yy=%a,o=1%b%1000
D:\Output>set /a yy=2014,o=1274%1000
D:\Output>set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
D:\Output>set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
D:\Output>set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
D:\Output>set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
D:\Output>set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
D:\Output>(if 10 LSS 10 set mm=010 ) & (if 1 LSS 10 set dd=01 )
D:\Output>endlocal & set yy=2014 & set month=10 & set dd=01 & goto :EOF
C2014274.A1_ABC.ABCD.tif matches to 2014-10-01
Running calculation
0...10...20...30...40...50...60...70...80...90Saving output
...100 - done.
C:\path\to\bat\file>(
set "year=C2014275.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo C2014275.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
gdal_calculate --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_mar.tif --image1=%in_path%\%%a --extent=INTERSECT
)
[b]The system cannot find the batch label specified - OrdinalToDate
C2014275.A1_ABC.ABCD.tif matches to --[/b]
RuntimeError: `D:\Sample\.tif' does not exist in the file system,
and is not recognised as a supported dataset name.
C:\path\to\bat\file>(
set "year=C2014276.A1_ABC.ABCD"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo C2014276.A1_ABC.ABCD.tif matches to !yy!-!month!-!dd!
if !Month! == 01 set Month=jan
if !Month! == 02 set Month=feb
if !Month! == 03 set Month=mar
if !Month! == 04 set Month=apr
if !Month! == 05 set Month=may
if !Month! == 06 set Month=jun
if !Month! == 07 set Month=jul
if !Month! == 08 set Month=aug
if !Month! == 09 set Month=sep
if !Month! == 10 set Month=oct
if !Month! == 11 set Month=nov
if !Month! == 12 set Month=dec
gdal_calculate --out=%out_path%\%%a --calc="((image1-image2))" --image2=%sample_path%\sample_file_mar.tif --image1=%in_path%\%%a --extent=INTERSECT
)
[b]Invalid attempt to call batch label outside of batch script.
A2014276.L2_LAC.SeAHABS.tif matches to !yy!-!month!-!dd![/b]
RuntimeError: `D:\Sample\!Month!.tif' does not exist in the file system,
and is not recognised as a supported dataset name.
-
This is untested - it displays the command to the screen only.
It is right then you can thank Squashman for supplying the meat of the batch file on the 3rd post in this thread.
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b /on c*.tif ') do (
set "year=%%~na"
set "daynum=!year:~5,3!"
set "year=!year:~1,4!"
call :OrdinalToDate !year! !daynum! yy month dd
echo %%a matches to !yy!-!month!-!dd!
if !Month!==01 set Month=JAN
if !Month!==02 set Month=FEB
if !Month!==03 set Month=MAR
if !Month!==04 set Month=APR
if !Month!==05 set Month=MAY
if !Month!==06 set Month=JUN
if !Month!==07 set Month=JUL
if !Month!==08 set Month=AUG
if !Month!==09 set Month=SEP
if !Month!==10 set Month=OCT
if !Month!==11 set Month=NOV
if !Month!==12 set Month=DEC
echo gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1+image2))" --image2=D:\path\to\subtrahend\sample_file_!Month!.tif image1=D:\path\to\minuend\%%a --extent=INTERSECT
pause
)
echo done
pause
goto :EOF
@echo off&setlocal
call :OrdinalToDate %1 %2 yy mm dd
echo/%yy%-%mm%-%dd%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:OrdinalToDate %year% %doy% yy mm dd
::
:: By: Ritchie Lawrence, 2002-09-29. Version 1.0
::
:: Func: Returns a calendar date from an ISO 8601 Ordinal date.
:: For NT4/2K/XP.
::
:: Args: %1 year component to be converted, 4 digits (by val)
:: %2 day of year component to be converted, 001 to 366 (by val)
:: %3 var to receive year, 4 digits (by ref)
:: %4 var to receive month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive day of month, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%a in ('echo/%1 %2') do set /a yy=%%a,o=1%%b%%1000
set /a z=14-1,z/=12,y=yy+4800-z,m=1+12*z-3,j=153*m+2
set /a j=j/5+1+y*365+y/4-y/100+y/400-2432046,j+=o-1
set /a a=j+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %3=%yy%&set %4=%mm%&set %5=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Hi foxidrive, if it's okay, can you explain to me the piece/s of code for every line starting from the for /f "delims=" %%a in ('dir /b /on c*.tif ') do (
up to the last piece of code just for me to understand everything most importantly those numbers, "year=%%~na", "daynum=!year:~5,3!", and "year=!year:~1,4!". Thank you!