IDL常用function书写归纳
检测输入路径
if ~file_test(input_directory,/dorectory) then begin
print,'输入路径不存在
return'
endif
检测输出路径
if dir_test eq 0 then begin
file_mkdir,out_directory
endif
获取 hdf4
输入:
1.数据地址
2.数据集名称
得到:
数据集的数据
function hdf4_data_get,file_name,sds_name
sd_id=hdf_sd_start(file_name,/read)
sds_index=hdf_sd_nametoindex(sd_id,sds_name)
sds_id=hdf_sd_select(sd_id,sds_index)
hdf_sd_getdata,sds_id,data
hdf_sd_endaccess,sds_id
hdf_sd_end,sd_id
return,data
end
获取 hdf5
输入:
1.数据地址
2.数据集名称
得到:
数据集的数据
function hdf5_data_get,file_name,dataset_name
file_id = h5f_open(file_name)
dataset_id = h5d_open(file_id,dataset_name) ;直接返回id 而不是index
data = h5d_read(dataset_id)
h5d_close,dataset_id ; h5d 关闭数据集
h5f_close,file_id ; h5f 关闭文件
return,data
data = !null ;销毁data, 清空内存
end
获取hdf4 数据集中的属性
输入:
1.数据地址
2.数据集名称
3.数据集中目标属性名称
得到:
目标属性名称
function hdf4_attdata_get,file_name,sds_name,att_name
sd_id=hdf_sd_start(file_name,/read)
sds_index=hdf_sd_nametoindex(sd_id,sds_name)
sds_id=hdf_sd_select(sd_id,sds_index)
att_index=hdf_sd_attrfind(sds_id,att_name)
hdf_sd_attrinfo,sds_id,att_index,data=att_data
hdf_sd_endaccess,sds_id
hdf_sd_end,sd_id
return,att_data
end
获取 hdf4 中数据集 并进行修正
输入:
1.数据地址
2.数据集名称
得到:
修正后的数据集数据
function hdf4_real_data,sd,sds_gindex ;输入file_list[file_i],数据
;输入数据地址,数据集名称,得到 真实数据
sd_id = hdf_sd_start(sd,/read)
sds_index = hdf_sd_nametoindex(sd_id, sds_gindex)
sds_id = hdf_sd_select(sd_id,sds_index)
hdf_sd_getdata, sds_id, data
index = hdf_sd_attrfind(sds_id,