[Dart-dev] [4049] DART/trunk/models/POP: This uses some 'standard' filenames to ease the scripting.

nancy at ucar.edu nancy at ucar.edu
Thu Sep 10 14:34:33 MDT 2009


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20090910/8c49eeea/attachment-0001.html 
-------------- next part --------------
Modified: DART/trunk/models/POP/dart_pop_mod.f90
===================================================================
--- DART/trunk/models/POP/dart_pop_mod.f90	2009-09-10 19:41:54 UTC (rev 4048)
+++ DART/trunk/models/POP/dart_pop_mod.f90	2009-09-10 20:34:33 UTC (rev 4049)
@@ -30,7 +30,7 @@
 public :: get_pop_calendar, set_model_time_step, &
           get_horiz_grid_dims, get_vert_grid_dim, &
           read_horiz_grid, read_topography, read_vert_grid, &
-          write_pop_namelist
+          write_pop_namelist, get_pop_restart_filename
 
 ! version controlled file description for error handling, do not edit
 character(len=128), parameter :: &
@@ -41,7 +41,8 @@
 character(len=256) :: msgstring
 logical, save :: module_initialized = .false.
 
-character(len=256) :: ic_filename, restart_filename 
+character(len=256) :: ic_filename      = 'pop.r.nc'
+!character(len=256) :: restart_filename = 'dart_pop_mod_restart_filename_not_set'
 
 ! set this to true if you want to print out the current time
 ! after each N observations are processed, for benchmarking.
@@ -191,26 +192,26 @@
 call check_namelist_read(iunit, io, 'init_ts_nml')
 
 ! Is it a pointer file or not ...
-if ( luse_pointer_files ) then
+!if ( luse_pointer_files ) then
+!
+!   restart_filename = trim(pointer_filename)//'.restart'
+!
+!   if ( .not. file_exist(restart_filename) ) then
+!      msgstring = 'pop_in:pointer file '//trim(restart_filename)//' not found'
+!      call error_handler(E_ERR,'initialize_module', &
+!             msgstring, source, revision, revdate)
+!   endif
+!
+!   iunit = open_file(restart_filename,'formatted')
+!   read(iunit,'(A)')ic_filename
+!
+!   restart_filename = ' '  
+!   write(*,*)'DEBUG ... pointer filename dereferenced to ',trim(ic_filename )
+!
+!else
+!   ic_filename = trim(init_ts_file)//'.'//trim(init_ts_file_fmt)
+!endif
 
-   restart_filename = trim(pointer_filename)//'.restart'
-
-   if ( .not. file_exist(restart_filename) ) then
-      msgstring = 'pop_in:pointer file '//trim(restart_filename)//' not found'
-      call error_handler(E_ERR,'initialize_module', &
-             msgstring, source, revision, revdate)
-   endif
-
-   iunit = open_file(restart_filename,'formatted')
-   read(iunit,'(A)')ic_filename
-
-   restart_filename = ' '  
-   write(*,*)'DEBUG ... pointer filename dereferenced to ',trim(ic_filename )
-
-else
-   ic_filename = trim(init_ts_file)//'.'//trim(init_ts_file_fmt)
-endif
-
 ! Make sure we have a pop restart file (for grid dims)
 if ( .not. file_exist(ic_filename) ) then
    msgstring = 'pop_in:init_ts_file '//trim(ic_filename)//' not found'
@@ -667,5 +668,17 @@
 end subroutine read_vert_grid
 
 
+!------------------------------------------------------------------
 
+
+subroutine get_pop_restart_filename( filename )
+character(len=*), intent(OUT) :: filename
+
+if ( .not. module_initialized ) call initialize_module
+
+filename   = trim(ic_filename)
+
+end subroutine get_pop_restart_filename
+
+
 end module dart_pop_mod

Modified: DART/trunk/models/POP/dart_to_pop.f90
===================================================================
--- DART/trunk/models/POP/dart_to_pop.f90	2009-09-10 19:41:54 UTC (rev 4048)
+++ DART/trunk/models/POP/dart_to_pop.f90	2009-09-10 20:34:33 UTC (rev 4049)
@@ -32,7 +32,7 @@
                              operator(-), set_time
 use        model_mod, only : static_init_model, sv_to_restart_file, &
                              get_model_size, get_model_time_step, &
-                             set_model_end_time
+                             set_model_end_time, get_pop_restart_filename
 use     dart_pop_mod, only : write_pop_namelist
 
 implicit none
@@ -47,12 +47,10 @@
 ! The namelist variables
 !------------------------------------------------------------------
 
-character (len = 128) :: dart_to_pop_input_file   = 'filter_ics'
-character (len = 128) :: dart_to_pop_restart_file = 'my_pop_restart_file'
+character (len = 128) :: dart_to_pop_input_file   = 'dart.ic'
 logical               :: advance_time_present     = .TRUE.
 
-namelist /dart_to_pop_nml/ dart_to_pop_input_file, dart_to_pop_restart_file, &
-                           advance_time_present
+namelist /dart_to_pop_nml/ dart_to_pop_input_file, advance_time_present
 
 !----------------------------------------------------------------------
 
@@ -60,6 +58,7 @@
 integer               :: secs, days
 type(time_type)       :: model_time, adv_to_time
 real(r8), allocatable :: statevector(:)
+character (len = 128) :: pop_restart_filename = 'no_pop_restart_file'
 
 !----------------------------------------------------------------------
 
@@ -73,12 +72,14 @@
 x_size = get_model_size()
 allocate(statevector(x_size))
 
-! Read the namelist to get the input and output filenames. 
+! Read the namelist to get the input filename. 
 
 call find_namelist_in_file("input.nml", "dart_to_pop_nml", iunit)
 read(iunit, nml = dart_to_pop_nml, iostat = io)
 call check_namelist_read(iunit, io, "dart_to_pop_nml")
 
+call get_pop_restart_filename( pop_restart_filename )
+
 !----------------------------------------------------------------------
 ! Reads the valid time, the state, and the target time.
 !----------------------------------------------------------------------
@@ -98,7 +99,7 @@
 ! time_manager_nml: stop_option, stop_count increments
 !----------------------------------------------------------------------
 
-call sv_to_restart_file(statevector, dart_to_pop_restart_file, model_time)
+call sv_to_restart_file(statevector, pop_restart_filename, model_time)
 
 if ( advance_time_present ) then
    call write_pop_namelist(model_time, adv_to_time)

Modified: DART/trunk/models/POP/model_mod.f90
===================================================================
--- DART/trunk/models/POP/model_mod.f90	2009-09-10 19:41:54 UTC (rev 4048)
+++ DART/trunk/models/POP/model_mod.f90	2009-09-10 20:34:33 UTC (rev 4049)
@@ -32,9 +32,10 @@
                              KIND_V_CURRENT_COMPONENT, KIND_SEA_SURFACE_HEIGHT
 use mpi_utilities_mod, only: my_task_id
 use    random_seq_mod, only: random_seq_type, init_random_seq, random_gaussian
-use      dart_pop_mod, only: get_pop_calendar, set_model_time_step, &
+use      dart_pop_mod, only: set_model_time_step, &
                              get_horiz_grid_dims, get_vert_grid_dim, &
-                             read_horiz_grid, read_topography, read_vert_grid
+                             read_horiz_grid, read_topography, read_vert_grid, &
+                             get_pop_restart_filename
 
 use typesizes
 use netcdf 
@@ -65,7 +66,7 @@
 ! generally useful routines for various support purposes.
 ! the interfaces here can be changed as appropriate.
 public :: POP_meta_type, get_gridsize, set_model_end_time, &
-          restart_file_to_sv, sv_to_restart_file
+          restart_file_to_sv, sv_to_restart_file, get_pop_restart_filename
 
 ! version controlled file description for error handling, do not edit
 character(len=128), parameter :: &
@@ -2958,6 +2959,8 @@
 !------------------------------------------------------------------
 ! public utility routine.
 
+if ( .not. module_initialized ) call static_init_model
+
  num_x = Nx
  num_y = Ny
  num_z = Nz
@@ -2976,6 +2979,8 @@
 
 logical :: is_ugrid
 
+if ( .not. module_initialized ) call static_init_model
+
 is_ugrid = is_on_ugrid(obs_type)
 if ((      is_ugrid .and. hgt_index > KMU(lon_index, lat_index)) .or. &
     (.not. is_ugrid .and. hgt_index > KMT(lon_index, lat_index))) then
@@ -2992,6 +2997,8 @@
 integer, intent(in) :: obs_type
 logical             :: is_on_ugrid
 
+if ( .not. module_initialized ) call static_init_model
+
 is_on_ugrid = .FALSE.
 
 if ((obs_type == KIND_U_CURRENT_COMPONENT)  .or.  &
@@ -3012,6 +3019,8 @@
 
  integer :: dimids(2);
 
+ if ( .not. module_initialized ) call static_init_model
+
  nlon = size(ULAT,1)
  nlat = size(ULAT,2)
  nz   = size(ZG)

Modified: DART/trunk/models/POP/pop_to_dart.f90
===================================================================
--- DART/trunk/models/POP/pop_to_dart.f90	2009-09-10 19:41:54 UTC (rev 4048)
+++ DART/trunk/models/POP/pop_to_dart.f90	2009-09-10 20:34:33 UTC (rev 4049)
@@ -13,10 +13,10 @@
 !         Write out state vector in "proprietary" format for DART.
 !         The output is a "DART restart file" format.
 ! 
-! USAGE:  <edit pop_to_dart_restart_file in input.nml:pop_to_dart_nml>
+! USAGE:  The POP filename is read from the pop_in namelist
+!         <edit pop_to_dart_output_file in input.nml:pop_to_dart_nml>
 !         pop_to_dart
 !
-!
 ! author: Tim Hoar 6/24/09
 !
 !----------------------------------------------------------------------
@@ -32,7 +32,7 @@
                              initialize_utilities, finalize_utilities, &
                              find_namelist_in_file, check_namelist_read
 use        model_mod, only : restart_file_to_sv, static_init_model, &
-                             get_model_size
+                             get_model_size, get_pop_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
 
@@ -49,18 +49,18 @@
 ! namelist parameters with default values.
 !-----------------------------------------------------------------------
 
-character (len = 128) :: pop_to_dart_restart_file = 'no_pop_to_dart_restart_file' 
-character (len = 128) :: pop_to_dart_output_file  = 'dart.ics'
+character (len = 128) :: pop_to_dart_output_file  = 'dart.ud'
 
-namelist /pop_to_dart_nml/ pop_to_dart_restart_file, pop_to_dart_output_file 
+namelist /pop_to_dart_nml/ pop_to_dart_output_file
 
 !----------------------------------------------------------------------
 ! global storage
 !----------------------------------------------------------------------
 
-integer                :: io, iunit, x_size
-type(time_type)        :: model_time
-real(r8), allocatable  :: statevector(:)
+integer               :: io, iunit, x_size
+type(time_type)       :: model_time
+real(r8), allocatable :: statevector(:)
+character (len = 128) :: pop_restart_filename = 'no_pop_restart_filename' 
 
 !----------------------------------------------------------------------
 
@@ -76,9 +76,11 @@
 read(iunit, nml = pop_to_dart_nml, iostat = io)
 call check_namelist_read(iunit, io, "pop_to_dart_nml") ! closes, too.
 
+call get_pop_restart_filename( pop_restart_filename )
+
 x_size = get_model_size()
 allocate(statevector(x_size))
-call restart_file_to_sv(pop_to_dart_restart_file, statevector, model_time) 
+call restart_file_to_sv(pop_restart_filename, statevector, model_time) 
 
 iunit = open_restart_write(pop_to_dart_output_file)
 

Added: DART/trunk/models/POP/shell_scripts/advance_model.csh
===================================================================
--- DART/trunk/models/POP/shell_scripts/advance_model.csh	                        (rev 0)
+++ DART/trunk/models/POP/shell_scripts/advance_model.csh	2009-09-10 20:34:33 UTC (rev 4049)
@@ -0,0 +1,169 @@
+#!/bin/tcsh
+#
+# Data Assimilation Research Testbed -- DART
+# Copyright 2004-2009, Data Assimilation Research Section
+# University Corporation for Atmospheric Research
+# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
+#
+# <next few lines under version control, do not edit>
+# $URL$
+# $Id$
+# $Revision$
+# $Date$
+#
+# This script has 4 logical 'blocks':
+# 1) creates a clean, temporary directory in which to run a model instance 
+#    and copies the necessary files into the temporary directory
+# 2) converts the DART output to input expected by the ocean model
+# 3) runs the ocean model
+# 4) converts the ocean model output to input expected by DART
+#
+# The error code from the script reflects which block it failed.
+#
+# Arguments are the 
+# 1) process number of caller, 
+# 2) the number of state copies belonging to that process, and 
+# 3) the name of the filter_control_file for that process
+
+set process = $1
+set num_states = $2
+set control_file = $3
+
+#-------------------------------------------------------------------------
+# Block 1: populate a run-time directory with the bits needed to 
+# run the ocean model.
+#-------------------------------------------------------------------------
+
+# Get unique name for temporary working directory for this process's stuff
+set temp_dir = 'advance_temp'${process}
+echo "temp_dir is $temp_dir"
+
+# Create a clean temporary directory and go there
+\rm -rf  $temp_dir
+mkdir -p $temp_dir
+cd       $temp_dir
+
+# Get the 'changing' namelist files from CENTRALDIR
+# Only the namelists in CENTRALDIR have the updated information about
+# the state of the model partway through an assimilation experiment.
+foreach FILE ( ../pop_in.part1 \
+               ../pop_in.part2 \
+               ../input.nml )
+   cp -pv $FILE . || exit 1
+end
+
+# copy the files used by 
+foreach FILE ( ../horiz_grid.gx3v5.* \
+               ../topography.gx3v5.* \
+               ../vert_grid.gx3v5    \
+               ../*_contents )
+   ln -sf $FILE . || exit 1
+end
+
+echo 'listing now that the table has been set ...'
+ls -l
+
+# Loop through each state
+set state_copy = 1
+set ensemble_member_line = 1
+set input_file_line = 2
+set output_file_line = 3
+while($state_copy <= $num_states)
+   
+   set ensemble_member = `head -$ensemble_member_line ../$control_file | tail -1`
+   set input_file      = `head -$input_file_line      ../$control_file | tail -1`
+   set output_file     = `head -$output_file_line     ../$control_file | tail -1`
+
+   #----------------------------------------------------------------------
+   # Block 2: Convert the DART output file to form needed by ocean model.
+   # We are going to take a POP netCDF restart file and simply overwrite the
+   # appropriate variables. The DART output file also has the 'advance_to'
+   # time - which must be communicated to the model ...
+   #----------------------------------------------------------------------
+
+   # The EXPECTED input DART 'initial conditions' file name is 'dart.ic'
+   # The dart_to_pop_nml:advance_time_present = .TRUE. must be set
+
+   ln -sfv ../$input_file dart.ic || exit 2
+
+   # CENTRALDIR will always contain a pointer file containing the name
+   # of the most recent POP restart file for this ensemble member.
+   # Locally, the POP restart file name is always pop.r.nc
+
+   if ( -e ../rpointer.ocn.${ensemble_member}.restart ) then
+      # dereference the pointer file
+      set RESTARTFILE = `head -1 ../rpointer.ocn.${ensemble_member}.restart`
+      cp -pv ../${RESTARTFILE} pop.r.nc || exit 2
+   
+   else
+      echo "Pointer file for ensemble member $ensemble_member is missing."
+      echo "Looking for "`pwd`" ../rpointer.ocn.${ensemble_member}.restart"
+      echo "Exiting ... (pointer file not found in CENTRALDIR)"
+      exit 2
+   endif
+
+   # create a pop_in to satisfy dart_pop_mod:initialize_module()
+
+   cat pop_in.part1 pop_in.part2 >! pop_in
+
+   ../dart_to_pop || exit 2
+
+   # Convey the new POP 'advance_to' time to POP via the namelist
+   cat pop_in.DART pop_in.part2 >! pop_in
+
+   # POP needs a pointer file containing the restart filename
+   echo "pop.r.nc"       >! rpointer.ocn.restart
+   echo "RESTART_FMT=nc" >> rpointer.ocn.restart
+
+   #----------------------------------------------------------------------
+   # Block 3: Run the ocean model
+   # The CCSM version has a pointer file that contains the name of the
+   # last restart. The LANL version has no such mechanism, but the 
+   # filename can be predicted from the pop_in namelist information.
+   #----------------------------------------------------------------------
+
+   mpirun.lsf ../pop || exit 3
+   
+   #----------------------------------------------------------------------
+   # Block 4: Convert the ocean model output to form needed by DART
+   #----------------------------------------------------------------------
+
+   ls -lrt
+
+   # POP makes a new restart file and updates the pointer file
+   set RESTARTFILE = `head -1 rpointer.ocn.restart`
+   echo "POP member $ensemble_member made restart file $RESTARTFILE"
+   ln -svf ${RESTARTFILE} pop.r.nc || exit 2
+   
+   # pop_to_dart reads the restart file after the model advance and writes
+   # out an updated DART 'initial conditions' file. This initial conditions
+   # file contains a header with the valid time of the ensuing model state.
+   # The POP restart files contain the valid time of the model state.
+
+   ../pop_to_dart || exit 4
+
+   # The (new,updated) DART restart file name is called 'dart.ud'
+   # Move the updated files back to 'centraldir'
+   mv -v dart.ud ../$output_file || exit 4
+   mv -v rpointer.ocn.restart ../rpointer.ocn.${ensemble_member}.restart || exit 4
+   mv -v ${RESTARTFILE} ../${RESTARTFILE} || exit 4
+
+   # bookkeeping
+
+   @ state_copy++
+   @ ensemble_member_line = $ensemble_member_line + 3
+   @ input_file_line = $input_file_line + 3
+   @ output_file_line = $output_file_line + 3
+end
+
+# must communicate the time_manager_nml:stop_count 
+# cp -pv pop_in.DART ../pop_in
+
+# Change back to original directory and get rid of temporary directory
+cd ..
+# \rm -rf $temp_dir
+
+# Remove the filter_control file to signal completion
+# Is there a need for any sleeps to avoid trouble on completing moves here?
+\rm -rf $control_file
+


Property changes on: DART/trunk/models/POP/shell_scripts/advance_model.csh
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: DART/trunk/models/POP/shell_scripts/run_perfect_model_obs.batch
===================================================================
--- DART/trunk/models/POP/shell_scripts/run_perfect_model_obs.batch	2009-09-10 19:41:54 UTC (rev 4048)
+++ DART/trunk/models/POP/shell_scripts/run_perfect_model_obs.batch	2009-09-10 20:34:33 UTC (rev 4049)
@@ -127,44 +127,43 @@
 #-----------------------------------------------------------------------------
 
 set DARTDIR = /fs/image/home/${user}/SVN/DART/models/POP
-set  POPDIR = /fs/image/home/${user}/SVN/DART/models/POP/input
+set  POPDIR = /ptmp/${user}/POP/osse
+set POPFILE = `head -1 ${POPDIR}/rpointer.ocn.20.restart`
 
 #-----------------------------------------------------------------------------
 # Get the DART executables, scripts, and input files
 #-----------------------------------------------------------------------------
 
 # executables
-${COPY} ${DARTDIR}/work/perfect_model_obs          .
-${COPY} ${DARTDIR}/work/dart_to_pop                .
-${COPY} ${DARTDIR}/work/pop_to_dart                .
+ ${COPY} ${DARTDIR}/work/perfect_model_obs          .
+ ${COPY} ${DARTDIR}/work/dart_to_pop                .
+ ${COPY} ${DARTDIR}/work/pop_to_dart                .
 
 # shell scripts
-${COPY} ${DARTDIR}/shell_scripts/advance_model.csh .
+ ${COPY} ${DARTDIR}/shell_scripts/advance_model.csh .
 
 # data files
-${COPY} ${DARTDIR}/work/obs_seq.in                 .
-${COPY} ${DARTDIR}/work/dart.ics                   perfect_ics
-${COPY} ${DARTDIR}/work/input.nml                  .
+ ${COPY} ${DARTDIR}/work/obs_seq.in                 .
+ ${COPY} ${DARTDIR}/work/input.nml                  .
 
 #-----------------------------------------------------------------------------
-# Get the POP executable, control files, and  data files.
+# Get the POP executable, control files, and data files.
 # trying to use the CCSM naming conventions
 #-----------------------------------------------------------------------------
 
-${COPY} ${POPDIR}/pop                       .
-${COPY} ${POPDIR}/pop_in.part1              .
-${COPY} ${POPDIR}/pop_in.part2              .
-${COPY} ${POPDIR}/pop.r.nc                  .
-echo "pop.r.nc" >! pop_pointer.restart
+ ${COPY} ${POPDIR}/pop                       .
+ ${COPY} ${POPDIR}/pop_in.part1              .
+ ${COPY} ${POPDIR}/pop_in.part2              .
+ ${COPY} ${POPDIR}/${POPFILE}                pop.r.nc
 
-${COPY} ${POPDIR}/gx3v5_tavg_contents       .
-${COPY} ${POPDIR}/gx3v5_movie_contents      .
-${COPY} ${POPDIR}/gx3v5_history_contents    .
-${COPY} ${POPDIR}/gx3v5_transport_contents  .
+ ${COPY} ${POPDIR}/gx3v5_tavg_contents       .
+ ${COPY} ${POPDIR}/gx3v5_movie_contents      .
+ ${COPY} ${POPDIR}/gx3v5_history_contents    .
+ ${COPY} ${POPDIR}/gx3v5_transport_contents  .
 
-${COPY} ${POPDIR}/vert_grid.gx3v5              .
-${COPY} ${POPDIR}/horiz_grid.gx3v5.r8ieee.le   .
-${COPY} ${POPDIR}/topography.gx3v5.r8ieee.le   .
+ ${COPY} ${POPDIR}/vert_grid.gx3v5              .
+ ${COPY} ${POPDIR}/horiz_grid.gx3v5.r8ieee.le   .
+ ${COPY} ${POPDIR}/topography.gx3v5.r8ieee.le   .
 
 #${COPY} ${POPDIR}/chl_mm_SeaWiFs97-01_20031205.ieeer8   .
 #${COPY} ${POPDIR}/sfwf_20040517.ieeer8                  .
@@ -174,14 +173,22 @@
 
 #-----------------------------------------------------------------------------
 # Check that everything moved OK, and the table is set.
-# Gives us a chance to edit the local input.nml, data.cal, etc. if needed.
+# Convert the POP restart file to a DART ics file.
 #-----------------------------------------------------------------------------
 
+cat pop_in.part1 pop_in.part2 >! pop_in
+
+./pop_to_dart
+
+${MOVE} dart.ud perfect_ics
+
 #-----------------------------------------------------------------------------
 # Run perfect_model_obs ... harvest the observations to populate obs_seq.out
+# This is the 'CENTRALDIR' ... advance_model.csh will expect some things.
 #-----------------------------------------------------------------------------
 
-cat pop_in.part1 pop_in.part2 >! pop_in
+echo "pop.r.nc"       >! rpointer.ocn.1.restart
+echo "RESTART_FMT=nc" >> rpointer.ocn.1.restart
 
 ./perfect_model_obs
 


More information about the Dart-dev mailing list