1 |
C $Header: /u/gcmpack/MITgcm/pkg/mdsio/mdsio_facef_read.F,v 1.3 2009/05/12 19:56:35 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "MDSIO_OPTIONS.h" |
5 |
|
6 |
C-- File mdsio_read_facefile.F: |
7 |
C-- Contents |
8 |
C-- o MDS_FACEF_READ_RS |
9 |
C-- o MDS_FACEF_READ_RL <- not yet coded |
10 |
|
11 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
12 |
|
13 |
CBOP |
14 |
C !ROUTINE: MDS_FACEF_READ_RS |
15 |
C !INTERFACE: |
16 |
SUBROUTINE MDS_FACEF_READ_RS( |
17 |
I fName, fPrec, irec, |
18 |
U array, |
19 |
I bi,bj, myThid ) |
20 |
C !DESCRIPTION: \bv |
21 |
C *==========================================================* |
22 |
C | SUBROUTINE MDS_FACEF_READ_RS |
23 |
C *==========================================================* |
24 |
C | Read 1 field from a file which contains all the data from |
25 |
C | 1 "face" (= piece of domain with rectangular topology) |
26 |
C *==========================================================* |
27 |
C \ev |
28 |
|
29 |
C !USES: |
30 |
IMPLICIT NONE |
31 |
C === Global variables === |
32 |
#include "SIZE.h" |
33 |
#include "EEPARAMS.h" |
34 |
#ifdef ALLOW_EXCH2 |
35 |
#include "W2_EXCH2_SIZE.h" |
36 |
#include "W2_EXCH2_TOPOLOGY.h" |
37 |
#endif /* ALLOW_EXCH2 */ |
38 |
|
39 |
C !INPUT/OUTPUT PARAMETERS: |
40 |
C == Routine arguments == |
41 |
CHARACTER*(*) fName |
42 |
INTEGER fPrec |
43 |
INTEGER irec |
44 |
_RS array(1-Olx:sNx+Olx,1-Oly:sNy+Oly,nSx,nSy) |
45 |
INTEGER bi,bj, myThid |
46 |
CEOP |
47 |
|
48 |
C !FUNCTIONS: |
49 |
INTEGER MDS_RECLEN |
50 |
EXTERNAL MDS_RECLEN |
51 |
INTEGER ILNBLNK |
52 |
EXTERNAL ILNBLNK |
53 |
|
54 |
C !LOCAL VARIABLES: |
55 |
C == Local variables == |
56 |
INTEGER i,j, dUnit, iLen |
57 |
INTEGER length_of_rec |
58 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
59 |
#ifdef ALLOW_EXCH2 |
60 |
INTEGER tN, dNx, dNy, tBx, tBy, tNx, tNY, jj, jBase |
61 |
Real*4 ioBuf4(1:sNx*nSx*nPx+1) |
62 |
Real*8 ioBuf8(1:sNx*nSx*nPx+1) |
63 |
#else |
64 |
Real*4 ioBuf4(1:sNx+1,1:sNy+1) |
65 |
Real*8 ioBuf8(1:sNx+1,1:sNy+1) |
66 |
#endif /* ALLOW_EXCH2 */ |
67 |
|
68 |
iLen = ILNBLNK(fName) |
69 |
#ifdef ALLOW_EXCH2 |
70 |
C Figure out offset of tile within face |
71 |
tN = W2_myTileList(bi,bj) |
72 |
dNx = exch2_mydnx(tN) |
73 |
dNy = exch2_mydny(tN) |
74 |
tBx = exch2_tbasex(tN) |
75 |
tBy = exch2_tbasey(tN) |
76 |
tNx = exch2_tnx(tN) |
77 |
tNy = exch2_tny(tN) |
78 |
|
79 |
CALL MDSFINDUNIT( dUnit, myThid ) |
80 |
length_of_rec = MDS_RECLEN( fPrec, (dNx+1), myThid ) |
81 |
OPEN( dUnit, file=fName(1:iLen), status='old', |
82 |
& access='direct', recl=length_of_rec ) |
83 |
j = 0 |
84 |
jBase=(irec-1)*(dNy+1) |
85 |
IF ( fPrec.EQ.precFloat32 ) THEN |
86 |
DO jj=1+tBy,sNy+1+tBy |
87 |
READ(dUnit,rec=jj+jBase) (ioBuf4(i),i=1,dNx+1) |
88 |
#ifdef _BYTESWAPIO |
89 |
CALL MDS_BYTESWAPR4( (dNx+1), ioBuf4 ) |
90 |
#endif |
91 |
j = j+1 |
92 |
DO i=1,sNx+1 |
93 |
array(i,j,bi,bj) = ioBuf4(i+tBx) |
94 |
ENDDO |
95 |
ENDDO |
96 |
ELSEIF ( fPrec.EQ.precFloat64 ) THEN |
97 |
DO jj=1+tBy,sNy+1+tBy |
98 |
READ(dUnit,rec=jj+jBase) (ioBuf8(i),i=1,dNx+1) |
99 |
#ifdef _BYTESWAPIO |
100 |
CALL MDS_BYTESWAPR8( (dNx+1), ioBuf8 ) |
101 |
#endif |
102 |
j = j+1 |
103 |
DO i=1,sNx+1 |
104 |
array(i,j,bi,bj) = ioBuf8(i+tBx) |
105 |
ENDDO |
106 |
ENDDO |
107 |
ELSE |
108 |
WRITE(msgBuf,'(A,I8,A)') ' MDS_FACEF_READ_RS:', |
109 |
& fPrec, ' = illegal value for fPrec' |
110 |
CALL PRINT_ERROR( msgBuf, myThid ) |
111 |
STOP 'ABNORMAL END: S/R MDS_FACEF_READ_RS' |
112 |
ENDIF |
113 |
CLOSE( dUnit ) |
114 |
|
115 |
#else /* ALLOW_EXCH2 */ |
116 |
|
117 |
CALL MDSFINDUNIT( dUnit, myThid ) |
118 |
length_of_rec = MDS_RECLEN( fPrec, (sNx+1)*(sNy+1), myThid ) |
119 |
OPEN( dUnit, file=fName(1:iLen), status='old', |
120 |
& access='direct', recl=length_of_rec ) |
121 |
IF ( fPrec.EQ.precFloat32 ) THEN |
122 |
READ(dUnit, rec=irec) ioBuf4 |
123 |
#ifdef _BYTESWAPIO |
124 |
CALL MDS_BYTESWAPR4( (sNx+1)*(sNy+1), ioBuf4 ) |
125 |
#endif |
126 |
DO j=1,sNy+1 |
127 |
DO i=1,sNx+1 |
128 |
array(i,j,bi,bj) = ioBuf4(i,j) |
129 |
ENDDO |
130 |
ENDDO |
131 |
ELSEIF ( fPrec.EQ.precFloat64 ) THEN |
132 |
READ(dUnit, rec=irec) ioBuf8 |
133 |
#ifdef _BYTESWAPIO |
134 |
CALL MDS_BYTESWAPR8( (sNx+1)*(sNy+1), ioBuf8 ) |
135 |
#endif |
136 |
DO j=1,sNy+1 |
137 |
DO i=1,sNx+1 |
138 |
array(i,j,bi,bj) = ioBuf8(i,j) |
139 |
ENDDO |
140 |
ENDDO |
141 |
ELSE |
142 |
WRITE(msgBuf,'(A,I8,A)') ' MDS_FACEF_READ_RS:', |
143 |
& fPrec, ' = illegal value for fPrec' |
144 |
CALL PRINT_ERROR( msgBuf, myThid ) |
145 |
STOP 'ABNORMAL END: S/R MDS_FACEF_READ_RS' |
146 |
ENDIF |
147 |
CLOSE( dUnit ) |
148 |
|
149 |
#endif /* ALLOW_EXCH2 */ |
150 |
|
151 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
152 |
|
153 |
RETURN |
154 |
END |