a = '20120203'year = fix(strmid(a,0,4))month = fix(strmid(a,4,2))day = fix(strmid(a,6,2))file = 'C:\Users\Administrator\Desktop\青藏高原雪深数据集1961-2013\青藏高原雪深数据集1961-2013\Tibetan_Plateau_Snow_Depth_1961-2013\52868.txt'cnt = file_lines(file);make_array int int int;openr,lun,file,/get_lunopenr,lun,file,/get_lunfor i = 0 , cnt-1 do beginreadf,lun,c,y,m,d,ddif fix(y) eq year and fix(m) eq month and fix(d) eq day then beginprint,ddendifendforfree_lun,lun
单个读取的时候就没错批处理循环就会报错
1、解决报错
2、降低复杂度
bug消失,不知道之前那种为啥一直报错,应该是读取 readf,lun,c,y,m,d,dd这句的问题
a = '20120203'year = fix(strmid(a,0,4))month = fix(strmid(a,4,2))day = fix(strmid(a,6,2))file = 'C:\Users\Administrator\Desktop\青藏高原雪深数据集1961-2013\青藏高原雪深数据集1961-2013\Tibetan_Plateau_Snow_Depth_1961-2013\'files = file_search(file,'*.txt',count=cnt)for i=0,cnt-1 do beginopenr,lun,files[i],/get_lunn = file_lines(files[i])temp=''for j = 0 , n-1 do beginreadf,lun,temphelp,temp[0]print,temp[0];readf,lun,c,y,m,d,ddtem = strsplit(temp[0],' ',/extract)help,tem; if fix(y) eq year and fix(m) eq month and fix(d) eq day then begin
; print,dd
; endif; if fix(temp[1]) eq year and fix(temp[2]) eq month and fix(temp[3]) eq day then begin
; print,temp[4]
; endifendforfree_lun,lunendfor
这种是直接按行读取,出来是字符串数组,取第一个进行分割处理
还有一种想法是全部读取到数组中,然后进行查找
还有就是修改readf,lun,c,y,m,d,dd,控制一下格式
pro tib_testCOMPILE_OPT IDL2,hiddene=envi(/headless)
; file = 'E:\data\BT\bt_500\FY3B_MWRID_GBAL_L1_20130102_2020_010KM_MS_result.tif'
; ;E:\data\wendu_lc_500_dem\A20121220.tif
; ;根据bt的日期构造温度文件名,打开,站点坐标转温度文件坐标 xf_t yf_t 文件号fid_bt
; ;下面站点循环构造dim_t
; t_name = strsplit(file,'_',/extract)
; t_file = 'E:\data\wendu_lc_500_dem\A'+t_name[5]+'.tif'
; temp = t_name[5]
; print,strmid(temp,0)
; print,t_file
; envi_open_file,t_file,r_fid = t_fid
; print,t_fid ; fn='C:\Users\Administrator\Desktop\tibtation.csv';
; data=READ_CSV(fn,count=nsta,header=header);
; point_fid=data.(0);
; id=data.(1);站点纬度
; print,id[0]
; help,id; pos = 0
; cnt = replicate(0,20)
; path = 'C:\Users\Administrator\Desktop\青藏高原雪深数据集1961-2013\青藏高原雪深数据集1961-2013\Tibetan_Plateau_Snow_Depth_1961-2013'
; files = file_search(path,'*.txt',count=n)
; print,n
; for i = 0 , n - 1 do begin
; ;openr,lun,files[i],/get_lun
; ;print,files[i],file_lines(files[i])
; if file_lines(files[i]) eq 19358 then begin
; cnt[pos] =
; endif
; endfor
; file = 'C:\Users\Administrator\Desktop\青藏高原雪深数据集1961-2013\青藏高原雪深数据集1961-2013\Tibetan_Plateau_Snow_Depth_1961-2013\52868.txt';openr,lun,file,/get_lun;file_lines;free_lun,luna = '20120203'year = fix(strmid(a,0,4))month = fix(strmid(a,4,2))day = fix(strmid(a,6,2))file = 'C:\Users\Administrator\Desktop\青藏高原雪深数据集1961-2013\青藏高原雪深数据集1961-2013\Tibetan_Plateau_Snow_Depth_1961-2013\'files = file_search(file,'*.txt',count=cnt)for i=0,cnt-1 do beginopenr,lun,files[i],/get_lunn = file_lines(files[i]);temp=''for j = 0 , n-1 do begin;readf,lun,temp;help,temp[0];print,temp[0]; readf,lun,format='(i6,i5,i3,i3,i1)',c,y,m,d,dd
; print,c,y,m,d,ddreadf,lun,c,y,m,d,dd;print,c,y,m,d,dd;tem = strsplit(temp[0],' ',/extract);help,temif fix(y) eq year and fix(m) eq month and fix(d) eq day then beginprint,ddendif; if fix(temp[1]) eq year and fix(temp[2]) eq month and fix(temp[3]) eq day then begin
; print,temp[4]
; endifendforfree_lun,lunendfor;make_array int int int;openr,lun,file,/get_lunend
。。。知道了
bug是long