题目要求
编写一个pro程序,给定一个路径,自动获取该路径下所有的hdf4或h5文件,将其中某个数据转化为tif格式
目录树即运行结果
具体文件我会放到百度网盘中
运行教程截图
-
编译
-
运行
-
选择图片 从grid中选择
-
勾选
代码和过程
pro homework_3_4_hdf_to_tiff
; 编写一个pro程序,给定一个路径,自动获取该路径下所有的hdf4或h5文件,将其中某个数据转化为tif格式
; the supported formats are: h5, hdf4, hdf, h4, he5, he2, hdf5
; 切换工作路径
cd, '/media/andy/Data/cs/IDL/third/'
;;设置支持的文件格式
file_path = dialog_pickfile(filter=['*.hdf', '*.hdf4', '*.h5'])
;判断是不是h5文件, 如是,进行h5的函数 否则进入h4的函数
is_h5_flag = h5f_is_hdf5(file_path)
if is_h5_flag then begin
res = h5_to_tiff(file_path)
endif else begin
res = h4_to_tiff(file_path)
endelse
end
function h4_to_tiff, file_path
; 将h4转为tiff格式
hd_id = hdf_sd_start(file_path)
template = hdf_browser(file_path)
output_structure = hdf_read(file_path, template=template)
; 数组在结构体最后一个
data = output_structure.(3)
write_tiff, 'res_3_4_h4_to_tiff.tif', data
return, 1
end
function h5_to_tiff, file_path
print, "the function is devploping..."
end
百度地址
链接: https://pan.baidu.com/s/1OPJw3DjiKSEW4UdqKmYmHA 密码: u84u
–来自百度网盘超级会员V4的分享