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(>), &
9 operator(<), months
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_comp = 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_comp = 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 character (len=:), allocatable :: description_str
614 character (len=:), allocatable :: OUTPUT_FILESname_str
615 character (len=256), save :: previous_zone_filename
616
617 ! OK, if this is the same ARC ASCII grid file processed in a previous iteration,
618 ! we leave the values as they are and skip reading in the grid again
619 if ( .not. trim(previous_zone_filename)==trim(grid_filename) ) then
620
621 ! remove file extension and path from zone filename
622 description_str = left( grid_filename, substring=".")
623 if (description_str .contains. "/") description_str = right( description_str, substring="/")
624 if (description_str .contains. "\") description_str = right( description_str, substring="\")
625
626 output_filesname_str = "zone_grid__"//trim(description_str)//"__as_read_into_SWBSTATS2.asc"
627
628 ! allocate memory for a generic data_catalog_entry
629 if (associated(this%grd_zone)) deallocate(this%grd_zone)
630 nullify(this%grd_zone)
631 allocate(this%grd_zone)
632
633 call this%grd_zone%set_target_PROJ4(this%target_proj4_string)
634 call this%grd_zone%initialize( &
635 sdescription="Zone Grid", &
636 sfiletype="ARC_GRID", &
637 sfilename=trim(grid_filename), &
638 idatatype=datatype_int )
639
640 call this%grd_zone%getvalues()
641
642! where ( this%grd_native%dpData <= NC_FILL_FLOAT )
643! this%grd_zone%pGrdBase%iData = NC_FILL_INT
644! end where
645
646 call grid_writearcgrid(output_filesname_str, this%grd_zone%pGrdBase )
647
648 ! set value of previous filename to the name of the grid we just processed.
649 previous_zone_filename = trim(grid_filename)
650
651 call this%unique_zone_list%clear()
652 call this%get_unique_int(this%grd_zone%pGrdBase%iData, this%unique_zone_list)
653
654 endif
655
656 end subroutine initialize_zone_grid
657
658!------------------------------------------------------------------------------
659
660 subroutine initialize_secondary_zone_grid(this, grid_filename)
661
662 class(swbstats_t), intent(inout) :: this
663 character (len=*), intent(inout) :: grid_filename
664
665 ! [ LOCALS ]
666 character (len=:), allocatable :: description_str
667 character (len=:), allocatable :: OUTPUT_FILESname_str
668 character (len=256), save :: previous_zone_filename
669
670 ! OK, if this is the same ARC ASCII grid file processed in a previous iteration,
671 ! we leave the values as they are and skip reading in the grid again
672 if ( .not. trim(previous_zone_filename)==trim(grid_filename) ) then
673
674 description_str = left( grid_filename, substring=".")
675 if (description_str .contains. "/") description_str = right( description_str, substring="/")
676 if (description_str .contains. "\") description_str = right( description_str, substring="\")
677
678 output_filesname_str = "zone_grid2__"//trim(description_str)//"__as_read_into_SWBSTATS2.asc"
679
680 ! allocate memory for a generic data_catalog_entry
681 if (associated(this%grd_zone2)) deallocate(this%grd_zone2)
682 nullify(this%grd_zone2)
683 allocate(this%grd_zone2)
684
685 call this%grd_zone2%set_target_PROJ4(this%target_proj4_string)
686 call this%grd_zone2%initialize( &
687 sdescription="Zone Grid", &
688 sfiletype="ARC_GRID", &
689 sfilename=trim(grid_filename), &
690 idatatype=datatype_int )
691
692 call this%grd_zone2%getvalues()
693
694! where ( this%grd_native%dpData <= NC_FILL_FLOAT )
695! this%grd_zone2%pGrdBase%iData = NC_FILL_INT
696! end where
697
698 call grid_writearcgrid(output_filesname_str, this%grd_zone2%pGrdBase )
699
700 previous_zone_filename = trim(grid_filename)
701
702 endif
703
704 end subroutine initialize_secondary_zone_grid
705
706 !------------------------------------------------------------------------------
707
708 subroutine initialize_comparison_grid( this, grid_filename )
709
710 class(swbstats_t), intent(inout) :: this
711 character (len=*), intent(inout) :: grid_filename
712
713 ! [ LOCALS ]
714 integer (c_int) :: iStat
715 character (len=:), allocatable :: description_str
716 character (len=:), allocatable :: OUTPUT_FILESname_str
717 character (len=256), save :: previous_comparison_filename
718
719 ! OK, if this is the same ARC ASCII grid file processed in a previous iteration,
720 ! we leave the values as they are and skip reading in the grid again
721 if ( .not. trim(previous_comparison_filename)==trim(grid_filename) ) then
722
723 description_str = left( grid_filename, substring=".")
724 if (description_str .contains. "/") description_str = right( description_str, substring="/")
725 if (description_str .contains. "\") description_str = right( description_str, substring="\")
726
727 output_filesname_str = "Comparison_grid__"//trim(description_str)//"__as_read_into_SWBSTATS2.asc"
728
729 ! allocate memory for a generic data_catalog_entry
730 if (.not. associated(this%grd_comparison)) allocate(this%grd_comparison, stat=istat)
731
732 call this%grd_comparison%set_target_PROJ4(this%target_proj4_string)
733
734 call this%grd_comparison%initialize( &
735 sdescription="Comparison Grid", &
736 sfiletype="ARC_GRID", &
737 sfilename=trim(grid_filename), &
738 idatatype=datatype_float )
739
740 call this%grd_comparison%getvalues()
741
742! where ( this%grd_native%dpData <= NC_FILL_FLOAT )
743! this%grd_comparison%pGrdBase%dpData = NC_FILL_FLOAT
744! elsewhere
745 this%grd_comparison%pGrdBase%dpData = this%grd_comparison%pGrdBase%dpData &
746 * this%comparison_grid_conversion_factor
747! end where
748
749 call grid_writearcgrid(output_filesname_str, this%grd_comparison%pGrdBase )
750
751 previous_comparison_filename = trim(grid_filename)
752
753 endif
754
755 end subroutine initialize_comparison_grid
756
758
759 class(swbstats_t), intent(inout) :: this
760
761 if (this%report_as_volume) then
762 if (this%target_proj4_string .containssimilar. "units=m") then
763 this%length_conversion_factor = 1.0_c_double
764 elseif (this%target_proj4_string .containssimilar. "units=us-ft") then
765 this%length_conversion_factor = 0.3048006096012192_c_double
766 elseif (this%target_proj4_string .containssimilar. "units=ft") then
767 this%length_conversion_factor = 0.3048_c_double
768 else
769 call die("Was attempting to define length conversion factor, but no units " &
770 //"information found in input PROJ4 string.")
771 endif
772 this%grid_cell_area_sq_meters = (this%grd_native%rGridCellSize &
773 * this%length_conversion_factor)**2
774 this%output_conversion_factor = this%grid_cell_area_sq_meters &
775 * this%unit_conversion_factor
776 else
777 this%output_conversion_factor = this%unit_conversion_factor
778 endif
779
780 this%filename_modifier_string = trim(this%filename_modifier_string) &
781 //"__cubic_meters"
782
783 end subroutine set_conversion_factors_sub
784
785
786 subroutine write_stats_to_netcdf( this, &
787 OUTPUT_FILES, &
788 start_date, &
789 end_date )
790
791 class(swbstats_t), intent(inout) :: this
792 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
793 type (DATETIME_T), intent(inout) :: start_date
794 type (DATETIME_T), intent(inout) :: end_date
795
796 ! [ LOCALS ]
797 real (c_double) :: start_bnd
798 real (c_double) :: end_bnd
799 integer (c_size_t) :: nx, ny
800 type (T_NETCDF4_FILE), pointer :: ncfile_out
801 type (GENERAL_GRID_T), pointer :: grid_ptr
802 integer (c_int) :: stat_indx
803
804 nx = bnds%iNumCols
805 ny = bnds%iNumRows
806
807 start_bnd = sim_dt%days_from_origin( start_date )
808 end_bnd = sim_dt%days_from_origin( end_date )
809
810 do stat_indx=stats_mean, stats_variance
811
812 if ( .not. output_files(stat_indx)%output_active ) cycle
813
814 if ( output_files(stat_indx)%write_netcdf ) then
815
816 ncfile_out => output_files(stat_indx)%nc_ptr
817 grid_ptr => output_files(stat_indx)%grid_ptr
818
819 call netcdf_put_variable_vector(ncfile=ncfile_out, &
820 ivarid=ncfile_out%iVarID(nc_time), &
821 istart=[ recnum ], &
822 icount=[1_c_size_t], &
823 istride=[1_c_size_t], &
824! rValues=[ real(( start_bnd + end_bnd ) / 2.0_c_float, c_float) ] )
825 rvalues=[ real(start_bnd, c_float) ] )
826
827 ! dpValues=[ real( SIM_DT%iNumDaysFromOrigin, c_double) ] )
828
829 ! call netcdf_put_variable_vector(NCFILE=ncfile_out, &
830 ! iVarID=TIME_BNDS_VARID, &
831 ! iStart=[ RECNUM ,0_c_size_t], &
832 ! iCount=[1_c_size_t,2_c_size_t], &
833 ! iStride=[1_c_size_t, 1_c_size_t], &
834 ! dpValues=[ start_bnd, end_bnd ] )
835
836 call netcdf_put_variable_array(ncfile=ncfile_out, &
837 ivarid=ncfile_out%iVarID(nc_z), &
838 istart=[ recnum , 0_c_size_t, 0_c_size_t], &
839 icount=[ 1_c_size_t, ny, nx ], &
840 istride=[1_c_size_t, 1_c_size_t, 1_c_size_t], &
841 rvalues=real(grid_ptr%dpData, c_float) )
842
843 output_files(stat_indx)%valid_min = &
844 update_minimum_value(output_files(stat_indx)%valid_min, real(grid_ptr%dpData, c_float))
845
846 output_files(stat_indx)%valid_max = &
847 update_maximum_value(output_files(stat_indx)%valid_max, real(grid_ptr%dpData, c_float))
848
849 endif
850
851 enddo
852
853 end subroutine write_stats_to_netcdf
854
855!------------------------------------------------------------------------------
856
857 subroutine write_monthly_stats_to_arcgrid( this, OUTPUT_FILES, &
858 date_range_string, &
859 output_file_prefix )
860
861 class(swbstats_t), intent(inout) :: this
862 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
863 character (len=*), intent(in), optional :: date_range_string
864 character (len=*), intent(in), optional :: output_file_prefix
865
866 ! [ LOCALS ]
867 character (len=:), allocatable :: filename
868 integer (c_int) :: nx, ny
869 type (GENERAL_GRID_T), pointer :: grid_ptr
870 character (len=8) :: stats_description
871 character (len=:), allocatable :: units_string
872 character (len=:), allocatable :: filename_modifier
873 character (len=:), allocatable :: file_prefix
874
875 integer (c_int) :: sum_index_num
876 integer (c_int) :: mean_index_num
877 integer (c_int) :: variance_index_num
878 character (len=3) :: month_name
879 integer (c_int) :: month_num
880
881 nx = bnds%iNumCols
882 ny = bnds%iNumRows
883
884 do month_num=1,12
885
886 ! extract month name from the datetime module MONTHS data structure
887 month_name = months(month_num)%sName
888 sum_index_num = ( month_num - 1 ) * 3 + 1
889 mean_index_num = ( month_num - 1 ) * 3 + 2
890 variance_index_num = ( month_num - 1 ) * 3 + 3
891
892 if ( output_files(mean_index_num)%write_arcgrid) then
893
894 if (this%report_as_volume) then
895 units_string = "cubic meters"
896 elseif (this%report_in_meters) then
897 units_string = "meters"
898 else
899 units_string = trim(this%netcdf_variable_units_string)
900 endif
901
902 call replace(units_string, ' ', '_' )
903
904 ! remove commas from filename modifier
905 filename_modifier = clean(units_string, ",")
906
907 ! ** preliminaries done; now begin to write out to Arc Grid files
908
909
910 ! write out MEAN values grid
911 grid_ptr => output_files(mean_index_num)%grid_ptr
912 call assert(associated(grid_ptr), "Unallocated array", __file__, __line__)
913 stats_description = output_files(mean_index_num)%stats_description
914
915 if ( present(output_file_prefix) ) then
916 file_prefix = output_file_prefix // "__" // "monthly_mean_over_all"
917 else
918 file_prefix = "monthly_mean_over_all"
919 endif
920
921 filename = trim(file_prefix) &
922 //"_"//trim(month_name) &
923 //"__"//trim(this%netcdf_variable_name_string) &
924 //"__"//trim(this%date_range_string) &
925 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
926 //"__"//trim(filename_modifier)//".asc"
927
928 call grid_writearcgrid( filename, grid_ptr )
929
930 !!! Now output the VARIANCE grid
931 grid_ptr => output_files(variance_index_num)%grid_ptr
932 call assert(associated(grid_ptr), "Unallocated array", __file__, __line__)
933 stats_description = output_files(variance_index_num)%stats_description
934
935 if ( present(output_file_prefix) ) then
936 file_prefix = output_file_prefix // "__" // "monthly_variance_over_all"
937 else
938 file_prefix = "monthly_variance_over_all"
939 endif
940
941 filename = trim(file_prefix) &
942 //"_"//trim(month_name) &
943 //"__"//trim(this%netcdf_variable_name_string) &
944 //"__"//trim(this%date_range_string) &
945 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
946 //"__"//trim(filename_modifier)//".asc"
947
948 call grid_writearcgrid( filename, grid_ptr )
949
950
951 endif
952
953 enddo
954
955 end subroutine write_monthly_stats_to_arcgrid
956
957
958!------------------------------------------------------------------------------
959
960 subroutine write_stats_to_arcgrid( this, OUTPUT_FILES, start_date, &
961 end_date, date_range_string, &
962 output_file_prefix )
963
964 class(swbstats_t), intent(inout) :: this
965 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
966 type (DATETIME_T), intent(inout) :: start_date
967 type (DATETIME_T), intent(inout) :: end_date
968 character (len=*), intent(in), optional :: date_range_string
969 character (len=:), allocatable, intent(in), optional :: output_file_prefix
970
971 ! [ LOCALS ]
972 character (len=:), allocatable :: filename
973 integer (c_int) :: nx, ny
974 type (GENERAL_GRID_T), pointer :: grid_ptr
975 integer (c_int) :: stat_indx
976 character (len=8) :: stats_description
977 character (len=:), allocatable :: units_string
978 character (len=:), allocatable :: filename_modifier
979 character (len=:), allocatable :: file_prefix
980
981 if ( present(output_file_prefix) ) then
982 if (allocated(output_file_prefix)) file_prefix = output_file_prefix // "__"
983 else
984 file_prefix = ""
985 endif
986
987 nx = bnds%iNumCols
988 ny = bnds%iNumRows
989
990 do stat_indx=stats_mean, stats_variance
991
992 if ( .not. output_files(stat_indx)%output_active ) cycle
993
994 if ( output_files(stat_indx)%write_arcgrid) then
995
996 if ( this%annualize_stats .and. stat_indx == stats_sum) then
997 units_string = trim(this%netcdf_variable_units_string)//", per year"
998 elseif (this%report_as_volume) then
999 units_string = "cubic meters"
1000 elseif (this%report_in_meters) then
1001 units_string = "meters"
1002 else
1003 units_string = trim(this%netcdf_variable_units_string)
1004 endif
1005
1006 call replace(units_string, ' ', '_' )
1007
1008 ! remove commas from filename modifier
1009 filename_modifier = clean(units_string, ",")
1010
1011 grid_ptr => output_files(stat_indx)%grid_ptr
1012 stats_description = output_files(stat_indx)%stats_description
1013
1014 if ( present(date_range_string) ) then
1015 !@todo: change filename depending on the desired output statistic
1016 filename = output_file_prefix &
1017 //trim(this%netcdf_variable_name_string) &
1018 //"__"//trim(date_range_string) &
1019 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
1020 //"__"//trim(stats_description) &
1021 //"__"//trim(filename_modifier)//".asc"
1022 else
1023 filename = output_file_prefix &
1024 //trim(this%netcdf_variable_name_string) &
1025 //"__"//start_date%prettydate()//"_to_"//end_date%prettydate() &
1026 //"__"//ascharacter(nx)//"_by_"//ascharacter(ny) &
1027 //"__"//trim(filename_modifier)//".asc"
1028 endif
1029
1030 ! ugly hack to make the output match the default NODATA value
1031 where ( this%grd_native%dpData <= nc_fill_float )
1032 grid_ptr%dpData = -9999.
1033 end where
1034
1035 call grid_writearcgrid( filename, grid_ptr )
1036
1037 endif
1038
1039 enddo
1040
1041 end subroutine write_stats_to_arcgrid
1042
1043!------------------------------------------------------------------------------
1044
1045! subroutine calculate_slice_statistics( this, grid_delta, grid_delta2, start_date, end_date, grid_mask )
1046
1047! class (SWBSTATS_T), intent(inout) :: this
1048! type (GENERAL_GRID_T), pointer :: grid_delta
1049! type (GENERAL_GRID_T), pointer :: grid_delta2
1050! type (DATETIME_T), intent(inout) :: start_date
1051! type (DATETIME_T), intent(inout) :: end_date
1052! logical, optional :: grid_mask(:,:)
1053
1054! ! [ LOCALS ]
1055! integer (c_int) :: julian_day_number
1056! real (c_float), allocatable :: tempvals(:)
1057! integer (c_int) :: day_count
1058! logical (c_bool), allocatable :: local_mask(:,:)
1059! real (c_float), dimension(size(grid_delta%dpData,1), size(grid_delta%dpData,2)) :: rTemp
1060
1061! ! force slice dates to honor bounds of data dates
1062! if ( start_date < this%data_start_date ) start_date = this%data_start_date
1063! if ( end_date > this%data_end_date ) end_date = this%data_end_date
1064
1065! ! call SIM_DT%initialize( start_date, end_date )
1066
1067! associate( grd_sum => OUTPUT_FILES(STATS_SUM)%grid_ptr%dpData, &
1068! grd_mean => OUTPUT_FILES(STATS_MEAN)%grid_ptr%dpData, &
1069! grd_var => OUTPUT_FILES(STATS_VARIANCE)%grid_ptr%dpData, &
1070! delta => grid_delta%dpData, &
1071! delta2 => grid_delta2%dpData, &
1072! grd_new => this%grd_native%dpData )
1073
1074! allocate(local_mask(ubound(grd_sum,1),ubound(grd_sum,2)))
1075
1076! day_count = 0
1077
1078! ! SIM_DT is being used here simply because it provides a simple way to march through
1079! ! time on a day-by-day basis; need to ensure that the "current" day aligns with the
1080! ! desired start and end dates of the slice.
1081! if ( SIM_DT%curr > start_date ) then
1082! call SIM_DT%set_current_date(start_date)
1083! endif
1084
1085! do
1086
1087! if ( SIM_DT%curr < start_date ) then
1088! call SIM_DT%addDay()
1089! cycle
1090! endif
1091
1092! julian_day_number = int( SIM_DT%curr%dJulianDate, c_int)
1093
1094! ! keep track of number of days that are summed together so we can calculated a mean grid value later
1095! day_count = day_count + 1
1096
1097! if ( netcdf_update_time_starting_index(this%ncfile_in, julian_day_number ) ) then
1098! call netcdf_get_variable_slice(NCFILE=this%ncfile_in, rValues=rTemp )
1099! endif
1100
1101! ! volumetric_conversion_factor is 1.0 *unless* user has specifically
1102! ! asked for volumetric reporting or other unit conversions; in this case,
1103! ! the output_conversion_factor amounts to the cell area times the
1104! ! unit length, appropriately converted to cubic meters, or if output
1105! ! is requested in meters, the conversion factor is just 0.
1106! grd_new = real(rTemp, c_double) * this%output_conversion_factor
1107
1108! if (day_count == 1) then
1109
1110! if (present(grid_mask)) then
1111! local_mask = (grd_new > NC_FILL_FLOAT) .and. grid_mask
1112! else
1113! local_mask = grd_new > NC_FILL_FLOAT
1114! endif
1115
1116! grd_sum = 0.0_c_double
1117! grd_mean = 0.0_c_double
1118! grd_var = 0.0_c_double
1119
1120! endif
1121
1122! where ( local_mask )
1123! delta = grd_new - grd_mean
1124! grd_sum = grd_sum + grd_new
1125! grd_mean = grd_mean + delta / real( day_count, c_double )
1126! delta2 = grd_new - grd_mean
1127! grd_var = grd_var + delta * delta2
1128! end where
1129
1130! ! write(*,fmt="(a,f14.3,f14.3)") "gridsum: ", minval(grd_sum, mask=grd_new > NC_FILL_FLOAT), &
1131! ! maxval(grd_sum, mask=grd_new > NC_FILL_FLOAT)
1132! !
1133! ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(grd_new, mask=grd_new > NC_FILL_FLOAT), &
1134! ! maxval(grd_new, mask=grd_new > NC_FILL_FLOAT)
1135! !
1136! ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", &
1137! ! minval(this%grd_native%dpData, &
1138! ! mask=this%grd_native%dpData > NC_FILL_FLOAT), &
1139! ! maxval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT)
1140
1141! call SIM_DT%addDay
1142! if ( SIM_DT%curr > end_date ) exit
1143
1144! end do
1145
1146! where ( .not. local_mask )
1147! grd_mean = NC_FILL_FLOAT
1148! grd_sum = NC_FILL_FLOAT
1149! grd_var = NC_FILL_FLOAT
1150! ! elsewhere
1151! ! grd_var = grd_var / (counter - 1)
1152! endwhere
1153
1154! if (this%annualize_stats) then
1155! where ( local_mask )
1156! ! grd_mean = grd_mean/ real( day_count, c_float ) * 365.25
1157! ! grd_var = grd_var/ real( day_count, c_float ) * 365.25
1158! grd_sum = grd_sum / real( day_count, c_double ) * 365.25
1159! end where
1160! ! else
1161! ! where ( local_mask )
1162! ! grd_mean = grd_sum / real( day_count, c_float )
1163! ! end where
1164! endif
1165
1166! deallocate(local_mask)
1167
1168! end associate
1169
1170! ! write(*,fmt="(a)") "gridsum: ", minval(grid_sum%rData, mask=this%grd_native%rData > NC_FILL_FLOAT), &
1171! ! maxval(grid_sum%rData, mask=this%grd_native%rData > NC_FILL_FLOAT)
1172
1173! end subroutine calculate_slice_statistics
1174
1175 subroutine calculate_slice_statistics( this, start_date, end_date, grd_sum, grd_mean, grd_var )
1176
1177 class(swbstats_t), intent(inout) :: this
1178 type (DATETIME_T), intent(inout) :: start_date
1179 type (DATETIME_T), intent(inout) :: end_date
1180 real (c_double), intent(inout) :: grd_sum(:,:)
1181 real (c_double), intent(inout) :: grd_mean(:,:)
1182 real (c_double), intent(inout) :: grd_var(:,:)
1183
1184 ! [ LOCALS ]
1185 integer (c_int) :: julian_day_number
1186 integer (c_int) :: day_count
1187 logical (c_bool), allocatable :: local_mask(:,:)
1188 real (c_float), allocatable :: rTemp(:,:)
1189 real (c_double), allocatable :: grd_new(:,:)
1190
1191 ! force slice dates to honor bounds of data dates
1192 if ( start_date < this%data_start_date ) start_date = this%data_start_date
1193 if ( end_date > this%data_end_date ) end_date = this%data_end_date
1194
1195 allocate(local_mask(this%ncfile_in%iNX,this%ncfile_in%iNY))
1196 allocate(rtemp(this%ncfile_in%iNX,this%ncfile_in%iNY))
1197 allocate(grd_new(this%ncfile_in%iNX,this%ncfile_in%iNY))
1198
1199 day_count = 0
1200
1201 ! call RSTAT%initialize(NX=this%ncfile_in%iNX, &
1202 ! NY=this%ncfile_in%iNY, &
1203 ! X0=this%ncfile_in%rX(NC_LEFT), &
1204 ! Y0=this%ncfile_in%rY(NC_BOTTOM), &
1205 ! X1=this%ncfile_in%rX(NC_RIGHT), &
1206 ! Y1=this%ncfile_in%rY(NC_TOP), &
1207 ! nodata_value=-9999._c_double)
1208
1209 call rstat%clear()
1210
1211 ! SIM_DT is being used here simply because it provides a simple way to march through
1212 ! time on a day-by-day basis; need to ensure that the "current" day aligns with the
1213 ! desired start and end dates of the slice.
1214 if ( sim_dt%curr > start_date ) then
1215 call sim_dt%set_current_date(start_date)
1216 endif
1217
1218 do
1219
1220 if ( sim_dt%curr < start_date ) then
1221 call sim_dt%addDay()
1222 cycle
1223 endif
1224
1225 julian_day_number = int( sim_dt%curr%dJulianDate, c_int)
1226
1227 ! keep track of number of days that are summed together so we can calculated a mean grid value later
1228 day_count = day_count + 1
1229
1230 if ( netcdf_update_time_starting_index(this%ncfile_in, julian_day_number ) ) then
1231 call netcdf_get_variable_slice(ncfile=this%ncfile_in, rvalues=rtemp )
1232 endif
1233
1234 ! volumetric_conversion_factor is 1.0 *unless* user has specifically
1235 ! asked for volumetric reporting or other unit conversions; in this case,
1236 ! the output_conversion_factor amounts to the cell area times the
1237 ! unit length, appropriately converted to cubic meters, or if output
1238 ! is requested in meters, the conversion factor is just 0.
1239 grd_new = real(rtemp, c_double) * this%output_conversion_factor
1240
1241 if (day_count == 1) then
1242 local_mask = grd_new > nc_fill_float
1243 endif
1244
1245 call rstat%push(grd_data=grd_new, mask=local_mask)
1246
1247
1248 ! write(*,fmt="(a,f14.3,f14.3)") "gridsum: ", minval(grd_sum, mask=grd_new > NC_FILL_FLOAT), &
1249 ! maxval(grd_sum, mask=grd_new > NC_FILL_FLOAT)
1250 !
1251 ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(grd_new, mask=grd_new > NC_FILL_FLOAT), &
1252 ! maxval(grd_new, mask=grd_new > NC_FILL_FLOAT)
1253 !
1254 ! write(*,fmt="(a,f14.3,f14.3)") "gridnew: ", minval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT), &
1255 ! maxval(this%grd_native%dpData, mask=this%grd_native%dpData > NC_FILL_FLOAT)
1256
1257 call sim_dt%addDay
1258 if ( sim_dt%curr > end_date ) exit
1259
1260 end do
1261
1262 call rstat%mean(grd_mean)
1263 call rstat%sum(grd_sum)
1264 call rstat%variance(grd_var)
1265
1266 where ( .not. local_mask )
1267 grd_mean = nc_fill_float
1268 grd_sum = nc_fill_float
1269 grd_var = nc_fill_float
1270 ! elsewhere
1271 ! grd_var = grd_var / (counter - 1)
1272 end where
1273
1274 if (this%annualize_stats) then
1275 where ( local_mask )
1276! grd_mean = grd_mean/ real( day_count, c_float ) * 365.25
1277! grd_var = grd_var/ real( day_count, c_float ) * 365.25
1278 grd_sum = grd_sum / real( day_count, c_double ) * 365.25
1279 end where
1280 ! else
1281 ! where ( local_mask )
1282 ! grd_mean = grd_sum / real( day_count, c_float )
1283 ! end where
1284 endif
1285
1286 deallocate(local_mask)
1287 deallocate(grd_new)
1288 deallocate(rtemp)
1289
1290 end subroutine calculate_slice_statistics
1291
1292!------------------------------------------------------------------------------
1293
1294 ! ASSUMPTION: this routine will be called *AFTER* the slice statistics are calculated and
1295 ! ONLY when the monthly statistics flag has been set from command line
1296 subroutine calculate_monthly_statistics(this, month_num, finalize)
1297
1298 class(swbstats_t), intent(inout) :: this
1299 integer (c_short), intent(in) :: month_num
1300 logical (c_bool), intent(in) :: finalize
1301
1302 integer (c_int) :: sum_index_num
1303 integer (c_int) :: mean_index_num
1304 integer (c_int) :: variance_index_num
1305 character (len=3) :: month_name
1306 integer (c_int) :: month_index
1307
1308 if (.not. finalize) then
1309
1310 call mon_stat(month_num)%push(grd_data=output_files(stats_sum)%grid_ptr%dpData, &
1311 mask=logical(OUTPUT_FILES(STATS_SUM)%grid_ptr%dpData > -9999._c_double, c_bool))
1312
1313 else !finalize monthly outputs
1314
1315 do month_index=1,12
1316
1317 month_name = months(month_index)%sName
1318 sum_index_num = ( month_index - 1 ) * 3 + 1
1319 mean_index_num = ( month_index- 1 ) * 3 + 2
1320 variance_index_num = ( month_index- 1 ) * 3 + 3
1321
1322 call mon_stat(month_index)%mean(output_files(mean_index_num)%grid_ptr%dpData)
1323 call mon_stat(month_index)%sum(output_files(sum_index_num)%grid_ptr%dpData)
1324 call mon_stat(month_index)%variance(output_files(variance_index_num)%grid_ptr%dpData)
1325
1326 ! if ( OUTPUT_FILES(sum_index_num)%n_count > 0 ) then
1327
1328 ! where ( OUTPUT_FILES(sum_index_num)%grid_ptr%dpData > -9999. )
1329 ! OUTPUT_FILES(mean_index_num)%grid_ptr%dpData = OUTPUT_FILES(sum_index_num)%grid_ptr%dpData &
1330 ! / real(OUTPUT_FILES(sum_index_num)%n_count, kind=c_double)
1331 ! else where
1332
1333 ! OUTPUT_FILES(mean_index_num)%grid_ptr%dpData = -9999.
1334
1335 ! end where
1336
1337 ! else
1338
1339 ! OUTPUT_FILES(mean_index_num)%grid_ptr%dpData = -9999.
1340
1341 ! endif
1342
1343 ! write(*,fmt='(a,i0,1x,6(f0.4, 2x))') 'FINALIZING: ', month_index, &
1344 ! minval(OUTPUT_FILES(sum_index_num)%grid_ptr%dpData), &
1345 ! maxval(OUTPUT_FILES(sum_index_num)%grid_ptr%dpData), &
1346 ! minval(OUTPUT_FILES(mean_index_num)%grid_ptr%dpData), &
1347 ! maxval(OUTPUT_FILES(mean_index_num)%grid_ptr%dpData), &
1348 ! minval(OUTPUT_FILES(variance_index_num)%grid_ptr%dpData), &
1349 ! maxval(OUTPUT_FILES(variance_index_num)%grid_ptr%dpData)
1350
1351 enddo
1352
1353 endif
1354
1355 end subroutine calculate_monthly_statistics
1356!------------------------------------------------------------------------------
1357
1358 subroutine read_date_range_file( this, &
1359 csv_filename, &
1360 date_range_id_list, &
1361 start_date_list, &
1362 end_date_list )
1363
1364 class(swbstats_t), intent(inout) :: this
1365 character (len=*), intent(inout) :: csv_filename
1366 type (FSTRING_LIST_T), intent(out) :: date_range_id_list
1367 type (FSTRING_LIST_T), intent(out) :: start_date_list
1368 type (FSTRING_LIST_T), intent(out) :: end_date_list
1369
1370 ! [ LOCALS ]
1371 type (ASCII_FILE_T), allocatable :: DF
1372 character (len=256) :: sRecord, sItem
1373
1374 allocate(df)
1375
1376 ! open the file associated with current file index value
1377 call df%open(sfilename = csv_filename, &
1378 sdelimiters=",", &
1379 scommentchars = "%#!", &
1380 lhasheader=true )
1381
1382 ! read in and throw away header of file
1383 srecord = df%readLine()
1384
1385 ! now read in the remainder of the file
1386 do while ( .not. df%isEOF() )
1387
1388 ! read in next line of file
1389 srecord = df%readLine()
1390
1391 ! skip blank lines
1392 if ( len_trim(srecord) == 0 ) cycle
1393
1394 call chomp( srecord, sitem, delimiter_chr="," )
1395 call this%date_range_id_list%append( sitem )
1396
1397 call chomp( srecord, sitem, delimiter_chr="," )
1398 call this%start_date_list%append( sitem )
1399 call this%end_date_list%append( srecord )
1400
1401 enddo
1402
1403 call df%close()
1404
1405 end subroutine read_date_range_file
1406
1407
1408!------------------------------------------------------------------------------
1409
1411 csv_filename, &
1412 date_range_id_list, &
1413 start_date_list, &
1414 end_date_list, &
1415 comparison_grid_file_list)
1416
1417 class(swbstats_t), intent(inout) :: this
1418 character (len=*), intent(inout) :: csv_filename
1419 type (FSTRING_LIST_T), intent(out) :: date_range_id_list
1420 type (FSTRING_LIST_T), intent(out) :: start_date_list
1421 type (FSTRING_LIST_T), intent(out) :: end_date_list
1422 type (FSTRING_LIST_T), intent(out) :: comparison_grid_file_list
1423
1424 ! [ LOCALS ]
1425 type (ASCII_FILE_T), allocatable :: DF
1426 character (len=256) :: sRecord, sItem
1427
1428 allocate(df)
1429
1430 ! open the file associated with current file index value
1431 call df%open(sfilename = csv_filename, &
1432 sdelimiters=",", &
1433 scommentchars = "%#!", &
1434 lhasheader=true )
1435
1436 ! read in and throw away header of file
1437 srecord = df%readLine()
1438
1439 ! now read in the remainder of the file
1440 do while ( .not. df%isEOF() )
1441
1442 ! read in next line of file
1443 srecord = df%readLine()
1444
1445 ! skip blank lines
1446 if ( len_trim(srecord) == 0 ) cycle
1447
1448 call chomp( srecord, sitem, delimiter_chr="," )
1449 call this%date_range_id_list%append( sitem )
1450
1451 call chomp( srecord, sitem, delimiter_chr="," )
1452 call this%start_date_list%append( sitem )
1453
1454 call chomp( srecord, sitem, delimiter_chr="," )
1455 call this%end_date_list%append( sitem )
1456
1457 call this%comparison_grid_file_list%append( srecord )
1458
1459 enddo
1460
1461 call df%close()
1462
1463 end subroutine read_comparison_period_file
1464
1465!------------------------------------------------------------------------------
1466
1467 subroutine read_zone_period_file( this, &
1468 csv_filename, &
1469 date_range_id_list, &
1470 start_date_list, &
1471 end_date_list, &
1472 zonal_stats_grid_file_list)
1473
1474 class(swbstats_t), intent(inout) :: this
1475 character (len=*), intent(inout) :: csv_filename
1476 type (FSTRING_LIST_T), intent(out) :: date_range_id_list
1477 type (FSTRING_LIST_T), intent(out) :: start_date_list
1478 type (FSTRING_LIST_T), intent(out) :: end_date_list
1479 type (FSTRING_LIST_T), intent(out) :: zonal_stats_grid_file_list
1480
1481 ! [ LOCALS ]
1482 type (ASCII_FILE_T), allocatable :: DF
1483 character (len=256) :: sRecord, sItem
1484
1485 allocate(df)
1486
1487 ! open the file associated with current file index value
1488 call df%open(sfilename = csv_filename, &
1489 sdelimiters=",", &
1490 scommentchars = "%#!", &
1491 lhasheader=true )
1492
1493 ! read in and throw away header of file
1494 srecord = df%readLine()
1495
1496 ! now read in the remainder of the file
1497 do while ( .not. df%isEOF() )
1498
1499 ! read in next line of file
1500 srecord = df%readLine()
1501
1502 ! skip blank lines
1503 if ( len_trim(srecord) == 0 ) cycle
1504
1505 call chomp( srecord, sitem, delimiter_chr="," )
1506 call this%date_range_id_list%append( sitem )
1507
1508 call chomp( srecord, sitem, delimiter_chr="," )
1509 call this%start_date_list%append( sitem )
1510
1511 call chomp( srecord, sitem, delimiter_chr="," )
1512 call this%end_date_list%append( sitem )
1513
1514 call this%zone_grid_file_list%append( srecord )
1515
1516 enddo
1517
1518 call df%close()
1519
1520 end subroutine read_zone_period_file
1521
1522!------------------------------------------------------------------------------
1523
1524 subroutine output_zonal_stats(this, &
1525 start_date, &
1526 end_date, &
1527 values, &
1528 zone_ids, &
1529 unique_zone_list, &
1530 delimiter, &
1531 funit, &
1532 zone2_ids, &
1533 unique_zone2_list, &
1534 comparison_values)
1535
1536 class(swbstats_t), intent(inout) :: this
1537 type (DATETIME_T), intent(in) :: start_date
1538 type (DATETIME_T), intent(in) :: end_date
1539 real (c_double), intent(inout) :: values(:,:)
1540 integer (c_int), intent(inout) :: zone_ids(:,:)
1541 type (FSTRING_LIST_T), intent(inout) :: unique_zone_list
1542 character (len=*), intent(in), optional :: delimiter
1543 integer (c_int), intent(in), optional :: funit
1544 integer (c_int), intent(inout), optional :: zone2_ids(:,:)
1545 type (FSTRING_LIST_T), intent(inout), optional :: unique_zone2_list
1546 real (c_double), intent(inout), optional :: comparison_values(:,:)
1547
1548 ! [ LOCALS ]
1549 integer (c_int) :: n, m
1550 integer (c_int) :: i, j
1551 integer (c_int), allocatable :: zone_values(:)
1552 integer (c_int), allocatable :: zone2_values(:)
1553 real (c_double), allocatable :: stats(:)
1554 integer (c_int) :: funit_l
1555 character (len=:), allocatable :: delimiter_
1556 character (len=6), parameter :: NUM_FMT = "g25.16"
1557
1558 if (present(funit)) then
1559 funit_l = funit
1560 else
1561 funit_l = output_unit
1562 endif
1563
1564 if (present(delimiter) ) then
1565 delimiter_ = trim(delimiter)
1566 else
1567 delimiter_ = ","
1568 endif
1569
1570 if (present(zone2_ids) .and. present(unique_zone2_list)) then
1571
1572 ! sort the values before use
1573 call unique_zone_list%sort_integer()
1574 call unique_zone2_list%sort_integer()
1575
1576 ! obtain list of unique integers present in the zone grid
1577 zone_values = unique_zone_list%get_integer()
1578 zone2_values = unique_zone2_list%get_integer()
1579
1580 if (present(comparison_values)) then
1581
1582 do i=1,ubound(zone_values,1)
1583 do j=1,ubound(zone2_values,1)
1584 n = zone_values(i)
1585 m = zone2_values(j)
1586 call calc_multizonal_stats(values, zone_ids, target_id=n, target2_id=m, &
1587 result_vector=stats, &
1588 zone2_ids=zone2_ids, &
1589 comparison_values=comparison_values)
1590
1591 write(unit=funit_l, fmt="(2(a,a),2(i0,a),4("//num_fmt//",a),i0,a,4("//num_fmt//",a),i0)") &
1592 start_date%prettydate(),delimiter_, &
1593 end_date%prettydate(), delimiter_, &
1594 n, delimiter_, m, delimiter_, &
1595 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1596 stats(4), delimiter_, int(stats(5)), delimiter_, &
1597 stats(6), delimiter_, stats(7), delimiter_, stats(8), delimiter_, &
1598 stats(9), delimiter_, int(stats(10))
1599
1600 enddo
1601 enddo
1602
1603 else
1604
1605 do i=1,ubound(zone_values,1)
1606 do j=1,ubound(zone2_values,1)
1607 n = zone_values(i)
1608 m = zone2_values(j)
1609
1610 call calc_multizonal_stats(values, zone_ids, target_id=n, target2_id=m, &
1611 result_vector=stats, zone2_ids=zone2_ids)
1612
1613 write(unit=funit_l, fmt="(2(a,a),2(i0,a),4("//num_fmt//",a),i0)") &
1614 start_date%prettydate(), delimiter_, &
1615 end_date%prettydate(), delimiter_, &
1616 n, delimiter_, m, delimiter_, &
1617 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1618 stats(4), delimiter_, int(stats(5))
1619 enddo
1620 enddo
1621
1622 endif
1623
1624 else
1625 ! obtain list of unique integers present in the zone grid
1626 zone_values = unique_zone_list%get_integer()
1627
1628 if (present(comparison_values)) then
1629
1630 do i=1,ubound(zone_values,1)
1631 n = zone_values(i)
1632
1633 call calc_zonal_stats(values, zone_ids, target_id=n, result_vector=stats, &
1634 comparison_values=comparison_values)
1635 write(unit=funit_l, fmt="(2(a,a),i0,a,4("//num_fmt//",a),i0,a,4("//num_fmt//",a),i0)") &
1636 start_date%prettydate(), delimiter_, &
1637 end_date%prettydate(), delimiter_, &
1638 n, delimiter_, &
1639 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1640 stats(4), delimiter_, int(stats(5)), delimiter_, &
1641 stats(6), delimiter_, stats(7), delimiter_, stats(8), delimiter_, &
1642 stats(9), delimiter_, int(stats(10))
1643
1644 enddo
1645
1646 else
1647
1648 do i=1,ubound(zone_values,1)
1649 n = zone_values(i)
1650
1651 call calc_zonal_stats(values, zone_ids, target_id=n, result_vector=stats)
1652 write(unit=funit_l, fmt="(2(a,a),i0,a,4("//num_fmt//",a),i0)") &
1653 start_date%prettydate(), delimiter_, &
1654 end_date%prettydate(), delimiter_, &
1655 n, delimiter_, &
1656 stats(1), delimiter_, stats(2), delimiter_, stats(3), delimiter_, &
1657 stats(4), delimiter_, int(stats(5))
1658 enddo
1659
1660 endif
1661
1662 endif
1663
1664 end subroutine output_zonal_stats
1665
1666!------------------------------------------------------------------------------
1667
1668 subroutine open_output_netcdf_files(this, &
1669 OUTPUT_FILES)
1670
1671 class(swbstats_t), intent(inout) :: this
1672 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
1673
1674 ! [ LOCALS ]
1675 integer (c_int) :: stat_indx
1676 integer (c_int) :: status
1677 type (T_NETCDF4_FILE), pointer :: ncfile_out
1678 character (len=:), allocatable :: units_string
1679 character (len=:), allocatable :: filename_prefix
1680
1681 if (allocated( this%output_file_prefix) ) then
1682 filename_prefix = this%output_file_prefix
1683 else
1684 filename_prefix = ""
1685 endif
1686
1687 do stat_indx=stats_mean, stats_variance
1688
1689 if ( .not. output_files(stat_indx)%output_active ) cycle
1690
1691 if (output_files(stat_indx)%write_netcdf) then
1692
1693 if ( this%annualize_stats .and. stat_indx == stats_sum) then
1694 units_string = trim(this%netcdf_variable_units_string)//", per year"
1695 elseif (this%report_as_volume) then
1696 units_string = "cubic meters"
1697 elseif (this%report_in_meters) then
1698 units_string = "meters"
1699 else
1700 units_string = trim(this%netcdf_variable_units_string)
1701 endif
1702
1703 allocate( output_files(stat_indx)%nc_ptr, stat=status)
1704 call assert( status==0, "Problem allocating netcdf file data structure.", &
1705 __file__, __line__)
1706 ncfile_out => output_files(stat_indx)%nc_ptr
1707
1709 ncfile=ncfile_out, &
1710 svariablename=trim(this%netcdf_variable_name_string), &
1711 svariableunits=units_string, &
1712 inx=this%ncfile_in%iNX, &
1713 iny=this%ncfile_in%iNY, &
1714 fx=this%ncfile_in%rX_Coords, &
1715 fy=this%ncfile_in%rY_Coords, &
1716 proj4_string=trim(this%target_proj4_string), &
1717 startdate=sim_dt%start, &
1718 enddate=sim_dt%end, &
1719 executable_name="SWBSTATS2", &
1720 filename_prefix=filename_prefix, &
1721 filename_modifier=this%filename_modifier_string &
1722 //"_"//output_files(stat_indx)%stats_description )
1723
1724 endif
1725
1726 enddo
1727
1728 end subroutine open_output_netcdf_files
1729
1730!------------------------------------------------------------------------------
1731
1732 subroutine close_output_netcdf_files(this, OUTPUT_FILES)
1733
1734 class(swbstats_t), intent(inout) :: this
1735 type (FILE_COLLECTION_T), intent(inout) :: OUTPUT_FILES(:)
1736
1737 ! [ LOCALS ]
1738 integer (c_int) :: stat_indx
1739 type (T_NETCDF4_FILE), pointer :: ncfile_out
1740
1741 do stat_indx=stats_mean, stats_variance
1742
1743 if ( .not. output_files(stat_indx)%output_active ) cycle
1744
1745 if (output_files(stat_indx)%write_netcdf) then
1746
1747 call netcdf_rewrite_attribute( ncfile=output_files(stat_indx)%nc_ptr, &
1748 svariablename=trim(this%netcdf_variable_name_string), &
1749 sattributename='valid_min', &
1750 rattributevalue=[output_files(stat_indx)%valid_min])
1751
1752 call netcdf_rewrite_attribute( ncfile=output_files(stat_indx)%nc_ptr, &
1753 svariablename=trim(this%netcdf_variable_name_string), &
1754 sattributename='valid_max', &
1755 rattributevalue=[output_files(stat_indx)%valid_max])
1756
1757 call netcdf_rewrite_attribute( ncfile=output_files(stat_indx)%nc_ptr, &
1758 svariablename=trim(this%netcdf_variable_name_string), &
1759 sattributename='valid_range', &
1760 rattributevalue=[output_files(stat_indx)%valid_min, &
1761 output_files(stat_indx)%valid_max])
1762
1763 ncfile_out => output_files(stat_indx)%nc_ptr
1764 call netcdf_close_file(ncfile=ncfile_out)
1765
1766 endif
1767
1768 enddo
1769
1770 end subroutine close_output_netcdf_files
1771
1772!------------------------------------------------------------------------------
1773
1774 subroutine open_zonal_stats_output_file(this, filename, delimiter)
1775
1776 class(swbstats_t), intent(inout) :: this
1777 character (len=*) :: filename
1778 character (len=*), intent(in), optional :: delimiter
1779
1780 ! [ LOCALS ]
1781 character (len=256) :: header_str
1782 character (len=:), allocatable :: delimiter_
1783
1784 if (present(delimiter)) then
1785 delimiter_ = delimiter
1786 else
1787 delimiter_ = ","
1788 endif
1789
1790 call this%zonal_stats_output_file%open(filename)
1791
1792 if (len_trim(this%zone_grid2_filename) > 0) then
1793
1794 if (this%multiple_comparison_grids .or. this%compare_to_obs_values) then
1795 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1796 //delimiter_//"zone2_id"//delimiter_//"minimum_swb"//delimiter_ &
1797 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1798 //delimiter_//"count_swb"//delimiter_//"minimum_obs"//delimiter_ &
1799 //"maximum_obs"//delimiter_//"mean_obs"//delimiter_//"sum_obs" &
1800 //delimiter_//"count_obs"
1801 else
1802 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1803 //delimiter_//"zone2_id"//delimiter_//"minimum_swb"//delimiter_ &
1804 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1805 //delimiter_//"count_swb"
1806 endif
1807
1808 else
1809
1810 if (this%multiple_comparison_grids .or. this%compare_to_obs_values) then
1811
1812 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1813 //delimiter_//"minimum_swb"//delimiter_ &
1814 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1815 //delimiter_//"count_swb"//delimiter_//"minimum_obs"//delimiter_ &
1816 //"maximum_obs"//delimiter_//"mean_obs"//delimiter_//"sum_obs" &
1817 //delimiter_//"count_obs"
1818
1819 else
1820
1821 header_str = "start_date"//delimiter_//"end_date"//delimiter_//"zone_id" &
1822 //delimiter_//"minimum_swb"//delimiter_ &
1823 //"maximum_swb"//delimiter_//"mean_swb"//delimiter_//"sum_swb" &
1824 //delimiter_//"count_swb"
1825
1826 endif
1827
1828 endif
1829
1830 call this%zonal_stats_output_file%writeLine(trim(header_str))
1831
1832 end subroutine open_zonal_stats_output_file
1833
1834!------------------------------------------------------------------------------
1835
1836 subroutine print_all_options(this)
1837
1838 class(swbstats_t) :: this
1839
1840 ! [ LOCALS ]
1841 character (len=:), allocatable :: fmt_string
1842
1843 write(*,fmt="(/,/,a)") " :: Dump of swbstats2 program this ::"
1844 write(*,fmt="(a,/)") repeat("-", 43)
1845
1846 fmt_string = "(a,t30,': ',l)"
1847 write(*,fmt=fmt_string) "write_csv", this%write_csv
1848 write(*,fmt=fmt_string) "write_netcdf (SUM)", output_files(stats_sum)%write_netcdf
1849 write(*,fmt=fmt_string) "write_netcdf (MEAN)", output_files(stats_mean)%write_netcdf
1850 write(*,fmt=fmt_string) "write_netcdf (VARIANCE)", output_files(stats_variance)%write_netcdf
1851 write(*,fmt=fmt_string) "write_arcgrid (SUM)", output_files(stats_sum)%write_arcgrid
1852 write(*,fmt=fmt_string) "write_arcgrid (MEAN)", output_files(stats_mean)%write_arcgrid
1853 write(*,fmt=fmt_string) "write_arcgrid (VARIANCE)", output_files(stats_variance)%write_arcgrid
1854 write(*,fmt=fmt_string) "output_active (SUM)", output_files(stats_sum)%output_active
1855 write(*,fmt=fmt_string) "output_active (MEAN)", output_files(stats_mean)%output_active
1856 write(*,fmt=fmt_string) "output_active (VARIANCE)", output_files(stats_variance)%output_active
1857
1858 fmt_string = "(a,t40,': ',l)"
1859 write(*,fmt=fmt_string) "grid pointer allocated? (SUM)", associated( output_files(stats_sum)%grid_ptr)
1860 write(*,fmt=fmt_string) "grid pointer allocated? (MEAN)", associated( output_files(stats_mean)%grid_ptr)
1861 write(*,fmt=fmt_string) "grid pointer allocated? (VARIANCE)", associated( output_files(stats_variance)%grid_ptr)
1862
1863 fmt_string = "(a,t30,': ',l)"
1864 write(*,fmt=fmt_string) "calc_zonal_stats", this%calc_zonal_stats
1865 write(*,fmt=fmt_string) "compare_to_obs_values", this%compare_to_obs_values
1866 write(*,fmt=fmt_string) "annualize_stats", this%annualize_stats
1867
1868 fmt_string = "(a,t30,': ',a)"
1869 write(*,fmt=fmt_string) "target_proj4_string", this%target_proj4_string
1870 write(*,fmt=fmt_string) "data_start_date", this%data_start_date%prettydate()
1871 write(*,fmt=fmt_string) "data_end_date", this%data_end_date%prettydate()
1872 write(*,fmt=fmt_string) "slice_start_date", this%slice_start_date%prettydate()
1873 write(*,fmt=fmt_string) "slice_end_date", this%slice_end_date%prettydate()
1874 !date_range_string
1875
1876 fmt_string = "(a,t30,': ',i0)"
1877 write(*,fmt=fmt_string) "input grid bounds, nx", bnds%iNumCols
1878 write(*,fmt=fmt_string) "input grid bounds, ny", bnds%iNumRows
1879
1880 fmt_string = "(a,t35,': ',f16.5)"
1881 write(*,fmt=fmt_string) "input grid bounds, X_ll", bnds%fX_ll
1882 write(*,fmt=fmt_string) "input grid bounds, Y_ll", bnds%fY_ll
1883 write(*,fmt=fmt_string) "input grid bounds, X_ur", bnds%fX_ur
1884 write(*,fmt=fmt_string) "input grid bounds, Y_ur", bnds%fY_ur
1885 write(*,fmt=fmt_string) "input grid bounds, grid-cell size", bnds%fGridCellSize
1886
1887 fmt_string = "(a,t30,': ',i0)"
1888 write(*,fmt=fmt_string) "calculation_time_period", this%calculation_time_period
1889
1890 fmt_string = "(a,t30,': ',a)"
1891 write(*,fmt=fmt_string) "stress_period_filename", this%stress_period_filename
1892 write(*,fmt=fmt_string) "comparison_period_filename", this%comparison_period_filename
1893 write(*,fmt=fmt_string) "zone_period_filename", this%zone_period_filename
1894 write(*,fmt=fmt_string) "comparison_grid_filename", this%comparison_grid_filename
1895 write(*,fmt=fmt_string) "zone_grid_filename", this%zone_grid_filename
1896 write(*,fmt=fmt_string) "netcdf_input_filename", this%netcdf_input_filename
1897 write(*,fmt=fmt_string) "netcdf_variable_name_string", this%netcdf_variable_name_string
1898 write(*,fmt=fmt_string) "netcdf_variable_units_string", this%netcdf_variable_units_string
1899
1900 fmt_string = "(a,t30,': ',l)"
1901 write(*,fmt=fmt_string) "netcdf_input_file_is_open : ", this%netcdf_input_file_is_open
1902 write(*,fmt=fmt_string) "multiple_zone_grids : ", this%multiple_zone_grids
1903 write(*,fmt=fmt_string) "multiple_comparison_grids : ", this%multiple_comparison_grids
1904 !comparison_grid_conversion_factor = 1.0_c_double
1905 fmt_string = "(/,a,/,'"//repeat("-",62)//"')"
1906 write(*,fmt=fmt_string) "Start date list"
1907 call this%start_date_list%print()
1908 write(*,fmt=fmt_string) "End date list"
1909 call this%end_date_list%print()
1910 write(*,fmt=fmt_string) "Date index list"
1911 call this%date_range_id_list%print()
1912 write(*,fmt=fmt_string) "Unique zone id list"
1913 call this%unique_zone_list%print()
1914 write(*,fmt=fmt_string) "Comparison grid file list"
1915 call this%comparison_grid_file_list%print()
1916 write(*,fmt=fmt_string) "Zone grid file list"
1917 call this%zone_grid_file_list%print()
1918
1919 end subroutine print_all_options
1920
1921!------------------------------------------------------------------------------
1922
1923 pure function update_minimum_value(current_minimum, values) result(new_minimum)
1924
1925 real (c_float), intent(in) :: current_minimum
1926 real (c_float), intent(in) :: values(:,:)
1927
1928 real (c_float) :: new_minimum
1929
1930 new_minimum = min(current_minimum, minval(values))
1931
1932 end function update_minimum_value
1933
1934!------------------------------------------------------------------------------
1935
1936 pure function update_maximum_value(current_maximum, values) result(new_maximum)
1937
1938 real (c_float), intent(in) :: current_maximum
1939 real (c_float), intent(in) :: values(:,:)
1940
1941 real (c_float) :: new_maximum
1942
1943 new_maximum = max(current_maximum, maxval(values))
1944
1945 end function update_maximum_value
1946
1947end module swbstats2_support
1948
1949
1950
1951
1952
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
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:1054
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)