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

Modifying CLM to read in extra 2D fields for use in calculations

Status
Not open for further replies.

nick

Herold
Member
Hi, I want to read in global 2D variables of stomatal parameters to be used instead of some of the PFT-specific constants (e.g. g1). And I'm just trying to see what my workflow should be. I assume it might be easiest to insert my new data into the surfdat file or similar and add some lines to read in the extra variables from that file.

The functions I'm interested in modifying are in PhotosynthesisMod.F90 and it's not clear to me where (i.e. what file) to read in the new data from and how to get the new data to this module. At a really simple level it seems I could read in my data in surfrdMod.F90, into some global variable (I know these aren't great), and then from the Photosynthesis module grab my data and operate. But it looks as though CLM splits the global grid into pieces (perhaps for parallelisation?) and those grids have patches etc. which get referred to in-code with patch or grid cell array indices like e.g. o2(bounds%begp:bounds%endp). So it's not a simple case of grabbing a value for a specific lat/lon and operating on it. It seems I need to initialise my variables at some higher level, read my data into those variables, and have those variables fed down to the Photosynthesis modules.

If there's any advice general or specific I'd appreciate it, or if there are previous examples on here that'd be great too.
 

oleson

Keith Oleson
CSEG and Liaisons
Staff member
In order to find a good example for you to follow, can I ask whether these are actually 3D parameters (pft, lat, lon) or 2D parameters (lat,lon). If 2D, do you want to assign the parameter value to every pft in that grid cell?
 

nick

Herold
Member
At the moment they are 2D (lat,lon) but it would be good to know how different reading in 3D data would be. And yes it would be to assign the same value to each pft in the grid cell. Thanks very much.
 

oleson

Keith Oleson
CSEG and Liaisons
Staff member
I think you could follow the SOIL_COLOR example. It is read in as a gridcell value and used as a column-level quantity, but you could do something similar to distribute your gridcell values to pfts instead of columns.
You could start by adding a subroutine into PhotosynthesisMod that is similar to the subroutine SurfaceAlbedoInitTimeConst in SurfaceAlbedoMod (e.g., PhotosynthesisInitTimeConst).

The relevant lines of code in SurfaceAlbedoInitTimeConst are:

allocate(isoicol(bounds%begc:bounds%endc))

allocate(soic2d(bounds%begg:bounds%endg))
call ncd_io(ncid=ncid, varname='SOIL_COLOR', flag='read', data=soic2d, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: SOIL_COLOR NOT on surfdata file'//errMsg(sourcefile, __LINE__))
end if
do c = bounds%begc, bounds%endc
g = col%gridcell(c)
isoicol(c) = soic2d(g)
end do

This reads in SOIL_COLOR from the surface dataset and assigns the gridcell value to all the columns in that gridcell.
For pft-level, you'd do something like:

allocate(g1(bounds%begp:bounds%endp))

allocate(g12d(bounds%begg:bounds%endg))
call ncd_io(ncid=ncid, varname='G1', flag='read', data=g12d, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: G1 NOT on surfdata file'//errMsg(sourcefile, __LINE__))
end if
do p = bounds%begp, bounds%endp
g = patch%gridcell(p)
g1(p) = g12d(g)
end do

Call your new subroutine from clm_instMod in a manner similar to:

call SurfaceAlbedoInitTimeConst(bounds)

Perhaps near this call:

call photosyns_inst%Init(bounds)

e.g.,

call PhotosynthesisInitTimeConst(bounds)

All of this is untested of course.

g1(p) can then be used in your photosynthesis routine.
 

nick

Herold
Member
Hi Keith, thanks very much. With a couple extra lines this seems to have worked. To test that I'm using the values I think I am, I want to write data to netcdf. Will start a new post.
 

SelenaChou

SelenaChou
New Member
I think you could follow the SOIL_COLOR example. It is read in as a gridcell value and used as a column-level quantity, but you could do something similar to distribute your gridcell values to pfts instead of columns.
You could start by adding a subroutine into PhotosynthesisMod that is similar to the subroutine SurfaceAlbedoInitTimeConst in SurfaceAlbedoMod (e.g., PhotosynthesisInitTimeConst).

The relevant lines of code in SurfaceAlbedoInitTimeConst are:

allocate(isoicol(bounds%begc:bounds%endc))

allocate(soic2d(bounds%begg:bounds%endg))
call ncd_io(ncid=ncid, varname='SOIL_COLOR', flag='read', data=soic2d, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: SOIL_COLOR NOT on surfdata file'//errMsg(sourcefile, __LINE__))
end if
do c = bounds%begc, bounds%endc
g = col%gridcell(c)
isoicol(c) = soic2d(g)
end do

This reads in SOIL_COLOR from the surface dataset and assigns the gridcell value to all the columns in that gridcell.
For pft-level, you'd do something like:

allocate(g1(bounds%begp:bounds%endp))

allocate(g12d(bounds%begg:bounds%endg))
call ncd_io(ncid=ncid, varname='G1', flag='read', data=g12d, dim1name=grlnd, readvar=readvar)
if (.not. readvar) then
call endrun(msg=' ERROR: G1 NOT on surfdata file'//errMsg(sourcefile, __LINE__))
end if
do p = bounds%begp, bounds%endp
g = patch%gridcell(p)
g1(p) = g12d(g)
end do

Call your new subroutine from clm_instMod in a manner similar to:

call SurfaceAlbedoInitTimeConst(bounds)

Perhaps near this call:

call photosyns_inst%Init(bounds)

e.g.,

call PhotosynthesisInitTimeConst(bounds)

All of this is untested of course.

g1(p) can then be used in your photosynthesis routine.
Hi,for ptt-level, should I add a new subroutine or replace the original one as the new one? Thanks!
 
Status
Not open for further replies.
Top