[Dart-dev] [4283] DART/trunk/models/wrf: Updated wrf model_mod:

nancy at ucar.edu nancy at ucar.edu
Tue Feb 16 15:51:57 MST 2010


Revision: 4283
Author:   nancy
Date:     2010-02-16 15:51:57 -0700 (Tue, 16 Feb 2010)
Log Message:
-----------
Updated wrf model_mod: 

Contains Ryan's new vortex center-finding code and a max 
surface height difference limit.  The default is to use the old code
so it's backwards compatible; edit the code and set 'use_old_vortex'
to .false. to try the new vortex code.  The default for the surface
height limit is -1, which disables the check so it's also backwards
compatible.

New namelist items:  sfc_elev_max_diff, circulation_pres_level, and
circulation_radius.  see docs for usage.

The routine which tests the height difference between the model surface
and the elevation of a surface observation is called 'height_diff_check'
and is public.

The sizes of local variables inside the spline routines have been
increased.

The old vortex code has changed in one place - if the center is located
on any of the edges of the search box, the forward operator will return
a failure code instead of returning success and the same location as
the incoming observation.

Other changes:

input.nml - the radar section has been updated; _r8 is not legal on
numeric constants in a namelist file.  each namelist is terminated
by a slash on a separate line in a consistent column.  two new
sections have been added:  &dart_to_wrf_nml and &replace_wrf_fields_nml.
see the docs for use.

dart_to_wrf - requires a namelist now.  the namelist settings allow
restart files to be converted to wrf netcdf files for continuing with
a free run after an assimilation.

replace_wrf_fields - a fortran version of the ncl scripts which
take 2 netcdf files and replace the fields from one into the other.
namelist options control which fields are copied, and whether a
missing field is simply skipped or becomes a fatal error.  the
field names can either be specified directly in the namelist or
can be stored in a text file, one fieldname per line.

Modified Paths:
--------------
    DART/trunk/models/wrf/WRF_DART_utilities/add_pert_where_high_refl.f90
    DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.f90
    DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.html
    DART/trunk/models/wrf/WRF_DART_utilities/ensemble_init.f90
    DART/trunk/models/wrf/WRF_DART_utilities/extract.f90
    DART/trunk/models/wrf/WRF_DART_utilities/grid_refl_obs.f90
    DART/trunk/models/wrf/WRF_DART_utilities/wrf_to_dart.f90
    DART/trunk/models/wrf/model_mod.f90
    DART/trunk/models/wrf/model_mod.html
    DART/trunk/models/wrf/model_mod.nml
    DART/trunk/models/wrf/work/input.nml
    DART/trunk/models/wrf/work/quickbuild.csh

Added Paths:
-----------
    DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.nml
    DART/trunk/models/wrf/WRF_DART_utilities/replace_wrf_fields.f90
    DART/trunk/models/wrf/WRF_DART_utilities/replace_wrf_fields.html
    DART/trunk/models/wrf/WRF_DART_utilities/replace_wrf_fields.nml
    DART/trunk/models/wrf/work/mkmf_replace_wrf_fields
    DART/trunk/models/wrf/work/path_names_replace_wrf_fields

-------------- next part --------------
Modified: DART/trunk/models/wrf/WRF_DART_utilities/add_pert_where_high_refl.f90
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/add_pert_where_high_refl.f90	2010-02-16 20:46:34 UTC (rev 4282)
+++ DART/trunk/models/wrf/WRF_DART_utilities/add_pert_where_high_refl.f90	2010-02-16 22:51:57 UTC (rev 4283)
@@ -32,8 +32,7 @@
 ! output:
 
 use        types_mod, only : r8, gravity, t_kelvin, ps0, gas_constant, gas_constant_v
-use    utilities_mod, only : error_handler, E_ERR, E_MSG, initialize_utilities, &
-                             timestamp, register_module, logfileunit, file_exist
+use    utilities_mod, only : error_handler, E_ERR
 use    random_nr_mod, only : random_seq_type, init_ran1
 use   random_seq_mod, only : random_gaussian
 use    netcdf
@@ -43,7 +42,7 @@
 
 ! version controlled file description for error handling, do not edit
 character(len=128), parameter :: &
-   source   = "$URL$", &
+   source   =  "$URL$", &
    revision = "$Revision$", &
    revdate  = "$Date$"
 

Modified: DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.f90
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.f90	2010-02-16 20:46:34 UTC (rev 4282)
+++ DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.f90	2010-02-16 22:51:57 UTC (rev 4283)
@@ -11,25 +11,18 @@
 ! $Date$
 
 use        types_mod, only : r8, missing_r8
-use time_manager_mod, only : time_type, write_time, read_time, get_date, set_date, operator(-), &
-                             get_time, print_time, set_calendar_type, GREGORIAN, julian_day
-use    utilities_mod, only : get_unit, file_exist, open_file, close_file, &
-                             error_handler, E_ERR, E_MSG, initialize_utilities, &
-                             register_module, logfileunit, nmlfileunit, timestamp, &
+use time_manager_mod, only : time_type, write_time, get_date, julian_day
+use    utilities_mod, only : get_unit, error_handler, E_ERR, E_MSG, &
+                             initialize_utilities, register_module, &
+                             logfileunit, nmlfileunit, &
                              find_namelist_in_file, check_namelist_read, &
-                             nc_check, do_nml_file, do_nml_term
-use  assim_model_mod, only : open_restart_read, open_restart_write, aread_state_restart, &
-                             awrite_state_restart
-use model_mod, only        : max_state_variables,  &
-                             num_state_table_columns, read_wrf_dimensions, &
-                             num_bounds_table_columns, &
-                             get_number_of_wrf_variables,  &
-                             get_variable_bounds,          &
-                             set_variable_bound_defaults,          &
-                             get_variable_size_from_file, wrf_dom, &
-                             fill_default_state_table, &
-                             trans_1Dto3D, trans_1Dto2D,&
-                             set_wrf_date
+                             nc_check, do_nml_file, do_nml_term, finalize_utilities
+use  assim_model_mod, only : static_init_assim_model, open_restart_read, &
+                             aread_state_restart, close_restart
+use        model_mod, only : max_state_variables, num_state_table_columns, &
+                             get_wrf_state_variables, get_number_domains, &
+                             get_model_size, get_wrf_static_data, trans_1Dto3D, &
+                             trans_1Dto2D, set_wrf_date, wrf_static_data_for_dart
 
 use                          netcdf
 
@@ -43,299 +36,215 @@
 
 
 !-----------------------------------------------------------------------
-! Model namelist parameters with default values.
+! dart_to_wrf namelist parameters with default values.
 !-----------------------------------------------------------------------
 
-logical :: output_state_vector  = .false.  ! state vs. prognostic format
-logical :: default_state_variables = .true.   ! use default state list?
-character(len=129) :: wrf_state_variables(num_state_table_columns,max_state_variables) = 'NULL'
-character(len=129) :: wrf_state_bounds(num_bounds_table_columns,max_state_variables) = 'NULL'
-integer :: num_moist_vars       = 3
-integer :: num_domains          = 1
-integer :: calendar_type        = GREGORIAN
-integer :: assimilation_period_seconds = 21600
-logical :: surf_obs             = .true.
-logical :: soil_data            = .true.
-logical :: h_diab               = .false.
-logical :: allow_obs_below_vol  = .false.
-character(len = 72) :: adv_mod_command = './wrf.exe'
-real (kind=r8) :: center_search_half_length = 500000.0_r8
-integer :: center_spline_grid_scale = 10
-integer :: vert_localization_coord  =  3  ! 1,2,3 == level,pressure,height
-! candidates for including in the WRF netcdf files:
-logical :: polar = .false.         ! wrap over the poles
-logical :: periodic_x = .false.    ! wrap in longitude or x
-logical :: periodic_y = .false.    ! used for single column model, wrap in y
-!JPH -- single column model flag 
-logical :: scm        = .false.    ! using the single column model
+logical :: model_advance_file = .TRUE.
+character(len=128) :: dart_restart_name = 'dart_wrf_vector'
+character(len=72)  :: adv_mod_command   = './wrf.exe'
 
+namelist /dart_to_wrf_nml/ model_advance_file, dart_restart_name, adv_mod_command
 
-namelist /model_nml/ output_state_vector, num_moist_vars, &
-                     num_domains, calendar_type, surf_obs, soil_data, h_diab, &
-                     default_state_variables, wrf_state_variables, &
-                     wrf_state_bounds, &
-                     adv_mod_command, assimilation_period_seconds, &
-                     allow_obs_below_vol, vert_localization_coord, &
-                     center_search_half_length, center_spline_grid_scale, &
-                     polar, periodic_x, periodic_y, scm
+!-------------------------------------------------------------
 
+logical, parameter :: debug = .true.
 
-!-------------------------------------------------------------
+type(wrf_static_data_for_dart) :: wrf
 
-type(wrf_dom) :: wrf
+character(len=129) :: wrf_state_variables(num_state_table_columns,max_state_variables)
 
 real(r8), pointer :: dart(:)
 real(r8), pointer :: wrf_var_3d(:,:,:), wrf_var_2d(:,:)
-real(r8)          :: lb, ub
 type(time_type)   :: dart_time(2)
-integer           :: number_dart_values, ndays, &
+integer            :: number_dart_values, num_domains, ndays, &
                      year, month, day, hour, minute, second
-integer           :: ind, dart_ind, my_index
+integer            :: ind, dart_ind, my_index, io
 character(len=19) :: timestring
-character(len=1)  :: idom
+character(len=2)   :: idom
 
-logical, parameter :: debug = .true.
-integer            :: ncid(50), io, var_id, id, iunit, dart_unit
-integer            :: var_element_list(max_state_variables)
+integer            :: ncid(50), var_id, id, iunit, dart_unit
 
-write(*,*) 'DART to WRF' !(.false./F)?'
+write(*,*) 'DART to WRF'
 
 call initialize_utilities('dart_to_wrf')
 call register_module(source, revision, revdate)
 
-! Begin by reading the namelist input
-call find_namelist_in_file("input.nml", "model_nml", iunit)
-read(iunit, nml = model_nml, iostat = io)
-call check_namelist_read(iunit, io, "model_nml")
+call static_init_assim_model()
 
+! Now the one specific to this tool.
+call find_namelist_in_file("input.nml", "dart_to_wrf_nml", iunit)
+read(iunit, nml = dart_to_wrf_nml, iostat = io)
+call check_namelist_read(iunit, io, "dart_to_wrf_nml")
+
 ! Record the namelist values used for the run ...
-if (do_nml_file()) write(nmlfileunit, nml=model_nml)
-if (do_nml_term()) write(     *     , nml=model_nml)
+if (do_nml_file()) write(nmlfileunit, nml=dart_to_wrf_nml)
+if (do_nml_term()) write(     *     , nml=dart_to_wrf_nml)
 
-call set_calendar_type(calendar_type)
+call get_wrf_state_variables(wrf_state_variables)
 
+num_domains        = get_number_domains()
+number_dart_values = get_model_size()
+
 call error_handler(E_MSG,'dart_to_wrf', &
    'Converting a dart_state_vector to a WRF netcdf file', &
    source, revision, revdate)
 
-allocate(wrf%dom(num_domains))
-
-! get default state variable table if asked
-if ( default_state_variables ) then
-  wrf_state_variables = 'NULL'
-  call fill_default_state_table(wrf_state_variables)
-endif
-
 if ( debug ) then
-  print*,'WRF state vector table'
-  print*,'default_state_variables = ',default_state_variables
-  print*,wrf_state_variables
+   print*,'dart vector size ',number_dart_values
 endif
 
+! allocate dart state vector
+allocate(dart(number_dart_values))
 
-! open wrf data netCDF file 'wrfinput_d0x'
-! we get sizes of the WRF geometry and resolution
+write (*, *) ' '
 
-! approach is to do everything in a loop, without any regard to the actual
-! order.  just use the namelist to read and unroll one at a time.
+! open dart file
+dart_unit = open_restart_read(dart_restart_name)
 
-! big loop over domains, just like in static_init
-number_dart_values = 0
-WRFDomains : do id = 1,num_domains
+! read dart vector - this is the line which depends on whether
+! this is a dart restart file or an advance_model file.
+if (model_advance_file) then
 
-   write(idom,'(I1)') id
+   write (*, *) 'reading dart model-advance data from file ', trim(dart_restart_name)
+   call aread_state_restart(dart_time(2), dart, dart_unit, dart_time(1))
 
-   if(file_exist('wrfinput_d0'//idom)) then
+   ! record wrf.info
+   write (*, *) 'writing wrf.info file '
+   iunit = get_unit()
+   open(unit = iunit, file = 'wrf.info')
+   call write_time(iunit, dart_time(1))
+   call write_time(iunit, dart_time(2))
+   call get_date(dart_time(2), year, month, day, hour, minute, second)
+   write (iunit,FMT='(I4,5I3.2)') year, month, day, hour, minute, second
 
-      call nc_check( nf90_open('wrfinput_d0'//idom, NF90_WRITE, ncid(id)), &
-                      'dart_to_wrf','open wrfinput_d0'//idom )
+   write (iunit,*) num_domains
+   write (iunit,*) adv_mod_command
+   close(iunit)
 
-   else
+else
 
-      call error_handler(E_ERR,'dart_to_wrf', &
-           'Please put wrfinput_d0'//idom//' in the work directory.', source, revision,revdate)
+   write (*, *) 'reading dart restart/ic data from file ', trim(dart_restart_name)
+   call aread_state_restart(dart_time(2), dart, dart_unit)
+   dart_time(1) = dart_time(2)
+   call get_date(dart_time(2), year, month, day, hour, minute, second)
 
-   endif
+endif
 
-! read WRF dimensions
-   call read_wrf_dimensions(ncid(id),wrf%dom(id)%bt, wrf%dom(id)%bts, &
-                                 wrf%dom(id)%sn, wrf%dom(id)%sns, &
-                                 wrf%dom(id)%we, wrf%dom(id)%wes, &
-                                 wrf%dom(id)%sls)
+call close_restart(dart_unit)
 
+! set new times
+call set_wrf_date(timestring, year, month, day, hour, minute, second)
+ndays = julian_day(year, month, day)
 
-! get the number of wrf variables wanted in this domain's state
-   wrf%dom(id)%number_of_wrf_variables = get_number_of_wrf_variables(id,wrf_state_variables,var_element_list)
+! loop through domains again and pull each variable from the state
+dart_ind = 1
+WRFDomains2 : do id = 1,num_domains
 
-  if ( debug ) then
-    print*,'Domain ',id,' number of wrf variables is ',wrf%dom(id)%number_of_wrf_variables
-  endif
+   wrf = get_wrf_static_data(id)
+   write(idom,'(I2.2)') id
+   write (*, *) 'overwriting state data in wrfinput_d' // idom
 
-! allocate and store the table locations of the variables valid on this domain
-   allocate(wrf%dom(id)%var_index_list(wrf%dom(id)%number_of_wrf_variables))
-   wrf%dom(id)%var_index_list = var_element_list(1:wrf%dom(id)%number_of_wrf_variables)
+   call nc_check( nf90_open('wrfinput_d' // idom, NF90_WRITE, ncid(id)), &
+                  'wrf_to_dart', 'open wrfinput_d' // idom )
 
-! allocate bounds lists and instructions
-   allocate(wrf%dom(id)%lower_bound(wrf%dom(id)%number_of_wrf_variables))
-   allocate(wrf%dom(id)%upper_bound(wrf%dom(id)%number_of_wrf_variables))
-   allocate(wrf%dom(id)%clamp_or_fail(wrf%dom(id)%number_of_wrf_variables))
-   call set_variable_bound_defaults(wrf%dom(id)%number_of_wrf_variables, &
-                                    wrf%dom(id)%lower_bound, &
-                                    wrf%dom(id)%upper_bound, &
-                                    wrf%dom(id)%clamp_or_fail)
+   do ind = 1,wrf%number_of_wrf_variables
 
-! assign default bounds and link the bounds to the correct variable locations
-   do ind = 1,wrf%dom(id)%number_of_wrf_variables
-
       ! actual location in state variable table
-      my_index =  wrf%dom(id)%var_index_list(ind)
+      my_index = wrf%var_index_list(ind)
 
-      call get_variable_bounds(wrf_state_bounds, &
-                               wrf_state_variables(1,my_index), &
-                               wrf%dom(id)%lower_bound(ind), &
-                               wrf%dom(id)%upper_bound(ind), &
-                               wrf%dom(id)%clamp_or_fail(ind))
-
       if ( debug ) then
-         write(*,*) 'Bounds for variable ',  &
-                     trim(wrf_state_variables(1,my_index)), &
-                     ' are ',wrf%dom(id)%lower_bound(ind), &
-                     wrf%dom(id)%upper_bound(ind), &
-                     wrf%dom(id)%clamp_or_fail(ind)
+         write(*,*) 'Rolling up variable ',trim(wrf_state_variables(1,my_index))
       endif
 
-   enddo
-
-
-! allocate var size
-  allocate(wrf%dom(id)%var_size(3,wrf%dom(id)%number_of_wrf_variables))
-
-! allocate stagger
-  allocate(wrf%dom(id)%stagger(wrf%dom(id)%number_of_wrf_variables))
-
-! add to the dart state vector size
-   do ind = 1,wrf%dom(id)%number_of_wrf_variables
-
-      ! actual location in state variable table
-      my_index =  wrf%dom(id)%var_index_list(ind)
-
       ! get stagger and variable size
-      call get_variable_size_from_file(ncid(id),id,  &
-                                       wrf_state_variables(1,my_index), &
-                                       wrf%dom(id)%bt, wrf%dom(id)%bts, &
-                                       wrf%dom(id)%sn, wrf%dom(id)%sns, &
-                                       wrf%dom(id)%we, wrf%dom(id)%wes, &
-                                       wrf%dom(id)%stagger(ind),        &
-                                       wrf%dom(id)%var_size(:,ind))
+      call nc_check( nf90_inq_varid(ncid(id),wrf_state_variables(1,my_index), &
+                     var_id), 'dart_to_wrf', &
+                     'inq_var_id ' // wrf_state_variables(1,my_index))
 
-      if ( debug ) then
-         print*,'variable size ',trim(wrf_state_variables(1,my_index)),' ',wrf%dom(id)%var_size(:,ind)
-      endif
+      if (  wrf%var_size(3,ind) == 1 ) then
 
-      number_dart_values = number_dart_values &
-                         + (wrf%dom(id)%var_size(1,ind) &
-                           * wrf%dom(id)%var_size(2,ind) &
-                           * wrf%dom(id)%var_size(3,ind)) 
-   enddo
+         if ( debug ) then
+            write(*,*) trim(wrf_state_variables(1,my_index)),' is 2D'
+            write(*,*) 'size  ',wrf%var_size(:,ind)
+         endif
 
-enddo WRFDomains
+         allocate(wrf_var_2d(wrf%var_size(1,ind),wrf%var_size(2,ind)))
 
-if ( debug ) then
-   print*,'dart vector size ',number_dart_values
-endif
+         wrf_var_2d = 0.0_r8
 
-! allocate dart state vector
-allocate(dart(number_dart_values))
+         call trans_1Dto2D( dart(dart_ind:), wrf_var_2d, &
+                            wrf%var_size(1,ind), wrf%var_size(2,ind))
 
-! open dart file
-dart_unit = open_restart_read("dart_wrf_vector")
+         ! check bounds and fail if requested
+         if ( trim(wrf%clamp_or_fail(my_index)) == 'FAIL' ) then
 
-! read dart vector
-call aread_state_restart(dart_time(2), dart, dart_unit, dart_time(1))
+            if (minval(wrf_var_2d) < wrf%lower_bound(my_index) ) then
+               call error_handler(E_ERR,'dart_to_wrf', &
+               'Variable '//trim(wrf_state_variables(1,my_index))// &
+               ' failed lower bounds check.', source, revision,revdate)
+            endif
 
-! record wrf.info
-iunit = get_unit()
-open(unit = iunit, file = 'wrf.info')
-call write_time(iunit, dart_time(1))
-call write_time(iunit, dart_time(2))
-call get_date(dart_time(2), year, month, day, hour, minute, second)
-write (iunit,FMT='(I4,5I3.2)') year, month, day, hour, minute, second
+            if (maxval(wrf_var_2d) > wrf%upper_bound(my_index) ) then
+               call error_handler(E_ERR,'dart_to_wrf', &
+               'Variable '//trim(wrf_state_variables(1,my_index))// &
+               ' failed upper bounds check.', source, revision,revdate)
+            endif
 
-write (iunit,*) num_domains
-write (iunit,*) adv_mod_command
-close(iunit)
+         endif ! bounds check failure request
 
-! set new times
-call set_wrf_date(timestring, year, month, day, hour, minute, second)
-ndays = julian_day(year, month, day)
+         !  apply lower bound test
+         if ( wrf%lower_bound(my_index) /= missing_r8 ) then
 
-! loop through domains again and pull each variable from the state
-dart_ind = 1
-WRFDomains2 : do id = 1,num_domains
+            if ( debug ) then
+              write(*,*) 'Setting lower bound ',wrf%lower_bound(my_index),' on ', &
+                          trim(wrf_state_variables(1,my_index))
+            endif
 
-   do ind = 1,wrf%dom(id)%number_of_wrf_variables
+            wrf_var_2d = max(wrf%lower_bound(my_index),wrf_var_2d)
 
-      ! actual location in state variable table
-      my_index = wrf%dom(id)%var_index_list(ind)
+         endif
 
-      if ( debug ) then
-         write(*,*) 'Rolling up variable ',trim(wrf_state_variables(1,my_index))
-      endif
+         !  apply upper bound test
+         if ( wrf%upper_bound(my_index) /= missing_r8 ) then
 
-      ! get stagger and variable size
-      call nc_check( nf90_inq_varid(ncid(id),wrf_state_variables(1,my_index), &
-                     var_id), 'dart_to_wrf', &
-                     'inq_var_id '//wrf_state_variables(1,my_index))
+            if ( debug ) then
+              write(*,*) 'Setting upper bound ',wrf%upper_bound(my_index),' on ', &
+                          trim(wrf_state_variables(1,my_index))
+            endif
 
-      if (  wrf%dom(id)%var_size(3,ind) == 1 ) then
+            wrf_var_2d = min(wrf%upper_bound(my_index),wrf_var_2d)
 
-         if ( debug ) then
-            write(*,*) trim(wrf_state_variables(1,my_index)),' is 2D'
-            write(*,*) 'size  ',wrf%dom(id)%var_size(:,ind)
          endif
 
-         allocate(wrf_var_2d(wrf%dom(id)%var_size(1,ind),wrf%dom(id)%var_size(2,ind)))
-
-         wrf_var_2d = 0.0_r8
-
-         call trans_1Dto2D( dart(dart_ind:),wrf_var_2d, &
-                       wrf%dom(id)%var_size(1,ind),wrf%dom(id)%var_size(2,ind))
-
          call nc_check( nf90_put_var(ncid(id), var_id, wrf_var_2d), &
-                     'dart_to_wrf','put_var '//wrf_state_variables(1,my_index) )
+                        'dart_to_wrf','put_var ' // wrf_state_variables(1,my_index) )
 
-
          deallocate(wrf_var_2d)
 
       else
 
          if ( debug ) then
             write(*,*) trim(wrf_state_variables(1,my_index)),' is 3D'
-            write(*,*) 'size  ',wrf%dom(id)%var_size(:,ind)
+            write(*,*) 'size  ',wrf%var_size(:,ind)
          endif
 
-         allocate(wrf_var_3d(wrf%dom(id)%var_size(1,ind),wrf%dom(id)%var_size(2,ind),wrf%dom(id)%var_size(3,ind)))
+         allocate(wrf_var_3d(wrf%var_size(1,ind),wrf%var_size(2,ind),wrf%var_size(3,ind)))
 
          wrf_var_3d = 0.0_r8
 
-         call trans_1Dto3D( dart(dart_ind:),wrf_var_3d, &
-                      wrf%dom(id)%var_size(1,ind), &
-                      wrf%dom(id)%var_size(2,ind),wrf%dom(id)%var_size(3,ind))
- 
-         ! check for bounds
-         lb = wrf%dom(id)%lower_bound(my_index)
-         ub = wrf%dom(id)%upper_bound(my_index)
+         call trans_1Dto3D( dart(dart_ind:), wrf_var_3d, wrf%var_size(1,ind), &
+                            wrf%var_size(2,ind), wrf%var_size(3,ind))
 
          ! check bounds and fail if requested
-         if ( trim(wrf%dom(id)%clamp_or_fail(my_index)) == 'FAIL' ) then
+         if ( trim(wrf%clamp_or_fail(my_index)) == 'FAIL' ) then
 
-            if (minval(wrf_var_3d) < lb ) then
+            if (minval(wrf_var_3d) < wrf%lower_bound(my_index) ) then
                call error_handler(E_ERR,'dart_to_wrf', &
                'Variable '//trim(wrf_state_variables(1,my_index))// &
                ' failed lower bounds check.', source, revision,revdate)
             endif
 
-            if (maxval(wrf_var_3d) > ub ) then
+            if (maxval(wrf_var_3d) > wrf%upper_bound(my_index) ) then
                call error_handler(E_ERR,'dart_to_wrf', &
                'Variable '//trim(wrf_state_variables(1,my_index))// &
                ' failed upper bounds check.', source, revision,revdate)
@@ -343,81 +252,69 @@
 
          endif ! bounds check failure request
 
-         ! apply bounds if asked
-         if ( lb /= missing_r8 ) then
+         !  apply lower bound test
+         if ( wrf%lower_bound(my_index) /= missing_r8 ) then
 
             if ( debug ) then
-              write(*,*) 'Setting lower bound ',lb,' on ', &
+              write(*,*) 'Setting lower bound ',wrf%lower_bound(my_index),' on ', &
                           trim(wrf_state_variables(1,my_index))
             endif
 
-            wrf_var_3d = max(lb,wrf_var_3d)
+            wrf_var_3d = max(wrf%lower_bound(my_index),wrf_var_3d)
   
          endif
 
-         if ( ub /= missing_r8 ) then
+         !  apply upper bound test
+         if ( wrf%upper_bound(my_index) /= missing_r8 ) then
 
             if ( debug ) then
-              write(*,*) 'Setting upper bound ',ub,' on ', &
+              write(*,*) 'Setting upper bound ',wrf%upper_bound(my_index),' on ', &
                           trim(wrf_state_variables(1,my_index))
             endif
 
-            wrf_var_3d = min(ub,wrf_var_3d)
+            wrf_var_3d = min(wrf%upper_bound(my_index),wrf_var_3d)
   
          endif
 
-!         if ( trim(wrf_state_variables(1,my_index)) == 'QVAPOR' .or.    &
-!              trim(wrf_state_variables(1,my_index)) == 'QRAIN' .or.     &
-!              trim(wrf_state_variables(1,my_index)) == 'QCLOUD' ) then
-!
-!            if ( debug ) then
-!              write(*,*) 'Setting 0 lower bound on ', &
-!                          trim(wrf_state_variables(1,my_index))
-!            endif
-
-!            wrf_var_3d = max(0.0_r8,wrf_var_3d)
-
-!         endif
-
          call nc_check( nf90_put_var(ncid(id), var_id, wrf_var_3d), &
-                     'dart_to_wrf','put_var '//wrf_state_variables(1,my_index) )
+                        'dart_to_wrf', 'put_var ' // wrf_state_variables(1,my_index) )
 
          deallocate(wrf_var_3d)
 
       endif 
 
-      dart_ind = dart_ind &
-                 + (wrf%dom(id)%var_size(1,ind) &
-                  * wrf%dom(id)%var_size(2,ind) &
-                  * wrf%dom(id)%var_size(3,ind))
+      dart_ind = dart_ind + wrf%var_size(1,ind) * wrf%var_size(2,ind) * wrf%var_size(3,ind)
  
    enddo
 
    ! output times too
-   call nc_check( nf90_inq_varid(ncid(id), "Times", var_id), 'dart_to_wrf', &
-               'inq_varid Times' )
-   call nc_check( nf90_put_var(ncid(id), var_id, timestring), 'dart_to_wrf', &
-               'put_var Times' )
+   call nc_check( nf90_inq_varid(ncid(id), "Times", var_id), &
+                  'dart_to_wrf', 'inq_varid Times' )
+   call nc_check( nf90_put_var(ncid(id), var_id, timestring), &
+                  'dart_to_wrf', 'put_var Times' )
+
+   call nc_check( nf90_redef(ncid(id)), 'dart_to_wrf', 'redef' )
    call nc_check( nf90_put_att(ncid(id), nf90_global, "START_DATE", timestring), &
                 'dart_to_wrf','put_att START_DATE' )
+   call nc_check( nf90_put_att(ncid(id), nf90_global, "SIMULATION_START_DATE", timestring), &
+                'dart_to_wrf','put_att SIMULATION_START_DATE' )
    call nc_check( nf90_put_att(ncid(id), nf90_global, "JULYR", year), &
                 'dart_to_wrf','put_att JULYR' )
    call nc_check( nf90_put_att(ncid(id), nf90_global, "JULDAY", ndays), &
                 'dart_to_wrf','put_att JULDY' ) 
+   call nc_check( nf90_enddef(ncid(id)), 'dart_to_wrf', 'enddef' )
 
    ! at this point we are done with this domain
-   call nc_check ( nf90_sync(ncid(id)),'dart_to_wrf','sync wrfinput' )
+   call nc_check ( nf90_sync(ncid(id)), 'dart_to_wrf','sync wrfinput' )
    call nc_check ( nf90_close(ncid(id)),'dart_to_wrf','close wrfinput' )
 
 enddo WRFDomains2
 
-deallocate(wrf%dom)
 deallocate(dart)
 
 write(logfileunit,*)'FINISHED dart_to_wrf.'
 write(logfileunit,*)
 
-call timestamp(source,revision,revdate,'end') ! That closes the log file, too.
+call finalize_utilities('dart_to_wrf')   ! closes log file.
 
 end PROGRAM dart_to_wrf
-

Modified: DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.html
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.html	2010-02-16 20:46:34 UTC (rev 4282)
+++ DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.html	2010-02-16 22:51:57 UTC (rev 4283)
@@ -65,21 +65,59 @@
 </P>
 <div class=namelist>
 <pre>
-<em class=call>namelist / model_nml / </em> &amp;
-    output_state_vector, num_moist_vars, num_domains, calendar_type, &amp;
-    surf_obs, soil_data, h_diab, adv_mod_command, assimilation_period_seconds,  &amp;
-    vert_localization_coord, center_search_half_length, center_spline_grid_scale
+<em class=call>namelist / dart_to_wrf_nml / </em> &amp;
+    model_advance_file, dart_restart_name, adv_mod_command
+    
+
+<em class=call>namelist / model_nml / </em> 
+
 </pre>
 </div>
 
 <div class=indent1>
 <!-- Description -->
 
-<P>
-These programs use the WRF model_nml. 
-See the description in <a href="../model_mod.html">model_mod.html</a>
+<P>The <em class=file>wrf_to_dart</em> program uses only the
+WRF model namelist.  See the description in
+the <a href="../model_mod.hmtl">WRF model_mod.html</a> file.
+The <em class=file>dart_to_wrf</em> program uses the model namelist
+plus an additional namelist: <em class=file>dart_to_wrf_nml</em>.
 </P>
 
+<P>Both namelists are read from a file 
+called <em class=file>input.nml</em>
+</P>
+
+<TABLE border=0 cellpadding=3 width=100%>
+<TR><TH align=left>Contents    </TH>
+    <TH align=left>Type        </TH>
+    <TH align=left>Description </TH></TR>
+<TR><!--contents--><TD valign=top>model_advance_file  </TD>
+    <!--  type  --><TD valign=top>logical             </TD>
+    <!--descript--><TD>In normal usage set this to .TRUE. so the
+     model_advance.csh script can function correctly.  The input
+     file will have 2 timestamps: time for model to advance to, 
+     and current time, plus the data.  However, to convert the
+     file restart files after DART finishes running into wrfinput_d01
+     files, for example to continue with a free run, set this to .FALSE.
+     Default .TRUE. </TD></TR>
+<TR><!--contents--><TD valign=top>dart_restart_name    </TD>
+    <!--  type  --><TD valign=top>character(len=128)   </TD>
+    <!--descript--><TD>In normal usage set this to 'dart_wrf_vector'
+     so the model_advance.csh script can function correctly.  However,
+     to write the output information directly to a netcdf file with
+     a different name, set this to another value.
+     Default 'dart_wrf_vector'. </TD></TR>
+<TR><!--contents--><TD valign=top>adv_mod_command      </TD>
+    <!--  type  --><TD valign=top>character(len=128)   </TD>
+    <!--descript--><TD>In normal usage set this to './wrf.exe'
+     so the model_advance.csh script can function correctly. 
+     This information along with some time information is written
+     to a file called 'wrf.info' if this is a model advance file.
+     Default './wrf.exe'. </TD></TR>
+</TABLE>
+
+
 </div>
 <br>
 
@@ -91,10 +129,10 @@
 <HR>
 <H2>FILES</H2>
 <UL>
-   <LI>input namelist ; <em class=file>input.nml</em></LI>
-   <LI>Input - output WRF state netCDF files; <em class=file>wrfinput_d01,
+   <LI>input namelist : <em class=file>input.nml</em></LI>
+   <LI>Input - output WRF state netCDF files : <em class=file>wrfinput_d01,
    wrfinput_d02, ...</em></LI>
-   <LI>Input - output dart state vector format files ; <em
+   <LI>Input - output dart state vector format files : <em
    class=file>dart_wrf_vector</em></LI>
    <LI>Input - output: <em class=file>wrf.info</em></LI>
 </UL>
@@ -235,7 +273,7 @@
 <!-- Description -->
 
 <P>
-Transfert from dart state vector to a wrf structure, or vice versa.
+Transfer from dart state vector to a wrf structure, or vice versa.
 </P>
 
 </div>
@@ -258,7 +296,7 @@
 <!-- Description -->
 
 <P>
-Transfert data from a 2D array into a 1D array, or vice versa.
+Transfer data from a 2D array into a 1D array, or vice versa.
 </P>
 
 </div>
@@ -281,7 +319,7 @@
 <!-- Description -->
 
 <P>
-Transfert data from a 3D array into a 1D array, or vice versa.
+Transfer data from a 3D array into a 1D array, or vice versa.
 </P>
 
 </div>

Added: DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.nml
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.nml	                        (rev 0)
+++ DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.nml	2010-02-16 22:51:57 UTC (rev 4283)
@@ -0,0 +1,5 @@
+&dart_to_wrf_nml
+   model_advance_file = .true.,
+   dart_restart_name = 'dart_wrf_vector',
+   adv_mod_command   = './wrf.exe',
+ /


Property changes on: DART/trunk/models/wrf/WRF_DART_utilities/dart_to_wrf.nml
___________________________________________________________________
Added: svn:mime-type
   + text/text
Added: svn:keywords
   + Date Revision Author HeadURL Id

Modified: DART/trunk/models/wrf/WRF_DART_utilities/ensemble_init.f90
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/ensemble_init.f90	2010-02-16 20:46:34 UTC (rev 4282)
+++ DART/trunk/models/wrf/WRF_DART_utilities/ensemble_init.f90	2010-02-16 22:51:57 UTC (rev 4283)
@@ -10,6 +10,12 @@
 ! $Revision$
 ! $Date$
 
+! This program is out of date compared to the other utilities in this directory.
+! I believe it could call the standard model_mod initialization routine and
+! be updated to work with the existing files, but I'm unsure about what exactly
+! it does.  So for now, I'm leaving it alone - but it's not going to work
+! correctly if used.     nsc 16 feb 2010
+
 ! Prototype to initialize ensemble for WRF EnKF 
 !  
 ! Reads:   Ensemble size, Ne    from    stdin 
@@ -45,12 +51,10 @@
                               vert_is_surface, vert_is_level, vert_is_pressure, vert_is_height, &
                               VERTISUNDEF, VERTISSURFACE, VERTISLEVEL, VERTISPRESSURE, &
                               VERTISHEIGHT
-                             
-
 use    utilities_mod, only : get_unit, file_exist, open_file, &
                              close_file, error_handler, E_ERR, E_MSG, initialize_utilities, &
-                             register_module, logfileunit, nmlfileunit, timestamp, &
-                             find_namelist_in_file, check_namelist_read
+                             register_module, logfileunit, nmlfileunit, &
+                             find_namelist_in_file, check_namelist_read, finalize_utilities
 
 use netcdf
 
@@ -62,42 +66,54 @@
    revision = "$Revision$", &
    revdate  = "$Date$"
 
+! miscellaneous
+integer, parameter :: max_state_variables = 100
+integer, parameter :: num_state_table_columns = 5
+integer, parameter :: num_bounds_table_columns = 4
+
 !-----------------------------------------------------------------------
 ! Model namelist parameters with default values.
 !-----------------------------------------------------------------------
 
-logical :: output_state_vector  = .false.     ! output prognostic variables
+logical :: output_state_vector     = .false.  ! output prognostic variables
+logical :: default_state_variables = .true.   ! use default state list?
+character(len=129) :: wrf_state_variables(num_state_table_columns,max_state_variables) = 'NULL'
+character(len=129) :: wrf_state_bounds(num_bounds_table_columns,max_state_variables) = 'NULL'
 integer :: num_moist_vars       = 3
 integer :: num_domains          = 1
 integer :: calendar_type        = GREGORIAN
 integer :: assimilation_period_seconds = 21600
-logical :: surf_obs             = .true.      
-logical :: soil_data            = .true.      
-logical :: h_diab               = .false.     
+logical :: surf_obs             = .true.
+logical :: soil_data            = .true.
+logical :: h_diab               = .false.
+! Max height a surface obs can be away from the actual model surface
+! and still be accepted (in meters)
+real (kind=r8) :: sfc_elev_max_diff  = -1.0_r8   ! could be something like 200.0_r8
 character(len = 72) :: adv_mod_command = './wrf.exe'
 real (kind=r8) :: center_search_half_length = 500000.0_r8
-integer :: center_spline_grid_scale = 10      
+real(r8) :: circulation_pres_level = 80000.0_r8
+real(r8) :: circulation_radius     = 108000.0_r8
+integer :: center_spline_grid_scale = 10
 integer :: vert_localization_coord = VERTISHEIGHT
-! Allow (or not) observations above the surface but below the lowest
-! sigma level.
+! Allow (or not) observations above the surface but below the lowest sigma level.
 logical :: allow_obs_below_vol = .false.
-! Max height a surface obs can be away from the actual model surface
-! and still be accepted (in meters)
-!real (kind=r8) :: max_surface_delta = 500.0
-! candidates for adding to the WRF netcdf files:
+!nc -- we are adding these to the model.nml until they appear in the NetCDF files
 logical :: polar = .false.         ! wrap over the poles
 logical :: periodic_x = .false.    ! wrap in longitude or x
 logical :: periodic_y = .false.    ! used for single column model, wrap in y
-!JPH -- single column model flag 
+!JPH -- single column model flag
 logical :: scm        = .false.    ! using the single column model
 
-
+! JPH note that soil_data and h_diab are never used and can be removed.
 namelist /model_nml/ output_state_vector, num_moist_vars, &
                      num_domains, calendar_type, surf_obs, soil_data, h_diab, &
+                     default_state_variables, wrf_state_variables, &
+                     wrf_state_bounds, sfc_elev_max_diff, &
                      adv_mod_command, assimilation_period_seconds, &
                      allow_obs_below_vol, vert_localization_coord, &
                      center_search_half_length, center_spline_grid_scale, &
-                     polar, periodic_x, periodic_y, scm
+                     circulation_pres_level, circulation_radius, polar, &
+                     periodic_x, periodic_y, scm
 
 !-----------------------------------------------------------------------
 
@@ -125,6 +141,13 @@
 call initialize_utilities('ensemble_init')
 call register_module(source, revision, revdate)
 
+! FIXME: i believe this program should call the wrf static_model_init code
+! to initialize the wrf static data, and then it doesn't have to read the
+! wrf model_mod namelist.  the num_moist_vars is no longer used, and there's
+! an array of fields which are going to be used in the state vector that
+! i believe should be used here instead.  see wrf_to_dart and dart_to_wrf
+! for now this program should be restructured.
+
 ! Begin by reading the namelist input
 call find_namelist_in_file("input.nml", "model_nml", iunit)
 read(iunit, nml = model_nml, iostat = io)
@@ -348,7 +371,7 @@
 write(logfileunit,*)'FINISHED ensemble_init.'
 write(logfileunit,*)
 
-call timestamp(source,revision,revdate,'end') ! That closes the log file, too.
+call finalize_utilities('ensemble_init')  ! closes log file.
  
 contains
 

Modified: DART/trunk/models/wrf/WRF_DART_utilities/extract.f90
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/extract.f90	2010-02-16 20:46:34 UTC (rev 4282)
+++ DART/trunk/models/wrf/WRF_DART_utilities/extract.f90	2010-02-16 22:51:57 UTC (rev 4283)
@@ -12,7 +12,7 @@
 
 use    utilities_mod, only : file_exist, open_file, close_file, &
                              error_handler, E_ERR, initialize_utilities, &
-                             timestamp, register_module, logfileunit
+                             register_module, logfileunit, finalize_utilities
 use    netcdf
 
 implicit none
@@ -110,7 +110,7 @@
 write(logfileunit,*)'FINISHED extract.'
 write(logfileunit,*)
 
-call timestamp(source,revision,revdate,'end') ! That closes the log file, too.
+call finalize_utilities('Extract')   ! closes log file.
  
 contains
 

Modified: DART/trunk/models/wrf/WRF_DART_utilities/grid_refl_obs.f90
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/grid_refl_obs.f90	2010-02-16 20:46:34 UTC (rev 4282)
+++ DART/trunk/models/wrf/WRF_DART_utilities/grid_refl_obs.f90	2010-02-16 22:51:57 UTC (rev 4283)
@@ -53,8 +53,7 @@
                              operator(*), operator(+), operator(-), &
                              operator(>), operator(<), operator(/), &
                              operator(/=), operator(<=)
-use    utilities_mod, only : error_handler, E_ERR, E_MSG, initialize_utilities, &
-                             timestamp, register_module, logfileunit, file_exist
+use    utilities_mod, only : error_handler, E_ERR, E_MSG, file_exist
 use    netcdf
 use    f2kcli
 

Added: DART/trunk/models/wrf/WRF_DART_utilities/replace_wrf_fields.f90
===================================================================
--- DART/trunk/models/wrf/WRF_DART_utilities/replace_wrf_fields.f90	                        (rev 0)
+++ DART/trunk/models/wrf/WRF_DART_utilities/replace_wrf_fields.f90	2010-02-16 22:51:57 UTC (rev 4283)
@@ -0,0 +1,347 @@
+! DART software - Copyright © 2004 - 2010 UCAR. This open source software is
+! provided by UCAR, "as is", without charge, subject to all terms of use at
+! http://www.image.ucar.edu/DAReS/DART/DART_download
+
+program replace_wrf_fields
+
+! <next few lines under version control, do not edit>
+! $URL$
+! $Id$
+! $Revision$
+! $Date$
+
+use     types_mod, only : r8
+use utilities_mod, only : register_module, error_handler, E_ERR, E_MSG,       &
+                          open_file, close_file, nc_check, get_next_filename, &
+                          find_namelist_in_file, check_namelist_read,         &
+                          do_nml_file, do_nml_term, nmlfileunit,              &
+                          initialize_utilities, finalize_utilities
+use parse_args_mod, only : get_args_from_string
+
+use netcdf
+
+implicit none
+
+! version controlled file description for error handling, do not edit
+! split into separate lines; getting too long for the absoft compiler
+character(len=128), parameter :: source = &
+ "$URL$"
+character(len=128), parameter :: revision = "$Revision$"
+character(len=128), parameter :: revdate  = "$Date$"
+
+! variables used to read the netcdf info
+integer, parameter :: maxd = 7
+integer :: i, j, ndims, odims, ncrc, etype
+integer :: ncinid, ncoutid        ! netcdf id for file
+integer :: invarid, outvarid
+integer :: dimid(maxd), dimlen(maxd), odimid(maxd), odimlen(maxd)
+character(128) :: dimname(maxd), odimname(maxd)
+integer ::  ninDimensions,  ninVariables,  ninAttributes,  inunlimitedDimID
+integer :: noutDimensions, noutVariables, noutAttributes, outunlimitedDimID
+
+! arrays for all possible dimensions
+real(r8), pointer ::   oned(:)       
+real(r8), pointer ::   twod(:,:)
+real(r8), pointer :: threed(:,:,:)
+real(r8), pointer ::  fourd(:,:,:,:)
+real(r8), pointer ::  fived(:,:,:,:,:)
+real(r8), pointer ::   sixd(:,:,:,:,:,:)
+real(r8), pointer :: sevend(:,:,:,:,:,:,:)
+
+logical, save :: module_initialized = .false.
+
+! arg parsing code
+character(len=256) :: argline
+integer :: argcount = 2
+character(len=NF90_MAX_NAME) :: argwords(3)
+
+character(len=NF90_MAX_NAME) :: infile, outfile
+character(len=NF90_MAX_NAME) :: nextfield
+integer :: fieldindex
+logical :: from_file
+
+character(len=128) :: msgstring, msgstring2, tmpstring
+integer :: iunit, io
+logical :: debug = .false.                   ! or .true.
+logical :: fail_on_missing_field = .true.    ! or .false.
+character(len=128) :: fieldnames(1000) = ''  ! something large
+character(len=128) :: fieldlist_file = ''
+
+! fieldnames here?
+namelist /replace_wrf_fields_nml/  debug, fail_on_missing_field, &
+                                   fieldnames, fieldlist_file
+
+! main code here
+ 
+! flow:
+!   initialization
+call initialize_utilities('replace_wrf_fields')
+call initialize_module()
+
+! Read the namelist entry

@@ Diff output truncated at 40000 characters. @@


More information about the Dart-dev mailing list