1 |
C $Header: /u/u3/gcmpack/MITgcm/pkg/sbo/sbo_writevector.F,v 1.2.4.1 2003/10/02 18:18:33 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "SBO_OPTIONS.h" |
5 |
|
6 |
#undef SAFE_IO |
7 |
|
8 |
#ifdef SAFE_IO |
9 |
#define _NEW_STATUS 'new' |
10 |
#else |
11 |
#define _NEW_STATUS 'unknown' |
12 |
#endif |
13 |
|
14 |
#ifdef ALLOW_AUTODIFF_TAMC |
15 |
#define _OLD_STATUS 'unknown' |
16 |
#else |
17 |
#define _OLD_STATUS 'old' |
18 |
#endif |
19 |
|
20 |
SUBROUTINE SBO_WRITEVECTOR( |
21 |
I fName, |
22 |
I narr, |
23 |
I arr, |
24 |
I irecord, |
25 |
I myIter, |
26 |
I myThid ) |
27 |
C /==========================================================\ |
28 |
C | SUBROUTINE SBO_WRITEVECTOR | |
29 |
C | o Routine to write a vector to a direct access file. | |
30 |
C |==========================================================| |
31 |
C | This is a rewrite of MDSWRITEVECTOR that outputs a | |
32 |
C | single Real*8 vector from the master process and thread. | |
33 |
C \==========================================================/ |
34 |
IMPLICIT NONE |
35 |
|
36 |
C === Global variables === |
37 |
#include "SIZE.h" |
38 |
#include "EEPARAMS.h" |
39 |
#include "PARAMS.h" |
40 |
|
41 |
C == Routine arguments == |
42 |
C |
43 |
C fName string base name for file to written |
44 |
C narr integer size of vector dimension |
45 |
C arr Real array to write, arr(narr) |
46 |
C irecord integer record number to read |
47 |
C myIter integer time step number |
48 |
C myThid integer thread identifier |
49 |
|
50 |
C Routine arguments |
51 |
character*(*) fName |
52 |
integer narr |
53 |
Real*8 arr(narr) |
54 |
integer irecord |
55 |
integer myIter |
56 |
integer myThid |
57 |
|
58 |
#ifdef ALLOW_SBO |
59 |
|
60 |
C Functions |
61 |
integer ILNBLNK |
62 |
integer MDS_RECLEN |
63 |
|
64 |
C Local variables |
65 |
C filePrec integer number of bits per word in file (64) |
66 |
integer filePrec / 64 / |
67 |
character*(80) dataFName,metaFName |
68 |
integer dUnit,IL |
69 |
logical fileIsOpen |
70 |
integer dimList(3,3),ndims |
71 |
integer length_of_rec |
72 |
character*(max_len_mbuf) msgbuf |
73 |
|
74 |
C Only do I/O if I am the master process |
75 |
IF( myProcId .EQ. 0 ) THEN |
76 |
|
77 |
C Only do I/O if I am the master thread |
78 |
_BEGIN_MASTER( myThid ) |
79 |
|
80 |
C Record number must be >= 1 |
81 |
if (irecord .LT. 1) then |
82 |
write(msgbuf,'(a,i9.8)') |
83 |
& ' SBO_WRITEVECTOR: argument irecord = ',irecord |
84 |
call print_message( msgbuf, standardmessageunit, |
85 |
& SQUEEZE_RIGHT , mythid) |
86 |
write(msgbuf,'(a)') |
87 |
& ' SBO_WRITEVECTOR: invalid value for irecord' |
88 |
call print_error( msgbuf, mythid ) |
89 |
stop 'ABNORMAL END: S/R SBO_WRITEVECTOR' |
90 |
endif |
91 |
|
92 |
C Assume nothing |
93 |
fileIsOpen = .FALSE. |
94 |
IL=ILNBLNK( fName ) |
95 |
|
96 |
C Assign a free unit number as the I/O channel for this routine |
97 |
call MDSFINDUNIT( dUnit, mythid ) |
98 |
|
99 |
C Open file |
100 |
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
101 |
if (irecord .EQ. 1) then |
102 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
103 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
104 |
& access='direct', recl=length_of_rec ) |
105 |
fileIsOpen=.TRUE. |
106 |
else |
107 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
108 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
109 |
& access='direct', recl=length_of_rec ) |
110 |
fileIsOpen=.TRUE. |
111 |
endif |
112 |
|
113 |
C Write record |
114 |
if (fileIsOpen) then |
115 |
write(msgbuf,'(a,i9.8,2x,i9.8)') |
116 |
& ' SBO_WRITEVECTOR: irec = ',irecord,narr |
117 |
call print_message( msgbuf, standardmessageunit, |
118 |
& SQUEEZE_RIGHT , mythid) |
119 |
write(dUnit,rec=irecord) arr |
120 |
else |
121 |
write(msgbuf,'(a)') |
122 |
& ' SBO_WRITEVECTOR: I should never get to this point' |
123 |
call print_error( msgbuf, mythid ) |
124 |
stop 'ABNORMAL END: S/R SBO_WRITEVECTOR' |
125 |
endif |
126 |
|
127 |
C Close file |
128 |
if (fileIsOpen) then |
129 |
close( dUnit ) |
130 |
fileIsOpen = .FALSE. |
131 |
endif |
132 |
|
133 |
C Create meta-file |
134 |
write(metaFName(1:80),'(2a)') fName(1:IL),'.meta' |
135 |
dimList(1,1) = narr |
136 |
dimList(2,1) = 1 |
137 |
dimList(3,1) = narr |
138 |
dimList(1,2) = 1 |
139 |
dimList(2,2) = 1 |
140 |
dimList(3,2) = 1 |
141 |
dimList(1,3) = 1 |
142 |
dimList(2,3) = 1 |
143 |
dimList(3,3) = 1 |
144 |
ndims=1 |
145 |
call MDSWRITEMETA( metaFName, dataFName, |
146 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
147 |
|
148 |
_END_MASTER( myThid ) |
149 |
|
150 |
ENDIF |
151 |
|
152 |
#endif /* ALLOW_SBO */ |
153 |
|
154 |
return |
155 |
end |