output_open_files Subroutine

public subroutine output_open_files()

Uses

  • proc~~output_open_files~~UsesGraph proc~output_open_files output_open_files module~utilities utilities proc~output_open_files->module~utilities

Arguments

None

Calls

proc~~output_open_files~~CallsGraph proc~output_open_files output_open_files proc~output_open_file output_open_file proc~output_open_files->proc~output_open_file proc~output_write_csv_header output_write_csv_header proc~output_open_files->proc~output_write_csv_header proc~open_file open_file proc~output_open_file->proc~open_file proc~log_error log_error proc~open_file->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~~output_open_files~~CalledByGraph proc~output_open_files output_open_files proc~output_initialise_storage output_initialise_storage proc~output_initialise_storage->proc~output_open_files proc~output_initialise output_initialise proc~output_initialise->proc~output_initialise_storage proc~initialise initialise proc~initialise->proc~output_initialise program~swim swim program~swim->proc~initialise

Contents

Source Code


Source Code

  subroutine output_open_files
    ! Open all needed output files and write csv headers
    use utilities, only : open_file
    integer fi, fid, rl
    type(output_file) :: fl
    character(len=path_max_length) :: fname
    integer, parameter :: nbytes_per_real = 4

    do fi = 1, output_nfiles
      fl = output_files(fi)
      fname = trim(output_space_dim(fl%space))//"_"//&
        trim(output_time_dim(fl%time))//"_"//trim(fl%name)// &
        "."//trim(output_format_dim(fl%format))
      if (fl%format == 1) then
        fid = output_open_file(fname)
      else if (fl%format == 2) then
        rl = output_nhydrotopes
        if (fl%space == 2) rl = output_nsubbasins
        if (fl%space == 3) rl = output_ncatchments
        if (fl%space == 4) rl = size(output_hydrotope_label_ix)
        if (fl%space == 5) rl = size(output_subbasin_label_ix)
        rl = rl * nbytes_per_real * fl%nvars
        ! TODO implement binary open file in open_file
        open(fid, file=fname, form="unformatted", access="direct", recl=rl)
      end if
      output_files(fi)%file_id = fid
      ! Write header if needed
      if (fl%format == 1) &
        call output_write_csv_header(fid, output_space_dim(fl%space), &
          output_requested_vars(fl%variable_ix(:fl%nvars)))
    end do
  end subroutine output_open_files