open_file Function

public function open_file(fname, status)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: fname
character(len=1), intent(in), optional :: status

Return Value integer


Calls

proc~~open_file~~CallsGraph proc~open_file 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~~open_file~~CalledByGraph proc~open_file open_file proc~log_create log_create proc~log_create->proc~open_file proc~get_config_fid get_config_fid proc~get_config_fid->proc~open_file proc~output_initialise_user_input output_initialise_user_input proc~output_initialise_user_input->proc~open_file proc~output_initialise_user_input->proc~log_create proc~output_initialise_user_input->proc~get_config_fid proc~input_open_file input_open_file proc~input_open_file->proc~open_file proc~soil_read_input soil_read_input proc~soil_read_input->proc~open_file proc~output_open_file output_open_file proc~output_open_file->proc~open_file proc~management_read_time_series management_read_time_series proc~management_read_time_series->proc~open_file proc~output_open_files output_open_files proc~output_open_files->proc~output_open_file proc~management_write_user_output management_write_user_output proc~management_write_user_output->proc~output_open_file proc~vegetation_initialise vegetation_initialise proc~vegetation_initialise->proc~get_config_fid proc~snow_initialise snow_initialise proc~snow_initialise->proc~get_config_fid proc~reservoir_read_storage_file reservoir_read_storage_file proc~reservoir_read_storage_file->proc~input_open_file proc~management_read_ctrl management_read_ctrl proc~management_read_ctrl->proc~input_open_file proc~groundwater_initialise groundwater_initialise proc~groundwater_initialise->proc~get_config_fid proc~terminate terminate proc~terminate->proc~get_config_fid proc~terminate->proc~management_write_user_output proc~input_initialise input_initialise proc~input_initialise->proc~get_config_fid proc~crop_initialise crop_initialise proc~crop_initialise->proc~get_config_fid proc~crop_initialise->proc~input_open_file proc~soil_initialise soil_initialise proc~soil_initialise->proc~get_config_fid proc~soil_initialise->proc~input_open_file proc~soil_initialise->proc~soil_read_input proc~reservoir_read_month_file reservoir_read_month_file proc~reservoir_read_month_file->proc~input_open_file proc~subbasin_read_routing subbasin_read_routing proc~subbasin_read_routing->proc~input_open_file proc~time_initialise time_initialise proc~time_initialise->proc~get_config_fid proc~erosion_initialise erosion_initialise proc~erosion_initialise->proc~get_config_fid proc~input_nc_check_grid input_nc_check_grid proc~input_nc_check_grid->proc~input_open_file proc~management_initialise management_initialise proc~management_initialise->proc~log_create proc~management_initialise->proc~management_read_ctrl proc~management_read_wu_inout management_read_wu_inout proc~management_initialise->proc~management_read_wu_inout proc~nutrient_initialise nutrient_initialise proc~nutrient_initialise->proc~get_config_fid proc~input_nc_read_grid input_nc_read_grid proc~input_nc_read_grid->proc~input_open_file proc~catchment_initialise catchment_initialise proc~catchment_initialise->proc~get_config_fid proc~catchment_initialise->proc~input_open_file proc~input_nc_initialise input_nc_initialise proc~input_nc_initialise->proc~get_config_fid proc~input_nc_initialise->proc~input_nc_check_grid proc~input_nc_initialise->proc~input_nc_read_grid proc~landuse_initialise landuse_initialise proc~landuse_initialise->proc~get_config_fid proc~landuse_initialise->proc~input_open_file proc~river_initialise river_initialise proc~river_initialise->proc~get_config_fid proc~subbasin_initialise subbasin_initialise proc~subbasin_initialise->proc~get_config_fid proc~subbasin_initialise->proc~input_open_file proc~subbasin_initialise->proc~subbasin_read_routing proc~management_read_wu_inout->proc~management_read_time_series proc~hydrotope_read_input hydrotope_read_input proc~hydrotope_read_input->proc~input_open_file proc~reservoir_initialise reservoir_initialise proc~reservoir_initialise->proc~get_config_fid proc~reservoir_initialise->proc~reservoir_read_storage_file proc~reservoir_initialise->proc~reservoir_read_month_file proc~reservoir_open_output reservoir_open_output proc~reservoir_initialise->proc~reservoir_open_output proc~reservoir_read_control_file reservoir_read_control_file proc~reservoir_initialise->proc~reservoir_read_control_file proc~reservoir_open_output->proc~output_open_file proc~initialise initialise proc~initialise->proc~get_config_fid proc~initialise->proc~output_initialise_user_input proc~initialise->proc~vegetation_initialise proc~initialise->proc~snow_initialise proc~initialise->proc~groundwater_initialise proc~initialise->proc~input_initialise proc~initialise->proc~crop_initialise proc~initialise->proc~soil_initialise proc~initialise->proc~time_initialise proc~initialise->proc~erosion_initialise proc~initialise->proc~management_initialise proc~initialise->proc~nutrient_initialise proc~initialise->proc~catchment_initialise proc~initialise->proc~input_nc_initialise proc~initialise->proc~landuse_initialise proc~initialise->proc~river_initialise proc~initialise->proc~subbasin_initialise proc~initialise->proc~reservoir_initialise proc~evapotranspiration_initialise evapotranspiration_initialise proc~initialise->proc~evapotranspiration_initialise proc~hydrotope_initialise hydrotope_initialise proc~initialise->proc~hydrotope_initialise proc~output_initialise output_initialise proc~initialise->proc~output_initialise proc~reservoir_read_control_file->proc~input_open_file proc~evapotranspiration_initialise->proc~get_config_fid proc~hydrotope_initialise->proc~hydrotope_read_input proc~output_initialise_storage output_initialise_storage proc~output_initialise_storage->proc~output_open_files program~swim swim program~swim->proc~terminate program~swim->proc~initialise proc~output_initialise->proc~output_initialise_storage

Contents

Source Code


Source Code

  integer function open_file(fname, status)
    ! This function opens a file and returns the unit id (a free unit number between 21-1000,
    ! if file open was successful. The file status remains open!
    ! If file opening was not successful, the functions stops the programme and closes the file.
    character(len=*), intent(in) :: fname
    ! r for reading, w for writing
    character(len=1), intent(in), optional :: status
    character(len=1) :: st
    integer :: opensucc
    integer ui, iostat
    logical opened

    st = 'r'
    if (present(status)) st = status
    ! get free unit id
    do ui = 21, 1000
      inquire(unit = ui, opened = opened, iostat = iostat)
      if (iostat .ne. 0) cycle
      if (.not. opened) exit
    end do
    open_file = ui
    ! open file
    if (trim(st) == 'r') then
      open(ui, file=trim(fname), status='OLD', IOSTAT=opensucc)
    else if (trim(st) == "w") then
      open(ui, file=trim(fname), IOSTAT=opensucc)
    endif
    if (opensucc /= 0) then
      close(ui)
      call log_error("open_file", "ERROR while opening file: "//trim(fname)//" does it exist?")
    end if
  end function open_file