-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_hdf.pro
98 lines (90 loc) · 3.21 KB
/
check_hdf.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;+
; Check HDF integrity and record the invalid HDF files for redowndload
;
; Version: 1.2.0 (2013-12-16)
;
; Author: Tony Tsai, Ph.D. Student
; (Center for Earth System Science, Tsinghua University)
; Contact Email: [email protected]
;
; Copyright: belongs to Dr.Xu's Lab
; (School of Environment, Tsinghua University)
; (College of Global Change and Earth System Science, Beijing Normal University)
;-
PRO CHECK_HDF
COMPILE_OPT IDL2
; Customize indir
indir = 'H:\ZhangYawen\2003\'
dlist = FILE_SEARCH(indir, '*', count = num_dir, /TEST_DIRECTORY)
IF num_dir EQ 0 THEN RETURN
FOR i = 0, num_dir - 1 DO BEGIN
subdir = dlist[i]
; Record wrong HDF files
whdf = subdir + '.redownload.txt'
PRINT, whdf
; First check
IF FILE_TEST(whdf) EQ 0 THEN BEGIN
flist = FILE_SEARCH(subdir, '*.hdf', count = num_hdf, /FULLY_QUALIFY_PATH)
IF num_hdf EQ 0 THEN CONTINUE
ENDIF ELSE BEGIN
; Read previous checking results and only check those files to save time
results = QUERY_ASCII(whdf, info)
num_hdf = info.LINES - 1
IF num_hdf EQ 0 THEN BEGIN
CONTINUE
ENDIF ELSE BEGIN
header = ''
; Records of wrong HDF files
records = !NULL
records = STRARR(num_hdf)
OPENR, lun, whdf, /GET_LUN
; Skip header
READF, lun, header
READF, lun, records
FREE_LUN, lun
; Split records to rows*cols
; Note: records is a LIST
records = STRSPLIT(records, ', ', /EXTRACT)
flist = STRARR(num_hdf)
FOR k = 0, num_hdf - 1 DO flist[k] = subdir + '\' + (records[k])[0]
FILE_DELETE, whdf
ENDELSE
ENDELSE
; Write header to redownload.txt
header = ['File Name', 'Error Index', 'Error Message']
OPENW, lun, whdf, /GET_LUN
PRINTF, lun, header, format = '(3(A, :, ", "))'
FREE_LUN, lun
FOR j = 0, num_hdf - 1 DO BEGIN
fname = flist[j]
fbname = FILE_BASENAME(fname)
str = STRSPLIT(fbname, '.', /EXTRACT)
IF str[0] EQ 'MYD35_L2' THEN SDS_name = 'Cloud_Mask' ELSE SDS_name = ['Longitude', 'Latitude']
CATCH, Error_status
IF Error_status NE 0 THEN BEGIN
; Write record to redownload.txt
record = [FILE_BASENAME(fname), STRTRIM(STRING(Error_status), 1), !ERROR_STATE.MSG]
OPENW, lun, whdf, /GET_LUN, /APPEND
PRINTF, lun, record, format = '(3(A, :, ", "))'
FREE_LUN, lun
; Print on console
PRINT, fname
PRINT, 'Error index: ', Error_status
PRINT, 'Error message: ', !ERROR_STATE.MSG
CATCH, /CANCEL
CONTINUE
ENDIF
; Try to catch Error index: -1112
SDinterface_id = HDF_SD_START(fname, /READ)
FOR k = 0, N_ELEMENTS(SDS_name) - 1 DO BEGIN
index = HDF_SD_NAMETOINDEX(SDinterface_id, SDS_name[k])
; Try to catch Error index: -1113
SDdataset_id = HDF_SD_SELECT(SDinterface_id, index)
; Try to catch Error index: -1119
HDF_SD_GETDATA, SDdataset_id, data
HDF_SD_ENDACCESS, SDdataset_id
ENDFOR
HDF_SD_END, SDinterface_id
ENDFOR
ENDFOR
END