|||
最近需要处理连续10年的MODIS LAI产品数据(MOD15A2)。根据自己的需求,写了一个MS-DOS批处理小程序,主要解决的问题是:YEAR和DOY两重循环,并将YEAR和DOY连接成YEAR+DOY的形式(如2001001)用以搜索符合条件的待拼接文件。
需要注意的地方(代码中红色标注处):
1、用set设置数据文件夹环境变量时,等号的前后都不能出现空格。如果等号前面有空格,则环境变量名称变为“MRTDATADIR ”,如果等号后有空格,则数据文件夹路径前面多出空格会导致MRT工具找不到相关数据文件。
2、DOY的设置采用了“曲线救国”方案,即先设置为10001的形式,然后截取最后三个字符作为标准DOY。
3、DOS下的字符截取操作:%DOY:~-3%表示截取DOY变量的最后三个字符,等效于%DOY:~4,3%,表示从DOY变量的第5个字符开始截取3个字符。
4、进行YEAR的循环时需要对DOY进行初始化。
代码如下:
@echo off
rem **This is a MS-DOS batch file to do multi-yearly mosaicing and resampling preprocessing by using MRT
rem **author: pengbin, institute of remote sensing and digital earth, CAS
rem **Memo: developed at May 7th, 2013
rem **Set the MRTDATADIR environmental var to the MRT data directory.
set MRTDATADIR=D:MOD15A2_h24-26_v4-5
rem **set batch data start time
set /a YEAR = 2001
set /a DOY = 10001
rem **set batch data end time
set /a ENDYEAR = 2010
set /a ENDDOY = 10365
:start
if %YEAR% leq %ENDYEAR% (goto ORDER1) else exit
:ORDER1
if %DOY% leq %ENDDOY% (goto ORDER2) else (
set /a YEAR = %YEAR% +1
set /a DOY = 10001
goto start
)
:ORDER2
set /a DAY = %YEAR%%DOY:~-3%
rem **save the file name into a notepad
dir %MRTDATADIR%*%DAY%.*.hdf/a/b/s > %MRTDATADIR%MOSAICINPUT.TXT
rem **execute mosaic
mrtmosaic.exe -i %MRTDATADIR%MOSAICINPUT.TXT -o %MRTDATADIR%MOSAIC_TMP.hdf
rem **execute resample
resample.exe -p %MRTDATADIR%MOD15A2.prm -i %MRTDATADIR%MOSAIC_TMP.hdf -o %MRTDATADIR%%DAY%.tif
set /a DOY = %DOY% + 8
goto ORDER1
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-4 01:39
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社