Skip to content

Commit

Permalink
ice_grid: initialize 'l_readCenter' for all grid types (#758)
Browse files Browse the repository at this point in the history
In 3fedc78 (Allow for read of tlat, tlon, anglet with popgrid (#463),
2020-06-24), ice_grid::init_grid2 was changed so that ice_grid::Tlatlon,
which computes the TLAT and TLON arrays from ULAT and ULON, is only
called if the private module variable 'l_readCenter' is false.

The idea is that if the grid file contains a variable 'anglet', then it
is assumed that it also contains variables 'tlon' and 'tlat', and so
these fields are read directly instead of being computed.

This logic, however, was only implemented in ice_grid::popgrid_nc, which
sets 'l_readCenter' depending on the presence or absence of 'anglet' in
the grid file. This means that if 'popgrid_nc' is not called (for
example with "grid_format='bin'", in which case init_grid2 calls
'popgrid' and not 'popgrid_nc'), then 'l_readCenter' is used
uninitialized in init_grid2, and so it's possible that 'Tlatlon' is not
called, if 'l_readCenter' happens to be initialized to true.

This in turns leads to 'TLAT' and 'TLON' being uninitialized, and the
code failing when accessing these arrays if compiling with NaN
initialization.

Fix this by initializing 'l_readCenter' at the beginning of init_grid2,
such that it is initialized for all choices of 'grid_format' and
'grid_type'. Remove the initialization in 'popgrid_nc'.
  • Loading branch information
phil-blain authored Aug 24, 2022
1 parent 588a86f commit 007fbff
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cicecore/cicedynB/infrastructure/ice_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ subroutine init_grid2
! lat, lon, cell widths, angle, land mask
!-----------------------------------------------------------------

l_readCenter = .false.

call icepack_query_parameters(pi_out=pi, pi2_out=pi2, puny_out=puny)
call icepack_warnings_flush(nu_diag)
if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
Expand Down Expand Up @@ -955,7 +957,6 @@ subroutine popgrid_nc
call ice_open_nc(kmt_file,fid_kmt)

diag = .true. ! write diagnostic info
l_readCenter = .false.
!-----------------------------------------------------------------
! topography
!-----------------------------------------------------------------
Expand Down

0 comments on commit 007fbff

Please sign in to comment.