IDL学习笔记(3)--hdf文件SDS读取并显示为图片

本文介绍了一个使用IDL语言读取HDF文件的具体示例,并展示了如何设置常量、打开文件、选择数据集、定义数据子集限制以及读取和处理数据的方法。

作者:fbysss
msn:jameslastchina@hotmail.com 
blog:blog.youkuaiyun.com/fbysss
声明:本文由fbysss原创,转载请注明出处
关键字:IDL

pro readhdf
; Set some constants
FILE_NAME="E:/sssbak/MODSST.hdf"
SDS_NAME="sst"
X_LENGTH=1354
Y_LENGTH=4856

; Open the file and initialize the SD interface
sd_id = HDF_SD_START( FILE_NAME, /read )
; Find the index of the sds to read using its name
sds_index = HDF_SD_NAMETOINDEX(sd_id,SDS_NAME)
; Select it
sds_id = HDF_SD_SELECT( sd_id, sds_index )

; Set the data subset limits. Actually, it is read from the first element, so "start" is [0,0]. X_LENGTH elements will be read along the X axis and Y_LENGTH along Y.
start=INTARR(2) ; the start position of the data to be read
start[0] = 0
start[1] = 0
edges=INTARR(2) ; the number of elements to read in each direction
edges[0] = X_LENGTH
edges[1] = Y_LENGTH
; Read the data : you can notice that here, it is not needed to allocate the data array yourself
HDF_SD_GETDATA, sds_id, data
dims = size(data)
;HDF_SD_GETDATA, sds_id, data, start = start, count = edges

; print them on the screen. You can notice that the IDL method HDF_SD_GETDATA swaps the HDF indexes convention [Z,Y,X] to [X,Y,Z]. This method is more efficient on IDL. If you prefer the usual HDF convention, you should better use the set the NOREVERSE keyword when calling HDF_SD_GETDATA
;FOR i=0,(X_LENGTH-1),1 DO BEGIN ; crosses X axis
;  FOR j=0,(Y_LENGTH-1),1 DO BEGIN ; crosses Y axis
;    PRINT, FORMAT='(I," ",$)', data[i,j]
;  ENDFOR
;  PRINT,""
;ENDFOR

; end access to SDS
HDF_SD_ENDACCESS, sds_id
; close the hdf file
HDF_SD_END, sd_id
print,dims[1];1354 也就是说,实际上X_LENGTH,X_LENGTH可以通过size读出。
print,dims[2];4856
print,dims[3]
print,dims[4]
filter_data = uintarr(dims[1], dims[2],dims[3])
;imagedata =    BYTSCL(data)
imagedata = bytscl( congrid(data,800,600) );缩小图片。

;print,imagedata
 loadct, 15;调色板编号不一样。
 window, 0, xsize=800, ysize=600, retain=2
 tv, imagedata
 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值