[Dart-dev] [3931] DART/trunk/utilities/utilities_mod.f90: New routine for opening a text file and returning each line, one at a time .
nancy at ucar.edu
nancy at ucar.edu
Fri Jun 19 09:26:05 MDT 2009
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20090619/e3e7f0c4/attachment.html
-------------- next part --------------
Modified: DART/trunk/utilities/utilities_mod.f90
===================================================================
--- DART/trunk/utilities/utilities_mod.f90 2009-06-12 21:41:36 UTC (rev 3930)
+++ DART/trunk/utilities/utilities_mod.f90 2009-06-19 15:26:03 UTC (rev 3931)
@@ -72,7 +72,7 @@
! logfileunit Global integer unit numbers for the log file and
! nmlfileunit for the namelist file (which defaults to same as log)
!
-! to_upper converts a character string to uppercase
+! to_upper converts a character string to uppercase.
!
! find_textfile_dims finds number of lines and max line length in a
! text file. Used so we can record the namelist
@@ -82,6 +82,10 @@
! a single text variable ... to record in the
! netcdf output files.
!
+! get_next_filename returns the next filename, given the name of
+! an ascii file which contains a filename per line.
+! it returns an empty string at end of list.
+!
! is_longitude_between checks whether a given longitude is between
! the two given limits, starting at the first and
! going EAST until reaching the second. the end
@@ -141,7 +145,7 @@
find_namelist_in_file, check_namelist_read, do_nml_term, &
set_tasknum, set_output, do_output, set_nml_output, do_nml_file, &
E_DBG, E_MSG, E_WARN, E_ERR, DEBUG, MESSAGE, WARNING, FATAL, &
- is_longitude_between
+ is_longitude_between, get_next_filename
! this routine is either in the null_mpi_utilities_mod.f90, or in
! the mpi_utilities_mod.f90 file, but it is not a module subroutine.
@@ -1027,7 +1031,8 @@
case default
call error_handler(E_ERR, 'set_nml_output', &
- 'unrecognized input string: '//trim(nmlstring))
+ 'unrecognized input string: '//trim(nmlstring), &
+ source, revision, revdate)
end select
@@ -1254,9 +1259,9 @@
if (len(nml_name) >= 10) then
if ((nml_name(1:10) == 'filter_nml') .and. (index(nml_string,'inf_start_from_restart') > 0)) then
write(msgstring, *) 'inf_start_from_restart obsolete'
- call error_handler(E_MSG, 'filter_nml: ', msgstring, "", "", "")
+ call error_handler(E_MSG, 'filter_nml: ', msgstring)
write(msgstring, *) 'use inf_initial_from_restart and inf_sd_initial_from_restart'
- call error_handler(E_MSG, 'filter_nml: ', msgstring, "", "", "")
+ call error_handler(E_MSG, 'filter_nml: ', msgstring)
endif
endif
write(msgstring, *) 'INVALID NAMELIST ENTRY: ', trim(nml_string), ' in namelist ', trim(nml_name)
@@ -1356,7 +1361,8 @@
if (ios < 0) exit READLOOP ! end of file
if (ios > 0) then
write(error_msg,'(A,'' read around line '',i8)')trim(fname),nlines
- call error_handler(E_ERR,'find_textfile_dims', error_msg)
+ call error_handler(E_ERR,'find_textfile_dims', error_msg, &
+ source, revision, revdate)
endif
nlines = nlines + 1
@@ -1413,7 +1419,8 @@
if ( ios /= 0 ) then
write(string,'(A,'' read around line '',i8)')trim(fname),i
- call error_handler(E_ERR,'file_to_text', trim(string))
+ call error_handler(E_ERR,'file_to_text', trim(string), &
+ source, revision, revdate)
endif
enddo PARSELOOP
@@ -1424,6 +1431,49 @@
!#######################################################################
+function get_next_filename( listname, index )
+
+! Arguments are the name of a file which contains a list of filenames.
+! This routine opens the listfile, and returns the index-th one.
+!
+character(len=*), intent(in) :: listname
+integer, intent(in) :: index
+character(len=128) :: get_next_filename
+
+integer :: i, ios, funit
+integer :: mynlines, mylinelen, strlen
+
+character(len=512) :: string
+
+funit = open_file(listname, form="FORMATTED", action="READ")
+
+PARSELOOP : do i=1, index
+
+ read(funit, '(A)', iostat=ios) string
+
+ ! reached end of file, return '' as indicator.
+ if ( ios /= 0 ) then
+ get_next_filename = ''
+ call close_file(funit)
+ return
+ endif
+
+enddo PARSELOOP
+
+! check for length problems
+if (len_trim(string) > len(get_next_filename)) then
+ call error_handler(E_ERR, 'get_next_filename', &
+ 'maximum filename length of 128 exceeded', &
+ source, revision, revdate)
+endif
+
+get_next_filename = string(1:len(get_next_filename))
+call close_file(funit)
+
+end function get_next_filename
+
+!#######################################################################
+
function is_longitude_between (lon, minlon, maxlon, doradians)
! uniform way to treat longitude ranges, in degrees, on a globe.
More information about the Dart-dev
mailing list