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.