[Dart-dev] [3215] DART/branches/nancy_work/obs_sequence: My test branch: commit proposed updates to merge_obs_seq

nancy at subversion.ucar.edu nancy at subversion.ucar.edu
Thu Feb 7 09:14:36 MST 2008


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20080207/19372acf/attachment.html
-------------- next part --------------
Modified: DART/branches/nancy_work/obs_sequence/merge_obs_seq.f90
===================================================================
--- DART/branches/nancy_work/obs_sequence/merge_obs_seq.f90	2008-02-05 22:23:15 UTC (rev 3214)
+++ DART/branches/nancy_work/obs_sequence/merge_obs_seq.f90	2008-02-07 16:14:35 UTC (rev 3215)
@@ -15,14 +15,15 @@
 use    utilities_mod, only : timestamp, register_module, initialize_utilities, &
                              find_namelist_in_file, check_namelist_read, &
                              error_handler, E_ERR, E_MSG, logfileunit
-use time_manager_mod, only : time_type, operator(>), print_time
+use time_manager_mod, only : time_type, operator(>), print_time, set_time
 use obs_sequence_mod, only : obs_sequence_type, obs_type, write_obs_seq, &
                              init_obs, init_obs_sequence, static_init_obs_sequence, &
                              read_obs_seq_header, read_obs_seq, assignment(=), &
                              get_num_obs, get_first_obs, get_last_obs, get_next_obs, &
                              insert_obs_in_seq, get_num_copies, get_num_qc, &
                              get_copy_meta_data, get_qc_meta_data, set_qc_meta_data, &
-                             destroy_obs, destroy_obs_sequence
+                             destroy_obs, destroy_obs_sequence, delete_seq_head, &
+                             delete_seq_tail
 
 implicit none
 
@@ -44,6 +45,7 @@
 integer                 :: max_num_obs, file_id
 character(len = 129)    :: read_format
 logical                 :: pre_I_format
+logical                 :: all_gone
 character(len = 129)    :: msgstring
 
 !----------------------------------------------------------------
@@ -56,8 +58,18 @@
 character(len = 129) :: filename_seq(max_num_input_files)
 character(len = 129) :: filename_out  = 'obs_seq.merged'
 
-namelist /merge_obs_seq_nml/ num_input_files, filename_seq, filename_out
+! Time of first and last observations to be used from obs_sequence
+! If negative, these are not used
+integer  :: first_obs_days    = -1
+integer  :: first_obs_seconds = -1
+integer  :: last_obs_days     = -1
+integer  :: last_obs_seconds  = -1
+type(time_type) :: first_obs_time, last_obs_time
 
+
+namelist /merge_obs_seq_nml/ num_input_files, filename_seq, filename_out, &
+         first_obs_days, first_obs_seconds, last_obs_days, last_obs_seconds
+
 !----------------------------------------------------------------
 ! Start of the routine.
 ! This routine basically opens the second observation sequence file
@@ -97,6 +109,10 @@
 add_qc       = 0
 add_size_seq = 0
 
+! Note for future enhancement:
+! create an empty header in all cases and place obs in it.  that sorts
+! them and allows us to trim the file if not all the obs are being used.
+
 do i = 1, num_input_files
 
    if ( len(filename_seq(i)) .eq. 0 .or. filename_seq(i) .eq. "" ) then
@@ -126,6 +142,27 @@
 
 ! Read 1st obs seq, expand its size for insertion
 call read_obs_seq(filename_seq(1), add_copies, add_qc, add_size_seq, seq1)
+
+! Need to find first obs with appropriate time, delete all earlier ones
+if(first_obs_seconds >= 0 .or. first_obs_days >= 0) then
+   first_obs_time = set_time(first_obs_seconds, first_obs_days)
+   call delete_seq_head(first_obs_time, seq1, all_gone)
+   if(all_gone) then
+      msgstring = 'All obs in sequence are before first_obs_days:first_obs_seconds'
+      call error_handler(E_ERR,'merge_obs_seq',msgstring,source,revision,revdate)
+   endif
+endif
+
+! Also get rid of observations past the last_obs_time if requested
+if(last_obs_seconds >= 0 .or. last_obs_days >= 0) then
+   last_obs_time = set_time(last_obs_seconds, last_obs_days)
+   call delete_seq_tail(last_obs_time, seq1, all_gone)
+   if(all_gone) then
+      msgstring = 'All obs in sequence are after last_obs_days:last_obs_seconds'
+      call error_handler(E_ERR,'merge_obs_seq',msgstring,source,revision,revdate)
+   endif
+endif
+
 size_seq    = get_num_obs(seq1)      ! does not include size_seq2
 num_copies  = get_num_copies(seq1)   ! already includes add_copies
 num_qc      = get_num_qc(seq1)       ! already includes add_qc
@@ -143,6 +180,32 @@
 
    call read_obs_seq(filename_seq(i), 0, 0, 0, seq2)
 
+   ! Need to find first obs with appropriate time, delete all earlier ones
+   if(first_obs_seconds >= 0 .or. first_obs_days >= 0) then
+      first_obs_time = set_time(first_obs_seconds, first_obs_days)
+      call delete_seq_head(first_obs_time, seq2, all_gone)
+      if(all_gone) then
+         msgstring = 'Skipping: all obs in ' // trim(filename_seq(i)) // &
+                     ' are before first_obs_days:first_obs_seconds'
+         call error_handler(E_MSG,'merge_obs_seq',msgstring,source,revision,revdate)
+         call destroy_obs_sequence(seq2)
+         cycle   ! skip this input file and do the next (if there are any)
+      endif
+   endif
+   
+   ! Also get rid of observations past the last_obs_time if requested
+   if(last_obs_seconds >= 0 .or. last_obs_days >= 0) then
+      last_obs_time = set_time(last_obs_seconds, last_obs_days)
+      call delete_seq_tail(last_obs_time, seq2, all_gone)
+      if(all_gone) then
+         msgstring = 'Skipping: all obs in ' // trim(filename_seq(i)) // &
+                     ' are after last_obs_days:last_obs_seconds'
+         call error_handler(E_MSG,'merge_obs_seq',msgstring,source,revision,revdate)
+         call destroy_obs_sequence(seq2)
+         cycle   ! skip this input file and do the next (if there are any)
+      endif
+   endif
+
    size_seq1 = get_num_obs(seq1)     !current size of seq1
    size_seq2 = get_num_obs(seq2)     !current size of seq2
 

Modified: DART/branches/nancy_work/obs_sequence/merge_obs_seq.html
===================================================================
--- DART/branches/nancy_work/obs_sequence/merge_obs_seq.html	2008-02-05 22:23:15 UTC (rev 3214)
+++ DART/branches/nancy_work/obs_sequence/merge_obs_seq.html	2008-02-07 16:14:35 UTC (rev 3215)
@@ -85,6 +85,15 @@
 <em class=file>obs_seq</em> file. The empty <em class=file>obs_seq</em> 
 must be specified first in the list of files to merge, it has to have a header, 
 and first = last = -1. Pretty Sneaky.
+<BR><BR>
+Sequence files can be trimmed, or partial files combined by setting the
+namelist entries for first and last observation timestamps (in Gregorian
+days and seconds).
+All observations before the start time and 
+after the last time will be removed before merging.  There is a currently
+a restriction that at least one observation from the first file must remain
+to have something to merge into.  It is ok for some or all of the additional
+files to have no observations in the requested time range.
 </P>
 
 
@@ -108,7 +117,8 @@
  '&#38;' and terminating with a slash '/'.
  </P>
  <div class=namelist><pre>
- <em class=call>namelist / merge_obs_seq / </em> num_input_files, filename_seq, filename_out
+ <em class=call>namelist / merge_obs_seq / </em> num_input_files, filename_seq,
+  filename_out, first_obs_days, first_obs_seconds, last_obs_days, last_obs_seconds
  </pre></div>
 
  <H3 class=indent1>Discussion</H3>
@@ -143,6 +153,28 @@
      <!--  type  --><TD>character(len=129)</TD>
      <!--descript--><TD>The name of the resulting (merged) observation sequence file.
                         Default: 'obs_seq.merged'</TD></TR>
+ <TR><!--contents--><TD valign=top>first_obs_days</TD>
+     <!--  type  --><TD>integer</TD>
+     <!--descript--><TD>If non-negative, restrict the timestamps of the observations
+                        copied to the merged file to be equal to or after this date
+                        (specified in the Gregorian calendar; day number since 1600).
+                        Default: -1, merge all observations</TD></TR>
+ <TR><!--contents--><TD valign=top>first_obs_seconds</TD>
+     <!--  type  --><TD>integer</TD>
+     <!--descript--><TD>If non-negative, restrict the timestamps of the observations
+                        copied to the merged file to be equal to or after this time.
+                        Default: -1, merge all observations</TD></TR>
+ <TR><!--contents--><TD valign=top>last_obs_days</TD>
+     <!--  type  --><TD>integer</TD>
+     <!--descript--><TD>If non-negative, restrict the timestamps of the observations
+                        copied to the merged file to be equal to or before this date
+                        (specified in the Gregorian calendar; day number since 1600).
+                        Default: -1, merge all observations</TD></TR>
+ <TR><!--contents--><TD valign=top>last_obs_seconds</TD>
+     <!--  type  --><TD>integer</TD>
+     <!--descript--><TD>If non-negative, restrict the timestamps of the observations
+                        copied to the merged file to be equal to or before this time.
+                        Default: -1, merge all observations</TD></TR>
  </TABLE>
  
 

Modified: DART/branches/nancy_work/obs_sequence/merge_obs_seq.nml
===================================================================
--- DART/branches/nancy_work/obs_sequence/merge_obs_seq.nml	2008-02-05 22:23:15 UTC (rev 3214)
+++ DART/branches/nancy_work/obs_sequence/merge_obs_seq.nml	2008-02-07 16:14:35 UTC (rev 3215)
@@ -1,5 +1,9 @@
 &merge_obs_seq_nml
    num_input_files = 2,
    filename_seq    = 'obs_seq.one', 'obs_seq.two',
-   filename_out    = 'obs_seq.merged'  /
+   filename_out    = 'obs_seq.merged',
+   first_obs_days           = -1,
+   first_obs_seconds        = -1,
+   last_obs_days            = -1,
+   last_obs_seconds         = -1  /
 


More information about the Dart-dev mailing list