1program midas_thinning
2 !
3 !:Purpose: The thinning program reduces the density of observations for the purpose of
4 ! assimilation.
5 !
6 !
7 !:Algorithm: After setting up the ``obsSpace_data`` object, the thinning program calls
8 ! the ``filt_suprep`` routine which rejects certain observations based on
9 ! blacklists and other checks.
10 !
11 ! --
12 !
13 ! Specific routines are then called for thinning each observation types.
14 ! These routines are found in ``thinning_mod`` and are controlled by the
15 ! following namelists:
16 !
17 ! |
18 !
19 ! ======================= ======
20 ! Namelist
21 ! ======================= ======
22 ! ``thn_surface``
23 ! ``thn_raobs``
24 ! ``thn_aircraft``
25 ! ``thn_satwind``
26 ! ``thn_gpsro``
27 ! ``thn_gbgps``
28 ! ``thn_aladin``
29 ! ``thn_csr``
30 ! ``thn_scat``
31 ! ``thn_tovs``
32 ! ``thn_hyper``
33 ! ``thn_thinSatSST``
34 ! ======================= ======
35 !
36 ! |
37 !
38 ! Observations that are rejected by the thinning routines have their 11th bit *flag* set.
39 ! In a subsequent step, these observations are removed from observation files.
40 !
41 ! |
42 !
43 !
44 !:File I/O:
45 !
46 ! ============================================== ================================================================
47 ! Input and Output Files (NWP applicaton) Description of file
48 ! ============================================== ================================================================
49 ! ``flnml`` In - Main namelist file with parameters user may modify
50 ! ``trlm_$NN`` (e.g. ``trlm_01``) In - Background state -> necessary for observations in pressure
51 ! coordinates.
52 ! Observation Files In/Out - Sqlite/Burp observation files for different families.
53 ! ============================================== ================================================================
54 !
55 !
56 use version_mod
57 use ramDisk_mod
58 use utilities_mod
59 use midasMpi_mod
60 use timeCoord_mod
61 use obsSpaceData_mod
62 use obsFiles_mod
63 use tovsNL_mod
64 use obsFilter_mod
65 use thinning_mod
66 use fSQLite
67
68 implicit none
69
70 type(struct_obs) :: obsSpaceData
71 integer :: istamp,exdb,exfin
72 integer :: ierr, dateStampFromObs
73 integer :: get_max_rss
74
75 istamp = exdb('THINNING', 'DEBUT', 'NON')
76
77 call ver_printNameAndVersion('thinning', 'Observation thinning')
78
79 ! MPI initilization
80 call mmpi_initialize
81
82 call tmg_init(mmpi_myid, 'TMG_INFO')
83 call utl_tmg_start(0, 'Main')
84
85 ! 1. Top level setup
86
87 call ram_setup
88
89 ! 2. configuration the job
90
91 call utl_tmg_start(10,'--Observations')
92
93 !- Initialize observation file names
94 call obsf_setup(dateStampFromObs, 'thinning')
95
96 !- Allocate obsSpaceData
97 call obs_class_initialize('ALL')
98 call obs_initialize(obsSpaceData, mpi_local_opt = .true.)
99
100 !- Setup obsFilter_mod
101 call filt_setup('bgck')
102
103 !- Read observations
104 call utl_tmg_start(11,'----ReadObsFiles')
105 call obsf_readFiles(obsSpaceData)
106 call utl_tmg_stop(11)
107
108 write(*,*) 'Memory Used: ', get_max_rss() / 1024,'Mb'
109
110 !- Initialize TOVS processing
111 if (obs_famExist(obsSpaceData, 'TO')) call tvs_setup
112
113 !- Select the elements to "assimilate" and apply rejection flags
114 call filt_suprep(obsSpaceData)
115
116 call utl_tmg_stop(10)
117
118 !- Setup timeCoord module and set dateStamp from env variable
119 call tim_setup()
120 if (tim_getDateStamp() == 0) then
121 if (dateStampFromObs > 0) then
122 ! use dateStamp from obs if not set by env variable
123 call tim_setDateStamp(dateStampFromObs)
124 else
125 call utl_abort('midas-thinning: DateStamp was not set')
126 end if
127 end if
128
129 ! 3. Do the Thinning
130
131 !- Set bit 11 of flag, process one observation type at a time
132 call thn_thinHyper(obsSpaceData)
133 call thn_thinTovs(obsSpaceData)
134 call thn_thinCSR(obsSpaceData)
135 call thn_thinScat(obsSpaceData)
136 call thn_thinSatWinds(obsSpaceData)
137 call thn_thinAircraft(obsSpaceData)
138 call thn_thinSurface(obsSpaceData, 'SF') ! surface data thinning
139 if (obs_famExist(obsSpaceData, 'TM')) then
140 call thn_thinSurface(obsSpaceData, 'TM') ! insitu SST thinning
141 call thn_thinSatSST(obsSpaceData) ! satellite SST thinning
142 end if
143 call thn_thinGbGps(obsSpaceData)
144 call thn_thinGpsRo(obsSpaceData)
145 call thn_thinAladin(obsSpaceData)
146 write(*,*) 'Memory Used: ',get_max_rss() / 1024,'Mb'
147
148 if (obs_famExist( obsSpaceData, 'UA' )) then
149 write(*,*) 'midas-thinning: WARNING: radiosonde observations found in obsSpaceData!'
150 write(*,*) ' These observations cannot be thinned using the stand-alone'
151 write(*,*) ' MIDAS thinning program. Instead they should be thinned'
152 write(*,*) ' in combination with doing the background check in the'
153 write(*,*) ' obsSelection program.'
154 end if
155
156 !- Update obs files and remove rejected obs (bit 11) from file (obsFileClean)
157 call obsf_writeFiles(obsSpaceData)
158 call obsf_cleanObsFiles()
159 write(*,*) 'Memory Used: ',get_max_rss()/1024,'Mb'
160
161 ! 4. Job termination
162
163 istamp = exfin('THINNING', 'FIN', 'NON')
164
165 !- deallocate obsSpaceData
166 call obs_finalize(obsSpaceData)
167
168 call utl_tmg_stop(0)
169 call tmg_terminate(mmpi_myid, 'TMG_INFO')
170
171 call rpn_comm_finalize(ierr)
172
173end program midas_thinning