-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReadGLA12.f95
1530 lines (1101 loc) · 46 KB
/
ReadGLA12.f95
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! fortran 90/95 program
! for icesat gla12 reading
!
! Mauro Alberti,
! July-November, 2007; April 2016
!
! part of code inspired to Fortran programs in NSIDC web site
! modified:
! 2008-09-23: changed InputFile to GLA12FileName, and its width to 45 (string then trimmed);
! 2010-06-26: output GIS data to multiple files; read analysis parameters for a text file
! 2016-04-30: adapted to release 34
!------------------------------------------------
module kinds_mod
integer, parameter :: i1b = selected_int_kind(1)
integer, parameter :: i2b = selected_int_kind(4)
integer, parameter :: i4b = selected_int_kind(9)
integer, parameter :: r4b = selected_real_kind( 6, 37)
integer, parameter :: r8b = selected_real_kind(15,307)
real (kind=r8b), parameter :: div_D06=1.0D06, div_D03=1.0D03, div_D02=1.0D02
! GLA input invalid_values
integer (kind=i1b),parameter :: gi_invalid_i1b=127
integer (kind=i2b),parameter :: gi_invalid_i2b=32767
integer (kind=i4b),parameter :: gi_invalid_i4b=2147483647
real (kind=r4b),parameter :: gi_invalid_r4b = huge(1.0_r4b)
real (kind=r8b),parameter :: gi_invalid_r8b = huge(1.0_r8b)
end module kinds_mod
!------------------------------------------------
!------------------------------------------------
module time_processing
use kinds_mod
type :: date
sequence
integer (kind=i2b) :: year, month, day, hour, minutes
real (kind=r4b) :: seconds
end type date
contains
!-----------------------------
! '..... to provide the calculation of Julian dates,
! after the C routines found in _ACM SIGNUM Newsletter_
! v 30, n 4, October 1995, beginning on p 14,
! "Algorithms for Julian Dates" by Richard L. Branham, Jr.'
! 'Translated to Fortran 90 by Dan Nagle, January, 1996.'
! Modified for inclusion into present program by Mauro Alberti, November, 2007
! Origin time_date is 2000-01-01 12:00:00.
real(kind=r8b) function date_to_j2000_sec(time_date) result(julian_time_sec)
type(date), intent(in) :: time_date
real(kind=r8b) :: julian_time_days
! days prior to beginning of each month (ly: leap year)
integer, parameter, dimension(13) :: &
bgn_day = (/0,31,59,90,120,151,181,212,243,273,304,334,365/), &
bgn_day_ly = (/0,31,60,91,121,152,182,213,244,274,305,335,366 /)
! calculate julian days at year start (1461 days in 4 years starting 4713 BC)
julian_time_days = real(((1461*(4712 + time_date%year)-1)/4), kind=r8b)
! add month day number (except the days in current month)
if( mod(time_date%year,4_i2b) == 0 )then
julian_time_days = julian_time_days + real( bgn_day_ly(time_date%month), r8b) !leap year
else
julian_time_days = julian_time_days + real( bgn_day(time_date%month), r8b)
endif
! add day number of current month
julian_time_days = julian_time_days + real(time_date%day,kind=r8b)
! correct for difference between astronomical and civil time_date, i.e. civil day less 12 hours
julian_time_days = julian_time_days - 0.5_r8b
! correct for origin time at 2000-01-01
julian_time_days = julian_time_days - 2451558.0_r8b
! converts to seconds and adds hours, minutes and seconds
julian_time_sec = julian_time_days*86400.0_r8b + real(time_date%hour,kind=r8b)*3600.0_r8b &
+ real(time_date%minutes,kind=r8b)*60.0_r8b + real(time_date%seconds,kind=r8b)
end function date_to_j2000_sec
!-----------------------------
!-----------------------------
! PURPOSE: Convert J2000 seconds to date
! in a structure containing year,month,day, hour,minutes,seconds
type(date) function date_from_j20002(J2000time_sec) result(time_date)
implicit none
real (kind=r8b), intent(in) :: J2000time_sec
integer (kind=i2b) :: i
integer (kind=i4b) :: J2000time
real (kind=r8b) :: residual_sec
integer (kind=i2b):: days_months (12)
integer (kind=i4b) :: month_sec_upp, month_sec
integer (kind=i4b), parameter :: day_secs = 86400
!---------------
days_months = (/31,28,31,30,31,30,31,31,30,31,30,31/)
J2000time = ceiling(J2000time_sec)
SELECT CASE (J2000time)
case(:-43201)
time_date%year = 9999
residual_sec = 9999
case(-43200:31579199)
time_date%year = 2000
residual_sec = J2000time_sec + 43200.0
case(31579200:63115199)
time_date%year = 2001
residual_sec = J2000time_sec - 31579200.0
case(63115200:94651199)
time_date%year = 2002
residual_sec = J2000time_sec - 63115200.0
case(94651200:126187199)
time_date%year = 2003
residual_sec = J2000time_sec - 94651200.0
case(126187200:157809599)
time_date%year = 2004
residual_sec = J2000time_sec - 126187200.0
case(157809600:189345599)
time_date%year = 2005
residual_sec = J2000time_sec - 157809600.0
case(189345600:220881599)
time_date%year = 2006
residual_sec = J2000time_sec - 189345600.0
case(220881600:252417599)
time_date%year = 2007
residual_sec = J2000time_sec - 220881600.0
case(252417600:284039999)
time_date%year = 2008
residual_sec = J2000time_sec - 252417600.0
case(284040000:315575999)
time_date%year = 2009
residual_sec = J2000time_sec - 284040000.0
case(315576000:)
time_date%year = 2010
residual_sec = J2000time_sec - 315576000.0
end select
! set february days number for leap years
if ((time_date%year == 2000).or. &
(time_date%year == 2004).or. &
(time_date%year == 2008)) then
days_months(2)=29
end if
month_sec = 0
do i=1,12
month_sec_upp = day_secs*days_months(i)+ month_sec
if (residual_sec < month_sec_upp) then
residual_sec = residual_sec - month_sec
exit
else
month_sec = month_sec_upp
end if
end do
time_date%month = i
time_date%day = int(residual_sec/day_secs)
residual_sec = residual_sec - (time_date%day*day_secs)
time_date%day = time_date%day+1
time_date%hour = int(residual_sec/3600.0)
residual_sec = residual_sec - (time_date%hour*3600)
time_date%minutes = int(residual_sec/60.0)
time_date%seconds = residual_sec - (time_date%minutes*60.0)
end function date_from_j20002
end module time_processing
!------------------------------------------------
!------------------------------------------------
module GLA12structure
use time_processing
! GLA12 Input Record Structure
type :: GLA12_prod_input
sequence
integer (kind=i4b) :: i_rec_ndx
integer (kind=i4b) :: i_UTCTime (2)
integer (kind=i2b) :: i_transtime
integer (kind=i1b) :: i_Spare1 (2)
integer (kind=i4b) :: i_deltagpstmcor
integer (kind=i4b) :: i_dShotTime (39)
integer (kind=i4b) :: i_lat (40)
integer (kind=i4b) :: i_lon (40)
integer (kind=i4b) :: i_elev (40)
integer (kind=i1b) :: i_campaign (2)
integer (kind=i2b) :: i_spare40
integer (kind=i4b) :: i_cycTrk
integer (kind=i4b) :: i_localSolarTime
integer (kind=i4b) :: i_spare41 (7)
integer (kind=i2b) :: i_deltaEllip (40)
integer (kind=i4b) :: i_beamCoelv (40)
integer (kind=i4b) :: i_beamAzimuth (40)
integer (kind=i4b) :: i_d2refTrk (40)
integer (kind=i4b) :: i_SigBegOff (40)
integer (kind=i1b) :: i_DEM_hires_src (40)
integer (kind=i2b) :: i_DEMhiresArElv (9,40)
integer (kind=i2b) :: i_ElevBiasCorr (40)
integer (kind=i2b) :: i_GmC (40)
integer (kind=i2b) :: i_spare42 (3, 40)
integer (kind=i2b) :: i_sigmaatt (40)
integer (kind=i4b) :: i_Azimuth
integer (kind=i4b) :: i_SolAng
integer (kind=i4b) :: i_tpintensity_avg
integer (kind=i2b) :: i_tpazimuth_avg
integer (kind=i2b) :: i_tpeccentricity_avg
integer (kind=i2b) :: i_tpmajoraxis_avg
integer (kind=i1b) :: i_poleTide (2)
integer (kind=i2b) :: i_gdHt (2)
integer (kind=i2b) :: i_erElv (2)
integer (kind=i2b) :: i_spElv (4)
integer (kind=i2b) :: i_ldElv (4)
integer (kind=i2b) :: i_spare12 (2)
integer (kind=i2b) :: i_wTrop (2)
integer (kind=i2b) :: i_dTrop (40)
integer (kind=i1b) :: i_surfType
integer (kind=i1b) :: i_spare11 (3)
integer (kind=i4b) :: i_DEM_elv (40)
integer (kind=i4b) :: i_refRng (40)
integer (kind=i4b) :: i_TrshRngOff (40)
integer (kind=i4b) :: i_isRngOff (40)
integer (kind=i4b) :: i_SigEndOff (40)
integer (kind=i4b) :: i_cntRngOff (40)
integer (kind=i4b) :: i_reflctUC (40)
integer (kind=i4b) :: i_reflCor_atm
integer (kind=i2b) :: i_maxSmAmp (40)
integer (kind=i2b) :: i_ocElv (40)
integer (kind=i1b) :: i_numPk (40)
integer (kind=i2b) :: i_kurt2 (40)
integer (kind=i2b) :: i_skew2 (40)
integer (kind=i1b) :: i_spare4 (160)
integer (kind=i4b) :: i_IsRngLast (40)
integer (kind=i4b) :: i_IsRngFst (40)
integer (kind=i2b) :: i_IceSVar (40)
integer (kind=i1b) :: i_ElvuseFlg (5)
integer (kind=i1b) :: i_atm_avail
integer (kind=i1b) :: i_spare16 (4)
integer (kind=i1b) :: i_cld1_mswf
integer (kind=i1b) :: i_MRC_af
integer (kind=i1b) :: i_spare9 (40)
integer (kind=i1b) :: i_ElvFlg (40)
integer (kind=i2b) :: i_rng_UQF (40)
integer (kind=i1b) :: i_spare49 (10)
integer (kind=i2b) :: i_timecorflg
integer (kind=i1b) :: i_APID_AvFlg (8)
integer (kind=i1b) :: i_AttFlg2 (20)
integer (kind=i1b) :: i_spare5
integer (kind=i1b) :: i_FrameQF
integer (kind=i1b) :: i_OrbFlg (2)
integer (kind=i1b) :: i_rngCorrFlg (2)
integer (kind=i1b) :: i_CorrStatFlg (2)
integer (kind=i1b) :: i_spare15 (8)
integer (kind=i2b) :: i_AttFlg1
integer (kind=i1b) :: i_Spare6 (2)
integer (kind=i1b) :: i_spare44 (120)
integer (kind=i1b) :: i_satNdx (40)
integer (kind=i2b) :: i_satElevCorr (40)
integer (kind=i1b) :: i_satCorrFlg (40)
integer (kind=i2b) :: i_satNrgCorr (40)
integer (kind=i2b) :: i_spare13 (40)
integer (kind=i2b) :: i_gval_rcv (40)
integer (kind=i2b) :: i_RecNrgAll (40)
integer (kind=i2b) :: i_FRir_cldtop (40)
integer (kind=i1b) :: i_FRir_qaFlag (40)
integer (kind=i2b) :: i_atm_char_flag
integer (kind=i2b) :: i_atm_char_conf
integer (kind=i1b) :: i_spare48 (36)
integer (kind=i2b) :: i_FRir_intsig (40)
integer (kind=i1b) :: i_spare14 (120)
integer (kind=i2b) :: i_Surface_temp
integer (kind=i2b) :: i_Surface_pres
integer (kind=i2b) :: i_Surface_relh
integer (kind=i2b) :: i_maxRecAmp (40)
integer (kind=i2b) :: i_sDevNsOb1 (40)
integer (kind=i1b) :: i_pctSAT (40)
integer (kind=i2b) :: i_TxNrg (40)
integer (kind=i2b) :: i_eqElv (2)
integer (kind=i1b) :: i_spare7 (282)
end type GLA12_prod_input
! Pole datum - defined by latitude and longitude, in decimal degrees
type :: pole
sequence
real (kind=r8b) :: lat_degr, lon_degr
end type pole
! GLA12 Output Record Structure - subset of the input structure, with converted unit measure, plus identifiers of track and shot
type :: GLA12_prod_output
sequence
integer (kind=i4b) :: id_shot ! id of shot
character (len=45) :: GLA12sourcefile ! GLA12 file name
integer (kind=i4b) :: id_track ! id of track
integer (kind=i4b) :: rec_ndx ! GLA12 record index
real (kind=r8b) :: UTCTime_julsec ! shot time in Julian seconds
type (date) :: time_shot ! shot time in year-month-day-hr-min-sec
type (pole) :: shot_loc ! location (latitude-longitude)
integer (kind=i1b) :: ElvuseFlg ! elevation use flag (0: valid elevation; 1: invalid e.)
real (kind=r4b) :: elev ! elevation (meters)
real (kind=r4b) :: satElevCorr ! elevation correction for saturation (meters)
real (kind=r4b) :: gdHt ! geoid (meters)
real (kind=r4b) :: erElv ! solid earth tide elevation (meters, linearly interpolated between first and last shot)
integer (kind=i2b) :: gval_rcv ! gain value used for received pulse
integer (kind=i2b) :: sigmaatt ! attitude quality indicator
real (kind=r4b) :: RecNrgAll ! received energy signal begin to signal end
integer (kind=i1b) :: numPk ! number of peaks found in the return
real (kind=r4b) :: kurt2 ! kurtosis of the received echo (standard)
real (kind=r4b) :: skew2 ! skewness
integer (kind=i2b) :: IceSVar ! standard deviation of the ice sheet Gaussian fit
integer (kind=i1b) :: satNdx ! saturation index
integer (kind=i1b) :: pctSAT ! percent saturation
end type GLA12_prod_output
integer (kind=i4b), parameter :: OutputRecLength = 133
end module GLA12structure
!------------------------------------------------
!------------------------------------------------
module UserInputs
use GLA12structure
implicit none
integer (i2b) :: ios, dummy_int
character (len= 37) :: InputFilesListName, InputParametersName
! Analysis filtering parameter structure
type :: analysis_param
! geographic parameters
real (r8b) :: lat_min, lat_max, long_min, long_max
! temporal parameters
logical :: temporal_filtering
real (r8b) :: timewindow_julsec(2)
type(date) :: timewindow_date(2)
! quality parameters
logical :: data_quality_filtering
integer (i2b) :: maxallow_SatElevCorr, maxallow_Gain
end type
contains
!-------------------------
! choice of input file storing the list of GLA12 files
subroutine InputFileDef()
do
write (*,"(A)", ADVANCE="no") 'Enter input list filename: '
read (*,*) InputFilesListName
open (unit=15,file=InputFilesListName,status='OLD',access='sequential', iostat=ios)
if (ios /= 0) then
write(*,*) 'Input file not found - Choose again'
else
exit
end if
end do
write (*,*)
end subroutine InputFileDef
!-------------------------
!-------------------------
! define output files storing results
subroutine OutputFilesDef()
character (len= 37) :: OutputFileName
do
write (*,"(A)", ADVANCE="no") 'Enter output filename (without extensions): '
read (*,*) OutputFileName
! create direct-access output file (for analysis with HeightVarGLA Fortran program)
open (unit=17,file=trim(OutputFileName)//'_an.dat',status='NEW' &
, access='direct', form='unformatted',recl=OutputRecLength, iostat=ios)
if (ios /= 0) then
write (*,"(A,/,A)") 'Error with output file creation.','Change name'
cycle
end if
! create metadata output file
open (unit=18,file=trim(OutputFileName)//'_md.txt',status='NEW' &
, access='sequential', form='formatted', iostat=ios)
if (ios /= 0) then
write (*,"(A,/,A)") 'Error with output file creation.','Change name'
cycle
end if
exit
end do
write (*,*)
end subroutine OutputFilesDef
!-------------------------
!-------------------------
! define parameters of analysis
! (i.e. geographical, time and quality subsetting)
subroutine ParamsDef(params)
type(analysis_param), intent(out) :: params
type(date):: dummy_date(2)
do
write (*,"(A)", ADVANCE="no") 'Enter parameters filename: '
read (*,*) InputParametersName
open (unit=20,file=InputParametersName,status='OLD',access='sequential', iostat=ios)
if (ios /= 0) then
write(*,*) 'Input parameters file not found - Choose again'
else
exit
end if
end do
! reads the boundary region
!! latitude
read (20,*) params%lat_min, params%lat_max
if (params%lat_min >= params%lat_max) then
write (*,*) 'Error: minimum value of latitude larger or equal to maximum value'
write (*,*) 'Program will stop'
stop
end if
!! longitude
read (20,*) params%long_min, params%long_max
if (params%long_min >= params%long_max) then
write (*,*) 'Error: minimum value of longitude larger or equal to maximum value '
write (*,*) 'Program will stop'
stop
end if
!! time
read (20,*) params%timewindow_date(1)%year &
,params%timewindow_date(1)%month,params%timewindow_date(1)%day &
,params%timewindow_date(2)%year,params%timewindow_date(2)%month &
,params%timewindow_date(2)%day
if (params%timewindow_date(1)%year == -1) then
params%temporal_filtering = .false.
else
params%temporal_filtering = .true.
end if
if (params%temporal_filtering) then
! check initial time
if ((params%timewindow_date(1)%month<1).or. &
(params%timewindow_date(1)%month>12).or. &
(params%timewindow_date(1)%day<1).or. &
(params%timewindow_date(1)%day>31)) then
write(*,*) 'Error in intial time month/day value(s)'
write (*,*) 'Program will stop'
stop
end if
params%timewindow_date(1)%hour = 0_i2b
params%timewindow_date(1)%minutes = 0_i2b
params%timewindow_date(1)%seconds = 0.0_r4b
params%timewindow_julsec(1) = date_to_j2000_sec(params%timewindow_date(1))
! check final time
if ((params%timewindow_date(2)%month<1).or. &
(params%timewindow_date(2)%month>12).or. &
(params%timewindow_date(2)%day<1).or. &
(params%timewindow_date(2)%day>31)) then
write(*,*) 'Error in final time month/day value(s)'
write (*,*) 'Program will stop'
stop
end if
params%timewindow_date(2)%hour = 0_i2b
params%timewindow_date(2)%minutes = 0_i2b
params%timewindow_date(2)%seconds = 0.0_r4b
params%timewindow_julsec(2) = date_to_j2000_sec(params%timewindow_date(2))
if (params%timewindow_julsec(2)<=params%timewindow_julsec(1)) then
write(*,*) 'Error: final time lower or equal to initial time'
write (*,*) 'Program will stop'
stop
end if
end if
!! quality filtering
read (20,*) params%maxallow_SatElevCorr, params%maxallow_Gain
if ((params%maxallow_SatElevCorr==-1).and. &
(params%maxallow_Gain==-1)) then
params%data_quality_filtering = .false.
else
params%data_quality_filtering = .true.
end if
close(unit=20)
write (*,*)
end subroutine ParamsDef
!------------------------
end module UserInputs
!------------------------------------------------
!------------------------------------------------
module InputAnalysis
use UserInputs
implicit none
contains
!-----------------------------
! calculate number of GLA12 file to read
function GLA12FilesNumber() result (GLA12Files_Number)
integer (kind=i2b) :: GLA12Files_Number
character (len= 45) :: GLA12FileName
GLA12Files_Number=0
do
read(15, *, iostat=ios) GLA12FileName
if (ios==0) then
GLA12Files_Number=GLA12Files_Number+1
else
exit
end if
end do
rewind(unit=15,iostat=ios)
if (ios/=0) then
write(*,*) ' error in rewinding the input list of file'
read(*,*)
stop
end if
end function GLA12FilesNumber
end module InputAnalysis
!------------------------------------------------
!------------------------------------------------
module InOutputsData
use InputAnalysis
implicit none
! name of input GLA12 files
character (len= 45) :: GLA12FileName
! first and last analysed time_date
real (kind=r8b) :: i_UTCTime_sec_MIN, i_UTCTime_sec_MAX
contains
!-----------------------------
! initialization of minimum and maximum analysed time_date
subroutine MinMaxTime_Initialization()
i_UTCTime_sec_MAX = 0
i_UTCTime_sec_MIN = huge(i_UTCTime_sec_MAX)
end subroutine MinMaxTime_Initialization
!-----------------------------
!-----------------------------
! processing of input GLA12 file
subroutine process_GLA12file (GLA12FileName, RecNum, params, numRecsUsedGLA12File)
implicit none
character (len=45), intent(in) :: GLA12FileName
integer (kind=i4b), intent(inout) :: RecNum, numRecsUsedGLA12File
type(analysis_param) :: params
type(analysis_param) :: FilteringParameters
integer (kind=i2b) :: ios_inpt, n
integer (kind=i4b) :: m
!------------------
! variable initialization
type (GLA12_prod_input) :: GLA12_prod_in !! GLA12 product vars
!------------------
! create sequential-access output file (for import in GIS)
open (unit=19,file=trim(GLA12FileName)//'_gis.txt',status='NEW' &
, access='sequential', form='formatted', iostat=ios)
if (ios /= 0) then
print*, 'Unable to create output GIS file. Program will stop'
stop
end if
! writes header of GIS-read file
call GISReadFileHeader()
!------------------
! read and process records in GLA12 input file
open (unit=16,file=GLA12FileName,status='OLD',access='direct', &
recl=6600,iostat=ios_inpt)
! local initialisations
n = 0
m = 0
numRecsUsedGLA12File = 0
! read cycle
do
n = n + 1
read(16,rec=n,iostat=ios_inpt) GLA12_prod_in
if (ios_inpt==0) then
call process_GLA12record(params, GLA12FileName, GLA12_prod_in, RecNum, m, numRecsUsedGLA12File)
else
exit
end if
end do
if (numRecsUsedGLA12File > 0) then
close(unit=19, STATUS='keep')
else
close(unit=19, STATUS='delete')
end if
end subroutine process_GLA12file
!------------------------
!------------------------
! processing of single GLA12 record
subroutine process_GLA12record(params, GLA12FileName, GLA12_prod_in, RecNum, m, numRecsUsedGLA12File)
! variable declarations
character (len=45), intent(in) :: GLA12FileName
type(analysis_param), intent(in) :: params
integer (kind=i4b), intent(inout) :: RecNum, numRecsUsedGLA12File, m
type (GLA12_prod_input) :: GLA12_prod_in
type (GLA12_prod_output) :: GLA12_prod_out
real (kind=r8b) :: conv_long
character (len=45) :: GLA12file_R
integer (kind=i1b) :: j_BElvuseFlg, j_bitElvuseFlg, ElvuseFlg_Byte
integer (kind=i1b), dimension(40) :: ShotElvuseFlg
integer (kind=i2b) :: i, ndx_rec_EUF
integer (kind=i4b), save :: cod_prof
real (kind=r4b) :: i_erElv_1_R, i_erElv_2_R, i_erElv_delta_R &
, i_gdHt_1_R, i_gdHt_2_R, i_gdHt_delta_R
type(date) :: shot_time
! logical variable that defines whether to print out shot data
logical :: ShotDataPrintOut
! declarations of time_date variables
integer (kind=i4b), save :: i_UTCTime_previous
real (kind=r8b) :: i_UTCTime_sec_R, i_UTCTime_sec(40)
!----------------
! initialize variables
GLA12file_R = GLA12FileName
! time_date of first shot in record
i_UTCTime_sec_R = GLA12_prod_in%i_UTCTime(1) + (GLA12_prod_in%i_UTCTime(2)/div_D06)
! START of elevation use flag processing
do j_BElvuseFlg = 5,1,-1
ElvuseFlg_Byte = GLA12_prod_in%i_ElvuseFlg(j_BElvuseFlg)
do j_bitElvuseFlg = 0,7
ndx_rec_EUF = (5-j_BElvuseFlg)*8 + (j_bitElvuseFlg+1)
ShotElvuseFlg(ndx_rec_EUF) = ibits(ElvuseFlg_Byte,j_bitElvuseFlg,1)
end do
end do
! END of elevation use flag processing
! START of definition of cod_prof - time_date difference with previous record greater than 100 [seconds]
if (m==1) then
cod_prof = 1
i_UTCTime_previous = GLA12_prod_in%i_UTCTime(1)
end if
if (GLA12_prod_in%i_UTCTime(1)>(i_UTCTime_previous + 100)) then
cod_prof = cod_prof + 1
end if
i_UTCTime_previous = GLA12_prod_in%i_UTCTime(1)
! END of definition of cod_prof
! START of processing of geoid height
if ((GLA12_prod_in%i_gdHt(1) /= gi_invalid_i2b) .and. &
(GLA12_prod_in%i_gdHt(2) /= gi_invalid_i2b)) then
i_gdHt_1_R = GLA12_prod_in%i_gdHt(1)/div_D02
i_gdHt_2_R = GLA12_prod_in%i_gdHt(2)/div_D02
i_gdHt_delta_R = (i_gdHt_2_R - i_gdHt_1_R)/39.0
end if
! END of processing of geoid height
! START of Solid Earth Tide Elevation (at first & last shot) processing
if ((GLA12_prod_in%i_erElv(1) /= gi_invalid_i2b) .and. &
(GLA12_prod_in%i_erElv(2) /= gi_invalid_i2b)) then
i_erElv_1_R = GLA12_prod_in%i_erElv(1)/div_D03
i_erElv_2_R = GLA12_prod_in%i_erElv(2)/div_D03
i_erElv_delta_R = (i_erElv_2_R - i_erElv_1_R)/39.0
end if
! END of Solid Earth Tide Elevation (at first & last shot) processing
! START shot-by-shot reading of record data
ShotDataPrintOut = .false.
do i=1,40
m = m + 1
! START OF RECORD FILTERING
! invalid latitude, longitude or elevation values
if ((GLA12_prod_in%i_lat(i) == gi_invalid_i4b) .or. &
(GLA12_prod_in%i_lon(i) == gi_invalid_i4b) .or. &
(GLA12_prod_in%i_elev(i) == gi_invalid_i4b)) then
cycle
end if
! geographic filtering
! latitude
if ((GLA12_prod_in%i_lat(i)/div_D06 < params%lat_min) .or. &
(GLA12_prod_in%i_lat(i)/div_D06 > params%lat_max)) then
cycle
end if
! longitude
! longitude conversion
conv_long = GLA12_prod_in%i_lon(i)/div_D06
if (conv_long > 180.0) then
conv_long = conv_long - 360.0
end if
if ((conv_long < params%long_min) .or. &
(conv_long > params%long_max)) then
cycle
end if
! END geographic filtering/processing
! julian time processing
if (i==1) then
i_UTCTime_sec(i) = i_UTCTime_sec_R
else
i_UTCTime_sec(i) = i_UTCTime_sec_R + (GLA12_prod_in%i_dShotTime(i-1)/div_D06)
end if
! time filtering
if (params%temporal_filtering) then
if ((i_UTCTime_sec(i) < params%timewindow_julsec(1)).or. &
(i_UTCTime_sec(i) > params%timewindow_julsec(2))) then
cycle
end if
end if
! time date processing
shot_time = date_from_j20002(i_UTCTime_sec(i))
! END of time filtering
! START quality data filtering/processing
if (params%data_quality_filtering) then
! gain
if (params%maxallow_Gain /= -1) then
if ((GLA12_prod_in%i_gval_rcv(i) == gi_invalid_i2b) .or. &
(GLA12_prod_in%i_gval_rcv(i) > params%maxallow_Gain)) then
cycle
end if
end if
! saturation elevation correction
if (params%maxallow_SatElevCorr /= -1) then
if ((GLA12_prod_in%i_satElevCorr(i) == gi_invalid_i2b) .or. &
(GLA12_prod_in%i_satElevCorr(i) > params%maxallow_SatElevCorr)) then
cycle
end if
end if
end if !(params%data_quality_filtering)
! END quality data filtering/processing
! END OF RECORD FILTERING/PROCESSING
!!
! ! IF WE ARE HERE, SHOT DATA WILL BE PRINT OUT
!!
! setting of variable for min and max time_date
ShotDataPrintOut = .true.
! setting of RecNum, the progressive counter of filtered-in records from all GLA12 file
RecNum = RecNum + 1
! setting of the number of filtered-in records from the current GLA12 file
numRecsUsedGLA12File = numRecsUsedGLA12File +1
! definition of shot parameters
GLA12_prod_out%id_shot = RecNum
GLA12_prod_out%GLA12sourcefile = GLA12file_R
GLA12_prod_out%id_track = cod_prof
GLA12_prod_out%rec_ndx = GLA12_prod_in%i_rec_ndx
GLA12_prod_out%UTCTime_julsec = i_UTCTime_sec(i) !time_date in Julian seconds
GLA12_prod_out%time_shot = shot_time
GLA12_prod_out%shot_loc%lat_degr = GLA12_prod_in%i_lat(i)/div_D06
GLA12_prod_out%shot_loc%lon_degr = GLA12_prod_in%i_lon(i)/div_D06
if (GLA12_prod_out%shot_loc%lon_degr > 180.0) then
GLA12_prod_out%shot_loc%lon_degr = GLA12_prod_out%shot_loc%lon_degr - 360.0
end if
GLA12_prod_out%ElvuseFlg = ShotElvuseFlg(i)
GLA12_prod_out%elev = GLA12_prod_in%i_elev(i)/div_D03
! TEST su corretto processing di Saturation Elevation Correction
if (mod(RecNum,10) == 0) then
GLA12_prod_in%i_satElevCorr(i) = gi_invalid_i2b
end if
! Saturation Elevation Correction
if (GLA12_prod_in%i_satElevCorr(i) /= gi_invalid_i2b) then
GLA12_prod_out%satElevCorr = GLA12_prod_in%i_satElevCorr(i)/div_D03
else
GLA12_prod_out%satElevCorr = gi_invalid_r4b
end if
! Geoid
if ((GLA12_prod_in%i_gdHt(1) /= gi_invalid_i2b) .and. &
(GLA12_prod_in%i_gdHt(2) /= gi_invalid_i2b)) then
GLA12_prod_out%gdHt = i_gdHt_1_R + (i-1)*i_gdHt_delta_R
else
GLA12_prod_out%gdHt = gi_invalid_r4b
end if
! Solid earth tide elevation (linearly interpolated between first and last shot)
if ((GLA12_prod_in%i_erElv(1) /= gi_invalid_i2b) .and. &
(GLA12_prod_in%i_erElv(2) /= gi_invalid_i2b)) then
GLA12_prod_out%erElv = i_erElv_1_R + (i-1)*i_erElv_delta_R
else
GLA12_prod_out%erElv = gi_invalid_r4b
end if
! Gain Value used for Received Pulse
if (GLA12_prod_in%i_gval_rcv(i) /= gi_invalid_i2b) then
GLA12_prod_out%gval_rcv = GLA12_prod_in%i_gval_rcv(i)
else