[Dart-dev] [5834] DART/branches/development/models/noah: First cut at moving from noah_1d to the general noah.

nancy at ucar.edu nancy at ucar.edu
Mon Aug 6 19:55:11 MDT 2012


Revision: 5834
Author:   thoar
Date:     2012-08-06 19:55:11 -0600 (Mon, 06 Aug 2012)
Log Message:
-----------
First cut at moving from noah_1d to the general noah.
After this commit, will rename files etc.

Modified Paths:
--------------
    DART/branches/development/models/noah/dart_to_noah1D.f90
    DART/branches/development/models/noah/dart_to_noah1D.nml
    DART/branches/development/models/noah/model_mod.f90
    DART/branches/development/models/noah/model_mod.nml
    DART/branches/development/models/noah/noah1D_to_dart.f90
    DART/branches/development/models/noah/noah1D_to_dart.nml
    DART/branches/development/models/noah/work/input.nml
    DART/branches/development/models/noah/work/mkmf_dart_to_noah1D
    DART/branches/development/models/noah/work/mkmf_noah1D_to_dart
    DART/branches/development/models/noah/work/path_names_create_fixed_network_seq
    DART/branches/development/models/noah/work/path_names_create_obs_sequence
    DART/branches/development/models/noah/work/path_names_dart_to_noah1D
    DART/branches/development/models/noah/work/path_names_filter
    DART/branches/development/models/noah/work/path_names_model_mod_check
    DART/branches/development/models/noah/work/path_names_noah1D_to_dart
    DART/branches/development/models/noah/work/path_names_obs_diag
    DART/branches/development/models/noah/work/path_names_obs_sequence_tool
    DART/branches/development/models/noah/work/path_names_perfect_model_obs
    DART/branches/development/models/noah/work/path_names_restart_file_tool

-------------- next part --------------
Modified: DART/branches/development/models/noah/dart_to_noah1D.f90
===================================================================
--- DART/branches/development/models/noah/dart_to_noah1D.f90	2012-08-06 22:19:46 UTC (rev 5833)
+++ DART/branches/development/models/noah/dart_to_noah1D.f90	2012-08-07 01:55:11 UTC (rev 5834)
@@ -11,14 +11,14 @@
 ! $Date$
 
 !----------------------------------------------------------------------
-! purpose: interface between DART and the noah1D model
+! purpose: interface between DART and the NOAH model
 !
-! method: Read DART state vector and overwrite values in a noah1D restart file.
+! method: Read DART state vector and overwrite values in a noah restart file.
 !         If the DART state vector has an 'advance_to_time' present, 
 !         it is read ... but nothing happens with it at this time.
-!         DART is NEVER expected to advance noah1D.
+!         DART is NEVER expected to advance noah.
 !
-!         The dart_to_noah1D_nml namelist setting for advance_time_present 
+!         The dart_to_noah_nml namelist setting for advance_time_present 
 !         determines whether or not the input file has an 'advance_to_time'.
 !         Typically, only temporary files like 'assim_model_state_ic' have
 !         an 'advance_to_time'.
@@ -48,15 +48,15 @@
 ! The namelist variables
 !------------------------------------------------------------------
 
-character (len = 128) :: dart_to_noah1D_input_file = 'dart_restart'
+character (len = 128) :: dart_to_noah_input_file = 'dart_restart'
 logical               :: advance_time_present   = .false.
 
-namelist /dart_to_noah1D_nml/ dart_to_noah1D_input_file, &
+namelist /dart_to_noah_nml/ dart_to_noah_input_file, &
                            advance_time_present
 
 !----------------------------------------------------------------------
 
-character(len=20)     :: noah1D_restart_filename = 'noah1d_input.nml'
+character(len=20)     :: noah_restart_filename = 'noah_input.nml'
 integer               :: iunit, io, x_size
 type(time_type)       :: model_time, adv_to_time
 real(r8), allocatable :: statevector(:)
@@ -64,10 +64,10 @@
 
 !----------------------------------------------------------------------
 
-call initialize_utilities(progname='dart_to_noah1D', output_flag=verbose)
+call initialize_utilities(progname='dart_to_noah', output_flag=verbose)
 
 !----------------------------------------------------------------------
-! Call model_mod:static_init_model() which reads the noah_1d namelist
+! Call model_mod:static_init_model() which reads the NOAH namelist
 ! to set location and state vector
 !----------------------------------------------------------------------
 
@@ -78,20 +78,20 @@
 
 ! Read the namelist to get the input filename. 
 
-call find_namelist_in_file("input.nml", "dart_to_noah1D_nml", iunit)
-read(iunit, nml = dart_to_noah1D_nml, iostat = io)
-call check_namelist_read(iunit, io, "dart_to_noah1D_nml")
+call find_namelist_in_file("input.nml", "dart_to_noah_nml", iunit)
+read(iunit, nml = dart_to_noah_nml, iostat = io)
+call check_namelist_read(iunit, io, "dart_to_noah_nml")
 
 write(*,*)
-write(*,'(''dart_to_noah1D:converting DART file '',A, &
-      &'' to noah_1d input namelist '',A)') &
-     trim(dart_to_noah1D_input_file), trim(noah1D_restart_filename)
+write(*,'(''dart_to_noah:converting DART file '',A, &
+      &'' to NOAH input namelist '',A)') &
+     trim(dart_to_noah_input_file), trim(noah_restart_filename)
 
 !----------------------------------------------------------------------
 ! Reads the valid time, the state, and the target time.
 !----------------------------------------------------------------------
 
-iunit = open_restart_read(dart_to_noah1D_input_file)
+iunit = open_restart_read(dart_to_noah_input_file)
 
 if ( advance_time_present ) then
    call aread_state_restart(model_time, statevector, iunit, adv_to_time)
@@ -105,25 +105,25 @@
 !----------------------------------------------------------------------
 
 if ( advance_time_present ) then
-   call dart_vector_to_model_file(statevector, noah1D_restart_filename, model_time, adv_to_time)
+   call dart_vector_to_model_file(statevector, noah_restart_filename, model_time, adv_to_time)
 else
-   call dart_vector_to_model_file(statevector, noah1D_restart_filename, model_time)
+   call dart_vector_to_model_file(statevector, noah_restart_filename, model_time)
 endif
 
 !----------------------------------------------------------------------
 ! Log what we think we're doing, and exit.
 !----------------------------------------------------------------------
 
-call print_date( model_time,'dart_to_noah1D:noah1D  model date')
-call print_time( model_time,'dart_to_noah1D:DART    model time')
-call print_date( model_time,'dart_to_noah1D:noah1D  model date',logfileunit)
-call print_time( model_time,'dart_to_noah1D:DART    model time',logfileunit)
+call print_date( model_time,'dart_to_noah:noah  model date')
+call print_time( model_time,'dart_to_noah:DART    model time')
+call print_date( model_time,'dart_to_noah:noah  model date',logfileunit)
+call print_time( model_time,'dart_to_noah:DART    model time',logfileunit)
 
 if ( advance_time_present ) then
-   call print_time(adv_to_time,'dart_to_noah1D:advance_to time')
-   call print_date(adv_to_time,'dart_to_noah1D:advance_to date')
-   call print_time(adv_to_time,'dart_to_noah1D:advance_to time',logfileunit)
-   call print_date(adv_to_time,'dart_to_noah1D:advance_to date',logfileunit)
+   call print_time(adv_to_time,'dart_to_noah:advance_to time')
+   call print_date(adv_to_time,'dart_to_noah:advance_to date')
+   call print_time(adv_to_time,'dart_to_noah:advance_to time',logfileunit)
+   call print_date(adv_to_time,'dart_to_noah:advance_to date',logfileunit)
 endif
 
 ! When called with 'end', timestamp will call finalize_utilities()

Modified: DART/branches/development/models/noah/dart_to_noah1D.nml
===================================================================
--- DART/branches/development/models/noah/dart_to_noah1D.nml	2012-08-06 22:19:46 UTC (rev 5833)
+++ DART/branches/development/models/noah/dart_to_noah1D.nml	2012-08-07 01:55:11 UTC (rev 5834)
@@ -1,5 +1,5 @@
-&dart_to_noah1D_nml
-   dart_to_noah1D_output_file   = 'dart_restart',
+&dart_to_noah_nml
+   dart_to_noah_output_file   = 'dart_restart',
    advance_time_present         = .true.,
   /
 

Modified: DART/branches/development/models/noah/model_mod.f90
===================================================================
--- DART/branches/development/models/noah/model_mod.f90	2012-08-06 22:19:46 UTC (rev 5833)
+++ DART/branches/development/models/noah/model_mod.f90	2012-08-07 01:55:11 UTC (rev 5834)
@@ -10,13 +10,6 @@
 ! $Revision$
 ! $Date$
 
-! This is a noah_1d showing the interfaces required for a model to be compliant
-! with the DART data assimilation infrastructure. The public interfaces listed
-! must all be supported with the argument lists as indicated. Many of the interfaces
-! are not required for minimal implementation (see the discussion of each
-! interface and look for NULL INTERFACE). 
-
-! Modules that are absolutely required for use are listed
 use        types_mod, only : r8, MISSING_R8, obstypelength
 use time_manager_mod, only : time_type, set_time, set_date, get_time,          &
                              print_time, print_date, set_calendar_type,        &
@@ -84,9 +77,9 @@
 ! not required by DART but for larger models can be useful for
 ! utility programs that are tightly tied to the other parts of
 ! the model_mod code.
-public :: noah1d_to_dart_vector, &
+public :: noah_to_dart_vector, &
           dart_vector_to_model_file, &
-          get_noah1D_restart_filename
+          get_noah_restart_filename
 
 ! version controlled file description for error handling, do not edit
 character(len=128), parameter :: &
@@ -108,23 +101,24 @@
 !------------------------------------------------------------------
 
 integer :: nfields
-integer, parameter :: max_state_variables = 40
-integer, parameter :: num_state_table_columns = 2
-character(len=obstypelength) :: variable_table(max_state_variables, num_state_table_columns)
+integer, parameter :: NSOLDX = 100
+integer, parameter :: MAX_STATE_VARIABLES = 40
+integer, parameter :: NUM_STATE_TABLE_COLUMNS = 2
+character(len=obstypelength) :: variable_table(MAX_STATE_VARIABLES, NUM_STATE_TABLE_COLUMNS)
 
 !------------------------------------------------------------------
 ! things which can/should be in the DART model_nml
 !------------------------------------------------------------------
 
-character(len=128)    :: noah_netcdf_filename   = 'OUTPUT.NC'
-character(len=128)    :: noah_namelist_filename = 'somelocation.dat'
+character(len=128)    :: noah_netcdf_filename   = 'restart.nc'
+character(len=128)    :: noah_namelist_filename = 'namelist.hrldas'
 integer               :: assimilation_period_days     = 0
 integer               :: assimilation_period_seconds  = 60
 real(r8)              :: model_perturbation_amplitude = 0.2
 logical               :: output_state_vector          = .true.
 character(len=32)     :: calendar = 'Gregorian'
 integer               :: debug    = 0  ! turn up for more and more debug messages
-character(len=obstypelength) :: noah_variables(max_state_variables*num_state_table_columns) = ' '
+character(len=obstypelength) :: noah_variables(MAX_STATE_VARIABLES*NUM_STATE_TABLE_COLUMNS) = ' '
 
 namelist /model_nml/ noah_netcdf_filename, noah_namelist_filename, &
           assimilation_period_days, assimilation_period_seconds,   &
@@ -138,74 +132,48 @@
 ! DART needs to write a NOAH-compatible namelist. 
 !------------------------------------------------------------------
 
-integer, parameter :: nSoilLayers = 4
+! ZSOIL, set through the namelist, is the BOTTOM of each soil layer (m)
+! Values are negative, implying depth below the surface.
+real(r8), dimension(nsoldx) :: zsoil
+integer                     :: nsoil
 
-character(len=12) :: startdate
-character(len=12) :: enddate
-logical  :: loop_for_a_while
-real(r8) :: Latitude
-real(r8) :: Longitude
-integer  :: Forcing_Timestep
-integer  :: Noahlsm_Timestep
-logical  :: Sea_ice_point
-real(r8), dimension(nSoilLayers) :: Soil_layer_thickness
-real(r8), dimension(nSoilLayers) :: Soil_Temperature
-real(r8), dimension(nSoilLayers) :: Soil_Moisture
-real(r8), dimension(nSoilLayers) :: Soil_Liquid
-real(r8) :: Skin_Temperature
-real(r8) :: Canopy_water
-real(r8) :: Snow_depth
-real(r8) :: Snow_equivalent
-real(r8) :: Deep_Soil_Temperature
-character(len=256) :: Landuse_dataset
-integer  :: Soil_type_index
-integer  :: Vegetation_type_index
-integer  :: Urban_veg_category
-integer  :: glacial_veg_category
-integer  :: Slope_type_index
-real(r8) :: Max_snow_albedo
-real(r8) :: Air_temperature_level
-real(r8) :: Wind_level
-real(r8) :: Green_Vegetation_Min
-real(r8) :: Green_Vegetation_Max
-logical  :: Usemonalb
-logical  :: Rdlai2d
-integer  :: sfcdif_option
-integer  :: iz0tlnd
-real(r8), dimension(12) :: Albedo_monthly
-real(r8), dimension(12) :: Shdfac_monthly
-real(r8), dimension(12) ::    lai_monthly
-real(r8), dimension(12) ::  Z0brd_monthly
+CHARACTER(len=256) :: indir
+character(len=256) :: outdir = "."
+character(len=256) :: hrldas_constants_file = " "
+character(len=256) :: external_fpar_filename_template = " "
+character(len=256) :: external_lai_filename_template = " "
+character(len=256) :: restart_filename_requested = " "
+integer            :: split_output_count = 1
+integer            :: restart_frequency_hours
+integer            :: output_timestep
+integer            :: subwindow_xstart = 1
+integer            :: subwindow_ystart = 1
+integer            :: subwindow_xend = 0
+integer            :: subwindow_yend = 0
+integer            :: sfcdif_option = 0
+integer            :: iz0tlnd = 0
+logical            :: update_snow_from_forcing = .TRUE.
 
-namelist /METADATA_NAMELIST/ startdate, enddate, loop_for_a_while,   &
-         Latitude, Longitude, Forcing_Timestep, Noahlsm_Timestep,    &
-         Sea_ice_point, Soil_layer_thickness, Soil_Temperature,      &
-         Soil_Moisture, Soil_Liquid, Skin_Temperature, Canopy_water, &
-         Snow_depth, Snow_equivalent, Deep_Soil_Temperature, Landuse_dataset, &
-         Soil_type_index, Vegetation_type_index, Urban_veg_category, &
-         glacial_veg_category, Slope_type_index, Max_snow_albedo,    &
-         Air_temperature_level, Wind_level, Green_Vegetation_Min,    &
-         Green_Vegetation_Max, Usemonalb, Rdlai2d, sfcdif_option,    &
-         iz0tlnd, Albedo_monthly, Shdfac_monthly, lai_monthly, Z0brd_monthly
+integer  :: start_year, start_month, start_day, start_hour, start_min
+integer  :: noah_timestep = -999
+integer  :: forcing_timestep = -999
 
-! We are going to create a DART state vector out of the following 17 items
+integer  :: khour, kday
+real(r8) :: zlvl, zlvl_wind
 
-type noahtype
-   private
-   real(r8), dimension(nSoilLayers) :: Soil_Temperature
-   real(r8), dimension(nSoilLayers) :: Soil_Moisture
-   real(r8), dimension(nSoilLayers) :: Soil_Liquid
-   real(r8) :: Skin_Temperature
-   real(r8) :: Canopy_water
-   real(r8) :: Snow_depth
-   real(r8) :: Snow_equivalent
-   real(r8) :: Deep_Soil_Temperature
-end type noahtype
+namelist / NOAHLSM_OFFLINE/ indir, nsoil, zsoil, forcing_timestep, noah_timestep, &
+       start_year, start_month, start_day, start_hour, start_min, &
+       restart_frequency_hours, output_timestep, &
+       split_output_count, sfcdif_option, iz0tlnd, update_snow_from_forcing, &
+       khour, kday, zlvl, zlvl_wind, hrldas_constants_file, outdir, restart_filename_requested, &
+       external_fpar_filename_template, external_lai_filename_template, &
+       subwindow_xstart, subwindow_xend, subwindow_ystart, subwindow_yend
 
+!------------------------------------------------------------------
+
 ! define model parameters here
 type(time_type)     :: time_step
-type(location_type) :: state_loc(0:nSoilLayers)
-type(noahtype)      :: noah1d
+type(location_type),allocatable, dimension(:) :: state_loc
 
 ! Everything needed to describe a variable
 
@@ -226,7 +194,7 @@
    character(len=paramname_length) :: kind_string
 end type progvartype
 
-type(progvartype), dimension(max_state_variables) :: progvar
+type(progvartype), dimension(MAX_STATE_VARIABLES) :: progvar
 
 !------------------------------------------------------------------------------
 ! These are the metadata arrays that are the same size as the state vector.
@@ -243,8 +211,11 @@
 type(time_type)    :: model_time_step  ! smallest time to adv model
 character(len=256) :: string1, string2, string3
 logical, save      :: module_initialized = .false.
-real(r8), dimension(nSoilLayers) :: soil_depths
+real(r8), allocatable, dimension(:) :: soil_depths
 
+real(r8), allocatable, dimension(:,:) :: xlong, xlat
+integer :: south_north, west_east
+
 !==================================================================
 contains
 !==================================================================
@@ -284,16 +255,7 @@
 if (do_nml_file()) write(nmlfileunit, nml=model_nml)
 if (do_nml_term()) write(     *     , nml=model_nml)
 
-! Read the NOAH namelist
-call find_namelist_in_file(trim(noah_namelist_filename), "METADATA_NAMELIST", iunit)
-read(iunit, nml = METADATA_NAMELIST, iostat = io)
-call check_namelist_read(iunit, io, "METADATA_NAMELIST")
-
-! Record the NOAH namelist
-if (do_nml_file()) write(nmlfileunit, nml=METADATA_NAMELIST)
-if (do_nml_term()) write(     *     , nml=METADATA_NAMELIST)
-
-! Check to make sure the required input files exist
+! Check to make sure the required NOAH input files exist
 if ( .not. file_exist(noah_netcdf_filename) ) then
    write(string1,*) 'cannot open file ', trim(noah_netcdf_filename),' for reading.'
    call error_handler(E_ERR,'static_init_model',string1,source,revision,revdate)
@@ -303,10 +265,23 @@
    call error_handler(E_ERR,'static_init_model',string1,source,revision,revdate)
 endif
 
-! convert the [-180,180] longitudes to [0,360)
+! Read the NOAH namelist
+call find_namelist_in_file(trim(noah_namelist_filename), "NOAHLSM_OFFLINE", iunit)
+read(iunit, nml = NOAHLSM_OFFLINE, iostat = io)
+call check_namelist_read(iunit, io, "NOAHLSM_OFFLINE")
 
-if (Longitude < 0.0_r8) Longitude = Longitude + 360.0_r8
+! Record the NOAH namelist
+if (do_nml_file()) write(nmlfileunit, nml=NOAHLSM_OFFLINE)
+if (do_nml_term()) write(     *     , nml=NOAHLSM_OFFLINE)
 
+! Check to make sure the NOAH constants file exists
+if ( .not. file_exist(hrldas_constants_file) ) then
+   write(string1,*) 'cannot open file ', trim(hrldas_constants_file),' for reading.'
+   call error_handler(E_ERR,'static_init_model',string1,source,revision,revdate)
+endif
+
+call get_hrldas_constants(hrldas_constants_file) ! TJH FIXME - write this
+
 ! The time_step in terms of a time type must also be initialized.
 
 call set_calendar_type( calendar )
@@ -325,30 +300,31 @@
 
 ! Make sure the number of soil layers is as we expect
 
-call nc_check(nf90_inq_dimid(iunit, 'num_soil_layers', dimIDs(1)), &
-                  'static_init_model','inq_dimid num_soil_layers '//trim(noah_netcdf_filename))
+call nc_check(nf90_inq_dimid(iunit, 'soil_layers_stag', dimIDs(1)), &
+                  'static_init_model','inq_dimid soil_layers_stag '//trim(noah_netcdf_filename))
 call nc_check(nf90_inquire_dimension(iunit, dimIDs(1), len=nLayers), &
                   'static_init_model','inquire_dimension Time '//trim(noah_netcdf_filename))
 
-if (nSoilLayers /= nLayers) then
-   write(string1,*) 'Expected ',nSoilLayers,' soil layers ', &
+if (nsoil /= nLayers) then
+   write(string1,*) 'Expected ',nsoil,' soil layers ', &
                        trim(noah_netcdf_filename),' has ',nLayers
    call error_handler(E_ERR,'static_init_model',string1,source,revision,revdate)
 endif
 
+! TJH FIXME ... simplify this ... extend to 2D case ...
 ! convert soil thicknesses to depths
 ! closer to the center of the earth is an increasingly large negative number
-soil_depths(1) = Soil_layer_thickness(1) 
-do i = 2,nSoilLayers
-   soil_depths(i) = soil_depths(i-1) + Soil_layer_thickness(i)
+allocate(soil_depths(0:nsoil), state_loc(0:nsoil))
+soil_depths(0) = 0.0_r8
+do i = 1,nsoil
+   soil_depths(i) = soil_depths(i-1) + zsoil(i)
 enddo
 soil_depths = -1.0_r8 * soil_depths
 
-! there are only nSoilLayers + 1 different locations
-
-state_loc(0) = set_location(Longitude, Latitude, 0.0_r8, VERTISHEIGHT)
-do i = 1,nSoilLayers
-   state_loc(i) = set_location(Longitude, Latitude, soil_depths(i), VERTISHEIGHT)
+state_loc(0)   = set_location(xlong(1,1), xlat(1,1), 0.0_r8, VERTISHEIGHT)
+! there are only nsoil + 1 different locations
+do i = 1,nsoil
+   state_loc(i) = set_location(xlong(1,1), xlat(1,1), soil_depths(i), VERTISHEIGHT)
 enddo
 
 !---------------------------------------------------------------
@@ -461,12 +437,12 @@
 if ((debug > 8) .and. do_output()) then
 
    write(*,*)
-   do i=1,nSoilLayers
+   do i=1,nsoil
       write(*,*)'soil layer',i,soil_depths(i)
    enddo
 
    write(*,*)
-   do i=0,nSoilLayers
+   do i=0,nsoil
       call write_location(iunit,state_loc(i),charstring=string1)
       write(*,*)'location ',i,' is ',trim(string1)
    enddo
@@ -730,7 +706,7 @@
 integer :: StateVarDimID    ! netCDF pointer to state variable dimension (model size)
 integer :: MemberDimID      ! netCDF pointer to dimension of ensemble    (ens_size)
 integer :: TimeDimID        ! netCDF pointer to time dimension           (unlimited)
-integer :: nSoilLayersDimID !   ..     ..                                (# soil layers)
+integer :: nsoilDimID !   ..     ..                                (# soil layers)
 
 integer :: StateVarVarID   ! netCDF pointer to state variable coordinate array
 integer :: StateVarID      ! netCDF pointer to 3D [state,copy,time] array
@@ -795,9 +771,9 @@
                            len=model_size, dimid=StateVarDimID), &
                            "nc_write_model_atts", "def_dim state")
 
-call nc_check(nf90_def_dim(ncid=ncFileID, name="nSoilLayers",  &
-                           len=nSoilLayers, dimid=nSoilLayersDimID), &
-                           "nc_write_model_atts", "def_dim nSoilLayers")
+call nc_check(nf90_def_dim(ncid=ncFileID, name="nsoil",  &
+                           len=nsoil, dimid=nsoilDimID), &
+                           "nc_write_model_atts", "def_dim nsoil")
 
 !-------------------------------------------------------------------------------
 ! Write Global Attributes 
@@ -815,25 +791,37 @@
                           "nc_write_model_atts", "put_att model_revision")
 call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "model_revdate" ,revdate), &
                           "nc_write_model_atts", "put_att model_revdate")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "model","noah_1d"), &
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "model","NOAH"), &
                           "nc_write_model_atts", "put_att model")
 call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "calendar",trim(calendar)), &
                           "nc_write_model_atts", "put_att calendar")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Longitude",Longitude), &
-                          "nc_write_model_atts", "put_att Longitude")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Latitude",Latitude), &
-                          "nc_write_model_atts", "put_att Latitude")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Forcing_Timestep",Forcing_Timestep), &
-                          "nc_write_model_atts", "put_att Forcing_Timestep")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Noahlsm_Timestep",Noahlsm_Timestep), &
-                          "nc_write_model_atts", "put_att Noahlsm_Timestep")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Soil_type_index",Soil_type_index), &
-                          "nc_write_model_atts", "put_att Soil_type_index")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Vegetation_type_index",Vegetation_type_index), &
-                          "nc_write_model_atts", "put_att Vegetation_type_index")
-call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Urban_veg_category",Urban_veg_category), &
-                          "nc_write_model_atts", "put_att Urban_veg_category")
 
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "HRLDAS_CONSTANTS_FILE",trim(hrldas_constants_file)), &
+                          "nc_write_model_atts", "put_att HRLDAS_CONSTANTS_FILE")
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "HRLDAS_INDIR",trim(INDIR)), &
+                          "nc_write_model_atts", "put_att HRLDAS_INDIR")
+
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "RESTART_FILENAME_REQUESTED",trim(restart_filename_requested)), &
+                          "nc_write_model_atts", "put_att RESTART_FILENAME_REQUESTED")
+
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "KDAY",KDAY), &
+                          "nc_write_model_atts", "put_att KDAY")
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "KHOUR",KHOUR), &
+                          "nc_write_model_atts", "put_att KHOUR")
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "FORCING_TIMESTEP",forcing_timestep), &
+                          "nc_write_model_atts", "put_att FORCING_TIMESTEP")
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "NOAH_TIMESTEP",noah_timestep), &
+                          "nc_write_model_atts", "put_att NOAH_TIMESTEP")
+call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "OUTPUT_TIMESTEP",output_timestep), &
+                          "nc_write_model_atts", "put_att OUTPUT_TIMESTEP")
+
+! call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Soil_type_index",Soil_type_index), &
+!                           "nc_write_model_atts", "put_att Soil_type_index")
+! call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Vegetation_type_index",Vegetation_type_index), &
+!                           "nc_write_model_atts", "put_att Vegetation_type_index")
+! call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "Urban_veg_category",Urban_veg_category), &
+!                           "nc_write_model_atts", "put_att Urban_veg_category")
+
 !-------------------------------------------------------------------------------
 ! Determine shape of most important namelist
 !-------------------------------------------------------------------------------
@@ -1129,7 +1117,7 @@
 enddo MyLoop
 
 if (ngood == nrows) then
-   string1 = 'WARNING: There is a possibility you need to increase ''max_state_variables'''
+   string1 = 'WARNING: There is a possibility you need to increase ''MAX_STATE_VARIABLES'''
    write(string2,'(''WARNING: you have specified at least '',i4,'' perhaps more.'')')ngood
    call error_handler(E_MSG,'verify_state_variables',string1,source,revision,revdate,text2=string2)
 endif
@@ -1139,20 +1127,20 @@
 
 
 
-subroutine get_noah1D_restart_filename( noah1D_restart_filename )
+subroutine get_noah_restart_filename( noah_restart_filename )
 !------------------------------------------------------------------
-character(len=*), intent(out) :: noah1d_restart_filename
+character(len=*), intent(out) :: noah_restart_filename
 
 if ( .not. module_initialized ) call static_init_model
 
-noah1d_restart_filename = noah_netcdf_filename
+noah_restart_filename = noah_netcdf_filename
 
-end subroutine get_noah1D_restart_filename
+end subroutine get_noah_restart_filename
 
 
 
 
-subroutine noah1d_to_dart_vector(filename, state_vector, restart_time)
+subroutine noah_to_dart_vector(filename, state_vector, restart_time)
 !------------------------------------------------------------------
 ! Reads the current time and state variables from a model data
 ! file and packs them into a dart state vector.
@@ -1179,11 +1167,11 @@
 
 if ( .not. file_exist(filename) ) then
    write(string1,*) 'file <', trim(filename),'> does not exist.'
-   call error_handler(E_ERR,'noah1d_to_dart_vector',string1,source,revision,revdate)
+   call error_handler(E_ERR,'noah_to_dart_vector',string1,source,revision,revdate)
 endif
 
 call nc_check(nf90_open(adjustl(filename), NF90_NOWRITE, ncid), &
-                   'noah1d_to_dart_vector', 'open '//trim(filename))
+                   'noah_to_dart_vector', 'open '//trim(filename))
 
 restart_time = get_state_time(ncid,filename)
 
@@ -1202,17 +1190,17 @@
    string3    = trim(filename)//' '//trim(varname)
 
    call nc_check(nf90_inq_varid(ncid, varname, VarID), &
-            'noah1d_to_dart_vector', 'inq_varid '//trim(string3))
+            'noah_to_dart_vector', 'inq_varid '//trim(string3))
 
    call nc_check(nf90_inquire_variable(ncid,VarID,dimids=dimIDs,ndims=ncNdims), &
-            'noah1d_to_dart_vector', 'inquire '//trim(string3))
+            'noah_to_dart_vector', 'inquire '//trim(string3))
 
    ! Check the rank of the variable
 
    if ( ncNdims /= progvar(ivar)%numdims ) then
       write(string1, *) 'netCDF rank of '//trim(varname)//' does not match derived type knowledge'
       write(string2, *) 'netCDF rank is ',ncNdims,' expected ',progvar(ivar)%numdims
-      call error_handler(E_ERR,'noah1d_to_dart_vector', string1, &
+      call error_handler(E_ERR,'noah_to_dart_vector', string1, &
                         source,revision,revdate,text2=string2)
    endif
 
@@ -1223,7 +1211,7 @@
 
       write(string1,'(''inquire dimension'',i2,A)') i,trim(string3)
       call nc_check(nf90_inquire_dimension(ncid, dimIDs(i), len=dimlen), &
-            'noah1d_to_dart_vector', string1)
+            'noah_to_dart_vector', string1)
 
       ncstart(i) = 1
       nccount(i) = dimlen
@@ -1234,7 +1222,7 @@
          nccount(i) = 1
       elseif ( dimlen /= progvar(ivar)%dimlens(i) ) then
          write(string1,*) trim(string3),' dim/dimlen ',i,dimlen,' not ',progvar(ivar)%dimlens(i)
-         call error_handler(E_ERR,'noah1d_to_dart_vector',string1,source,revision,revdate)
+         call error_handler(E_ERR,'noah_to_dart_vector',string1,source,revision,revdate)
       endif
 
    enddo
@@ -1250,7 +1238,7 @@
 
       call nc_check(nf90_get_var(ncid, VarID, data_1d_array,  &
                      start=ncstart(1:1), count=nccount(1:1)), &
-                  'noah1d_to_dart_vector', 'get_var '//trim(string3))
+                  'noah_to_dart_vector', 'get_var '//trim(string3))
 
       do i = 1, dimlen
          state_vector(indx) = data_1d_array(i)
@@ -1265,7 +1253,7 @@
 
       call nc_check(nf90_get_var(ncid, VarID, data_2d_array,  &
                      start=ncstart(1:2), count=nccount(1:2)), &
-                  'noah1d_to_dart_vector', 'get_var '//trim(string3))
+                  'noah_to_dart_vector', 'get_var '//trim(string3))
 
       do j = 1, progvar(ivar)%dimlens(2)
       do i = 1, progvar(ivar)%dimlens(1)
@@ -1279,7 +1267,7 @@
 
       write(string1, *)'Variable '//trim(varname)//' has ',ncNdims,' dimensions.'
       write(string2, *)'cannot handle that.'
-      call error_handler(E_ERR,'noah1d_to_dart_vector', string1, &
+      call error_handler(E_ERR,'noah_to_dart_vector', string1, &
                         source,revision,revdate,text2=string2)
 
    endif
@@ -1288,7 +1276,7 @@
    if ( indx /= progvar(ivar)%indexN ) then
       write(string1, *)'Variable '//trim(varname)//' filled wrong.'
       write(string2, *)'Should have ended at ',progvar(ivar)%indexN,' actually ended at ',indx
-      call error_handler(E_ERR,'noah1d_to_dart_vector', string1, &
+      call error_handler(E_ERR,'noah_to_dart_vector', string1, &
                         source,revision,revdate,text2=string2)
    endif
 
@@ -1301,7 +1289,7 @@
    enddo
 endif
 
-end subroutine noah1d_to_dart_vector
+end subroutine noah_to_dart_vector
 
 
  
@@ -1326,7 +1314,7 @@
 ! convert statedate to namelist variable
 ! convert adv_to_time to namelist variable if needed
 
-write(iunit,nml=METADATA_NAMELIST)
+write(iunit,nml=NOAHLSM_OFFLINE)
 close(iunit)
 
 end subroutine dart_vector_to_model_file
@@ -1338,20 +1326,20 @@
 ! The restart netcdf files have the time of the state.
 ! We are always using the 'most recent' which is, by defn, the last one.
 !
-!        Time = UNLIMITED ; // (35039 currently)
-!        num_soil_layers = 4 ;
-!        DatStrLen = 12 ;
+!        Time = UNLIMITED ; // (blah_blah_blah currently)
+!        DateStrLen = 19 ;
 !variables:
-!        char Times(Time, DatStrLen) ;
-!                Times:description = "UTC time of data output" ;
-!                Times:units = "YYYYMMDD HH:mm" ;
+!        char Times(Time, DateStrLen) ;
+!
+! Times =
+!  "2004-01-01_01:00:00" ;
 
 type(time_type) :: get_state_time
 integer,          intent(in) :: ncid
 character(len=*), intent(in) :: filename
 
-character(len=12), allocatable, dimension(:) :: datestring
-integer               :: year, month, day, hour, minute
+character(len=19), allocatable, dimension(:) :: datestring
+integer               :: year, month, day, hour, minute, second
 integer               :: DimID, VarID, strlen, ntimes
 integer, dimension(2) :: ncstart, nccount
 
@@ -1364,13 +1352,13 @@
 call nc_check(nf90_inquire_dimension(ncid, DimID, len=ntimes), &
                   'get_state_time','inquire_dimension Time '//trim(filename))
 
-call nc_check(nf90_inq_dimid(ncid, 'DatStrLen', DimID), &
-                  'get_state_time','inq_dimid DatStrLen '//trim(filename))
+call nc_check(nf90_inq_dimid(ncid, 'DateStrLen', DimID), &
+                  'get_state_time','inq_dimid DateStrLen '//trim(filename))
 call nc_check(nf90_inquire_dimension(ncid, DimID, len=strlen), &
                   'get_state_time','inquire_dimension DatStrLen '//trim(filename))
 
-if (strlen /= 12) then
-   write(string1,*)"DatStrLen string length ",strlen," /= 12 "
+if (strlen /= len(datestring)) then
+   write(string1,*)"DatStrLen string length ",strlen," /= ",len(datestring)
    call error_handler(E_ERR,"get_state_time", string1, source, revision, revdate)
 endif
 
@@ -1391,9 +1379,9 @@
 
 if (debug > 0) write(*,*)'Last time is '//trim(datestring(ntimes))
 
-read(datestring(ntimes),'(i4,i2,i2,i2,i2)')year, month, day, hour, minute
+read(datestring(ntimes),'(i4,5(1x,i2))')year, month, day, hour, minute, second
 
-get_state_time = set_date(year, month, day, hours=hour, minutes=minute, seconds=0)
+get_state_time = set_date(year, month, day, hours=hour, minutes=minute, seconds=second)
 
 deallocate(datestring)
 
@@ -1401,6 +1389,99 @@
 
 
 
+subroutine get_hrldas_constants(filename)
+! Read the 'wrfinput' netCDF file for grid information, etc.
+! This is all time-invariant, so we can mostly ignore the Time coordinate.
+!
+! MODULE variables set by this routine:
+!    south_north
+!    west_east 
+!    xlong
+!    xlat
+
+character(len=*), intent(in) :: filename
+
+integer, dimension(NF90_MAX_VAR_DIMS) :: dimIDs, ncstart, nccount
+character(len=NF90_MAX_NAME)          :: dimname, varname
+
+integer :: i, iunit, DimID, VarID, numdims, dimlen, xtype
+
+if ( .not. module_initialized ) call static_init_model
+
+call nc_check(nf90_open(adjustl(filename), NF90_NOWRITE, iunit), &
+                   'get_hrldas_constants', 'open '//trim(filename))
+
+call nc_check(nf90_inq_dimid(iunit, 'south_north', DimID), &
+                  'get_hrldas_constants','inq_dimid south_north '//trim(filename))
+call nc_check(nf90_inquire_dimension(iunit, DimID, len=south_north), &
+                  'get_hrldas_constants','inquire_dimension south_north '//trim(filename))
+
+call nc_check(nf90_inq_dimid(iunit, 'west_east', DimID), &
+                  'get_hrldas_constants','inq_dimid west_east '//trim(filename))
+call nc_check(nf90_inquire_dimension(iunit, DimID, len=west_east), &
+                  'get_hrldas_constants','inquire_dimension west_east '//trim(filename))
+
+! Require that the xlong and xlat are the same shape.
+
+allocate(xlong(west_east,south_north), xlat(west_east,south_north))
+
+call nc_check(nf90_inq_varid(iunit, 'XLONG', VarID), &
+                  'get_hrldas_constants','inq_varid XLONG '//trim(filename))
+
+call nc_check(nf90_inquire_variable(iunit, VarID, dimids=dimIDs, &
+                  ndims=numdims, xtype=xtype), &
+                  'get_hrldas_constants', 'inquire_variable XLONG '//trim(filename))
+
+! Form the start/count such that we always get the 'latest' time.
+
+ncstart(:) = 0
+nccount(:) = 0
+
+do i = 1,numdims
+
+   write(string1,'(''inquire dimension'',i2,A)') i,trim(filename)
+   call nc_check(nf90_inquire_dimension(iunit, dimIDs(i), name=dimname, len=dimlen), &
+                                          'static_init_model', string1)
+   ncstart(i) = 1
+   nccount(i) = dimlen
+
+   if ((trim(dimname) == 'Time') .or. (trim(dimname) == 'time')) then
+      ncstart(i) = dimlen
+      nccount(i) = 1
+   endif
+
+enddo
+
+if (debug > 7) write(*,*)'TJH DEBUG get_hrldas_constants ncstart is',ncstart(1:numdims)
+if (debug > 7) write(*,*)'TJH DEBUG get_hrldas_constants nccount is',nccount(1:numdims)
+
+! finally get the longitudes
+
+call nc_check(nf90_get_var(iunit, VarID, xlong, &
+                  start=ncstart(1:numdims), count=nccount(1:numdims)), &
+                  'get_hrldas_constants', 'get_var XLONG '//trim(filename))
+
+where(xlong < 0.0_r8) xlong = xlong + 360.0_r8
+
+! finally get the latitudes
+
+call nc_check(nf90_inq_varid(iunit, 'XLAT', VarID), &
+                  'get_hrldas_constants','inq_varid XLAT '//trim(filename))
+
+call nc_check(nf90_get_var(iunit, VarID, xlat, &
+                  start=ncstart(1:numdims), count=nccount(1:numdims)), &
+                  'get_hrldas_constants', 'get_var XLAT '//trim(filename))
+
+write(*,*)'TJH DEBUG XLONG is',xlong
+write(*,*)'TJH DEBUG XLAT  is',xlat
+
+! FIXME
+write(string1,*) 'get_hrldas_constants not written yet.'
+call error_handler(E_MSG,'static_init_model',string1,source,revision,revdate)
+
+end subroutine get_hrldas_constants
+
+
 !===================================================================
 ! End of model_mod
 !===================================================================

Modified: DART/branches/development/models/noah/model_mod.nml
===================================================================
--- DART/branches/development/models/noah/model_mod.nml	2012-08-06 22:19:46 UTC (rev 5833)
+++ DART/branches/development/models/noah/model_mod.nml	2012-08-07 01:55:11 UTC (rev 5834)
@@ -1,6 +1,6 @@
 &model_nml
-     noah_netcdf_filename         = 'OUTPUT.nc',
-     noah_namelist_filename       = 'bondville.dat',
+     noah_netcdf_filename         = 'restart.nc',
+     noah_namelist_filename       = 'namelist.hrldas',
      assimilation_period_days     =    0,
      assimilation_period_seconds  = 3600,
      model_perturbation_amplitude = 0.0,

Modified: DART/branches/development/models/noah/noah1D_to_dart.f90
===================================================================
--- DART/branches/development/models/noah/noah1D_to_dart.f90	2012-08-06 22:19:46 UTC (rev 5833)
+++ DART/branches/development/models/noah/noah1D_to_dart.f90	2012-08-07 01:55:11 UTC (rev 5834)
@@ -2,7 +2,7 @@
 ! provided by UCAR, "as is", without charge, subject to all terms of use at
 ! http://www.image.ucar.edu/DAReS/DART/DART_download
 
-program noah1D_to_dart
+program noah_to_dart
 
 ! <next few lines under version control, do not edit>
 ! $URL$
@@ -11,16 +11,16 @@
 ! $Date$
 
 !----------------------------------------------------------------------
-! purpose: interface between noah1D and DART
+! purpose: interface between NOAH and DART
 !
-! method: Read noah1D "restart" files of model state
+! method: Read noah "restart" files of model state
 !         Reform fields into a DART state vector (control vector).
 !         Write out state vector in "proprietary" format for DART.
 !         The output is a "DART restart file" format.
 ! 
-! USAGE:  The noah1D filename is read from the noah1D_in namelist
-!         <edit noah1D_to_dart_output_file in input.nml:noah1D_to_dart>
-!         noah1D_to_dart
+! USAGE:  The noah filename is read from the noah_in namelist
+!         <edit noah_to_dart_output_file in input.nml:noah_to_dart>
+!         noah_to_dart
 !
 ! author: Tim Hoar 11 July 2012
 !----------------------------------------------------------------------
@@ -28,8 +28,8 @@
 use        types_mod, only : r8
 use    utilities_mod, only : initialize_utilities, timestamp, &
                              find_namelist_in_file, check_namelist_read
-use        model_mod, only : get_model_size, noah1d_to_dart_vector, &
-                             get_noah1D_restart_filename
+use        model_mod, only : get_model_size, noah_to_dart_vector, &
+                             get_noah_restart_filename
 use  assim_model_mod, only : awrite_state_restart, open_restart_write, close_restart
 use time_manager_mod, only : time_type, print_time, print_date
 
@@ -45,9 +45,9 @@
 ! namelist parameters with default values.
 !-----------------------------------------------------------------------
 
-character(len=128) :: noah1D_to_dart_output_file  = 'dart_ics'
+character(len=128) :: noah_to_dart_output_file  = 'dart_ics'
 
-namelist /noah1D_to_dart_nml/ noah1D_to_dart_output_file
+namelist /noah_to_dart_nml/ noah_to_dart_output_file
 
 !----------------------------------------------------------------------
 ! global storage
@@ -57,26 +57,26 @@
 integer               :: io, iunit, x_size
 type(time_type)       :: model_time
 real(r8), allocatable :: statevector(:)
-character(len=256)    :: noah1D_restart_filename
+character(len=256)    :: noah_restart_filename
 
 !======================================================================
 
-call initialize_utilities(progname='noah1D_to_dart', output_flag=verbose)
+call initialize_utilities(progname='noah_to_dart', output_flag=verbose)
 
 !----------------------------------------------------------------------
 ! Read the namelist to get the output filename.
 !----------------------------------------------------------------------
 
-call find_namelist_in_file("input.nml", "noah1D_to_dart_nml", iunit)
-read(iunit, nml = noah1D_to_dart_nml, iostat = io)
-call check_namelist_read(iunit, io, "noah1D_to_dart_nml") ! closes, too.
+call find_namelist_in_file("input.nml", "noah_to_dart_nml", iunit)
+read(iunit, nml = noah_to_dart_nml, iostat = io)
+call check_namelist_read(iunit, io, "noah_to_dart_nml") ! closes, too.
 
-call get_noah1D_restart_filename( noah1D_restart_filename )
+call get_noah_restart_filename( noah_restart_filename )
 
 write(*,*)
-write(*,'(''noah1D_to_dart:converting noah1D restart file '',A, &
+write(*,'(''noah_to_dart:converting noah restart file '',A, &
       &'' to DART file '',A)') &
-       trim(noah1D_restart_filename), trim(noah1D_to_dart_output_file)
+       trim(noah_restart_filename), trim(noah_to_dart_output_file)
 
 !----------------------------------------------------------------------
 ! get to work
@@ -85,9 +85,9 @@
 x_size = get_model_size()
 allocate(statevector(x_size))
 

@@ Diff output truncated at 40000 characters. @@


More information about the Dart-dev mailing list