-
Notifications
You must be signed in to change notification settings - Fork 6
/
CRTM_RTSolution_Define.f90
2866 lines (2598 loc) · 108 KB
/
CRTM_RTSolution_Define.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
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
!
! CRTM_RTSolution_Define
!
! Module defining the CRTM RTSolution structure and containing routines
! to manipulate it.
!
!
! CREATION HISTORY:
! Written by: Paul van Delst, 13-May-2004
!
! Modified by: James Rosinski, 08-Feb-2019
!
! Modified by: Cheng Dang, 09-Aug-2023, add CRTM_RTSolution_WriteFile_netCDF
!
MODULE CRTM_RTSolution_Define
! ------------------
! Environment set up
! ------------------
! Intrinsic modules
USE ISO_Fortran_Env , ONLY: OUTPUT_UNIT
! Module use statements
USE Type_Kinds , ONLY: Double, Long, fp
USE Message_Handler , ONLY: SUCCESS, FAILURE, WARNING, INFORMATION, Display_Message
USE Compare_Float_Numbers, ONLY: DEFAULT_N_SIGFIG, &
OPERATOR(.EqualTo.), &
Compares_Within_Tolerance
USE File_Utility , ONLY: File_Open, File_Exists
USE Binary_File_Utility , ONLY: Open_Binary_File , &
WriteGAtts_Binary_File, &
ReadGAtts_Binary_File
USE SensorInfo_Parameters, ONLY: INVALID_SENSOR, &
INVALID_WMO_SATELLITE_ID, &
INVALID_WMO_SENSOR_ID
USE CRTM_Parameters , ONLY: STRLEN
USE netcdf
! Disable all implicit typing
IMPLICIT NONE
! --------------------
! Default visibilities
! --------------------
! Everything private by default
PRIVATE
! Datatypes
PUBLIC :: CRTM_RTSolution_type
! Operators
PUBLIC :: OPERATOR(==)
PUBLIC :: OPERATOR(+)
PUBLIC :: OPERATOR(-)
! Public procedures
PUBLIC :: CRTM_RTSolution_Associated
PUBLIC :: CRTM_RTSolution_Destroy
PUBLIC :: CRTM_RTSolution_Create
PUBLIC :: CRTM_RTSolution_Zero
PUBLIC :: CRTM_RTSolution_Inspect
PUBLIC :: CRTM_RTSolution_DefineVersion
PUBLIC :: CRTM_RTSolution_Compare
PUBLIC :: CRTM_RTSolution_Statistics
PUBLIC :: CRTM_RTSolution_InquireFile
PUBLIC :: CRTM_RTSolution_ReadFile
PUBLIC :: CRTM_RTSolution_WriteFile
PUBLIC :: CRTM_RTSolution_WriteFile_netCDF
! ---------------------
! Procedure overloading
! ---------------------
INTERFACE OPERATOR(==)
MODULE PROCEDURE CRTM_RTSolution_Equal
END INTERFACE OPERATOR(==)
INTERFACE OPERATOR(+)
MODULE PROCEDURE CRTM_RTSolution_Add
END INTERFACE OPERATOR(+)
INTERFACE OPERATOR(-)
MODULE PROCEDURE CRTM_RTSolution_Subtract
END INTERFACE OPERATOR(-)
INTERFACE OPERATOR(**)
MODULE PROCEDURE CRTM_RTSolution_Exponent
END INTERFACE OPERATOR(**)
INTERFACE OPERATOR(/)
MODULE PROCEDURE CRTM_RTSolution_Normalise
END INTERFACE OPERATOR(/)
INTERFACE SQRT
MODULE PROCEDURE CRTM_RTSolution_Sqrt
END INTERFACE SQRT
INTERFACE CRTM_RTSolution_Inspect
MODULE PROCEDURE Scalar_Inspect
MODULE PROCEDURE Rank2_Inspect
END INTERFACE CRTM_RTSolution_Inspect
! -----------------
! Module parameters
! -----------------
CHARACTER(*), PARAMETER :: MODULE_VERSION_ID = &
'$Id: CRTM_RTSolution_Define.f90 100697 2018-12-21 18:33:44Z [email protected] $'
! Literal constants
REAL(fp), PARAMETER :: ZERO = 0.0_fp
REAL(fp), PARAMETER :: ONE = 1.0_fp
! Message string length
INTEGER, PARAMETER :: ML = 256
! File status on close after write error
CHARACTER(*), PARAMETER :: WRITE_ERROR_STATUS = 'DELETE'
! Output netCDF attributes
! G_LONGNAME
CHARACTER(*), PARAMETER :: SENSOR_ID_GATTNAME = 'Sensor_ID' ! Char
! Dimension names
CHARACTER(*), PARAMETER :: LAYER_DIMNAME = 'n_Layers' ! K
CHARACTER(*), PARAMETER :: CHANNEL_DIMNAME = 'n_Channels' ! J
CHARACTER(*), PARAMETER :: STOKE_DIMNAME = 'n_Stokes'
! Variable names
CHARACTER(*), PARAMETER :: CHANNEL_VARNAME = 'Sensor_Channel' ! Integer
! CHARACTER(*), PARAMETER :: RTNAME_VARNAME = 'RT_Algorithm_Name' ! Char
! CHARACTER(*), PARAMETER :: SCATF_VARNAME = 'Scattering_Flag' ! Boolean
!... FLOAT, ALL VARIABLES ARE IN DIMENSION J (n_channels)
CHARACTER(*), PARAMETER :: STREAM_VARNAME = 'n_Full_Streams'
CHARACTER(*), PARAMETER :: SSAMAX_VARNAME = 'SSA_Max'
CHARACTER(*), PARAMETER :: SOD_VARNAME = 'SOD'
CHARACTER(*), PARAMETER :: SEMIS_VARNAME = 'Surface_Emissivity'
CHARACTER(*), PARAMETER :: SREFL_VARNAME = 'Surface_Reflectivity'
CHARACTER(*), PARAMETER :: UPR_VARNAME = 'Up_Radiance'
CHARACTER(*), PARAMETER :: DWNR_VARNAME = 'Down_Radiance'
CHARACTER(*), PARAMETER :: DWNSOLARR_VARNAME = 'Down_Solar_Radiance'
CHARACTER(*), PARAMETER :: SPR_VARNAME = 'Surface_Planck_Radiance'
CHARACTER(*), PARAMETER :: TCC_VARNAME = 'Total_Cloud_Cover'
CHARACTER(*), PARAMETER :: RCLEAR_VARNAME = 'R_clear'
CHARACTER(*), PARAMETER :: TBCLEAR_VARNAME = 'Tb_clear'
CHARACTER(*), PARAMETER :: RADIANCE_VARNAME = 'Radiance'
CHARACTER(*), PARAMETER :: BT_VARNAME = 'Brightness_Temperature'
!... FLOAT, ALL VARIABLES ARE IN DIMENSION J * K (n_Channels * n_Layers)
CHARACTER(*), PARAMETER :: UPOR_PRF_VARNAME = 'Upwelling_Overcast_Radiance'
CHARACTER(*), PARAMETER :: UPR_PRF_VARNAME = 'Upwelling_Radiance'
CHARACTER(*), PARAMETER :: LOP_VARNAME = 'Layer_Optical_Depth'
CHARACTER(*), PARAMETER :: SSA_VARNAME = 'Single_Scatter_Albedo'
! Variable units attribute.
CHARACTER(*), PARAMETER :: UNITS_ATTNAME = 'units'
CHARACTER(*), PARAMETER :: CHANNEL_UNITS = 'N/A'
CHARACTER(*), PARAMETER :: STREAM_UNITS = 'N/A'
CHARACTER(*), PARAMETER :: RTNAME_UNITS = 'N/A'
CHARACTER(*), PARAMETER :: SCATF_UNITS = 'N/A'
! ...Emissivity/Reflectivity
CHARACTER(*), PARAMETER :: SEMIS_UNITS = 'fraction (0->1)'
CHARACTER(*), PARAMETER :: SREFL_UNITS = 'fraction (0->1)'
! ...Cloud
CHARACTER(*), PARAMETER :: TCC_UNITS = 'fraction (0->1)'
CHARACTER(*), PARAMETER :: RCLEAR_UNITS = 'fraction (0->1)'
! Single scattering albedo, max single scattering Albedo
CHARACTER(*), PARAMETER :: SSA_UNITS = 'fraction (0->1)'
! SOD, Layer_Optical_Depth
CHARACTER(*), PARAMETER :: OD_UNITS = '1'
! ...Radiance, Up_Radiance, Down_Radiance, Down_Solar_Radiance, Surface_Planck_Radiance
CHARACTER(*), PARAMETER :: RAD_UNITS = 'Watts per Ssuare Metre per Micron per Rad (W m^-2 micron^-1 rad^-1)'
! ...Brightness_Temperature, Tb_clear
CHARACTER(*), PARAMETER :: BT_UNITS = 'Kelvin'
! Variable _FillValue attribute.
CHARACTER(*), PARAMETER :: FILLVALUE_ATTNAME = '_FillValue'
REAL(Double), PARAMETER :: FILL_FLOAT = -999.0_fp
INTEGER(long), PARAMETER :: FILL_INT = 0
CHARACTER(*) , PARAMETER :: FILL_CHAR = NF90_FILL_CHAR
! Variable types
INTEGER, PARAMETER :: INT_TYPE = NF90_INT
INTEGER, PARAMETER :: CHAR_TYPE = NF90_CHAR
INTEGER, PARAMETER :: FLOAT_TYPE = NF90_DOUBLE
! -------------------------------
! RTSolution data type definition
! -------------------------------
!:tdoc+:
TYPE :: CRTM_RTSolution_type
! Allocation indicator
LOGICAL :: Is_Allocated = .FALSE.
! Dimensions
INTEGER :: n_Layers = 0 ! K
! Sensor information
CHARACTER(STRLEN) :: Sensor_ID = ''
INTEGER :: WMO_Satellite_ID = INVALID_WMO_SATELLITE_ID
INTEGER :: WMO_Sensor_ID = INVALID_WMO_SENSOR_ID
INTEGER :: Sensor_Channel = 0
! RT algorithm information
CHARACTER(STRLEN) :: RT_Algorithm_Name = ''
! Internal variables. Users do not need to worry about these.
LOGICAL :: Scattering_Flag = .TRUE.
INTEGER :: n_Full_Streams = 0
INTEGER :: n_Stokes = 0
! Forward radiative transfer intermediate results for a single channel
! These components are not defined when they are used as TL, AD
! and K variables
REAL(fp) :: SSA_Max = ZERO ! Max Single Scattering Albedo in the profile
REAL(fp) :: SOD = ZERO ! Scattering Optical Depth
REAL(fp) :: Surface_Emissivity = ZERO
! For UV/Visible, Surface_Reflectivity,Up_Radiance,Down_Radiance are used, but their meanings are changed.
REAL(fp) :: Surface_Reflectivity = ZERO
REAL(fp) :: Up_Radiance = ZERO
REAL(fp) :: Down_Radiance = ZERO
REAL(fp) :: Down_Solar_Radiance = ZERO
REAL(fp) :: Surface_Planck_Radiance = ZERO
REAL(fp) :: Total_Cloud_Cover = ZERO ! Only used for fractional clear/cloudy calculation
REAL(fp) :: R_clear = ZERO ! Only used for fractional clear/cloudy calculation
REAL(fp) :: Tb_clear = ZERO ! Only used for fractional clear/cloudy calculation
REAL(fp), ALLOCATABLE :: Upwelling_Overcast_Radiance(:) ! K
REAL(fp), ALLOCATABLE :: Upwelling_Radiance(:) ! K
REAL(fp), ALLOCATABLE :: Layer_Optical_Depth(:) ! K
REAL(fp), ALLOCATABLE :: Single_Scatter_Albedo(:) ! K
! Radiative transfer results for a single channel
REAL(fp) :: Radiance = ZERO
REAL(fp) :: Brightness_Temperature = ZERO
REAL(fp) :: Stokes(4)
REAL(fp) :: SolarIrradiance = ZERO
END TYPE CRTM_RTSolution_type
!:tdoc-:
CONTAINS
!##################################################################################
!##################################################################################
!## ##
!## ## PUBLIC MODULE ROUTINES ## ##
!## ##
!##################################################################################
!##################################################################################
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_Associated
!
! PURPOSE:
! Elemental function to test the status of the allocatable components
! of a CRTM RTSolution object.
!
! CALLING SEQUENCE:
! Status = CRTM_RTSolution_Associated( RTSolution )
!
! OBJECTS:
! RTSolution: RTSolution structure which is to have its member's
! status tested.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN)
!
! FUNCTION RESULT:
! Status: The return value is a logical value indicating the
! status of the RTSolution members.
! .TRUE. - if the array components are allocated.
! .FALSE. - if the array components are not allocated.
! UNITS: N/A
! TYPE: LOGICAL
! DIMENSION: Same as input RTSolution argument
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL FUNCTION CRTM_RTSolution_Associated( RTSolution ) RESULT( Status )
TYPE(CRTM_RTSolution_type), INTENT(IN) :: RTSolution
LOGICAL :: Status
Status = RTSolution%Is_Allocated
END FUNCTION CRTM_RTSolution_Associated
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_Destroy
!
! PURPOSE:
! Elemental subroutine to re-initialize CRTM RTSolution objects.
!
! CALLING SEQUENCE:
! CALL CRTM_RTSolution_Destroy( RTSolution )
!
! OBJECTS:
! RTSolution: Re-initialized RTSolution structure.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Scalar OR any rank
! ATTRIBUTES: INTENT(OUT)
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_RTSolution_Destroy( RTSolution )
TYPE(CRTM_RTSolution_type), INTENT(OUT) :: RTSolution
RTSolution%Is_Allocated = .FALSE.
RTSolution%n_Layers = 0
END SUBROUTINE CRTM_RTSolution_Destroy
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_Create
!
! PURPOSE:
! Elemental subroutine to create an instance of the CRTM RTSolution object.
!
! CALLING SEQUENCE:
! CALL CRTM_RTSolution_Create( RTSolution, n_Layers )
!
! OBJECTS:
! RTSolution: RTSolution structure.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(OUT)
!
! INPUTS:
! n_Layers: Number of layers for which there is RTSolution data.
! Must be > 0.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Same as RTSolution object
! ATTRIBUTES: INTENT(IN)
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_RTSolution_Create( RTSolution, n_Layers )
! Arguments
TYPE(CRTM_RTSolution_type), INTENT(OUT) :: RTSolution
INTEGER, INTENT(IN) :: n_Layers
! Local variables
INTEGER :: alloc_stat
! Check input
IF ( n_Layers < 1 ) RETURN
! Perform the allocation
ALLOCATE( RTSolution%Upwelling_Radiance(n_Layers), &
RTSolution%Upwelling_Overcast_Radiance(n_Layers), &
RTSolution%Layer_Optical_Depth(n_Layers), &
RTSolution%Single_Scatter_Albedo(n_Layers), &
STAT = alloc_stat )
IF ( alloc_stat /= 0 ) RETURN
! Initialise
! ...Dimensions
RTSolution%n_Layers = n_Layers
! ...Arrays
RTSolution%Upwelling_Radiance = ZERO
RTSolution%Upwelling_Overcast_Radiance = ZERO
RTSolution%Layer_Optical_Depth = ZERO
RTSolution%Single_Scatter_Albedo = ZERO
! Set allocation indicator
RTSolution%Is_Allocated = .TRUE.
END SUBROUTINE CRTM_RTSolution_Create
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_Zero
!
! PURPOSE:
! Elemental subroutine to zero out the data components
! in a CRTM RTSolution object.
!
! CALLING SEQUENCE:
! CALL CRTM_RTSolution_Zero( rts )
!
! OUTPUTS:
! rts: CRTM RTSolution structure in which the data components
! are to be zeroed out.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN OUT)
!
! COMMENTS:
! - The dimension components of the structure are *NOT* set to zero.
! - The sensor infomration and RT algorithm components are
! *NOT* reset in this routine.
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_RTSolution_Zero( RTSolution )
TYPE(CRTM_RTSolution_type), INTENT(IN OUT) :: RTSolution
! Zero out the scalar data components
RTSolution%SSA_Max = ZERO
RTSolution%SOD = ZERO
RTSolution%Surface_Emissivity = ZERO
RTSolution%Surface_Reflectivity = ZERO
RTSolution%Up_Radiance = ZERO
RTSolution%Down_Radiance = ZERO
RTSolution%Down_Solar_Radiance = ZERO
RTSolution%Surface_Planck_Radiance = ZERO
RTSolution%Total_Cloud_Cover = ZERO
RTSolution%R_clear = ZERO
RTSolution%Tb_clear = ZERO
RTSolution%Radiance = ZERO
RTSolution%Brightness_Temperature = ZERO
RTSolution%Stokes = ZERO
! Zero out the array data components
IF ( CRTM_RTSolution_Associated(RTSolution) ) THEN
RTSolution%Upwelling_Radiance = ZERO
RTSolution%Upwelling_Overcast_Radiance = ZERO
RTSolution%Layer_Optical_Depth = ZERO
RTSolution%Single_Scatter_Albedo = ZERO
END IF
END SUBROUTINE CRTM_RTSolution_Zero
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_Inspect
!
! PURPOSE:
! Subroutine to print the contents of a CRTM RTSolution object to stdout.
!
! CALLING SEQUENCE:
! CALL CRTM_RTSolution_Inspect( RTSolution, Unit=unit )
!
! INPUTS:
! RTSolution: CRTM RTSolution object to display.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Scalar or Rank-2 (n_channels x n_profiles)
! ATTRIBUTES: INTENT(IN)
!
! OPTIONAL INPUTS:
! Unit: Unit number for an already open file to which the output
! will be written.
! If the argument is specified and the file unit is not
! connected, the output goes to stdout.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN), OPTIONAL
!
!:sdoc-:
!--------------------------------------------------------------------------------
SUBROUTINE Scalar_Inspect( RTSolution, Unit )
! Arguments
TYPE(CRTM_RTSolution_type), INTENT(IN) :: RTSolution
INTEGER, OPTIONAL, INTENT(IN) :: Unit
! Local variables
INTEGER :: fid
CHARACTER(len=*), PARAMETER :: fmt64 = '(3x,a,es22.15)' ! print in 64-bit precision
CHARACTER(len=*), PARAMETER :: fmt32 = '(3x,a,es13.6)' ! print in 32-bit precision
CHARACTER(len=*), PARAMETER :: fmt = fmt64 ! choose 64-bit precision
! Setup
fid = OUTPUT_UNIT
IF ( PRESENT(Unit) ) THEN
IF ( File_Open(Unit) ) fid = Unit
END IF
WRITE(fid,'(1x,"RTSolution OBJECT")')
! Display components
WRITE(fid,'(3x,"Sensor Id : ",a )') TRIM(RTSolution%Sensor_ID)
WRITE(fid,'(3x,"WMO Satellite Id : ",i0)') RTSolution%WMO_Satellite_ID
WRITE(fid,'(3x,"WMO Sensor Id : ",i0)') RTSolution%WMO_Sensor_ID
WRITE(fid,'(3x,"Channel : ",i0)') RTSolution%Sensor_Channel
WRITE(fid,'(3x,"RT Algorithm Name : ",a )') RTSolution%RT_Algorithm_Name
WRITE(fid,fmt) "Scattering Optical Depth : ", RTSolution%SOD
WRITE(fid,fmt) "Surface Emissivity : ", RTSolution%Surface_Emissivity
WRITE(fid,fmt) "Surface Reflectivity : ", RTSolution%Surface_Reflectivity
WRITE(fid,fmt) "Up Radiance : ", RTSolution%Up_Radiance
WRITE(fid,fmt) "Down Radiance : ", RTSolution%Down_Radiance
WRITE(fid,fmt) "Down Solar Radiance : ", RTSolution%Down_Solar_Radiance
WRITE(fid,fmt) "Surface Planck Radiance : ", RTSolution%Surface_Planck_Radiance
WRITE(fid,fmt) "Total cloud cover : ", RTSolution%Total_Cloud_Cover
WRITE(fid,fmt) "Radiance (clear) : ", RTSolution%R_clear
WRITE(fid,fmt) "Brightness Temperature (clear): ", RTSolution%Tb_clear
WRITE(fid,fmt) "Radiance : ", RTSolution%Radiance
WRITE(fid,fmt) "Brightness Temperature : ", RTSolution%Brightness_Temperature
IF ( CRTM_RTSolution_Associated(RTSolution) ) THEN
WRITE(fid,'(3x,"n_Layers : ",i0)') RTSolution%n_Layers
WRITE(fid,'(3x,"Upwelling Overcast Radiance :")')
WRITE(fid,'(5(1x,es22.15,:))') RTSolution%Upwelling_Overcast_Radiance
WRITE(fid,'(3x,"Upwelling Radiance :")')
WRITE(fid,'(5(1x,es22.15,:))') RTSolution%Upwelling_Radiance
WRITE(fid,'(3x,"Layer Optical Depth :")')
WRITE(fid,'(5(1x,es22.15,:))') RTSolution%Layer_Optical_Depth
END IF
FLUSH(fid)
END SUBROUTINE Scalar_Inspect
SUBROUTINE Rank2_Inspect( RTSolution, Unit )
TYPE(CRTM_RTSolution_type), INTENT(IN) :: RTSolution(:,:)
INTEGER, OPTIONAL, INTENT(IN) :: Unit
INTEGER :: fid
INTEGER :: i, n_channels
INTEGER :: j, n_profiles
fid = OUTPUT_UNIT
IF ( PRESENT(Unit) ) THEN
IF ( File_Open(Unit) ) fid = Unit
END IF
n_channels = SIZE(RTSolution,1)
n_profiles = SIZE(RTSolution,2)
DO j = 1, n_profiles
DO i = 1, n_channels
WRITE(fid, FMT='(1x,"PROFILE INDEX:",i0,", CHANNEL INDEX:",i0," - ")', ADVANCE='NO') j,i
CALL Scalar_Inspect(RTSolution(i,j), Unit=Unit)
END DO
END DO
END SUBROUTINE Rank2_Inspect
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_DefineVersion
!
! PURPOSE:
! Subroutine to return the module version information.
!
! CALLING SEQUENCE:
! CALL CRTM_RTSolution_DefineVersion( Id )
!
! OUTPUTS:
! Id: Character string containing the version Id information
! for the module.
! UNITS: N/A
! TYPE: CHARACTER(*)
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(OUT)
!
!:sdoc-:
!--------------------------------------------------------------------------------
SUBROUTINE CRTM_RTSolution_DefineVersion( Id )
CHARACTER(*), INTENT(OUT) :: Id
Id = MODULE_VERSION_ID
END SUBROUTINE CRTM_RTSolution_DefineVersion
!------------------------------------------------------------------------------
!:sdoc+:
! NAME:
! CRTM_RTSolution_Compare
!
! PURPOSE:
! Elemental function to compare two CRTM_RTSolution objects to within
! a user specified number of significant figures.
!
! CALLING SEQUENCE:
! is_comparable = CRTM_RTSolution_Compare( x, y, n_SigFig=n_SigFig )
!
! OBJECTS:
! x, y: Two CRTM RTSolution objects to be compared.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN)
!
! OPTIONAL INPUTS:
! n_SigFig: Number of significant figure to compare floating point
! components.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Conformable with inputs
! ATTRIBUTES: INTENT(IN), OPTIONAL
!
! FUNCTION RESULT:
! is_comparable: Logical value indicating whether the inputs are
! comparable.
! UNITS: N/A
! TYPE: LOGICAL
! DIMENSION: Same as inputs.
!:sdoc-:
!------------------------------------------------------------------------------
ELEMENTAL FUNCTION CRTM_RTSolution_Compare( &
x, &
y, &
n_SigFig ) &
RESULT( is_comparable )
TYPE(CRTM_RTSolution_type), INTENT(IN) :: x, y
INTEGER, OPTIONAL, INTENT(IN) :: n_SigFig
LOGICAL :: is_comparable
! Variables
INTEGER :: n
! Set up
is_comparable = .FALSE.
IF ( PRESENT(n_SigFig) ) THEN
n = ABS(n_SigFig)
ELSE
n = DEFAULT_N_SIGFIG
END IF
! Check the structure association status
IF ( CRTM_RTSolution_Associated(x) .NEQV. CRTM_RTSolution_Associated(y) ) RETURN
! Check the sensor information
IF ( (x%Sensor_ID /= y%Sensor_ID ) .OR. &
(x%WMO_Satellite_ID /= y%WMO_Satellite_ID) .OR. &
(x%WMO_Sensor_ID /= y%WMO_Sensor_ID ) .OR. &
(x%Sensor_Channel /= y%Sensor_Channel ) ) RETURN
! Check the RT algorithm name
IF ( x%RT_Algorithm_Name /= y%RT_Algorithm_Name ) RETURN
! Check the scalar components
IF ( .NOT. Compares_Within_Tolerance(x%SOD , y%SOD , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Surface_Emissivity , y%Surface_Emissivity , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Surface_Reflectivity , y%Surface_Reflectivity , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Up_Radiance , y%Up_Radiance , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Down_Radiance , y%Down_Radiance , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Down_Solar_Radiance , y%Down_Solar_Radiance , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Surface_Planck_Radiance, y%Surface_Planck_Radiance, n) .OR. &
.NOT. Compares_Within_Tolerance(x%Total_Cloud_Cover , y%Total_Cloud_Cover , n) .OR. &
.NOT. Compares_Within_Tolerance(x%R_clear , y%R_clear , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Tb_clear , y%Tb_clear , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Radiance , y%Radiance , n) .OR. &
.NOT. Compares_Within_Tolerance(x%Brightness_Temperature , y%Brightness_Temperature , n) ) RETURN
! Check the array components
IF ( CRTM_RTSolution_Associated(x) .AND. CRTM_RTSolution_Associated(y) ) THEN
IF ( (.NOT. ALL(Compares_Within_Tolerance(x%Upwelling_Overcast_Radiance, y%Upwelling_Overcast_Radiance, n))) .OR. &
(.NOT. ALL(Compares_Within_Tolerance(x%Upwelling_Radiance , y%Upwelling_Radiance , n))) .OR. &
(.NOT. ALL(Compares_Within_Tolerance(x%Layer_Optical_Depth , y%Layer_Optical_Depth , n))) ) RETURN
END IF
! If we get here, the structures are comparable
is_comparable = .TRUE.
END FUNCTION CRTM_RTSolution_Compare
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_Statistics
!
! PURPOSE:
! Function to compute the statistics of an array of CRTM RTSolution objects.
!
! CALLING SEQUENCE:
! Error_Status = CRTM_RTSolution_Statistics( rts, rts_stats )
!
! INPUTS:
! rts: RTSolution object array for which statistics are required.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Rank-2 (n_channels x n_profiles)
! ATTRIBUTES: INTENT(IN)
!
! OUTPUTS:
! rts_stats: Allocatable RTSolution object array containing the statistics
! for each channel.
! rts_stats(:,1) contains the profile average
! rts_stats(:,2) contains the profile standard deviation
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Rank-2 (n_channels x 2)
! ATTRIBUTES: INTENT(IN), ALLOCATABLE
!
! FUNCTION RESULT:
! Error_Status: The return value is an integer defining the error status.
! The error codes are defined in the Message_Handler module.
! If == SUCCESS, the file write was successful
! == FAILURE, an unrecoverable error occurred.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
!:sdoc-:
!--------------------------------------------------------------------------------
FUNCTION CRTM_RTSolution_Statistics(rts, rts_stats) RESULT( err_stat )
! Arguments
TYPE(CRTM_RTSolution_type), INTENT(IN) :: rts(:,:)
TYPE(CRTM_RTSolution_type), ALLOCATABLE, INTENT(OUT) :: rts_stats(:,:)
! Function result
INTEGER :: err_stat
! Function parameters
CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'CRTM_RTSolution_Statistics'
! Function variables
CHARACTER(ML) :: err_msg
CHARACTER(ML) :: alloc_msg
INTEGER :: alloc_stat
INTEGER :: n_channels, l
INTEGER :: n_profiles, m
REAL(fp) :: factor
! Setup
err_stat = SUCCESS
n_channels = SIZE(rts, DIM=1)
n_profiles = SIZE(rts, DIM=2)
factor = REAL(n_profiles,fp)
! Allocate the output stats object array
ALLOCATE( rts_stats(n_channels, 2), &
STAT = alloc_stat )
!STAT = alloc_stat, ERRMSG = alloc_msg )
IF ( alloc_stat /= 0 ) THEN
err_msg = 'Error allocating output RTSolution structure - '//TRIM(alloc_msg)
err_stat = FAILURE
CALL Display_Message( ROUTINE_NAME, err_msg, err_stat ); RETURN
END IF
rts_stats(:,1) = rts(:,1)
rts_stats(:,2) = rts(:,1)
CALL CRTM_RTSolution_Zero(rts_stats)
! Compute the average
DO m = 1, n_profiles
DO l = 1, n_channels
rts_stats(l,1) = rts_stats(l,1) + rts(l,m)
END DO
END DO
rts_stats(:,1) = rts_stats(:,1)/factor
! Compute the standard deviation
DO m = 1, n_profiles
DO l = 1, n_channels
rts_stats(l,2) = rts_stats(l,2) + (rts(l,m) - rts_stats(l,1))**2
END DO
END DO
rts_stats(:,2) = SQRT(rts_stats(:,2)/factor)
! Replace the algorithm identifier
rts_stats(:,1)%RT_Algorithm_Name = 'Average'
rts_stats(:,2)%RT_Algorithm_Name = 'Standard deviation'
END FUNCTION CRTM_RTSolution_Statistics
!------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_InquireFile
!
! PURPOSE:
! Function to inquire CRTM RTSolution object files.
!
! CALLING SEQUENCE:
! Error_Status = CRTM_RTSolution_InquireFile( Filename , &
! n_Channels = n_Channels, &
! n_Profiles = n_Profiles )
!
! INPUTS:
! Filename: Character string specifying the name of a
! CRTM RTSolution data file to read.
! UNITS: N/A
! TYPE: CHARACTER(*)
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN)
!
! OPTIONAL OUTPUTS:
! n_Channels: The number of spectral channels for which there is
! data in the file.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
! ATTRIBUTES: OPTIONAL, INTENT(OUT)
!
! n_Profiles: The number of profiles in the data file.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
! ATTRIBUTES: OPTIONAL, INTENT(OUT)
!
! FUNCTION RESULT:
! Error_Status: The return value is an integer defining the error status.
! The error codes are defined in the Message_Handler module.
! If == SUCCESS, the file inquire was successful
! == FAILURE, an unrecoverable error occurred.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
!
!:sdoc-:
!------------------------------------------------------------------------------
FUNCTION CRTM_RTSolution_InquireFile( &
Filename , & ! Input
n_Channels , & ! Optional output
n_Profiles ) & ! Optional output
RESULT( err_stat )
! Arguments
CHARACTER(*), INTENT(IN) :: Filename
INTEGER , OPTIONAL, INTENT(OUT) :: n_Channels
INTEGER , OPTIONAL, INTENT(OUT) :: n_Profiles
! Function result
INTEGER :: err_stat
! Function parameters
CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'CRTM_RTSolution_InquireFile'
! Function variables
CHARACTER(ML) :: msg
CHARACTER(ML) :: io_msg
INTEGER :: io_stat
INTEGER :: fid
INTEGER :: l, m
! Set up
err_stat = SUCCESS
! Check that the file exists
IF ( .NOT. File_Exists( TRIM(Filename) ) ) THEN
msg = 'File '//TRIM(Filename)//' not found.'
CALL Inquire_Cleanup(); RETURN
END IF
! Open the file
err_stat = Open_Binary_File( Filename, fid )
IF ( err_stat /= SUCCESS ) THEN
msg = 'Error opening '//TRIM(Filename)
CALL Inquire_Cleanup(); RETURN
END IF
! Read the number of channels,profiles
READ( fid,IOSTAT=io_stat,IOMSG=io_msg ) l, m
IF ( io_stat /= 0 ) THEN
msg = 'Error reading dimensions from '//TRIM(Filename)//' - '//TRIM(io_msg)
CALL Inquire_Cleanup(); RETURN
END IF
! Close the file
CLOSE( fid,IOSTAT=io_stat,IOMSG=io_msg )
IF ( io_stat /= 0 ) THEN
msg = 'Error closing '//TRIM(Filename)//' - '//TRIM(io_msg)
CALL Inquire_Cleanup(); RETURN
END IF
! Set the return arguments
IF ( PRESENT(n_Channels) ) n_Channels = l
IF ( PRESENT(n_Profiles) ) n_Profiles = m
CONTAINS
SUBROUTINE Inquire_CleanUp()
IF ( File_Open( Filename ) ) THEN
CLOSE( fid,IOSTAT=io_stat,IOMSG=io_msg )
IF ( io_stat /= SUCCESS ) &
msg = TRIM(msg)//'; Error closing input file during error cleanup - '//TRIM(io_msg)
END IF
err_stat = FAILURE
CALL Display_Message( ROUTINE_NAME, msg, err_stat )
END SUBROUTINE Inquire_CleanUp
END FUNCTION CRTM_RTSolution_InquireFile
!------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_RTSolution_ReadFile
!
! PURPOSE:
! Function to read CRTM RTSolution object files.
!
! CALLING SEQUENCE:
! Error_Status = CRTM_RTSolution_ReadFile( Filename , &
! RTSolution , &
! Quiet = Quiet , &
! n_Channels = n_Channels , &
! n_Profiles = n_Profiles , &
!
! INPUTS:
! Filename: Character string specifying the name of an
! RTSolution format data file to read.
! UNITS: N/A
! TYPE: CHARACTER(*)
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN)
!
! OUTPUTS:
! RTSolution: CRTM RTSolution object array containing the RTSolution
! data.
! UNITS: N/A
! TYPE: CRTM_RTSolution_type
! DIMENSION: Rank-2 (n_Channels x n_Profiles)
! ATTRIBUTES: INTENT(OUT), ALLOCATABLE
!
! OPTIONAL INPUTS:
! Quiet: Set this logical argument to suppress INFORMATION
! messages being printed to stdout
! If == .FALSE., INFORMATION messages are OUTPUT [DEFAULT].
! == .TRUE., INFORMATION messages are SUPPRESSED.
! If not specified, default is .FALSE.
! UNITS: N/A
! TYPE: LOGICAL
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN), OPTIONAL
!
! OPTIONAL OUTPUTS:
! n_Channels: The number of channels for which data was read.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
! ATTRIBUTES: OPTIONAL, INTENT(OUT)
!
! n_Profiles: The number of profiles for which data was read.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
! ATTRIBUTES: OPTIONAL, INTENT(OUT)
!
!
! FUNCTION RESULT:
! Error_Status: The return value is an integer defining the error status.
! The error codes are defined in the Message_Handler module.
! If == SUCCESS, the file read was successful
! == FAILURE, an unrecoverable error occurred.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Scalar
!
!:sdoc-:
!------------------------------------------------------------------------------
FUNCTION CRTM_RTSolution_ReadFile( &
Filename , & ! Input
RTSolution , & ! Output
Quiet , & ! Optional input
n_Channels , & ! Optional output
n_Profiles , & ! Optional output
Debug ) & ! Optional input (Debug output control)
RESULT( err_stat )
! Arguments
CHARACTER(*), INTENT(IN) :: Filename
TYPE(CRTM_RTSolution_type), ALLOCATABLE, INTENT(OUT) :: RTSolution(:,:) ! L x M
LOGICAL, OPTIONAL, INTENT(IN) :: Quiet
INTEGER, OPTIONAL, INTENT(OUT) :: n_Channels
INTEGER, OPTIONAL, INTENT(OUT) :: n_Profiles
LOGICAL, OPTIONAL, INTENT(IN) :: Debug
! Function result
INTEGER :: err_stat
! Function parameters
CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'CRTM_RTSolution_ReadFile'
! Function variables
CHARACTER(ML) :: msg
CHARACTER(ML) :: io_msg
CHARACTER(ML) :: alloc_msg
INTEGER :: io_stat
INTEGER :: alloc_stat
LOGICAL :: noisy
INTEGER :: fid
INTEGER :: l, n_input_channels
INTEGER :: m, n_input_profiles
! Set up
err_stat = SUCCESS
! ...Check Quiet argument
noisy = .TRUE.
IF ( PRESENT(Quiet) ) noisy = .NOT. Quiet
! ...Override Quiet settings if debug set.
IF ( PRESENT(Debug) ) noisy = Debug
! Open the file
err_stat = Open_Binary_File( Filename, fid )
IF ( err_stat /= SUCCESS ) THEN
msg = 'Error opening '//TRIM(Filename)
CALL Read_Cleanup(); RETURN
END IF
! Read the dimensions
READ( fid,IOSTAT=io_stat,IOMSG=io_msg ) n_input_channels, n_input_profiles
IF ( io_stat /= 0 ) THEN