Skip to content

Commit

Permalink
io_{netcdf,pio2}/ice_history_write: use namelist flags for coordinate…
Browse files Browse the repository at this point in the history
… variables

In order to enable the namelist flags for each coordinate variables
added in the previous commit, adjust the code of the io_netcdf and
io_pio2 backends by checking the value of 'icoord(i)' for each loop on
'ncoord' that calls NetCDF or PIO functions.

Add the new flags to the reference namelist.
  • Loading branch information
phil-blain committed Feb 22, 2024
1 parent fb329f6 commit 0ddd23c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 91 deletions.
104 changes: 54 additions & 50 deletions cicecore/cicedyn/infrastructure/io/io_netcdf/ice_history_write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,20 @@ subroutine ice_write_hist (ns)
dimid(3) = timid

do i = 1, ncoord
call ice_hist_coord_def(ncid, var_coord(i), lprecision, dimid(1:2), varid)
call ice_write_hist_fill(ncid,varid,var_coord(i)%short_name,history_precision)
if (var_coord(i)%short_name == 'ULAT') then
status = nf90_put_att(ncid,varid,'comment', &
'Latitude of NE corner of T grid cell')
call ice_check_nc(status, subname// ' ERROR: defining comment for '//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
endif
if (f_bounds) then
status = nf90_put_att(ncid, varid, 'bounds', coord_bounds(i))
call ice_check_nc(status, subname// ' ERROR: defining bounds for '//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
if(icoord(i)) then
call ice_hist_coord_def(ncid, var_coord(i), lprecision, dimid(1:2), varid)
call ice_write_hist_fill(ncid,varid,var_coord(i)%short_name,history_precision)
if (var_coord(i)%short_name == 'ULAT') then
status = nf90_put_att(ncid,varid,'comment', &
'Latitude of NE corner of T grid cell')
call ice_check_nc(status, subname// ' ERROR: defining comment for '//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
endif
if (f_bounds) then
status = nf90_put_att(ncid, varid, 'bounds', coord_bounds(i))
call ice_check_nc(status, subname// ' ERROR: defining bounds for '//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
endif
endif
enddo

Expand Down Expand Up @@ -707,44 +709,46 @@ subroutine ice_write_hist (ns)
!-----------------------------------------------------------------

do i = 1,ncoord
call broadcast_scalar(var_coord(i)%short_name,master_task)
SELECT CASE (var_coord(i)%short_name)
CASE ('TLON')
! Convert T grid longitude from -180 -> 180 to 0 to 360
work1 = TLON*rad_to_deg + c360
where (work1 > c360) work1 = work1 - c360
where (work1 < c0 ) work1 = work1 + c360
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('TLAT')
work1 = TLAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ULON')
work1 = ULON*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ULAT')
work1 = ULAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('NLON')
work1 = NLON*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('NLAT')
work1 = NLAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ELON')
work1 = ELON*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ELAT')
work1 = ELAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
END SELECT

if (my_task == master_task) then
status = nf90_inq_varid(ncid, var_coord(i)%short_name, varid)
call ice_check_nc(status, subname// ' ERROR: getting varid for '//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
status = nf90_put_var(ncid,varid,work_g1)
call ice_check_nc(status, subname// ' ERROR: writing'//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
if(icoord(i)) then
call broadcast_scalar(var_coord(i)%short_name,master_task)
SELECT CASE (var_coord(i)%short_name)
CASE ('TLON')
! Convert T grid longitude from -180 -> 180 to 0 to 360
work1 = TLON*rad_to_deg + c360
where (work1 > c360) work1 = work1 - c360
where (work1 < c0 ) work1 = work1 + c360
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('TLAT')
work1 = TLAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ULON')
work1 = ULON*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ULAT')
work1 = ULAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('NLON')
work1 = NLON*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('NLAT')
work1 = NLAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ELON')
work1 = ELON*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
CASE ('ELAT')
work1 = ELAT*rad_to_deg
call gather_global(work_g1,work1,master_task,distrb_info)
END SELECT

if (my_task == master_task) then
status = nf90_inq_varid(ncid, var_coord(i)%short_name, varid)
call ice_check_nc(status, subname// ' ERROR: getting varid for '//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
status = nf90_put_var(ncid,varid,work_g1)
call ice_check_nc(status, subname// ' ERROR: writing'//var_coord(i)%short_name, &
file=__FILE__, line=__LINE__)
endif
endif
enddo

Expand Down
86 changes: 45 additions & 41 deletions cicecore/cicedyn/infrastructure/io/io_pio2/ice_history_write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,18 @@ subroutine ice_write_hist (ns)
dimid2(2) = jmtid

do i = 1, ncoord
call ice_hist_coord_def(File, var_coord(i), lprecision, dimid2, varid)
call ice_write_hist_fill(File,varid,var_coord(i)%short_name,history_precision)
if (var_coord(i)%short_name == 'ULAT') then
call ice_pio_check(pio_put_att(File,varid,'comment', &
trim('Latitude of NE corner of T grid cell')), &
subname//' ERROR: defining att comment',file=__FILE__,line=__LINE__)
endif
if (f_bounds) then
call ice_pio_check(pio_put_att(File, varid, 'bounds', trim(coord_bounds(i))), &
subname//' ERROR: defining att bounds '//trim(coord_bounds(i)),file=__FILE__,line=__LINE__)
if (icoord(i)) then
call ice_hist_coord_def(File, var_coord(i), lprecision, dimid2, varid)
call ice_write_hist_fill(File,varid,var_coord(i)%short_name,history_precision)
if (var_coord(i)%short_name == 'ULAT') then
call ice_pio_check(pio_put_att(File,varid,'comment', &
trim('Latitude of NE corner of T grid cell')), &
subname//' ERROR: defining att comment',file=__FILE__,line=__LINE__)
endif
if (f_bounds) then
call ice_pio_check(pio_put_att(File, varid, 'bounds', trim(coord_bounds(i))), &
subname//' ERROR: defining att bounds '//trim(coord_bounds(i)),file=__FILE__,line=__LINE__)
endif
endif
enddo

Expand Down Expand Up @@ -706,38 +708,40 @@ subroutine ice_write_hist (ns)
allocate(workr2(nx_block,ny_block,nblocks))

do i = 1,ncoord
call ice_pio_check(pio_inq_varid(File, var_coord(i)%short_name, varid), &
subname//' ERROR: getting '//var_coord(i)%short_name ,file=__FILE__,line=__LINE__)
SELECT CASE (var_coord(i)%short_name)
CASE ('TLON')
! Convert T grid longitude from -180 -> 180 to 0 to 360
workd2(:,:,:) = mod(tlon(:,:,1:nblocks)*rad_to_deg + c360, c360)
CASE ('TLAT')
workd2(:,:,:) = tlat(:,:,1:nblocks)*rad_to_deg
CASE ('ULON')
workd2(:,:,:) = ulon(:,:,1:nblocks)*rad_to_deg
CASE ('ULAT')
workd2(:,:,:) = ulat(:,:,1:nblocks)*rad_to_deg
CASE ('NLON')
workd2(:,:,:) = nlon(:,:,1:nblocks)*rad_to_deg
CASE ('NLAT')
workd2(:,:,:) = nlat(:,:,1:nblocks)*rad_to_deg
CASE ('ELON')
workd2(:,:,:) = elon(:,:,1:nblocks)*rad_to_deg
CASE ('ELAT')
workd2(:,:,:) = elat(:,:,1:nblocks)*rad_to_deg
END SELECT
if (history_precision == 8) then
call pio_write_darray(File, varid, iodesc2d, &
workd2, status, fillval=spval_dbl)
else
workr2 = workd2
call pio_write_darray(File, varid, iodesc2d, &
workr2, status, fillval=spval)
endif
if(icoord(i)) then
call ice_pio_check(pio_inq_varid(File, var_coord(i)%short_name, varid), &
subname//' ERROR: getting '//var_coord(i)%short_name ,file=__FILE__,line=__LINE__)
SELECT CASE (var_coord(i)%short_name)
CASE ('TLON')
! Convert T grid longitude from -180 -> 180 to 0 to 360
workd2(:,:,:) = mod(tlon(:,:,1:nblocks)*rad_to_deg + c360, c360)
CASE ('TLAT')
workd2(:,:,:) = tlat(:,:,1:nblocks)*rad_to_deg
CASE ('ULON')
workd2(:,:,:) = ulon(:,:,1:nblocks)*rad_to_deg
CASE ('ULAT')
workd2(:,:,:) = ulat(:,:,1:nblocks)*rad_to_deg
CASE ('NLON')
workd2(:,:,:) = nlon(:,:,1:nblocks)*rad_to_deg
CASE ('NLAT')
workd2(:,:,:) = nlat(:,:,1:nblocks)*rad_to_deg
CASE ('ELON')
workd2(:,:,:) = elon(:,:,1:nblocks)*rad_to_deg
CASE ('ELAT')
workd2(:,:,:) = elat(:,:,1:nblocks)*rad_to_deg
END SELECT
if (history_precision == 8) then
call pio_write_darray(File, varid, iodesc2d, &
workd2, status, fillval=spval_dbl)
else
workr2 = workd2
call pio_write_darray(File, varid, iodesc2d, &
workr2, status, fillval=spval)
endif

call ice_pio_check(status,subname//' ERROR: writing '//avail_hist_fields(n)%vname, &
file=__FILE__,line=__LINE__)
call ice_pio_check(status,subname//' ERROR: writing '//avail_hist_fields(n)%vname, &
file=__FILE__,line=__LINE__)
endif
enddo

! Extra dimensions (NCAT, NFSD, VGRD*)
Expand Down
8 changes: 8 additions & 0 deletions configuration/scripts/ice_in
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@
/

&icefields_nml
f_tlon = .true.
f_tlat = .true.
f_ulon = .true.
f_ulat = .true.
f_nlon = .true.
f_nlat = .true.
f_elon = .true.
f_elat = .true.
f_tmask = .true.
f_umask = .false.
f_nmask = .false.
Expand Down

0 comments on commit 0ddd23c

Please sign in to comment.