1 |
C $Header: $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "MDSIO_OPTIONS.h" |
5 |
|
6 |
SUBROUTINE MDSWRITEVECTOR( |
7 |
I fName, |
8 |
I filePrec, |
9 |
I globalfile, |
10 |
I arrType, |
11 |
I narr, |
12 |
I arr, |
13 |
I bi, |
14 |
I bj, |
15 |
I irecord, |
16 |
I myIter, |
17 |
I myThid ) |
18 |
C Arguments: |
19 |
C |
20 |
C fName string base name for file to written |
21 |
C filePrec integer number of bits per word in file (32 or 64) |
22 |
C globalFile logical selects between writing a global or tiled file |
23 |
C arrType char(2) declaration of "arr": either "RS" or "RL" |
24 |
C narr integer size of third dimension: normally either 1 or Nr |
25 |
C arr RS/RL array to write, arr(narr) |
26 |
ce bi integer x tile index |
27 |
ce bj integer y tile index |
28 |
C irecord integer record number to read |
29 |
C myIter integer time step number |
30 |
C myThid integer thread identifier |
31 |
C |
32 |
C Created: 03/26/99 eckert@mit.edu |
33 |
C Modified: 03/29/99 adcroft@mit.edu + eckert@mit.edu |
34 |
C Fixed to work work with _RS and _RL declarations |
35 |
C Modified: 07/27/99 eckert@mit.edu |
36 |
C Customized for state estimation (--> active_file_control.F) |
37 |
C Changed: 05/31/00 heimbach@mit.edu |
38 |
C open(dUnit, ..., status='old', ... -> status='unknown' |
39 |
|
40 |
implicit none |
41 |
C Global variables / common blocks |
42 |
#include "SIZE.h" |
43 |
#include "EEPARAMS.h" |
44 |
#include "PARAMS.h" |
45 |
|
46 |
C Routine arguments |
47 |
character*(*) fName |
48 |
integer filePrec |
49 |
logical globalfile |
50 |
character*(2) arrType |
51 |
integer narr |
52 |
Real arr(narr) |
53 |
integer irecord |
54 |
integer myIter |
55 |
integer myThid |
56 |
ce |
57 |
integer bi,bj |
58 |
ce |
59 |
|
60 |
C Functions |
61 |
integer ILNBLNK |
62 |
integer MDS_RECLEN |
63 |
C Local variables |
64 |
character*(80) dataFName,metaFName |
65 |
integer iG,jG,irec,dUnit,IL |
66 |
logical fileIsOpen |
67 |
integer dimList(3,3),ndims |
68 |
integer length_of_rec |
69 |
character*(max_len_mbuf) msgbuf |
70 |
C ------------------------------------------------------------------ |
71 |
|
72 |
C Only do I/O if I am the master thread |
73 |
_BEGIN_MASTER( myThid ) |
74 |
|
75 |
C Record number must be >= 1 |
76 |
if (irecord .LT. 1) then |
77 |
write(msgbuf,'(a,i9.8)') |
78 |
& ' MDSWRITEVECTOR: argument irecord = ',irecord |
79 |
call print_message( msgbuf, standardmessageunit, |
80 |
& SQUEEZE_RIGHT , mythid) |
81 |
write(msgbuf,'(a)') |
82 |
& ' MDSWRITEVECTOR: invalid value for irecord' |
83 |
call print_error( msgbuf, mythid ) |
84 |
stop 'ABNORMAL END: S/R MDSWRITEVECTOR' |
85 |
endif |
86 |
|
87 |
C Assume nothing |
88 |
fileIsOpen = .FALSE. |
89 |
IL=ILNBLNK( fName ) |
90 |
|
91 |
C Assign a free unit number as the I/O channel for this routine |
92 |
call MDSFINDUNIT( dUnit, mythid ) |
93 |
|
94 |
C If we are writing to a global file then we open it here |
95 |
if (globalFile) then |
96 |
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
97 |
if (irecord .EQ. 1) then |
98 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
99 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
100 |
& access='direct', recl=length_of_rec ) |
101 |
fileIsOpen=.TRUE. |
102 |
else |
103 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
104 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
105 |
& access='direct', recl=length_of_rec ) |
106 |
fileIsOpen=.TRUE. |
107 |
endif |
108 |
endif |
109 |
|
110 |
C Loop over all tiles |
111 |
ce do bj=1,nSy |
112 |
ce do bi=1,nSx |
113 |
C If we are writing to a tiled MDS file then we open each one here |
114 |
if (.NOT. globalFile) then |
115 |
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
116 |
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
117 |
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
118 |
& fName(1:IL),'.',iG,'.',jG,'.data' |
119 |
if (irecord .EQ. 1) then |
120 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
121 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
122 |
& access='direct', recl=length_of_rec ) |
123 |
fileIsOpen=.TRUE. |
124 |
else |
125 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
126 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
127 |
& access='direct', recl=length_of_rec ) |
128 |
fileIsOpen=.TRUE. |
129 |
endif |
130 |
endif |
131 |
if (fileIsOpen) then |
132 |
if (globalFile) then |
133 |
iG = myXGlobalLo-1+(bi-1)*sNx |
134 |
jG = myYGlobalLo-1+(bj-1)*sNy |
135 |
irec = 1 + int(iG/sNx) + (jG/sNy)*nSx*nPx + |
136 |
& (irecord-1)*nSx*nPx*nSy*nPy |
137 |
else |
138 |
iG = 0 |
139 |
jG = 0 |
140 |
irec = irecord |
141 |
endif |
142 |
if (filePrec .eq. precFloat32) then |
143 |
call MDS_WRITE_RS_VEC( dUnit, irec, narr, arr, myThid ) |
144 |
elseif (filePrec .eq. precFloat64) then |
145 |
call MDS_WRITE_RL_VEC( dUnit, irec, narr, arr, myThid ) |
146 |
else |
147 |
write(msgbuf,'(a)') |
148 |
& ' MDSWRITEVECTOR: illegal value for filePrec' |
149 |
call print_error( msgbuf, mythid ) |
150 |
stop 'ABNORMAL END: S/R MDSWRITEVECTOR' |
151 |
endif |
152 |
else |
153 |
write(msgbuf,'(a)') |
154 |
& ' MDSWRITEVECTOR: I should never get to this point' |
155 |
call print_error( msgbuf, mythid ) |
156 |
stop 'ABNORMAL END: S/R MDSWRITEVECTOR' |
157 |
endif |
158 |
C If we were writing to a tiled MDS file then we close it here |
159 |
if (fileIsOpen .AND. (.NOT. globalFile)) then |
160 |
close( dUnit ) |
161 |
fileIsOpen = .FALSE. |
162 |
endif |
163 |
C Create meta-file for each tile file |
164 |
if (.NOT. globalFile) then |
165 |
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
166 |
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
167 |
write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)') |
168 |
& fName(1:IL),'.',iG,'.',jG,'.meta' |
169 |
dimList(1,1) = nPx*nSx*narr |
170 |
dimList(2,1) = ((myXGlobalLo-1)/sNx + (bi-1))*narr + 1 |
171 |
dimList(3,1) = ((myXGlobalLo-1)/sNx + bi )*narr |
172 |
dimList(1,2) = nPy*nSy |
173 |
dimList(2,2) = (myYGlobalLo-1)/sNy + bj |
174 |
dimList(3,2) = (myYGlobalLo-1)/sNy + bj |
175 |
dimList(1,3) = 1 |
176 |
dimList(2,3) = 1 |
177 |
dimList(3,3) = 1 |
178 |
ndims=1 |
179 |
call MDSWRITEMETA( metaFName, dataFName, |
180 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
181 |
endif |
182 |
C End of bi,bj loops |
183 |
ce enddo |
184 |
ce enddo |
185 |
|
186 |
C If global file was opened then close it |
187 |
if (fileIsOpen .AND. globalFile) then |
188 |
close( dUnit ) |
189 |
fileIsOpen = .FALSE. |
190 |
endif |
191 |
|
192 |
C Create meta-file for global file |
193 |
if (globalFile) then |
194 |
write(metaFName(1:80),'(2a)') fName(1:IL),'.meta' |
195 |
dimList(1,1) = nPx*nSx*narr |
196 |
dimList(2,1) = 1 |
197 |
dimList(3,1) = nPx*nSx*narr |
198 |
dimList(1,2) = nPy*nSy |
199 |
dimList(2,2) = 1 |
200 |
dimList(3,2) = nPy*nSy |
201 |
dimList(1,3) = 1 |
202 |
dimList(2,3) = 1 |
203 |
dimList(3,3) = 1 |
204 |
ndims=1 |
205 |
call MDSWRITEMETA( metaFName, dataFName, |
206 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
207 |
endif |
208 |
|
209 |
_END_MASTER( myThid ) |
210 |
C ------------------------------------------------------------------ |
211 |
return |
212 |
end |