!*
!* Copyright 2010. The Regents of the University of California.
!* All Rights Reserved.
!* @author Prakashan Korambath
!*
!* Purpose: Make use of scheduler TMPDIR variable for File I/O. The scratch space
!* defined in SGE is often has a faster I/O than NFS file system. So your codes
!* may run faster if you use TMPDIR to write scratch files which are not needed
!* at the end of a run. The scheduler used on Hoffman2 is Oracle Grid Engine.
!* In place of TMPDIR any other faster SCRATCH space can be substituted.
!* Example compile command: ifort -o sgeenviron sgeenviron.f90
!*
!* This software program and documentation are copyrighted by The Regents
!* of the University of California. The software program and documentation
!* are supplied "as is", without any accompanying services from The Regents.
!* The Regents does not warrant that the operation of the program will be
!* uninterrupted or error-free. The end-user understands that the program
!* was developed for research purposes and is advised not to rely exclusively
!* on the program for any reason.
!* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
!* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
!* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
!* EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
!* OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
!* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
!* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED
!* HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO
!* OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
!* MODIFICATIONS.
!*
!*
PROGRAM sgeenviron
implicit none
CHARACTER(len=255) :: tmpdir
CHARACTER(len=128) :: scratch1
CHARACTER(len=512) :: filepath
INTEGER :: length, index, rindex
! get SGE TMPDIR environment variable
CALL getenv("TMPDIR", tmpdir)
length = len(trim(tmpdir))
if (length == 0) then
print *, 'Failed to get environment variable TMPDIR'
tmpdir = '/work'
endif
print *, 'TMPDIR = ', trim(tmpdir)
! This is the scratch file in your program (do not forget leading / character)
scratch1='/scratchxxx'
length = len(trim(tmpdir))
length = length + len(trim(scratch1))
if ( length .gt. 512) then
print *, 'scratch file buffer is too small'
endif
! This is the full path of your scratch file
filepath = trim(tmpdir)//trim(scratch1)
print *, ' Full filepath =', trim(filepath)
! Open the scratch file for write
OPEN(UNIT=1,FILE=trim(filepath),STATUS='NEW')
do index=1,10
write(1, '(I4)') index
enddo
close (1)
! open the scratch file for read
OPEN(UNIT=8,FILE=trim(filepath),STATUS='OLD')
do index=1,10
read(8, '(I4)') rindex
print *, rindex
enddo
CLOSE(UNIT=8,STATUS='DELETE')
END PROGRAM