Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions components/eam/src/chemistry/utils/tracer_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module tracer_data
pio_put_att, pio_put_var, &
pio_get_var, pio_get_att, pio_nowrite, pio_inq_dimlen, &
pio_inq_vardimid, pio_inq_dimlen, pio_closefile, &
pio_inquire_variable
pio_inquire_variable, pio_inq_varndims

implicit none

Expand Down Expand Up @@ -1669,6 +1669,7 @@ subroutine read_za_trc_linoz( fid, vid, loc_arr, strt, cnt, file, order ,vid_srf
type(var_desc_t), intent(in), optional :: vid_srf
integer :: cnt_srf(2)
integer :: strt_srf(2)
integer :: srf_ndims
!!
type(interp_type) :: lat_wgts
real(r8) :: to_lats(pcols), to_lons(pcols), wrk(pcols)
Expand Down Expand Up @@ -1716,7 +1717,14 @@ subroutine read_za_trc_linoz( fid, vid, loc_arr, strt, cnt, file, order ,vid_srf
if (present(vid_srf)) then
!!padding for clim terms
allocate(wrksrf(cnt(1)), stat=ierr )
ierr = pio_get_var( fid, vid_srf, strt_srf, cnt_srf, wrksrf )
!! Use only as many start/count elements as the variable has dims
!! to avoid PIO warnings when the surface variable is 1D.
ierr = pio_inq_varndims(fid, vid_srf, srf_ndims)
if (srf_ndims >= 2) then
ierr = pio_get_var( fid, vid_srf, strt_srf, cnt_srf, wrksrf )
else
ierr = pio_get_var( fid, vid_srf, strt_srf(1:1), cnt_srf(1:1), wrksrf )
end if
!!surface padding
wrk2d(:,file%nlev)=wrksrf
deallocate(wrksrf)
Expand Down Expand Up @@ -1774,6 +1782,7 @@ subroutine read_zasrf_trc_linoz( fid, vid, loc_arr, strt, cnt, file)
integer :: c, k, ierr, ncols
integer :: cnt_srf(2)
integer :: strt_srf(2)
integer :: srf_ndims
!!
nullify(wrk_in)
allocate( wrk(cnt(1)), stat=ierr )
Expand All @@ -1789,7 +1798,14 @@ subroutine read_zasrf_trc_linoz( fid, vid, loc_arr, strt, cnt, file)
!!
!for surface variable with the dimension of (time,lat) or (time,1)
!for (time) it is also set like (time,1)
ierr = pio_get_var( fid, vid, strt_srf, cnt_srf, wrk )
!! Use only as many start/count elements as the variable has dims
!! to avoid PIO warnings when the surface variable is 1D.
ierr = pio_inq_varndims(fid, vid, srf_ndims)
if (srf_ndims >= 2) then
ierr = pio_get_var( fid, vid, strt_srf, cnt_srf, wrk )
else
ierr = pio_get_var( fid, vid, strt_srf(1:1), cnt_srf(1:1), wrk )
end if
!!
if(associated(wrk_in)) then
wrk_in = reshape( wrk(:),(/file%nlat/))
Expand Down
32 changes: 24 additions & 8 deletions components/eam/src/control/cam_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module cam_history
! The size of these parameters should match the assignments in restart_vars_setnames and restart_dims_setnames below
!
integer, parameter :: restartvarcnt = 38
integer, parameter :: restartdimcnt = 10
integer, parameter :: restartdimcnt = 11
type(rvar_id) :: restartvars(restartvarcnt)
type(rdim_id) :: restartdims(restartdimcnt)
integer, parameter :: ptapes_dim_ind = 1
Expand All @@ -116,6 +116,7 @@ module cam_history
integer, parameter :: maxvarmdims_dim_ind = 8
integer, parameter :: registeredmdims_dim_ind = 9
integer, parameter :: max_hcoordname_len_dim_ind = 10
integer, parameter :: avgflag_len_dim_ind = 11

integer :: nfmaster = 0 ! number of fields in master field list
integer :: nflds(ptapes) ! number of fields per tape
Expand Down Expand Up @@ -1099,9 +1100,10 @@ subroutine restart_vars_setnames()
rvindex = rvindex + 1
restartvars(rvindex)%name = 'avgflag'
restartvars(rvindex)%type = pio_char
restartvars(rvindex)%ndims = 2
restartvars(rvindex)%dims(1) = maxnflds_dim_ind
restartvars(rvindex)%dims(2) = ptapes_dim_ind
restartvars(rvindex)%ndims = 3
restartvars(rvindex)%dims(1) = avgflag_len_dim_ind
restartvars(rvindex)%dims(2) = maxnflds_dim_ind
restartvars(rvindex)%dims(3) = ptapes_dim_ind

rvindex = rvindex + 1
restartvars(rvindex)%name = 'sampling_seq'
Expand Down Expand Up @@ -1263,6 +1265,9 @@ subroutine restart_dims_setnames()
restartdims(max_hcoordname_len_dim_ind)%name = 'max_hcoordname_len'
restartdims(max_hcoordname_len_dim_ind)%len = max_hcoordname_len

restartdims(avgflag_len_dim_ind)%name = 'avgflag_len'
restartdims(avgflag_len_dim_ind)%len = 1

end subroutine restart_dims_setnames


Expand Down Expand Up @@ -1517,11 +1522,11 @@ subroutine write_restart_history ( File, &
ierr = pio_put_var(File, numlev_desc,start,tape(t)%hlist(f)%field%numlev)

ierr = pio_put_var(File, hwrt_prec_desc,start,tape(t)%hlist(f)%hwrt_prec)
ierr = pio_put_var(File, avgflag_desc,startc,tape(t)%hlist(f)%avgflag)
ierr = pio_put_var(File, sseq_desc,startc,tape(t)%hlist(f)%field%sampling_seq)
ierr = pio_put_var(File, longname_desc,startc,tape(t)%hlist(f)%field%long_name)
ierr = pio_put_var(File, standardname_desc,startc,tape(t)%hlist(f)%field%standard_name)
ierr = pio_put_var(File, units_desc,startc,tape(t)%hlist(f)%field%units)
ierr = pio_put_var(File, avgflag_desc,start, tape(t)%hlist(f)%avgflag)

ierr = pio_put_var(File, fillval_desc,start, tape(t)%hlist(f)%field%fillvalue)
ierr = pio_put_var(File, meridional_complement_desc,start, tape(t)%hlist(f)%field%meridional_complement)
Expand Down Expand Up @@ -1583,7 +1588,7 @@ end subroutine write_restart_history

subroutine read_restart_history (File)
use pio, only: pio_inq_dimid
use pio, only: pio_inq_varid, pio_inq_dimname
use pio, only: pio_inq_varid, pio_inq_dimname, pio_inq_varndims
use cam_pio_utils, only: cam_pio_openfile, cam_pio_closefile
use cam_pio_utils, only: cam_pio_var_info
use ioFileMod, only: getfil
Expand Down Expand Up @@ -1836,11 +1841,22 @@ subroutine read_restart_history (File)
ierr = pio_get_var(File,fillval_desc, (/f,t/), tape(t)%hlist(f)%field%fillvalue)
ierr = pio_get_var(File,meridional_complement_desc, (/f,t/), tape(t)%hlist(f)%field%meridional_complement)
ierr = pio_get_var(File,zonal_complement_desc, (/f,t/), tape(t)%hlist(f)%field%zonal_complement)
ierr = pio_get_var(File,avgflag_desc, (/f,t/), tape(t)%hlist(f)%avgflag)
! avgflag: new restarts store it as 3D (avgflag_len=1, maxnflds, ptapes) to satisfy
! PIO's convention that the first Fortran dim is the string length. Old restarts
! stored it as 2D (maxnflds, ptapes) without a leading string-length dim, which
! caused spurious PIO buffer-size warnings. Support both layouts here.
ierr = pio_inq_varndims(File, avgflag_desc, ndims)
if (ndims == 3) then
ierr = pio_get_var(File,avgflag_desc, (/1,f,t/), tape(t)%hlist(f)%avgflag)
else
ierr = pio_get_var(File,avgflag_desc, (/f,t/), tape(t)%hlist(f)%avgflag)
end if
ierr = pio_get_var(File,longname_desc, (/1,f,t/), tape(t)%hlist(f)%field%long_name)
tape(t)%hlist(f)%field%standard_name = ''
ierr = pio_get_var(File,standardname_desc, (/1,f,t/), tape(t)%hlist(f)%field%standard_name)
call strip_null(tape(t)%hlist(f)%field%standard_name)
ierr = pio_get_var(File,units_desc, (/1,f,t/), tape(t)%hlist(f)%field%units)
call strip_null(tape(t)%hlist(f)%field%units)
tape(t)%hlist(f)%field%sampling_seq(1:max_chars) = ' '
ierr = pio_get_var(File,sseq_desc, (/1,f,t/), tape(t)%hlist(f)%field%sampling_seq)
call strip_null(tape(t)%hlist(f)%field%sampling_seq)
Expand Down Expand Up @@ -4151,7 +4167,7 @@ subroutine h_define (t, restart)
'h_define: cannot define long_name for '//trim(fname_tmp))

str = tape(t)%hlist(f)%field%standard_name
if (str /= ' ') then
if (len_trim(str) > 0) then
ierr=pio_put_att (tape(t)%File, varid, 'standard_name', trim(str))
call cam_pio_handle_error(ierr, &
'h_define: cannot define standard_name for '//trim(fname_tmp))
Expand Down
24 changes: 20 additions & 4 deletions components/eam/src/physics/cam/phys_prop.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module phys_prop
use cam_pio_utils, only: cam_pio_openfile
use pio, only: file_desc_t, var_desc_t, pio_get_var, pio_inq_varid, &
pio_inq_dimlen, pio_inq_dimid , pio_nowrite, pio_closefile, &
pio_seterrorhandling, PIO_BCAST_ERROR, PIO_INTERNAL_ERROR, PIO_NOERR
pio_seterrorhandling, PIO_BCAST_ERROR, PIO_INTERNAL_ERROR, PIO_NOERR, &
pio_inq_varndims

use cam_logfile, only: iulog
use cam_abortutils, only: endrun
Expand Down Expand Up @@ -587,7 +588,8 @@ subroutine insoluble_optics_init(phys_prop, nc_id)
integer :: sw_ext_id, sw_ssa_id, sw_asm_id, lw_ext_id
integer :: swbands, nbnd
integer :: ierr ! error flag
integer :: start(2), count(2)
integer :: ndims
integer, allocatable :: start(:), count(:)
!------------------------------------------------------------------------------------

allocate (phys_prop%sw_nonhygro_ext(nswbands))
Expand Down Expand Up @@ -615,14 +617,28 @@ subroutine insoluble_optics_init(phys_prop, nc_id)
ierr = pio_inq_varid(nc_id, 'asm_sw', sw_asm_id)
ierr = pio_inq_varid(nc_id, 'abs_lw', lw_ext_id)

! Query ndims from file so start/count match exactly, avoiding warnings
! from SCORPIO when array size differs from variable rank. The band
! dimension is always the last (or only) dimension; all leading dimensions
! are singleton and get start=1, count=1.
ierr = pio_inq_varndims(nc_id, sw_ext_id, ndims)
allocate(start(ndims), count(ndims))
start = 1
count=(/1,swbands/)
count = 1
count(ndims) = swbands

ierr = pio_get_var(nc_id, sw_ext_id, start, count, phys_prop%sw_nonhygro_ext)
ierr = pio_get_var(nc_id, sw_ssa_id, start, count, phys_prop%sw_nonhygro_ssa)
ierr = pio_get_var(nc_id, sw_asm_id, start, count, phys_prop%sw_nonhygro_asm)
count = (/1,nbnd/)
deallocate(start, count)

ierr = pio_inq_varndims(nc_id, lw_ext_id, ndims)
allocate(start(ndims), count(ndims))
start = 1
count = 1
count(ndims) = nbnd
ierr = pio_get_var(nc_id, lw_ext_id, start, count, phys_prop%lw_abs)
deallocate(start, count)

! read refractive index data if available
call refindex_aer_init(phys_prop, nc_id)
Expand Down
6 changes: 4 additions & 2 deletions components/eam/src/utils/cam_grid_support.F90
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,10 @@ subroutine write_horiz_coord_attr(this, File, dimid_out)
ierr=pio_put_att(File, this%vardesc, 'long_name', trim(this%long_name))
call cam_pio_handle_error(ierr, 'Error writing "long_name" attr in write_horiz_coord_attr')
! units
ierr=pio_put_att(File, this%vardesc, 'units', trim(this%units))
call cam_pio_handle_error(ierr, 'Error writing "units" attr in write_horiz_coord_attr')
if (len_trim(this%units) > 0) then
ierr=pio_put_att(File, this%vardesc, 'units', trim(this%units))
call cam_pio_handle_error(ierr, 'Error writing "units" attr in write_horiz_coord_attr')
end if
end if ! We define the variable

if (present(dimid_out)) then
Expand Down
Loading