array_indices
valid = where(lat ge 60.,count_valid) ;
if count_valid gt 0 then begin
ind = array_indices(lat,valid)
x = ind[0,*]
y = ind[1,*]
判断文件是否存在 file_test
result = file_test(file)
result = 1 文件存在
result = 0 文件
IDL画直方图
个数统计直方图
;dif为我们要统计的参数
hist = HISTOGRAM(dif,binsize=0.05)
x_range=FINDGEN(N_ELEMENTS(hist))*0.05+min(dif)
his = barplot(x_range,hist, fill_color='royal blue',XTITLE = '℃',YTITLE='Number',title = 'dif')
his.save,file_path+'zhifangtu.png'
概率统计直方图
;cnt为dif的个数,即统计该范围的个数后除以总个数,为概率值。
;cnt要用float,否则得到的将是个整数
hist = HISTOGRAM(dif,binsize=0.05)/float(cnt)
x_range=FINDGEN(N_ELEMENTS(hist))*0.05+min(dif)
his = barplot(x_range,hist, fill_color='royal blue',XTITLE = '℃',YTITLE='Percent',title = 'dif')
his.save,file_path+'zhifangtu.png'
读写txt文件
读取txt文件
files_path = 'D:\02周报告\00论文\match\2\'
file = file_search(files_path,'avr_P*.txt',count = file_num)
all_data = []
for num = 0,file_num-1 do begin
openr,lun,file[num],/get_lun
nLines = file_lines(file[num])
data =fltarr(12,nLines)
for i=0,nLines-1 do begin
x = fltarr(12)
readf,lun,x
data[*,i] = x
endfor
FREE_LUN, lun
all_data = [[all_data],[data]]
endfor
写入txt文件
Wpath = save_files_path + save_name + '.txt'
OPENW, lun, Wpath, /get_lun,width=200 ;/append参数可不断往txt文件中加内容
PRINTF, lun, [parameter1,parameter2]
;当parameter为一维时需用 PRINTF, lun, [transpose(parameter1),transpose(parameter2)]
FREE_LUN, lun
读取文件名信信息
file_basename & file_dirname
文件通常包含时间信息,之前在读取过程中通常有4步
文件夹路径、查找文件,文件夹长度,截取文件名时间信息
sim_files_path = 'J:\project_simulation\modtran_output\output_info\V3\'
sim_files = file_search(sim_files_path,'*_bt_ch4_ch5.txt',count = files_num)
file_path_length = strlen(sim_files_path)
date_dir = strmid(sim_files[fcnt],file_path_length,9)
但这样每次都需要读取文件夹长度,也可以使用file_basename
sim_files_path = 'J:\project_simulation\modtran_output\output_info\V3\'
sim_files = file_search(sim_files_path,'*_bt_ch4_ch5.txt',count = files_num)
date_dir = strmid(file_basename(sim_files[fcnt],0,9))
两个函数的用法
IDL>file_basename(sim_files[1])
0901_0035_bt_ch4_ch5.txt
IDL> file_dirname(sim_files[1])
J:\project_simulation\modtran_output\output_info\V3