input_count_rows Function

public function input_count_rows(funit, header) result(nlines)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: funit
logical, intent(in) :: header

Return Value integer


Calls

proc~~input_count_rows~~CallsGraph proc~input_count_rows input_count_rows proc~log_error log_error proc~input_count_rows->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~~input_count_rows~~CalledByGraph proc~input_count_rows input_count_rows proc~crop_initialise crop_initialise proc~crop_initialise->proc~input_count_rows proc~soil_initialise soil_initialise proc~soil_initialise->proc~input_count_rows proc~management_read_ctrl management_read_ctrl proc~management_read_ctrl->proc~input_count_rows proc~reservoir_read_control_file reservoir_read_control_file proc~reservoir_read_control_file->proc~input_count_rows proc~subbasin_read_routing subbasin_read_routing proc~subbasin_read_routing->proc~input_count_rows proc~landuse_initialise landuse_initialise proc~landuse_initialise->proc~input_count_rows proc~subbasin_initialise subbasin_initialise proc~subbasin_initialise->proc~input_count_rows proc~subbasin_initialise->proc~subbasin_read_routing proc~hydrotope_read_input hydrotope_read_input proc~hydrotope_read_input->proc~input_count_rows proc~initialise initialise proc~initialise->proc~crop_initialise proc~initialise->proc~soil_initialise proc~initialise->proc~landuse_initialise proc~initialise->proc~subbasin_initialise proc~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~reservoir_initialise reservoir_initialise proc~initialise->proc~reservoir_initialise proc~management_initialise management_initialise proc~initialise->proc~management_initialise proc~hydrotope_initialise->proc~hydrotope_read_input proc~reservoir_initialise->proc~reservoir_read_control_file proc~management_initialise->proc~management_read_ctrl program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  function input_count_rows(funit, header) result(nlines)
    ! Author: stefan.liersch@pik-potsdam.de
    ! Date: 2009-09-20
    ! PURPOSE: counts the number of rows in input file with given file unit
    ! The file must already be open!!!
    ! file unit

    integer, intent(in) :: funit
    ! true if input file contains a header
    logical, intent(in) :: header
    ! counter
    integer :: nlines
    ! file status
    integer :: status
    ! dummy for reading
    character(len=read_line_buffer_size) :: a
    character(len=path_max_length) fname

    status = 0
    nlines = 0
    ! rewind file in order to be sure to read the file from the first line
    rewind(funit)

    if (header) nlines = nlines - 1

    ! count number of rows in file: fname
    do
      read(funit, *, IOSTAT=status) a
      if (status > 0) then  ! read error (unlikely since we are only skipping lines)
        inquire(unit=funit, name=fname)
        call log_error("input_count_rows", 'Unable to count lines of file '//trim(fname))
      else if (status == -1 .or. len_trim(a) == 0) then  ! end of file or empty line
        EXIT
      end if
      nlines = nlines + 1
    end do

    rewind(funit)
  end function input_count_rows