1 |
C $Header: /u/gcmpack/MITgcm/pkg/ptracers/ptracers_write_pickup.F,v 1.7 2008/05/08 19:50:09 jahn Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "GAD_OPTIONS.h" |
5 |
#include "PTRACERS_OPTIONS.h" |
6 |
|
7 |
CBOP |
8 |
C !ROUTINE: PTRACERS_WRITE_PICKUP |
9 |
|
10 |
C !INTERFACE: ========================================================== |
11 |
SUBROUTINE PTRACERS_WRITE_PICKUP( permCheckPoint, |
12 |
& suff, myTime, myIter, myThid ) |
13 |
|
14 |
C !DESCRIPTION: |
15 |
C Writes current state of passive tracers to a pickup file |
16 |
|
17 |
C !USES: =============================================================== |
18 |
#include "PTRACERS_MOD.h" |
19 |
IMPLICIT NONE |
20 |
#include "SIZE.h" |
21 |
#include "EEPARAMS.h" |
22 |
#include "PARAMS.h" |
23 |
#include "GAD.h" |
24 |
#include "PTRACERS_SIZE.h" |
25 |
#include "PTRACERS_PARAMS.h" |
26 |
#include "PTRACERS_RESTART.h" |
27 |
#include "PTRACERS_FIELDS.h" |
28 |
|
29 |
C !INPUT PARAMETERS: =================================================== |
30 |
C permCheckPoint :: permanent or a rolling checkpoint |
31 |
C suff :: suffix for pickup file (eg. ckptA or 0000000010) |
32 |
C myTime :: model time |
33 |
C myIter :: time-step number |
34 |
C myThid :: thread number |
35 |
LOGICAL permCheckPoint |
36 |
CHARACTER*(*) suff |
37 |
_RL myTime |
38 |
INTEGER myIter |
39 |
INTEGER myThid |
40 |
|
41 |
C !OUTPUT PARAMETERS: ================================================== |
42 |
C none |
43 |
|
44 |
#ifdef ALLOW_PTRACERS |
45 |
|
46 |
C === Functions ==== |
47 |
INTEGER ILNBLNK |
48 |
EXTERNAL ILNBLNK |
49 |
|
50 |
C !LOCAL VARIABLES: ==================================================== |
51 |
C iTracer :: tracer index |
52 |
C j :: loop index / field number |
53 |
C prec :: pickup-file precision |
54 |
C glf :: local flag for "globalFiles" |
55 |
C fn :: character buffer for creating filename |
56 |
C nWrFlds :: number of fields being written |
57 |
C listDim :: dimension of "wrFldList" local array |
58 |
C wrFldList :: list of written fields |
59 |
C msgBuf :: Informational/error message buffer |
60 |
INTEGER iTracer, j, prec, lChar, n, iRec |
61 |
LOGICAL glf |
62 |
CHARACTER*(MAX_LEN_FNAM) fn |
63 |
INTEGER listDim, nWrFlds |
64 |
PARAMETER( listDim = 3*PTRACERS_num ) |
65 |
CHARACTER*(8) wrFldList(listDim) |
66 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
67 |
CEOP |
68 |
|
69 |
#ifdef ALLOW_MNC |
70 |
IF ( PTRACERS_pickup_write_mnc ) THEN |
71 |
IF ( permCheckPoint ) THEN |
72 |
WRITE(fn,'(A)') 'pickup_ptracers' |
73 |
ELSE |
74 |
lChar = ILNBLNK(suff) |
75 |
WRITE(fn,'(2A)') 'pickup_ptracers.', suff(1:lChar) |
76 |
ENDIF |
77 |
CALL MNC_FILE_CLOSE_ALL_MATCHING(fn, myThid) |
78 |
C First ***define*** the file group name |
79 |
CALL MNC_CW_SET_UDIM(fn, 1, myThid) |
80 |
IF ( permCheckPoint ) THEN |
81 |
CALL MNC_CW_SET_CITER(fn, 3, 3, myIter, -1, myThid) |
82 |
ELSE |
83 |
CALL MNC_CW_SET_CITER(fn, 2, -1, -1, -1, myThid) |
84 |
ENDIF |
85 |
C Then set the actual unlimited dimension |
86 |
CALL MNC_CW_SET_UDIM(fn, 1, myThid) |
87 |
C The following two values should probably be for the n-1 time |
88 |
C step since we're saving the gpTrNm1 variable first |
89 |
CALL MNC_CW_RL_W_S('D',fn,0,0,'T', myTime, myThid) |
90 |
CALL MNC_CW_I_W_S('I',fn,0,0,'iter', myIter, myThid) |
91 |
DO iTracer = 1,PTRACERS_numInUse |
92 |
CALL MNC_CW_RL_W('D',fn,0,0, PTRACERS_names(iTracer), |
93 |
& gpTrNm1(1-OLx,1-OLy,1,1,1,iTracer),myThid) |
94 |
ENDDO |
95 |
CALL MNC_CW_SET_UDIM(fn, 2, myThid) |
96 |
CALL MNC_CW_RL_W_S('D',fn,0,0,'T', myTime, myThid) |
97 |
CALL MNC_CW_I_W_S('I',fn,0,0,'iter', myIter, myThid) |
98 |
DO iTracer = 1,PTRACERS_numInUse |
99 |
CALL MNC_CW_RL_W('D',fn,0,0, PTRACERS_names(iTracer), |
100 |
& pTracer(1-OLx,1-OLy,1,1,1,iTracer),myThid) |
101 |
ENDDO |
102 |
ENDIF |
103 |
IF ( useMNC .AND. PTRACERS_pickup_write_mnc ) THEN |
104 |
DO iTracer = 1, PTRACERS_numInUse |
105 |
IF ( PTRACERS_SOM_Advection(iTracer) ) THEN |
106 |
WRITE(msgBuf,'(3A)')'PTRACERS_WRITE_PICKUP: MNC not yet coded', |
107 |
& ' for SOM advection', |
108 |
& ' => write bin file instead' |
109 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
110 |
& SQUEEZE_RIGHT, myThid) |
111 |
ENDIF |
112 |
ENDDO |
113 |
ENDIF |
114 |
#endif /* ALLOW_MNC */ |
115 |
|
116 |
IF ( PTRACERS_pickup_write_mdsio ) THEN |
117 |
|
118 |
lChar = ILNBLNK(suff) |
119 |
IF ( lChar.EQ.0 ) THEN |
120 |
WRITE(fn,'(2A)') 'pickup_ptracers' |
121 |
ELSE |
122 |
WRITE(fn,'(2A)') 'pickup_ptracers.',suff(1:lChar) |
123 |
ENDIF |
124 |
prec = precFloat64 |
125 |
|
126 |
C Firstly, write ptracer fields as consecutive records, |
127 |
C one tracer after the other, for all tracers "InUse". |
128 |
|
129 |
j = 0 |
130 |
C record number < 0 : a hack not to write meta files now: |
131 |
DO iTracer = 1, PTRACERS_numInUse |
132 |
j = j + 1 |
133 |
CALL WRITE_REC_3D_RL( fn, prec, Nr, |
134 |
& pTracer(1-Olx,1-Oly,1,1,1,iTracer), |
135 |
& -j, myIter, myThid ) |
136 |
IF (j.LE.listDim) |
137 |
& wrFldList(j) = 'pTr'//PTRACERS_ioLabel(iTracer)//' ' |
138 |
ENDDO |
139 |
|
140 |
C Then write ptracer tendencies (if this tracer is using AB time-stepping) |
141 |
DO iTracer = 1, PTRACERS_numInUse |
142 |
IF ( PTRACERS_AdamsBashGtr(iTracer) ) THEN |
143 |
j = j + 1 |
144 |
CALL WRITE_REC_3D_RL( fn, prec, Nr, |
145 |
& gpTrNm1(1-Olx,1-Oly,1,1,1,iTracer), |
146 |
& -j, myIter, myThid ) |
147 |
IF (j.LE.listDim) |
148 |
& wrFldList(j) = 'gPtr'//PTRACERS_ioLabel(iTracer)//'m1' |
149 |
ENDIF |
150 |
|
151 |
ENDDO |
152 |
|
153 |
C-------------------------- |
154 |
nWrFlds = j |
155 |
IF ( nWrFlds.GT.listDim ) THEN |
156 |
WRITE(msgBuf,'(2A,I5,A)') 'PTRACERS_WRITE_PICKUP: ', |
157 |
& 'trying to write ',nWrFlds,' fields' |
158 |
CALL PRINT_ERROR( msgBuf, myThid ) |
159 |
WRITE(msgBuf,'(2A,I5,A)') 'PTRACERS_WRITE_PICKUP: ', |
160 |
& 'field-list dimension (listDim=',listDim,') too small' |
161 |
CALL PRINT_ERROR( msgBuf, myThid ) |
162 |
STOP 'ABNORMAL END: S/R PTRACERS_WRITE_PICKUP (list-size Pb)' |
163 |
ENDIF |
164 |
#ifdef ALLOW_MDSIO |
165 |
C uses this specific S/R to write (with more informations) only meta files |
166 |
glf = globalFiles |
167 |
CALL MDS_WR_METAFILES( fn, prec, glf, .FALSE., |
168 |
& 0, 0, Nr, ' ', |
169 |
& nWrFlds, wrFldList, |
170 |
& 1, myTime, |
171 |
& j, myIter, myThid ) |
172 |
#endif /* ALLOW_MDSIO */ |
173 |
C-------------------------- |
174 |
#ifdef PTRACERS_ALLOW_DYN_STATE |
175 |
C write pickup for 2nd-order moment fields |
176 |
C we write a separate file for each Ptracer that uses SOM advection |
177 |
DO iTracer = 1, PTRACERS_numInUse |
178 |
IF ( PTRACERS_SOM_Advection(iTracer) ) THEN |
179 |
IF ( lChar.EQ.0 ) THEN |
180 |
WRITE(fn,'(2A)') 'pickup_somTRAC',PTRACERS_ioLabel(iTracer) |
181 |
ELSE |
182 |
WRITE(fn,'(4A)') 'pickup_somTRAC',PTRACERS_ioLabel(iTracer), |
183 |
& '.',suff(1:lChar) |
184 |
ENDIF |
185 |
WRITE(msgBuf,'(A,I3,A)')'PTRACERS_WRITE_PICKUP: iTracer = ', |
186 |
& iTracer, |
187 |
& ' : writing 2nd-order moments to file ' |
188 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
189 |
& SQUEEZE_RIGHT, myThid) |
190 |
CALL PRINT_MESSAGE( fn, standardMessageUnit, |
191 |
& SQUEEZE_RIGHT, myThid) |
192 |
prec = precFloat64 |
193 |
C Write 2nd Order moments as consecutive records |
194 |
DO n=1,nSOM |
195 |
iRec = n |
196 |
CALL WRITE_REC_3D_RL( fn, prec, Nr, |
197 |
I _Ptracers_som(1-Olx,1-Oly,1,1,1,n,iTracer), |
198 |
I iRec, myIter, myThid ) |
199 |
ENDDO |
200 |
ENDIF |
201 |
ENDDO |
202 |
#endif /* PTRACERS_ALLOW_DYN_STATE */ |
203 |
C-------------------------- |
204 |
ENDIF |
205 |
|
206 |
#endif /* ALLOW_PTRACERS */ |
207 |
|
208 |
RETURN |
209 |
END |