[Dart-dev] [9744] DART/trunk/observations/NCEP/ascii_to_obs/real_obs_mod.f90: Now reports the offending line number if the read fails.

nancy at ucar.edu nancy at ucar.edu
Fri Feb 12 11:54:37 MST 2016


Revision: 9744
Author:   thoar
Date:     2016-02-12 11:54:37 -0700 (Fri, 12 Feb 2016)
Log Message:
-----------
Now reports the offending line number if the read fails.
Removed unused routines/modules.
Now uses the error_handler for all messages - since this frequently
gets called in a script, it is nice to have the run-time messages
in the dart log file as well. Changed some duplicate debug statements
to be unique and hopefully a bit more informative.

Modified Paths:
--------------
    DART/trunk/observations/NCEP/ascii_to_obs/real_obs_mod.f90

-------------- next part --------------
Modified: DART/trunk/observations/NCEP/ascii_to_obs/real_obs_mod.f90
===================================================================
--- DART/trunk/observations/NCEP/ascii_to_obs/real_obs_mod.f90	2016-02-12 18:38:02 UTC (rev 9743)
+++ DART/trunk/observations/NCEP/ascii_to_obs/real_obs_mod.f90	2016-02-12 18:54:37 UTC (rev 9744)
@@ -7,18 +7,12 @@
 module real_obs_mod
 
 use types_mod,        only : r8, rad2deg, PI
-use obs_def_mod,      only : obs_def_type, get_obs_def_time, read_obs_def, &
-                             write_obs_def, destroy_obs_def, interactive_obs_def, &
-                             copy_obs_def, set_obs_def_time, set_obs_def_kind, &
-                             set_obs_def_error_variance, set_obs_def_location
 use time_manager_mod, only : time_type, operator(>), operator(<), operator(>=), &
                              operator(/=), set_date, set_calendar_type, get_time, &
-                             get_date, set_time, GREGORIAN, increment_time
-use    utilities_mod, only : get_unit, open_file, close_file, file_exist, &
-                             register_module, error_handler, &
+                             set_time, GREGORIAN, increment_time
+use    utilities_mod, only : get_unit, register_module, error_handler, &
                              E_ERR, E_MSG, timestamp, is_longitude_between
-use     location_mod, only : location_type, set_location, &
-                             VERTISPRESSURE, VERTISSURFACE
+use     location_mod, only : VERTISPRESSURE, VERTISSURFACE
 use obs_sequence_mod, only : init_obs_sequence, init_obs, obs_sequence_type, obs_type, &
                              set_copy_meta_data, set_qc_meta_data
 
@@ -93,6 +87,8 @@
 integer :: print_every_Nth  = 10000
 logical :: debug            = .false.
 
+character(len=512) :: msgstring1, msgstring2, msgstring3
+
 !-------------------------------------------------
 
 contains
@@ -118,11 +114,11 @@
 
 
 type(obs_type) :: obs, prev_obs
-integer :: i, num_copies, num_qc
+integer :: i, io, num_copies, num_qc
 integer :: days, seconds
 integer :: day0, sec0
 integer :: hour, imin, sec
-integer :: obs_num, calender_type
+integer :: obs_num, calender_type, read_counter
 type(time_type) :: current_day, time_obs, prev_time
 
 integer, parameter :: num_fail_kinds = 8
@@ -194,7 +190,8 @@
 call get_time(current_day, sec0, day0)
 
 !   output the day and sec.
-print*, 'processing data for day, sec= ', day0, sec0
+write(msgstring1,*) 'processing data for day, sec= ', day0, sec0
+call error_handler(E_MSG,'real_obs_sequence',msgstring1)
 
 ! open NCEP observation data file
 
@@ -202,7 +199,8 @@
 obsfile   = trim(adjustl(ObsBase))//obsdate//hourt
 obs_unit  = get_unit()
 open(unit = obs_unit, file = obsfile, form='formatted', status='old')
-print*, 'input file opened= ', trim(obsfile)
+write(msgstring1,*) 'input file opened >'//trim(obsfile)//'<'
+call error_handler(E_MSG,'real_obs_sequence',msgstring1)
 rewind (obs_unit)
 
 !print*, 'ncep obsdates = ', obsdate
@@ -214,26 +212,41 @@
 !  loop over all observations within the file
 !------------------------------------------------------------------------------
 
+read_counter = 1
+
 obsloop:  do
 
-   read(obs_unit,880,end=200) obs_err, lon, lat, lev, zob, zob2, rcount, time, &
+   read(obs_unit,880,end=200,iostat=io) obs_err, lon, lat, lev, zob, zob2, rcount, time, &
                               obstype, iqc, subset, pc
+   if (io /= 0) then
+      write(msgstring1,*)'read error was ',io,' for line ',read_counter
+      call error_handler(E_ERR,'real_obs_sequence', msgstring1, source, revision, revdate)
+   endif
 
  880 format(f4.2,2f9.4,e12.5,f7.2,f7.2,f9.0,f7.3,i4,i2,1x,a6,i2)
 
+   read_counter = read_counter + 1
+
 !   A 'day' is from 03:01Z of one day through 03Z of the next.
 !   skip the observations at exact 03Z of the beginning of the day
 !   (obs at 03Z the next day have a time of 27.)
 !------------------------------------------------------------------------------
    if(time == 3.0_r8) then
-      if (debug) write(*,*) 'invalid time.  hours = ', time
+      if (debug) then
+         write(msgstring1,*) 'invalid time.  hours = ', time
+         call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+      endif
       iskip(fail_3Z) = iskip(fail_3Z) + 1
       cycle obsloop 
    endif 
 
    !  select the obs for the time window
    if(time < bin_beg .or. time > bin_end) then
-      if (debug) write(*,*) 'invalid time.  hours = ', time
+      if (debug) then
+         write(msgstring1,*) 'invalid time.  hours = ', time
+         write(msgstring2,*) 'desired range is ', bin_beg, ' to ', bin_end
+         call error_handler(E_MSG,'real_obs_sequence',msgstring1, msgstring2)
+      endif
       iskip(fail_timerange) = iskip(fail_timerange) + 1
       cycle obsloop
    endif
@@ -241,7 +254,10 @@
    ! verify the location is not outside valid limits
    if((lon > 360.0_r8) .or. (lon <   0.0_r8) .or.  &
       (lat >  90.0_r8) .or. (lat < -90.0_r8)) then
-      if (debug) write(*,*) 'invalid location.  lon,lat = ', lon, lat
+      if (debug) then
+         write(msgstring1,*) 'invalid location: lon,lat = ', lon, lat
+         call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+      endif
       iskip(fail_badloc) = iskip(fail_badloc) + 1
       cycle obsloop
    endif
@@ -249,7 +265,10 @@
    ! reject observations outside the bounding box
    if(lat < lat1 .or. lat > lat2 .or. & 
      .not. is_longitude_between(lon, lon1, lon2)) then
-      if (debug) write(*,*) 'invalid location.  lon,lat = ', lon, lat
+      if (debug) then
+         write(msgstring1,*) 'not-in-domain location: lon,lat = ', lon, lat
+         call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+      endif
       iskip(fail_areabox) = iskip(fail_areabox) + 1
       cycle obsloop
    endif
@@ -265,10 +284,16 @@
    ! still the pole but isn't going to round out of range.
    if      (lat >=  89.9999_r8) then
      lat = lat - 1.0e-12_r8
-     if (debug) write(*,*) 'lat adjusted down, now ', lat
+     if (debug) then
+        write(msgstring1,*) 'lat adjusted down, now ', lat
+        call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+     endif
    else if (lat <= -89.9999_r8) then
      lat = lat + 1.0e-12_r8
-     if (debug) write(*,*) 'lat adjusted   up, now ', lat
+     if (debug) then
+        write(msgstring1,*) 'lat adjusted   up, now ', lat
+        call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+     endif
    endif
 
    obs_prof = rcount/1000000
@@ -324,11 +349,11 @@
        if(obstype == 180 .or. obstype == 182) obs_kind = MARINE_SFC_PRESSURE 
        if(obstype == 181                    ) obs_kind = LAND_SFC_PRESSURE 
      else
-     if(obstype == 120                    ) obs_kind = RADIOSONDE_SURFACE_ALTIMETER
-     if(obstype == 180 .or. obstype == 182) obs_kind = MARINE_SFC_ALTIMETER
-     if(obstype == 181                    ) obs_kind = LAND_SFC_ALTIMETER
+       if(obstype == 120                    ) obs_kind = RADIOSONDE_SURFACE_ALTIMETER
+       if(obstype == 180 .or. obstype == 182) obs_kind = MARINE_SFC_ALTIMETER
+       if(obstype == 181                    ) obs_kind = LAND_SFC_ALTIMETER
+     endif
    endif
-   endif
 
    if(obs_prof == 2) then
      obs_kind_gen = KIND_U_WIND_COMPONENT
@@ -370,10 +395,16 @@
       ! types which are not desired.  for now, avoid giving them the wrong type
       ! and quietly loop.
       if (obs_prof == 5) then
-         if (debug) write(*,*) 'unwanted moisture obs_prof, skipping', obs_prof, obstype, zob2
+         if (debug) then
+            write(msgstring1,*) 'unwanted moisture obs_prof, skipping', obs_prof, obstype, zob2
+            call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+         endif
          iskip(fail_moisttype) = iskip(fail_moisttype) + 1
       else
-         if (debug) write(*,*) 'unrecognized obs_prof or obstype, skipping', obs_prof, obstype
+         if (debug) then
+            write(msgstring1,*) 'unrecognized obs_prof or obstype, skipping', obs_prof, obstype
+            call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+         endif
          iskip(fail_badkind) = iskip(fail_badkind) + 1
       endif
       cycle obsloop 
@@ -415,7 +446,10 @@
 
       ! if pass is still true, we want to ignore this obs.
       if(pass) then
-         if (debug) write(*,*) 'obs skipped because not on wanted list.  subset, obs_kind = ', subset, obs_kind_gen
+         if (debug) then
+            write(msgstring1,*) 'obs skipped because not on wanted list.  subset, obs_kind = ', subset, obs_kind_gen
+            call error_handler(E_MSG,'real_obs_sequence',msgstring1)
+         endif
          iskip(fail_notwanted) = iskip(fail_notwanted) + 1
          cycle obsloop 
       endif
@@ -439,8 +473,10 @@
        endif
    endif
    if(obs_num == max_num) then
-      print*, 'Max limit for observation count reached.  Increase value in namelist'
-      stop
+      write(msgstring1,*)'limit for observation count (',max_num,') reached.'
+      write(msgstring2,*)'Increase "max_num" in namelist and try again.'
+      call error_handler(E_ERR, 'read_obs_sequence', msgstring1, &
+                 source, revision, revdate, text2=msgstring2)
    endif
 
    ! set vertical coordinate for upper-air observations
@@ -515,10 +551,17 @@
 
 close(obs_unit)
 
-print*, 'date ', obsdate
-print*, 'num obs used = ', obs_num, ' total obs skipped = ', sum(iskip)
+write(msgstring1,*) 'Summary for '//trim(obsfile)
+write(msgstring2,*) 'date ', obsdate
+write(msgstring3,*) 'num obs used = ', obs_num, ' total obs skipped = ', sum(iskip)
+call error_handler(E_MSG,'real_obs_sequence', msgstring1, &
+           text2=msgstring2, text3=msgstring3)
+
 do i=1, num_fail_kinds
-  if (iskip(i) >  0) print *, iskip(i), 'skipped because ', skip_reasons(i)
+  if (iskip(i) >  0) then
+     write(msgstring1,*) iskip(i), 'skipped because ', skip_reasons(i)
+     call error_handler(E_MSG,' ',msgstring1)
+  endif
 enddo
 
 end function real_obs_sequence


More information about the Dart-dev mailing list