input_nc_read_grid Subroutine

public subroutine input_nc_read_grid(mb)

Arguments

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

Calls

proc~~input_nc_read_grid~~CallsGraph proc~input_nc_read_grid input_nc_read_grid proc~input_open_file input_open_file proc~input_nc_read_grid->proc~input_open_file proc~check_range check_range proc~input_nc_read_grid->proc~check_range proc~open_file open_file proc~input_open_file->proc~open_file proc~log_warn log_warn proc~check_range->proc~log_warn proc~out_of_range_error out_of_range_error proc~check_range->proc~out_of_range_error proc~log_error log_error proc~check_range->proc~log_error proc~log_message log_message proc~log_warn->proc~log_message proc~out_of_range_error->proc~log_error proc~to_string to_string proc~out_of_range_error->proc~to_string proc~open_file->proc~log_error 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~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_read_grid~~CalledByGraph proc~input_nc_read_grid input_nc_read_grid proc~input_nc_initialise input_nc_initialise proc~input_nc_initialise->proc~input_nc_read_grid proc~initialise initialise proc~initialise->proc~input_nc_initialise program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  subroutine input_nc_read_grid(mb)
    integer, intent(in) :: mb
    integer :: fui, i, ii, sb
    real(dp) :: ilon, ilat, iweight

    ! open weights and coordinates file
    fui = input_open_file(NC_GRID)
    read(fui, *) ! header line
    do i = 1, nc_nrows
      ! read line
      read(fui, *) sb, ilon, ilat, iweight
      ! count cells
      nc_ncells_sb(sb) = nc_ncells_sb(sb) + 1
      ii = nc_ncells_sb(sb)
      ! check input and assign
      call check_range((/ilon/), 'longitude', (/-180., 180./), sb)
      nc_lon_sb(sb, ii) = ilon
      call check_range((/ilat/), 'latitude', (/-90., 90./), sb)
      nc_lat_sb(sb, ii) = ilat
      call check_range((/iweight/), 'weight', (/0., 1.e6/), sb)
      nc_weight_sb(sb, ii) = iweight
      ! weights sum
      nc_wsum_sb(sb) = nc_wsum_sb(sb) + nc_weight_sb(sb, ii)
    end do
    ! close info file again
    close(fui)

    ! adjust/make sure weights add up to 1
    do sb = 1, mb
      do ii = 1, nc_ncells_sb(sb)
        nc_weight_sb(sb, ii) = nc_weight_sb(sb, ii) / nc_wsum_sb(sb)
      enddo
    enddo

  end subroutine input_nc_read_grid