tem_open Subroutine

public subroutine tem_open(file, unit, newunit, status, position, action, form, access, recl)

Wrapper around Fortran open of files to take care of errors and improve the error message in case the opening goes wrong.

Use newunit to let tem_open provide a new file unit for the opened file.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file
integer, intent(in), optional :: unit
integer, intent(out), optional :: newunit
character(len=*), intent(in), optional :: status
character(len=*), intent(in), optional :: position
character(len=*), intent(in), optional :: action
character(len=*), intent(in), optional :: form
character(len=*), intent(in), optional :: access
integer, intent(in), optional :: recl

Calls

proc~~tem_open~~CallsGraph proc~tem_open tem_open proc~upper_to_lower upper_to_lower proc~tem_open->proc~upper_to_lower proc~tem_abort tem_abort proc~tem_open->proc~tem_abort proc~newunit newunit proc~tem_open->proc~newunit mpi_abort mpi_abort proc~tem_abort->mpi_abort

Called by

proc~~tem_open~~CalledByGraph proc~tem_open tem_open proc~load_tem_bc_prop load_tem_BC_prop proc~load_tem_bc_prop->proc~tem_open proc~tem_color_prop_out tem_color_prop_out proc~tem_color_prop_out->proc~tem_open proc~hvs_ascii_open hvs_ascii_open proc~hvs_ascii_open->proc~tem_open proc~load_datafile load_datafile proc~load_datafile->proc~tem_open proc~hvs_vtk_open~2 hvs_vtk_open proc~hvs_vtk_open~2->proc~tem_open proc~hvs_vtk_init~2 hvs_vtk_init proc~hvs_vtk_init~2->proc~tem_open proc~tem_size_stlb tem_size_stlb proc~tem_size_stlb->proc~tem_open proc~tem_read_stlb tem_read_stlb proc~tem_read_stlb->proc~tem_open proc~tem_color_prop_load tem_color_prop_load proc~tem_color_prop_load->proc~tem_open proc~tem_timer_dumplabeled tem_timer_dumplabeled proc~tem_timer_dumplabeled->proc~tem_open proc~load_treelmesh load_treelmesh proc~load_treelmesh->proc~tem_open proc~tem_restart_writeheader tem_restart_writeHeader proc~tem_restart_writeheader->proc~tem_open proc~tem_dump_stlb tem_dump_stlb proc~tem_dump_stlb->proc~tem_open proc~tem_subres_prop_load tem_subres_prop_load proc~tem_subres_prop_load->proc~tem_open proc~hvs_asciispatial_open hvs_asciiSpatial_open proc~hvs_asciispatial_open->proc~tem_open proc~tem_trackmem tem_trackmem proc~tem_trackmem->proc~tem_open proc~load_temporal_from_file load_temporal_from_file proc~load_temporal_from_file->proc~load_datafile proc~load_tem load_tem proc~load_tem->proc~load_treelmesh proc~init_tem_bc_prop init_tem_bc_prop proc~init_tem_bc_prop->proc~load_tem_bc_prop proc~hvs_ascii_init hvs_ascii_init proc~hvs_ascii_init->proc~hvs_ascii_open proc~tem_read_stlfiles tem_read_stlFiles proc~tem_read_stlfiles->proc~tem_size_stlb proc~tem_read_stlfiles->proc~tem_read_stlb proc~hvs_dump_debug_array hvs_dump_debug_array proc~hvs_dump_debug_array->proc~hvs_vtk_open~2 proc~hvs_dump_debug_array->proc~hvs_vtk_init~2 proc~tem_readandunify_surfdata tem_readAndUnify_surfData proc~tem_readandunify_surfdata->proc~tem_size_stlb proc~tem_readandunify_surfdata->proc~tem_read_stlb proc~tem_timer_dump_glob tem_timer_dump_glob proc~tem_timer_dump_glob->proc~tem_timer_dumplabeled proc~tem_restart_openwrite tem_restart_openWrite proc~tem_restart_openwrite->proc~tem_restart_writeheader proc~tem_restart_closewrite tem_restart_closeWrite proc~tem_restart_closewrite->proc~tem_restart_writeheader proc~hvs_output_open hvs_output_open proc~hvs_output_open->proc~hvs_asciispatial_open

Contents

Source Code


Source Code

  subroutine tem_open(file, unit, newunit, status, position, action, form, &
    &                 access, recl)
    character(len=*), intent(in) :: file
    character(len=*), intent(in), optional :: status
    character(len=*), intent(in), optional :: position
    character(len=*), intent(in), optional :: action
    character(len=*), intent(in), optional :: form
    character(len=*), intent(in), optional :: access
    integer, intent(in), optional :: recl
    integer, intent(in), optional :: unit
    integer, intent(out), optional :: newunit
    ! -------------------------------------------------------------------- !
    character(len=labelLen) :: loc_status
    character(len=labelLen) :: loc_position
    character(len=labelLen) :: loc_action
    character(len=labelLen) :: loc_form
    character(len=labelLen) :: loc_access
    integer :: stat
    integer :: funit
    ! -------------------------------------------------------------------- !

    ! Defaults:
    loc_status   = 'unknown'
    loc_position = 'asis'
    loc_action   = 'readwrite'
    loc_form     = 'formatted'
    loc_access   = 'sequential'

    if (present(status)) loc_status = upper_to_lower(status)
    if (present(position)) loc_position = upper_to_lower(position)
    if (present(action)) loc_action = upper_to_lower(action)
    if (present(access)) loc_access = upper_to_lower(access)

    ! Stream IO is by default unformatted.
    if (loc_access == 'stream') loc_form = 'unformatted'

    if (present(form)) loc_form = upper_to_lower(form)

    if (present(unit)) then
      funit = unit
    else
      funit = env_nu()
      if (present(newunit)) then
        newunit = funit
      end if
    end if

    rl_provided: if (present(recl)) then

      pos_provided: if (present(position)) then
        open( unit     = funit,            &
          &   file     = file,             &
          &   action   = trim(loc_action), &
          &   access   = loc_access,       &
          &   status   = loc_status,       &
          &   position = loc_position,     &
          &   form     = loc_form,         &
          &   recl     = recl,             &
          &   iostat   = stat              )
      else pos_provided
        open( unit     = funit,            &
          &   file     = file,             &
          &   action   = trim(loc_action), &
          &   access   = loc_access,       &
          &   status   = loc_status,       &
          &   form     = loc_form,         &
          &   recl     = recl,             &
          &   iostat   = stat              )
      end if pos_provided

    else rl_provided

      seqpos: if ( (loc_access == 'sequential') .and. present(position)) then
        open( unit     = funit,            &
          &   file     = file,             &
          &   action   = trim(loc_action), &
          &   access   = loc_access,       &
          &   status   = loc_status,       &
          &   position = loc_position,     &
          &   form     = loc_form,         &
          &   iostat   = stat              )
      else seqpos
        open( unit     = funit,            &
          &   file     = file,             &
          &   action   = trim(loc_action), &
          &   access   = loc_access,       &
          &   status   = loc_status,       &
          &   form     = loc_form,         &
          &   iostat   = stat              )
      end if seqpos

    end if rl_provided

    if (stat /= 0) then
      write(logUnit(1), *) 'Could not open file!'
      write(logUnit(1), *) 'iostat=', stat
      write(logUnit(1), *) 'File:     ' // trim(file)
      if (present(action))   write(logUnit(1), *) 'Action:   ' // trim(action)
      if (present(form))     write(logUnit(1), *) 'Form:     ' // trim(form)
      if (present(access))   write(logUnit(1), *) 'Access:   ' // trim(access)
      if (present(status))   write(logUnit(1), *) 'Status:   ' // trim(status)
      if (present(recl))     write(logUnit(1), *) 'Recl:     ', recl
      if (present(position)) write(logUnit(1), *) 'Position: ' // trim(position)
      write(logUnit(1), *) 'Aborting...'
      call tem_abort()
    end if

  end subroutine tem_open