Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading of mixed layer forcing file. #578

Merged
merged 12 commits into from
Mar 24, 2021
35 changes: 17 additions & 18 deletions cicecore/cicedynB/general/ice_forcing.F90
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ subroutine init_forcing_atmo

if (forcing_debug .and. my_task == master_task) write(nu_diag,*) subname,'fdbg start'

! Allocate forcing arrays
call alloc_forcing()

modadj = abs((min(0,myear-fyear_init)/ycycle+1)*ycycle)
fyear = fyear_init + mod(myear-fyear_init+modadj,ycycle)
fyear_final = fyear_init + ycycle - 1 ! last year in forcing cycle
Expand Down Expand Up @@ -351,10 +348,12 @@ subroutine init_forcing_ocn(dt)
if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
file=__FILE__, line=__LINE__)

! sst_data(:,:,:,:) = c0
! sss_data(:,:,:,:) = c0
! uocn_data(:,:,:,:) = c0
! vocn_data(:,:,:,:) = c0
call alloc_forcing()

sst_data(:,:,:,:) = c0
sss_data(:,:,:,:) = c0
uocn_data(:,:,:,:) = c0
vocn_data(:,:,:,:) = c0

nbits = 64 ! double precision data

Expand Down Expand Up @@ -488,8 +487,8 @@ subroutine init_forcing_ocn(dt)
endif ! ocn_data_type

if (trim(ocn_data_type) == 'ncar') then
! call ocn_data_ncar_init
call ocn_data_ncar_init_3D
call ocn_data_ncar_init
! call ocn_data_ncar_init_3D
endif

if (trim(ocn_data_type) == 'hycom') then
Expand Down Expand Up @@ -4099,13 +4098,14 @@ subroutine ocn_data_ncar_init
do m=1,12

! Note: netCDF does single to double conversion if necessary
if (n >= 4 .and. n <= 7) then
call ice_read_nc(fid, m, vname(n), work1, dbug, &
field_loc_NEcorner, field_type_vector)
else
! if (n >= 4 .and. n <= 7) then
! call ice_read_nc(fid, m, vname(n), work1, dbug, &
! field_loc_NEcorner, field_type_vector)
! else
call ice_read_nc(fid, m, vname(n), work1, dbug, &
field_loc_center, field_type_scalar)
endif
! endif

ocn_frc_m(:,:,:,n,m) = work1(:,:,:)

enddo ! month loop
Expand Down Expand Up @@ -4141,8 +4141,8 @@ subroutine ocn_data_ncar_init
endif

!echmod - currents cause Fram outflow to be too large
ocn_frc_m(:,:,:,4,:) = c0
ocn_frc_m(:,:,:,5,:) = c0
! ocn_frc_m(:,:,:,4,:) = c0
! ocn_frc_m(:,:,:,5,:) = c0
!echmod

end subroutine ocn_data_ncar_init
Expand Down Expand Up @@ -4376,8 +4376,8 @@ subroutine ocn_data_ncar(dt)
! Find interpolation coefficients
call interp_coeff_monthly (recslot)

sst_data(:,:,:,:) = c0
do n = nfld, 1, -1
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
! use sst_data arrays as temporary work space until n=1
if (ixm /= -99) then ! first half of month
Expand All @@ -4388,7 +4388,6 @@ subroutine ocn_data_ncar(dt)
sst_data(:,:,2,iblk) = ocn_frc_m(:,:,iblk,n,ixp)
endif
enddo
!$OMP END PARALLEL DO

call interpolate_data (sst_data,work1)
! masking by hm is necessary due to NaNs in the data file
Expand Down
31 changes: 20 additions & 11 deletions cicecore/cicedynB/infrastructure/ice_read_write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ subroutine ice_read_nc_xy(fid, nrec, varname, work, diag, &
! dimlen ! dimension size

real (kind=dbl_kind) :: &
missingvalue, &
amin, amax, asum ! min, max values and sum of input array

! character (char_len) :: &
Expand All @@ -1141,6 +1142,8 @@ subroutine ice_read_nc_xy(fid, nrec, varname, work, diag, &
nx = nx_global
ny = ny_global

work = c0 ! to satisfy intent(out) attribute

if (present(restart_ext)) then
if (restart_ext) then
nx = nx_global + 2*nghost
Expand Down Expand Up @@ -1181,25 +1184,26 @@ subroutine ice_read_nc_xy(fid, nrec, varname, work, diag, &
count=(/nx,ny,1/) )
endif

status = nf90_get_att(fid, varid, "_FillValue", missingvalue)
endif ! my_task = master_task

!-------------------------------------------------------------------
! optional diagnostics
!-------------------------------------------------------------------

if (my_task==master_task .and. diag) then
! write(nu_diag,*) &
! 'ice_read_nc_xy, fid= ',fid, ', nrec = ',nrec, &
! ', varname = ',trim(varname)
write(nu_diag,*) &
'ice_read_nc_xy, fid= ',fid, ', nrec = ',nrec, &
', varname = ',trim(varname)
! status = nf90_inquire(fid, nDimensions=ndim, nVariables=nvar)
! write(nu_diag,*) 'ndim= ',ndim,', nvar= ',nvar
! do id=1,ndim
! status = nf90_inquire_dimension(fid,id,name=dimname,len=dimlen)
! write(nu_diag,*) 'Dim name = ',trim(dimname),', size = ',dimlen
! enddo
amin = minval(work_g1)
amax = maxval(work_g1, mask = work_g1 /= spval_dbl)
asum = sum (work_g1, mask = work_g1 /= spval_dbl)
amax = maxval(work_g1, mask = work_g1 /= missingvalue)
asum = sum (work_g1, mask = work_g1 /= missingvalue)
write(nu_diag,*) ' min, max, sum =', amin, amax, asum, trim(varname)
endif

Expand All @@ -1223,12 +1227,15 @@ subroutine ice_read_nc_xy(fid, nrec, varname, work, diag, &
endif

deallocate(work_g1)

! echmod: this should not be necessary if fill/missing are only on land
where (work > 1.0e+30_dbl_kind) work = c0

if (orca_halogrid .and. .not. present(restart_ext)) deallocate(work_g2)

#else
call abort_ice(subname//'ERROR: USE_NETCDF cpp not defined', &
file=__FILE__, line=__LINE__)
work = c0 ! to satisfy intent(out) attribute
#endif
end subroutine ice_read_nc_xy

Expand Down Expand Up @@ -1282,6 +1289,7 @@ subroutine ice_read_nc_xyz(fid, nrec, varname, work, diag, &
! dimlen ! size of dimension

real (kind=dbl_kind) :: &
missingvalue, & ! missing value
amin, amax, asum ! min, max values and sum of input array

! character (char_len) :: &
Expand Down Expand Up @@ -1347,16 +1355,17 @@ subroutine ice_read_nc_xyz(fid, nrec, varname, work, diag, &
count=(/nx,ny,ncat,1/) )
endif

status = nf90_get_att(fid, varid, "_FillValue", missingvalue)
endif ! my_task = master_task

!-------------------------------------------------------------------
! optional diagnostics
!-------------------------------------------------------------------

if (my_task==master_task .and. diag) then
! write(nu_diag,*) &
! 'ice_read_nc_xyz, fid= ',fid, ', nrec = ',nrec, &
! ', varname = ',trim(varname)
write(nu_diag,*) &
'ice_read_nc_xyz, fid= ',fid, ', nrec = ',nrec, &
', varname = ',trim(varname)
! status = nf90_inquire(fid, nDimensions=ndim, nVariables=nvar)
! write(nu_diag,*) 'ndim= ',ndim,', nvar= ',nvar
! do id=1,ndim
Expand All @@ -1365,8 +1374,8 @@ subroutine ice_read_nc_xyz(fid, nrec, varname, work, diag, &
! enddo
do n=1,ncat
amin = minval(work_g1(:,:,n))
amax = maxval(work_g1(:,:,n), mask = work_g1(:,:,n) /= spval_dbl)
asum = sum (work_g1(:,:,n), mask = work_g1(:,:,n) /= spval_dbl)
amax = maxval(work_g1(:,:,n), mask = work_g1(:,:,n) /= missingvalue)
asum = sum (work_g1(:,:,n), mask = work_g1(:,:,n) /= missingvalue)
write(nu_diag,*) ' min, max, sum =', amin, amax, asum, trim(varname)
enddo
endif
Expand Down
7 changes: 7 additions & 0 deletions configuration/scripts/options/set_nml.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

oceanmixed_ice = .true.
ocn_data_type = 'ncar'
ocn_data_format = 'nc'
ocn_data_dir = 'ICE_MACHINE_INPUTDATA/CICE_data/forcing/gx1/CESM/MONTHLY'
oceanmixed_file = 'ocean_forcing_clim_2D_gx1.nc'

1 change: 1 addition & 0 deletions configuration/scripts/tests/base_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ restart gx1 8x1 bgczclim,medium
smoke gx1 24x1 medium,run90day,yi2008
smoke gx3 8x1 medium,run90day,yi2008
restart gx1 24x1 short
restart gx1 24x1 short,ml
restart gx3 8x1 short
smoke gx3 4x2 fsd1,diag24,run5day,debug
smoke gx3 8x2 fsd12,diag24,run5day,short
Expand Down