Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:45:09 UTC

view on githubraw file Latest commit 279dc77b on 2015-07-03 21:33:55 UTC
279dc77b07 Patr*0001 module OAD_regular_cp
                0002 
                0003   implicit none
                0004 
                0005   private :: cp_file_number, cp_open
                0006 
                0007   public :: cp_io_unit, cp_init, cp_write_open, cp_read_open, cp_close, cp_fNumber
                0008 
                0009   integer :: cp_file_number, cp_io_unit
                0010 
                0011   interface cp_init
                0012      module procedure init_i
                0013   end interface
                0014 
                0015   interface cp_open
                0016      module procedure open_i
                0017   end interface
                0018 
                0019   interface cp_write_open
                0020      module procedure write_open_i
                0021      module procedure write_openX_i
                0022   end interface
                0023 
                0024   interface cp_read_open
                0025      module procedure read_open_i
                0026      module procedure read_openX_i
                0027   end interface
                0028 
                0029   interface cp_close
                0030      module procedure close_i
                0031   end interface
                0032 
                0033   interface cp_findunit
                0034      module procedure findunit_i
                0035   end interface
                0036   
                0037 contains
                0038 
                0039   subroutine init_i
                0040     implicit none
                0041     cp_file_number=1
                0042   end subroutine
                0043 
                0044   subroutine write_open_i()
                0045     implicit none
                0046     call cp_open()
                0047 !    print *, 'writing ', cp_file_number
                0048     cp_file_number=cp_file_number+1
                0049   end subroutine 
                0050 
                0051   subroutine write_openX_i(X)
                0052     implicit none
                0053     integer X
                0054     cp_file_number=X
                0055 !    print *, 'writing ', cp_file_number
                0056     call cp_open()
                0057   end subroutine 
                0058 
                0059   subroutine read_open_i()
                0060     implicit none
                0061     cp_file_number=cp_file_number-1
                0062 !    print *, 'reading ', cp_file_number
                0063     call cp_open()
                0064   end subroutine 
                0065 
                0066   subroutine read_openX_i(X)
                0067     implicit none
                0068     integer X
                0069     cp_file_number=X
                0070 !    print *, 'reading ', cp_file_number
                0071     call cp_open()
                0072   end subroutine 
                0073 
                0074   subroutine open_i()
                0075     implicit none
                0076 
                0077 
                0078 
                0079     integer rank, mpirc
                0080     character*128 fname ! file name
                0081     ! get unit
                0082     rank=0
                0083     call cp_findunit()
                0084 !    print *, 'OAD: opening CP file ', cp_file_number
                0085     ! construct the file name
                0086 
                0087 
                0088 
                0089     write(fname,'(A,I3.3,A,I5.5)') 'oad_reg_cp.',rank,'.',cp_file_number
                0090     open( UNIT=cp_io_unit,FILE=TRIM(fname),FORM='unformatted',STATUS='UNKNOWN' )
                0091     !open( UNIT=cp_io_unit,FILE=TRIM(fname),FORM='formatted',STATUS='UNKNOWN' )
                0092   end subroutine 
                0093 
                0094   subroutine close_i()
                0095     implicit none
                0096     close( UNIT=cp_io_unit)
                0097   end subroutine
                0098 
                0099   subroutine findunit_i()
                0100     ! returns a valid, unused unit number for Fortran I/O
                0101     ! the routine stops the program if an error occurs in the process
                0102     ! of searching the I/O channels.
                0103     implicit none
                0104     ! Local
                0105     integer ii
                0106     logical op
                0107     integer ios
                0108     character*(1024) msgbuf
                0109     ! Sweep through a valid range of unit numbers
                0110     cp_io_unit=-1
                0111     do ii=9,999
                0112        if (cp_io_unit.eq.-1) then
                0113           inquire(unit=ii,iostat=ios,opened=op)
                0114           if (ios.ne.0) then
                0115              write(msgbuf,'(a,i2.2)')  'OAD_regular_cp:findunit_i: inquiring unit number = ',ii
                0116              print *, msgBuf
                0117              write(msgbuf,'(a)') 'OAD_regular_cp:findunit_i: inquire statement failed!'
                0118              print *, msgBuf
                0119              stop 'ABNORMAL END: S/R OAD_regular_cp:findunit_i'
                0120           endif
                0121           if (.NOT. op) then
                0122              cp_io_unit=ii
                0123           end if
                0124        end if
                0125     end do
                0126     ! Was there an available unit number
                0127     if (cp_io_unit.eq.-1) then
                0128        write(msgbuf,'(a)')  'OAD_regular_cp:findunit_i: could not find an available unit number!'
                0129        print *, msgBuf
                0130        stop 'ABNORMAL END: S/R OAD_regular_cp:findunit_i'
                0131     endif
                0132   end subroutine
                0133 
                0134   function cp_fNumber()
                0135     integer cp_fNumber
                0136     cp_fNumber=cp_file_number
                0137   end function 
                0138 
                0139 end module