1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/mdsfindunit.F,v 1.3 2012/11/26 00:13:05 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
SUBROUTINE MDSFINDUNIT( ioUnit, myThid ) |
7 |
C OUT: |
8 |
C ioUnit (integer) :: unit number |
9 |
C |
10 |
C MDSFINDUNIT returns a valid, unused unit number for f77 I/O |
11 |
C The routine stops the program is an error occurs in the process |
12 |
C of searching the I/O channels. |
13 |
C |
14 |
C Created: 03/20/99 adcroft@mit.edu |
15 |
|
16 |
IMPLICIT NONE |
17 |
|
18 |
#include "EEPARAMS.h" |
19 |
|
20 |
C Arguments |
21 |
INTEGER ioUnit |
22 |
INTEGER myThid |
23 |
C Local |
24 |
INTEGER ii |
25 |
LOGICAL op |
26 |
INTEGER ios |
27 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
28 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
29 |
|
30 |
C Sweep through a valid range of unit numbers |
31 |
ioUnit=-1 |
32 |
#ifdef HACK_FOR_GMAO_CPL |
33 |
DO ii=31,999 |
34 |
#else /* HACK_FOR_GMAO_CPL */ |
35 |
DO ii=9,999 |
36 |
#endif /* HACK_FOR_GMAO_CPL */ |
37 |
IF ( ioUnit.EQ.-1 ) THEN |
38 |
C- skip reserved unit numbers |
39 |
IF ( ii.NE.errorMessageUnit |
40 |
& .AND. ii.NE.standardMessageUnit |
41 |
& .AND. ii.NE.scrUnit1 .AND. ii.NE.scrUnit2 |
42 |
& .AND. ii.NE.eeDataUnit .AND. ii.NE.modelDataUnit |
43 |
& ) THEN |
44 |
INQUIRE(unit=ii,iostat=ios,opened=op) |
45 |
IF ( ios.NE.0 ) THEN |
46 |
WRITE(msgBuf,'(A,I4)') |
47 |
& ' MDSFINDUNIT: inquiring unit number =', ii |
48 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
49 |
& SQUEEZE_RIGHT, myThid ) |
50 |
WRITE(msgBuf,'(A)') |
51 |
& ' MDSFINDUNIT: inquire statement failed!' |
52 |
CALL PRINT_ERROR( msgBuf, myThid ) |
53 |
STOP 'ABNORMAL END: S/R MDSFINDUNIT' |
54 |
ENDIF |
55 |
IF ( .NOT.op ) THEN |
56 |
ioUnit=ii |
57 |
ENDIF |
58 |
ENDIF |
59 |
ENDIF |
60 |
ENDDO |
61 |
|
62 |
C Was there an available unit number |
63 |
IF ( ioUnit.EQ.-1 ) THEN |
64 |
WRITE(msgBuf,'(A)') |
65 |
& ' MDSFINDUNIT: could not find an available unit number!' |
66 |
CALL PRINT_ERROR( msgBuf, myThid ) |
67 |
STOP 'ABNORMAL END: S/R MDSFINDUNIT' |
68 |
ENDIF |
69 |
|
70 |
RETURN |
71 |
END |