skip the corrupted hdf file and continue the for lood for uncorrupted hdfs [message #87349] |
Mon, 27 January 2014 00:22  |
Brent Fallarcuna
Messages: 6 Registered: July 2013
|
Junior Member |
|
|
Hello everyone!
I'm extracting values on a specific pixel from hundreds of hdf files and used for loop.
This is my code:
;Daily NPP/GPP Plotting
cd, ('C:\Users\Brent\Documents\NPP Annual Files\MODIS17A2v5')
filelist = file_search('*.*.h29v07.005.*.hdf')
i = 0
arr = strarr(1,637)
FOR i = 0, 636 DO BEGIN
; Open HDF and Import SDS
filename = filelist[i]
;access hdf file
hdf_id = hdf_sd_start(filename);this is where my program stops
;return the index of 'Npp_1km' variable
index = hdf_sd_nametoindex(hdf_id, 'PsnNet_1km')
;access the dataset
varid = hdf_sd_select(hdf_id, index)
;read the contents of the variable
hdf_sd_getdata, varid, data
;endaccess
hdf_sd_endaccess, varid
hdf_sd_end, hdf_id
;rotate hdf
data = rotate(data, 7)
;scale the data
kaliwa_tile = data * (0.0001)
point = kaliwa_tile[880,566]
print, point
arr[0,i] = point
ENDFOR
cd, ('C:\Users\Brent\Documents\MOD17A3UTM')
openw, lun, 'outputfilefor8dayPsnNet1km.csv', /get_lun
printf, lun, arr, format= '(a)'
close, lun
free_lun, lun
END
After the values from several hdfs are printed, there's an error on the console saying "HDF_SD_START: Unable to start the HDF-SD interface."
As I checked the variables tab, the i stopped at the 24th hdf file. As I checked the file using hdf browser, it didn't open, thus the file seems to be corrupted.
My question is, can I continue my for loop and proceed reading the other uncorrupted hdf files every time I got the said error?
I've tried catch statement but I can't figure it out on how to use and implement it correctly.
Brent
|
|
|