[Dart-dev] [3724] DART/trunk: The 'namelist.input'
file contents are now included in the netcdf
nancy at ucar.edu
nancy at ucar.edu
Fri Jan 2 16:05:35 MST 2009
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20090102/fbe07ef1/attachment.html
-------------- next part --------------
Modified: DART/trunk/models/wrf/model_mod.f90
===================================================================
--- DART/trunk/models/wrf/model_mod.f90 2008-12-30 23:24:42 UTC (rev 3723)
+++ DART/trunk/models/wrf/model_mod.f90 2009-01-02 23:05:34 UTC (rev 3724)
@@ -39,7 +39,8 @@
use utilities_mod, only : file_exist, open_file, close_file, &
register_module, error_handler, E_ERR, E_WARN, &
E_MSG, nmlfileunit, do_output, nc_check, &
- find_namelist_in_file, check_namelist_read
+ find_namelist_in_file, check_namelist_read, &
+ find_textfile_dims, file_to_text
use obs_kind_mod, only : KIND_U_WIND_COMPONENT, KIND_V_WIND_COMPONENT, &
KIND_SURFACE_PRESSURE, KIND_TEMPERATURE, &
@@ -152,6 +153,8 @@
center_search_half_length, center_spline_grid_scale, &
polar, periodic_x, periodic_y, scm
+character(len = 20) :: wrf_nml_file = 'namelist.input'
+
!-----------------------------------------------------------------------
! Private definition of domain map projection use by WRF
@@ -3128,8 +3131,6 @@
function nc_write_model_atts( ncFileID ) result (ierr)
!-----------------------------------------------------------------
! Writes the model-specific attributes to a netCDF file
-! A. Caya May 7 2003
-! T. Hoar Mar 8 2004 writes prognostic flavor
integer, intent(in) :: ncFileID ! netCDF file identifier
integer :: ierr ! return value of function
@@ -3168,6 +3169,10 @@
character (len=1) :: idom
+character(len=129), allocatable, dimension(:) :: textblock
+integer :: nlines, linelen
+integer :: LineLenDimID, nlinesDimID, nmlVarID
+
!-----------------------------------------------------------------
ierr = 0 ! assume normal termination
@@ -3185,6 +3190,8 @@
! We need the dimension ID for the number of copies
!-----------------------------------------------------------------
+call nc_check(nf90_inq_dimid(ncid=ncFileID, name="NMLlinelen", dimid=LineLenDimID), &
+ 'nc_write_model_atts','inq_dimid NMLlinelen')
call nc_check(nf90_inq_dimid(ncid=ncFileID, name="copy", dimid=MemberDimID), &
'nc_write_model_atts','inq_dimid copy')
call nc_check(nf90_inq_dimid(ncid=ncFileID, name="time", dimid= TimeDimID), &
@@ -3221,8 +3228,20 @@
call nc_check(nf90_put_att(ncFileID, NF90_GLOBAL, "model_revdate",revdate), &
'nc_write_model_atts','put_att model_revdate')
+!-----------------------------------------------------------------
! how about namelist input? might be nice to save ...
+! long lines are truncated when read into textblock
+!-----------------------------------------------------------------
+call find_textfile_dims(wrf_nml_file, nlines, linelen)
+
+allocate(textblock(nlines))
+textblock = ''
+
+call nc_check(nf90_def_dim(ncid=ncFileID, name="nlines", &
+ len = nlines, dimid = nlinesDimID), &
+ 'nc_write_model_atts', 'def_dim nlines ')
+
!-----------------------------------------------------------------
! Define the dimensions IDs
!-----------------------------------------------------------------
@@ -3265,6 +3284,12 @@
! Commented block is from wrfinput
!-----------------------------------------------------------------
+call nc_check(nf90_def_var(ncFileID,name="WRFnml", xtype=nf90_char, &
+ dimids = (/ linelenDimID, nlinesDimID /), varid=nmlVarID), &
+ 'nc_write_model_atts', 'def_var WRFnml')
+call nc_check(nf90_put_att(ncFileID, nmlVarID, "long_name", &
+ "namelist.input contents"), 'nc_write_model_atts', 'put_att WRFnml')
+
call nc_check(nf90_def_var(ncFileID, name="DX", xtype=nf90_real, &
dimids= DomDimID, varid=DXVarID), &
'nc_write_model_atts','def_var DX')
@@ -4004,6 +4029,11 @@
!-----------------------------------------------------------------
call nc_check(nf90_enddef(ncfileID),'nc_write_model_atts','enddef')
+call file_to_text(wrf_nml_file, textblock)
+call nc_check(nf90_put_var(ncFileID, nmlVarID, textblock ), &
+ 'nc_write_model_atts', 'put_var nmlVarID')
+deallocate(textblock)
+
call nc_check(nf90_put_var(ncFileID, DXVarID, wrf%dom(1:num_domains)%dx), &
'nc_write_model_atts','put_var dx')
call nc_check(nf90_put_var(ncFileID, DYVarID, wrf%dom(1:num_domains)%dy), &
Modified: DART/trunk/utilities/utilities_mod.f90
===================================================================
--- DART/trunk/utilities/utilities_mod.f90 2008-12-30 23:24:42 UTC (rev 3723)
+++ DART/trunk/utilities/utilities_mod.f90 2009-01-02 23:05:34 UTC (rev 3724)
@@ -1197,28 +1197,35 @@
character(len=*), dimension(:), intent(OUT) :: textblock
integer :: i, ios, funit
-integer :: mynlines, mylinelen
+integer :: mynlines, mylinelen, strlen
-character(len=129) :: error_msg
+character(len=512) :: string
call find_textfile_dims(fname, mynlines, mylinelen)
+strlen = len(textblock)
+
if ( ( mynlines /= size(textblock) ) .or. &
- (mylinelen /= len(textblock)) ) then
- write(error_msg,'(A, '' file shape is '',i6,'' by '',i4, &
- &'' textblock is '',i6,'' by '',i4)') &
- trim(fname),mynlines,mylinelen,size(textblock),len(textblock)
- call error_handler(E_MSG,'file_to_text', error_msg)
+ (mylinelen /= strlen ) ) then
+ write(string,'(A, '' file shape is '',i6,'' by '',i4, &
+ &'' ?truncating? to '',i6,'' by '',i4)') &
+ trim(fname),mynlines,mylinelen,size(textblock),strlen
+ call error_handler(E_MSG,'file_to_text', trim(string))
endif
funit = open_file(fname, form="FORMATTED", action="READ")
+strlen = min(mylinelen, strlen)
+
PARSELOOP : do i = 1,mynlines
- read(funit, '(A)', iostat=ios) textblock(i)
+ read(funit, '(A)', iostat=ios) string
+
+ write(textblock(i),'(A)') string(1:strlen)
+
if ( ios /= 0 ) then
- write(error_msg,'(A,'' read around line '',i8)')trim(fname),i
- call error_handler(E_ERR,'file_to_text', error_msg)
+ write(string,'(A,'' read around line '',i8)')trim(fname),i
+ call error_handler(E_ERR,'file_to_text', trim(string))
endif
enddo PARSELOOP
More information about the Dart-dev
mailing list