header_column_index Function

public function header_column_index(column, file_id, required)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: column
integer, intent(in) :: file_id
logical, intent(in), optional :: required

Return Value integer


Calls

proc~~header_column_index~~CallsGraph proc~header_column_index header_column_index proc~input_error_column_not_found input_error_column_not_found proc~header_column_index->proc~input_error_column_not_found proc~move_lines move_lines proc~header_column_index->proc~move_lines proc~log_error log_error proc~input_error_column_not_found->proc~log_error proc~log_message 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~~header_column_index~~CalledByGraph proc~header_column_index header_column_index proc~read_logical_column read_logical_column proc~read_logical_column->proc~header_column_index proc~read_string_column read_string_column proc~read_string_column->proc~header_column_index proc~has_column has_column proc~has_column->proc~header_column_index proc~read_real_column read_real_column proc~read_real_column->proc~header_column_index proc~subbasin_initialise subbasin_initialise proc~subbasin_initialise->proc~header_column_index proc~subbasin_read_routing subbasin_read_routing proc~subbasin_initialise->proc~subbasin_read_routing proc~subbasin_allocate_obs_discharge subbasin_allocate_obs_discharge proc~subbasin_initialise->proc~subbasin_allocate_obs_discharge proc~subbasin_read_input subbasin_read_input proc~subbasin_initialise->proc~subbasin_read_input proc~read_integer_column read_integer_column proc~read_integer_column->proc~header_column_index proc~snow_read_input snow_read_input proc~snow_read_input->proc~read_real_column proc~reservoir_read_storage_file reservoir_read_storage_file proc~reservoir_read_storage_file->proc~read_real_column proc~evapotranspiration_read_input evapotranspiration_read_input proc~evapotranspiration_read_input->proc~read_real_column proc~management_read_ctrl management_read_ctrl proc~management_read_ctrl->proc~read_string_column proc~management_read_ctrl->proc~read_real_column proc~management_read_ctrl->proc~read_integer_column proc~soil_read_input soil_read_input proc~soil_read_input->proc~read_string_column proc~groundwater_read_input groundwater_read_input proc~groundwater_read_input->proc~read_real_column proc~reservoir_read_month_file reservoir_read_month_file proc~reservoir_read_month_file->proc~read_real_column proc~catchment_read_subcatch_params catchment_read_subcatch_params proc~catchment_read_subcatch_params->proc~read_real_column proc~catchment_read_subcatch_params->proc~read_integer_column proc~river_read_input river_read_input proc~river_read_input->proc~read_real_column proc~subbasin_read_climate subbasin_read_climate proc~subbasin_read_climate->proc~read_real_column proc~subbasin_read_routing->proc~read_integer_column proc~crop_read_management_input crop_read_management_input proc~crop_read_management_input->proc~read_real_column proc~crop_read_management_input->proc~read_integer_column proc~crop_read_input crop_read_input proc~crop_read_input->proc~read_string_column proc~crop_read_input->proc~read_real_column proc~crop_read_input->proc~read_integer_column proc~subbasin_allocate_obs_discharge->proc~has_column proc~subbasin_read_input->proc~read_string_column proc~subbasin_read_input->proc~read_real_column proc~subbasin_read_input->proc~read_integer_column proc~landuse_read_input landuse_read_input proc~landuse_read_input->proc~read_real_column proc~landuse_read_input->proc~read_integer_column proc~hydrotope_read_input hydrotope_read_input proc~hydrotope_read_input->proc~read_real_column proc~hydrotope_read_input->proc~read_integer_column proc~initialise initialise proc~initialise->proc~subbasin_initialise proc~initialise->proc~crop_read_input proc~erosion_initialise erosion_initialise proc~initialise->proc~erosion_initialise proc~reservoir_initialise reservoir_initialise proc~initialise->proc~reservoir_initialise proc~snow_initialise snow_initialise proc~initialise->proc~snow_initialise proc~catchment_initialise_parameters catchment_initialise_parameters proc~initialise->proc~catchment_initialise_parameters proc~landuse_initialise landuse_initialise proc~initialise->proc~landuse_initialise proc~crop_initialise crop_initialise proc~initialise->proc~crop_initialise proc~soil_initialise soil_initialise proc~initialise->proc~soil_initialise proc~evapotranspiration_initialise evapotranspiration_initialise proc~initialise->proc~evapotranspiration_initialise proc~groundwater_initialise groundwater_initialise proc~initialise->proc~groundwater_initialise proc~river_initialise river_initialise proc~initialise->proc~river_initialise proc~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~management_initialise management_initialise proc~initialise->proc~management_initialise proc~output_initialise output_initialise proc~initialise->proc~output_initialise proc~reservoir_read_control_file reservoir_read_control_file proc~reservoir_read_control_file->proc~read_logical_column proc~reservoir_read_control_file->proc~read_string_column proc~reservoir_read_control_file->proc~read_real_column proc~reservoir_read_control_file->proc~read_integer_column proc~output_initialise_labelled output_initialise_labelled proc~output_initialise_labelled->proc~read_string_column proc~output_initialise_labelled->proc~has_column proc~erosion_read_input erosion_read_input proc~erosion_read_input->proc~read_real_column proc~management_read_time_series management_read_time_series proc~management_read_time_series->proc~read_real_column proc~time_initialise_year time_initialise_year proc~time_initialise_year->proc~read_real_column proc~erosion_initialise->proc~erosion_read_input proc~reservoir_initialise->proc~reservoir_read_storage_file proc~reservoir_initialise->proc~reservoir_read_month_file proc~reservoir_initialise->proc~reservoir_read_control_file proc~output_initialise_storage output_initialise_storage proc~output_initialise_storage->proc~output_initialise_labelled proc~snow_initialise->proc~snow_read_input proc~catchment_initialise_parameters->proc~catchment_read_subcatch_params proc~landuse_initialise->proc~landuse_read_input program~swim swim program~swim->proc~initialise proc~time_process_years time_process_years program~swim->proc~time_process_years proc~crop_initialise->proc~crop_read_management_input proc~soil_initialise->proc~soil_read_input proc~evapotranspiration_initialise->proc~evapotranspiration_read_input proc~management_read_wu_inout management_read_wu_inout proc~management_read_wu_inout->proc~management_read_time_series proc~time_process_years->proc~time_initialise_year proc~time_process_month time_process_month proc~time_process_years->proc~time_process_month proc~groundwater_initialise->proc~groundwater_read_input proc~river_initialise->proc~river_read_input proc~hydrotope_initialise->proc~hydrotope_read_input proc~time_process_day time_process_day proc~time_process_day->proc~subbasin_read_climate proc~management_initialise->proc~management_read_ctrl proc~management_initialise->proc~management_read_wu_inout proc~time_process_month->proc~time_process_day proc~output_initialise->proc~output_initialise_storage

Contents

Source Code


Source Code

  integer function header_column_index(column, file_id, required)
    ! Return index of column in first line of file_id, return 0 if not found
    character(len=*), intent(in) :: column
    integer, intent(in) :: file_id
    logical, intent(in), optional :: required
    integer iostat, ie
    character(len=read_line_buffer_size) buffer
    character(len=read_line_buffer_size*2) scanpart, current_col
    logical column_not_found

    rewind(file_id)
    scanpart = ''
    column_not_found = .True.
    header_column_index = 0
    iostat = 0
    do while (column_not_found .and. iostat == 0)
      read(file_id, "(a)", advance="no", iostat=iostat) buffer
      scanpart = trim(adjustl(scanpart))//buffer
      ie = 1
      do while (column_not_found .and. ie > 0)
        ie = scan(scanpart, ",")
        if (ie > 0) then
          current_col = trim(adjustl(scanpart(:ie-1)))
          scanpart = scanpart(ie+1:)
          header_column_index = header_column_index + 1
          column_not_found = trim(adjustl(current_col)) /= trim(adjustl(column))
        else if (iostat < 0) then  ! last column
          current_col = scanpart
          header_column_index = header_column_index + 1
          column_not_found = trim(adjustl(current_col)) /= trim(adjustl(column))
        end if
      end do
    end do
    if (column_not_found) then
      header_column_index = 0
      if (present(required)) then
        if (required) call input_error_column_not_found(column, file_id)
      end if
    end if
    ! Make sure we move to next line if not already
    if (iostat == 0) call move_lines(file_id, 1)
  end function header_column_index