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