opntext Subroutine

private subroutine opntext(lu, filename, status, rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: lu
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: status
integer, intent(out) :: rc

Source Code

    subroutine opntext(lu, filename, status, rc)

      integer,         intent(in) :: lu     ! logical unit number
      character(len=*),intent(in) :: filename  ! filename to be opened
      character(len=*),intent(in) :: status ! the value for STATUS=<>
      integer,         intent(out):: rc     ! the status

!-----------------------------------------------------------------------
!

                ! local parameter

        character(len=len(status)) :: Ustat
        integer :: iostat


#ifdef _UNICOS
        call asnunit(lu,'-R',iostat)         ! remove any set attributes
        if (iostat /= 0) then
          rc = ESMF_FAILURE
          return  ! let the parent handle it
        end if
#endif

        Ustat = ESMF_UtilStringUpperCase (string=status)
        select case(Ustat)

        case ('APPEND')

          open(                           &
            unit        =lu,              &
            file        =filename,        &
            form        ='formatted',     &
            access      ='sequential',    &
            status      ='unknown',       &
            action      ='readwrite',     &
            position    ='append',        &
            iostat      =iostat            )

        case default

          open(                           &
            unit        =lu,              &
            file        =filename,        &
            form        ='formatted',     &
            access      ='sequential',    &
            status      =status,          &
            action      ='read',          &
            position    ='asis',          &
            iostat      =iostat            )

        end select

        if (iostat == 0) then
          rc = ESMF_SUCCESS
        else
          rc = ESMF_RC_FILE_OPEN
        endif

        end subroutine opntext