?? histfilemod.f90
字號:
#include <misc.h>#include <preproc.h>module histFileMod use precision use clmtype use clm_varpar !parameters use clm_varmap !mapping variables use shr_const_mod, only: SHR_CONST_CDAY use fileutils, only : get_filename implicit none!----------------------------------------------------------------------------! Creating a netCDF dataset is a two phase process in which (1) dimensions! and variables are first defined (define mode), but can not read or write! data, and (2) variables are written (data mode), but can not create new! dimensions or variables. The general netCDF calling sequence to do this is:!! - nf_create !create dataset: enter define mode -! | nf_def_dim !define dimensions |! define mode| nf_def_var !define variables and set id's | histcrt! | nf_put_att !assign attributes to variables |! - nf_enddef !end definitions: leave define mode -! data mode | nf_put_var !provide values for variables | histwrt! | nf_close !close: save dataset | histcls!! There is one call to nf_def_dim for each dimension! There is one call to nf_def_var for each variable! There is one call to nf_put_att for each attribute for each variable! There is one call to nf_put_var for each variable!! Subroutine histcrt creates a netCDF dataset and creates dimensions/variables! Subroutine histwrt writes data values to a netCDF dataset! Subroutine histcls closes a netCDF dataset!! Every file that references a netCDF function must have the ! include statement: include 'netcdf.inc'!! netCDF datasets -! o referenced by a dataset id that is obtained when the! dataset is first created or opened! o nf_create (fname, nf_clobber, ncid): creates a new netCDF data file! with name [fname], overwritting if already exists, and returning! a dataset id [ncid] that is used to refer to dataset in other! netCDF function calls! o nf_open (fname, nf_nowrite, ncid): opens existing netCDF file! [fname] in read mode only, returning id [ncid]! o nf_enddef (ncid): takes open netCDF dataset, referenced by [ncid],! out of define mode! o nf_close (ncid): closes an open netCDF dataset, referenced by [ncid]!! netCDF dimensions -! o has both a name and a length! o one dimension in the dataset can have length unlimited (e.g., time! dimension can be unlimited to have multiple time slices in dataset)!! netCDF variables -! o A netCDF variable has a name, type [nf_char, nf_int, nf_float, ! nf_double], shape (dimension), and attributes (e.g., long name, units).! These are specified when the variable is defined. A variable also! has values, which are specified in data mode. ! o A netCDF variable is referenced by an integer variable (1,2,3,...),! which is in the order in which the variables are defined! o Character string is treated as an array of characters! o A coordinate variable is a special netCDF variable that has the! same name as a dimensions (e.g., lat(lat), lon(lon)). It is used! by some appication packages to define the physical coordinate! corresponding to that dimension! o Variables are dimensioned in Fortran opposite of how listed! in netCDF file, e.g.:! Fortran netCDF! -------------- --------------! x(lon,lat) -> x(lat,lon)! x(lon,lat,lev) -> x(lev,lat,lon)! x(lon,lat,tim) -> x(tim,lat,lon)!! netCDF functions used:! o nf_create (fname, nf_clobber, ncid)! o nf_def_dim (ncid, dimnam, dimlen, dimid)! o nf_def_var (ncid, varnam, vartyp, ndim, vdim, varid)! o nf_put_att_text (ncid, varid, attnam, len, text)! o nf_put_att_real (ncid, varid, attnam, vartyp, len, attval)! o nf_enddef (ncid)!! character fname - netCDF dataset name! 'nf_clobber' - overwrite existing file! integer ncid - returned netCDF dataset id! character dimnam - dimension name ! character dimid - associated dimension id ! character dimlen - dimension length ! character varnam - variable name ! integer varid - associated netCDF variable id! varytp - 'nf_int', 'nf_float', 'nf_double'! integer ndim - number of dimensions: 0 - scalar. 1 - vector! integer vdim - vector of ndim dimension id's corresponding to ! the variables dimensions! character attnam - character attribute name (e.g., 'units')! character text - attribute text! integer len - length of attribute text or attribute array! real attval - array of len attribute values!----------------------------------------------------------------------------! $Id: histFileMod.F90,v 1.19.6.6.6.1 2002/05/13 19:25:04 erik Exp $!-----------------------------------------------------------------------! History file parameters real(r8), public, parameter :: spval = 1.e36 !special value for fill value! History file structures type histentry logical :: active(maxflds) !true => field is active character(len= 8) :: name(maxflds) !field name character(len= 8) :: unit(maxflds) !field units character(len= 8) :: levl(maxflds) !field levels: single level, multi soil character(len= 8) :: type(maxflds) !field time accumulation type: inst, maxi, mini, aver character(len=40) :: desc(maxflds) !field description end type histentry type singl_level integer :: num(maxhist) !number of active single-level fields character(len= 8) :: nam(max_slevflds,maxhist) !single-level field: name character(len= 8) :: uni(max_slevflds,maxhist) !single-level field: units character(len= 8) :: typ(max_slevflds,maxhist) !time accumation type: ninst, nmaxi, nmini, naver character(len=40) :: des(max_slevflds,maxhist) !description of single-level fields integer , pointer :: count(:,:,:) !number accumulations, single-level field real(r8), pointer :: value(:,:,:) !accumulated single-lev field end type singl_level type multi_level integer :: num(maxhist) !number of active multi-level fields character(len= 8) :: nam(max_mlevflds,maxhist) !multi-level field : name character(len= 8) :: uni(max_mlevflds,maxhist) !multi-level field : units character(len= 8) :: typ(max_mlevflds,maxhist) !time accumation type: ninst, nmaxi, nmini, naver character(len=40) :: des(max_mlevflds,maxhist) !description of multi-level fields integer , pointer :: count(:,:,:,:) !number accumulations, mutli-level field real(r8), pointer :: value(:,:,:,:) !accumulated multi-lev field end type multi_level! History file variables integer :: nhist !actual number of history files integer :: ncid(maxhist) !netCDF id from nf_open or nf_create logical :: ncgetid(maxhist) !true: need to get netCDF variable id's (masterproc only) logical :: ehi(maxhist) !true: current nstep is end of history interval integer :: ntim(maxhist) !current number of time samples for history file integer :: nbeghis(maxhist) !nbeghis=1:current nstep begins history interval character(len=80), public :: timcom(maxhist) !comment: start and end of history interval character(len= 8), public :: fldaux(maxalflds,maxhist) !fields for auxillary history files! History field level types type(singl_level) :: slfld !history file type(multi_level) :: mlsoifld !history file character(len= 8) :: nsing = 'sing-lev' !single-level field character(len= 8) :: nsoil = 'mlev_soi' !multi-level soil field! History field time accumulation types character(len= 8) :: naver = 'average' !average field over history interval character(len= 8) :: nmaxi = 'maximum' !max field value over history interval character(len= 8) :: nmini = 'minimum' !min field value over history interval character(len= 8) :: ninst = 'instant' !instantaneous field value character(len= 8) :: ncnst = 'constnt' !instantaneous field value! History file grid variable id's integer :: lonvar_id(maxhist) !id full grid longitude coordinate variable integer :: latvar_id(maxhist) !id full grid latitude coordinate variable integer :: levvar_id(maxhist) !id soil level coordinate variable integer :: timvar_id(maxhist) !id timecoordinate variable integer :: longxy_id(maxhist) !id 2d longitudes (longxy) integer :: latixy_id(maxhist) !id 2d latitudes (latixy) integer :: area_id(maxhist) !id 2d area (area) integer :: landfrac_id(maxhist) !id 2d land fraction integer :: numlon_id(maxhist) !id number of longitudes at each latitude integer :: landmask_id(maxhist) !id 2d land/ocean mask (landmask)#if (defined OFFLINE) integer :: edgen_id(maxhist) !id northern edge of grid (lsmedge(1)) integer :: edgee_id(maxhist) !id eastern edge of grid (lsmedge(2)) integer :: edges_id(maxhist) !id southern edge of grid (lsmedge(3)) integer :: edgew_id(maxhist) !id western edge of grid (lsmedge(4))#endif! History file time variant variable id's integer :: slfld_id(max_slevflds,maxhist) !id single-level fields (slfld%value) integer :: mlsoifld_id(max_mlevflds,maxhist) !id multi-level fields (mlsoifld%value) integer :: mcdate_id(maxhist) !id current date, yyyymmdd format (mcdate) integer :: mcsec_id(maxhist) !id current seconds in day (mcsec) integer :: mdcur_id(maxhist) !id current day (from base day) (mdcur) integer :: mscur_id(maxhist) !id current seconds of current day (mdcur) integer :: nstep_id(maxhist) !id current nstep integer :: timcom_id(maxhist) !id time comment (timcom) SAVE!=======================================================================CONTAINS!======================================================================= subroutine histini ()!----------------------------------------------------------------------- ! ! Purpose: ! initialize variables for history files!! Method: ! ! Author: Gordon Bonan! !----------------------------------------------------------------------- use clm_varctl use spmdMod, only : masterproc! ------------------------ local variables ------------------------ integer :: i !loop index! ----------------------------------------------------------------- if (masterproc) then write(6,*) 'Initializing variables for history files .....' write(6,'(72a1)') ("-",i=1,60) endif! -----------------------------------------------------------------! Initialize active history fields! ----------------------------------------------------------------- call histlst ! -----------------------------------------------------------------! Initialize variables for initial or branch runs! ----------------------------------------------------------------- if (nsrest==0 .or. nsrest==3) then! nbeghis = 1 indicates the current time step is start of a history! interval. This is part of the restart file if continuation run nbeghis(:) = 1! Set accumulation counters to zero: only if current time step! start of history interval. Otherwise read in from restart file slfld%count(:,:,:) = 0 mlsoifld%count(:,:,:,:) = 0! Initialize local file name for history files locfnh(:) = ' '! Set current number of time samples in history file and current ! history file counter ntim(:) = 0! No need to obtain time dependent netCDF variable id's from history! file because a new history file will be created ncgetid(:) = .false. end if if (masterproc) then write(6,'(72a1)') ("-",i=1,60) write(6,*) 'Successfully initialized history files' write(6,*) endif return end subroutine histini!======================================================================= subroutine histlst !----------------------------------------------------------------------- ! ! Purpose: ! initialize active field list for history files!! Method: ! This subroutine sets for both primary and auxillary history files:! o number of active single-level and multi-level fields! o names of active single-level and multi-level fields! o units of active single-level and multi-level fields! o type of active single-level and multi-level fields! o description of active single-level and multi-level fields!! The field types, which are set for each active field, are:! o average over history interval! o maximum in history interval! o minimum in history interval! o instantaneous when history file written!! Default inactive fields can be made active by setting the [hist_fldadd] ! variable to the appropriate field name via the namelist input!! Field type can be overridden by setting the [hist_chntyp] variable to the! appropriate field name and new field type via the namelist input!! Fields for auxillary files are read from namelist and must be! a subset of the primary history file fields! ! Author: Gordon Bonan! !----------------------------------------------------------------------- use clm_varctl use spmdMod, only : masterproc ! ------------------------ local variables ------------------------ integer :: i,j,k,n !indices integer :: nflds = 0 !number of declared fields (active+inactive) integer :: nacti = 0 !number of active fields integer :: ind(maxflds) !index to active fields type(histentry) histfld !primary field names type(histentry) tempfld !temporary field name! -----------------------------------------------------------------! set default fields for primary history files:! snow properties (will be vertically averaged over the snow profile) call histfldini(nflds, 'SNOWDP ', 'm ', nsing, naver, &
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -