Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
swbstats2_support.F90
Go to the documentation of this file.
2
6 use iso_fortran_env, only : output_unit
8 use datetime, only : datetime_t, assignment(=), operator(>), &
10 use exceptions, only : assert, die
12 use grid, only : general_grid_t, &
18 use fstring
19 use fstring_list, only : fstring_list_t, &
21
23 use iso_c_binding
24 implicit none
25
26 enum, bind(c)
40 end enum
41
42 enum, bind(c)
46 end enum
47
48 integer (c_size_t) :: recnum = 0
49
50
52 character (len=24) :: unit_name
53 character (len=10) :: unit_abbrev
54 real (c_double) :: conversion_factor_from_inches
55 end type length_unit_t
56
58 character (len=24) :: unit_name
59 character (len=10) :: unit_abbrev
60 real (c_double) :: conversion_factor_from_cubic_feet
61 end type volume_unit_t
62
64 type (t_netcdf4_file), pointer :: nc_ptr => null()
65 type (general_grid_t), pointer :: grid_ptr => null()
66 character (len=8) :: stats_description
67 integer (c_int) :: n_count = 0
68 logical (c_bool) :: write_netcdf = false
69 logical (c_bool) :: write_arcgrid = false
70 logical (c_bool) :: output_active = false
71 real (c_float) :: valid_min = 10000. ! only used for netCDF output
72 real (c_float) :: valid_max = -10000.
73 end type file_collection_t
74
76 logical (c_bool) :: dump_options_to_screen = false
77 logical (c_bool) :: write_csv = false
78 logical (c_bool) :: calc_zonal_stats = false
79 logical (c_bool) :: compare_to_obs_values = false
80 logical (c_bool) :: annualize_stats = false
81 logical (c_bool) :: report_as_volume = false
82 logical (c_bool) :: report_in_meters = false
83 character (len=:), allocatable :: output_file_prefix
84 character (len=:), allocatable :: target_proj4_string
85 type (datetime_t) :: data_start_date
86 type (datetime_t) :: data_end_date
87 type (datetime_t) :: slice_start_date
88 type (datetime_t) :: slice_end_date
89 character (len=:), allocatable :: slice_range_string
90 character (len=:), allocatable :: date_range_string
91 integer (c_int) :: calculation_time_period = calc_period_all
92 character (len=:), allocatable :: stress_period_filename
93 character (len=:), allocatable :: comparison_period_filename
94 character (len=:), allocatable :: zone_period_filename
95 character (len=:), allocatable :: comparison_grid_filename
96 character (len=:), allocatable :: zone_grid_filename
97 character (len=:), allocatable :: zone_grid2_filename
98 character (len=:), allocatable :: netcdf_input_filename
99 character (len=:), allocatable :: netcdf_variable_units_string
100 character (len=:), allocatable :: netcdf_variable_name_string
101 character (len=:), allocatable :: filename_modifier_string
102 logical (c_bool) :: netcdf_input_file_is_open = false
103 logical (c_bool) :: multiple_zone_grids = false
104 logical (c_bool) :: multiple_comparison_grids = false
105 real (c_double) :: comparison_grid_conversion_factor = 1.0_c_double
106 type (fstring_list_t) :: start_date_list
107 type (fstring_list_t) :: end_date_list
108 type (fstring_list_t) :: date_range_id_list
109 type (fstring_list_t) :: unique_zone_list
110 type (fstring_list_t) :: unique_zone2_list
111 type (fstring_list_t) :: comparison_grid_file_list
112 type (fstring_list_t) :: zone_grid_file_list
113 real (c_double) :: output_conversion_factor = 1.0_c_double
114 real (c_double) :: unit_conversion_factor = 1.0_c_double
115 real (c_double) :: grid_cell_area_sq_meters = 1.0_c_double
116 real (c_double) :: length_conversion_factor = 1.0_c_double
117 type (t_netcdf4_file), pointer :: ncfile_in
118 type (ascii_file_t) :: zonal_stats_output_file
119 type (ascii_file_t) :: whole_grid_stats_output_file
120
121 type (general_grid_t), pointer :: grd_native => null()
122 type (general_grid_t), pointer :: grd_delta => null()
123 type (general_grid_t), pointer :: grd_delta2 => null()
124 type (data_catalog_entry_t), pointer :: grd_zone => null()
125 type (data_catalog_entry_t), pointer :: grd_zone2 => null()
126 type (data_catalog_entry_t), pointer :: grd_comparison => null()
127
128 contains
129
131 generic :: set_conversion_factors => set_conversion_factors_sub
132
135
137
142
146
147 procedure :: get_unique_int
148
152
155
158
163
164 procedure :: print_all_options
165
166 end type swbstats_t
167
168 type (length_unit_t), parameter :: length_units(3) = [ &
169 length_unit_t("meters ", "m ", 0.254_c_double), &
170 length_unit_t("feet ", "ft", 1.0_c_double / 12.0_c_double), &
171 length_unit_t("millimeters", "mm", 25.4_c_double) ]
172
173 type (volume_unit_t), parameter :: volume_units(3) = [ &
174 volume_unit_t("billions of gallons", "BG ", 7.4805194805e-9_c_double ), &
175 volume_unit_t("millions of gallons", "MG ", 7.4805194805e-6_c_double), &
176 volume_unit_t("acre-feet ", "ac-ft", 0.000022956840808_c_double) ]
177
179
181
183
185
186contains
187
188 subroutine create_working_grids(this)
189
190 class(swbstats_t), intent(inout) :: this
191
192 ! create some working grids to hold raw and summed values
193 this%grd_native => grid_create( inx=this%ncfile_in%iNX, &
194 iny=this%ncfile_in%iNY, &
195 rx0=this%ncfile_in%rX(nc_left), &
196 ry0=this%ncfile_in%rY(nc_bottom), &
197 rx1=this%ncfile_in%rX(nc_right), &
198 ry1=this%ncfile_in%rY(nc_top), &
199 idatatype=grid_datatype_double )
200
201 output_files(stats_sum)%grid_ptr => grid_create( &
202 inx=this%ncfile_in%iNX, &
203 iny=this%ncfile_in%iNY, &
204 rx0=this%ncfile_in%rX(nc_left), &
205 ry0=this%ncfile_in%rY(nc_bottom), &
206 rx1=this%ncfile_in%rX(nc_right), &
207 ry1=this%ncfile_in%rY(nc_top), &
208 idatatype=grid_datatype_double )
209 output_files(stats_sum)%stats_description = "SUM"
210
211 output_files(stats_mean)%grid_ptr => grid_create( &
212 inx=this%ncfile_in%iNX, &
213 iny=this%ncfile_in%iNY, &
214 rx0=this%ncfile_in%rX(nc_left), &
215 ry0=this%ncfile_in%rY(nc_bottom), &
216 rx1=this%ncfile_in%rX(nc_right), &
217 ry1=this%ncfile_in%rY(nc_top), &
218 idatatype=grid_datatype_double )
219 output_files(stats_mean)%stats_description = "MEAN"
220
222 inx=this%ncfile_in%iNX, &
223 iny=this%ncfile_in%iNY, &
224 rx0=this%ncfile_in%rX(nc_left), &
225 ry0=this%ncfile_in%rY(nc_bottom), &
226 rx1=this%ncfile_in%rX(nc_right), &
227 ry1=this%ncfile_in%rY(nc_top), &
228 idatatype=grid_datatype_double )
229 output_files(stats_variance)%stats_description = "VARIANCE"
230
231 ! delta, delta2 are temporary work grids used in calculating variance
232 this%grd_delta => grid_create( inx=this%ncfile_in%iNX, &
233 iny=this%ncfile_in%iNY, &
234 rx0=this%ncfile_in%rX(nc_left), &
235 ry0=this%ncfile_in%rY(nc_bottom), &
236 rx1=this%ncfile_in%rX(nc_right), &
237 ry1=this%ncfile_in%rY(nc_top), &
238 idatatype=grid_datatype_double )
239
240 this%grd_delta2 => grid_create( inx=this%ncfile_in%iNX, &
241 iny=this%ncfile_in%iNY, &
242 rx0=this%ncfile_in%rX(nc_left), &
243 ry0=this%ncfile_in%rY(nc_bottom), &
244 rx1=this%ncfile_in%rX(nc_right), &
245 ry1=this%ncfile_in%rY(nc_top), &
246 idatatype=grid_datatype_double )
247
248 ! extract basic information about the SWB computational grid
249 ! 'BNDS' is defined in module constants_and_conversions
250 bnds%iNumCols = this%ncfile_in%iNX
251 bnds%iNumRows = this%ncfile_in%iNY
252 bnds%fX_ll = this%grd_native%rX0
253 bnds%fY_ll = this%grd_native%rY0
254 bnds%fX_ur = this%grd_native%rX1
255 bnds%fY_ur = this%grd_native%rY1
256 bnds%fGridCellSize = this%grd_native%rGridCellSize
257 bnds%sPROJ4_string = this%target_proj4_string
258
259 end subroutine create_working_grids
260
261!------------------------------------------------------------------------------
262
264
265 class(swbstats_t), intent(inout) :: this
266
267 integer (c_int) :: month_num
268 integer (c_int) :: sum_index_num
269 integer (c_int) :: mean_index_num
270 integer (c_int) :: variance_index_num
271 character (len=3) :: month_name
272
273 do month_num = 1,12
274
275 ! extract month name from the datetime module MONTHS data structure
276 month_name = months(month_num)%sName ! yields the following index numbers...
277 sum_index_num = ( month_num - 1 ) * 3 + 1 ! 1 4 7 10 13 16 19 22 25 28 31 34
278 mean_index_num = ( month_num - 1 ) * 3 + 2 ! 2 5 8 11 14 17 20 23 26 29 32 35
279 variance_index_num = ( month_num - 1 ) * 3 + 3 ! 3 6 9 12 15 18 21 24 27 30 33 36
280
281 output_files(sum_index_num)%grid_ptr => grid_create( &
282 inx=this%ncfile_in%iNX, &
283 iny=this%ncfile_in%iNY, &
284 rx0=this%ncfile_in%rX(nc_left), &
285 ry0=this%ncfile_in%rY(nc_bottom), &
286 rx1=this%ncfile_in%rX(nc_right), &
287 ry1=this%ncfile_in%rY(nc_top), &
288 idatatype=grid_datatype_double )
289 output_files(sum_index_num)%stats_description = "SUM"
290 output_files(sum_index_num)%write_arcgrid = true
291
292 output_files(mean_index_num)%grid_ptr => grid_create( &
293 inx=this%ncfile_in%iNX, &
294 iny=this%ncfile_in%iNY, &
295 rx0=this%ncfile_in%rX(nc_left), &
296 ry0=this%ncfile_in%rY(nc_bottom), &
297 rx1=this%ncfile_in%rX(nc_right), &
298 ry1=this%ncfile_in%rY(nc_top), &
299 idatatype=grid_datatype_double )
300 output_files(mean_index_num)%stats_description = "MEAN"
301 output_files(mean_index_num)%write_arcgrid = true
302
303 output_files(variance_index_num)%grid_ptr => grid_create( &
304 inx=this%ncfile_in%iNX, &
305 iny=this%ncfile_in%iNY, &
306 rx0=this%ncfile_in%rX(nc_left), &
307 ry0=this%ncfile_in%rY(nc_bottom), &
308 rx1=this%ncfile_in%rX(nc_right), &
309 ry1=this%ncfile_in%rY(nc_top), &
310 idatatype=grid_datatype_double )
311 output_files(variance_index_num)%stats_description = "VARIANCE"
312
313 enddo
314
315 end subroutine create_monthly_working_grids
316
317!------------------------------------------------------------------------------
318
319 subroutine calc_zonal_stats(values, zone_ids, target_id, result_vector, comparison_values)
320
321 real (c_double), intent(inout) :: values(:,:)
322 integer (c_int), intent(inout) :: zone_ids(:,:)
323 integer (c_int), intent(inout) :: target_id
324 real (c_double), intent(inout), allocatable :: result_vector(:)
325 real (c_double), intent(inout), optional :: comparison_values(:,:)
326
327 ! [ LOCALS ]
328 real (c_double) :: min_val
329 real (c_double) :: max_val
330 real (c_double) :: mean_val
331 real (c_double) :: sum_val
332 real (c_double) :: n_val
333
334 real (c_double) :: min_val_comp
335 real (c_double) :: max_val_comp
336 real (c_double) :: mean_val_comp
337 real (c_double) :: sum_val_comp
338 real (c_double) :: n_val_comp
339
340 mean_val = 0.0; mean_val_comp = 0.0
341 max_val = 0.0; max_val_comp = 0.0
342 min_val = 0.0; min_val_comp = 0.0
343 sum_val = 0.0; sum_val = 0.0
344 n_val = 0.0; n_val_comp = 0.0
345
346 n_val = count( zone_ids==target_id .and. values > nc_fill_float )
347
348 if ( n_val > 0 ) then
349 sum_val = sum( values, zone_ids==target_id .and. values > nc_fill_float )
350 mean_val = sum_val / n_val
351 min_val = minval( values, zone_ids==target_id .and. values > nc_fill_float )
352 max_val = maxval( values, zone_ids==target_id .and. values > nc_fill_float )
353 endif
354
355 if ( allocated(result_vector) ) deallocate(result_vector)
356
357 if ( present( comparison_values ) ) then
358
359 n_val_comp = count( zone_ids==target_id .and. comparison_values > nc_fill_float )
360
361 if ( n_val_comp > 0 ) then
362 n_val_comp = count( zone_ids==target_id .and. comparison_values > nc_fill_float )
363 sum_val_comp = sum( comparison_values, zone_ids==target_id .and. comparison_values > nc_fill_float )
364 mean_val_comp = sum_val_comp / n_val_comp
365 min_val_comp = minval( comparison_values, zone_ids==target_id .and. comparison_values > nc_fill_float )
366 max_val_comp = maxval( comparison_values, zone_ids==target_id .and. comparison_values > nc_fill_float )
367 endif
368
369 allocate( result_vector(10) )
370 result_vector(6) = min_val_comp
371 result_vector(7) = max_val_comp
372 result_vector(8) = mean_val_comp
373 result_vector(9) = sum_val_comp
374 result_vector(10) = n_val_comp
375 else
376 allocate (result_vector(5))
377 endif
378
379 result_vector(1) = min_val
380 result_vector(2) = max_val
381 result_vector(3) = mean_val
382 result_vector(4) = sum_val
383 result_vector(5) = n_val
384
385 end subroutine calc_zonal_stats
386
387!------------------------------------------------------------------------------
388
389 subroutine calc_multizonal_stats(values, zone_ids, zone2_ids, &
390 target_id, target2_id, result_vector, comparison_values)
391
392 real (c_double), intent(inout) :: values(:,:)
393 integer (c_int), intent(inout) :: zone_ids(:,:)
394 integer (c_int), intent(inout) :: zone2_ids(:,:)
395 integer (c_int), intent(inout) :: target_id
396 integer (c_int), intent(inout) :: target2_id
397 real (c_double), intent(inout), allocatable :: result_vector(:)
398 real (c_double), intent(inout), optional :: comparison_values(:,:)
399
400 ! [ LOCALS ]
401 real (c_double) :: min_val
402 real (c_double) :: max_val
403 real (c_double) :: mean_val
404 real (c_double) :: sum_val
405 real (c_double) :: n_val
406
407 real (c_double) :: min_val_comp
408 real (c_double) :: max_val_comp
409 real (c_double) :: mean_val_comp
410 real (c_double) :: sum_val_comp
411 real (c_double) :: n_val_comp
412
413 mean_val = 0.0; mean_val_comp = 0.0
414 max_val = 0.0; max_val_comp = 0.0
415 min_val = 0.0; min_val_comp = 0.0
416 sum_val = 0.0; sum_val = 0.0
417 n_val = 0.0; n_val_comp = 0.0
418
419 n_val = count( zone_ids==target_id .and. zone2_ids==target2_id &
420 .and. values > nc_fill_float )
421
422 if ( n_val > 0 ) then
423 sum_val = sum( values, zone_ids==target_id .and. zone2_ids==target2_id &
424 .and. values > nc_fill_float )
425 mean_val = sum_val / n_val
426 min_val = minval( values, zone_ids==target_id .and. zone2_ids==target2_id &
427 .and. values > nc_fill_float )
428 max_val = maxval( values, zone_ids==target_id .and. zone2_ids==target2_id &
429 .and. values > nc_fill_float )
430 endif
431
432 if ( allocated(result_vector) ) deallocate(result_vector)
433
434 if ( present( comparison_values ) ) then
435
436 n_val_comp = count( zone_ids==target_id .and. zone2_ids==target2_id &
437 .and. comparison_values > nc_fill_float )
438
439 if ( n_val_comp > 0 ) then
440 n_val_comp = count( zone_ids==target_id .and. zone2_ids==target2_id &
441 .and. comparison_values > nc_fill_float )
442 sum_val_comp = sum( comparison_values, zone_ids==target_id .and. zone2_ids==target2_id &
443 .and. comparison_values > nc_fill_float )
444 mean_val_comp = sum_val_comp / n_val_comp
445 min_val_comp = minval( comparison_values, zone_ids==target_id .and. zone2_ids==target2_id &
446 .and. comparison_values > nc_fill_float )
447 max_val_comp = maxval( comparison_values, zone_ids==target_id .and. zone2_ids==target2_id &
448 .and. comparison_values > nc_fill_float )
449 endif
450
451 allocate( result_vector(10) )
452 result_vector(6) = min_val_comp
453 result_vector(7) = max_val_comp
454 result_vector(8) = mean_val_comp
455 result_vector(9) = sum_val_comp
456 result_vector(10) = n_val_comp
457 else
458 allocate (result_vector(5))
459 endif
460
461 result_vector(1) = min_val
462 result_vector(2) = max_val
463 result_vector(3) = mean_val
464 result_vector(4) = sum_val
465 result_vector(5) = n_val
466
467 end subroutine calc_multizonal_stats
468
469!------------------------------------------------------------------------------
470
471 subroutine get_unique_int(this, grid_values, unique_val_list)
472
473 class(swbstats_t), intent(inout) :: this
474 integer (c_int), intent(in) :: grid_values(:,:)
475 type (FSTRING_LIST_T), intent(inout) :: unique_val_list
476
477 ! [ LOCALS ]
478 integer (c_int) :: ix, iy
479 character (len=20) :: sval
480
481 do ix=1,ubound(grid_values,1)
482 do iy=1,ubound(grid_values,2)
483
484 if (grid_values(ix, iy) < 0 ) cycle
485
486 sval = ascharacter( grid_values(ix,iy) )
487
488 if ( unique_val_list%count == 0) then
489 call unique_val_list%append(sval)
490
491 else
492 if ( unique_val_list%count_matching( sval ) > 0 ) cycle
493 call unique_val_list%append(sval)
494
495 endif
496
497 enddo
498 enddo
499
500 end subroutine get_unique_int
501
502 !------------------------------------------------------------------------------
503
505
506 class(swbstats_t), intent(inout) :: this
507
508 ! [ LOCALS ]
509 integer (c_int) :: indx
510 type (DATE_RANGE_T) :: ANN_DT
511
512 indx = 0
513
514 call ann_dt%initialize( this%data_start_date, this%data_end_date )
515
516 do
517 indx = indx + 1
518 call this%start_date_list%append( ann_dt%curr%prettydate() )
519 call ann_dt%advance_to_last_doy()
520 call this%date_range_id_list%append( ascharacter(indx) )
521 if ( ann_dt%curr < ann_dt%end ) then
522 call this%end_date_list%append( ann_dt%curr%prettydate() )
523 call ann_dt%addDay()
524 else
525 call this%end_date_list%append( ann_dt%end%prettydate() )
526 exit
527 endif
528 enddo
529
531
532 !------------------------------------------------------------------------------
533
535
536 class(swbstats_t), intent(inout) :: this
537
538 ! [ LOCALS ]
539 integer (c_int) :: indx
540 type (DATE_RANGE_T) :: MON_DT
541
542 indx = 0
543
544 call mon_dt%initialize( this%data_start_date, this%data_end_date )
545
546 do
547 indx = indx + 1
548 call this%start_date_list%append( mon_dt%curr%prettydate() )
549 call mon_dt%advance_to_last_day_of_month()
550 call this%date_range_id_list%append( ascharacter(indx) )
551 if ( mon_dt%curr < mon_dt%end ) then
552 call this%end_date_list%append( mon_dt%curr%prettydate() )
553 call mon_dt%addDay()
554 else
555 call this%end_date_list%append( mon_dt%end%prettydate() )
556 exit
557 endif
558 enddo
559
561
562!------------------------------------------------------------------------------
563
565
566 class(swbstats_t), intent(inout) :: this
567
568 ! [ LOCALS ]
569 integer (c_int) :: indx
570 type (DATE_RANGE_T) :: DAILY_DT
571
572 indx = 0
573
574 call daily_dt%initialize( this%data_start_date, this%data_end_date )
575
576 do
577 indx = indx + 1
578 call this%start_date_list%append( daily_dt%curr%prettydate() )
579 call this%end_date_list%append( daily_dt%curr%prettydate() )
580 call this%date_range_id_list%append( ascharacter(indx) )
581
582 if ( daily_dt%curr < daily_dt%end ) then
583 call daily_dt%addDay()
584 else
585 exit
586 endif
587 enddo
588
590
591!------------------------------------------------------------------------------
592
593 subroutine create_date_list_for_period_statistics(this, start_date, end_date)
594
595 class(swbstats_t), intent(inout) :: this
596 type (DATETIME_T), intent(in) :: start_date
597 type (DATETIME_T), intent(in) :: end_date
598
599 call this%start_date_list%append( start_date%prettydate() )
600 call this%date_range_id_list%append( "1" )
601 call this%end_date_list%append( end_date%prettydate() )
602
604
605!------------------------------------------------------------------------------
606
607 subroutine initialize_zone_grid(this, grid_filename)
608
609 class(swbstats_t), intent(inout) :: this
610 character (len=*), intent(inout) :: grid_filename
611
612 ! [ LOCALS ]
613 integer (c_int) :: iIndex
614 integer (c_int) :: iStat
615 character (len=:), allocatable :: description_str
616 character (len=:), allocatable :: OUTPUT_FILESname_str
617 character (len=256), save :: previous_zone_filename
618
619 ! OK, if this is the same ARC ASCII grid file processed in a previous iteration,
620 ! we leave the values as they are and skip reading in the grid again
621 if ( .not. trim(previous_zone_filename)==trim(grid_filename) ) then
622
623 ! remove file extension and path from zone filename
624 description_str = left( grid_filename, substring=".")
625 if (description_str .contains. "/") description_str = right( description_str, substring="/")
626 if (description_str .contains. "\") description_str = right( description_str, substring="\")
627
628 output_filesname_str = "zone_grid__"//trim(description_str)//"__as_read_into_SWBSTATS2.asc"
629
630 ! allocate memory for a generic data_catalog_entry
631 if (associated(this%grd_zone)) deallocate(this%grd_zone)
632 nullify(this%grd_zone)
633 allocate(this%grd_zone)
634
635 call this%grd_zone%set_target_PROJ4(this%target_proj4_string)
636 call this%grd_zone%initialize( &
637 sdescription="Zone Grid", &
638 sfiletype="ARC_GRID", &
639 sfilename=trim(grid_filename), &
640 idatatype=datatype_int )
641
642 call this%grd_zone%getvalues()
643
644! where ( this%grd_native%dpData <= NC_FILL_FLOAT )
645! this%grd_zone%pGrdBase%iData = NC_FILL_INT
646! end where
647
648 call grid_writearcgrid(output_filesname_str, this%grd_zone%pGrdBase )
649
650 ! set value of previous filename to the name of the grid we just processed.
651 previous_zone_filename = trim(grid_filename)
652
653 call this%unique_zone_list%clear()
654 call this%get_unique_int(this%grd_zone%pGrdBase%iData, this%unique_zone_list)
655
656 endif
657
658 end subroutine initialize_zone_grid
659
660!------------------------------------------------------------------------------
661
662 subroutine initialize_secondary_zone_grid(this, grid_filename)
663
664 class(swbstats_t), intent(inout) :: this
665 character (len=*), intent(inout) :: grid_filename
666
667 ! [ LOCALS ]
668 integer (c_int) :: iIndex
669 integer (c_int) :: iStat
670 character (len=:), allocatable :: description_str
671 character (len=:), allocatable :: OUTPUT_FILESname_str
672 character (len=256), save :: previous_zone_filename
673
674 ! OK, if this is the same ARC ASCII grid file processed in a previous iteration,
675 ! we leave the values as they are and skip reading in the grid again
676 if ( .not. trim(previous_zone_filename)==trim(grid_filename) ) then
677
678 description_str = left( grid_filename, substring=".")
679 if (description_str .contains. "/") description_str = right( description_str, substring="/")
680 if (description_str .contains. "\") description_str = right( description_str, substring="\")
681
682 output_filesname_str = "zone_grid2__"//trim(description_str)//"__as_read_into_SWBSTATS2.asc"
683
684 ! allocate memory for a generic data_catalog_entry
685 if (associated(this%grd_zone2)) deallocate(this%grd_zone2)
686 nullify(this%grd_zone2)
687 allocate(this%grd_zone2)
688
689 call this%grd_zone2%set_target_PROJ4(this%target_proj4_string)
690 call this%grd_zone2%initialize( &
691 sdescription="Zone Grid", &
692 sfiletype="ARC_GRID", &
693 sfilename=trim(grid_filename), &
694 idatatype=datatype_int )
695
696 call this%grd_zone2%getvalues()
697
698! where ( this%grd_native%dpData <= NC_FILL_FLOAT )
699! this%grd_zone2%pGrdBase%iData = NC_FILL_INT
700! end where
701
702 call grid_writearcgrid(output_filesname_str, this%grd_zone2%pGrdBase )
703
704 previous_zone_filename = trim(grid_filename)
705
706 endif
707
708 end subroutine initialize_secondary_zone_grid
709
710 !------------------------------------------------------------------------------
711
712 subroutine initialize_comparison_grid( this, grid_filename )
713
714 class(swbstats_t), intent(inout) :: this
715 character (len=*), intent(inout) :: grid_filename
716
717 ! [ LOCALS ]
718 integer (c_int) :: iIndex
719 integer (c_int) :: iStat
720 character (len=:), allocatable :: description_str
721 character (len=:), allocatable :: OUTPUT_FILESname_str
722 character (len=256), save :: previous_comparison_filename
723
724 ! OK, if this is the same ARC ASCII grid file processed in a previous iteration,
725 ! we leave the values as they are and skip reading in the grid again
726 if ( .not. trim(previous_comparison_filename)==trim(grid_filename) ) then
727
728 description_str = left( grid_filename, substring=".")
729 if (description_str .contains. "/") description_str = right( description_str, substring="/")
730 if (description_str .contains. "\") description_str = right( description_str, substring="\")
731
732 output_filesname_str = "Comparison_grid__"//trim(description_str)//"__as_read_into_SWBSTATS2.asc"
733
734 ! allocate memory for a generic data_catalog_entry
735 if (.not. associated(this%grd_comparison)) allocate(this%grd_comparison, stat=istat)
736
737 call this%grd_comparison%set_target_PROJ4(this%target_proj4_string)
738
739 call this%grd_comparison%initialize( &
740 sdescription="Comparison Grid", &
741 sfiletype="ARC_GRID", &
742 sfilename=trim(grid_filename), &
743 idatatype=datatype_float )
744
745 call this%grd_comparison%getvalues()
746
747! where ( this%grd_native%dpData <= NC_FILL_FLOAT )
748! this%grd_comparison%pGrdBase%dpData = NC_FILL_FLOAT
749! elsewhere
750 this%grd_comparison%pGrdBase%dpData = this%grd_comparison%pGrdBase%dpData &
751 * this%comparison_grid_conversion_factor
752! end where
753
754 call grid_writearcgrid(output_filesname_str, this%grd_comparison%pGrdBase )
755
756 previous_comparison_filename = trim(grid_filename)
757
758 endif
759
760 end subroutine initialize_comparison_grid
761
763
764 class(swbstats_t), intent(inout) :: this
765
766 if (this%report_as_volume) then
767 if (this%target_proj4_string .containssimilar. "units=m") then
768 this%length_conversion_factor = 1.0_c_double
769 elseif (this%target_proj4_string .containssimilar. "units=us-ft") then
770 this%length_conversion_factor = 0.3048006096012192_c_double
771 elseif (this%target_proj4_string .containssimilar. "units=ft") then
772 this%length_conversion_factor = 0.3048_c_double
773 else
774 call die("Was attempting to define length conversion factor, but no units " &
775 //"information found in input PROJ4 string.")
776 endif
777 this%grid_cell_area_sq_meters = (this%grd_native%rGridCellSize &
778 * this%length_conversion_factor)**2
779 this%output_conversion_factor = this%grid_cell_area_sq_meters &
780 * this%unit_conversion_factor
781 else
782 this%output_conversion_factor = this%unit_conversion_factor
783 endif
784
785 this%filename_modifier_string = trim(this%filename_modifier_string) &
786 //"__cubic_meters"
787
788 end subroutine set_conversion_factors_sub
789
790
791 subroutine write_stats_to_netcdf( this, &
792 OUTPUT_FILES, &
793 start_date, &
794 end_date )
795
796 class(swbstats_t), intent(inout) :: this
797 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
798 type (DATETIME_T), intent(inout) :: start_date
799 type (DATETIME_T), intent(inout) :: end_date
800
801 ! [ LOCALS ]
802 real (c_double) :: start_bnd
803 real (c_double) :: end_bnd
804 integer (c_size_t) :: nx, ny
805 type (T_NETCDF4_FILE), pointer :: ncfile_out
806 type (GENERAL_GRID_T), pointer :: grid_ptr
807 integer (c_int) :: stat_indx
808
809 nx = bnds%iNumCols
810 ny = bnds%iNumRows
811
812 start_bnd = sim_dt%days_from_origin( start_date )
813 end_bnd = sim_dt%days_from_origin( end_date )
814
815 do stat_indx=stats_mean, stats_variance
816
817 if ( .not. output_files(stat_indx)%output_active ) cycle
818
819 if ( output_files(stat_indx)%write_netcdf ) then
820
821 ncfile_out => output_files(stat_indx)%nc_ptr
822 grid_ptr => output_files(stat_indx)%grid_ptr
823
824 call netcdf_put_variable_vector(ncfile=ncfile_out, &
825 ivarid=ncfile_out%iVarID(nc_time), &
826 istart=[ recnum ], &
827 icount=[1_c_size_t], &
828 istride=[1_c_size_t], &
829! rValues=[ real(( start_bnd + end_bnd ) / 2.0_c_float, c_float) ] )
830 rvalues=[ real(start_bnd, c_float) ] )
831
832 ! dpValues=[ real( SIM_DT%iNumDaysFromOrigin, c_double) ] )
833
834 ! call netcdf_put_variable_vector(NCFILE=ncfile_out, &
835 ! iVarID=TIME_BNDS_VARID, &
836 ! iStart=[ RECNUM ,0_c_size_t], &
837 ! iCount=[1_c_size_t,2_c_size_t], &
838 ! iStride=[1_c_size_t, 1_c_size_t], &
839 ! dpValues=[ start_bnd, end_bnd ] )
840
841 call netcdf_put_variable_array(ncfile=ncfile_out, &
842 ivarid=ncfile_out%iVarID(nc_z), &
843 istart=[ recnum , 0_c_size_t, 0_c_size_t], &
844 icount=[ 1_c_size_t, ny, nx ], &
845 istride=[1_c_size_t, 1_c_size_t, 1_c_size_t], &
846 rvalues=real(grid_ptr%dpData, c_float) )
847
848 output_files(stat_indx)%valid_min = &
849 update_minimum_value(output_files(stat_indx)%valid_min, real(grid_ptr%dpData, c_float))
850
851 output_files(stat_indx)%valid_max = &
852 update_maximum_value(output_files(stat_indx)%valid_max, real(grid_ptr%dpData, c_float))
853
854 endif
855
856 enddo
857
858 end subroutine write_stats_to_netcdf
859
860!------------------------------------------------------------------------------
861
862 subroutine write_monthly_stats_to_arcgrid( this, OUTPUT_FILES, &
863 date_range_string, &
864 output_file_prefix )
865
866 class(swbstats_t), intent(inout) :: this
867 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
868 character (len=*), intent(in), optional :: date_range_string
869 character (len=*), intent(in), optional :: output_file_prefix
870
871 ! [ LOCALS ]
872 character (len=:), allocatable :: filename
873 integer (c_int) :: nx, ny
874 type (GENERAL_GRID_T), pointer :: grid_ptr
875 character (len=8) :: stats_description
876 character (len=:), allocatable :: units_string
877 character (len=:), allocatable :: filename_modifier
878 character (len=:), allocatable :: file_prefix
879
880 integer (c_int) :: sum_index_num
881 integer (c_int) :: mean_index_num
882 integer (c_int) :: variance_index_num
883 character (len=3) :: month_name
884 integer (c_int) :: month_num
885
886 nx = bnds%iNumCols
887 ny = bnds%iNumRows
888
889 do month_num=1,12
890
891 ! extract month name from the datetime module MONTHS data structure
892 month_name = months(month_num)%sName
893 sum_index_num = ( month_num - 1 ) * 3 + 1
894 mean_index_num = ( month_num - 1 ) * 3 + 2
895 variance_index_num = ( month_num - 1 ) * 3 + 3
896
897 if ( output_files(mean_index_num)%write_arcgrid) then
898
899 if (this%report_as_volume) then
900 units_string = "cubic meters"
901 elseif (this%report_in_meters) then
902 units_string = "meters"
903 else
904 units_string = trim(this%netcdf_variable_units_string)
905 endif
906
907 call replace(units_string, ' ', '_' )
908
909 ! remove commas from filename modifier
910 filename_modifier = clean(units_string, ",")
911
912 ! ** preliminaries done; now begin to write out to Arc Grid files
913
914
915 ! write out MEAN values grid
916 grid_ptr => output_files(mean_index_num)%grid_ptr
917 call assert(associated(grid_ptr), "Unallocated array", __file__, __line__)
918 stats_description = output_files(mean_index_num)%stats_description
919
920 if ( present(output_file_prefix) ) then
921 file_prefix = output_file_prefix // "__" // "monthly_mean_over_all"
922 else
923 file_prefix = "monthly_mean_over_all"
924 endif
925
926 filename = trim(file_prefix) &
927 //"_"//trim(month_name) &
928 //"__"//trim(this%netcdf_variable_name_string) &
929 //"__"//trim(this%date_range_string) &
930 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
931 //"__"//trim(filename_modifier)//".asc"
932
933 call grid_writearcgrid( filename, grid_ptr )
934
935 !!! Now output the VARIANCE grid
936 grid_ptr => output_files(variance_index_num)%grid_ptr
937 call assert(associated(grid_ptr), "Unallocated array", __file__, __line__)
938 stats_description = output_files(variance_index_num)%stats_description
939
940 if ( present(output_file_prefix) ) then
941 file_prefix = output_file_prefix // "__" // "monthly_variance_over_all"
942 else
943 file_prefix = "monthly_variance_over_all"
944 endif
945
946 filename = trim(file_prefix) &
947 //"_"//trim(month_name) &
948 //"__"//trim(this%netcdf_variable_name_string) &
949 //"__"//trim(this%date_range_string) &
950 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
951 //"__"//trim(filename_modifier)//".asc"
952
953 call grid_writearcgrid( filename, grid_ptr )
954
955
956 endif
957
958 enddo
959
960 end subroutine write_monthly_stats_to_arcgrid
961
962
963!------------------------------------------------------------------------------
964
965 subroutine write_stats_to_arcgrid( this, OUTPUT_FILES, start_date, &
966 end_date, date_range_string, &
967 output_file_prefix )
968
969 class(swbstats_t), intent(inout) :: this
970 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
971 type (DATETIME_T), intent(inout) :: start_date
972 type (DATETIME_T), intent(inout) :: end_date
973 character (len=*), intent(in), optional :: date_range_string
974 character (len=:), allocatable, intent(in), optional :: output_file_prefix
975
976 ! [ LOCALS ]
977 character (len=:), allocatable :: filename
978 integer (c_int) :: nx, ny
979 type (GENERAL_GRID_T), pointer :: grid_ptr
980 integer (c_int) :: stat_indx
981 character (len=8) :: stats_description
982 character (len=:), allocatable :: units_string
983 character (len=:), allocatable :: filename_modifier
984 character (len=:), allocatable :: file_prefix
985
986 if ( present(output_file_prefix) ) then
987 if (allocated(output_file_prefix)) file_prefix = output_file_prefix // "__"
988 else
989 file_prefix = ""
990 endif
991
992 nx = bnds%iNumCols
993 ny = bnds%iNumRows
994
995 do stat_indx=stats_mean, stats_variance
996
997 if ( .not. output_files(stat_indx)%output_active ) cycle
998
999 if ( output_files(stat_indx)%write_arcgrid) then
1000
1001 if ( this%annualize_stats .and. stat_indx == stats_sum) then
1002 units_string = trim(this%netcdf_variable_units_string)//", per year"
1003 elseif (this%report_as_volume) then
1004 units_string = "cubic meters"
1005 elseif (this%report_in_meters) then
1006 units_string = "meters"
1007 else
1008 units_string = trim(this%netcdf_variable_units_string)
1009 endif
1010
1011 call replace(units_string, ' ', '_' )
1012
1013 ! remove commas from filename modifier
1014 filename_modifier = clean(units_string, ",")
1015
1016 grid_ptr => output_files(stat_indx)%grid_ptr
1017 stats_description = output_files(stat_indx)%stats_description
1018
1019 if ( present(date_range_string) ) then
1020 !@todo: change filename depending on the desired output statistic
1021 filename = output_file_prefix &
1022 //trim(this%netcdf_variable_name_string) &
1023 //"__"//trim(date_range_string) &
1024 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
1025 //"__"//trim(stats_description) &
1026 //"__"//trim(filename_modifier)//".asc"
1027 else
1028 filename = output_file_prefix &
1029 //trim(this%netcdf_variable_name_string) &
1030 //"__"//start_date%prettydate()//"_to_"//end_date%prettydate() &
1031 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
1032 //"__"//trim(filename_modifier)//".asc"
1033 endif
1034
1035 ! ugly hack to make the output match the default NODATA value
1036 where ( this%grd_native%dpData <= nc_fill_float )
1037 grid_ptr%dpData = -9999.
1038 end where
1039
1040 call grid_writearcgrid( filename, grid_ptr )
1041
1042 endif
1043
1044 enddo
1045
1046 end subroutine write_stats_to_arcgrid
1047
1048!------------------------------------------------------------------------------
1049
1050! subroutine calculate_slice_statistics( this, grid_delta, grid_delta2, start_date, end_date, grid_mask )
1051
1052! class (SWBSTATS_T), intent(inout) :: this
1053! type (GENERAL_GRID_T), pointer :: grid_delta
1054! type (GENERAL_GRID_T), pointer :: grid_delta2
1055! type (DATETIME_T), intent(inout) :: start_date
1056! type (DATETIME_T), intent(inout) :: end_date
1057! logical, optional :: grid_mask(:,:)
1058
1059! ! [ LOCALS ]
1060! integer (c_int) :: julian_day_number
1061! real (c_float), allocatable :: tempvals(:)
1062! integer (c_int) :: day_count
1063! logical (c_bool), allocatable :: local_mask(:,:)
1064! real (c_float), dimension(size(grid_delta%dpData,1), size(grid_delta%dpData,2)) :: rTemp
1065
1066! ! force slice dates to honor bounds of data dates
1067! if ( start_date < this%data_start_date ) start_date = this%data_start_date
1068! if ( end_date > this%data_end_date ) end_date = this%data_end_date
1069
1070! ! call SIM_DT%initialize( start_date, end_date )
1071
1072! associate( grd_sum => OUTPUT_FILES(STATS_SUM)%grid_ptr%dpData, &
1073! grd_mean => OUTPUT_FILES(STATS_MEAN)%grid_ptr%dpData, &
1074! grd_var => OUTPUT_FILES(STATS_VARIANCE)%grid_ptr%dpData, &
1075! delta => grid_delta%dpData, &
1076! delta2 => grid_delta2%dpData, &
1077! grd_new => this%grd_native%dpData )
1078
1079! allocate(local_mask(ubound(grd_sum,1),ubound(grd_sum,2)))
1080
1081! day_count = 0
1082
1083! ! SIM_DT is being used here simply because it provides a simple way to march through
1084! ! time on a day-by-day basis; need to ensure that the "current" day aligns with the
1085! ! desired start and end dates of the slice.
1086! if ( SIM_DT%curr > start_date ) then
1087! call SIM_DT%set_current_date(start_date)
1088! endif
1089
1090! do
1091
1092! if ( SIM_DT%curr < start_date ) then
1093! call SIM_DT%addDay()
1094! cycle
1095! endif
1096
1097! julian_day_number = int( SIM_DT%curr%dJulianDate, c_int)
1098
1099! ! keep track of number of days that are summed together so we can calculated a mean grid value later
1100! day_count = day_count + 1
1101
1102! if ( netcdf_update_time_starting_index(this%ncfile_in, julian_day_number ) ) then
1103! call netcdf_get_variable_slice(NCFILE=this%ncfile_in, rValues=rTemp )
1104! endif
1105
1106! ! volumetric_conversion_factor is 1.0 *unless* user has specifically
1107! ! asked for volumetric reporting or other unit conversions; in this case,
1108! ! the output_conversion_factor amounts to the cell area times the
1109! ! unit length, appropriately converted to cubic meters, or if output
1110! ! is requested in meters, the conversion factor is just 0.
1111! grd_new = real(rTemp, c_double) * this%output_conversion_factor
1112
1113! if (day_count == 1) then
1114
1115! if (present(grid_mask)) then
1116! local_mask = (grd_new > NC_FILL_FLOAT) .and. grid_mask
1117! else
1118! local_mask = grd_new > NC_FILL_FLOAT
1119! endif
1120
1121! grd_sum = 0.0_c_double
1122! grd_mean = 0.0_c_double
1123! grd_var = 0.0_c_double
1124
1125! endif
1126
1127! where ( local_mask )
1128! delta = grd_new - grd_mean
1129! grd_sum = grd_sum + grd_new
1130! grd_mean = grd_mean + delta / real( day_count, c_double )
1131! delta2 = grd_new - grd_mean
1132! grd_var = grd_var + delta * delta2
1133! end where
1134
1135! ! write(*,fmt="(a,f14.3,f14.3)") "gridsum: ", minval(grd_sum, mask=grd_new > NC_FILL_FLOAT), &
1136! ! maxval(grd_sum, mask=grd_new > NC_FILL_FLOAT)
1137! !
1138! ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(grd_new, mask=grd_new > NC_FILL_FLOAT), &
1139! ! maxval(grd_new, mask=grd_new > NC_FILL_FLOAT)
1140! !
1141! ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT), &
1142! ! maxval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT)
1143
1144! call SIM_DT%addDay
1145! if ( SIM_DT%curr > end_date ) exit
1146
1147! end do
1148
1149! where ( .not. local_mask )
1150! grd_mean = NC_FILL_FLOAT
1151! grd_sum = NC_FILL_FLOAT
1152! grd_var = NC_FILL_FLOAT
1153! ! elsewhere
1154! ! grd_var = grd_var / (counter - 1)
1155! endwhere
1156
1157! if (this%annualize_stats) then
1158! where ( local_mask )
1159! ! grd_mean = grd_mean/ real( day_count, c_float ) * 365.25
1160! ! grd_var = grd_var/ real( day_count, c_float ) * 365.25
1161! grd_sum = grd_sum / real( day_count, c_double ) * 365.25
1162! end where
1163! ! else
1164! ! where ( local_mask )
1165! ! grd_mean = grd_sum / real( day_count, c_float )
1166! ! end where
1167! endif
1168
1169! deallocate(local_mask)
1170
1171! end associate
1172
1173! ! write(*,fmt="(a)") "gridsum: ", minval(grid_sum%rData, mask=this%grd_native%rData > NC_FILL_FLOAT), &
1174! ! maxval(grid_sum%rData, mask=this%grd_native%rData > NC_FILL_FLOAT)
1175
1176! end subroutine calculate_slice_statistics
1177
1178 subroutine calculate_slice_statistics( this, start_date, end_date, grd_sum, grd_mean, grd_var )
1179
1180 class(swbstats_t), intent(inout) :: this
1181 type (DATETIME_T), intent(inout) :: start_date
1182 type (DATETIME_T), intent(inout) :: end_date
1183 real (c_double), intent(inout) :: grd_sum(:,:)
1184 real (c_double), intent(inout) :: grd_mean(:,:)
1185 real (c_double), intent(inout) :: grd_var(:,:)
1186
1187 ! [ LOCALS ]
1188 integer (c_int) :: julian_day_number
1189 integer (c_int) :: day_count
1190 logical (c_bool), allocatable :: local_mask(:,:)
1191 real (c_float), allocatable :: rTemp(:,:)
1192 real (c_double), allocatable :: grd_new(:,:)
1193
1194 ! force slice dates to honor bounds of data dates
1195 if ( start_date < this%data_start_date ) start_date = this%data_start_date
1196 if ( end_date > this%data_end_date ) end_date = this%data_end_date
1197
1198 allocate(local_mask(this%ncfile_in%iNX,this%ncfile_in%iNY))
1199 allocate(rtemp(this%ncfile_in%iNX,this%ncfile_in%iNY))
1200 allocate(grd_new(this%ncfile_in%iNX,this%ncfile_in%iNY))
1201
1202 day_count = 0
1203
1204 ! call RSTAT%initialize(NX=this%ncfile_in%iNX, &
1205 ! NY=this%ncfile_in%iNY, &
1206 ! X0=this%ncfile_in%rX(NC_LEFT), &
1207 ! Y0=this%ncfile_in%rY(NC_BOTTOM), &
1208 ! X1=this%ncfile_in%rX(NC_RIGHT), &
1209 ! Y1=this%ncfile_in%rY(NC_TOP), &
1210 ! nodata_value=-9999._c_double)
1211
1212 call rstat%clear()
1213
1214 ! SIM_DT is being used here simply because it provides a simple way to march through
1215 ! time on a day-by-day basis; need to ensure that the "current" day aligns with the
1216 ! desired start and end dates of the slice.
1217 if ( sim_dt%curr > start_date ) then
1218 call sim_dt%set_current_date(start_date)
1219 endif
1220
1221 do
1222
1223 if ( sim_dt%curr < start_date ) then
1224 call sim_dt%addDay()
1225 cycle
1226 endif
1227
1228 julian_day_number = int( sim_dt%curr%dJulianDate, c_int)
1229
1230 ! keep track of number of days that are summed together so we can calculated a mean grid value later
1231 day_count = day_count + 1
1232
1233 if ( netcdf_update_time_starting_index(this%ncfile_in, julian_day_number ) ) then
1234 call netcdf_get_variable_slice(ncfile=this%ncfile_in, rvalues=rtemp )
1235 endif
1236
1237 ! volumetric_conversion_factor is 1.0 *unless* user has specifically
1238 ! asked for volumetric reporting or other unit conversions; in this case,
1239 ! the output_conversion_factor amounts to the cell area times the
1240 ! unit length, appropriately converted to cubic meters, or if output
1241 ! is requested in meters, the conversion factor is just 0.
1242 grd_new = real(rtemp, c_double) * this%output_conversion_factor
1243
1244 if (day_count == 1) then
1245 local_mask = grd_new > nc_fill_float
1246 endif
1247
1248 call rstat%push(grd_data=grd_new, mask=local_mask)
1249
1250
1251 ! write(*,fmt="(a,f14.3,f14.3)") "gridsum: ", minval(grd_sum, mask=grd_new > NC_FILL_FLOAT), &
1252 ! maxval(grd_sum, mask=grd_new > NC_FILL_FLOAT)
1253 !
1254 ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(grd_new, mask=grd_new > NC_FILL_FLOAT), &
1255 ! maxval(grd_new, mask=grd_new > NC_FILL_FLOAT)
1256 !
1257 ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT), &
1258 ! maxval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT)
1259
1260 call sim_dt%addDay
1261 if ( sim_dt%curr > end_date ) exit
1262
1263 end do
1264
1265 call rstat%mean(grd_mean)
1266 call rstat%sum(grd_sum)
1267 call rstat%variance(grd_var)
1268
1269 where ( .not. local_mask )
1270 grd_mean = nc_fill_float
1271 grd_sum = nc_fill_float
1272 grd_var = nc_fill_float
1273 ! elsewhere
1274 ! grd_var = grd_var / (counter - 1)
1275 end where
1276
1277 if (this%annualize_stats) then
1278 where ( local_mask )
1279! grd_mean = grd_mean/ real( day_count, c_float ) * 365.25
1280! grd_var = grd_var/ real( day_count, c_float ) * 365.25
1281 grd_sum = grd_sum / real( day_count, c_double ) * 365.25
1282 end where
1283 ! else
1284 ! where ( local_mask )
1285 ! grd_mean = grd_sum / real( day_count, c_float )
1286 ! end where
1287 endif
1288
1289 deallocate(local_mask)
1290 deallocate(grd_new)
1291 deallocate(rtemp)
1292
1293 end subroutine calculate_slice_statistics
1294
1295!------------------------------------------------------------------------------
1296
1297 ! ASSUMPTION: this routine will be called *AFTER* the slice statistics are calculated and
1298 ! ONLY when the monthly statistics flag has been set from command line
1299 subroutine calculate_monthly_statistics(this, month_num, finalize)
1300
1301 class(swbstats_t), intent(inout) :: this
1302 integer (c_short), intent(in) :: month_num
1303 logical (c_bool), intent(in) :: finalize
1304
1305 integer (c_int) :: sum_index_num
1306 integer (c_int) :: mean_index_num
1307 integer (c_int) :: variance_index_num
1308 character (len=3) :: month_name
1309 integer (c_int) :: month_index
1310
1311 if (.not. finalize) then
1312
1313 call mon_stat(month_num)%push(grd_data=output_files(stats_sum)%grid_ptr%dpData, &
1314 mask=logical(OUTPUT_FILES(STATS_SUM)%grid_ptr%dpData > -9999._c_double, c_bool))
1315
1316 else !finalize monthly outputs
1317
1318 do month_index=1,12
1319
1320 month_name = months(month_index)%sName
1321 sum_index_num = ( month_index - 1 ) * 3 + 1
1322 mean_index_num = ( month_index- 1 ) * 3 + 2
1323 variance_index_num = ( month_index- 1 ) * 3 + 3
1324
1325 call mon_stat(month_index)%mean(output_files(mean_index_num)%grid_ptr%dpData)
1326 call mon_stat(month_index)%sum(output_files(sum_index_num)%grid_ptr%dpData)
1327 call mon_stat(month_index)%variance(output_files(variance_index_num)%grid_ptr%dpData)
1328
1329 ! if ( OUTPUT_FILES(sum_index_num)%n_count > 0 ) then
1330
1331 ! where ( OUTPUT_FILES(sum_index_num)%grid_ptr%dpData > -9999. )
1332 ! OUTPUT_FILES(mean_index_num)%grid_ptr%dpData = OUTPUT_FILES(sum_index_num)%grid_ptr%dpData &
1333 ! / real(OUTPUT_FILES(sum_index_num)%n_count, kind=c_double)
1334 ! else where
1335
1336 ! OUTPUT_FILES(mean_index_num)%grid_ptr%dpData = -9999.
1337
1338 ! end where
1339
1340 ! else
1341
1342 ! OUTPUT_FILES(mean_index_num)%grid_ptr%dpData = -9999.
1343
1344 ! endif
1345
1346 ! write(*,fmt='(a,i0,1x,6(f0.4, 2x))') 'FINALIZING: ', month_index, &
1347 ! minval(OUTPUT_FILES(sum_index_num)%grid_ptr%dpData), &
1348 ! maxval(OUTPUT_FILES(sum_index_num)%grid_ptr%dpData), &
1349 ! minval(OUTPUT_FILES(mean_index_num)%grid_ptr%dpData), &
1350 ! maxval(OUTPUT_FILES(mean_index_num)%grid_ptr%dpData), &
1351 ! minval(OUTPUT_FILES(variance_index_num)%grid_ptr%dpData), &
1352 ! maxval(OUTPUT_FILES(variance_index_num)%grid_ptr%dpData)
1353
1354 enddo
1355
1356 endif
1357
1358 end subroutine calculate_monthly_statistics
1359!------------------------------------------------------------------------------
1360
1361 subroutine read_date_range_file( this, &
1362 csv_filename, &
1363 date_range_id_list, &
1364 start_date_list, &
1365 end_date_list )
1366
1367 class(swbstats_t), intent(inout) :: this
1368 character (len=*), intent(inout) :: csv_filename
1369 type (FSTRING_LIST_T), intent(out) :: date_range_id_list
1370 type (FSTRING_LIST_T), intent(out) :: start_date_list
1371 type (FSTRING_LIST_T), intent(out) :: end_date_list
1372
1373 ! [ LOCALS ]
1374 integer (c_int) :: iFileIndex, iColIndex
1375 integer (c_int) :: iStat
1376 type (ASCII_FILE_T) :: DF
1377 character (len=256) :: sRecord, sItem
1378
1379 ! open the file associated with current file index value
1380 call df%open(sfilename = csv_filename, &
1381 sdelimiters=",", &
1382 scommentchars = "%#!", &
1383 lhasheader=true )
1384
1385 ! read in and throw away header of file
1386 srecord = df%readLine()
1387
1388 ! now read in the remainder of the file
1389 do while ( .not. df%isEOF() )
1390
1391 ! read in next line of file
1392 srecord = df%readLine()
1393
1394 ! skip blank lines
1395 if ( len_trim(srecord) == 0 ) cycle
1396
1397 call chomp( srecord, sitem, delimiter_chr="," )
1398 call this%date_range_id_list%append( sitem )
1399
1400 call chomp( srecord, sitem, delimiter_chr="," )
1401 call this%start_date_list%append( sitem )
1402 call this%end_date_list%append( srecord )
1403
1404 enddo
1405
1406 call df%close()
1407
1408 end subroutine read_date_range_file
1409
1410
1411!------------------------------------------------------------------------------
1412
1414 csv_filename, &
1415 date_range_id_list, &
1416 start_date_list, &
1417 end_date_list, &
1418 comparison_grid_file_list)
1419
1420 class(swbstats_t), intent(inout) :: this
1421 character (len=*), intent(inout) :: csv_filename
1422 type (FSTRING_LIST_T), intent(out) :: date_range_id_list
1423 type (FSTRING_LIST_T), intent(out) :: start_date_list
1424 type (FSTRING_LIST_T), intent(out) :: end_date_list
1425 type (FSTRING_LIST_T), intent(out) :: comparison_grid_file_list
1426
1427 ! [ LOCALS ]
1428 integer (c_int) :: iFileIndex, iColIndex
1429 integer (c_int) :: iStat
1430 type (ASCII_FILE_T) :: DF
1431 character (len=256) :: sRecord, sItem
1432
1433 ! open the file associated with current file index value
1434 call df%open(sfilename = csv_filename, &
1435 sdelimiters=",", &
1436 scommentchars = "%#!", &
1437 lhasheader=true )
1438
1439 ! read in and throw away header of file
1440 srecord = df%readLine()
1441
1442 ! now read in the remainder of the file
1443 do while ( .not. df%isEOF() )
1444
1445 ! read in next line of file
1446 srecord = df%readLine()
1447
1448 ! skip blank lines
1449 if ( len_trim(srecord) == 0 ) cycle
1450
1451 call chomp( srecord, sitem, delimiter_chr="," )
1452 call this%date_range_id_list%append( sitem )
1453
1454 call chomp( srecord, sitem, delimiter_chr="," )
1455 call this%start_date_list%append( sitem )
1456
1457 call chomp( srecord, sitem, delimiter_chr="," )
1458 call this%end_date_list%append( sitem )
1459
1460 call this%comparison_grid_file_list%append( srecord )
1461
1462 enddo
1463
1464 call df%close()
1465
1466 end subroutine read_comparison_period_file
1467
1468!------------------------------------------------------------------------------
1469
1470 subroutine read_zone_period_file( this, &
1471 csv_filename, &
1472 date_range_id_list, &
1473 start_date_list, &
1474 end_date_list, &
1475 zonal_stats_grid_file_list)
1476
1477 class(swbstats_t), intent(inout) :: this
1478 character (len=*), intent(inout) :: csv_filename
1479 type (FSTRING_LIST_T), intent(out) :: date_range_id_list
1480 type (FSTRING_LIST_T), intent(out) :: start_date_list
1481 type (FSTRING_LIST_T), intent(out) :: end_date_list
1482 type (FSTRING_LIST_T), intent(out) :: zonal_stats_grid_file_list
1483
1484 ! [ LOCALS ]
1485 integer (c_int) :: iFileIndex, iColIndex
1486 integer (c_int) :: iStat
1487 type (ASCII_FILE_T) :: DF
1488 character (len=256) :: sRecord, sItem
1489
1490 ! open the file associated with current file index value
1491 call df%open(sfilename = csv_filename, &
1492 sdelimiters=",", &
1493 scommentchars = "%#!", &
1494 lhasheader=true )
1495
1496 ! read in and throw away header of file
1497 srecord = df%readLine()
1498
1499 ! now read in the remainder of the file
1500 do while ( .not. df%isEOF() )
1501
1502 ! read in next line of file
1503 srecord = df%readLine()
1504
1505 ! skip blank lines
1506 if ( len_trim(srecord) == 0 ) cycle
1507
1508 call chomp( srecord, sitem, delimiter_chr="," )
1509 call this%date_range_id_list%append( sitem )
1510
1511 call chomp( srecord, sitem, delimiter_chr="," )
1512 call this%start_date_list%append( sitem )
1513
1514 call chomp( srecord, sitem, delimiter_chr="," )
1515 call this%end_date_list%append( sitem )
1516
1517 call this%zone_grid_file_list%append( srecord )
1518
1519 enddo
1520
1521 call df%close()
1522
1523 end subroutine read_zone_period_file
1524
1525!------------------------------------------------------------------------------
1526
1527 subroutine output_zonal_stats(this, &
1528 start_date, &
1529 end_date, &
1530 values, &
1531 zone_ids, &
1532 unique_zone_list, &
1533 delimiter, &
1534 funit, &
1535 zone2_ids, &
1536 unique_zone2_list, &
1537 comparison_values)
1538
1539 class(swbstats_t), intent(inout) :: this
1540 type (DATETIME_T), intent(in) :: start_date
1541 type (DATETIME_T), intent(in) :: end_date
1542 real (c_double), intent(inout) :: values(:,:)
1543 integer (c_int), intent(inout) :: zone_ids(:,:)
1544 type (FSTRING_LIST_T), intent(inout) :: unique_zone_list
1545 character (len=*), intent(in), optional :: delimiter
1546 integer (c_int), intent(in), optional :: funit
1547 integer (c_int), intent(inout), optional :: zone2_ids(:,:)
1548 type (FSTRING_LIST_T), intent(inout), optional :: unique_zone2_list
1549 real (c_double), intent(inout), optional :: comparison_values(:,:)
1550
1551 ! [ LOCALS ]
1552 integer (c_int) :: n, m
1553 integer (c_int) :: i, j
1554 integer (c_int), allocatable :: zone_values(:)
1555 integer (c_int), allocatable :: zone2_values(:)
1556 integer (c_int) :: number_of_matches
1557 real (c_double), allocatable :: stats(:)
1558 integer (c_int) :: funit_l
1559 character (len=:), allocatable :: delimiter_
1560 character (len=6), parameter :: NUM_FMT = "g25.16"
1561
1562 if (present(funit)) then
1563 funit_l = funit
1564 else
1565 funit_l = output_unit
1566 endif
1567
1568 if (present(delimiter) ) then
1569 delimiter_ = trim(delimiter)
1570 else
1571 delimiter_ = ","
1572 endif
1573
1574 if (present(zone2_ids) .and. present(unique_zone2_list)) then
1575
1576 ! sort the values before use
1577 call unique_zone_list%sort_integer()
1578 call unique_zone2_list%sort_integer()
1579
1580 ! obtain list of unique integers present in the zone grid
1581 zone_values = unique_zone_list%get_integer()
1582 zone2_values = unique_zone2_list%get_integer()
1583
1584 if (present(comparison_values)) then
1585
1586 do i=1,ubound(zone_values,1)
1587 do j=1,ubound(zone2_values,1)
1588 n = zone_values(i)
1589 m = zone2_values(j)
1590 call calc_multizonal_stats(values, zone_ids, target_id=n, target2_id=m, &
1591 result_vector=stats, &
1592 zone2_ids=zone2_ids, &
1593 comparison_values=comparison_values)
1594
1595 write(unit=funit_l, fmt="(2(a,a),2(i0,a),4("//num_fmt//",a),i0,a,4("//num_fmt//",a),i0)") &
1596 start_date%prettydate(),delimiter_, &
1597 end_date%prettydate(), delimiter_, &
1598 n, delimiter_, m, delimiter_, &
1599 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1600 stats(4), delimiter_, int(stats(5)), delimiter_, &
1601 stats(6), delimiter_, stats(7), delimiter_, stats(8), delimiter_, &
1602 stats(9), delimiter_, int(stats(10))
1603
1604 enddo
1605 enddo
1606
1607 else
1608
1609 do i=1,ubound(zone_values,1)
1610 do j=1,ubound(zone2_values,1)
1611 n = zone_values(i)
1612 m = zone2_values(j)
1613
1614 call calc_multizonal_stats(values, zone_ids, target_id=n, target2_id=m, &
1615 result_vector=stats, zone2_ids=zone2_ids)
1616
1617 write(unit=funit_l, fmt="(2(a,a),2(i0,a),4("//num_fmt//",a),i0)") &
1618 start_date%prettydate(), delimiter_, &
1619 end_date%prettydate(), delimiter_, &
1620 n, delimiter_, m, delimiter_, &
1621 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1622 stats(4), delimiter_, int(stats(5))
1623 enddo
1624 enddo
1625
1626 endif
1627
1628 else
1629 ! obtain list of unique integers present in the zone grid
1630 zone_values = unique_zone_list%get_integer()
1631
1632 if (present(comparison_values)) then
1633
1634 do i=1,ubound(zone_values,1)
1635 n = zone_values(i)
1636
1637 call calc_zonal_stats(values, zone_ids, target_id=n, result_vector=stats, &
1638 comparison_values=comparison_values)
1639 write(unit=funit_l, fmt="(2(a,a),i0,a,4("//num_fmt//",a),i0,a,4("//num_fmt//",a),i0)") &
1640 start_date%prettydate(), delimiter_, &
1641 end_date%prettydate(), delimiter_, &
1642 n, delimiter_, &
1643 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1644 stats(4), delimiter_, int(stats(5)), delimiter_, &
1645 stats(6), delimiter_, stats(7), delimiter_, stats(8), delimiter_, &
1646 stats(9), delimiter_, int(stats(10))
1647
1648 enddo
1649
1650 else
1651
1652 do i=1,ubound(zone_values,1)
1653 n = zone_values(i)
1654
1655 call calc_zonal_stats(values, zone_ids, target_id=n, result_vector=stats)
1656 write(unit=funit_l, fmt="(2(a,a),i0,a,4("//num_fmt//",a),i0)") &
1657 start_date%prettydate(), delimiter_, &
1658 end_date%prettydate(), delimiter_, &
1659 n, delimiter_, &
1660 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1661 stats(4), delimiter_, int(stats(5))
1662 enddo
1663
1664 endif
1665
1666 endif
1667
1668 end subroutine output_zonal_stats
1669
1670!------------------------------------------------------------------------------
1671
1672 subroutine open_output_netcdf_files(this, &
1673 OUTPUT_FILES)
1674
1675 class(swbstats_t), intent(inout) :: this
1676 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
1677
1678 ! [ LOCALS ]
1679 integer (c_int) :: stat_indx
1680 integer (c_int) :: status
1681 type (T_NETCDF4_FILE), pointer :: ncfile_out
1682 character (len=:), allocatable :: units_string
1683 character (len=:), allocatable :: filename_prefix
1684
1685 if (allocated( this%output_file_prefix) ) then
1686 filename_prefix = this%output_file_prefix
1687 else
1688 filename_prefix = ""
1689 endif
1690
1691 do stat_indx=stats_mean, stats_variance
1692
1693 if ( .not. output_files(stat_indx)%output_active ) cycle
1694
1695 if (output_files(stat_indx)%write_netcdf) then
1696
1697 if ( this%annualize_stats .and. stat_indx == stats_sum) then
1698 units_string = trim(this%netcdf_variable_units_string)//", per year"
1699 elseif (this%report_as_volume) then
1700 units_string = "cubic meters"
1701 elseif (this%report_in_meters) then
1702 units_string = "meters"
1703 else
1704 units_string = trim(this%netcdf_variable_units_string)
1705 endif
1706
1707 allocate( output_files(stat_indx)%nc_ptr, stat=status)
1708 call assert( status==0, "Problem allocating netcdf file data structure.", &
1709 __file__, __line__)
1710 ncfile_out => output_files(stat_indx)%nc_ptr
1711
1713 ncfile=ncfile_out, &
1714 svariablename=trim(this%netcdf_variable_name_string), &
1715 svariableunits=units_string, &
1716 inx=this%ncfile_in%iNX, &
1717 iny=this%ncfile_in%iNY, &
1718 fx=this%ncfile_in%rX_Coords, &
1719 fy=this%ncfile_in%rY_Coords, &
1720 proj4_string=trim(this%target_proj4_string), &
1721 startdate=sim_dt%start, &
1722 enddate=sim_dt%end, &
1723 executable_name="SWBSTATS2", &
1724 filename_prefix=filename_prefix, &
1725 filename_modifier=this%filename_modifier_string &
1726 //"_"//output_files(stat_indx)%stats_description )
1727
1728 endif
1729
1730 enddo
1731
1732 end subroutine open_output_netcdf_files
1733
1734!------------------------------------------------------------------------------
1735
1736 subroutine close_output_netcdf_files(this, OUTPUT_FILES)
1737
1738 class(swbstats_t), intent(inout) :: this
1739 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
1740
1741 ! [ LOCALS ]
1742 integer (c_int) :: stat_indx
1743 integer (c_int) :: status
1744 type (T_NETCDF4_FILE), pointer :: ncfile_out
1745
1746 do stat_indx=stats_mean, stats_variance
1747
1748 if ( .not. output_files(stat_indx)%output_active ) cycle
1749
1750 if (output_files(stat_indx)%write_netcdf) then
1751
1752 call netcdf_rewrite_attribute( ncfile=output_files(stat_indx)%nc_ptr, &
1753 svariablename=trim(this%netcdf_variable_name_string), &
1754 sattributename='valid_min', &
1755 rattributevalue=[output_files(stat_indx)%valid_min])
1756
1757 call netcdf_rewrite_attribute( ncfile=output_files(stat_indx)%nc_ptr, &
1758 svariablename=trim(this%netcdf_variable_name_string), &
1759 sattributename='valid_max', &
1760 rattributevalue=[output_files(stat_indx)%valid_max])
1761
1762 call netcdf_rewrite_attribute( ncfile=output_files(stat_indx)%nc_ptr, &
1763 svariablename=trim(this%netcdf_variable_name_string), &
1764 sattributename='valid_range', &
1765 rattributevalue=[output_files(stat_indx)%valid_min, &
1766 output_files(stat_indx)%valid_max])
1767
1768 ncfile_out => output_files(stat_indx)%nc_ptr
1769 call netcdf_close_file(ncfile=ncfile_out)
1770
1771 endif
1772
1773 enddo
1774
1775 end subroutine close_output_netcdf_files
1776
1777!------------------------------------------------------------------------------
1778
1779 subroutine open_zonal_stats_output_file(this, filename, delimiter)
1780
1781 class(swbstats_t), intent(inout) :: this
1782 character (len=*) :: filename
1783 character (len=*), intent(in), optional :: delimiter
1784
1785 ! [ LOCALS ]
1786 character (len=256) :: header_str
1787 character (len=:), allocatable :: delimiter_
1788
1789 if (present(delimiter)) then
1790 delimiter_ = delimiter
1791 else
1792 delimiter_ = ","
1793 endif
1794
1795 call this%zonal_stats_output_file%open(filename)
1796
1797 if (len_trim(this%zone_grid2_filename) > 0) then
1798
1799 if (this%multiple_comparison_grids .or. this%compare_to_obs_values) then
1800 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1801 //delimiter_//"zone2_id"//delimiter_//"minimum_swb"//delimiter_ &
1802 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1803 //delimiter_//"count_swb"//delimiter_//"minimum_obs"//delimiter_ &
1804 //"maximum_obs"//delimiter_//"mean_obs"//delimiter_//"sum_obs" &
1805 //delimiter_//"count_obs"
1806 else
1807 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1808 //delimiter_//"zone2_id"//delimiter_//"minimum_swb"//delimiter_ &
1809 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1810 //delimiter_//"count_swb"
1811 endif
1812
1813 else
1814
1815 if (this%multiple_comparison_grids .or. this%compare_to_obs_values) then
1816
1817 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1818 //delimiter_//"minimum_swb"//delimiter_ &
1819 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1820 //delimiter_//"count_swb"//delimiter_//"minimum_obs"//delimiter_ &
1821 //"maximum_obs"//delimiter_//"mean_obs"//delimiter_//"sum_obs" &
1822 //delimiter_//"count_obs"
1823
1824 else
1825
1826 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1827 //delimiter_//"minimum_swb"//delimiter_ &
1828 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1829 //delimiter_//"count_swb"
1830
1831 endif
1832
1833 endif
1834
1835 call this%zonal_stats_output_file%writeLine(trim(header_str))
1836
1837 end subroutine open_zonal_stats_output_file
1838
1839!------------------------------------------------------------------------------
1840
1841 subroutine print_all_options(this)
1842
1843 class(swbstats_t) :: this
1844
1845 ! [ LOCALS ]
1846 character (len=:), allocatable :: fmt_string
1847
1848 write(*,fmt="(/,/,a)") " :: Dump of swbstats2 program this ::"
1849 write(*,fmt="(a,/)") repeat("-", 43)
1850
1851 fmt_string = "(a,t30,': ',l)"
1852 write(*,fmt=fmt_string) "write_csv", this%write_csv
1853 write(*,fmt=fmt_string) "write_netcdf (SUM)", output_files(stats_sum)%write_netcdf
1854 write(*,fmt=fmt_string) "write_netcdf (MEAN)", output_files(stats_mean)%write_netcdf
1855 write(*,fmt=fmt_string) "write_netcdf (VARIANCE)", output_files(stats_variance)%write_netcdf
1856 write(*,fmt=fmt_string) "write_arcgrid (SUM)", output_files(stats_sum)%write_arcgrid
1857 write(*,fmt=fmt_string) "write_arcgrid (MEAN)", output_files(stats_mean)%write_arcgrid
1858 write(*,fmt=fmt_string) "write_arcgrid (VARIANCE)", output_files(stats_variance)%write_arcgrid
1859 write(*,fmt=fmt_string) "output_active (SUM)", output_files(stats_sum)%output_active
1860 write(*,fmt=fmt_string) "output_active (MEAN)", output_files(stats_mean)%output_active
1861 write(*,fmt=fmt_string) "output_active (VARIANCE)", output_files(stats_variance)%output_active
1862
1863 fmt_string = "(a,t40,': ',l)"
1864 write(*,fmt=fmt_string) "grid pointer allocated? (SUM)", associated( output_files(stats_sum)%grid_ptr)
1865 write(*,fmt=fmt_string) "grid pointer allocated? (MEAN)", associated( output_files(stats_mean)%grid_ptr)
1866 write(*,fmt=fmt_string) "grid pointer allocated? (VARIANCE)", associated( output_files(stats_variance)%grid_ptr)
1867
1868 fmt_string = "(a,t30,': ',l)"
1869 write(*,fmt=fmt_string) "calc_zonal_stats", this%calc_zonal_stats
1870 write(*,fmt=fmt_string) "compare_to_obs_values", this%compare_to_obs_values
1871 write(*,fmt=fmt_string) "annualize_stats", this%annualize_stats
1872
1873 fmt_string = "(a,t30,': ',a)"
1874 write(*,fmt=fmt_string) "target_proj4_string", this%target_proj4_string
1875 write(*,fmt=fmt_string) "data_start_date", this%data_start_date%prettydate()
1876 write(*,fmt=fmt_string) "data_end_date", this%data_end_date%prettydate()
1877 write(*,fmt=fmt_string) "slice_start_date", this%slice_start_date%prettydate()
1878 write(*,fmt=fmt_string) "slice_end_date", this%slice_end_date%prettydate()
1879 !date_range_string
1880
1881 fmt_string = "(a,t30,': ',i0)"
1882 write(*,fmt=fmt_string) "input grid bounds, nx", bnds%iNumCols
1883 write(*,fmt=fmt_string) "input grid bounds, ny", bnds%iNumRows
1884
1885 fmt_string = "(a,t35,': ',f16.5)"
1886 write(*,fmt=fmt_string) "input grid bounds, X_ll", bnds%fX_ll
1887 write(*,fmt=fmt_string) "input grid bounds, Y_ll", bnds%fY_ll
1888 write(*,fmt=fmt_string) "input grid bounds, X_ur", bnds%fX_ur
1889 write(*,fmt=fmt_string) "input grid bounds, Y_ur", bnds%fY_ur
1890 write(*,fmt=fmt_string) "input grid bounds, grid-cell size", bnds%fGridCellSize
1891
1892 fmt_string = "(a,t30,': ',i0)"
1893 write(*,fmt=fmt_string) "calculation_time_period", this%calculation_time_period
1894
1895 fmt_string = "(a,t30,': ',a)"
1896 write(*,fmt=fmt_string) "stress_period_filename", this%stress_period_filename
1897 write(*,fmt=fmt_string) "comparison_period_filename", this%comparison_period_filename
1898 write(*,fmt=fmt_string) "zone_period_filename", this%zone_period_filename
1899 write(*,fmt=fmt_string) "comparison_grid_filename", this%comparison_grid_filename
1900 write(*,fmt=fmt_string) "zone_grid_filename", this%zone_grid_filename
1901 write(*,fmt=fmt_string) "netcdf_input_filename", this%netcdf_input_filename
1902 write(*,fmt=fmt_string) "netcdf_variable_name_string", this%netcdf_variable_name_string
1903 write(*,fmt=fmt_string) "netcdf_variable_units_string", this%netcdf_variable_units_string
1904
1905 fmt_string = "(a,t30,': ',l)"
1906 write(*,fmt=fmt_string) "netcdf_input_file_is_open : ", this%netcdf_input_file_is_open
1907 write(*,fmt=fmt_string) "multiple_zone_grids : ", this%multiple_zone_grids
1908 write(*,fmt=fmt_string) "multiple_comparison_grids : ", this%multiple_comparison_grids
1909 !comparison_grid_conversion_factor = 1.0_c_double
1910 fmt_string = "(/,a,/,'"//repeat("-",62)//"')"
1911 write(*,fmt=fmt_string) "Start date list"
1912 call this%start_date_list%print()
1913 write(*,fmt=fmt_string) "End date list"
1914 call this%end_date_list%print()
1915 write(*,fmt=fmt_string) "Date index list"
1916 call this%date_range_id_list%print()
1917 write(*,fmt=fmt_string) "Unique zone id list"
1918 call this%unique_zone_list%print()
1919 write(*,fmt=fmt_string) "Comparison grid file list"
1920 call this%comparison_grid_file_list%print()
1921 write(*,fmt=fmt_string) "Zone grid file list"
1922 call this%zone_grid_file_list%print()
1923
1924 end subroutine print_all_options
1925
1926!------------------------------------------------------------------------------
1927
1928 pure function update_minimum_value(current_minimum, values) result(new_minimum)
1929
1930 real (c_float), intent(in) :: current_minimum
1931 real (c_float), intent(in) :: values(:,:)
1932
1933 real (c_float) :: new_minimum
1934
1935 new_minimum = min(current_minimum, minval(values))
1936
1937 end function update_minimum_value
1938
1939!------------------------------------------------------------------------------
1940
1941 pure function update_maximum_value(current_maximum, values) result(new_maximum)
1942
1943 real (c_float), intent(in) :: current_maximum
1944 real (c_float), intent(in) :: values(:,:)
1945
1946 real (c_float) :: new_maximum
1947
1948 new_maximum = max(current_maximum, maxval(values))
1949
1950 end function update_maximum_value
1951
1952end module swbstats2_support
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public true
logical(c_bool), parameter, public false
integer(c_int), parameter datatype_float
integer(c_int), parameter datatype_int
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition datetime.F90:9
type(month_t), dimension(12), target, public months
Month information.
Definition datetime.F90:148
subroutine, public die(smessage, smodule, iline, shints, scalledby, icalledbyline)
Provides support for input and output of gridded ASCII data, as well as for creation and destruction ...
Definition grid.F90:8
real(c_float), parameter nc_fill_float
Definition grid.F90:34
subroutine, public grid_writearcgrid(sfilename, pgrd)
Definition grid.F90:1056
integer(c_int), parameter, public grid_datatype_double
Definition grid.F90:27
Provide support for use of netCDF files as input for time-varying, gridded meteorlogic data,...
integer(c_int), parameter, public nc_bottom
subroutine, public netcdf_open_and_prepare_as_output(ncfile, svariablename, svariableunits, inx, iny, fx, fy, startdate, enddate, proj4_string, history_list, executable_name, dplat, dplon, fvalidmin, fvalidmax, write_time_bounds, filename_prefix, filename_modifier)
integer(c_int), parameter, public nc_top
integer(c_int), parameter, public nc_right
subroutine, public netcdf_get_variable_slice(ncfile, rvalues, dpvalues, ivalues)
subroutine, public netcdf_close_file(ncfile)
integer(c_int), parameter, public nc_time
@TODO: implement a more flexible way of tracking variable IDs; presently the code can break if lat an...
integer(c_int), parameter, public nc_left
subroutine, public netcdf_put_variable_array(ncfile, ivarid, istart, icount, istride, ivalues, i2values, rvalues, dpvalues)
subroutine, public netcdf_put_variable_vector(ncfile, ivarid, istart, icount, istride, ivalues, i2values, rvalues, dpvalues)
logical(c_bool) function, public netcdf_update_time_starting_index(ncfile, ijulianday)
integer(c_int), parameter, public nc_z
subroutine, public netcdf_rewrite_attribute(ncfile, svariablename, sattributename, sattributevalue, iattributevalue, rattributevalue, dpattributevalue)
type(date_range_t), public sim_dt
subroutine initialize_zone_grid(this, grid_filename)
type(length_unit_t), dimension(3), parameter length_units
subroutine write_stats_to_netcdf(this, output_files, start_date, end_date)
subroutine create_date_list_for_monthly_statistics(this)
subroutine close_output_netcdf_files(this, output_files)
subroutine create_working_grids(this)
type(running_stats_t) rstat
integer(c_size_t) recnum
subroutine calculate_monthly_statistics(this, month_num, finalize)
type(data_catalog_entry_t) input_data_obj
subroutine write_monthly_stats_to_arcgrid(this, output_files, date_range_string, output_file_prefix)
type(file_collection_t), dimension(39) output_files
type(running_stats_t), dimension(12) mon_stat
subroutine print_all_options(this)
subroutine initialize_comparison_grid(this, grid_filename)
subroutine create_date_list_for_period_statistics(this, start_date, end_date)
subroutine create_date_list_for_annual_statistics(this)
subroutine create_monthly_working_grids(this)
subroutine read_zone_period_file(this, csv_filename, date_range_id_list, start_date_list, end_date_list, zonal_stats_grid_file_list)
subroutine create_date_list_for_daily_statistics(this)
subroutine get_unique_int(this, grid_values, unique_val_list)
subroutine open_output_netcdf_files(this, output_files)
subroutine output_zonal_stats(this, start_date, end_date, values, zone_ids, unique_zone_list, delimiter, funit, zone2_ids, unique_zone2_list, comparison_values)
subroutine write_stats_to_arcgrid(this, output_files, start_date, end_date, date_range_string, output_file_prefix)
type(volume_unit_t), dimension(3), parameter volume_units
subroutine calc_multizonal_stats(values, zone_ids, zone2_ids, target_id, target2_id, result_vector, comparison_values)
subroutine initialize_secondary_zone_grid(this, grid_filename)
subroutine set_conversion_factors_sub(this)
pure real(c_float) function update_maximum_value(current_maximum, values)
subroutine read_comparison_period_file(this, csv_filename, date_range_id_list, start_date_list, end_date_list, comparison_grid_file_list)
pure real(c_float) function update_minimum_value(current_minimum, values)
subroutine read_date_range_file(this, csv_filename, date_range_id_list, start_date_list, end_date_list)
subroutine calculate_slice_statistics(this, start_date, end_date, grd_sum, grd_mean, grd_var)
subroutine open_zonal_stats_output_file(this, filename, delimiter)
subroutine calc_zonal_stats(values, zone_ids, target_id, result_vector, comparison_values)