-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdacget2s.pro
165 lines (131 loc) · 2.72 KB
/
dacget2s.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
pro dacget2s,files,data,narg=narg $
,ix=ix,jx=jx,nx=nx,narr=narr,ndx=ndx,margin=margin
if n_elements(narg) eq 0 then narg=-1
sz=size(narg)
allreadflag=0
if (sz[0] ge 1) then begin
narr=narg
endif else begin
if (narg ge 0) then begin
narr=[narg]
endif else begin
allreadflag=1
endelse
endelse
mfx=n_elements(files)
if (mfx eq 1) then begin
file=files[0]
; check header
;
openr,unit,file,/get_lun
unity=0L
pos=4
point_lun,unit,pos
readu,unit,unity
if (unity gt 1000) then endian_flag=1 else endian_flag=0
; if (endian_flag = 1) then machine-arch and file-endian is different.
mver=0L
pos=pos+12
point_lun,unit,pos
readu,unit,mver
if endian_flag then byteorder,mver,/ntohl
; for data type: integer=4, real=5, double=6
mtype=0L
pos=pos+12
point_lun,unit,pos
readu,unit,mtype
if endian_flag then byteorder,mtype,/ntohl
mndim=0L
pos=pos+12
point_lun,unit,pos
readu,unit,mndim
if endian_flag then byteorder,mndim,/ntohl
mdim=lonarr(mndim)
pos=pos+12
point_lun,unit,pos
readu,unit,mdim
if endian_flag then byteorder,mdim,/ntohl
ix=mdim[0] & jx=mdim[1]
if (mdim[mndim-1] eq -1) then begin
headersize=12L*4+mndim*4+8
tmp=FSTAT(unit) & filesize=tmp.size
datasize=filesize-headersize
if (mtype eq 6) then dataunitsize=8L*ix*jx else dataunitsize=4L*ix*jx
dataperstep=dataunitsize+8
ndx=datasize/dataperstep
endif else begin
ndx=mdim[mndim-1]
endelse
if (allreadflag eq 1) then narr=indgen(ndx)
sz=size(narr)
ndmax=sz[1]
case mtype of
4: begin
data0=lonarr(ix,jx)
data=lonarr(ix,jx,ndmax)
end
5: begin
data0=fltarr(ix,jx)
data=fltarr(ix,jx,ndmax)
end
6: begin
data0=dblarr(ix,jx)
data=dblarr(ix,jx,ndmax)
end
endcase
for nd=0,ndmax-1 do begin
nn=narr[nd]
pos=headersize+nn*dataperstep ; position in file
if (pos lt filesize) then begin
point_lun,unit,pos+4
readu,unit,data0
data[*,*,nd]=data0
endif else begin
goto,label0
endelse
endfor
label0:
ndx=nd
data=data[*,*,0:ndx-1]
nx=ndx
close,unit
free_lun,unit
if endian_flag then begin
case mtype of
4: byteorder,data,/ntohl
5: byteorder,data,/xdrtof
6: byteorder,data,/xdrtod
endcase
endif
endif else begin
for mf=0,mfx-1 do begin
file=files[mf]
dacget2s,file,data0,narg=narg $
,ix=ix,jx=jx,nx=nx,narr=narr,ndx=ndx
if (mf eq 0) then begin
igx=ix
jgx=jx*mfx-2*margin*(mfx-1)
sz=size(data0)
mtype=sz[sz[0]+1]+1
case mtype of
4: begin
data=lonarr(ix,jgx,ndx)
end
5: begin
data=fltarr(ix,jgx,ndx)
end
6: begin
data=dblarr(ix,jgx,ndx)
end
endcase
endif
moff=mf*(jx-2*margin)+margin
data[*,moff:moff+jx-1-margin,*]=data0[*,margin:jx-1,*]
if (margin ge 1) then $
if (mf eq 0) then data[*,0:margin-1,*]=data0[*,0:margin-1,*]
endfor
ix=igx
jx=jgx
endelse
return
end