12 |
I globalFile, |
I globalFile, |
13 |
I useCurrentDir, |
I useCurrentDir, |
14 |
I arrType, |
I arrType, |
15 |
I zSize,nNz, |
I kSize,kLo,kHi, |
16 |
I arr, |
I arr, |
17 |
I jrecord, |
I jrecord, |
18 |
I myIter, |
I myIter, |
27 |
C useCurrentDir(logic):: always write to the current directory (even if |
C useCurrentDir(logic):: always write to the current directory (even if |
28 |
C "mdsioLocalDir" is set) |
C "mdsioLocalDir" is set) |
29 |
C arrType (char(2)) :: declaration of "arr": either "RS" or "RL" |
C arrType (char(2)) :: declaration of "arr": either "RS" or "RL" |
30 |
C zSize (integer) :: size of third dimension: normally either 1 or Nr |
C kSize (integer) :: size of third dimension: normally either 1 or Nr |
31 |
C nNz (integer) :: number of vertical levels to write |
C kLo (integer) :: 1rst vertical level (of array "arr") to write |
32 |
C arr ( RS/RL ) :: array to write, arr(:,:,zSize,:,:) |
C kHi (integer) :: last vertical level (of array "arr") to write |
33 |
|
C arr ( RS/RL ) :: array to write, arr(:,:,kSize,:,:) |
34 |
C irecord (integer) :: record number to write |
C irecord (integer) :: record number to write |
35 |
C myIter (integer) :: time step number |
C myIter (integer) :: time step number |
36 |
C myThid (integer) :: thread identifier |
C myThid (integer) :: thread identifier |
37 |
C |
C |
38 |
C MDS_WRITE_FIELD creates either a file of the form "fName.data" and |
C MDS_WRITE_FIELD creates either a file of the form "fName.data" and |
39 |
C "fName.meta" if the logical flag "globalFile" is set true. Otherwise |
C "fName.meta" if the logical flag "globalFile" is set true. Otherwise |
40 |
C it creates MDS tiled files of the form "fName.xxx.yyy.data" and |
C it creates MDS tiled files of the form "fName.xxx.yyy.data" and |
41 |
C "fName.xxx.yyy.meta". If jrecord > 0, a meta-file is created. |
C "fName.xxx.yyy.meta". If jrecord > 0, a meta-file is created. |
42 |
C Currently, the meta-files are not read because it is difficult |
C Currently, the meta-files are not read because it is difficult |
43 |
C to parse files in fortran. We should read meta information before |
C to parse files in fortran. We should read meta information before |
44 |
C adding records to an existing multi-record file. |
C adding records to an existing multi-record file. |
45 |
C The precision of the file is decsribed by filePrec, set either |
C The precision of the file is decsribed by filePrec, set either |
46 |
C to floatPrec32 or floatPrec64. The precision or declaration of |
C to floatPrec32 or floatPrec64. The precision or declaration of |
47 |
C the array argument must be consistently described by the char*(2) |
C the array argument must be consistently described by the char*(2) |
48 |
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
C string arrType, either "RS" or "RL". |
49 |
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
C (kSize,kLo,kHi) allows for both 2-D and 3-D arrays to be handled, with |
50 |
C nNz=Nr implies a 3-D model field. irecord=|jrecord| is the record number |
C the option to only write a sub-set of consecutive vertical levels (from |
51 |
C to be written and must be >= 1. NOTE: It is currently assumed that |
C kLo to kHi); (kSize,kLo,kHi)=(1,1,1) implies a 2-D model field and |
52 |
C the highest record number in the file was the last record written. |
C (kSize,kLo,kHi)=(Nr,1,Nr) implies a 3-D model field. |
53 |
C Nor is there a consistency check between the routine arguments and file. |
C irecord=|jrecord| is the record number to be written and must be >= 1. |
54 |
C ie. if you write record 2 after record 4 the meta information |
C NOTE: It is currently assumed that the highest record number in the file |
55 |
C will record the number of records to be 2. This, again, is because |
C was the last record written. Nor is there a consistency check between the |
56 |
C we have read the meta information. To be fixed. |
C routine arguments and file, i.e., if you write record 2 after record 4 |
57 |
|
C the meta information will record the number of records to be 2. This, |
58 |
|
C again, is because we have read the meta information. To be fixed. |
59 |
C |
C |
60 |
C Created: 03/16/99 adcroft@mit.edu |
C Created: 03/16/99 adcroft@mit.edu |
61 |
C Changed: 01/06/02 menemenlis@jpl.nasa.gov |
C Changed: 01/06/02 menemenlis@jpl.nasa.gov |
83 |
LOGICAL globalFile |
LOGICAL globalFile |
84 |
LOGICAL useCurrentDir |
LOGICAL useCurrentDir |
85 |
CHARACTER*(2) arrType |
CHARACTER*(2) arrType |
86 |
INTEGER zSize, nNz |
INTEGER kSize, kLo, kHi |
87 |
cph( |
cph( |
88 |
cph Real arr(*) |
cph Real arr(*) |
89 |
_RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,zSize,nSx,nSy) |
_RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,kSize,nSx,nSy) |
90 |
cph) |
cph) |
91 |
INTEGER jrecord |
INTEGER jrecord |
92 |
INTEGER myIter |
INTEGER myIter |
108 |
LOGICAL iAmDoingIO |
LOGICAL iAmDoingIO |
109 |
LOGICAL writeMetaF |
LOGICAL writeMetaF |
110 |
INTEGER irecord |
INTEGER irecord |
111 |
INTEGER iG,jG,irec,bi,bj,i,j,k,dUnit,IL,pIL |
INTEGER iG,jG,bi,bj,i,j,k,nNz |
112 |
|
INTEGER irec,dUnit,IL,pIL |
113 |
INTEGER dimList(3,3), nDims, map2gl(2) |
INTEGER dimList(3,3), nDims, map2gl(2) |
114 |
INTEGER iGjLoc, jGjLoc |
INTEGER iGjLoc, jGjLoc |
115 |
INTEGER x_size,y_size,length_of_rec |
INTEGER x_size,y_size,length_of_rec |
142 |
fileIsOpen = .FALSE. |
fileIsOpen = .FALSE. |
143 |
IL = ILNBLNK( fName ) |
IL = ILNBLNK( fName ) |
144 |
pIL = ILNBLNK( mdsioLocalDir ) |
pIL = ILNBLNK( mdsioLocalDir ) |
145 |
|
nNz = 1 + kHi - kLo |
146 |
irecord = ABS(jrecord) |
irecord = ABS(jrecord) |
147 |
writeMetaF = jrecord.GT.0 |
writeMetaF = jrecord.GT.0 |
148 |
|
|
163 |
CALL PRINT_ERROR( msgBuf, myThid ) |
CALL PRINT_ERROR( msgBuf, myThid ) |
164 |
STOP 'ABNORMAL END: S/R MDS_WRITE_FIELD' |
STOP 'ABNORMAL END: S/R MDS_WRITE_FIELD' |
165 |
ENDIF |
ENDIF |
166 |
|
C check for valid sub-set of levels: |
167 |
|
IF ( kLo.LT.1 .OR. kHi.GT.kSize ) THEN |
168 |
|
WRITE(msgBuf,'(3(A,I6))') |
169 |
|
& ' MDS_WRITE_FIELD: arguments kSize=', kSize, |
170 |
|
& ' , kLo=', kLo, ' , kHi=', kHi |
171 |
|
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
172 |
|
& SQUEEZE_RIGHT , myThid) |
173 |
|
WRITE(msgBuf,'(A)') |
174 |
|
& ' MDS_WRITE_FIELD: invalid sub-set of levels' |
175 |
|
CALL PRINT_ERROR( msgBuf, myThid ) |
176 |
|
STOP 'ABNORMAL END: S/R MDS_WRITE_FIELD' |
177 |
|
ENDIF |
178 |
|
|
179 |
C Assign special directory |
C Assign special directory |
180 |
IF ( useCurrentDir .OR. pIL.EQ.0 ) THEN |
IF ( useCurrentDir .OR. pIL.EQ.0 ) THEN |
208 |
ENDIF |
ENDIF |
209 |
|
|
210 |
C Gather array and WRITE it to file, one vertical level at a time |
C Gather array and WRITE it to file, one vertical level at a time |
211 |
DO k=1,nNz |
DO k=kLo,kHi |
212 |
C- copy from arr(level=k) to 2-D "local": |
C- copy from arr(level=k) to 2-D "local": |
213 |
IF ( arrType.EQ.'RS' ) THEN |
IF ( arrType.EQ.'RS' ) THEN |
214 |
CALL MDS_PASStoRS(sharedLocalBuf,arr,k,zSize,.FALSE.,myThid) |
CALL MDS_PASStoRS(sharedLocalBuf,arr,k,kSize,.FALSE.,myThid) |
215 |
ELSEIF ( arrType.EQ.'RL' ) THEN |
ELSEIF ( arrType.EQ.'RL' ) THEN |
216 |
CALL MDS_PASStoRL(sharedLocalBuf,arr,k,zSize,.FALSE.,myThid) |
CALL MDS_PASStoRL(sharedLocalBuf,arr,k,kSize,.FALSE.,myThid) |
217 |
ELSE |
ELSE |
218 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
219 |
& ' MDS_WRITE_FIELD: illegal value for arrType' |
& ' MDS_WRITE_FIELD: illegal value for arrType' |
304 |
ENDIF |
ENDIF |
305 |
#endif /* defined(ALLOW_EXCH2) && !defined(MISSING_TILE_IO) */ |
#endif /* defined(ALLOW_EXCH2) && !defined(MISSING_TILE_IO) */ |
306 |
|
|
307 |
irec=k+nNz*(irecord-1) |
irec=k+1-kLo+nNz*(irecord-1) |
308 |
IF (filePrec .EQ. precFloat32) THEN |
IF (filePrec .EQ. precFloat32) THEN |
309 |
#ifdef _BYTESWAPIO |
#ifdef _BYTESWAPIO |
310 |
CALL MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 ) |
CALL MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 ) |
404 |
#ifdef ALLOW_EXCH2 |
#ifdef ALLOW_EXCH2 |
405 |
irec = 1 + ( tGx-1 + (j-1)*iGjLoc )/tNx |
irec = 1 + ( tGx-1 + (j-1)*iGjLoc )/tNx |
406 |
& + ( tGy-1 + (j-1)*jGjLoc )*exch2_domain_nxt |
& + ( tGy-1 + (j-1)*jGjLoc )*exch2_domain_nxt |
407 |
& + ( k-1 + (irecord-1)*nNz |
& + ( k-kLo + (irecord-1)*nNz |
408 |
& )*y_size*exch2_domain_nxt |
& )*y_size*exch2_domain_nxt |
409 |
#else /* ALLOW_EXCH2 */ |
#else /* ALLOW_EXCH2 */ |
410 |
iG = myXGlobalLo-1 + (bi-1)*sNx |
iG = myXGlobalLo-1 + (bi-1)*sNx |
411 |
jG = myYGlobalLo-1 + (bj-1)*sNy |
jG = myYGlobalLo-1 + (bj-1)*sNy |
412 |
irec= 1 + INT(iG/sNx) + nSx*nPx*(jG+j-1) |
irec= 1 + INT(iG/sNx) + nSx*nPx*(jG+j-1) |
413 |
& + nSx*nPx*Ny*(k-1) |
& + nSx*nPx*Ny*(k-kLo) |
414 |
& + nSx*nPx*Ny*nNz*(irecord-1) |
& + nSx*nPx*Ny*nNz*(irecord-1) |
415 |
#endif /* ALLOW_EXCH2 */ |
#endif /* ALLOW_EXCH2 */ |
416 |
ELSE |
ELSE |
417 |
irec=j + sNy*(k-1) + sNy*nNz*(irecord-1) |
irec=j + sNy*(k-kLo) + sNy*nNz*(irecord-1) |
418 |
ENDIF |
ENDIF |
419 |
IF (filePrec .EQ. precFloat32) THEN |
IF (filePrec .EQ. precFloat32) THEN |
420 |
IF (arrType .EQ. 'RS') THEN |
IF (arrType .EQ. 'RS') THEN |
421 |
CALL MDS_SEG4toRS( j,bi,bj,k,zSize, r4seg,.FALSE.,arr ) |
CALL MDS_SEG4toRS( j,bi,bj,k,kSize, r4seg,.FALSE.,arr ) |
422 |
ELSEIF (arrType .EQ. 'RL') THEN |
ELSEIF (arrType .EQ. 'RL') THEN |
423 |
CALL MDS_SEG4toRL( j,bi,bj,k,zSize, r4seg,.FALSE.,arr ) |
CALL MDS_SEG4toRL( j,bi,bj,k,kSize, r4seg,.FALSE.,arr ) |
424 |
ELSE |
ELSE |
425 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
426 |
& ' MDS_WRITE_FIELD: illegal value for arrType' |
& ' MDS_WRITE_FIELD: illegal value for arrType' |
433 |
WRITE(dUnit,rec=irec) r4seg |
WRITE(dUnit,rec=irec) r4seg |
434 |
ELSEIF (filePrec .EQ. precFloat64) THEN |
ELSEIF (filePrec .EQ. precFloat64) THEN |
435 |
IF (arrType .EQ. 'RS') THEN |
IF (arrType .EQ. 'RS') THEN |
436 |
CALL MDS_SEG8toRS( j,bi,bj,k,zSize, r8seg,.FALSE.,arr ) |
CALL MDS_SEG8toRS( j,bi,bj,k,kSize, r8seg,.FALSE.,arr ) |
437 |
ELSEIF (arrType .EQ. 'RL') THEN |
ELSEIF (arrType .EQ. 'RL') THEN |
438 |
CALL MDS_SEG8toRL( j,bi,bj,k,zSize, r8seg,.FALSE.,arr ) |
CALL MDS_SEG8toRL( j,bi,bj,k,kSize, r8seg,.FALSE.,arr ) |
439 |
ELSE |
ELSE |
440 |
WRITE(msgBuf,'(A)') |
WRITE(msgBuf,'(A)') |
441 |
& ' MDS_WRITE_FIELD: illegal value for arrType' |
& ' MDS_WRITE_FIELD: illegal value for arrType' |