28 character(3),
dimension(:),
allocatable :: obstype
29 integer(i_kind) :: n_obstype
30 integer(i_kind),
dimension(:),
allocatable :: n_observations
31 integer(i_kind) :: n_observations_mass
32 integer(i_kind) :: n_observations_wind
33 integer(i_kind) :: n_observations_total
34 integer(i_kind) :: date
38 character(8) :: station_id
39 character(3) :: observation_class
40 real(r_kind) :: observation_type
41 real(r_kind) :: observation_subtype
42 real(r_kind) :: latitude
43 real(r_kind) :: longitude
44 real(r_kind) :: station_elevation
45 real(r_kind) :: pressure
46 real(r_kind) :: height
48 real(r_kind) :: prep_qc_mark
49 real(r_kind) :: setup_qc_mark
50 real(r_kind) :: prep_use_flag
51 real(r_kind) :: analysis_use_flag
52 real(r_kind) :: nonlinear_qc_rel_wgt
53 real(r_kind) :: errinv_input
54 real(r_kind) :: errinv_adjust
55 real(r_kind) :: errinv_final
56 real(r_kind) :: observation
57 real(r_kind) :: obs_minus_forecast_adjusted
58 real(r_kind) :: obs_minus_forecast_unadjusted
63 character(8) :: station_id
64 character(3) :: observation_class
65 real(r_kind) :: observation_type
66 real(r_kind) :: observation_subtype
67 real(r_kind) :: latitude
68 real(r_kind) :: longitude
69 real(r_kind) :: station_elevation
70 real(r_kind) :: pressure
71 real(r_kind) :: height
73 real(r_kind) :: prep_qc_mark
74 real(r_kind) :: setup_qc_mark
75 real(r_kind) :: prep_use_flag
76 real(r_kind) :: analysis_use_flag
77 real(r_kind) :: nonlinear_qc_rel_wgt
78 real(r_kind) :: errinv_input
79 real(r_kind) :: errinv_adjust
80 real(r_kind) :: errinv_final
81 real(r_kind) :: u_observation
82 real(r_kind) :: u_obs_minus_forecast_adjusted
83 real(r_kind) :: u_obs_minus_forecast_unadjusted
84 real(r_kind) :: v_observation
85 real(r_kind) :: v_obs_minus_forecast_adjusted
86 real(r_kind) :: v_obs_minus_forecast_unadjusted
87 real(r_kind) :: wind_reduction_factor_at_10m
93 integer,
parameter ::
lun=413
96 subroutine read_conv_diag(fn, conv_header, conv_mass, conv_wind, nobs_mass, nobs_wind, ncep)
97 character(120),
intent(in) :: fn
99 type(
diag_conv_mass),
dimension(:),
allocatable,
intent(inout) :: conv_mass
100 type(
diag_conv_wind),
dimension(:),
allocatable,
intent(inout) :: conv_wind
101 integer(i_kind),
intent(out) :: nobs_mass, nobs_wind
102 logical,
intent(in) :: ncep
104 integer(i_kind) :: ios
105 integer(i_kind) :: date
106 character(3) :: obstype
107 integer(i_kind) :: nchar, ninfo, nobs, mype, ioff
108 character(8),
allocatable,
dimension(:) :: cdiagbuf
109 real(r_single),
allocatable,
dimension(:,:) :: diagbuf
111 integer i, cobmass, cobwind
113 nobs_wind = conv_header%n_Observations(
get_obstype_index(
' uv',conv_header%ObsType))
114 nobs_mass = conv_header%n_Observations_Total - nobs_wind
116 print *,
'Mass, Wind obs count:',nobs_mass, nobs_wind
118 open(unit=
lun,file=trim(fn), iostat=ios, form=
'unformatted')
123 allocate( conv_mass(nobs_mass), conv_wind(nobs_wind) )
128 do while (ios .eq. 0)
130 read(
lun,iostat=ios) obstype,nchar,ninfo,nobs,mype
132 read(
lun,iostat=ios) obstype,nchar,ninfo,nobs,mype,ioff
136 allocate( cdiagbuf(nobs), diagbuf(ninfo, nobs) )
137 read(
lun,iostat=ios) cdiagbuf, diagbuf
140 if (obstype .eq.
' uv')
then 141 conv_wind(cobwind)%Station_ID = cdiagbuf(i)
142 conv_wind(cobwind)%Observation_Class = obstype
143 conv_wind(cobwind)%Observation_Type = diagbuf( 1,i)
144 conv_wind(cobwind)%Observation_Subtype = diagbuf( 2,i)
145 conv_wind(cobwind)%Latitude = diagbuf( 3,i)
146 conv_wind(cobwind)%Longitude = diagbuf( 4,i)
147 conv_wind(cobwind)%Station_Elevation = diagbuf( 5,i)
148 conv_wind(cobwind)%Pressure = diagbuf( 6,i)
149 conv_wind(cobwind)%Height = diagbuf( 7,i)
150 conv_wind(cobwind)%Time = diagbuf( 8,i)
151 conv_wind(cobwind)%Prep_QC_Mark = diagbuf( 9,i)
152 conv_wind(cobwind)%Setup_QC_Mark = diagbuf(10,i)
153 conv_wind(cobwind)%Prep_Use_Flag = diagbuf(11,i)
154 conv_wind(cobwind)%Analysis_Use_Flag = diagbuf(12,i)
155 conv_wind(cobwind)%Nonlinear_QC_Rel_Wgt = diagbuf(13,i)
156 conv_wind(cobwind)%Errinv_Input = diagbuf(14,i)
157 conv_wind(cobwind)%Errinv_Adjust = diagbuf(15,i)
158 conv_wind(cobwind)%Errinv_Final = diagbuf(16,i)
159 conv_wind(cobwind)%u_Observation = diagbuf(17,i)
160 conv_wind(cobwind)%u_Obs_Minus_Forecast_adjusted = diagbuf(18,i)
161 conv_wind(cobwind)%u_Obs_Minus_Forecast_unadjusted = diagbuf(19,i)
162 conv_wind(cobwind)%v_Observation = diagbuf(20,i)
163 conv_wind(cobwind)%v_Obs_Minus_Forecast_adjusted = diagbuf(21,i)
164 conv_wind(cobwind)%v_Obs_Minus_Forecast_unadjusted = diagbuf(22,i)
165 conv_wind(cobwind)%Wind_Reduction_Factor_at_10m = diagbuf(23,i)
166 cobwind = cobwind + 1
168 conv_mass(cobmass)%Station_ID = cdiagbuf(i)
169 conv_mass(cobmass)%Observation_Class = obstype
170 conv_mass(cobmass)%Observation_Type = diagbuf( 1,i)
171 conv_mass(cobmass)%Observation_Subtype = diagbuf( 2,i)
172 conv_mass(cobmass)%Latitude = diagbuf( 3,i)
173 conv_mass(cobmass)%Longitude = diagbuf( 4,i)
174 conv_mass(cobmass)%Station_Elevation = diagbuf( 5,i)
175 conv_mass(cobmass)%Pressure = diagbuf( 6,i)
176 conv_mass(cobmass)%Height = diagbuf( 7,i)
177 conv_mass(cobmass)%Time = diagbuf( 8,i)
178 conv_mass(cobmass)%Prep_QC_Mark = diagbuf( 9,i)
179 conv_mass(cobmass)%Setup_QC_Mark = diagbuf(10,i)
180 conv_mass(cobmass)%Prep_Use_Flag = diagbuf(11,i)
181 conv_mass(cobmass)%Analysis_Use_Flag = diagbuf(12,i)
182 conv_mass(cobmass)%Nonlinear_QC_Rel_Wgt = diagbuf(13,i)
183 conv_mass(cobmass)%Errinv_Input = diagbuf(14,i)
184 conv_mass(cobmass)%Errinv_Adjust = diagbuf(15,i)
185 conv_mass(cobmass)%Errinv_Final = diagbuf(16,i)
186 conv_mass(cobmass)%Observation = diagbuf(17,i)
187 conv_mass(cobmass)%Obs_Minus_Forecast_adjusted = diagbuf(18,i)
188 conv_mass(cobmass)%Obs_Minus_Forecast_unadjusted = diagbuf(19,i)
189 cobmass = cobmass + 1
197 deallocate( cdiagbuf, diagbuf)
209 character(120),
intent(in) :: fn
211 logical,
intent(in) :: ncep
213 character(3),
dimension(maxobstype) :: cobstype
214 integer(i_kind),
dimension(maxobstype) :: cnobs
216 integer(i_kind) :: ios
217 integer(i_kind) :: date
218 character(3) :: obstype
219 integer(i_kind) :: nchar, ninfo, nobs, mype, ioff
220 character(8),
allocatable,
dimension(:) :: cdiagbuf
221 real(4),
allocatable,
dimension(:,:) :: diagbuf
224 integer(i_kind) :: idx
229 open(unit=
lun,file=trim(fn), iostat=ios, form=
'unformatted')
234 conv_header%date = date
235 conv_header%n_Observations_Total = 0
239 do while (ios .eq. 0)
241 read(
lun,iostat=ios) obstype,nchar,ninfo,nobs,mype
243 read(
lun,iostat=ios) obstype,nchar,ninfo,nobs,mype,ioff
247 conv_header%n_Observations_Total = conv_header%n_Observations_Total + nobs
249 cnobs(idx) = cnobs(idx) + nobs
251 allocate( cdiagbuf(nobs), diagbuf(ninfo, nobs) )
252 read(
lun,iostat=ios) cdiagbuf, diagbuf
253 deallocate( cdiagbuf, diagbuf)
260 allocate( conv_header%ObsType(
nobstype), conv_header%n_Observations(
nobstype) )
262 print *,
'n_ObsType=',conv_header%n_ObsType
263 print *,
'obstype, count=' 265 conv_header%ObsType(idx) = cobstype(idx)
266 conv_header%n_Observations(idx) = cnobs(idx)
267 print *,conv_header%ObsType(idx),conv_header%n_Observations(idx)
270 conv_header%n_Observations_Wind = conv_header%n_Observations(
get_obstype_index(
' uv',conv_header%ObsType))
271 conv_header%n_Observations_Mass = conv_header%n_Observations_Total - conv_header%n_Observations_Wind
277 character(3),
intent(in) :: obstype
278 character(3),
intent(inout),
dimension(*) :: obstypearr
287 obstypearr(1) = obstype
289 print *,
'obstype=',obstype,
' set to index',idx
292 if (obstype .eq. obstypearr(i))
then 297 if (.not. matched)
then 301 print *,
'obstype=',obstype,
' set to index',idx
312 character(120),
intent(in) :: infn
314 type(
diag_conv_mass),
dimension(conv_header%n_Observations_Mass),
intent(in) :: conv_mass
315 type(
diag_conv_wind),
dimension(conv_header%n_Observations_Wind),
intent(in) :: conv_wind
316 logical,
intent(in) :: append_suffix
318 character(120) :: outfn
319 character(20) :: str, str2
323 do itype=1, conv_header%n_ObsType
324 str = conv_header%ObsType(itype)
325 if (.not. append_suffix)
then 326 str2 =
'diag_conv_' // trim(adjustl(str))
329 outfn = outfn(1:
strlen-3) //
'nc4' 331 outfn = trim(infn) //
'.' // trim(adjustl(str)) //
'.nc4' 338 if (conv_header%ObsType(itype) .eq.
' uv')
then 339 do i=1,conv_header%n_Observations_Wind
340 call nc_diag_metadata(
"Station_ID", conv_wind(i)%Station_ID)
341 call nc_diag_metadata(
"Observation_Class", conv_wind(i)%Observation_Class )
342 call nc_diag_metadata(
"Observation_Type", conv_wind(i)%Observation_Type )
343 call nc_diag_metadata(
"Observation_Subtype", conv_wind(i)%Observation_Subtype )
344 call nc_diag_metadata(
"Latitude", conv_wind(i)%Latitude )
345 call nc_diag_metadata(
"Longitude", conv_wind(i)%Longitude )
346 call nc_diag_metadata(
"Station_Elevation", conv_wind(i)%Station_Elevation )
347 call nc_diag_metadata(
"Pressure", conv_wind(i)%Pressure )
348 call nc_diag_metadata(
"Height", conv_wind(i)%Height )
349 call nc_diag_metadata(
"Time", conv_wind(i)%Time )
350 call nc_diag_metadata(
"Prep_QC_Mark", conv_wind(i)%Prep_QC_Mark )
351 call nc_diag_metadata(
"Setup_QC_Mark", conv_wind(i)%Setup_QC_Mark )
352 call nc_diag_metadata(
"Prep_Use_Flag", conv_wind(i)%Prep_Use_Flag )
353 call nc_diag_metadata(
"Analysis_Use_Flag", conv_wind(i)%Analysis_Use_Flag )
354 call nc_diag_metadata(
"Nonlinear_QC_Rel_Wgt", conv_wind(i)%Nonlinear_QC_Rel_Wgt )
355 call nc_diag_metadata(
"Errinv_Input", conv_wind(i)%Errinv_Input )
356 call nc_diag_metadata(
"Errinv_Adjust", conv_wind(i)%Errinv_Adjust )
357 call nc_diag_metadata(
"Errinv_Final", conv_wind(i)%Errinv_Final )
358 call nc_diag_metadata(
"u_Observation", conv_wind(i)%u_Observation )
359 call nc_diag_metadata(
"u_Obs_Minus_Forecast_adjusted", conv_wind(i)%u_Obs_Minus_Forecast_adjusted )
360 call nc_diag_metadata(
"u_Obs_Minus_Forecast_unadjusted", conv_wind(i)%u_Obs_Minus_Forecast_unadjusted )
361 call nc_diag_metadata(
"v_Observation", conv_wind(i)%v_Observation )
362 call nc_diag_metadata(
"v_Obs_Minus_Forecast_adjusted", conv_wind(i)%v_Obs_Minus_Forecast_adjusted )
363 call nc_diag_metadata(
"v_Obs_Minus_Forecast_unadjusted", conv_wind(i)%v_Obs_Minus_Forecast_unadjusted )
364 call nc_diag_metadata(
"Wind_Reduction_Factor_at_10m", conv_wind(i)%Wind_Reduction_Factor_at_10m )
367 do i=1,conv_header%n_Observations_Mass
368 if (conv_mass(i)%Observation_Class .eq. conv_header%ObsType(itype) )
then 369 call nc_diag_metadata(
"Station_ID", conv_mass(i)%Station_ID )
370 call nc_diag_metadata(
"Observation_Class", conv_mass(i)%Observation_Class )
371 call nc_diag_metadata(
"Observation_Type", conv_mass(i)%Observation_Type )
372 call nc_diag_metadata(
"Observation_Subtype", conv_mass(i)%Observation_Subtype )
373 call nc_diag_metadata(
"Latitude", conv_mass(i)%Latitude )
374 call nc_diag_metadata(
"Longitude", conv_mass(i)%Longitude )
375 call nc_diag_metadata(
"Station_Elevation", conv_mass(i)%Station_Elevation )
376 call nc_diag_metadata(
"Pressure", conv_mass(i)%Pressure )
377 call nc_diag_metadata(
"Height", conv_mass(i)%Height )
378 call nc_diag_metadata(
"Time", conv_mass(i)%Time )
379 call nc_diag_metadata(
"Prep_QC_Mark", conv_mass(i)%Prep_QC_Mark )
380 call nc_diag_metadata(
"Setup_QC_Mark", conv_mass(i)%Setup_QC_Mark )
381 call nc_diag_metadata(
"Prep_Use_Flag", conv_mass(i)%Prep_Use_Flag )
382 call nc_diag_metadata(
"Analysis_Use_Flag", conv_mass(i)%Analysis_Use_Flag )
383 call nc_diag_metadata(
"Nonlinear_QC_Rel_Wgt", conv_mass(i)%Nonlinear_QC_Rel_Wgt )
384 call nc_diag_metadata(
"Errinv_Input", conv_mass(i)%Errinv_Input )
385 call nc_diag_metadata(
"Errinv_Adjust", conv_mass(i)%Errinv_Adjust )
386 call nc_diag_metadata(
"Errinv_Final", conv_mass(i)%Errinv_Final )
387 call nc_diag_metadata(
"Observation", conv_mass(i)%Observation )
388 call nc_diag_metadata(
"Obs_Minus_Forecast_adjusted", conv_mass(i)%Obs_Minus_Forecast_adjusted )
389 call nc_diag_metadata(
"Obs_Minus_Forecast_unadjusted", conv_mass(i)%Obs_Minus_Forecast_unadjusted )
401 character(len=*),
intent(in) :: infn
403 integer(i_kind),
intent(inout) :: nobs
405 integer(i_kind) :: fid
408 call nc_diag_read_init(infn,fid)
409 nobs = nc_diag_read_get_dim(fid,
'nobs')
410 call nc_diag_read_get_global_attr(fid,
"date_time", conv_header%date )
411 conv_header%n_Observations_Mass = nobs
412 call nc_diag_read_close(infn)
417 character(len=*),
intent(in) :: infn
419 type(
diag_conv_mass),
dimension(conv_header%n_Observations_Mass),
intent(inout) :: conv_mass
421 character(20) :: str, str2
422 integer(i_kind) :: i, itype, fid, nobs
423 character(len=8),
allocatable,
dimension(:) :: c_var
424 integer(i_kind),
allocatable,
dimension(:) :: i_var
425 real(r_kind),
allocatable,
dimension(:) :: r_var
427 call nc_diag_read_init(infn,fid)
429 nobs=conv_header%n_Observations_Mass
430 allocate(c_var(nobs))
431 allocate(i_var(nobs))
432 allocate(r_var(nobs))
437 call nc_diag_read_get_var(fid,
"Observation_Type", i_var ); conv_mass(:)%Observation_Type = i_var
438 call nc_diag_read_get_var(fid,
"Observation_Subtype", i_var ); conv_mass(:)%Observation_Subtype = i_var
439 call nc_diag_read_get_var(fid,
"Latitude", r_var ); conv_mass(:)%Latitude = r_var
440 call nc_diag_read_get_var(fid,
"Longitude", r_var ); conv_mass(:)%Longitude = r_var
441 call nc_diag_read_get_var(fid,
"Pressure", r_var ); conv_mass(:)%Pressure = r_var
442 call nc_diag_read_get_var(fid,
"Height", r_var ); conv_mass(:)%Height = r_var
443 call nc_diag_read_get_var(fid,
"Time", r_var ); conv_mass(:)%Time = r_var
444 call nc_diag_read_get_var(fid,
"Prep_QC_Mark", r_var ); conv_mass(:)%Prep_QC_Mark = r_var
445 call nc_diag_read_get_var(fid,
"Setup_QC_Mark", r_var ); conv_mass(:)%Setup_QC_Mark = r_var
446 call nc_diag_read_get_var(fid,
"Prep_Use_Flag", r_var ); conv_mass(:)%Prep_Use_Flag = r_var
447 call nc_diag_read_get_var(fid,
"Analysis_Use_Flag", r_var ); conv_mass(:)%Analysis_Use_Flag = r_var
448 call nc_diag_read_get_var(fid,
"Nonlinear_QC_Rel_Wgt", r_var ); conv_mass(:)%Nonlinear_QC_Rel_Wgt = r_var
449 call nc_diag_read_get_var(fid,
"Errinv_Input", r_var ); conv_mass(:)%Errinv_Input = r_var
450 call nc_diag_read_get_var(fid,
"Errinv_Adjust", r_var ); conv_mass(:)%Errinv_Adjust = r_var
451 call nc_diag_read_get_var(fid,
"Errinv_Final", r_var ); conv_mass(:)%Errinv_Final = r_var
452 call nc_diag_read_get_var(fid,
"Observation", r_var ); conv_mass(:)%Observation = r_var
453 call nc_diag_read_get_var(fid,
"Obs_Minus_Forecast_adjusted", r_var ); conv_mass(:)%Obs_Minus_Forecast_adjusted = r_var
454 call nc_diag_read_get_var(fid,
"Obs_Minus_Forecast_unadjusted",r_var ); conv_mass(:)%Obs_Minus_Forecast_unadjusted = r_var
460 call nc_diag_read_close(infn)
464 character(*) :: s,text,rep
465 character(len(s)+100) :: outs
468 outs = s ; nt = len_trim(text) ; nr = len_trim(rep)
469 i = index(outs,text(:nt))
470 outs = outs(:i-1) // rep(:nr) // outs(i+nt:)
subroutine, public read_conv_diag_nc_header(infn, conv_header, nobs)
integer, parameter, public strlen
integer, parameter, public i_kind
subroutine nc_diag_init(filename, append)
character(len(s)+100) function replace_text(s, text, rep)
integer, parameter maxobstype
integer(i_kind) function get_obstype_index(obstype, obstypearr)
subroutine, public open_conv_diag(fn, conv_header, ncep)
subroutine, public read_conv_diag(fn, conv_header, conv_mass, conv_wind, nobs_mass, nobs_wind, ncep)
subroutine nc_diag_read_close(filename, file_ncdr_id, from_pop)
integer, parameter, public r_double
subroutine, public read_conv_diag_nc_mass(infn, conv_header, conv_mass)
integer, parameter, public r_single
integer, parameter, public r_kind
subroutine nc_diag_read_init(filename, file_ncdr_id, from_push)
subroutine, public write_split_conv_diag_nc(infn, conv_header, conv_mass, conv_wind, append_suffix)