[Dart-dev] [8735] DART/trunk/models/LMDZ: initial commit of the interface to the LMDZ model.

nancy at ucar.edu nancy at ucar.edu
Mon Oct 5 16:32:57 MDT 2015


Revision: 8735
Author:   nancy
Date:     2015-10-05 16:32:57 -0600 (Mon, 05 Oct 2015)
Log Message:
-----------
initial commit of the interface to the LMDZ model.
this has NOT been independently tested.  i've run
perfect_model_obs and filter one step, but the code
should be reviewed and some .html files should be
created.

Modified Paths:
--------------
    DART/trunk/models/LMDZ/README

Added Paths:
-----------
    DART/trunk/models/LMDZ/dart_to_lmdz.f90
    DART/trunk/models/LMDZ/lmdz_to_dart.f90
    DART/trunk/models/LMDZ/model_mod.f90
    DART/trunk/models/LMDZ/model_mod.nml
    DART/trunk/models/LMDZ/shell_scripts/
    DART/trunk/models/LMDZ/shell_scripts/'
    DART/trunk/models/LMDZ/shell_scripts/Control_File.csh
    DART/trunk/models/LMDZ/shell_scripts/advance_model.csh
    DART/trunk/models/LMDZ/shell_scripts/input_1.nml
    DART/trunk/models/LMDZ/shell_scripts/input_n.nml
    DART/trunk/models/LMDZ/shell_scripts/job.csh
    DART/trunk/models/LMDZ/shell_scripts/run_filter.csh
    DART/trunk/models/LMDZ/shell_scripts/run_lmdz.csh
    DART/trunk/models/LMDZ/work/
    DART/trunk/models/LMDZ/work/input.nml
    DART/trunk/models/LMDZ/work/mkmf_closest_member_tool
    DART/trunk/models/LMDZ/work/mkmf_create_fixed_network_seq
    DART/trunk/models/LMDZ/work/mkmf_create_obs_sequence
    DART/trunk/models/LMDZ/work/mkmf_dart_to_lmdz
    DART/trunk/models/LMDZ/work/mkmf_fill_inflation_restart
    DART/trunk/models/LMDZ/work/mkmf_filter
    DART/trunk/models/LMDZ/work/mkmf_integrate_model
    DART/trunk/models/LMDZ/work/mkmf_lmdz_to_dart
    DART/trunk/models/LMDZ/work/mkmf_model_mod_check
    DART/trunk/models/LMDZ/work/mkmf_obs_common_subset
    DART/trunk/models/LMDZ/work/mkmf_obs_diag
    DART/trunk/models/LMDZ/work/mkmf_obs_seq_to_netcdf
    DART/trunk/models/LMDZ/work/mkmf_obs_sequence_tool
    DART/trunk/models/LMDZ/work/mkmf_perfect_model_obs
    DART/trunk/models/LMDZ/work/mkmf_preprocess
    DART/trunk/models/LMDZ/work/mkmf_restart_file_tool
    DART/trunk/models/LMDZ/work/mkmf_wakeup_filter
    DART/trunk/models/LMDZ/work/obs_seq.in
    DART/trunk/models/LMDZ/work/obs_seq.out
    DART/trunk/models/LMDZ/work/path_names_closest_member_tool
    DART/trunk/models/LMDZ/work/path_names_create_fixed_network_seq
    DART/trunk/models/LMDZ/work/path_names_create_obs_sequence
    DART/trunk/models/LMDZ/work/path_names_dart_to_lmdz
    DART/trunk/models/LMDZ/work/path_names_fill_inflation_restart
    DART/trunk/models/LMDZ/work/path_names_filter
    DART/trunk/models/LMDZ/work/path_names_integrate_model
    DART/trunk/models/LMDZ/work/path_names_lmdz_to_dart
    DART/trunk/models/LMDZ/work/path_names_model_mod_check
    DART/trunk/models/LMDZ/work/path_names_obs_common_subset
    DART/trunk/models/LMDZ/work/path_names_obs_diag
    DART/trunk/models/LMDZ/work/path_names_obs_seq_to_netcdf
    DART/trunk/models/LMDZ/work/path_names_obs_sequence_tool
    DART/trunk/models/LMDZ/work/path_names_perfect_model_obs
    DART/trunk/models/LMDZ/work/path_names_preprocess
    DART/trunk/models/LMDZ/work/path_names_restart_file_tool
    DART/trunk/models/LMDZ/work/path_names_wakeup_filter
    DART/trunk/models/LMDZ/work/quickbuild.csh
    DART/trunk/models/LMDZ/work/start.nc

-------------- next part --------------
Modified: DART/trunk/models/LMDZ/README
===================================================================
--- DART/trunk/models/LMDZ/README	2015-10-05 21:50:14 UTC (rev 8734)
+++ DART/trunk/models/LMDZ/README	2015-10-05 22:32:57 UTC (rev 8735)
@@ -1,23 +1,11 @@
+The detailed documentaion of interface codes and scripts for 
+running will be added later. 
 
-There are several DART users who have working DART interface code
-to the LMDZ atmospheric general circulation model.  This model is
-developed and supported by the Laboratorie de Meteorologie Dynamique
-which is located at three French universities, one in Palaiseau and 
-two in Paris.
+Please contact me if you have any queries
 
-See here:
+Tarkeshwar Singh
+E-mail: tarkphysics87 at gmail.com
+Research Scholar
+Centre for Atmospheric Sciences
+Indian Institute of Technology (IIT) Delhi
 
-http://lmdz.lmd.jussieu.fr/?set_language=en
-
-for more information on the model.  
-
-If you are interested in running DART with this model please contact 
-the DART group at 'dart at ucar.edu' for more information.  We currently do
-not have a copy of the model_mod interface code nor any of the scripting 
-required to run an assimilation, but we may be able to put you in contact 
-with the right people to get it.
-
-The DART Group
-17 Sept 2014
-
-

Added: DART/trunk/models/LMDZ/dart_to_lmdz.f90
===================================================================
--- DART/trunk/models/LMDZ/dart_to_lmdz.f90	                        (rev 0)
+++ DART/trunk/models/LMDZ/dart_to_lmdz.f90	2015-10-05 22:32:57 UTC (rev 8735)
@@ -0,0 +1,111 @@
+! DART software - Copyright 2004 - 2011 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 dart_to_lmdz
+
+!----------------------------------------------------------------------
+! purpose: interface between LMDZ and DART
+!
+! method: Read DART state vector ("proprietary" format), including time(s).
+!         Reform state vector back into LMDZ fields.
+!         Replace those fields on the LMDZ initial file with the new values,
+!         preserving all other information on the file.
+!
+!----------------------------------------------------------------------
+
+use       types_mod, only : r8
+use   utilities_mod, only : open_file, close_file, &
+                            initialize_utilities, finalize_utilities, &
+                            logfileunit, nmlfileunit, do_nml_file, do_nml_term, &
+                            check_namelist_read, find_namelist_in_file
+use       model_mod, only : data_2d_type,data_3d_type, init_model_instance, write_lmdz_init, &
+                            vector_to_prog_var, static_init_model, get_model_size
+use assim_model_mod, only : aread_state_restart, open_restart_read, close_restart
+use time_manager_mod, only : time_type, print_time, print_date
+
+implicit none
+
+! version controlled file description for error handling, do not edit
+character(len=128), parameter :: &
+   source   = "$URL$", &
+   revision = "$Revision$", &
+   revdate  = "$Date$"
+
+!------------------------------------------------------------------
+! The namelist variables
+!------------------------------------------------------------------
+
+character (len = 128) :: dart_to_lmdz_input_file  = 'dart_ics'
+character (len = 128) :: dart_to_lmdz_output_file = 'start.nc'
+logical               :: advance_time_present    = .true.
+
+namelist /dart_to_lmdz_nml/ dart_to_lmdz_input_file,  &
+                           dart_to_lmdz_output_file, &
+                           advance_time_present
+
+!----------------------------------------------------------------------
+
+type(data_2d_type)     :: PS_local
+type(data_3d_type)     :: T_local,U_local,V_local,Q_local,CLDLIQ_local
+type(time_type)        :: model_time, adv_to_time
+real(r8), allocatable  :: statevector(:)
+integer                :: file_unit, vecsize, iunit, io
+
+!-----------------------------------------------------------------------------
+! start of program
+!-----------------------------------------------------------------------------
+
+call initialize_utilities('dart_to_lmdz')
+
+! Read the namelist to get the input filename and whether
+! a simple restart/ic file or a model advance file.
+call find_namelist_in_file("input.nml", "dart_to_lmdz_nml", iunit)
+read(iunit, nml = dart_to_lmdz_nml, iostat = io)
+call check_namelist_read(iunit, io, "dart_to_lmdz_nml")
+
+! Record the namelist values used for the run 
+if (do_nml_file()) write(nmlfileunit, nml=dart_to_lmdz_nml)
+if (do_nml_term()) write(     *     , nml=dart_to_lmdz_nml)
+
+! initialize model
+call static_init_model()
+
+vecsize = get_model_size()
+allocate(statevector(vecsize))
+
+! Allocate the instance of the lmdz model type for storage
+call init_model_instance(PS_local,T_local,U_local,V_local,Q_local,CLDLIQ_local)
+
+! Get file for DART vector input
+file_unit = open_restart_read(dart_to_lmdz_input_file)
+
+
+! read in model time and state vector from DART
+if (advance_time_present) then
+   call aread_state_restart(model_time, statevector, file_unit, adv_to_time)
+else
+   call aread_state_restart(model_time, statevector, file_unit)
+endif
+call close_restart(file_unit)
+
+! decompose vector back into LMDZ fields
+call vector_to_prog_var (statevector, PS_local,T_local,U_local,V_local, &
+                                                   Q_local,CLDLIQ_local)
+
+deallocate (statevector)
+
+! write fields to the netCDF initial file.
+call write_lmdz_init(dart_to_lmdz_output_file, PS_local,T_local,U_local, &
+                               V_local,Q_local,CLDLIQ_local, model_time)
+
+call finalize_utilities()
+
+end program dart_to_lmdz
+
+! <next few lines under version control, do not edit>
+! $URL$
+! $Id$
+! $Revision$
+! $Date$
+


Property changes on: DART/trunk/models/LMDZ/dart_to_lmdz.f90
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author HeadURL Id
Added: svn:eol-style
   + native

Added: DART/trunk/models/LMDZ/lmdz_to_dart.f90
===================================================================
--- DART/trunk/models/LMDZ/lmdz_to_dart.f90	                        (rev 0)
+++ DART/trunk/models/LMDZ/lmdz_to_dart.f90	2015-10-05 22:32:57 UTC (rev 8735)
@@ -0,0 +1,101 @@
+! DART software - Copyright 2004 - 2011 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 lmdz_to_dart
+
+!----------------------------------------------------------------------
+! <next few lines under version control, do not edit>
+! $URL:https://proxy.subversion.ucar.edu/DAReS/DART/releases/Kodiak/models/LMDZ/lmdz_to_dart.f90  $
+! $Id$
+! $Revision$
+! $Date$
+
+!----------------------------------------------------------------------
+! purpose: interface between LMDZ and DART
+!
+! method: Read LMDZ 'initial' file (netCDF format) for model state and time.
+!         Reform fields into a DART state vector.
+!         Write out state vector in "proprietary" format for DART
+!----------------------------------------------------------------------
+
+
+use        types_mod, only : r8
+use    utilities_mod, only : initialize_utilities, finalize_utilities, do_output,     &
+                             check_namelist_read, find_namelist_in_file, nmlfileunit, &
+                             do_nml_file, do_nml_term
+use        model_mod, only : data_2d_type,data_3d_type, init_model_instance, end_model_instance, &
+                             prog_var_to_vector, read_lmdz_init, static_init_model,PS,T,U,V,Q,CLDLIQ
+use  assim_model_mod, only : static_init_assim_model, get_model_size, &
+                             open_restart_write, awrite_state_restart, close_restart
+use time_manager_mod, only : time_type
+
+implicit none
+
+! version controlled file description for error handling, do not edit
+character(len=128), parameter :: &
+   source   = "$URL$", &
+   revision = "$Revision$", &
+   revdate  = "$Date$"
+
+
+!-----------------------------------------------------------------------
+! namelist parameters with default values.
+!-----------------------------------------------------------------------
+
+character (len = 128) :: lmdz_to_dart_input_file  = 'start.nc'
+character (len = 128) :: lmdz_to_dart_output_file = 'dart_ics'
+
+namelist /lmdz_to_dart_nml/ lmdz_to_dart_input_file, lmdz_to_dart_output_file
+
+! allocatable storage to read in a native format for lmdz state
+
+real(r8), allocatable  :: statevector(:)
+type(time_type)        :: model_time
+integer                :: iunit, x_size, io
+
+call initialize_utilities('lmdz_to_dart')
+
+! Read the namelist entry
+call find_namelist_in_file("input.nml", "lmdz_to_dart_nml", iunit)
+read(iunit, nml = lmdz_to_dart_nml, iostat = io)
+call check_namelist_read(iunit, io, "lmdz_to_dart_nml")
+
+! Record the namelist values
+
+! do_nml_file () :  *** return whether nml should be written to nml file 
+
+if (do_nml_file()) write(nmlfileunit, nml=lmdz_to_dart_nml)
+if (do_nml_term()) write(     *     , nml=lmdz_to_dart_nml)
+
+! Static init assim model sets the output file format (binary/ascii)
+! call static_init_model() 
+
+call static_init_assim_model()
+
+! Allocate the local state vector
+x_size = get_model_size()
+allocate(statevector(x_size))
+
+
+! Allocate the instance of the lmdz model type for storage
+call init_model_instance(PS, T, U, V, Q, CLDLIQ)
+
+! Read the file lmdz state fragments into var;
+! transform fields into state vector for DART
+
+
+call read_lmdz_init(lmdz_to_dart_input_file, model_time)
+
+call prog_var_to_vector(statevector, PS, T, U, V, Q, CLDLIQ)
+
+call end_model_instance(PS, T, U, V, Q, CLDLIQ)
+
+! write out state vector in "proprietary" format
+iunit = open_restart_write(lmdz_to_dart_output_file)
+call awrite_state_restart(model_time, statevector, iunit)
+call close_restart(iunit)
+
+call finalize_utilities()
+
+end program lmdz_to_dart


Property changes on: DART/trunk/models/LMDZ/lmdz_to_dart.f90
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author HeadURL Id
Added: svn:eol-style
   + native

Added: DART/trunk/models/LMDZ/model_mod.f90
===================================================================
--- DART/trunk/models/LMDZ/model_mod.f90	                        (rev 0)
+++ DART/trunk/models/LMDZ/model_mod.f90	2015-10-05 22:32:57 UTC (rev 8735)
@@ -0,0 +1,4383 @@
+! DART software - Copyright 2004 - 2011 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
+
+module model_mod
+
+!--------------------------------------------------------------------------------------------
+!                Assimilation interface for LMDZ  model
+!-------------------------------------------------------------------------------------------
+!---------------- m o d u l e   i n f o r m a t i o n --------------------------------------
+!-------------------------------------------------------------------------------------------
+
+
+use           netcdf
+use        types_mod, only : r8, MISSING_I,MISSING_R8,  gravity_const => gravity
+use time_manager_mod, only : time_type, set_time,set_date,get_date, set_calendar_type, operator(+)
+use    utilities_mod, only : register_module, error_handler, nc_check,                           &
+                             E_ERR, E_MSG, nmlfileunit, do_output, do_nml_file, do_nml_term,     &
+                             find_namelist_in_file, check_namelist_read,logfileunit,file_exist,  &
+                             get_unit
+use mpi_utilities_mod, only : my_task_id, task_count
+!-------------------------------------------------------------------------
+use     location_mod,  only : location_type, get_location, set_location, query_location,         &
+                              LocationDims, LocationName, LocationLName,horiz_dist_only,         &
+                              vert_is_level, vert_is_pressure, vert_is_height,vert_is_surface,   &
+                              VERTISUNDEF, VERTISSURFACE, VERTISLEVEL,                           &
+                              VERTISPRESSURE, VERTISHEIGHT,                                      &
+                              get_close_type, get_close_maxdist_init, get_close_obs_init,        &
+                              get_dist,loc_get_close_obs => get_close_obs
+
+! BEGIN DART PREPROCESS USED KINDS
+use     obs_kind_mod, only : KIND_U_WIND_COMPONENT, KIND_V_WIND_COMPONENT,KIND_PRESSURE,         &
+                             KIND_SURFACE_PRESSURE, KIND_TEMPERATURE,KIND_SPECIFIC_HUMIDITY,     &
+                             KIND_CLOUD_LIQUID_WATER, KIND_SURFACE_ELEVATION
+use   random_seq_mod, only : random_seq_type, init_random_seq, random_gaussian
+
+! end of use statements
+!==============================================================================================
+!
+! LMDZ global/module declarations
+
+implicit none
+private
+
+! The first block are the 16 required interfaces.  The following block
+! are additional useful interfaces that utility programs can call.
+public ::                                                            &
+   static_init_model, get_model_size, get_model_time_step,           &
+   pert_model_state, get_state_meta_data, model_interpolate,         &
+   nc_write_model_atts, nc_write_model_vars,                         &
+   init_conditions, init_time, adv_1step, end_model,                 &
+   get_close_maxdist_init, get_close_obs_init, get_close_obs,        &
+   ens_mean_for_model
+
+public ::                                                            &
+   data_2d_type,data_3d_type,PS,T,U,V,Q,CLDLIQ, prog_var_to_vector,  &
+    vector_to_prog_var,  read_lmdz_init, read_lmdz_init_size,        &
+   init_model_instance, end_model_instance, write_lmdz_init, coord_index
+   
+
+
+!----------------------------------------------------------------------------
+!----------------------------------------------------------------------------
+
+! version controlled file description for error handling, do not edit
+character(len=128), parameter :: &
+   source   = "$URL$", &
+   revision = "$Revision$", &
+   revdate  = "$Date$"
+
+! Ensemble mean is used so that the same "state" will be used for the heigh calculations
+! on all processors, for all ensemble members.
+! This is allocated in static_init_model().
+real(r8), allocatable :: ens_mean(:)
+
+!----------------------------------------------------------------------
+! Global storage for describing LMDZ  model class
+!----------------------------------------------------------------------
+
+!-----------------------------------------------------------------------
+! Definition of variable types
+! Values will be defined in order_state_fields
+! All fields will have entries in the TYPE_xD corresponding to their orders
+! in state_names_Xd.  The explicitly named TYPE_s are for convenience
+integer :: TYPE_PS   = MISSING_I,         &
+           TYPE_T    = MISSING_I,         &
+           TYPE_U    = MISSING_I,         &
+           TYPE_V    = MISSING_I,         &
+           TYPE_Q    = MISSING_I,         &
+           TYPE_CLDLIQ = MISSING_I
+!-----------------------------------------------------------------------
+
+type(time_type)                  :: time_step
+type(location_type), allocatable :: state_loc(:)
+
+! temporary output
+integer :: num_calced = 0, num_searched = 0
+
+!---------------Variables and grid structure of start.nc ----------------------
+!               
+!
+!          (PS,T,Q,CLDLIQ)               (PS,T,Q,CLDLIQ)
+!               *--------------(U)--------------*
+!               !                               !
+!               !                               !
+!               !                               !
+!               !                               !
+!  rlatv------>(V)              *              (V)       
+! (~slat)       !          (rlonu,rlatv)        !       
+!               !                               !
+!               !                               !
+!               !                               !
+!  rlatu-__---->*-------------(U)---------------*
+!  (~lat)  (PS,T,Q,CLDLIQ)     ^          (PS,T,Q,CLDLIQ)
+!               ^              !
+!               !              !
+!               !              !
+!           rlonv (~lon)    rlonu (~slon)
+!---------------------------------------------------------------------------------            
+! (PS,PHIS)(lon,lat)  ! (T,Q,CLDLIQ)(lon,lat,sigs),! U(slon,lat,sigs),! V(lon,slat,sigs)
+!--------------------------------------------------------------------------------
+! PHIS  : Surface Geopotential 
+! PS    : Surface Pressure (Pa)
+! T     : Air Temparature  (K)
+! U     : Zonal Wind Comp  (m/s)
+! V     : Meridional Wind  (m/s)
+! Q     : Specific Humidity (kg/kg)   ??
+! CLDLIQ: Cloud liq. water
+!------------------------------------------------------------------
+!------------------------------------------------------------------
+! In start.nc lon~(-180,180), lat~(90,-90), level(bottom,top) but
+! for  DART  it has been converted to lon~(0,360), lat~(-90, 90), level(top, bottom)
+!----------------------------------------------------------------
+!----------------------------------------------------------------
+
+type grid_1D_type
+    !private
+    integer                      :: dim_id
+    integer                      :: length
+    real(r8)                     :: resolution
+    real(r8), pointer            :: vals(:)
+    character (len=128)          :: var_name
+    integer                      :: num_atts
+    character (len=128), pointer :: atts_names(:)
+    character (len=128), pointer :: atts_vals(:)
+end type grid_1D_type
+
+!-------
+type data_2d_type
+   !private
+   integer               :: var_id
+   integer               :: length
+   real(r8), pointer     :: vals(:,:)
+   character (len=128)   :: atts_names  ! start.nc have only one attribute
+   character (len=128)   :: atts_vals  
+end type data_2d_type
+!-------
+type data_3d_type
+   !private
+   integer               :: var_id
+   integer               :: length
+   real(r8), pointer     :: vals(:,:,:)
+   character (len=128)   :: atts_names  ! start.nc have only one attribute
+   character (len=128)   :: atts_vals   ! start.nc have only one attribute  
+end type data_3d_type
+
+! renaming of coordinate variables in  start.nc: lon=rlonv, lat=rlatu, slon=rlonu, slat=rlatv 
+! here slat & slon represents staggered coordinates.
+ type(grid_1D_type)    ::  slon, lat, lon, slat, sig, sigs, ap,apm,bp, bpm, presnivs,temps 
+ type(data_3d_type)    ::  T,U,V,Q,CLDLIQ
+ type(data_2d_type)    ::  PHIS,PS
+
+! end of model section
+!----------------------------------------------------------------------
+! Derived parameters
+
+! make sure static init code only called once
+logical :: module_initialized = .false.
+!-------
+
+type(time_type) :: Time_step_atmos
+! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
+! Random sequence and init for pert_model_state
+type(random_seq_type)   :: random_seq
+! Variable for keeping track of which ensemble member is to be perturbed
+! by pert_model_state, which is called by filter for each ensemble member
+! for a cold start.
+integer                 :: num_tasks
+integer                 :: my_task
+integer                 :: ens_member = 0
+logical                 :: do_out
+
+! common message string used by many subroutines
+character(len=150)               :: msgstring, string2
+!----
+character (len=8), allocatable   :: cflds(:)
+integer                          :: nflds         ! # fields to read
+integer                          :: num_dims
+integer                          :: model_size
+
+!----- used in data conversion from [-180 180] to [0 360] Formate
+integer :: botm_positive_lon_index
+integer :: botm_positive_slon_index
+integer :: botm_negative_lon_index
+integer :: botm_negative_slon_index
+
+! Surface pressures, used by vertical interpolation routines.
+logical               :: alloc_ps=.true.              ! Flag whether to alloc space for ps[_stagr] 
+real(r8), allocatable :: ps_ens_mean(:, :)            ! ps ensemble mean
+real(r8), allocatable :: ps_ens_mean_stagr_lonu(:, :) ! ps used to calc P profiles & heights on grid staggered
+                                                      !    East-West (i.e. at location  of  UCOV) relative to ps
+real(r8), allocatable :: ps_ens_mean_stagr_latv(:, :) ! ps used to calc P profiles & heights on grid staggered
+                                                      !    North-South (i.e. at location  of  VCOV)
+
+! height
+! Surface potential; used for calculation of geometric heights.
+logical               :: alloc_phis=.true.     ! Flag whether to allocate space for phis[_stagr] 
+real(r8), allocatable :: phis_stagr_lonu(:, :) ! surface geopotential staggered as for ps
+real(r8), allocatable :: phis_stagr_latv(:, :) ! surface geopotential staggered as for ps
+
+
+integer :: ii
+! columns of pressure and model level heights for use in convert_vert
+real(r8), allocatable :: p_col(:), model_h(:)
+
+
+! array for the linking of obs_kinds (KIND_) to model field TYPE_s
+! It's filled in map_kinds.The max size of KIND_ should come from obs_kind_mod
+! These should be dimensioned the same size as the total of state_names_Nd.
+integer, dimension(100) :: dart_to_lmdz_kinds = (/(MISSING_I,ii=1,100)/)
+integer, dimension(100) :: lmdz_to_dart_kinds = (/(MISSING_I,ii=1,100)/)
+
+
+!----------------------------------------------------------------------
+! Namelist variables with default values follow
+!-----------------------------------------------------------------------
+!define names list for  model_nml in input.nml file
+! Special for an experiment.  Specify one string kind e.g KIND_CLOUD_LIQUID and 
+! observations of that kind will only impact other obs and state vars of that
+! same kind.  All other kinds of obs and state vars will not be impacted
+! by obs of this kind.  A null string means behave as normal.  Kind strings
+! are limited by compilers to be 32 chars, since they are declared as params.
+character(len=32) :: impact_only_same_kind = ' '
+integer           :: impact_kind_index = -1
+
+logical :: print_details = .false.
+logical :: write_grads   = .false.
+
+
+! output_state_vector = .true.     results in a "state-vector" netCDF file
+! output_state_vector = .false.    results in a "prognostic-var" netCDF file
+logical  :: output_state_vector = .false.
+character(len = 128) :: model_config_file = 'start.nc'
+
+integer, parameter :: MAX_STATE_NAMES = 100
+
+! list of fields which this code needs to perturb because they're
+! constant valued model parameters and show no spread when start_from_restart = .true.
+character (len=8),dimension(MAX_STATE_NAMES) :: pert_names = (/('',ii=1,MAX_STATE_NAMES)/)
+real(r8)         ,dimension(MAX_STATE_NAMES) :: pert_sd    = (/(-888888.0d0,ii=1,MAX_STATE_NAMES)/)
+real(r8)         ,dimension(MAX_STATE_NAMES) :: pert_base_vals = (/(-888888.0d0,ii=1,MAX_STATE_NAMES)/)
+
+! Specify shortest time step that the model will support
+! This is limited below by CAMs fixed time step but is also impacted
+! by numerical stability concerns for repeated restarting in leapfrog.
+integer  :: time_step_days      = 1
+integer  :: time_step_seconds   = 0
+
+
+! Define location restrictions on which observations are assimilated
+! (values are calculated anyway, but istatus is set to 2)
+real(r8) :: max_obs_lat_degree        = 90.0_r8
+real(r8) :: highest_obs_pressure_mb   = 150.0_r8
+real(r8) :: highest_state_pressure_mb = 150.0_r8
+
+! exclude some upper levs fron initial perturbations let model balance in free run
+integer  :: exclude_pert_upper_levs = 1
+! These are not namelist variables, but are related, and calculated from
+! highest_obs_pressure_mb
+real(r8) :: highest_obs_level         = MISSING_R8
+real(r8) :: highest_obs_height_m      = MISSING_R8
+!---- end of namelist (found in file input.nml) ----
+
+namelist /model_nml/ output_state_vector, model_config_file,time_step_seconds, time_step_days, write_grads, &
+                     impact_only_same_kind, print_details, max_obs_lat_degree, highest_obs_pressure_mb,     &
+                      highest_state_pressure_mb, pert_names,pert_sd,pert_base_vals, exclude_pert_upper_levs    
+
+
+contains
+
+!==================================================================
+
+subroutine static_init_model()
+!------------------------------------------------------------------
+!
+! Called to do one time initialization of the model. As examples,
+! might define information about the model size or model timestep.
+! In models that require pre-computed static data, for instance
+! spherical harmonic weights, these would also be computed here.
+! Can be a NULL INTERFACE for the simplest models.
+
+ real(r8)        :: x_loc
+ integer         :: i, j, iunit, io, ncfileid
+ integer         :: max_levs, topog_lons, topog_lats
+ type(time_type) :: model_time 
+
+!------------------------------------------------------------------
+! only execute this code once
+if (module_initialized) return
+! Print module information to log file and stdout.
+call register_module(source, revision, revdate)
+
+! setting calendar type
+! calendar types listed in time_manager_mod.f90
+! this information is NOT passed to LMDZ; it must be set in the LMDZ namelist
+
+call set_calendar_type('GREGORIAN')
+
+! Read a the namelist entry 
+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")
+
+! set the printed output logical variable to reduce printed output;
+! depends on whether this is being called by dart_to_cam (read ens member # from
+! file 'element' )  or by filter (multiple processes, printout controlled by do_output())
+
+if (file_exist('element')) then
+   iunit = get_unit()
+   open(unit = iunit, file='element', form = 'formatted')
+   read(iunit,*) ens_member
+   close(iunit)
+   do_out = .false.
+   if (ens_member == 1) do_out = .true.
+else
+   do_out = do_output()
+   !write(*,*) 'do_out = ',do_out
+   ! static_init_model is called once(?) for each task(?).
+   ! There may be more or fewer ensemble members than tasks.
+   ! No problem if there are fewer.
+   ! In pert_model_state generate a unique ens_member from my_task and globally
+   ! stored info  about previous calls to pert_model_state.
+   num_tasks = task_count()
+   my_task = my_task_id()
+end if
+
+
+! Record (write in a file) the namelist values used for the run ...
+if (do_nml_file()) write(nmlfileunit, nml=model_nml)
+if (do_nml_term()) write(     *     , nml=model_nml)
+
+! Set the model minimum time step from the namelist seconds and days input
+Time_step_atmos = set_time(time_step_seconds, time_step_days)
+
+! read LMDZ 'initial' file domain info
+
+call nc_check(nf90_open(path = trim(model_config_file), mode =nf90_nowrite , ncid = ncfileid), &
+             'static_init_model', 'opening '//trim(model_config_file))
+
+call nc_check(nf90_inquire(ncfileid, num_dims), 'read_lmdz_init_size', 'inquire num_dims')
+
+write(*,*)'Num of coordinate var. in start.nc=',num_dims
+
+call read_lmdz_init_size(ncfileid)
+
+  PS%length     = lon%length*lat%length
+  U%length      = slon%length*lat%length*sigs%length
+  V%length      = lon%length*slat%length*sigs%length
+  T%length      = lon%length*lat%length*sigs%length
+  Q%length      = lon%length*lat%length*sigs%length
+  CLDLIQ%length = lon%length*lat%length*sigs%length
+
+! Lenght of state vector
+  model_size =  PS%length + U%length + V%length + T%length + Q%length + CLDLIQ%length
+print*, 'Model Size =',model_size
+
+call read_lmdz_coord(ncfileid, lon,      'rlonv     ')
+call read_lmdz_coord(ncfileid, lat,      'rlatu     ')
+call read_lmdz_coord(ncfileid, slon,     'rlonu     ')
+call read_lmdz_coord(ncfileid, slat,     'rlatv     ')
+call read_lmdz_coord(ncfileid, presnivs, 'presnivs  ')
+call read_lmdz_coord(ncfileid, ap   ,    'ap        ')
+call read_lmdz_coord(ncfileid, bp   ,    'bp        ')
+call read_lmdz_coord(ncfileid, sigs ,    'nivsigs   ')
+call read_lmdz_coord(ncfileid, temps   , 'temps     ')
+
+
+call change_lon_lat_lev_to_dart()
+!-----------------------------------------------------------------------
+!find hybrid layer coefficient at mid point of layers
+allocate(apm%vals(sigs%length))
+allocate(bpm%vals(sigs%length))
+call hybrid_coefi_mid_layer(apm, bpm, sig%length)
+!-----------------------------------------------------------------------
+
+!----
+max_levs = sig%length  !(sig%length = sigs%length + 1)
+
+nflds = 6  ! variables in state vector
+allocate (cflds(nflds))
+! Order of state variables in statevector 
+cflds=(/'PS      ', 'T       ', 'U       ', 'V       ','Q       ','CLDLIQ  '/)
+call order_state_fields()
+!----------
+
+! start.nc have only one attribute 'title'
+call nc_read_model_atts_2d( ncfileid ,'title', PS ,      'ps      ')
+call nc_read_model_atts_3d( ncfileid ,'title', U  ,      'ucov    ')
+call nc_read_model_atts_3d( ncfileid ,'title', V  ,      'vcov    ')
+call nc_read_model_atts_3d( ncfileid ,'title', T  ,      'teta    ')
+call nc_read_model_atts_3d( ncfileid ,'title', Q  ,      'H2Ov    ')
+call nc_read_model_atts_3d( ncfileid ,'title', CLDLIQ  , 'H2Ol    ')
+!call nc_read_model_atts( ncfileid ,'title',PHIS ,'phisinit')
+
+! Read surface geopotential for use in vertical interpolation in height
+
+topog_lats= lat%length
+topog_lons= lon%length
+allocate(PHIS%vals (topog_lons, topog_lats))
+
+
+allocate (p_col(max_levs), model_h(max_levs))
+allocate(ens_mean(model_size))
+
+!--get PHIS data
+call read_lmdz_horiz (ncfileid, phis , topog_lons, topog_lats, 'phisinit')
+
+!-------
+call nc_check(nf90_close(ncfileid), &
+              'static_init_model', 'closing '//trim(model_config_file))
+
+!------------------------------------------------------------------------
+! arrays for the linking of obs_kinds (KIND_) to model field TYPE_s; 
+! Makes an array of 'locations within the state vector'
+! of  all the available obs kinds that come from obs_kind_mod.
+
+call map_kinds()
+
+!if (len_trim(impact_only_same_kind) > 0) then
+!   impact_kind_index = get_raw_obs_kind_index(impact_only_same_kind)
+!endif
+
+! make sure we only come through here once
+
+module_initialized = .true.
+
+!=======================================================================
+end subroutine 
+
+
+
+subroutine read_lmdz_init_size(ncfileid)
+
+!=======================================================================
+integer,  intent(in)  :: ncfileid
+
+!   dim_ids(i) = i   ! Dimension ids are sequential integers on the NetCDF file.
+
+   call nc_check(nf90_inquire_dimension(ncfileid, 2, slon%var_name , slon%length), &
+                 'read_lmdz_init_size', 'inquire for '//trim(slon%var_name))
+   call nc_check(nf90_inquire_dimension(ncfileid, 3, lat%var_name , lat%length), &
+                 'read_lmdz_init_size', 'inquire for '//trim(lat%var_name))
+   call nc_check(nf90_inquire_dimension(ncfileid, 4, lon%var_name , lon%length), &
+                 'read_lmdz_init_size', 'inquire for '//trim(lon%var_name))
+   call nc_check(nf90_inquire_dimension(ncfileid, 5, slat%var_name , slat%length), &
+                 'read_lmdz_init_size', 'inquire for '//trim(slat%var_name))
+   call nc_check(nf90_inquire_dimension(ncfileid, 6, sigs%var_name , sigs%length), &
+                 'read_lmdz_init_size', 'inquire for '//trim(sigs%var_name))
+   call nc_check(nf90_inquire_dimension(ncfileid, 7, sig%var_name , sig%length), &
+                 'read_lmdz_init_size', 'inquire for '//trim(sig%var_name))
+   !call nc_check(nf90_inquire_dimension(ncfileid, 15, temps%var_name , temps%length), &
+   !              'read_lmdz_init_size', 'inquire for '//trim(temps%var_name))
+    !if (print_details .and. do_out) write(*,*) 'Dims info = ',i, trim(dim_names(i)), dim_sizes(i)
+
+    ap%length       = sig%length
+    bp%length       = sig%length
+    presnivs%length = sigs%length
+    temps%length    = 1
+
+    write(*,"(A10,I3)") slon%var_name , slon%length
+    write(*,"(A10,I3)") lat%var_name , lat%length
+    write(*,"(A10,I3)") lon%var_name , lon%length
+    write(*,"(A10,I3)") slat%var_name , slat%length
+    write(*,"(A10,I3)") sigs%var_name  , sigs%length
+    write(*,"(A10,I3)") sig%var_name   , sig%length
+
+end subroutine
+
+
+subroutine read_lmdz_coord(ncfileid, var, cfield)
+!=======================================================================
+integer,            intent(in)  :: ncfileid   ! file and field IDs
+character (len=8),  intent(in)  :: cfield
+type(grid_1d_type), intent(out) :: var
+!-----------
+!----------------------------------------------------------------------
+! Local workspace
+integer :: i, coord_size             ! grid/array indices
+integer :: ncfldid    ! file and field IDs
+integer :: ncerr      ! other nc errors; don't abort
+integer, dimension(nf90_max_var_dims) :: coord_dims
+integer :: num_atts, keep_atts, alen
+integer                                     :: att_type
+!character (len=nf90_max_name)               :: att_name
+!character (len=nf90_max_name), pointer      :: att_vals(:)
+character (len=nf90_max_name) , pointer     :: att_names(:)
+character (len=nf90_max_name), pointer      :: att_vals(:)
+real(r8)                                    :: resol, resol_1, resol_n
+
+  call nc_check(nf90_inq_varid(ncfileid,trim(cfield), ncfldid), &
+                 'read_lmdz_coord', 'inq_varid '//trim(cfield))
+  call nc_check( nf90_inquire_variable(ncfileid, ncfldid, dimids = coord_dims, nAtts =num_atts), &
+               'read_lmdz_coord', 'inqure_variable '//trim('cfield'))
+
+  allocate(att_names(num_atts), att_vals(num_atts))
+!-------
+ do i=1,num_atts
+
+  call nc_check(nf90_inq_attname(ncfileid, ncfldid, i, att_names(i)), &
+                 'read_lmdz_coord', 'inq_attname '//trim('att_name'))
+  !var%atts_names(i) = att_name
+
+  call nc_check(nf90_get_att(ncfileid, ncfldid, att_names(i),att_vals(i)), &
+                    'read_lmdz_coord', 'get_att '//trim('att_vals' ))
+
+ end do
+
+ call init_grid_1d_instance(var, var%length, num_atts)
+
+
+ var%var_name = cfield
+ var%dim_id = coord_dims(1)
+ var%atts_vals = att_vals 
+ var%atts_names = att_names
+
+ call nc_check(nf90_get_var(ncfileid, ncfldid, var%vals, start=(/1/) &
+    ,count=(/var%length/) ), 'read_lmdz_coord' ,'get_var '//cfield)
+
+   !PRINT*,'reading ',cfield,' using id ',ncfldid,' size ',var%length
+   !WRITE(*,*) 'first, last val: ', var%vals(1),var%vals(var%length)
+   !PRINT*,var%length
+! radian to degree
+if (cfield(1:2) == 'rl') then
+   call rad_to_degree(var)
+end if
+
+
+if (cfield(1:2) == 'ap'.OR.cfield(1:2) == 'bp') then
+   var%resolution = MISSING_R8
+else
+   resol_1 = var%vals(2) - var%vals(1)
+   resol = 1.0_r8/resol_1
+   var%resolution = resol_1
+
+   ! Test all other coordinate spacings.  If any of them differ from the first
+   ! by more than epsilon (smallest meaningful number relative to the coordinate
+   ! spacings)
+   ! then spacing is irregular.
+   Res: do i = 3, var%length 
+      resol_n = var%vals(i) - var%vals(i-1)
+      if (((resol_n - resol_1) *resol) > epsilon(resol_n)) then
+         var%resolution = -1.0_r8
+      !print*,var%var_name , resol_n , var%resolution ;pause
+         exit Res
+      endif
+   end do Res
+endif
+
+ deallocate(att_names, att_vals)
+
+end subroutine
+
+
+   subroutine init_grid_1d_instance(var, length, num_atts)
+!=======================================================================
+! subroutine init_grid_1d_instance(var)
+!
+! Initializes an instance of a lmdz grid variable
+
+type(grid_1d_type), intent(out) :: var
+integer,       intent(in ) :: length, num_atts
+
+! Initialize the storage space and return
+allocate( var%vals      (length))
+var%vals = 0.0_r8
+
+allocate( var%atts_names(num_atts))
+allocate( var%atts_vals (num_atts))
+var%num_atts = num_atts
+
+!var%length = length
+
+
+end subroutine init_grid_1d_instance
+
+
+subroutine end_grid_1d_instance(var)
+!=======================================================================
+! subroutine end_grid_1d_instance(var)
+!
+! Ends an instance of a lmdz  grid_1d variable
+
+ type(grid_1d_type), intent(inout) :: var
+
+ deallocate(var%vals, var%atts_names, var%atts_vals)
+
+end subroutine end_grid_1d_instance
+
+
+
+   subroutine nc_read_model_atts_3d(  ncfileid , att, var, cfield)
+!=======================================================================
+! Local workspace
+integer :: i, nchars, ierr
+integer :: ncfileid, ncfldid, ncattid, att_type
+!----------------------------------------------------------------------
+
+character (len=8),  intent(in)  :: cfield
+character (len=*),  intent(in)  :: att
+type(data_3d_type)              :: var
+character (len=128)             :: att_vals
+!----------------------------------------------------------------------
+
+    call nc_check(nf90_inq_varid(ncfileid, cfield, ncfldid),'nc_read_model_atts', &
+                 'inq_varid '//trim(cfield))
+ 
+   ierr = nf90_inquire_attribute(ncfileid, ncfldid, trim(att), att_type, nchars, ncattid)
+
+   if (ierr == nf90_noerr) then
+      call nc_check(nf90_get_att(ncfileid, ncfldid, trim(att) ,att_vals ), &
+                    'nc_read_model_atts', 'get_att '//trim(att))
+      att_vals(nchars+1:128) = ' '
+   else
+      WRITE(*,*) ncfldid, 'NOT AVAILABLE!'
+   end if
+
+    var%atts_names = att 
+    var%atts_vals  = att_vals
+
+end subroutine nc_read_model_atts_3d
+
+
+   subroutine nc_read_model_atts_2d(  ncfileid , att, var, cfield)
+!=======================================================================
+! Local workspace
+integer :: i, nchars, ierr
+integer :: ncfileid, ncfldid, ncattid, att_type
+!----------------------------------------------------------------------
+
+character (len=8),  intent(in)  :: cfield
+character (len=*),  intent(in)  :: att
+type(data_2d_type)              :: var
+character (len=128)             :: att_vals
+!----------------------------------------------------------------------
+
+    call nc_check(nf90_inq_varid(ncfileid, cfield,ncfldid),'nc_read_model_atts', &
+                 'inq_varid '//trim(cfield))
+
+   ierr = nf90_inquire_attribute(ncfileid, ncfldid, trim(att), att_type, nchars,ncattid)
+
+   if (ierr == nf90_noerr) then
+      call nc_check(nf90_get_att(ncfileid, ncfldid, trim(att) ,att_vals ), &
+                    'nc_read_model_atts', 'get_att '//trim(att))
+      att_vals(nchars+1:128) = ' '
+   else
+      WRITE(*,*) ncfldid, 'NOT AVAILABLE!'
+   end if
+
+    var%atts_names = att
+    var%atts_vals  = att_vals
+
+end subroutine nc_read_model_atts_2d
+
+
+
+
+   subroutine read_lmdz_horiz(ncfileid, var, dim1, dim2, cfield)
+!======================================================
+! should be called with cfield = a 2D record variable  (time,lat,lon):
+
+implicit none
+!------------------------------------------------------
+integer,                         intent(in)  :: ncfileid, dim1, dim2
+type(data_2d_type)                           :: var
+character (len=8),               intent(in)  :: cfield
+
+!------------------------------------------------------
+integer :: ncfldid
+integer :: i, j
+!if (print_details .and. do_out) PRINT*,'read_lmdz_horiz; reading ',cfield
+
+
+call nc_check(nf90_inq_varid(ncfileid, trim(cfield), ncfldid), &
+              'read_lmdz_horiz', 'inq_varid '//trim(cfield))
+call nc_check(nf90_get_var(ncfileid, ncfldid, var%vals, start=(/1,1,1/), &
+           count=(/dim1, dim2, 1/)), 'read_lmdz_horiz', trim(cfield))
+
+call convert_grid_2d_data_to_dart(dim1,dim2,botm_positive_lon_index,var%vals)
+
+if (cfield == 'phisinit') then
+
+ if (alloc_phis) then
+     allocate ( phis_stagr_lonu( slon%length,  lat%length) )   ! at UCOV on grid C
+     allocate ( phis_stagr_latv( lon%length , slat%length) )   ! at VCOV on grid C
+     alloc_phis = .false. 
+
+
+     do i = 1, slon%length
+       do j = 1, lat%length
+        phis_stagr_lonu(i, j) = 0.5 * (PHIS%vals(i, j) + PHIS%vals(i+1, j))       
+       end do
+     end do 
+
+     do i = 1, lon%length
+       do j = 1, slat%length
+        phis_stagr_latv(i, j) = 0.5 * (PHIS%vals(i, j) + PHIS%vals(i, j+1))       
+       end do
+     end do 
+
+  end if ! alloc_phis 
+end if ! cfield 
+end subroutine read_lmdz_horiz
+
+ 
+
+
+
+ subroutine map_kinds()
+!=======================================================================
+! subroutine map_kinds()
+! Borrowed from CAM
+
+! ? Should this be a function instead; removes need to dimension obs_loc_in
+! arbitrarily

@@ Diff output truncated at 40000 characters. @@


More information about the Dart-dev mailing list