[Dart-dev] [4174] DART/trunk: Make the code use the common routine in the utilities mod ( ascii_file_format())

nancy at ucar.edu nancy at ucar.edu
Tue Dec 1 10:03:36 MST 2009


Revision: 4174
Author:   nancy
Date:     2009-12-01 10:03:35 -0700 (Tue, 01 Dec 2009)
Log Message:
-----------
Make the code use the common routine in the utilities mod (ascii_file_format())
for determining ascii/formatted vs binary/unformatted file format.  
Also make the last arg of write_time() consistently named (ios_out vs ios)
with read_time. Update docs to match the argument name change.

Modified Paths:
--------------
    DART/trunk/assim_model/assim_model_mod.f90
    DART/trunk/time_manager/time_manager_mod.f90
    DART/trunk/time_manager/time_manager_mod.html

-------------- next part --------------
Modified: DART/trunk/assim_model/assim_model_mod.f90
===================================================================
--- DART/trunk/assim_model/assim_model_mod.f90	2009-11-30 21:37:15 UTC (rev 4173)
+++ DART/trunk/assim_model/assim_model_mod.f90	2009-12-01 17:03:35 UTC (rev 4174)
@@ -26,7 +26,8 @@
                           E_ERR, E_WARN, E_MSG, E_DBG, logfileunit, nmlfileunit,   &
                           do_output, dump_unit_attributes, find_namelist_in_file,  &
                           check_namelist_read, nc_check, do_nml_file, do_nml_term, &
-                          find_textfile_dims, file_to_text, timestamp, set_output
+                          find_textfile_dims, file_to_text, timestamp, set_output, &
+                          ascii_file_format
 use     model_mod, only : get_model_size, static_init_model, get_state_meta_data,  &
                           get_model_time_step, model_interpolate, init_conditions, &
                           init_time, adv_1step, end_model, nc_write_model_atts,    &
@@ -797,24 +798,23 @@
 io = 0
 
 ! Write the state vector
-SELECT CASE (open_format)
-   CASE ("unf","UNF","unformatted","UNFORMATTED")
-      if(present(target_time)) call write_time(funit, target_time, "unformatted", ios=io)
+if (ascii_file_format(open_format)) then
+   if(present(target_time)) call write_time(funit, target_time, ios_out=io)
+   if (io /= 0) goto 10
+   call write_time(funit, model_time, ios_out=io)
+   if (io /= 0) goto 10
+   do i = 1, size(model_state)
+      write(funit, *, iostat = io) model_state(i)
       if (io /= 0) goto 10
-      call write_time(funit, model_time, "unformatted", ios=io)
-      if (io /= 0) goto 10
-      write(funit, iostat = io) model_state
-      if (io /= 0) goto 10
-   CASE DEFAULT
-      if(present(target_time)) call write_time(funit, target_time, ios=io)
-      if (io /= 0) goto 10
-      call write_time(funit, model_time, ios=io)
-      if (io /= 0) goto 10
-      do i = 1, size(model_state)
-         write(funit, *, iostat = io) model_state(i)
-         if (io /= 0) goto 10
-      end do
-END SELECT  
+   end do
+else
+   if(present(target_time)) call write_time(funit, target_time, form="unformatted", ios_out=io)
+   if (io /= 0) goto 10
+   call write_time(funit, model_time, form="unformatted", ios_out=io)
+   if (io /= 0) goto 10
+   write(funit, iostat = io) model_state
+   if (io /= 0) goto 10
+endif
 
 ! come directly here on error. 
 10 continue
@@ -879,16 +879,15 @@
 ! Figure out whether the file is opened FORMATTED or UNFORMATTED
 inquire(funit, FORM=open_format)
 
-SELECT CASE (open_format)
-   CASE ("unf","UNF","unformatted","UNFORMATTED")
-      if(present(target_time)) target_time = read_time(funit, form = "unformatted")
-      model_time = read_time(funit, form = "unformatted")
-      read(funit,iostat=ios) model_state
-   CASE DEFAULT
-      if(present(target_time)) target_time = read_time(funit)
-      model_time = read_time(funit)
-      read(funit,*,iostat=ios) model_state
-END SELECT  
+if (ascii_file_format(open_format)) then
+   if(present(target_time)) target_time = read_time(funit)
+   model_time = read_time(funit)
+   read(funit,*,iostat=ios) model_state
+else
+   if(present(target_time)) target_time = read_time(funit, form = "unformatted")
+   model_time = read_time(funit, form = "unformatted")
+   read(funit,iostat=ios) model_state
+endif
 
 ! If the model_state read fails ... dump diagnostics.
 if ( ios /= 0 ) then

Modified: DART/trunk/time_manager/time_manager_mod.f90
===================================================================
--- DART/trunk/time_manager/time_manager_mod.f90	2009-11-30 21:37:15 UTC (rev 4173)
+++ DART/trunk/time_manager/time_manager_mod.f90	2009-12-01 17:03:35 UTC (rev 4174)
@@ -13,7 +13,8 @@
 
 use     types_mod, only : missing_i, digits12
 use utilities_mod, only : error_handler, E_DBG, E_MSG, E_WARN, E_ERR, &
-                          register_module, dump_unit_attributes, to_upper
+                          register_module, dump_unit_attributes, to_upper, &
+                          ascii_file_format
 
 implicit none
 private
@@ -2879,29 +2880,24 @@
 implicit none
 
 integer,          intent(in)            :: file_unit
-character(len=*), intent(in), optional  :: form
+character(len=*), intent(in),  optional :: form
 integer,          intent(out), optional :: ios_out
 
 type(time_type)   :: read_time
 integer           :: secs, days, ios
-character(len=32) :: fileformat
 
-character(len=128) :: str1, filename
+character(len=128) :: filename
 logical :: is_named
 integer :: rc
 
 if ( .not. module_initialized ) call time_manager_init
 
-fileformat = "ascii"   ! supply default
-if (present(form)) fileformat = trim(adjustl(form))
+if (ascii_file_format(form)) then
+   read(file_unit, *, iostat=ios) secs, days
+else
+   read(file_unit, iostat=ios) secs, days
+endif
 
-SELECT CASE (fileformat)
-   CASE ("unf","UNF","unformatted","UNFORMATTED")
-      read(file_unit, iostat=ios) secs, days
-   CASE DEFAULT
-      read(file_unit, *, iostat=ios) secs, days
-END SELECT
-
 if ( ios /= 0 ) then
 
    ! If ios_out argument is present, just return a non-zero ios
@@ -2917,8 +2913,8 @@
 
    ! Otherwise, read error is fatal, print message and stop
    call dump_unit_attributes(file_unit)   ! TJH DEBUG statement
-   write(str1,*)'read returned status ', ios, 'from input file ', trim(filename)
-   call error_handler(E_ERR,'read_time',str1,source,revision,revdate)
+   write(errstring,*)'read returned status ', ios, 'from input file ', trim(filename)
+   call error_handler(E_ERR,'read_time',errstring,source,revision,revdate)
 else
    read_time = set_time(secs, days)
    if(present(ios_out)) ios_out = 0
@@ -2928,51 +2924,46 @@
 
 
 
-subroutine write_time(file_unit, time, form, ios)
+subroutine write_time(file_unit, time, form, ios_out)
 !------------------------------------------------------------------------
 ! The time is expected to be written as either 
 ! an unformatted binary (form == "unformatted")
 ! or free-format ascii (form /= "unformatted")
-! If ios is specified, do not call error handler here, but return so
-! a better context message can be generated.
+! If ios_out is specified, do not call error handler here, 
+! but return so a better context message can be generated.
 
 implicit none
 
 integer,          intent(in)            :: file_unit
 type(time_type),  intent(in)            :: time
-character(len=*), intent(in), optional  :: form
-integer,          intent(out), optional :: ios
+character(len=*), intent(in),  optional :: form
+integer,          intent(out), optional :: ios_out
 
-integer           :: secs, days, io
-character(len=32) :: fileformat
+integer            :: secs, days, io
 character(len=129) :: filename
 logical :: is_named
 integer :: rc
 
 if ( .not. module_initialized ) call time_manager_init
 
-fileformat = "ascii"   ! supply default
-if (present(form)) fileformat = trim(adjustl(form))
+call get_time(time, secs, days)
 io = 0
 
-call get_time(time, secs, days)
+if (ascii_file_format(form)) then
+   write(file_unit,'(i6,1x,i10)', iostat = io) secs, days
+else
+   write(file_unit, iostat = io) secs, days
+endif
 
-SELECT CASE (fileformat)
-   CASE ("unf","UNF","unformatted","UNFORMATTED")
-      write(file_unit, iostat = io) secs, days
-   CASE DEFAULT
-      write(file_unit,'(i6,1x,i10)', iostat = io) secs, days
-END SELECT
-
 ! return code for write.  0 = good, anything else bad.
-if (present(ios)) then
-   ios = io
+if (present(ios_out)) then
+   ios_out = io
 endif
 
 ! if the caller is not asking for the return code, error out here.
 ! otherwise, return so caller can print out a better error message
 ! about which time it is trying to write.
-if ((io /= 0) .and. (.not. present(ios))) then
+if ((io /= 0) .and. (.not. present(ios_out))) then
 
    ! try to extract filename associated with unit to give context
    ! for which file we are trying to write to.

Modified: DART/trunk/time_manager/time_manager_mod.html
===================================================================
--- DART/trunk/time_manager/time_manager_mod.html	2009-11-30 21:37:15 UTC (rev 4173)
+++ DART/trunk/time_manager/time_manager_mod.html	2009-12-01 17:03:35 UTC (rev 4174)
@@ -802,19 +802,18 @@
 <A NAME="write_time"></A>
 <P></P><HR><P></P>
 <div class=routine>
-<em class=call> call write_time(file_unit, time [, form, ios])</em>
+<em class=call> call write_time(file_unit, time [, form, ios_out])</em>
 <pre>
 integer,          intent(in)               :: <em class=code>file_unit</em>
 type(time_type),  intent(in)               :: <em class=code>time</em>
 character(len=*), intent(in),  optional    :: <em class=optionalcode>form</em>
-integer,          intent(out), optional    :: <em class=optionalcode>ios</em>
+integer,          intent(out), optional    :: <em class=optionalcode>ios_out</em>
 </pre></div>
-<!-- ios should be ios_out to match read_time (or visa versa) -->
 <H3 class=indent1>Description</H3>
 <P>
 Write a time to an already open file unit.  The optional 'form'
 argument controls whether it is formatted or unformatted.
-On error, the optional 'ios' argument returns the error code; otherwise
+On error, the optional 'ios_out' argument returns the error code; otherwise
 a fatal error is triggered.
 </P>
 <TABLE width=100% border=0 summary="" celpadding=3>
@@ -825,7 +824,7 @@
 <TR><TD valign=top><em class=optionalcode>form</em></TD>
     <TD>String format specifier; either 'unformatted' or 'formatted'.
         Defaults to 'formatted'.</TD><TR>
-<TR><TD valign=top><em class=optionalcode>ios</em></TD>
+<TR><TD valign=top><em class=optionalcode>ios_out</em></TD>
     <TD>If specified, on error the i/o status error code is returned here.
         Otherwise, the standard error handler is called and the 
         program exits. </TD><TR>


More information about the Dart-dev mailing list