GETFILE Function

public function GETFILE(Name, DO_OPEN, Form, ALL_PES, BLOCKSIZE, NUMBUFFERS, RC)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: Name
integer, intent(in), optional :: DO_OPEN
character(len=*), intent(in), optional :: Form
logical, intent(in), optional :: ALL_PES
integer, intent(in), optional :: BLOCKSIZE
integer, intent(in), optional :: NUMBUFFERS
integer, intent(out), optional :: RC

Return Value integer


Calls

proc~~getfile~~CallsGraph proc~getfile GETFILE interface~mapl_am_i_root MAPL_Am_I_Root proc~getfile->interface~mapl_am_i_root proc~mapl_return MAPL_Return proc~getfile->proc~mapl_return proc~mapl_verify MAPL_Verify proc~getfile->proc~mapl_verify at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Called by

proc~~getfile~~CalledByGraph proc~getfile GETFILE proc~mapl_climupdate MAPL_ClimUpdate proc~mapl_climupdate->proc~getfile proc~mapl_destroystatesave MAPL_DestroyStateSave proc~mapl_destroystatesave->proc~getfile proc~mapl_destroystatesave->proc~mapl_destroystatesave proc~mapl_esmfstatereadfromfile MAPL_ESMFStateReadFromFile proc~mapl_esmfstatereadfromfile->proc~getfile proc~mapl_genericfinalize MAPL_GenericFinalize proc~mapl_genericfinalize->proc~getfile proc~mapl_genericrecord MAPL_GenericRecord proc~mapl_genericrecord->proc~getfile proc~mapl_genericrefresh MAPL_GenericRefresh proc~mapl_genericrefresh->proc~getfile proc~mapl_genericrefresh->proc~mapl_esmfstatereadfromfile proc~mapl_genericrefresh->proc~mapl_genericrefresh proc~mapl_genericstaterestore MAPL_GenericStateRestore proc~mapl_genericstaterestore->proc~getfile proc~mapl_genericstaterestore->proc~mapl_esmfstatereadfromfile proc~mapl_genericstaterestore->proc~mapl_genericstaterestore proc~mapl_genericstatesave MAPL_GenericStateSave proc~mapl_genericstatesave->proc~getfile proc~mapl_genericstatesave->proc~mapl_genericstatesave proc~mapl_genericinitialize MAPL_GenericInitialize proc~mapl_genericinitialize->proc~mapl_esmfstatereadfromfile

Source Code

  INTEGER FUNCTION GETFILE( NAME, DO_OPEN, FORM, ALL_PES, &
                             BLOCKSIZE, NUMBUFFERS, RC )
    IMPLICIT NONE

    character(LEN=*), intent(in   )           :: Name
    integer         , intent(in   ), OPTIONAL :: DO_OPEN
    character(LEN=*), intent(in   ), OPTIONAL :: Form
    logical         , intent(in   ), OPTIONAL :: ALL_PES
    integer         , intent(in   ), OPTIONAL :: BLOCKSIZE
    integer         , intent(in   ), OPTIONAL :: NUMBUFFERS
    integer         , intent(  out), OPTIONAL :: RC

    INTEGER I
    integer :: DO_OPEN_
    logical :: ALL_PES_
    integer          :: status

    LOGICAL FILEOPEN, UNITOPEN, FOUND

    if(INDEX(NAME,'*') /= 0) then
        getfile = getfilemem(name,rc=status)
    _VERIFY(STATUS)
        _RETURN(ESMF_SUCCESS)
    endif

    if (NAME == "stdout" .or. NAME== "STDOUT") then
       GETFILE = STD_OUT_UNIT_NUMBER
       _RETURN(ESMF_SUCCESS)
    end if

    if (.not. present(DO_OPEN)) then
       DO_OPEN_ = 1
    else
       DO_OPEN_ = DO_OPEN
    end if

    ALL_PES_ = .false.
    if (present(ALL_PES)) then
       ALL_PES_ = ALL_PES
    end if

    if (.not. MAPL_AM_I_ROOT() .and. .not. ALL_PES_) then
       GETFILE = UNDEF
       _RETURN(ESMF_SUCCESS)
    end if

!   Check if the file is already open

    INQUIRE ( FILE=NAME, NUMBER=GETFILE, OPENED=FILEOPEN )

!   If the file isnt already open THEN

    IF ( .NOT. FILEOPEN ) THEN
       I = 20
       FOUND = .FALSE.
       DO WHILE ( I.LE.LAST_UNIT .AND. .NOT.FOUND )
          IF ( .NOT. TAKEN(I) ) THEN
             TAKEN(I) = .TRUE.
             INQUIRE ( UNIT=I, OPENED=UNITOPEN )
             IF ( .NOT. UNITOPEN ) THEN

                status = 0

                if ( DO_OPEN_ .NE. 0 ) then
                   call MAPL_open(UNIT=i,FILE=Name,FORM=FORM, &
                                  BLOCKSIZE= BLOCKSIZE, NUMBUFFERS=NUMBUFFERS, RC=STATUS)
                endif

                if ( status /= 0 ) then
                   write (0,*) 'ERROR opening "',trim(Name),'" using GETFILE'
                   write (0,*) ' IOSTAT = ',status
                   _RETURN(ESMF_FAILURE)
                endif

                GETFILE = I
                FOUND = .TRUE.
             ENDIF
          ENDIF
          I = I + 1
       ENDDO
!
!      IF there are no available logical units THEN
!         Write an error message
!         Return Error status
!      ENDIF there are no available logical units
!
       IF ( .NOT. FOUND ) THEN
          WRITE (0,*) ' COULD NOT FIND ANY AVAILABLE UNITS '
          _RETURN(ESMF_FAILURE)
       ENDIF

    ENDIF ! the file isnt already open

    _RETURN(ESMF_SUCCESS)
  END FUNCTION GETFILE