作者:fbysss
msn:[email protected]
blog:blog.csdn.net/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