forked from gmcgarragh/seviri_util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseviri_util_f90.f90
589 lines (466 loc) · 23 KB
/
seviri_util_f90.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
!*******************************************************************************
!
! Copyright (C) 2014-2018 Greg McGarragh <[email protected]>
! Copyright (C) 2018 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 containing the Fortran interface to seviri_util. Please see the
! comments in the C code for descriptions of the various routines including
! their arguments and return values.
!*******************************************************************************
module seviri_util
use iso_c_binding
implicit none
private
public :: seviri_preproc_t_f90, &
seviri_get_dimens_nat_f90, &
seviri_get_dimens_hrit_f90, &
seviri_get_dimens_f90, &
seviri_read_and_preproc_nat_f90, &
seviri_read_and_preproc_hrit_f90, &
seviri_read_and_preproc_f90, &
seviri_preproc_free_f90
integer, parameter, public :: SEVIRI_BOUNDS_FULL_DISK = 0
integer, parameter, public :: SEVIRI_BOUNDS_ACTUAL_IMAGE = 1
integer, parameter, public :: SEVIRI_BOUNDS_LINE_COLUMN = 2
integer, parameter, public :: SEVIRI_BOUNDS_LAT_LON = 3
integer, parameter, public :: SEVIRI_UNIT_CNT = 0
integer, parameter, public :: SEVIRI_UNIT_RAD = 1
integer, parameter, public :: SEVIRI_UNIT_REF = 2
integer, parameter, public :: SEVIRI_UNIT_BRF = 3
integer, parameter, public :: SEVIRI_UNIT_BT = 4
type, bind(c) :: seviri_preproc_t
integer(c_int) :: memory_alloc_d
integer(c_int) :: n_bands
integer(c_int) :: n_lines
integer(c_int) :: n_columns
real(c_float) :: fill_value
type(c_ptr) :: time
type(c_ptr) :: lat
type(c_ptr) :: lon
type(c_ptr) :: sza
type(c_ptr) :: saa
type(c_ptr) :: vza
type(c_ptr) :: vaa
type(c_ptr) :: data
type(c_ptr) :: data2
end type seviri_preproc_t
type :: seviri_preproc_t_f90
logical :: memory_alloc_d
integer :: n_bands
integer :: n_lines
integer :: n_columns
real(4) :: fill_value
real(8), pointer :: time(:, :)
real(4), pointer :: lat(:, :)
real(4), pointer :: lon(:, :)
real(4), pointer :: sza(:, :)
real(4), pointer :: saa(:, :)
real(4), pointer :: vza(:, :)
real(4), pointer :: vaa(:, :)
real(4), pointer :: data(:, :, :)
type(seviri_preproc_t) :: preproc
end type seviri_preproc_t_f90
interface
integer(c_int) function seviri_get_dimens_nat(filename, &
i_line, i_column, n_lines, n_columns, bounds, line0, line1, &
column0, column1, lat0, lat1, lon0, lon1) &
bind(C, name = 'seviri_get_dimens_nat')
use iso_c_binding
implicit none
character(c_char), intent(in) :: filename(*)
integer(c_int), intent(out) :: i_line, i_column
integer(c_int), intent(out) :: n_lines, n_columns
integer(c_int), intent(in), value :: bounds
integer(c_int), intent(in), value :: line0, line1, &
column0, column1
real(c_double), intent(in), value :: lat0, lat1, lon0, lon1
end function seviri_get_dimens_nat
end interface
interface
integer(c_int) function seviri_get_dimens_hrit(filename, timeslot, &
satnum, i_line, i_column, n_lines, n_columns, bounds, line0, line1, &
column0, column1, lat0, lat1, lon0, lon1) &
bind(C, name = 'seviri_get_dimens_hrit')
use iso_c_binding
implicit none
character(c_char), intent(in) :: filename(*)
character(c_char), intent(in) :: timeslot(*)
integer(c_int), intent(in) :: satnum
integer(c_int), intent(out) :: i_line, i_column
integer(c_int), intent(out) :: n_lines, n_columns
integer(c_int), intent(in), value :: bounds
integer(c_int), intent(in), value :: line0, line1, &
column0, column1
real(c_double), intent(in), value :: lat0, lat1, lon0, lon1
end function seviri_get_dimens_hrit
end interface
interface
integer(c_int) function seviri_get_dimens(filename, &
i_line, i_column, n_lines, n_columns, bounds, line0, line1, &
column0, column1, lat0, lat1, lon0, lon1) &
bind(C, name = 'seviri_get_dimens')
use iso_c_binding
implicit none
character(c_char), intent(in) :: filename(*)
integer(c_int), intent(out) :: i_line, i_column
integer(c_int), intent(out) :: n_lines, n_columns
integer(c_int), intent(in), value :: bounds
integer(c_int), intent(in), value :: line0, line1, &
column0, column1
real(c_double), intent(in), value :: lat0, lat1, lon0, lon1
end function seviri_get_dimens
end interface
interface
integer(c_int) function seviri_read_and_preproc_nat(filename, preproc, &
n_bands, band_ids, band_units, bounds, line0, line1, column0, column1, &
lat0, lat1, lon0, lon1, do_calib, satposstr, do_not_alloc) bind(C, &
name = 'seviri_read_and_preproc_nat')
use iso_c_binding
import seviri_preproc_t
implicit none
character(c_char), intent(in) :: filename(*)
type(seviri_preproc_t), intent(out) :: preproc
integer(c_int), intent(in), value :: n_bands
integer(c_int), intent(in) :: band_ids(*)
integer(c_int), intent(in) :: band_units(*)
integer(c_int), intent(in), value :: bounds
integer(c_int), intent(in), value :: line0, line1, &
column0, column1
real(c_double), intent(in), value :: lat0, lat1, lon0, lon1
integer(c_int), intent(in), value :: do_calib
character(c_char), intent(inout) :: satposstr(128)
integer(c_int), intent(in), value :: do_not_alloc
end function seviri_read_and_preproc_nat
end interface
interface
integer(c_int) function seviri_read_and_preproc_hrit(filename, timeslot, &
satnum, preproc, n_bands, band_ids, band_units, bounds, line0, line1, &
column0, column1, lat0, lat1, lon0, lon1, rss, do_calib, satposstr, &
do_not_alloc) bind(C, name = 'seviri_read_and_preproc_hrit')
use iso_c_binding
import seviri_preproc_t
implicit none
character(c_char), intent(in) :: filename(*)
character(c_char), intent(in) :: timeslot(*)
integer(c_int), intent(in) :: satnum
type(seviri_preproc_t), intent(out) :: preproc
integer(c_int), intent(in), value :: n_bands
integer(c_int), intent(in) :: band_ids(*)
integer(c_int), intent(in) :: band_units(*)
integer(c_int), intent(in), value :: bounds
integer(c_int), intent(in), value :: line0, line1, &
column0, column1
real(c_double), intent(in), value :: lat0, lat1, lon0, lon1
integer(c_int), intent(in), value :: rss
integer(c_int), intent(in), value :: do_calib
character(c_char), intent(inout) :: satposstr(128)
integer(c_int), intent(in), value :: do_not_alloc
end function seviri_read_and_preproc_hrit
end interface
interface
integer(c_int) function seviri_read_and_preproc(filename, preproc, &
n_bands, band_ids, band_units, bounds, line0, line1, column0, column1, &
lat0, lat1, lon0, lon1, do_calib, satposstr, do_not_alloc) bind(C, &
name = 'seviri_read_and_preproc')
use iso_c_binding
import seviri_preproc_t
implicit none
character(c_char), intent(in) :: filename(*)
type(seviri_preproc_t), intent(out) :: preproc
integer(c_int), intent(in), value :: n_bands
integer(c_int), intent(in) :: band_ids(*)
integer(c_int), intent(in) :: band_units(*)
integer(c_int), intent(in), value :: bounds
integer(c_int), intent(in), value :: line0, line1, &
column0, column1
real(c_double), intent(in), value :: lat0, lat1, lon0, lon1
integer(c_int), intent(in), value :: do_calib
character(c_char), intent(inout) :: satposstr(128)
integer(c_int), intent(in), value :: do_not_alloc
end function seviri_read_and_preproc
end interface
interface
integer(c_int) function seviri_preproc_free(preproc) &
bind(C, name = 'seviri_preproc_free')
use iso_c_binding
import seviri_preproc_t
implicit none
type(seviri_preproc_t), intent(inout) :: preproc
end function seviri_preproc_free
end interface
contains
integer function seviri_get_dimens_nat_f90(filename, i_line, i_column, &
n_lines, n_columns, bounds, line0, line1, column0, column1, lat0, lat1, &
lon0, lon1) result(status)
implicit none
character(*), intent(in) :: filename
integer, intent(out) :: i_line, i_column
integer, intent(out) :: n_lines, n_columns
integer, intent(in), value :: bounds
integer, intent(in), value :: line0, line1, &
column0, column1
real(8), intent(in), value :: lat0, lat1, lon0, lon1
status = seviri_get_dimens_nat(trim(filename)//C_NULL_CHAR, &
i_line, i_column, n_lines, n_columns, bounds, line0, line1, &
column0, column1, lat0, lat1, lon0, lon1)
if (status .ne. 0) then
write(6, *) 'ERROR: seviri_get_dimens_nat()'
return
end if
end function seviri_get_dimens_nat_f90
integer function seviri_get_dimens_hrit_f90(filename, timeslot, satnum, &
i_line, i_column, n_lines, n_columns, bounds, line0, line1, column0, &
column1, lat0, lat1, lon0, lon1) result(status)
implicit none
character(*), intent(in) :: filename
character(*), intent(in) :: timeslot
integer, intent(in) :: satnum
integer, intent(out) :: i_line, i_column
integer, intent(out) :: n_lines, n_columns
integer, intent(in), value :: bounds
integer, intent(in), value :: line0, line1, &
column0, column1
real(8), intent(in), value :: lat0, lat1, lon0, lon1
status = seviri_get_dimens_hrit(trim(filename)//C_NULL_CHAR, &
trim(timeslot)//C_NULL_CHAR, satnum, i_line, i_column, n_lines, &
n_columns, bounds, line0, line1, column0, column1, lat0, lat1, &
lon0, lon1)
if (status .ne. 0) then
write(6, *) 'ERROR: seviri_get_dimens_hrit()'
return
end if
end function seviri_get_dimens_hrit_f90
integer function seviri_get_dimens_f90(filename, i_line, i_column, &
n_lines, n_columns, bounds, line0, line1, column0, column1, lat0, lat1, &
lon0, lon1) result(status)
implicit none
character(*), intent(in) :: filename
integer, intent(out) :: i_line, i_column
integer, intent(out) :: n_lines, n_columns
integer, intent(in), value :: bounds
integer, intent(in), value :: line0, line1, &
column0, column1
real(8), intent(in), value :: lat0, lat1, lon0, lon1
status = seviri_get_dimens(trim(filename)//C_NULL_CHAR, &
i_line, i_column, n_lines, n_columns, bounds, line0, line1, &
column0, column1, lat0, lat1, lon0, lon1)
if (status .ne. 0) then
write(6, *) 'ERROR: seviri_get_dimens()'
return
end if
end function seviri_get_dimens_f90
integer function seviri_read_and_preproc_nat_f90(filename, preproc_f90, n_bands, &
band_ids, band_units, bounds, line0, line1, column0, column1, lat0, lat1, &
lon0, lon1, do_calib_f90, satposstr, do_not_alloc_f90) result(status)
implicit none
character(*), intent(in) :: filename
type(seviri_preproc_t_f90), intent(out) :: preproc_f90
integer, intent(in), value :: n_bands
integer, intent(in) :: band_ids(:)
integer, intent(in) :: band_units(:)
integer, intent(in), value :: bounds
integer, intent(in), value :: line0, line1, &
column0, column1
real(8), intent(in), value :: lat0, lat1, lon0, lon1
logical, intent(in), value :: do_calib_f90
character(kind=c_char), intent(inout) :: satposstr(128)
logical, intent(in), value :: do_not_alloc_f90
integer :: do_calib
integer :: do_not_alloc
type(seviri_preproc_t) :: preproc
integer :: shape1(2)
integer :: shape2(3)
do_calib = 0
if (do_calib_f90) &
do_calib = 1
do_not_alloc = 0
if (do_not_alloc_f90) &
do_not_alloc = 1
if (do_not_alloc_f90) then
preproc%time = c_loc(preproc_f90%time(1, 1))
preproc%lat = c_loc(preproc_f90%lat (1, 1))
preproc%lon = c_loc(preproc_f90%lon (1, 1))
preproc%sza = c_loc(preproc_f90%sza (1, 1))
preproc%saa = c_loc(preproc_f90%saa (1, 1))
preproc%vza = c_loc(preproc_f90%vza (1, 1))
preproc%vaa = c_loc(preproc_f90%vaa (1, 1))
preproc%data2 = c_loc(preproc_f90%data(1, 1, 1))
end if
status = seviri_read_and_preproc_nat(trim(filename)//C_NULL_CHAR, preproc, &
n_bands, band_ids, band_units, bounds, line0, line1, column0, column1, &
lat0, lat1, lon0, lon1, do_calib, satposstr, do_not_alloc)
if (status .ne. 0) then
write(6, *) 'ERROR: seviri_read_and_preproc_nat()'
return
end if
preproc_f90%memory_alloc_d = .false.
if (preproc%memory_alloc_d .ne. 0) &
preproc_f90%memory_alloc_d = .true.
preproc_f90%n_bands = preproc%n_bands
preproc_f90%n_lines = preproc%n_lines
preproc_f90%n_columns = preproc%n_columns
preproc_f90%fill_value = preproc%fill_value
shape1 = [preproc_f90%n_columns, preproc_f90%n_lines]
if (.not. do_not_alloc_f90) then
call c_f_pointer(preproc%time, preproc_f90%time, shape1)
call c_f_pointer(preproc%lat, preproc_f90%lat, shape1)
call c_f_pointer(preproc%lon, preproc_f90%lon, shape1)
call c_f_pointer(preproc%sza, preproc_f90%sza, shape1)
call c_f_pointer(preproc%saa, preproc_f90%saa, shape1)
call c_f_pointer(preproc%vza, preproc_f90%vza, shape1)
call c_f_pointer(preproc%vaa, preproc_f90%vaa, shape1)
shape2 = [preproc_f90%n_columns, preproc_f90%n_lines, n_bands]
call c_f_pointer(preproc%data2, preproc_f90%data, shape2)
end if
preproc_f90%preproc = preproc
end function seviri_read_and_preproc_nat_f90
integer function seviri_read_and_preproc_hrit_f90(filename, timeslot, satnum, &
preproc_f90, n_bands, band_ids, band_units, bounds, line0, line1, column0, &
column1, lat0, lat1, lon0, lon1, rss_f90, do_calib_f90, satposstr, &
do_not_alloc_f90) result(status)
implicit none
character(*), intent(in) :: filename
character(*), intent(in) :: timeslot
integer, intent(in) :: satnum
type(seviri_preproc_t_f90), intent(out) :: preproc_f90
integer, intent(in), value :: n_bands
integer, intent(in) :: band_ids(:)
integer, intent(in) :: band_units(:)
integer, intent(in), value :: bounds
integer, intent(in), value :: line0, line1, &
column0, column1
real(8), intent(in), value :: lat0, lat1, lon0, lon1
logical, intent(in), value :: rss_f90
logical, intent(in), value :: do_calib_f90
character(kind=c_char), intent(inout) :: satposstr(128)
logical, intent(in), value :: do_not_alloc_f90
integer :: rss
integer :: do_calib
integer :: do_not_alloc
type(seviri_preproc_t) :: preproc
integer :: shape1(2)
integer :: shape2(3)
rss = 0
if (rss_f90) &
rss = 1
do_calib = 0
if (do_calib_f90) &
do_calib = 1
do_not_alloc = 0
if (do_not_alloc_f90) &
do_not_alloc = 1
if (do_not_alloc_f90) then
preproc%time = c_loc(preproc_f90%time(1, 1))
preproc%lat = c_loc(preproc_f90%lat (1, 1))
preproc%lon = c_loc(preproc_f90%lon (1, 1))
preproc%sza = c_loc(preproc_f90%sza (1, 1))
preproc%saa = c_loc(preproc_f90%saa (1, 1))
preproc%vza = c_loc(preproc_f90%vza (1, 1))
preproc%vaa = c_loc(preproc_f90%vaa (1, 1))
preproc%data2 = c_loc(preproc_f90%data(1, 1, 1))
end if
status = seviri_read_and_preproc_hrit(trim(filename)//C_NULL_CHAR, &
trim(timeslot)//C_NULL_CHAR, satnum, preproc, n_bands, band_ids, &
band_units, bounds, line0, line1, column0, column1, lat0, lat1, &
lon0, lon1, rss, do_calib, satposstr, do_not_alloc)
if (status .ne. 0) then
write(6, *) 'ERROR: seviri_read_and_preproc_hrit()'
return
end if
preproc_f90%memory_alloc_d = .false.
if (preproc%memory_alloc_d .ne. 0) &
preproc_f90%memory_alloc_d = .true.
preproc_f90%n_bands = preproc%n_bands
preproc_f90%n_lines = preproc%n_lines
preproc_f90%n_columns = preproc%n_columns
preproc_f90%fill_value = preproc%fill_value
shape1 = [preproc_f90%n_columns, preproc_f90%n_lines]
if (.not. do_not_alloc_f90) then
call c_f_pointer(preproc%time, preproc_f90%time, shape1)
call c_f_pointer(preproc%lat, preproc_f90%lat, shape1)
call c_f_pointer(preproc%lon, preproc_f90%lon, shape1)
call c_f_pointer(preproc%sza, preproc_f90%sza, shape1)
call c_f_pointer(preproc%saa, preproc_f90%saa, shape1)
call c_f_pointer(preproc%vza, preproc_f90%vza, shape1)
call c_f_pointer(preproc%vaa, preproc_f90%vaa, shape1)
shape2 = [preproc_f90%n_columns, preproc_f90%n_lines, n_bands]
call c_f_pointer(preproc%data2, preproc_f90%data, shape2)
end if
preproc_f90%preproc = preproc
end function seviri_read_and_preproc_hrit_f90
integer function seviri_read_and_preproc_f90(filename, preproc_f90, n_bands, &
band_ids, band_units, bounds, line0, line1, column0, column1, lat0, lat1, &
lon0, lon1, do_calib_f90, satposstr, do_not_alloc_f90) result(status)
implicit none
character(*), intent(in) :: filename
type(seviri_preproc_t_f90), intent(out) :: preproc_f90
integer, intent(in), value :: n_bands
integer, intent(in) :: band_ids(:)
integer, intent(in) :: band_units(:)
integer, intent(in), value :: bounds
integer, intent(in), value :: line0, line1, &
column0, column1
real(8), intent(in), value :: lat0, lat1, lon0, lon1
logical, intent(in), value :: do_calib_f90
character(kind=c_char), intent(inout) :: satposstr(128)
logical, intent(in), value :: do_not_alloc_f90
integer :: do_calib
integer :: do_not_alloc
type(seviri_preproc_t) :: preproc
integer :: shape1(2)
integer :: shape2(3)
do_calib = 0
if (do_calib_f90) &
do_calib = 1
do_not_alloc = 0
if (do_not_alloc_f90) &
do_not_alloc = 1
if (do_not_alloc_f90) then
preproc%time = c_loc(preproc_f90%time(1, 1))
preproc%lat = c_loc(preproc_f90%lat (1, 1))
preproc%lon = c_loc(preproc_f90%lon (1, 1))
preproc%sza = c_loc(preproc_f90%sza (1, 1))
preproc%saa = c_loc(preproc_f90%saa (1, 1))
preproc%vza = c_loc(preproc_f90%vza (1, 1))
preproc%vaa = c_loc(preproc_f90%vaa (1, 1))
preproc%data2 = c_loc(preproc_f90%data(1, 1, 1))
end if
status = seviri_read_and_preproc(trim(filename)//C_NULL_CHAR, preproc, &
n_bands, band_ids, band_units, bounds, line0, line1, column0, column1, &
lat0, lat1, lon0, lon1, do_calib, satposstr, do_not_alloc)
if (status .ne. 0) then
write(6, *) 'ERROR: seviri_read_and_preproc()'
return
end if
preproc_f90%memory_alloc_d = .false.
if (preproc%memory_alloc_d .ne. 0) &
preproc_f90%memory_alloc_d = .true.
preproc_f90%n_bands = preproc%n_bands
preproc_f90%n_lines = preproc%n_lines
preproc_f90%n_columns = preproc%n_columns
preproc_f90%fill_value = preproc%fill_value
shape1 = [preproc_f90%n_columns, preproc_f90%n_lines]
if (.not. do_not_alloc_f90) then
call c_f_pointer(preproc%time, preproc_f90%time, shape1)
call c_f_pointer(preproc%lat, preproc_f90%lat, shape1)
call c_f_pointer(preproc%lon, preproc_f90%lon, shape1)
call c_f_pointer(preproc%sza, preproc_f90%sza, shape1)
call c_f_pointer(preproc%saa, preproc_f90%saa, shape1)
call c_f_pointer(preproc%vza, preproc_f90%vza, shape1)
call c_f_pointer(preproc%vaa, preproc_f90%vaa, shape1)
shape2 = [preproc_f90%n_columns, preproc_f90%n_lines, n_bands]
call c_f_pointer(preproc%data2, preproc_f90%data, shape2)
end if
preproc_f90%preproc = preproc
end function seviri_read_and_preproc_f90
integer function seviri_preproc_free_f90(preproc_f90) result(status)
implicit none
type(seviri_preproc_t_f90), intent(inout) :: preproc_f90
status = seviri_preproc_free(preproc_f90%preproc)
end function seviri_preproc_free_f90
end module seviri_util