Skip to content

Commit

Permalink
Fix for maybe-unitialized gfortran errors
Browse files Browse the repository at this point in the history
It looks like gfortran does not like optional arrays to have an undetermined
dimension, so I changed a bunch of "dimension(:)" attributes to
"dimension(size(other_variable))". There was also a private routine in cvmix_io
that should only be called if you've compiled with netcdf that was kicking off
a "routine defined but never called" warning when I built without netcdf... so
I moved the "#ifdef _NETCDF" to include the entire routine.
  • Loading branch information
mnlevy1981 committed Jul 14, 2014
1 parent 7552fd6 commit bccd414
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 58 deletions.
10 changes: 2 additions & 8 deletions src/cvmix_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1611,26 +1611,20 @@ function get_netcdf_varid(file_id, var_name, xtype, ndims)

end function get_netcdf_varid

#endif

! Routine to handle errors returned from netcdf
subroutine netcdf_check(status)

integer, intent(in) :: status

#ifdef _NETCDF
if (status.ne.nf90_noerr) then
print*, "netCDF error: ", trim(nf90_strerror(status))
stop 1
end if
#else
print*, "ERROR: can not call netcdf_check unless compiling -D_NETCDF"
print*, "The status you passed in = ", status
stop 1
#endif

end subroutine netcdf_check

#endif

! DEBUGGING ROUTINE
subroutine print_open_files()

Expand Down
54 changes: 10 additions & 44 deletions src/shared/cvmix_kpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1595,9 +1595,10 @@ function cvmix_kpp_compute_bulk_Richardson(zt_cntr, delta_buoy_cntr, &
! * Nsqr_iface: squared buoyancy frequency at interfaces (units: 1/s^2)
! * Vt_sqr_cntr: squared unresolved shear term (units m^2/s^2)
! See note in description about what values should be passed in
real(cvmix_r8), dimension(:), intent(in), optional :: ws_cntr, N_iface, &
Nsqr_iface, &
Vt_sqr_cntr
real(cvmix_r8), dimension(size(zt_cntr)), intent(in), optional :: &
ws_cntr, Vt_sqr_cntr
real(cvmix_r8), dimension(size(zt_cntr)+1), intent(in), optional :: &
N_iface, Nsqr_iface
type(cvmix_kpp_params_type), intent(in), optional, target :: &
CVmix_kpp_params_user

Expand Down Expand Up @@ -1757,8 +1758,8 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_sigma(sigma_coord, &
CVmix_kpp_params_user

! !OUTPUT PARAMETERS:
real(cvmix_r8), optional, dimension(:), intent(inout) :: w_m
real(cvmix_r8), optional, dimension(:), intent(inout) :: w_s
real(cvmix_r8), optional, dimension(size(sigma_coord)), intent(inout) :: &
w_m, w_s

!EOP
!BOC
Expand Down Expand Up @@ -1791,10 +1792,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_sigma(sigma_coord, &
end do

if (compute_wm) then
if (size(w_m).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_m must be same size!"
stop 1
end if
w_m(1) = compute_phi_inv(zeta(1), CVmix_kpp_params_in, lphi_m=.true.)*&
vonkar*surf_fric_vel
do kw=2,n_sigma
Expand All @@ -1808,10 +1805,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_sigma(sigma_coord, &
end if

if (compute_ws) then
if (size(w_s).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_s must be same size!"
stop 1
end if
w_s(1) = compute_phi_inv(zeta(1), CVmix_kpp_params_in, lphi_s=.true.)*&
vonkar*surf_fric_vel
do kw=2,n_sigma
Expand All @@ -1825,11 +1818,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_sigma(sigma_coord, &
end if
else ! surf_fric_vel = 0
if (compute_wm) then
if (size(w_m).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_m must be same size!"
stop 1
end if

if (surf_buoy_force.ge.cvmix_zero) then
! Stable regime with surf_fric_vel = 0 => w_m = 0
w_m = cvmix_zero
Expand All @@ -1849,11 +1837,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_sigma(sigma_coord, &
end if ! compute_wm

if (compute_ws) then
if (size(w_s).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_s must be same size!"
stop 1
end if

if (surf_buoy_force.ge.cvmix_zero) then
! Stable regime with surf_fric_vel = 0 => w_s = 0
w_s = cvmix_zero
Expand Down Expand Up @@ -1905,8 +1888,8 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_OBL(sigma_coord, &
CVmix_kpp_params_user

! !OUTPUT PARAMETERS:
real(cvmix_r8), optional, dimension(:), intent(inout) :: w_m
real(cvmix_r8), optional, dimension(:), intent(inout) :: w_s
real(cvmix_r8), optional, dimension(size(surf_buoy_force)), intent(inout) &
:: w_m, w_s

!EOP
!BOC
Expand Down Expand Up @@ -1939,10 +1922,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_OBL(sigma_coord, &
end do

if (compute_wm) then
if (size(w_m).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_m must be same size!"
stop 1
end if
w_m(1) = compute_phi_inv(zeta(1), CVmix_kpp_params_in, lphi_m=.true.)*&
vonkar*surf_fric_vel
do kw=2,n_sigma
Expand All @@ -1956,10 +1935,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_OBL(sigma_coord, &
end if

if (compute_ws) then
if (size(w_s).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_s must be same size!"
stop 1
end if
w_s(1) = compute_phi_inv(zeta(1), CVmix_kpp_params_in, lphi_s=.true.)*&
vonkar*surf_fric_vel
do kw=2,n_sigma
Expand All @@ -1975,11 +1950,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_OBL(sigma_coord, &

else ! surf_fric_vel = 0
if (compute_wm) then
if (size(w_m).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_m must be same size!"
stop 1
end if

! Unstable forcing, Eqs. (13) and (B1c) reduce to following
do kw=1,n_sigma
if(surf_buoy_force(kw) .ge. cvmix_zero) then
Expand All @@ -1998,11 +1968,6 @@ subroutine cvmix_kpp_compute_turbulent_scales_1d_OBL(sigma_coord, &
end if ! compute_wm

if (compute_ws) then
if (size(w_s).ne.n_sigma) then
print*, "ERROR: sigma_coord and w_s must be same size!"
stop 1
end if

! Unstable forcing, Eqs. (13) and (B1e) reduce to following
do kw=1,n_sigma
if (surf_buoy_force(kw) .ge. cvmix_zero) then
Expand Down Expand Up @@ -2056,7 +2021,8 @@ function cvmix_kpp_compute_unresolved_shear(zt_cntr, ws_cntr, N_iface, &
! N_iface: buoyancy frequency at cell interfaces (units: 1/s)
! Nsqr_iface: squared buoyancy frequency at cell interfaces (units: 1/s^2)
! note that you must provide exactly one of these two inputs!
real(cvmix_r8), dimension(:), intent(in), optional :: N_iface, Nsqr_iface
real(cvmix_r8), dimension(size(zt_cntr)+1), intent(in), optional :: &
N_iface, Nsqr_iface
type(cvmix_kpp_params_type), intent(in), optional, target :: &
CVmix_kpp_params_user

Expand Down
12 changes: 6 additions & 6 deletions src/shared/cvmix_utils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ subroutine cvmix_update_wrap(old_vals, nlev, Mdiff_out, new_Mdiff, &

! !INPUT PARAMETERS:
integer, intent(in) :: old_vals, nlev
real(cvmix_r8), dimension(:), optional, intent(in) :: new_Mdiff, &
new_Tdiff, &
new_Sdiff
real(cvmix_r8), dimension(nlev+1), optional, intent(in) :: new_Mdiff, &
new_Tdiff, &
new_Sdiff

! !OUTPUT PARAMETERS:
real(cvmix_r8), dimension(:), optional, intent(inout) :: Mdiff_out, &
Tdiff_out, &
Sdiff_out
real(cvmix_r8), dimension(nlev+1), optional, intent(inout) :: Mdiff_out, &
Tdiff_out, &
Sdiff_out

!EOP
!BOC
Expand Down

0 comments on commit bccd414

Please sign in to comment.