1 |
jmc |
1.11 |
C $Header: /u/gcmpack/MITgcm/pkg/exf/exf_interp_read.F,v 1.10 2007/04/09 23:57:50 dimitri Exp $ |
2 |
jmc |
1.5 |
C $Name: $ |
3 |
|
|
|
4 |
heimbach |
1.1 |
#include "EXF_OPTIONS.h" |
5 |
|
|
|
6 |
jmc |
1.11 |
CBOP |
7 |
|
|
C !ROUTINE: EXF_INTERP_READ |
8 |
|
|
C !INTERFACE: |
9 |
|
|
SUBROUTINE EXF_INTERP_READ( |
10 |
|
|
I infile, filePrec, |
11 |
|
|
O arrayin, |
12 |
|
|
I irecord, nx_in, ny_in, myThid ) |
13 |
heimbach |
1.1 |
|
14 |
jmc |
1.11 |
C !DESCRIPTION: |
15 |
|
|
|
16 |
|
|
C !USES: |
17 |
|
|
IMPLICIT NONE |
18 |
|
|
|
19 |
|
|
C Global variables / common blocks |
20 |
heimbach |
1.1 |
#include "SIZE.h" |
21 |
|
|
#include "EEPARAMS.h" |
22 |
jmc |
1.11 |
#include "EXF_PARAM.h" |
23 |
heimbach |
1.1 |
#ifdef ALLOW_USE_MPI |
24 |
|
|
# include "EESUPPORT.h" |
25 |
|
|
#endif /* ALLOW_USE_MPI */ |
26 |
|
|
#include "PARAMS.h" |
27 |
|
|
|
28 |
jmc |
1.11 |
|
29 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
30 |
|
|
C infile (string) :: name of the binary input file (direct access) |
31 |
|
|
C filePrec (integer) :: number of bits per word in file (32 or 64) |
32 |
|
|
C arrayin ( _RL ) :: array to read file into |
33 |
|
|
C irecord (integer) :: record number to read |
34 |
|
|
C nx_in,ny_in (integer) :: size in x & y direction of input file to read |
35 |
|
|
C myThid (integer) :: My Thread Id number |
36 |
|
|
|
37 |
|
|
CHARACTER*(*) infile |
38 |
|
|
INTEGER filePrec, irecord, nx_in, ny_in |
39 |
|
|
_RL arrayin( -1:nx_in+2 , -1:ny_in+2 ) |
40 |
|
|
INTEGER myThid |
41 |
|
|
CEOP |
42 |
|
|
|
43 |
|
|
C !FUNCTIONS |
44 |
|
|
INTEGER MDS_RECLEN |
45 |
|
|
LOGICAL MASTER_CPU_IO |
46 |
|
|
EXTERNAL MDS_RECLEN |
47 |
|
|
EXTERNAL MASTER_CPU_IO |
48 |
|
|
|
49 |
|
|
C !LOCAL VARIABLES |
50 |
|
|
INTEGER i, j |
51 |
|
|
INTEGER ioUnit, length_of_rec |
52 |
|
|
#ifdef EXF_INTERP_USE_DYNALLOC |
53 |
cnh |
1.3 |
#ifdef EXF_IREAD_USE_GLOBAL_POINTER |
54 |
|
|
C When using threads the address of the local automatic array |
55 |
jmc |
1.11 |
C "buffer" is not visible to the other threads. So we create |
56 |
cnh |
1.3 |
C a pointer to share that address here. This is presently |
57 |
|
|
C in an ifdef because it won't go through g77 and I'm not |
58 |
|
|
C currently sure what TAF would do with this. |
59 |
dimitri |
1.9 |
COMMON /EXF_IOPTR8/ glPtr8 |
60 |
|
|
REAL*8, POINTER :: glPtr8(:,:) |
61 |
jmc |
1.11 |
COMMON /EXF_IOPTR4/ glPtr4 |
62 |
|
|
REAL*4, POINTER :: glPtr4(:,:) |
63 |
cnh |
1.3 |
|
64 |
jmc |
1.11 |
Real*8, target :: buffer_r8(nx_in,ny_in) |
65 |
|
|
Real*4, target :: buffer_r4(nx_in,ny_in) |
66 |
|
|
#else /* ndef EXF_IREAD_USE_GLOBAL_POINTER */ |
67 |
|
|
Real*8 buffer_r8(nx_in,ny_in) |
68 |
|
|
Real*4 buffer_r4(nx_in,ny_in) |
69 |
|
|
#endif /* ndef EXF_IREAD_USE_GLOBAL_POINTER */ |
70 |
|
|
#else /* ndef EXF_INTERP_USE_DYNALLOC */ |
71 |
|
|
Real*8 buffer_r8(exf_interp_bufferSize) |
72 |
|
|
Real*4 buffer_r4(exf_interp_bufferSize) |
73 |
|
|
COMMON /EXF_INTERP_BUFFER/ buffer_r8, buffer_r4 |
74 |
|
|
INTEGER ijs |
75 |
|
|
#endif /* ndef EXF_INTERP_USE_DYNALLOC */ |
76 |
|
|
#ifdef ALLOW_USE_MPI |
77 |
|
|
INTEGER ierr |
78 |
cnh |
1.3 |
#endif |
79 |
heimbach |
1.1 |
|
80 |
jmc |
1.11 |
C-- Check for consistency: |
81 |
|
|
#ifdef EXF_INTERP_USE_DYNALLOC |
82 |
cnh |
1.3 |
#ifndef EXF_IREAD_USE_GLOBAL_POINTER |
83 |
jmc |
1.11 |
C The CPP symbol EXF_IREAD_USE_GLOBAL_POINTER must be defined for the |
84 |
|
|
C case of nThreads > 1. Stop IF it isnt. |
85 |
cnh |
1.3 |
IF ( nThreads .GT. 1 ) THEN |
86 |
jmc |
1.11 |
STOP |
87 |
cnh |
1.3 |
&'EXF_INTERP_READ: nThreads > 1 needs EXF_IREAD_USE_GLOBAL_POINTER' |
88 |
|
|
ENDIF |
89 |
|
|
#endif |
90 |
jmc |
1.11 |
#else /* ndef EXF_INTERP_USE_DYNALLOC */ |
91 |
dimitri |
1.6 |
#ifdef EXF_IREAD_USE_GLOBAL_POINTER |
92 |
jmc |
1.11 |
STOP |
93 |
|
|
&'EXF_INTERP_READ: USE_GLOBAL_POINTER needs INTERP_USE_DYNALLOC' |
94 |
dimitri |
1.6 |
#endif |
95 |
jmc |
1.11 |
IF ( nx_in*ny_in .GT. exf_interp_bufferSize ) THEN |
96 |
|
|
STOP 'EXF_INTERP_READ: exf_interp_bufferSize too small' |
97 |
|
|
ENDIF |
98 |
|
|
#endif /* ndef EXF_INTERP_USE_DYNALLOC */ |
99 |
|
|
|
100 |
|
|
C-- before starting to read, wait for everyone to finish |
101 |
|
|
_BARRIER |
102 |
heimbach |
1.1 |
|
103 |
jmc |
1.11 |
C--- read in input data |
104 |
heimbach |
1.1 |
|
105 |
jmc |
1.11 |
IF ( MASTER_CPU_IO(myThid) ) THEN |
106 |
|
|
C-- master thread of process 0, only, opens a global file |
107 |
heimbach |
1.1 |
|
108 |
jmc |
1.11 |
CALL MDSFINDUNIT( ioUnit, myThid ) |
109 |
|
|
length_of_rec=MDS_RECLEN( filePrec, nx_in*ny_in, myThid ) |
110 |
|
|
OPEN( ioUnit, file=infile, status='old', access='direct', |
111 |
|
|
& recl=length_of_rec ) |
112 |
dimitri |
1.9 |
IF ( filePrec .EQ. 32 ) THEN |
113 |
jmc |
1.11 |
#ifdef EXF_INTERP_USE_DYNALLOC |
114 |
|
|
READ(ioUnit,rec=irecord) buffer_r4 |
115 |
|
|
#else |
116 |
|
|
READ(ioUnit,rec=irecord) (buffer_r4(i),i=1,nx_in*ny_in) |
117 |
|
|
#endif |
118 |
dimitri |
1.9 |
#ifdef _BYTESWAPIO |
119 |
jmc |
1.11 |
CALL MDS_BYTESWAPR4(nx_in*ny_in,buffer_r4) |
120 |
dimitri |
1.9 |
#endif /* _BYTESWAPIO */ |
121 |
|
|
ELSE |
122 |
jmc |
1.11 |
#ifdef EXF_INTERP_USE_DYNALLOC |
123 |
|
|
READ(ioUnit,rec=irecord) buffer_r8 |
124 |
|
|
#else |
125 |
|
|
READ(ioUnit,rec=irecord) (buffer_r8(i),i=1,nx_in*ny_in) |
126 |
|
|
#endif |
127 |
dimitri |
1.9 |
#ifdef _BYTESWAPIO |
128 |
jmc |
1.11 |
CALL MDS_BYTESWAPR8(nx_in*ny_in,buffer_r8) |
129 |
dimitri |
1.9 |
#endif /* _BYTESWAPIO */ |
130 |
|
|
ENDIF |
131 |
jmc |
1.11 |
CLOSE( ioUnit ) |
132 |
|
|
C-- end if MASTER_CPU_IO |
133 |
|
|
ENDIF |
134 |
heimbach |
1.1 |
|
135 |
jmc |
1.11 |
_BEGIN_MASTER( myThid ) |
136 |
heimbach |
1.1 |
#ifdef ALLOW_USE_MPI |
137 |
jmc |
1.11 |
C-- broadcast to all processes |
138 |
|
|
IF ( useSingleCPUIO ) THEN |
139 |
|
|
IF ( filePrec .EQ. 32 ) THEN |
140 |
|
|
CALL MPI_BCAST(buffer_r4,nx_in*ny_in,MPI_REAL, |
141 |
|
|
& 0,MPI_COMM_MODEL,ierr) |
142 |
|
|
ELSE |
143 |
|
|
CALL MPI_BCAST(buffer_r8,nx_in*ny_in,MPI_DOUBLE_PRECISION, |
144 |
|
|
& 0,MPI_COMM_MODEL,ierr) |
145 |
|
|
ENDIF |
146 |
|
|
ENDIF |
147 |
heimbach |
1.1 |
#endif /* ALLOW_USE_MPI */ |
148 |
jmc |
1.11 |
|
149 |
cnh |
1.3 |
#ifdef EXF_IREAD_USE_GLOBAL_POINTER |
150 |
dimitri |
1.9 |
IF ( filePrec .EQ. 32 ) THEN |
151 |
jmc |
1.11 |
glPtr4 => buffer_r4 |
152 |
dimitri |
1.9 |
ELSE |
153 |
jmc |
1.11 |
glPtr8 => buffer_r8 |
154 |
dimitri |
1.9 |
ENDIF |
155 |
cnh |
1.3 |
#endif |
156 |
|
|
_END_MASTER( myThid ) |
157 |
|
|
_BARRIER |
158 |
dimitri |
1.9 |
|
159 |
jmc |
1.11 |
C--- Transfer buffer to "arrayin" array: |
160 |
|
|
#ifdef EXF_INTERP_USE_DYNALLOC |
161 |
cnh |
1.3 |
#ifdef EXF_IREAD_USE_GLOBAL_POINTER |
162 |
dimitri |
1.9 |
IF ( filePrec .EQ. 32 ) THEN |
163 |
jmc |
1.11 |
DO j=1,ny_in |
164 |
|
|
DO i=1,nx_in |
165 |
|
|
arrayin(i,j)=glPtr4(i,j) |
166 |
|
|
ENDDO |
167 |
|
|
ENDDO |
168 |
|
|
ELSE |
169 |
|
|
DO j=1,ny_in |
170 |
|
|
DO i=1,nx_in |
171 |
|
|
arrayin(i,j)=glPtr8(i,j) |
172 |
|
|
ENDDO |
173 |
|
|
ENDDO |
174 |
|
|
ENDIF |
175 |
|
|
#else /* ndef EXF_IREAD_USE_GLOBAL_POINTER */ |
176 |
|
|
IF ( filePrec .EQ. 32 ) THEN |
177 |
|
|
DO j=1,ny_in |
178 |
|
|
DO i=1,nx_in |
179 |
|
|
arrayin(i,j)=buffer_r4(i,j) |
180 |
|
|
ENDDO |
181 |
|
|
ENDDO |
182 |
dimitri |
1.9 |
ELSE |
183 |
jmc |
1.11 |
DO j=1,ny_in |
184 |
|
|
DO i=1,nx_in |
185 |
|
|
arrayin(i,j)=buffer_r8(i,j) |
186 |
|
|
ENDDO |
187 |
|
|
ENDDO |
188 |
dimitri |
1.9 |
ENDIF |
189 |
jmc |
1.11 |
#endif /* ndef EXF_IREAD_USE_GLOBAL_POINTER */ |
190 |
|
|
#else /* ndef EXF_INTERP_USE_DYNALLOC */ |
191 |
dimitri |
1.9 |
IF ( filePrec .EQ. 32 ) THEN |
192 |
jmc |
1.11 |
DO j=1,ny_in |
193 |
|
|
ijs = (j-1)*nx_in |
194 |
|
|
DO i=1,nx_in |
195 |
|
|
arrayin(i,j)=buffer_r4(i+ijs) |
196 |
|
|
ENDDO |
197 |
|
|
ENDDO |
198 |
dimitri |
1.9 |
ELSE |
199 |
jmc |
1.11 |
DO j=1,ny_in |
200 |
|
|
ijs = (j-1)*nx_in |
201 |
|
|
DO i=1,nx_in |
202 |
|
|
arrayin(i,j)=buffer_r8(i+ijs) |
203 |
|
|
ENDDO |
204 |
|
|
ENDDO |
205 |
dimitri |
1.9 |
ENDIF |
206 |
jmc |
1.11 |
#endif /* ndef EXF_INTERP_USE_DYNALLOC */ |
207 |
heimbach |
1.1 |
|
208 |
jmc |
1.5 |
RETURN |
209 |
heimbach |
1.1 |
END |