-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetboundingrect.pro
75 lines (69 loc) · 3.14 KB
/
getboundingrect.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
;+
; Function of getting bounding rectangle of a HDF-EOS Swath file
;
; Usage: BoudingRect = GETBOUNDINGRECT(FileName, /Type)
; The returned BoundingRect contains bounding rectangle coordinates if
; Type = 'LAT_LONG'
; BoundingRect[0]: east bounding coordinate
; BoundingRect[1]: west bounding coordinate
; BoundingRect[2]: south bounding coordinate
; BoundingRect[3]: north bounding coordinate
; Type = 'LINE_SAMPLE'
; BoundingRect[0]: 1
; BoundingRect[1]: 1
; BoundingRect[2]: sample
; BoundingRect[3]: line
;
; Version: 2.1.0 (2013-12-7)
;
; 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)
;-
FUNCTION GETBOUNDINGRECT, FileName, Type
BoundingRect = STRARR(4)
SDinterface_id = HDF_SD_START(FileName, /READ)
IF Type EQ 'LAT_LONG' THEN BEGIN
; Bounding rectangle information in 'CoreMetadata.0' attribute
gindex = HDF_SD_ATTRFIND(SDinterface_id, 'CoreMetadata.0')
IF gindex EQ -1 THEN RETURN, !NULL
HDF_SD_ATTRINFO, SDinterface_id, gindex, data = data
; Locate bounding rectangle group
gstart = 'GROUP = BOUNDINGRECTANGLE'
sind = STRPOS(data, gstart)
gend = 'END_GROUP = BOUNDINGRECTANGLE'
eind = STRPOS(data, gend)
strrect = STRMID(data, sind, eind - sind + STRLEN(gend))
; Locate east, west, south, north bounding coordinate
strbound = ['EASTBOUNDINGCOORDINATE', 'WESTBOUNDINGCOORDINATE', 'SOUTHBOUNDINGCOORDINATE', 'NORTHBOUNDINGCOORDINATE']
FOR i = 0, N_ELEMENTS(strbound) - 1 DO BEGIN
objstart = 'OBJECT = ' + strbound[i]
sind = STRPOS(strrect, objstart)
objend = 'END_OBJECT = ' + strbound[i]
eind = STRPOS(strrect, objend)
strobj = STRMID(strrect, sind, eind - sind + STRLEN(gend))
result = STRSPLIT(strobj, ' ', /EXTRACT)
; remove '\n' from the string, e.g:'123\n'->'123'
BoundingRect[i] = STRSPLIT(result[8], STRING(10B), /EXTRACT)
ENDFOR
ENDIF ELSE BEGIN
BoundingRect[0] = '1'
BoundingRect[1] = '1'
; SAMPLE information in 'Maximum_Number_of_1km_Frames' attribute
gindex = HDF_SD_ATTRFIND(SDinterface_id, 'Maximum_Number_of_1km_Frames')
IF gindex EQ -1 THEN RETURN, !NULL
HDF_SD_ATTRINFO, SDinterface_id, gindex, data = sample
BoundingRect[2] = STRTRIM(STRING(sample), 1)
; Line information in 'Number_of_Instrument_Scans' attribute
gindex = HDF_SD_ATTRFIND(SDinterface_id, 'Number_of_Instrument_Scans')
IF gindex EQ -1 THEN RETURN, !NULL
HDF_SD_ATTRINFO, SDinterface_id, gindex, data = line
BoundingRect[3] = STRTRIM(STRING(line), 1)
ENDELSE
HDF_SD_END, SDinterface_id
RETURN, BoundingRect
END