-
Notifications
You must be signed in to change notification settings - Fork 1
/
CRTM_Surface_Define.f90
2505 lines (2187 loc) · 87.8 KB
/
CRTM_Surface_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_Surface_Define
!
! Module defining the CRTM Surface structure and containing routines
! to manipulate it.
!
!
! CREATION HISTORY:
! Written by: Yong Han, [email protected]
! Quanhua Liu, [email protected]
! Paul van Delst, [email protected]
! 07-May-2004
!
MODULE CRTM_Surface_Define
! -----------------
! Environment setup
! -----------------
! Intrinsic modules
USE ISO_Fortran_Env , ONLY: OUTPUT_UNIT
! Module use
USE Type_Kinds , ONLY: 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 CRTM_SensorData_Define, ONLY: CRTM_SensorData_type, &
OPERATOR(==), &
OPERATOR(+), &
OPERATOR(-), &
CRTM_SensorData_Associated, &
CRTM_SensorData_Destroy, &
CRTM_SensorData_Create, &
CRTM_SensorData_Zero, &
CRTM_SensorData_IsValid, &
CRTM_SensorData_Inspect, &
CRTM_SensorData_DefineVersion, &
CRTM_SensorData_Compare, &
CRTM_SensorData_ReadFile, &
CRTM_SensorData_WriteFile
! Disable implicit typing
IMPLICIT NONE
! ------------
! Visibilities
! ------------
! Everything private by default
PRIVATE
! Operators
PUBLIC :: OPERATOR(==)
PUBLIC :: OPERATOR(+)
PUBLIC :: OPERATOR(-)
! SensorData enitities
! ...Structures
PUBLIC :: CRTM_SensorData_type
! ...Procedures
PUBLIC :: CRTM_SensorData_Associated
PUBLIC :: CRTM_SensorData_Destroy
PUBLIC :: CRTM_SensorData_Create
PUBLIC :: CRTM_SensorData_Zero
PUBLIC :: CRTM_SensorData_IsValid
PUBLIC :: CRTM_SensorData_Inspect
PUBLIC :: CRTM_SensorData_DefineVersion
PUBLIC :: CRTM_SensorData_Compare
! Surface entities
! ...Gross surface parameters
PUBLIC :: INVALID_SURFACE
PUBLIC :: LAND_SURFACE
PUBLIC :: WATER_SURFACE
PUBLIC :: SNOW_SURFACE
PUBLIC :: ICE_SURFACE
PUBLIC :: N_VALID_SURFACE_TYPES
PUBLIC :: SURFACE_TYPE_NAME
! ...Structures
PUBLIC :: CRTM_Surface_type
! ...Procedures
PUBLIC :: CRTM_Surface_Associated
PUBLIC :: CRTM_Surface_Destroy
PUBLIC :: CRTM_Surface_Create
PUBLIC :: CRTM_Surface_NonVariableCopy
PUBLIC :: CRTM_Surface_Zero
PUBLIC :: CRTM_Surface_IsValid
PUBLIC :: CRTM_Surface_Inspect
PUBLIC :: CRTM_Surface_IsCoverageValid
PUBLIC :: CRTM_Surface_CoverageType
PUBLIC :: CRTM_Surface_DefineVersion
PUBLIC :: CRTM_Surface_Compare
PUBLIC :: CRTM_Surface_InquireFile
PUBLIC :: CRTM_Surface_ReadFile
PUBLIC :: CRTM_Surface_WriteFile
! ---------------------
! Procedure overloading
! ---------------------
INTERFACE OPERATOR(==)
MODULE PROCEDURE CRTM_Surface_Equal
END INTERFACE OPERATOR(==)
INTERFACE OPERATOR(+)
MODULE PROCEDURE CRTM_Surface_Add
END INTERFACE OPERATOR(+)
INTERFACE OPERATOR(-)
MODULE PROCEDURE CRTM_Surface_Subtract
END INTERFACE OPERATOR(-)
INTERFACE CRTM_Surface_ReadFile
MODULE PROCEDURE Read_Surface_Rank1
MODULE PROCEDURE Read_Surface_Rank2
END INTERFACE CRTM_Surface_ReadFile
INTERFACE CRTM_Surface_WriteFile
MODULE PROCEDURE Write_Surface_Rank1
MODULE PROCEDURE Write_Surface_Rank2
END INTERFACE CRTM_Surface_WriteFile
! -----------------
! Module parameters
! -----------------
CHARACTER(*), PARAMETER :: MODULE_VERSION_ID = &
'$Id: CRTM_Surface_Define.f90 99117 2017-11-27 18:37:14Z [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'
! The gross surface types. These are used for
! cross-checking with the coverage fractions
! of each gross surface types.
INTEGER, PARAMETER :: INVALID_SURFACE = 0
INTEGER, PARAMETER :: LAND_SURFACE = 1
INTEGER, PARAMETER :: WATER_SURFACE = 2
INTEGER, PARAMETER :: SNOW_SURFACE = 4
INTEGER, PARAMETER :: ICE_SURFACE = 8
INTEGER, PARAMETER :: N_VALID_SURFACE_TYPES = LAND_SURFACE + &
WATER_SURFACE + &
SNOW_SURFACE + &
ICE_SURFACE
CHARACTER(*), PARAMETER, DIMENSION( 0:N_VALID_SURFACE_TYPES ) :: &
SURFACE_TYPE_NAME = (/ 'Invalid surface type ', &
'Land ', &
'Water ', &
'Land + water ', &
'Snow ', &
'Land + snow ', &
'Water + snow ', &
'Land + water + snow ', &
'Ice ', &
'Land + ice ', &
'Water + ice ', &
'Land + water + ice ', &
'Snow + ice ', &
'Land + snow + ice ', &
'Water + snow + ice ', &
'Land + water + snow + ice' /)
! Default value parameters
! ...Land surface type data
INTEGER, PARAMETER :: DEFAULT_LAND_TYPE = 1 ! First item in list
REAL(fp), PARAMETER :: DEFAULT_LAND_TEMPERATURE = 283.0_fp ! K
REAL(fp), PARAMETER :: DEFAULT_SOIL_MOISTURE_CONTENT = 0.05_fp ! g/cm^3
REAL(fp), PARAMETER :: DEFAULT_CANOPY_WATER_CONTENT = 0.05_fp ! g/cm^3
REAL(fp), PARAMETER :: DEFAULT_VEGETATION_FRACTION = 0.3_fp ! 30%
REAL(fp), PARAMETER :: DEFAULT_SOIL_TEMPERATURE = 283.0_fp ! K
REAL(fp), PARAMETER :: DEFAULT_LAI = 3.5
INTEGER, PARAMETER :: DEFAULT_SOIL_TYPE = 1 ! First item in list
INTEGER, PARAMETER :: DEFAULT_VEGETATION_TYPE = 1 ! First item in list
! ...Water type data
INTEGER, PARAMETER :: DEFAULT_WATER_TYPE = 1 ! First item in list
REAL(fp), PARAMETER :: DEFAULT_WATER_TEMPERATURE = 283.0_fp ! K
REAL(fp), PARAMETER :: DEFAULT_WIND_SPEED = 5.0_fp ! m/s
REAL(fp), PARAMETER :: DEFAULT_WIND_DIRECTION = 0.0_fp ! Southerly wind, i.e. FROM the south. Opposite from met. defn.
REAL(fp), PARAMETER :: DEFAULT_SALINITY = 33.0_fp ! ppmv
! ...Snow surface type data
INTEGER, PARAMETER :: DEFAULT_SNOW_TYPE = 1 ! First item in list
REAL(fp), PARAMETER :: DEFAULT_SNOW_TEMPERATURE = 263.0_fp ! K
REAL(fp), PARAMETER :: DEFAULT_SNOW_DEPTH = 50.0_fp ! mm
REAL(fp), PARAMETER :: DEFAULT_SNOW_DENSITY = 0.2_fp ! g/cm^3
REAL(fp), PARAMETER :: DEFAULT_SNOW_GRAIN_SIZE = 2.0_fp ! mm
! ...Ice surface type data
INTEGER, PARAMETER :: DEFAULT_ICE_TYPE = 1 ! First item in list
REAL(fp), PARAMETER :: DEFAULT_ICE_TEMPERATURE = 263.0_fp ! K
REAL(fp), PARAMETER :: DEFAULT_ICE_THICKNESS = 10.0_fp ! mm
REAL(fp), PARAMETER :: DEFAULT_ICE_DENSITY = 0.9_fp ! g/cm^3
REAL(fp), PARAMETER :: DEFAULT_ICE_ROUGHNESS = ZERO
! ----------------------------
! Surface structure definition
! ----------------------------
!:tdoc+:
TYPE :: CRTM_Surface_type
! Allocation indicator
LOGICAL :: Is_Allocated = .TRUE. ! Placeholder for future expansion
! Dimension values
! ...None yet
! Gross type of surface determined by coverage
REAL(fp) :: Land_Coverage = ZERO
REAL(fp) :: Water_Coverage = ZERO
REAL(fp) :: Snow_Coverage = ZERO
REAL(fp) :: Ice_Coverage = ZERO
! Land surface type data
INTEGER :: Land_Type = DEFAULT_LAND_TYPE
REAL(fp) :: Land_Temperature = DEFAULT_LAND_TEMPERATURE
REAL(fp) :: Soil_Moisture_Content = DEFAULT_SOIL_MOISTURE_CONTENT
REAL(fp) :: Canopy_Water_Content = DEFAULT_CANOPY_WATER_CONTENT
REAL(fp) :: Vegetation_Fraction = DEFAULT_VEGETATION_FRACTION
REAL(fp) :: Soil_Temperature = DEFAULT_SOIL_TEMPERATURE
REAL(fp) :: LAI = DEFAULT_LAI
INTEGER :: Soil_Type = DEFAULT_SOIL_TYPE
INTEGER :: Vegetation_Type = DEFAULT_VEGETATION_TYPE
! Water type data
INTEGER :: Water_Type = DEFAULT_WATER_TYPE
REAL(fp) :: Water_Temperature = DEFAULT_WATER_TEMPERATURE
REAL(fp) :: Wind_Speed = DEFAULT_WIND_SPEED
REAL(fp) :: Wind_Direction = DEFAULT_WIND_DIRECTION
REAL(fp) :: Salinity = DEFAULT_SALINITY
! Snow surface type data
INTEGER :: Snow_Type = DEFAULT_SNOW_TYPE
REAL(fp) :: Snow_Temperature = DEFAULT_SNOW_TEMPERATURE
REAL(fp) :: Snow_Depth = DEFAULT_SNOW_DEPTH
REAL(fp) :: Snow_Density = DEFAULT_SNOW_DENSITY
REAL(fp) :: Snow_Grain_Size = DEFAULT_SNOW_GRAIN_SIZE
! Ice surface type data
INTEGER :: Ice_Type = DEFAULT_ICE_TYPE
REAL(fp) :: Ice_Temperature = DEFAULT_ICE_TEMPERATURE
REAL(fp) :: Ice_Thickness = DEFAULT_ICE_THICKNESS
REAL(fp) :: Ice_Density = DEFAULT_ICE_DENSITY
REAL(fp) :: Ice_Roughness = DEFAULT_ICE_ROUGHNESS
! SensorData containing channel brightness temperatures
TYPE(CRTM_SensorData_type) :: SensorData
END TYPE CRTM_Surface_type
!:tdoc-:
CONTAINS
!################################################################################
!################################################################################
!## ##
!## ## PUBLIC MODULE ROUTINES ## ##
!## ##
!################################################################################
!################################################################################
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_Associated
!
! PURPOSE:
! Elemental function to test the status of the allocatable components
! of a CRTM Surface object.
!
! CALLING SEQUENCE:
! Status = CRTM_Surface_Associated( Sfc )
!
! OBJECTS:
! Sfc: Surface structure which is to have its member's
! status tested.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN)
!
! FUNCTION RESULT:
! Status: The return value is a logical value indicating the
! status of the Surface 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
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL FUNCTION CRTM_Surface_Associated( Sfc ) RESULT( Status )
TYPE(CRTM_Surface_type), INTENT(IN) :: Sfc
LOGICAL :: Status
Status = Sfc%Is_Allocated
! ...SensorData
Status = Status .AND. CRTM_SensorData_Associated(Sfc%SensorData)
END FUNCTION CRTM_Surface_Associated
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_Destroy
!
! PURPOSE:
! Elemental subroutine to re-initialize CRTM Surface objects.
!
! CALLING SEQUENCE:
! CALL CRTM_Surface_Destroy( Sfc )
!
! OBJECTS:
! Sfc: Re-initialized Surface structure.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(OUT)
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_Surface_Destroy( Sfc )
TYPE(CRTM_Surface_type), INTENT(OUT) :: Sfc
Sfc%Is_Allocated = .TRUE. ! Placeholder for future expansion
END SUBROUTINE CRTM_Surface_Destroy
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_Create
!
! PURPOSE:
! Elemental subroutine to create an instance of the CRTM Surface object.
!
! CALLING SEQUENCE:
! CALL CRTM_Surface_Create( Sfc , &
! n_Channels )
!
! OBJECTS:
! Sfc: Surface structure.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(OUT)
!
! INPUT ARGUMENTS:
! n_Channels: Number of channels dimension of SensorData
! substructure
! ** Note: Can be = 0 (i.e. no sensor data). **
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Same as Surface object
! ATTRIBUTES: INTENT(IN)
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_Surface_Create( &
Sfc , & ! Output
n_Channels ) ! Input
! Arguments
TYPE(CRTM_Surface_type), INTENT(OUT) :: Sfc
INTEGER , INTENT(IN) :: n_Channels
! Check input
IF ( n_Channels < 0 ) RETURN
! Perform the substructure allocation
! ...SensorData
IF ( n_Channels > 0 ) CALL CRTM_SensorData_Create( Sfc%SensorData, n_Channels )
! Set allocation indicator
Sfc%Is_Allocated = .TRUE.
END SUBROUTINE CRTM_Surface_Create
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_NonVariableCopy
!
! PURPOSE:
! Elemental utility subroutine to copy the "non-variable" data (coverages
! and surface types) from one instance of a CRTM Surface object to another
! (usually a TL or AD one).
!
! NOTE: No error checking is performed in this procedure.
!
! CALLING SEQUENCE:
! CALL CRTM_Surface_NonVariableCopy( sfc, modified_sfc )
!
! OBJECTS:
! sfc: Surface object from which to copy.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN)
!
! IN/OUTPUTS:
! modified_sfc: Existing Surface object to be modified.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Conformable with sfc input
! ATTRIBUTES: INTENT(IN OUT)
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_Surface_NonVariableCopy( sfc, modified_sfc )
TYPE(CRTM_Surface_type), INTENT(IN) :: sfc
TYPE(CRTM_Surface_type), INTENT(IN OUT) :: modified_sfc
modified_sfc%Land_Coverage = sfc%Land_Coverage
modified_sfc%Water_Coverage = sfc%Water_Coverage
modified_sfc%Snow_Coverage = sfc%Snow_Coverage
modified_sfc%Ice_Coverage = sfc%Ice_Coverage
modified_sfc%Land_Type = sfc%Land_Type
modified_sfc%Water_Type = sfc%Water_Type
modified_sfc%Snow_Type = sfc%Snow_Type
modified_sfc%Ice_Type = sfc%Ice_Type
END SUBROUTINE CRTM_Surface_NonVariableCopy
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_Zero
!
! PURPOSE:
! Elemental subroutine to zero out the data arrays
! in a CRTM Surface object.
!
! CALLING SEQUENCE:
! CALL CRTM_Surface_Zero( Sfc )
!
! OUTPUT ARGUMENTS:
! Sfc: CRTM Surface structure in which the data arrays
! are to be zeroed out.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN OUT)
!
! COMMENTS:
! - The various surface type indicator flags are
! *NOT* reset in this routine.
!
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL SUBROUTINE CRTM_Surface_Zero( Sfc )
TYPE(CRTM_Surface_type), INTENT(IN OUT) :: Sfc
! Zero the components
! ...Coverage fractions
Sfc%Land_Coverage = ZERO
Sfc%Water_Coverage = ZERO
Sfc%Snow_Coverage = ZERO
Sfc%Ice_Coverage = ZERO
! ...The various surface types
CALL CRTM_LandSurface_Zero(sfc)
CALL CRTM_WaterSurface_Zero(sfc)
CALL CRTM_SnowSurface_Zero(sfc)
CALL CRTM_IceSurface_Zero(sfc)
! Reset the structure components
IF ( CRTM_SensorData_Associated(Sfc%SensorData) ) CALL CRTM_SensorData_Zero(Sfc%SensorData)
END SUBROUTINE CRTM_Surface_Zero
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_IsValid
!
! PURPOSE:
! Non-pure function to perform some simple validity checks on a
! CRTM Surface object.
!
! If invalid data is found, a message is printed to stdout.
!
! CALLING SEQUENCE:
! result = CRTM_Surface_IsValid( Sfc )
!
! or
!
! IF ( CRTM_Surface_IsValid( Sfc ) ) THEN....
!
! OBJECTS:
! Sfc: CRTM Surface object which is to have its
! contents checked.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN)
!
! FUNCTION RESULT:
! result: Logical variable indicating whether or not the input
! passed the check.
! If == .FALSE., Surface object is unused or contains
! invalid data.
! == .TRUE., Surface object can be used in CRTM.
! UNITS: N/A
! TYPE: LOGICAL
! DIMENSION: Scalar
!
!:sdoc-:
!--------------------------------------------------------------------------------
FUNCTION CRTM_Surface_IsValid( Sfc ) RESULT( IsValid )
TYPE(CRTM_Surface_type), INTENT(IN) :: Sfc
LOGICAL :: IsValid
CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'CRTM_Surface_IsValid'
CHARACTER(ML) :: msg
! Check the gross surface type indicators
IsValid = CRTM_Surface_IsCoverageValid(sfc)
IF ( .NOT. IsValid ) THEN
msg = 'Invalid surface coverage fraction(s) found'
CALL Display_Message( ROUTINE_NAME, TRIM(msg), INFORMATION )
ENDIF
! Check the various surface types
IF ( Sfc%Land_Coverage > ZERO ) IsValid = CRTM_LandSurface_IsValid(sfc) .AND. IsValid
IF ( Sfc%Water_Coverage > ZERO ) IsValid = CRTM_WaterSurface_IsValid(sfc) .AND. IsValid
IF ( Sfc%Snow_Coverage > ZERO ) IsValid = CRTM_SnowSurface_IsValid(sfc) .AND. IsValid
IF ( Sfc%Ice_Coverage > ZERO ) IsValid = CRTM_IceSurface_IsValid(sfc) .AND. IsValid
! Structure components
IF ( CRTM_SensorData_Associated(Sfc%SensorData) ) &
IsValid = CRTM_SensorData_IsValid( Sfc%SensorData ) .AND. IsValid
END FUNCTION CRTM_Surface_IsValid
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_Inspect
!
! PURPOSE:
! Subroutine to print the contents of a CRTM Surface object to stdout.
!
! CALLING SEQUENCE:
! CALL CRTM_Surface_Inspect( Sfc, Unit=unit )
!
! INPUTS:
! Sfc: CRTM Surface object to display.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar
! 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 CRTM_Surface_Inspect( Sfc, Unit )
! Arguments
TYPE(CRTM_Surface_type), INTENT(IN) :: Sfc
INTEGER, OPTIONAL, INTENT(IN) :: Unit
! Local variables
INTEGER :: fid
! Setup
fid = OUTPUT_UNIT
IF ( PRESENT(Unit) ) THEN
IF ( File_Open(Unit) ) fid = Unit
END IF
WRITE(fid,'(1x,"Surface OBJECT")')
! Surface coverage
WRITE(fid,'(3x,"Land Coverage :",1x,f6.3)') Sfc%Land_Coverage
WRITE(fid,'(3x,"Water Coverage:",1x,f6.3)') Sfc%Water_Coverage
WRITE(fid,'(3x,"Snow Coverage :",1x,f6.3)') Sfc%Snow_Coverage
WRITE(fid,'(3x,"Ice Coverage :",1x,f6.3)') Sfc%Ice_Coverage
! The various surface types
IF ( sfc%Land_Coverage > ZERO ) CALL CRTM_LandSurface_Inspect(sfc, Unit=Unit)
IF ( sfc%Water_Coverage > ZERO ) CALL CRTM_WaterSurface_Inspect(sfc, Unit=Unit)
IF ( sfc%Snow_Coverage > ZERO ) CALL CRTM_SnowSurface_Inspect(sfc, Unit=Unit)
IF ( sfc%Ice_Coverage > ZERO ) CALL CRTM_IceSurface_Inspect(sfc, Unit=Unit)
! SensorData information
IF ( CRTM_SensorData_Associated(Sfc%SensorData) ) &
CALL CRTM_SensorData_Inspect(Sfc%SensorData, Unit=Unit)
END SUBROUTINE CRTM_Surface_Inspect
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_IsCoverageValid
!
! PURPOSE:
! Function to determine if the coverage fractions are valid
! for a CRTM Surface object.
!
! CALLING SEQUENCE:
! result = CRTM_Surface_IsCoverageValid( Sfc )
!
! OBJECTS:
! Sfc: CRTM Surface object which is to have its
! coverage fractions checked.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN)
!
! FUNCTION RESULT:
! result: Logical variable indicating whether or not the input
! passed the check.
! If == .FALSE., Surface object coverage fractions are invalid.
! == .TRUE., Surface object coverage fractions are valid.
! UNITS: N/A
! TYPE: LOGICAL
! DIMENSION: Scalar
!
!:sdoc-:
!--------------------------------------------------------------------------------
FUNCTION CRTM_Surface_IsCoverageValid( Sfc ) RESULT( IsValid )
TYPE(CRTM_Surface_type), INTENT(IN) :: Sfc
LOGICAL :: IsValid
CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'CRTM_Surface_IsCoverageValid'
REAL(fp) , PARAMETER :: TOLERANCE = 1.0e-10_fp
CHARACTER(ML) :: msg
REAL(fp) :: Total_Coverage
! Compute the total coverage
Total_Coverage = Sfc%Land_Coverage + Sfc%Water_Coverage + &
Sfc%Snow_Coverage + Sfc%Ice_Coverage
! Check coverage fractions for < 0 and > 1
IsValid = IsCoverageValid(Sfc%Land_Coverage, 'Land')
IsValid = IsValid .AND. IsCoverageValid(Sfc%Water_Coverage, 'Water')
IsValid = IsValid .AND. IsCoverageValid(Sfc%Snow_Coverage, 'Snow')
IsValid = IsValid .AND. IsCoverageValid(Sfc%Ice_Coverage, 'Ice')
! Check total coverage sums to 1
IF ( ABS(Total_Coverage-ONE) > TOLERANCE ) THEN
WRITE( msg,'("Total coverage fraction does not sum to 1 +/- ",es13.6)' ) TOLERANCE
CALL Display_Message( ROUTINE_NAME,msg,INFORMATION )
IsValid = .FALSE.
END IF
CONTAINS
FUNCTION IsCoverageValid( Coverage, Name ) RESULT( IsValid )
REAL(fp) , INTENT(IN) :: Coverage
CHARACTER(*), INTENT(IN) :: Name
LOGICAL :: IsValid
IsValid = .TRUE.
! Check for coverage < -TOLERANCE
IF ( Coverage < -TOLERANCE ) THEN
WRITE( msg,'(a," coverage fraction is < ",es13.6)' ) TRIM(Name), -TOLERANCE
CALL Display_Message( ROUTINE_NAME,msg,INFORMATION )
IsValid = .FALSE.
END IF
! Check for coverage > 1+TOLERANCE
IF ( Coverage > ONE+TOLERANCE ) THEN
WRITE( msg,'(a," coverage fraction is > 1 +",es13.6)' ) TRIM(Name), TOLERANCE
CALL Display_Message( ROUTINE_NAME,msg,INFORMATION )
IsValid = .FALSE.
END IF
END FUNCTION IsCoverageValid
END FUNCTION CRTM_Surface_IsCoverageValid
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_CoverageType
!
! PURPOSE:
! Elemental function to return the gross surface type based on coverage.
!
! CALLING SEQUENCE:
! type = CRTM_Surface_CoverageType( sfc )
!
! INPUTS:
! Sfc: CRTM Surface object for which the gross surface type is required.
! UNITS: N/A
! TYPE: CRTM_Surface_type
! DIMENSION: Scalar or any rank
! ATTRIBUTES: INTENT(IN)
!
! FUNCTION:
! type: Surface type indicator for the passed CRTM Surface object.
! UNITS: N/A
! TYPE: INTEGER
! DIMENSION: Same as input
!
! COMMENTS:
! For a scalar Surface object, this function result can be used to
! determine what gross surface types are included by using it to
! index the SURFACE_TYPE_NAME parameter arrays, e.g.
!
! WRITE(*,*) SURFACE_TYPE_NAME(CRTM_Surface_CoverageType(sfc))
!:sdoc-:
!--------------------------------------------------------------------------------
ELEMENTAL FUNCTION CRTM_Surface_CoverageType( sfc ) RESULT( Coverage_Type )
TYPE(CRTM_Surface_type), INTENT(IN) :: sfc
INTEGER :: Coverage_Type
Coverage_Type = 0
IF ( sfc%Land_Coverage > ZERO ) Coverage_Type = LAND_SURFACE
IF ( sfc%Water_Coverage > ZERO ) Coverage_Type = Coverage_Type + WATER_SURFACE
IF ( sfc%Snow_Coverage > ZERO ) Coverage_Type = Coverage_Type + SNOW_SURFACE
IF ( sfc%Ice_Coverage > ZERO ) Coverage_Type = Coverage_Type + ICE_SURFACE
END FUNCTION CRTM_Surface_CoverageType
!--------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_DefineVersion
!
! PURPOSE:
! Subroutine to return the module version information.
!
! CALLING SEQUENCE:
! CALL CRTM_Surface_DefineVersion( Id )
!
! OUTPUT ARGUMENTS:
! Id: Character string containing the version Id information
! for the module.
! UNITS: N/A
! TYPE: CHARACTER(*)
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(OUT)
!
!:sdoc-:
!--------------------------------------------------------------------------------
SUBROUTINE CRTM_Surface_DefineVersion( Id )
CHARACTER(*), INTENT(OUT) :: Id
Id = MODULE_VERSION_ID
END SUBROUTINE CRTM_Surface_DefineVersion
!------------------------------------------------------------------------------
!:sdoc+:
! NAME:
! CRTM_Surface_Compare
!
! PURPOSE:
! Elemental function to compare two CRTM_Surface objects to within
! a user specified number of significant figures.
!
! CALLING SEQUENCE:
! is_comparable = CRTM_Surface_Compare( x, y, n_SigFig=n_SigFig )
!
! OBJECTS:
! x, y: Two CRTM Surface objects to be compared.
! UNITS: N/A
! TYPE: CRTM_Surface_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: Scalar or same as input
! ATTRIBUTES: INTENT(IN), OPTIONAL
!
! FUNCTION RESULT:
! is_equal: Logical value indicating whether the inputs are equal.
! UNITS: N/A
! TYPE: LOGICAL
! DIMENSION: Same as inputs.
!:sdoc-:
!------------------------------------------------------------------------------
ELEMENTAL FUNCTION CRTM_Surface_Compare( &
x, &
y, &
n_SigFig ) &
RESULT( is_comparable )
TYPE(CRTM_Surface_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
! Compare gross surface type coverage
IF ( (.NOT. Compares_Within_Tolerance(x%Land_Coverage ,y%Land_Coverage ,n)) .OR. &
(.NOT. Compares_Within_Tolerance(x%Water_Coverage,y%Water_Coverage,n)) .OR. &
(.NOT. Compares_Within_Tolerance(x%Snow_Coverage ,y%Snow_Coverage ,n)) .OR. &
(.NOT. Compares_Within_Tolerance(x%Ice_Coverage ,y%Ice_Coverage ,n)) ) RETURN
! Compare the land surface type data
IF ( .NOT. CRTM_LandSurface_Compare(x,y,n_SigFig=n) ) RETURN
! Compare the water surface type data
IF ( .NOT. CRTM_WaterSurface_Compare(x,y,n_SigFig=n) ) RETURN
! Compare the snow surface type data
IF ( .NOT. CRTM_SnowSurface_Compare(x,y,n_SigFig=n) ) RETURN
! Compare the ice surface type data
IF ( .NOT. CRTM_IceSurface_Compare(x,y,n_SigFig=n) ) RETURN
! Check the SensorData
IF ( CRTM_SensorData_Associated(x%SensorData) .AND. &
CRTM_SensorData_Associated(y%SensorData) ) THEN
IF ( .NOT. CRTM_SensorData_Compare(x%SensorData,y%SensorData,n_SigFig=n) ) RETURN
END IF
! If we get here, the structures are comparable
is_comparable = .TRUE.
END FUNCTION CRTM_Surface_Compare
!------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_InquireFile
!
! PURPOSE:
! Function to inquire CRTM Surface object files.
!
! CALLING SEQUENCE:
! Error_Status = CRTM_Surface_InquireFile( Filename , &
! n_Channels = n_Channels, &
! n_Profiles = n_Profiles )
!
! INPUTS:
! Filename: Character string specifying the name of a
! CRTM Surface 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. Note that this value will always
! be 0 for a profile-only dataset-- it only has meaning
! for K-matrix data.
! 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_Surface_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_Surface_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(fid) ) 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_Surface_InquireFile
!------------------------------------------------------------------------------
!:sdoc+:
!
! NAME:
! CRTM_Surface_ReadFile
!
! PURPOSE:
! Function to read CRTM Surface object files.
!
! CALLING SEQUENCE:
! Error_Status = CRTM_Surface_ReadFile( Filename , &
! Surface , &
! Quiet = Quiet , &
! n_Channels = n_Channels, &
! n_Profiles = n_Profiles )
!
! INPUTS:
! Filename: Character string specifying the name of an
! Surface format data file to read.
! UNITS: N/A
! TYPE: CHARACTER(*)
! DIMENSION: Scalar
! ATTRIBUTES: INTENT(IN)
!
! OUTPUTS:
! Surface: CRTM Surface object array containing the Surface