-
Notifications
You must be signed in to change notification settings - Fork 3
/
himawari_utils.f90
322 lines (256 loc) · 8.14 KB
/
himawari_utils.f90
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
!******************************************************************************%
! *
! * Copyright (C) 2016 Simon Proud <[email protected]>
! *
! * This source code is licensed under the GNU General Public License (GPL),
! * Version 3. See the file COPYING for more details.
! *
! ******************************************************************************/
module himawari_utils
use himawari
implicit none
public :: AHI_get_timeslot, &
AHI_get_indir, &
AHI_free_vals, &
AHI_alloc_vals, &
AHI_alloc_vals_data, &
AHI_get_file_name, &
AHI_file_exists
contains
integer function AHI_get_timeslot(filename,timeslot) result(status)
character(len=*), intent(in) :: filename
character(len=*), intent(out) :: timeslot
integer pos
pos = index(trim(filename),".DAT")
if (pos .le. 0) then
status = HIMAWARI_FAILURE
return
endif
timeslot(1:8) = filename(pos-32:pos-32+8)
timeslot(9:12) = filename(pos-23:pos-23+4)
status = HIMAWARI_SUCCESS
return
end function AHI_get_timeslot
integer function AHI_get_indir(filename,indir) result(status)
character(len=*), intent(in) :: filename
character(len=*), intent(out) :: indir
integer pos
pos = index(trim(filename),"HS_H08_")
if (pos .le. 0) then
pos = index(trim(filename),"HS_H09_")
endif
if (pos .le. 0) then
status = HIMAWARI_FAILURE
return
endif
indir = filename(1:pos-1)
status = HIMAWARI_SUCCESS
return
end function AHI_get_indir
integer function AHI_free_vals(ahi_main) result(status)
type(himawari_t_struct), intent(inout) :: ahi_main
deallocate(ahi_main%ahi_data%lat)
deallocate(ahi_main%ahi_data%lon)
deallocate(ahi_main%ahi_data%vza)
deallocate(ahi_main%ahi_data%vaa)
deallocate(ahi_main%ahi_data%sza)
deallocate(ahi_main%ahi_data%saa)
deallocate(ahi_main%ahi_data%time)
deallocate(ahi_main%ahi_data%indata)
status = HIMAWARI_SUCCESS
return
end function AHI_free_vals
integer function AHI_free_vals_data(ahi_data,verbose) result(status)
type(himawari_t_data), intent(inout) :: ahi_data
logical, intent(in) :: verbose
deallocate(ahi_data%lat)
deallocate(ahi_data%lon)
deallocate(ahi_data%vza)
deallocate(ahi_data%vaa)
deallocate(ahi_data%sza)
deallocate(ahi_data%saa)
deallocate(ahi_data%time)
deallocate(ahi_data%indata)
status = HIMAWARI_SUCCESS
return
end function AHI_free_vals_data
integer function AHI_alloc_vals_data(ahi_data,nchans,verbose) result(status)
type(himawari_t_data), intent(inout) :: ahi_data
integer, intent(in) :: nchans
integer :: i,length
logical, intent(in) :: verbose
if (verbose) then
write(*,*)"Number of bands to read:",nchans
endif
allocate(ahi_data%lat(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%lon(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%vza(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%vaa(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%sza(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%saa(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%time(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_data%indata(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS,nchans))
status = HIMAWARI_SUCCESS
return
end function AHI_alloc_vals_data
integer function AHI_alloc_vals(ahi_main,verbose) result(status)
type(himawari_t_struct), intent(inout) :: ahi_main
integer :: i,length
logical, intent(in) :: verbose
! ahi_main%ahi_data%n_bands = 0
! do i=1,16
! if (ahi_main%inchans(i) .eq. 1) then
! ahi_main%ahi_data%n_bands = ahi_main%ahi_data%n_bands+1
! endif
! end do
if (ahi_main%ahi_data%n_bands <= 0) then
write(*,*)"No bands are selected!"
status = HIMAWARI_FAILURE
return
endif
if (verbose) then
write(*,*)"Number of bands to read:",ahi_main%ahi_data%n_bands
endif
allocate(ahi_main%ahi_data%lat(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%lon(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%vza(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%vaa(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%sza(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%saa(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%time(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS))
allocate(ahi_main%ahi_data%indata(HIMAWARI_IR_NLINES,HIMAWARI_IR_NCOLS,ahi_main%ahi_data%n_bands))
status = HIMAWARI_SUCCESS
return
end function AHI_alloc_vals
integer function AHI_get_file_name(cnum, timeslot, satname, indir, outfile,verbose) result(status)
integer, intent(in) :: cnum
character(len=*), intent(in) :: timeslot
character(len=*), intent(in) :: satname
character(len=*), intent(in) :: indir
character(len=*), intent(out) :: outfile
logical, intent(in) :: verbose
outfile=indir
outfile = trim(outfile)//trim(satname)
outfile = trim(outfile)//trim("_ahi_le1b_")
select case(cnum)
case(1)
outfile = trim(outfile)//trim("b01")
case(2)
outfile = trim(outfile)//trim("b02")
case(3)
outfile = trim(outfile)//trim("b03")
case(4)
outfile = trim(outfile)//trim("b04")
case(5)
outfile = trim(outfile)//trim("b05")
case(6)
outfile = trim(outfile)//trim("b06")
case(7)
outfile = trim(outfile)//trim("b07")
case(8)
outfile = trim(outfile)//trim("b08")
case(9)
outfile = trim(outfile)//trim("b09")
case(10)
outfile = trim(outfile)//trim("b10")
case(11)
outfile = trim(outfile)//trim("b11")
case(12)
outfile = trim(outfile)//trim("b12")
case(13)
outfile = trim(outfile)//trim("b13")
case(14)
outfile = trim(outfile)//trim("b14")
case(15)
outfile = trim(outfile)//trim("b15")
case(16)
outfile = trim(outfile)//trim("b16")
case default
status = HIMAWARI_FAILURE
return
end select
outfile = trim(outfile)//trim("_org_f_")
outfile = trim(outfile)//trim(timeslot)
outfile = trim(outfile)//trim(".bin")
status = HIMAWARI_SUCCESS
return
end function AHI_get_file_name
integer function AHI_get_file_name_seg(cnum, seg, timeslot, satname, indir, outfile,verbose) result(status)
integer, intent(in) :: cnum
integer, intent(in) :: seg
character(len=*), intent(in) :: timeslot
character(len=*), intent(in) :: satname
character(len=*), intent(in) :: indir
character(len=*), intent(out) :: outfile
logical, intent(in) :: verbose
character(len=3) :: tstr
outfile=indir
outfile = trim(outfile)//trim("HS_H08_")
outfile = trim(outfile)//trim(timeslot(1:8))
outfile = trim(outfile)//trim("_")
outfile = trim(outfile)//trim(timeslot(9:12))
outfile = trim(outfile)//trim("_")
select case(cnum)
case(1)
outfile = trim(outfile)//trim("B01")
case(2)
outfile = trim(outfile)//trim("B02")
case(3)
outfile = trim(outfile)//trim("B03")
case(4)
outfile = trim(outfile)//trim("B04")
case(5)
outfile = trim(outfile)//trim("B05")
case(6)
outfile = trim(outfile)//trim("B06")
case(7)
outfile = trim(outfile)//trim("B07")
case(8)
outfile = trim(outfile)//trim("B08")
case(9)
outfile = trim(outfile)//trim("B09")
case(10)
outfile = trim(outfile)//trim("B10")
case(11)
outfile = trim(outfile)//trim("B11")
case(12)
outfile = trim(outfile)//trim("B12")
case(13)
outfile = trim(outfile)//trim("B13")
case(14)
outfile = trim(outfile)//trim("B14")
case(15)
outfile = trim(outfile)//trim("B15")
case(16)
outfile = trim(outfile)//trim("B16")
case default
status = HIMAWARI_FAILURE
return
end select
outfile = trim(outfile)//trim("_FLDK_R")
if (cnum.eq.1.or.cnum.eq.2.or.cnum.eq.4) then
outfile = trim(outfile)//trim("10_S")
else if (cnum.eq.3) then
outfile = trim(outfile)//trim("05_S")
else
outfile = trim(outfile)//trim("20_S")
endif
write(tstr,"(I2.2)")seg
outfile = trim(outfile)//trim(tstr)
outfile = trim(outfile)//trim("10.DAT")
status = HIMAWARI_SUCCESS
return
end function AHI_get_file_name_seg
integer function AHI_file_exists(filename,verbose) result(status)
character(len=*), intent(in) :: filename
logical, intent(in) :: verbose
logical exists
inquire(file=filename, exist=exists)
if (exists .eqv. .true.) then
status = HIMAWARI_SUCCESS;
else
status = HIMAWARI_FAILURE;
endif
return
end function AHI_file_exists
end module himawari_utils