here it is:
pro modisterrandvitimestack, infiledirectory, infilename, startyear, startday, endyear, endday, fileextension, outfiledirectory, suffix
; By Guy Serbin, ASRC Management Services, USDA/FAS Office of Global Analysis, 1400 Independence Ave. SW, Washington, DC 20250.
; This creates a MODIS Terra NDVI image stack. Data are assumed to be in 8-bit format.
; This currently only works for images of the same spatial extent, dimensions, etc.
; This will only work for TIFF files from Pekko, without any name changes.
; The output file will be in ENVI Standard format with a ".DAT" file extension.
; Variables:
; infiledirectory - path information for where NDVI images reside.
; infilename - name of files without date or file extension information. Must be the same for all input images.
; startyear - year in which the first image was collected.
; startday - Julian day for the first image collected.
; endyear - year in which the last image was collected.
; endday - Julian day for the last image collected.
; fileextension – file extension, e.g., “img”, “tif”, “dat”, etc.
; outfiledirectory - directory in which NDVI anomaly data are to be saved.
; suffix - this should appear either blank '' or as '.v1' or '.v2' should the MODIS image have '.v1' or '.v2' prior to the tif extension
datevec=[1, 17, 33, 49, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 273, 289, 305, 321, 337, 353]
; load in year to be compared to average
if startyear gt endyear then begin
print, 'Start year is greater than end year, please correct. The start year must be less than or equal to the end year.'
return
endif
if startyear lt 2000 or endyear lt 2000 then begin
print, 'All MODIS Terra NDVI data are available from 2000 and on. Please correct.'
return
endif
years=endyear-startyear+1
startdayloctemp=where(datevec eq startday)
enddayloctemp=where(datevec eq endday)
startdayloc=startdayloctemp[0]
enddayloc=enddayloctemp[0]
if startdayloc eq -1 or enddayloc eq -1 then begin
if startdayloc eq -1 then print, 'Invalid start date, see
http://pekko.geog.umd.edu/usda/test/data.php for actual dates.'
if enddayloc eq -1 then print, 'Invalid end date, see
http://pekko.geog.umd.edu/usda/test/data.php for actual dates.'
return
endif
if years eq 1 then totalfiles = enddayloc-startdayloc+1 else $
totalfiles = 24-startdayloc+enddayloc+(years-2)*23
print, totalfiles
dates=findgen(totalfiles)
file_ids=intarr(totalfiles)
currentyear=startyear
currentloc=startdayloc
missingfiles=0
;load files to be stacked
dims=intarr(5,totalfiles)
for i=0,totalfiles-1 do begin
if (datevec[currentloc]