input_nc_check_dims Subroutine

public subroutine input_nc_check_dims(ncid, icheck, vname)

Uses

    • netcdf
  • proc~~input_nc_check_dims~~UsesGraph proc~input_nc_check_dims input_nc_check_dims netcdf netcdf proc~input_nc_check_dims->netcdf

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: ncid
logical, intent(in) :: icheck
character(len=*), intent(in) :: vname

Calls

proc~~input_nc_check_dims~~CallsGraph proc~input_nc_check_dims input_nc_check_dims proc~log_error log_error proc~input_nc_check_dims->proc~log_error nf90_inq_dimid nf90_inq_dimid proc~input_nc_check_dims->nf90_inq_dimid nf90_inquire_dimension nf90_inquire_dimension proc~input_nc_check_dims->nf90_inquire_dimension proc~log_debug log_debug proc~input_nc_check_dims->proc~log_debug nf90_get_var nf90_get_var proc~input_nc_check_dims->nf90_get_var nf90_inq_varid nf90_inq_varid proc~input_nc_check_dims->nf90_inq_varid proc~input_nc_check_error input_nc_check_error proc~input_nc_check_dims->proc~input_nc_check_error proc~log_message log_message proc~log_error->proc~log_message proc~log_debug->proc~log_message proc~input_nc_check_error->proc~log_error nf90_strerror nf90_strerror proc~input_nc_check_error->nf90_strerror proc~log_write log_write proc~log_message->proc~log_write proc~log_format_message log_format_message proc~log_message->proc~log_format_message proc~to_string to_string proc~log_write->proc~to_string proc~date_time_str date_time_str proc~log_format_message->proc~date_time_str proc~colourise colourise proc~log_format_message->proc~colourise proc~string_index string_index proc~colourise->proc~string_index

Called by

proc~~input_nc_check_dims~~CalledByGraph proc~input_nc_check_dims input_nc_check_dims proc~input_nc_initialise input_nc_initialise proc~input_nc_initialise->proc~input_nc_check_dims proc~initialise initialise proc~initialise->proc~input_nc_initialise program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  subroutine input_nc_check_dims(ncid, icheck, vname)
    use netcdf, only : &
      nf90_inq_dimid, nf90_inquire_dimension, nf90_inq_varid, nf90_get_var

    ! file and variable id to read from
    integer, intent (in) :: ncid
    ! check if same as already set values
    logical, intent (in) :: icheck
    ! name of variable being checked
    character(len=*), intent(in) :: vname
    ! dimension ids to read length
    integer :: lon_dimid, lat_dimid, rec_dimid
    ! variable ids to read time, lon/lat values
    integer :: lon_varid, lat_varid, time_varid
    integer :: nlo, nla, nre

    ! Get var ids of lon/lat and time
    call input_nc_check_error( nf90_inq_dimid(ncid, trim(NC_LON_VNAME), lon_dimid) )
    call input_nc_check_error( nf90_inquire_dimension(ncid, lon_dimid, len = nlo) )
    call input_nc_check_error( nf90_inq_dimid(ncid, trim(NC_LAT_VNAME), lat_dimid) )
    call input_nc_check_error( nf90_inquire_dimension(ncid, lat_dimid, len = nla) )
    call input_nc_check_error( nf90_inq_dimid(ncid, trim(NC_TIME_VNAME), rec_dimid) )
    call input_nc_check_error( nf90_inquire_dimension(ncid, rec_dimid, len = nre) )

    ! report dimensions
    if (NC_DEBUG) call log_debug("input_nc_check_dims", &
      'Number of nc_lons, nc_lats, timesteps:', ints=(/nlo, nla, nre/))

    ! check or assign
    if (icheck) then
      if (nlo /= nc_nlons) then
        call log_error("input_nc_check_dims", vname//' has different number of nc_lons', &
          ints=(/nlo, nc_nlons/))
      endif
      if (nla /= nc_nlats) then
        call log_error("input_nc_check_dims", vname//' has different number of nc_lats', &
          ints=(/nla, nc_nlats/))
      endif
      if (nre /= nc_nrecs) then
        call log_error("input_nc_check_dims", vname//' has different number of time steps', &
          ints=(/nre, nc_nrecs/))
      endif
    else
      ! assign
      nc_nlons = nlo
      nc_nlats = nla
      nc_nrecs = nre
      ! allocate nc_lons, nc_lats, time
      allocate(nc_lons(nc_nlons))
      allocate(nc_lats(nc_nlats))
      allocate(nc_time_ix(nc_nrecs))
      ! read time, nc_lons and nc_lats
      call input_nc_check_error( nf90_inq_varid(ncid, trim(NC_LON_VNAME), lon_varid) )
      call input_nc_check_error( nf90_get_var(ncid, lon_varid, nc_lons) )
      call input_nc_check_error( nf90_inq_varid(ncid, trim(NC_LAT_VNAME), lat_varid) )
      call input_nc_check_error( nf90_get_var(ncid, lat_varid, nc_lats) )
      call input_nc_check_error( nf90_inq_varid(ncid, trim(NC_TIME_VNAME), time_varid) )
      call input_nc_check_error( nf90_get_var(ncid, time_varid, nc_time_ix) )
    endif

  end subroutine input_nc_check_dims