[Dart-dev] DART/branches Revision: 10966

dart at ucar.edu dart at ucar.edu
Fri Jan 27 14:14:27 MST 2017


nancy at ucar.edu
2017-01-27 14:14:27 -0700 (Fri, 27 Jan 2017)
101
updated to squeeze duplicate entries out of the namelist
so only new ensemble sizes are computed.  




Modified: DART/branches/rma_trunk/system_simulation/gen_sampling_err_table.f90
===================================================================
--- DART/branches/rma_trunk/system_simulation/gen_sampling_err_table.f90	2017-01-27 20:27:28 UTC (rev 10965)
+++ DART/branches/rma_trunk/system_simulation/gen_sampling_err_table.f90	2017-01-27 21:14:27 UTC (rev 10966)
@@ -23,7 +23,7 @@
 
 program gen_sampling_err_table
 
-use types_mod,      only : r8
+use types_mod,      only : r8, MISSING_I
 use utilities_mod,  only : error_handler, E_ERR, nc_check, file_exist,  &
                            initialize_utilities, finalize_utilities, &
                            find_namelist_in_file, check_namelist_read, &
@@ -58,7 +58,7 @@
 
 integer, allocatable :: index_array(:)
 
-integer  :: ncid, num_ens, esize, this_slot
+integer  :: ncid, num_ens, add_ens, esize, current_count
 integer  :: iunit, io
 
 character(len=512) :: msgstring
@@ -87,33 +87,63 @@
 if (do_nml_file()) write(nmlfileunit, nml=gen_sampling_error_table_nml)
 if (do_nml_term()) write(     *     , nml=gen_sampling_error_table_nml)
 
+! blank line to make it easier to see messages 
+call error_handler(E_MSG, '', '')
 
-call init_random_seq(ran_id)
-
-num_ens = valid_entries(ens_sizes, 3)
+! check that the ensemble sizes are all good - 3 is the minimum size accepted
+! and there is no max limit.  returns the number of values found
+num_ens = valid_entries(ens_sizes, 3, MISSING_I, 'namelist variable "ens_size"')
 if (num_ens < 1) then
-   call error_handler(E_ERR, 'gen_sampling_err_table', 'no valid ensemble sizes specified', &
+   call error_handler(E_ERR, 'gen_sampling_err_table:', 'no valid ensemble sizes specified', &
              source, revision, revdate, text2='check values of namelist item "ens_sizes"')
 endif
 
 if (file_exist(output_filename)) then
-   ncid = setup_to_append_output_file(nentries, num_samples, this_slot)
+   ncid = setup_to_append_output_file(nentries, num_samples, current_count)
 else
-   ncid = create_output_file(nentries, num_samples, this_slot)
+   ncid = create_output_file(nentries, num_samples, current_count)
 endif
 
-call validate_list(ncid, this_slot, index_array, num_ens, ens_sizes)
+! add the new values to an existing list, if present, remove values that 
+! already exist or are repeated in the list.  add_ens returns with the actual
+! number of new ensemble sizes which need to be computed and the ens_sizes
+! array has been updated to remove duplicates.
 
-do esize=1, num_ens
+! save original value and tell user if we're avoiding duplicates or
+! existing values in file.
 
-   this_slot = this_slot + 1
+call merge_lists(ncid, current_count, index_array, num_ens, ens_sizes, add_ens)
 
-   call compute_table(ens_sizes(esize), nentries, bin_count, true_correl_mean, alpha)
-   call addto_output_file(ncid, this_slot, bin_count(1:nentries), true_correl_mean, &
-                          alpha, ens_sizes(esize))
+if (add_ens <= 0) then
 
-enddo
+   call error_handler(E_MSG, 'gen_sampling_err_table:', &
+             'no new ensemble sizes specified, nothing to do.', &
+             source, revision, revdate, text2='all sizes specified already exist in output file')
 
+else
+   if (num_ens /= add_ens) then
+      write(msgstring, *) num_ens-add_ens, ' "ens_sizes" entries ignored; either duplicate values'
+      call error_handler(E_MSG, 'gen_sampling_err_table:', msgstring, &
+             source, revision, revdate, &
+             text2='in namelist, or ensemble size already exists in output file')
+      call error_handler(E_MSG, '', '')  ! blank line
+   endif
+
+
+   do esize=current_count+1, current_count+add_ens
+      ! seed the generator with the ensemble size so the results are
+      ! completely reproducible.
+      call init_random_seq(ran_id, index_array(esize))
+   
+      call compute_table(index_array(esize), nentries, bin_count, true_correl_mean, alpha)
+      call addto_output_file(ncid, esize, bin_count(1:nentries), true_correl_mean, &
+                             alpha, index_array(esize))
+   
+      call sync_output_file(ncid)
+   
+   enddo
+endif
+
 call close_output_file(ncid)
 
 call finalize_utilities()
@@ -145,7 +175,9 @@
 


More information about the Dart-dev mailing list