input_nc_initialise Subroutine

public subroutine input_nc_initialise(iyr, mb)

Uses

    • netcdf
  • proc~~input_nc_initialise~~UsesGraph proc~input_nc_initialise input_nc_initialise netcdf netcdf proc~input_nc_initialise->netcdf

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: iyr
integer, intent(in) :: mb

Calls

proc~~input_nc_initialise~~CallsGraph proc~input_nc_initialise input_nc_initialise proc~log_info log_info proc~input_nc_initialise->proc~log_info proc~input_nc_check_attr input_nc_check_attr proc~input_nc_initialise->proc~input_nc_check_attr proc~input_nc_read_grid input_nc_read_grid proc~input_nc_initialise->proc~input_nc_read_grid proc~input_nc_check_missing input_nc_check_missing proc~input_nc_initialise->proc~input_nc_check_missing nf90_open nf90_open proc~input_nc_initialise->nf90_open proc~log_debug log_debug proc~input_nc_initialise->proc~log_debug proc~input_nc_convert_coordinates input_nc_convert_coordinates proc~input_nc_initialise->proc~input_nc_convert_coordinates proc~get_config_fid get_config_fid proc~input_nc_initialise->proc~get_config_fid proc~input_nc_check_dims input_nc_check_dims proc~input_nc_initialise->proc~input_nc_check_dims nf90_inq_varid nf90_inq_varid proc~input_nc_initialise->nf90_inq_varid proc~input_nc_check_error input_nc_check_error proc~input_nc_initialise->proc~input_nc_check_error proc~input_nc_offset_time input_nc_offset_time proc~input_nc_initialise->proc~input_nc_offset_time proc~input_nc_check_grid input_nc_check_grid proc~input_nc_initialise->proc~input_nc_check_grid proc~input_nc_find_time input_nc_find_time proc~input_nc_initialise->proc~input_nc_find_time proc~log_message log_message proc~log_info->proc~log_message proc~input_nc_check_attr->proc~log_debug nf90_get_att nf90_get_att proc~input_nc_check_attr->nf90_get_att proc~check_range check_range proc~input_nc_read_grid->proc~check_range proc~input_open_file input_open_file proc~input_nc_read_grid->proc~input_open_file proc~input_nc_check_missing->proc~log_debug proc~input_nc_check_missing->proc~input_nc_check_error proc~log_error log_error proc~input_nc_check_missing->proc~log_error nf90_get_var nf90_get_var proc~input_nc_check_missing->nf90_get_var proc~log_warn log_warn proc~input_nc_check_missing->proc~log_warn proc~log_debug->proc~log_message proc~input_nc_convert_coordinates->proc~log_debug proc~input_nc_convert_coordinates->proc~log_error proc~open_file open_file proc~get_config_fid->proc~open_file proc~input_nc_check_dims->proc~log_debug proc~input_nc_check_dims->nf90_inq_varid proc~input_nc_check_dims->proc~input_nc_check_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~input_nc_check_dims->nf90_get_var proc~input_nc_check_error->proc~log_error nf90_strerror nf90_strerror proc~input_nc_check_error->nf90_strerror proc~input_nc_offset_time->proc~log_error proc~input_nc_check_grid->proc~log_debug proc~input_nc_check_grid->proc~input_open_file proc~input_nc_check_grid->proc~log_warn proc~input_nc_find_time->proc~log_debug proc~input_nc_find_time->proc~log_error proc~log_error->proc~log_message proc~check_range->proc~log_error proc~check_range->proc~log_warn proc~out_of_range_error out_of_range_error proc~check_range->proc~out_of_range_error proc~open_file->proc~log_error proc~input_open_file->proc~open_file 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~log_warn->proc~log_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~out_of_range_error->proc~log_error proc~out_of_range_error->proc~to_string proc~string_index string_index proc~colourise->proc~string_index

Called by

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

Contents

Source Code


Source Code

  subroutine input_nc_initialise(iyr, mb)
    use netcdf, only : nf90_open, nf90_nowrite, nf90_inq_varid

    integer, intent(in) :: iyr
    integer, intent(in) :: mb
    integer :: i
    logical :: fexists
    character(len=path_max_length) :: fpaths(6)

    call log_info('input_nc_initialise', 'Opening netCDF files...')

    ! allocate arrays with subbasin count
    allocate(nc_wsum_sb(mb))
    nc_wsum_sb = 0
    allocate(nc_ncells_sb(mb))
    nc_ncells_sb = 0

    ! read namelist parameters
    read(get_config_fid(), nml=NC_CLIMATE_PARAMETERS)
    ! open nc files, get var ids and compare the dimensions of first file (0), check if others are the same (1)
    do i = 1, 6
      ! check if file exists in input_dir, otherwise interpret as absolute path
      INQUIRE(file = trim(input_dir) // trim(NC_FNAMES(i)), EXIST = fexists)
      if (fexists) then
        fpaths(i) = trim(input_dir) // trim(NC_FNAMES(i))
      else
        fpaths(i) = trim(NC_FNAMES(i))
      endif
      if (NC_DEBUG) call log_debug("input_nc_initialise", trim(fpaths(i))//' ('//trim(NC_VNAMES(i))//')')
      ! open file, get fileID, check dims and attributes
      call input_nc_check_error( nf90_open(trim(fpaths(i)), nf90_nowrite, nc_ids(i)) )
      call input_nc_check_error( nf90_inq_varid(nc_ids(i), trim(NC_VNAMES(i)), nc_var_ids(i)) )
      call input_nc_check_dims(nc_ids(i), i /= 1, trim(NC_VNAMES(i)))
      call input_nc_check_attr(i)
    enddo

    ! check ncgrid.dat, count rows (nc_nrows) and max cell per subbasins (nc_mxc)
    call input_nc_check_grid(mb)

    ! allocated arrays with nc_mxc
    allocate(nc_weight_sb(mb, nc_mxc))
    nc_weight_sb = 0
    allocate(nc_lon_sb(mb, nc_mxc))
    nc_lon_sb = 0
    allocate(nc_lat_sb(mb, nc_mxc))
    nc_lat_sb = 0
    allocate(nc_x_sb(mb, nc_mxc))
    nc_x_sb = 0
    allocate(nc_y_sb(mb, nc_mxc))
    nc_y_sb = 0

    ! read ncinfo.dat
    call input_nc_read_grid(mb)

    ! convert lon/lat to x/y indecies
    call input_nc_convert_coordinates(mb)
    ! find time offset
    if (NC_REF_YEAR >= 0) then
        call input_nc_find_time(iyr) ! resets nc_nday
    else if (NC_OFFSET_DAYS /= 0) then
        call input_nc_offset_time() ! adds to nc_nday
    endif

    ! allocate nc_var_in to read in
    allocate(nc_var_in(nc_nx, nc_ny))
    nc_var_in = 0

    ! check for missing values
    if (NC_DEBUG) call input_nc_check_missing(mb)

  end subroutine input_nc_initialise