Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

How to add new variable to history files

For those of you who want to write new variables to the CAM history files, you can edit the the module "cam_diagnostics.F90" in /working_directory_name/models/atm/cam/src/physics/cam.

I added potential temperature using the following procedure:

1) in the subroutine diag_init, add the line 'call addfld('TH ', 'K' , pver , 'I','potential temperature',phys_decomp)' ---the 'I" denotes instantaneous values. If you want average values, insert 'A'

2) in the subroutine diag_phys_writeout:
add 'cpair' to 'use_physconst'
declare variable as 'real(r8) th(pcols,pver)'
calculate potential temperature
do k = 1, pver
th(:ncol,k) = state%t(:ncol,k)*(state%ps(:ncol)/state%pmid(:ncol,k))**(rair/cpair)
end do

insert the line 'call outfld ('TH ', th , pcols, lchnk)'

3) After creating and configuring your case using the ccsm/cesm scripts (I'm running cam4 with ccsm4 scripts), insert 'TH:I' (or 'TH:A' for average values) after 'fincl1' in the cam_buildnml.csh script in the local Buildconf folder. Or, specify your own history output variable(s) in a file called 'user_nl' and place it in the Sourcemods/src.cam folder before configuring.
Alternately, you can add your variable to one of the default history files by inserting 'call add_default ('TH ', , ' ') in subroutine the diag_init.

4) build and run as usual

Diag_phys_writeout included the necessary state variables to compute potential temperature, but you can compute your variable in another subroutine (or write your own). You may also need to insert additional 'counter' integers such as i, or call other constants from 'physconst'.
 
Top