input_nc_convert_coordinates Subroutine

public subroutine input_nc_convert_coordinates(mb)

Arguments

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

Calls

proc~~input_nc_convert_coordinates~~CallsGraph proc~input_nc_convert_coordinates input_nc_convert_coordinates proc~log_debug log_debug proc~input_nc_convert_coordinates->proc~log_debug proc~log_error log_error proc~input_nc_convert_coordinates->proc~log_error proc~log_message log_message proc~log_debug->proc~log_message proc~log_error->proc~log_message 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_convert_coordinates~~CalledByGraph proc~input_nc_convert_coordinates input_nc_convert_coordinates proc~input_nc_initialise input_nc_initialise proc~input_nc_initialise->proc~input_nc_convert_coordinates proc~initialise initialise proc~initialise->proc~input_nc_initialise program~swim swim program~swim->proc~initialise

Contents


Source Code

  subroutine input_nc_convert_coordinates(mb)
    integer, intent(in) :: mb
    integer sb, c, i
    ! loop over subbasins, then cells, then lon/lat stopping at the matching one
    do sb = 1, mb
      do c = 1, nc_ncells_sb(sb)
        do i = 1, nc_nlons
          if (nc_lons(i) == nc_lon_sb(sb, c)) then
            nc_x_sb(sb, c) = i
            nc_xmin = min(nc_xmin, i)
            nc_xmax = max(nc_xmax, i)
            exit
          endif
          ! if it hasn't found one and got to the end, stop and warn
          if (i == nc_nlons) then
            call log_error("input_nc_convert_coordinates", 'Longitude (at subbasin, cell) not in ncdf lon!', &
              real=nc_lon_sb(sb, c), i1=sb, i2=c)
          endif
        end do
        do i = 1, nc_nlats
          if (nc_lats(i) == nc_lat_sb(sb, c)) then
            nc_y_sb(sb, c) = i
            nc_ymin = min(nc_ymin, i)
            nc_ymax = max(nc_ymax, i)
            exit
          endif
          ! if it hasn't found one ang got to the end, stop and warn
          if (i == nc_nlats) then
            call log_error("input_nc_convert_coordinates", 'Latitude (at subbasin, cell) not in ncdf lat!', &
              real=nc_lon_sb(sb, c), i1=sb, i2=c)
          endif
        end do
      enddo
    enddo
    ! adjust x/y indicies for minimal window
    nc_nx = nc_xmax - (nc_xmin - 1)
    nc_ny = nc_ymax - (nc_ymin - 1)
    do sb = 1, mb
      do c = 1, nc_ncells_sb(sb)
        nc_x_sb(sb, c) = nc_x_sb(sb, c) - (nc_xmin - 1)
        nc_y_sb(sb, c) = nc_y_sb(sb, c) - (nc_ymin - 1)
      enddo
    enddo
    if (NC_DEBUG) call log_debug("input_nc_convert_coordinates", &
      'Minimum window size (n nc_lons, n nc_lats):', i1=nc_nx, i2=nc_ny)
  end subroutine input_nc_convert_coordinates