[Dart-dev] [3212] DART/branches/nancy_work/preprocess/preprocess.f90: My test branch: new code to automatically add the module code to

nancy at subversion.ucar.edu nancy at subversion.ucar.edu
Tue Feb 5 15:14:03 MST 2008


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20080205/b2bf8773/attachment.html
-------------- next part --------------
Modified: DART/branches/nancy_work/preprocess/preprocess.f90
===================================================================
--- DART/branches/nancy_work/preprocess/preprocess.f90	2008-02-05 22:00:46 UTC (rev 3211)
+++ DART/branches/nancy_work/preprocess/preprocess.f90	2008-02-05 22:14:02 UTC (rev 3212)
@@ -40,18 +40,21 @@
 integer, parameter   :: max_kinds = 10000
 character(len = 256) :: line, test, kind_string(max_kinds), &
                         raw_kind_item(max_kinds), t_string
-integer              :: iunit, ierr, io, i, j, k, l_kind_string
+integer              :: iunit, ierr, io, i, j, k, l, l_kind_string
 integer              :: num_kinds_found
+logical              :: duplicate
 character(len = 169) :: err_string
 
 ! List of the DART PREPROCESS strings
-character(len = 29) :: preprocess_string(7) = (/'USE FOR OBS_KIND_MOD         ', &
-                                                'USE OF SPECIAL OBS_DEF MODULE', &
-                                                'GET_EXPECTED_OBS_FROM_DEF    ', &
-                                                'READ_OBS_DEF                 ', &
-                                                'WRITE_OBS_DEF                ', &
-                                                'INTERACTIVE_OBS_DEF          ', &
-                                                'THE SEVENTH ONE IS UNDEFINED '/)
+character(len = 29) :: preprocess_string(8) = (/ &
+      'MODULE CODE                  ', &
+      'USE FOR OBS_KIND_MOD         ', &
+      'USE OF SPECIAL OBS_DEF MODULE', &
+      'GET_EXPECTED_OBS_FROM_DEF    ', &
+      'READ_OBS_DEF                 ', &
+      'WRITE_OBS_DEF                ', &
+      'INTERACTIVE_OBS_DEF          ', &
+      'THE EIGHTH ONE IS UNDEFINED  '/)
 
 integer :: num_input_files = 0
 integer :: obs_def_in_unit, obs_def_out_unit, obs_kind_in_unit, obs_kind_out_unit, in_unit
@@ -193,7 +196,8 @@
       if(test(1:33) == '! BEGIN DART PREPROCESS KIND LIST') exit FIND_KIND_LIST
    end do FIND_KIND_LIST
 
-   ! Subsequent lines contain the kind_identifier (same as kind_string), and raw_kind_ident separated by commas
+   ! Subsequent lines contain the kind_identifier (same as kind_string), and 
+   ! raw_kind_ident separated by commas
    EXTRACT_KINDS: do
       read(in_unit, 222, IOSTAT = ierr) line
       ! If end of file, then the input file is incomplete or weird stuff has happened
@@ -209,7 +213,8 @@
 
       ! Found a kind; increment the count
       num_kinds_found = num_kinds_found + 1
-      ! Otherwise this line should contain kind_identifier (same as kind_string),  raw_kind_item with leading comment
+      ! Otherwise this line should contain kind_identifier (same as kind_string),  
+      ! raw_kind_item with leading comment
       ! Get rid of the leading comment and subsequent space
       test = adjustl(line(2:))
       ! Compute the length of the kind_string by seeking comma
@@ -326,15 +331,15 @@
 
 ! There are five special code sections (ITEMS) in the obs_def file at present
 ! That copy code in from the special type specific obs_kind modules
-! Loop goes to 6 so that stuff after the last item is also copied to the final obs_def_mod.f90
-ITEMS: do i = 1, 7
+! Loop goes to 8 so that stuff after the last item is also copied to the final obs_def_mod.f90
+ITEMS: do i = 1, 8
    READ_LINE: do
       read(obs_def_in_unit, 222, IOSTAT = ierr) line
       222 format(A256)
 
-      ! Check for end of file (it's an error if this before all 5 DART ITEMS have been passed)
-      if(ierr /=0) then
-         if(i < 7) then
+      ! Check for end of file (it's an error if this is before the first 7 DART ITEMS have been passed)
+      if(ierr /= 0) then
+         if(i < 8) then
             call error_handler(E_ERR, 'preprocess', 'Input DEFAULT obs_def file ended unexpectedly', &
                source, revision, revdate)
          else
@@ -352,9 +357,27 @@
       if(trim(test) == trim(t_string)) exit READ_LINE
    end do READ_LINE
 
-   ! Insert the code for this ITEM from each of the requested obs_kind 'modules'
-   ! The first Entry does NOT copy code but creates code from the kind list
-   if(i /= 1) then 
+   ! The 'USE FOR OBS_KIND_MOD' section is handled differently; lines are not
+   ! copied, they are generated based on the list of types and kinds.
+   if(i == 2) then
+     ! Create use statements for both the KIND_ kinds and the individual
+     ! observation type strings.
+     do k = 1, num_kinds_found
+        write(obs_def_out_unit, 21) 'use obs_kind_mod, only : ' // trim(kind_string(k))
+     end do
+     do k = 1, num_kinds_found
+        duplicate = .false.
+        do l = 1, k-1
+           if (trim(raw_kind_item(k)) == trim(raw_kind_item(l))) then
+              duplicate = .true.
+              exit 
+           endif
+        end do
+        if (.not. duplicate) &
+           write(obs_def_out_unit, 21) 'use obs_kind_mod, only : ' // trim(raw_kind_item(k))
+     end do
+   else
+      ! Insert the code for this ITEM from each of the requested obs_kind 'modules'
       do j = 1, num_input_files
          ! Since there might someday be a lot of these, open and close them each time needed
          if(file_exist(trim(input_files(j)))) then
@@ -400,21 +423,21 @@
             if(trim(test) == trim(t_string)) exit COPY_ITEM
      
             ! Write the line to the output obs_def_mod.f90 file
-            write(obs_def_out_unit, 21) trim(line(2:))
+            ! The module code, if present, is copied verbatim.  The rest of the lines
+            ! are preceeded by a ! in col 1, so that must be stripped off.
+            if (i == 1) then
+               write(obs_def_out_unit, 21) trim(line)
+            else
+               write(obs_def_out_unit, 21) trim(line(2:))
+            endif
          end do COPY_ITEM
       
          ! Got everything from this file, move along
          close(in_unit)
       end do
-
-   ! If this is the first substitution spot in the DEFAULT file, create new code from kind list
-   ! in the individual special obs_def file
-   else
-      do k = 1, num_kinds_found
-         write(obs_def_out_unit, 21) 'use obs_kind_mod, only : ' // trim(kind_string(k))
-      end do
    endif
 
+
 end do ITEMS
 
 !_______________________________________________________________________________________


More information about the Dart-dev mailing list