read_csv_item Function

public function read_csv_item(index, file_id) result(column)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: index
integer, intent(in) :: file_id

Return Value character(len=read_line_buffer_size)


Called by

proc~~read_csv_item~~CalledByGraph proc~read_csv_item read_csv_item proc~read_real_column read_real_column proc~read_real_column->proc~read_csv_item proc~read_logical_column read_logical_column proc~read_logical_column->proc~read_csv_item proc~read_integer_column read_integer_column proc~read_integer_column->proc~read_csv_item proc~read_string_column read_string_column proc~read_string_column->proc~read_csv_item 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_real_column proc~management_read_ctrl->proc~read_integer_column proc~management_read_ctrl->proc~read_string_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~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~reservoir_read_month_file reservoir_read_month_file proc~reservoir_read_month_file->proc~read_real_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 subbasin_read_routing 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_real_column proc~crop_read_input->proc~read_integer_column proc~crop_read_input->proc~read_string_column proc~subbasin_read_input subbasin_read_input proc~subbasin_read_input->proc~read_real_column proc~subbasin_read_input->proc~read_integer_column proc~subbasin_read_input->proc~read_string_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~reservoir_read_control_file reservoir_read_control_file proc~reservoir_read_control_file->proc~read_real_column proc~reservoir_read_control_file->proc~read_logical_column proc~reservoir_read_control_file->proc~read_integer_column proc~reservoir_read_control_file->proc~read_string_column proc~output_initialise_labelled output_initialise_labelled proc~output_initialise_labelled->proc~read_string_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 erosion_initialise proc~erosion_initialise->proc~erosion_read_input proc~reservoir_initialise reservoir_initialise 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~initialise initialise proc~initialise->proc~crop_read_input proc~initialise->proc~erosion_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~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~groundwater_initialise groundwater_initialise proc~initialise->proc~groundwater_initialise proc~river_initialise river_initialise proc~initialise->proc~river_initialise proc~subbasin_initialise subbasin_initialise proc~initialise->proc~subbasin_initialise proc~management_initialise management_initialise proc~initialise->proc~management_initialise proc~output_initialise output_initialise proc~initialise->proc~output_initialise proc~snow_initialise->proc~snow_read_input proc~catchment_initialise_parameters->proc~catchment_read_subcatch_params proc~landuse_initialise->proc~landuse_read_input proc~crop_initialise->proc~crop_read_management_input proc~soil_initialise->proc~soil_read_input proc~evapotranspiration_initialise->proc~evapotranspiration_read_input proc~hydrotope_initialise->proc~hydrotope_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 time_process_years 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~subbasin_initialise->proc~subbasin_read_routing proc~subbasin_initialise->proc~subbasin_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 program~swim swim program~swim->proc~initialise program~swim->proc~time_process_years proc~time_process_month->proc~time_process_day proc~output_initialise->proc~output_initialise_storage

Contents

Source Code


Source Code

  function read_csv_item(index, file_id) result(column)
    ! Return the index'th item from the next line of file_id and move to next line
    ! Raise error if number of items not found
    integer, intent(in) :: index, file_id
    character(len=read_line_buffer_size) :: column
    character(len=read_line_buffer_size) buffer
    character(len=read_line_buffer_size*2) scanpart
    logical column_not_found
    integer ic, iostat, ie

    scanpart = ''
    column_not_found = .True.
    ic = 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  ! comma found
          ic = ic + 1
          column_not_found = ic /= index
          if (.not. column_not_found) column = trim(adjustl(scanpart(:ie-1)))
          scanpart = scanpart(ie+1:)
        else if (iostat < 0 .and. ic+1 == index) then  ! last item
          column = trim(adjustl(scanpart))
          column_not_found = .False.
        end if
      end do
    end do
    if (column_not_found) then
      ! TODO error if not found, e.g. because end of file or line
    else
      ! Move to next line if not already
      if (iostat == 0) read(file_id, "(a)")
    end if
  end function read_csv_item