19 USE iso_fortran_env ,
ONLY: output_unit
24 OPERATOR(.equalto.), &
48 PUBLIC ::
OPERATOR(==)
68 INTERFACE OPERATOR(==)
70 END INTERFACE OPERATOR(==)
74 END INTERFACE OPERATOR(+)
78 END INTERFACE OPERATOR(-)
85 '$Id: CRTM_SensorData_Define.f90 60152 2015-08-13 19:19:13Z paul.vandelst@noaa.gov $' 87 REAL(fp),
PARAMETER ::
zero = 0.0_fp
88 REAL(fp),
PARAMETER ::
one = 1.0_fp
90 INTEGER,
PARAMETER ::
ml = 256
101 LOGICAL :: is_allocated = .false.
103 INTEGER :: n_channels = 0
105 CHARACTER(STRLEN) :: sensor_id =
' ' 109 INTEGER ,
ALLOCATABLE :: sensor_channel(:)
110 REAL(fp),
ALLOCATABLE :: tb(:)
162 status = sensordata%Is_Allocated
190 sensordata%Is_Allocated = .false.
227 INTEGER,
INTENT(IN) :: n_channels
229 INTEGER :: alloc_stat
232 IF ( n_channels < 1 )
RETURN 235 ALLOCATE( sensordata%Sensor_Channel( n_channels ), &
236 sensordata%Tb( n_channels ), &
238 IF ( alloc_stat /= 0 )
RETURN 242 sensordata%n_Channels = n_channels
244 sensordata%Sensor_Channel = 0
248 sensordata%Is_Allocated = .true.
333 CHARACTER(*),
PARAMETER :: routine_name =
'CRTM_SensorData_IsValid' 340 msg =
'SensorData structure not allocated' 344 IF ( sensordata%n_channels < 1 )
THEN 345 msg =
'SensorData structure dimension invalid' 354 IF ( len_trim(sensordata%Sensor_Id) == 0 )
THEN 355 msg =
'Invalid Sensor Id found' 360 msg =
'Invalid WMO Satellite Id found. Continuing...' 364 msg =
'Invalid WMO Sensor Id Continuing...' 368 IF ( any(sensordata%Sensor_Channel < 1) )
THEN 369 msg =
'Invalid Sensor Channel found' 374 IF ( all(sensordata%Tb <
zero ) )
THEN 375 msg =
'All input SensorData brightness temperatures are negative' 418 INTEGER,
OPTIONAL,
INTENT(IN) :: unit
424 IF (
PRESENT(unit) )
THEN 429 WRITE(fid,
'(1x,"SENSORDATA OBJECT")')
431 WRITE(fid,
'(3x,"n_Channels:",1x,i0)') sensordata%n_Channels
433 WRITE(fid,
'(3x,"Sensor Id :",1x,a)') sensordata%Sensor_Id
434 WRITE(fid,
'(3x,"WMO Satellite Id:",1x,i0)') sensordata%WMO_Satellite_Id
435 WRITE(fid,
'(3x,"WMO Sensor Id :",1x,i0)') sensordata%WMO_Sensor_Id
438 WRITE(fid,
'(3x,"Sensor channels:")')
439 WRITE(fid,
'(10(1x,i5))') sensordata%Sensor_Channel
440 WRITE(fid,
'(3x,"Brightness temperatures:")')
441 WRITE(fid,
'(10(1x,es13.6))') sensordata%Tb
469 CHARACTER(*),
INTENT(OUT) :: id
513 result( is_comparable )
515 INTEGER,
OPTIONAL,
INTENT(IN) :: n_sigfig
516 LOGICAL :: is_comparable
521 is_comparable = .false.
522 IF (
PRESENT(n_sigfig) )
THEN 533 IF ( (x%n_Channels /= y%n_Channels ) .OR. &
534 (x%Sensor_Id /= y%Sensor_Id ) .OR. &
535 (x%WMO_Satellite_ID /= y%WMO_Satellite_ID) .OR. &
536 (x%WMO_Sensor_ID /= y%WMO_Sensor_ID ) )
RETURN 540 IF ( any(x%Sensor_Channel(1:l) /= y%Sensor_Channel(1:l)) .OR. &
544 is_comparable = .true.
594 CHARACTER(*),
INTENT(IN) :: filename
595 INTEGER,
OPTIONAL,
INTENT(OUT) :: n_datasets
599 CHARACTER(*),
PARAMETER :: routine_name =
'CRTM_SensorData_InquireFile' 610 msg =
'File '//trim(filename)//
' not found.' 616 IF ( err_stat /=
success )
THEN 617 msg =
'Error opening '//trim(filename)
622 READ( fid,iostat=io_stat ) n
623 IF ( io_stat /= 0 )
THEN 624 WRITE( msg,
'("Error reading dataset dimensions from ",a,". IOSTAT = ",i0)' ) &
625 trim(filename), io_stat
630 CLOSE( fid, iostat=io_stat )
631 IF ( io_stat /= 0 )
THEN 632 WRITE( msg,
'("Error closing ",a,". IOSTAT = ",i0)' ) trim(filename), io_stat
637 IF (
PRESENT(n_datasets) ) n_datasets = n
642 LOGICAL,
OPTIONAL,
INTENT(IN) :: Close_File
644 IF (
PRESENT(close_file) )
THEN 645 IF ( close_file )
THEN 646 CLOSE( fid,iostat=io_stat )
648 msg = trim(msg)//
'; Error closing input file during error cleanup' 731 SensorData, & ! Output
732 Quiet , & ! Optional input
733 No_Close , & ! Optional input
734 n_DataSets, & ! Optional output
738 CHARACTER(*),
INTENT(IN) :: filename
740 LOGICAL,
OPTIONAL,
INTENT(IN) :: quiet
741 LOGICAL,
OPTIONAL,
INTENT(IN) :: no_close
742 INTEGER,
OPTIONAL,
INTENT(OUT) :: n_datasets
743 LOGICAL,
OPTIONAL,
INTENT(IN) :: debug
747 CHARACTER(*),
PARAMETER :: routine_name =
'CRTM_SensorData_ReadFile' 760 IF (
PRESENT(quiet) ) noisy = .NOT. quiet
763 IF (
PRESENT(no_close) ) yes_close = .NOT. no_close
765 IF (
PRESENT(debug) )
THEN 766 IF ( debug ) noisy = .true.
774 INQUIRE( file=filename,number=fid )
775 IF ( fid == -1 )
THEN 776 msg =
'Error inquiring '//trim(filename)//
' for its fid' 783 msg =
'File '//trim(filename)//
' not found.' 788 IF ( err_stat /=
success )
THEN 789 msg =
'Error opening '//trim(filename)
796 READ( fid,iostat=io_stat ) n
797 IF ( io_stat /= 0 )
THEN 798 WRITE( msg,
'("Error reading dataset dimensions from ",a,". IOSTAT = ",i0)' ) &
799 trim(filename), io_stat
803 IF ( n >
SIZE(sensordata) )
THEN 804 WRITE( msg,
'("Number of SensorData sets, ",i0," > size of the output ",& 805 &"SensorData object array, ",i0,".")' ) &
812 sensordata_loop:
DO i = 1, n
814 IF ( err_stat /=
success )
THEN 815 WRITE( msg,
'("Error reading SensorData element #",i0," from ",a)' ) &
819 END DO sensordata_loop
823 IF ( yes_close )
THEN 824 CLOSE( fid,iostat=io_stat )
825 IF ( io_stat /= 0 )
THEN 826 WRITE( msg,
'("Error closing ",a,". IOSTAT = ",i0)' ) trim(filename), io_stat
833 IF (
PRESENT(n_datasets) ) n_datasets = n
838 WRITE( msg,
'("Number of datasets read from ",a,": ",i0)' ) trim(filename), n
845 LOGICAL,
OPTIONAL,
INTENT(IN) :: Close_File
847 IF (
PRESENT(close_file) )
THEN 848 IF ( close_file )
THEN 849 CLOSE( fid,iostat=io_stat )
850 IF ( io_stat /= 0 ) &
851 msg = trim(msg)//
'; Error closing input file during error cleanup.' 932 SensorData, & ! Input
933 Quiet , & ! Optional input
934 No_Close , & ! Optional input
938 CHARACTER(*),
INTENT(IN) :: filename
940 LOGICAL,
OPTIONAL,
INTENT(IN) :: quiet
941 LOGICAL,
OPTIONAL,
INTENT(IN) :: no_close
942 LOGICAL,
OPTIONAL,
INTENT(IN) :: debug
946 CHARACTER(*),
PARAMETER :: routine_name =
'CRTM_SensorData_WriteFile' 947 CHARACTER(*),
PARAMETER :: file_status_on_error =
'DELETE' 960 IF (
PRESENT(quiet) ) noisy = .NOT. quiet
963 IF (
PRESENT(no_close) ) yes_close = .NOT. no_close
965 IF (
PRESENT(debug) )
THEN 966 IF ( debug ) noisy = .true.
970 IF ( any(sensordata%n_Channels < 1) )
THEN 971 msg =
'Dimensions of SensorData structures are < or = 0.' 979 INQUIRE( file=filename,number=fid )
980 IF ( fid == -1 )
THEN 981 msg =
'Error inquiring '//trim(filename)//
' for its fid' 987 IF ( err_stat /=
success )
THEN 988 msg =
'Error opening '//trim(filename)
996 WRITE( fid,iostat=io_stat) n
997 IF ( io_stat /= 0 )
THEN 998 WRITE( msg,
'("Error writing dataset dimensions to ",a,". IOSTAT = ",i0)' ) &
999 trim(filename), io_stat
1005 sensordata_loop:
DO i = 1, n
1007 IF ( err_stat /=
success )
THEN 1008 WRITE( msg,
'("Error writing SensorData element #",i0," to ",a)' ) &
1012 END DO sensordata_loop
1016 IF ( yes_close )
THEN 1017 CLOSE( fid,status=
'KEEP',iostat=io_stat )
1018 IF ( io_stat /= 0 )
THEN 1019 WRITE( msg,
'("Error closing ",a,". IOSTAT = ",i0)' ) trim(filename), io_stat
1027 WRITE( msg,
'("Number of datasets written to ",a,": ",i0)' ) trim(filename), n
1034 LOGICAL,
OPTIONAL,
INTENT(IN) :: Close_File
1036 IF (
PRESENT(close_file) )
THEN 1037 IF ( close_file )
THEN 1039 IF ( io_stat /= 0 ) &
1040 msg = trim(msg)//
'; Error deleting output file during error cleanup.' 1107 IF ( (x%n_Channels /= y%n_Channels ) .OR. &
1108 (x%Sensor_Id /= y%Sensor_Id ) .OR. &
1109 (x%WMO_Satellite_ID /= y%WMO_Satellite_ID) .OR. &
1110 (x%WMO_Sensor_ID /= y%WMO_Sensor_ID ) )
RETURN 1113 IF ( all(x%Sensor_Channel(1:n) == y%Sensor_Channel(1:n) ) .AND. &
1114 all(x%Tb(1:n) .equalto. y%Tb(1:n)) ) &
1163 IF ( sdata1%n_Channels /= sdata2%n_Channels .OR. &
1164 sdata1%Sensor_Id /= sdata2%Sensor_Id .OR. &
1165 sdata1%WMO_Satellite_ID /= sdata2%WMO_Satellite_ID .OR. &
1166 sdata1%WMO_Sensor_ID /= sdata2%WMO_Sensor_ID .OR. &
1167 any(sdata1%Sensor_Channel /= sdata2%Sensor_Channel) )
RETURN 1173 n = sdata1%n_Channels
1174 sdatasum%Tb(1:n) = sdatasum%Tb(1:n) + sdata2%Tb(1:n)
1221 IF ( sdata1%n_Channels /= sdata2%n_Channels .OR. &
1222 sdata1%Sensor_Id /= sdata2%Sensor_Id .OR. &
1223 sdata1%WMO_Satellite_ID /= sdata2%WMO_Satellite_ID .OR. &
1224 sdata1%WMO_Sensor_ID /= sdata2%WMO_Sensor_ID .OR. &
1225 any(sdata1%Sensor_Channel /= sdata2%Sensor_Channel) )
RETURN 1231 n = sdata1%n_Channels
1232 sdatadiff%Tb(1:n) = sdatadiff%Tb(1:n) - sdata2%Tb(1:n)
1278 INTEGER ,
INTENT(IN) :: fid
1283 CHARACTER(*),
PARAMETER :: routine_name =
'CRTM_SensorData_ReadFile(Record)' 1285 CHARACTER(ML) :: msg
1287 INTEGER :: n_channels
1294 READ( fid,iostat=io_stat ) n_channels
1295 IF ( io_stat /= 0 )
THEN 1296 WRITE( msg,
'("Error reading data dimensions. IOSTAT = ",i0)' ) io_stat
1304 msg =
'SensorData object allocation failed.' 1310 READ( fid,iostat=io_stat ) sensordata%Sensor_Id , &
1311 sensordata%WMO_Satellite_ID, &
1312 sensordata%WMO_Sensor_ID , &
1313 sensordata%Sensor_Channel , &
1315 IF ( io_stat /= 0 )
THEN 1316 WRITE( msg,
'("Error reading SensorData data. IOSTAT = ",i0)' ) io_stat
1326 CLOSE( fid,iostat=io_stat )
1328 msg = trim(msg)//
'; Error closing file during error cleanup' 1377 INTEGER ,
INTENT(IN) :: fid
1382 CHARACTER(*),
PARAMETER :: routine_name =
'CRTM_SensorData_WriteFile(Record)' 1384 CHARACTER(ML) :: msg
1390 msg =
'Input SensorData object is not used.' 1396 WRITE( fid,iostat=io_stat ) sensordata%n_Channels
1397 IF ( io_stat /= 0 )
THEN 1398 WRITE( msg,
'("Error writing dimensions. IOSTAT = ",i0)' ) io_stat
1404 WRITE( fid,iostat=io_stat ) sensordata%Sensor_Id , &
1405 sensordata%WMO_Satellite_ID, &
1406 sensordata%WMO_Sensor_ID , &
1407 sensordata%Sensor_Channel , &
1409 IF ( io_stat /= 0 )
THEN 1410 WRITE( msg,
'("Error writing SensorData data. IOSTAT = ",i0)' ) io_stat
1420 msg = trim(msg)//
'; Error closing file during error cleanup' elemental subroutine, public crtm_sensordata_create(SensorData, n_Channels)
integer, parameter, public failure
integer, parameter, public invalid_wmo_sensor_id
subroutine, public crtm_sensordata_inspect(SensorData, Unit)
integer, parameter, public strlen
integer, parameter, public warning
integer, parameter, public fp
elemental logical function, public crtm_sensordata_associated(SensorData)
integer function, public readgatts_binary_file(fid, Write_Module, Created_On, Title, History, Comment)
elemental logical function, public crtm_sensordata_compare(x, y, n_SigFig)
integer function, public crtm_sensordata_writefile(Filename, SensorData, Quiet, No_Close, Debug)
character(*), parameter write_error_status
integer function, public crtm_sensordata_inquirefile(Filename, n_DataSets)
subroutine inquire_cleanup()
integer, parameter, public invalid_wmo_satellite_id
logical function, public crtm_sensordata_isvalid(SensorData)
subroutine read_cleanup()
elemental subroutine, public crtm_sensordata_destroy(SensorData)
subroutine write_cleanup()
elemental subroutine, public crtm_sensordata_zero(SensorData)
subroutine read_record_cleanup()
integer function, public open_binary_file(Filename, FileID, For_Output, No_Check)
recursive subroutine, public display_message(Routine_Name, Message, Error_State, Message_Log)
elemental type(crtm_sensordata_type) function crtm_sensordata_subtract(sData1, sData2)
integer, parameter, public default_n_sigfig
integer function, public writegatts_binary_file(fid, Write_Module, Created_On, Title, History, Comment)
subroutine, public crtm_sensordata_defineversion(Id)
subroutine write_record_cleanup()
integer function read_record(fid, SensorData)
character(*), parameter module_version_id
integer function, public crtm_sensordata_readfile(Filename, SensorData, Quiet, No_Close, n_DataSets, Debug)
elemental type(crtm_sensordata_type) function crtm_sensordata_add(sData1, sData2)
elemental logical function crtm_sensordata_equal(x, y)
integer, parameter, public success
integer, parameter, public information