[Dart-dev] DART/branches Revision: 13045

dart at ucar.edu dart at ucar.edu
Thu Mar 21 10:54:38 MDT 2019


nancy at ucar.edu
2019-03-21 10:54:38 -0600 (Thu, 21 Mar 2019)
417
complete overhaul of the utilities module.  
prompted by the possibility of recursive calls to initialize 
by routines that are used in the init routine.  

simplify the code by consolidating repeated code sections 
into smaller routines; remove unused code; reformat into
our current coding style guidelines.  

functionally should be the same from the outside.  
internally should be simpler to read and maintain.




Modified: DART/branches/recam/assimilation_code/modules/utilities/utilities_mod.f90
===================================================================
--- DART/branches/recam/assimilation_code/modules/utilities/utilities_mod.f90	2019-03-21 15:58:08 UTC (rev 13044)
+++ DART/branches/recam/assimilation_code/modules/utilities/utilities_mod.f90	2019-03-21 16:54:38 UTC (rev 13045)
@@ -594,14 +594,14 @@
 integer :: get_unit
 
 integer :: i, iunit
-logical :: already_open
+logical :: open
 
 if ( .not. module_initialized ) call fatal_not_initialized('get_unit')
 
 iunit = -1
 do i = 10, 80
-   inquire (i, opened=already_open)
-   if (.not. already_open) then
+   inquire (i, opened=open)
+   if (.not. open) then
       get_unit = i
       return
    endif
@@ -1379,9 +1379,8 @@
 
 !-----------------------------------------------------------------------
 !> Arguments are the name of a file which contains a list of filenames.
-!> This routine opens the listfile, and returns the index-th one.
-!>@todo FIXME this should return 512 chars, not 256.  will that 
-!>break some of the calling code?
+!> This routine opens the listfile, and returns the lineindex-th one.
+!> We agreed to support filenames/pathnames up to 256.
 
 function get_next_filename( listname, lineindex )
 
@@ -1390,11 +1389,10 @@
 character(len=256)            :: get_next_filename
 
 integer :: i, ios, funit
+character(len=512) :: string
 
-character(len=512)  :: string
+funit = open_file(listname, form="FORMATTED", action="READ")
 
-funit   = open_file(listname, form="FORMATTED", action="READ")
-
 do i=1, lineindex
 
    read(funit, '(A)', iostat=ios) string
@@ -1408,17 +1406,20 @@
 
 enddo
 
-! check for length problems
-if (len_trim(string) > len(get_next_filename)) then
+call close_file(funit)
+
+
+! check for length problems after stripping off any leading blanks.
+! @todo FIXME define 256 as a constant - MAXFILENAMELEN or something
+if (len_trim(adjustl(string)) > 256) then
    call error_handler(E_ERR, 'get_next_filename', &
                       'maximum filename length of 256 exceeded', &
                       source, revision, revdate)   
 endif
 
-! is this overly complicated?  either just adjustl() or nothing?
-get_next_filename = adjustl(string(1:len(get_next_filename)))
-call close_file(funit)
 
+get_next_filename = adjustl(string)
+
 end function get_next_filename
 
 
@@ -1685,6 +1686,7 @@
 ! FIXME: THIS FUNCTION IS DEPRECATED AND SHOULD BE REMOVED.
 ! FIXME: THIS FUNCTION IS DEPRECATED AND SHOULD BE REMOVED.
 ! FIXME: THIS FUNCTION IS DEPRECATED AND SHOULD BE REMOVED.
+! (only used by obs_seq_to_netcdf currently.)
 
 !----------------------------------------------------------------------
 ! The file name can take one of three forms:
@@ -2648,7 +2650,7 @@
 
 integer, intent(in) :: iunit
 
-logical :: exists, connected, named_file
+logical :: exists, open, named_file
 integer :: ios, reclen, nextrecnum
 character(len=256) :: file_name
 character(len=32)  :: ynu     ! YES, NO, UNDEFINED ... among others
@@ -2657,8 +2659,8 @@
 
 call output_unit_attribs(ios, 'for unit', '', ivalue=iunit)
 
-inquire(iunit, opened = connected, iostat=ios)
-call output_unit_attribs(ios, 'connected', '', lvalue=connected)
+inquire(iunit, opened = open, iostat=ios)
+call output_unit_attribs(ios, 'opened', '', lvalue=open)
 
 inquire(iunit, named = named_file, iostat=ios)


More information about the Dart-dev mailing list