Back to home page

MITgcm

 
 

    


File indexing completed on 2023-08-03 05:10:22 UTC

view on githubraw file Latest commit 57622776 on 2023-08-02 18:02:22 UTC
9c019881ee Jean*0001 #include "MDSIO_OPTIONS.h"
                0002 
                0003 C--  File mdsio_read_section.F: Routines to handle mid-level I/O interface.
                0004 C--   Contents
                0005 C--   o MDS_WRITE_SEC_XZ
                0006 C--   o MDS_WRITE_SEC_YZ
                0007 
                0008 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
                0009 
                0010 CBOP
                0011 C !ROUTINE: MDS_WRITE_SEC_XZ
                0012 C !INTERFACE:
                0013       SUBROUTINE MDS_WRITE_SEC_XZ(
                0014      I   fName,
                0015      I   filePrec,
                0016      I   globalFile,
                0017      I   useCurrentDir,
                0018      I   arrType,
57622776fd Jean*0019      I   kSize, kLo, kHi,
9c019881ee Jean*0020      I   fldRL, fldRS,
                0021      I   irecord,
                0022      I   myIter,
                0023      I   myThid )
                0024 
                0025 C !DESCRIPTION
                0026 C Arguments:
                0027 C
                0028 C fName       string  :: base name for file to read
                0029 C filePrec    integer :: number of bits per word in file (32 or 64)
                0030 C globalFile  logical :: selects between writing a global or tiled file
                0031 C useCurrentDir logic :: always write to the current directory (even if
                0032 C                        "mdsioLocalDir" is set)
3daafce20b Jean*0033 C arrType     char(2) :: which array (fldRL/RS) to write, either "RL" or "RS"
57622776fd Jean*0034 C kSize       integer :: size of second dimension: normally either 1 or Nr
                0035 C kLo         integer :: 1rst vertical level (of array fldRL/RS) to write
                0036 C kHi         integer :: last vertical level (of array fldRL/RS) to write
9c019881ee Jean*0037 C fldRL         RL    :: array to write if arrType="RL", fldRL(:,kSize,:,:)
                0038 C fldRS         RS    :: array to write if arrType="RS", fldRS(:,kSize,:,:)
                0039 C irecord     integer :: record number to read
                0040 C myIter      integer :: time step number
                0041 C myThid      integer :: thread identifier
                0042 C
                0043 C MDS_WRITE_SEC_XZ creates either a file of the form "fName.data"
                0044 C if the logical flag "globalFile" is set true. Otherwise
                0045 C it creates MDS tiled files of the form "fName.xxx.yyy.data".
                0046 C The precision of the file is decsribed by filePrec, set either
                0047 C  to floatPrec32 or floatPrec64. The char*(2) string arrType, either "RL"
                0048 C  or "RS", selects which array is written, either fldRL or fldRS.
                0049 C This routine writes vertical slices (X-Z) including overlap regions.
                0050 C irecord is the record number to be read and must be >= 1.
                0051 C NOTE: It is currently assumed that
                0052 C the highest record number in the file was the last record written.
                0053 C
                0054 C Modified: 06/02/00 spk@ocean.mit.edu
                0055 CEOP
                0056 
                0057 C !USES:
                0058       IMPLICIT NONE
                0059 C Global variables / common blocks
                0060 #include "SIZE.h"
                0061 #include "EEPARAMS.h"
                0062 #include "PARAMS.h"
87c5bcbdbd Oliv*0063 #ifdef ALLOW_EXCH2
                0064 #include "W2_EXCH2_SIZE.h"
                0065 #include "W2_EXCH2_TOPOLOGY.h"
                0066 #include "W2_EXCH2_PARAMS.h"
                0067 #endif /* ALLOW_EXCH2 */
9c019881ee Jean*0068 
                0069 C !INPUT PARAMETERS:
                0070       CHARACTER*(*) fName
                0071       INTEGER filePrec
                0072       LOGICAL globalFile
                0073       LOGICAL useCurrentDir
                0074       CHARACTER*(2) arrType
57622776fd Jean*0075       INTEGER kSize, kLo, kHi
9c019881ee Jean*0076       _RL  fldRL(*)
                0077       _RS  fldRS(*)
                0078       INTEGER irecord
                0079       INTEGER myIter
                0080       INTEGER myThid
                0081 C !OUTPUT PARAMETERS:
                0082 
                0083 C !FUNCTIONS:
                0084       INTEGER ILNBLNK
                0085       INTEGER MDS_RECLEN
                0086       EXTERNAL ILNBLNK, MDS_RECLEN
                0087 
                0088 C !LOCAL VARIABLES:
57622776fd Jean*0089       CHARACTER*(MAX_LEN_FNAM) dataFName, pfName
                0090       INTEGER IL, pIL, dUnit, nLev, irec
                0091       INTEGER iG, jG, bi, bj, k, kL
9c019881ee Jean*0092       Real*4 r4seg(sNx)
                0093       Real*8 r8seg(sNx)
                0094       INTEGER length_of_rec
                0095       LOGICAL fileIsOpen
57622776fd Jean*0096       CHARACTER*(MAX_LEN_MBUF) msgBuf
87c5bcbdbd Oliv*0097 #ifdef ALLOW_EXCH2
57622776fd Jean*0098       INTEGER tGx, tNx, tN
87c5bcbdbd Oliv*0099 #endif /* ALLOW_EXCH2 */
                0100 
9c019881ee Jean*0101 C     ------------------------------------------------------------------
                0102 
                0103 C Only do I/O if I am the master thread
                0104       _BEGIN_MASTER( myThid )
                0105 
                0106 C Record number must be >= 1
                0107       IF (irecord .LT. 1) THEN
                0108        WRITE(msgBuf,'(A,I9.8)')
                0109      &   ' MDS_WRITE_SEC_XZ: argument irecord = ',irecord
                0110        CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
                0111      &                     SQUEEZE_RIGHT, myThid )
                0112        WRITE(msgBuf,'(A)')
                0113      &   ' MDS_WRITE_SEC_XZ: invalid value for irecord'
                0114        CALL PRINT_ERROR( msgBuf, myThid )
                0115        STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_XZ'
                0116       ENDIF
                0117 
                0118 C Assume nothing
                0119       fileIsOpen=.FALSE.
                0120       IL  = ILNBLNK( fName )
                0121       pIL = ILNBLNK( mdsioLocalDir )
                0122 
                0123 C Assign special directory
                0124       IF ( useCurrentDir .OR. pIL.EQ.0 ) THEN
                0125        pfName= fName
                0126       ELSE
                0127        WRITE(pfName,'(2A)') mdsioLocalDir(1:pIL), fName(1:IL)
                0128       ENDIF
                0129       pIL=ILNBLNK( pfName )
                0130 
57622776fd Jean*0131 C Set number of levels to write:
                0132       nLev = kHi - kLo + 1
                0133 
9c019881ee Jean*0134 C Assign a free unit number as the I/O channel for this routine
                0135       CALL MDSFINDUNIT( dUnit, myThid )
                0136 
                0137 C If we are writing to a global file then we open it here
                0138       IF (globalFile) THEN
                0139        WRITE(dataFName,'(2A)') fName(1:IL),'.data'
                0140        IF (irecord .EQ. 1) THEN
                0141         length_of_rec = MDS_RECLEN( filePrec, sNx, myThid )
                0142         OPEN( dUnit, file=dataFName, status=_NEW_STATUS,
                0143      &        access='direct', recl=length_of_rec )
                0144         fileIsOpen=.TRUE.
                0145        ELSE
                0146         length_of_rec = MDS_RECLEN( filePrec, sNx, myThid )
                0147         OPEN( dUnit, file=dataFName, status='old',
                0148      &        access='direct', recl=length_of_rec )
                0149         fileIsOpen=.TRUE.
                0150        ENDIF
                0151       ENDIF
                0152 
                0153 C Loop over all tiles
                0154       DO bj=1,nSy
                0155        DO bi=1,nSx
                0156 C If we are writing to a tiled MDS file then we open each one here
                0157         IF (.NOT. globalFile) THEN
                0158          iG=bi+(myXGlobalLo-1)/sNx
                0159          jG=bj+(myYGlobalLo-1)/sNy
                0160          WRITE(dataFName,'(2A,I3.3,A,I3.3,A)')
                0161      &              pfName(1:pIL),'.',iG,'.',jG,'.data'
                0162          IF (irecord .EQ. 1) THEN
                0163           length_of_rec = MDS_RECLEN( filePrec, sNx, myThid )
                0164           OPEN( dUnit, file=dataFName, status=_NEW_STATUS,
                0165      &          access='direct', recl=length_of_rec )
                0166           fileIsOpen=.TRUE.
                0167          ELSE
                0168           length_of_rec = MDS_RECLEN( filePrec, sNx, myThid )
                0169           OPEN( dUnit, file=dataFName, status='old',
                0170      &          access='direct', recl=length_of_rec )
                0171           fileIsOpen=.TRUE.
                0172          ENDIF
                0173         ENDIF
                0174         IF (fileIsOpen) THEN
87c5bcbdbd Oliv*0175 #ifdef ALLOW_EXCH2
                0176 C layout of global x-z section files is "xStack"
                0177          tN = W2_myTileList(bi,bj)
                0178          tGx = exch2_txXStackLo(tN)
                0179          tNx = exch2_tNx(tN)
                0180 #endif /* ALLOW_EXCH2 */
57622776fd Jean*0181          DO k=1,nLev
                0182            kL = k + kLo - 1
9c019881ee Jean*0183            IF (globalFile) THEN
87c5bcbdbd Oliv*0184 #ifdef ALLOW_EXCH2
                0185 C record length is sNx==tNx
                0186             irec = 1 + ( tGx-1
57622776fd Jean*0187      &                   + ( k-1 + (irecord-1)*nLev )*exch2_xStack_Nx
87c5bcbdbd Oliv*0188      &                 )/tNx
                0189 #else /* ALLOW_EXCH2 */
9c019881ee Jean*0190             iG = myXGlobalLo-1 + (bi-1)*sNx
                0191             jG = (myYGlobalLo-1)/sNy + (bj-1)
57622776fd Jean*0192             irec = 1 + INT(iG/sNx) + nSx*nPx*(k-1)
                0193      &           + nSx*nPx*nLev*(irecord-1)
87c5bcbdbd Oliv*0194 #endif /* ALLOW_EXCH2 */
9c019881ee Jean*0195            ELSE
                0196             iG = 0
                0197             jG = 0
57622776fd Jean*0198             irec = k + nLev*(irecord-1)
9c019881ee Jean*0199            ENDIF
                0200            IF (filePrec .EQ. precFloat32) THEN
                0201             IF (arrType .EQ. 'RS') THEN
57622776fd Jean*0202              CALL MDS_SEG4toRS_2D( sNx,OLx,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0203      &                             r4seg,fldRS )
                0204             ELSEIF (arrType .EQ. 'RL') THEN
57622776fd Jean*0205              CALL MDS_SEG4toRL_2D( sNx,OLx,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0206      &                             r4seg,fldRL )
                0207             ELSE
                0208              WRITE(msgBuf,'(A)')
                0209      &         ' MDS_WRITE_SEC_XZ: illegal value for arrType'
                0210              CALL PRINT_ERROR( msgBuf, myThid )
                0211              STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_XZ'
                0212             ENDIF
                0213 #ifdef _BYTESWAPIO
                0214             CALL MDS_BYTESWAPR4(sNx,r4seg)
                0215 #endif
                0216             WRITE(dUnit,rec=irec) r4seg
                0217            ELSEIF (filePrec .EQ. precFloat64) THEN
                0218             IF (arrType .EQ. 'RS') THEN
57622776fd Jean*0219              CALL MDS_SEG8toRS_2D( sNx,OLx,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0220      &                             r8seg,fldRS )
                0221             ELSEIF (arrType .EQ. 'RL') THEN
57622776fd Jean*0222              CALL MDS_SEG8toRL_2D( sNx,OLx,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0223      &                             r8seg,fldRL )
                0224             ELSE
                0225              WRITE(msgBuf,'(A)')
                0226      &         ' MDS_WRITE_SEC_XZ: illegal value for arrType'
                0227              CALL PRINT_ERROR( msgBuf, myThid )
                0228              STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_XZ'
                0229             ENDIF
                0230 #ifdef _BYTESWAPIO
                0231             CALL MDS_BYTESWAPR8( sNx, r8seg )
                0232 #endif
                0233             WRITE(dUnit,rec=irec) r8seg
                0234            ELSE
                0235             WRITE(msgBuf,'(A)')
                0236      &        ' MDS_WRITE_SEC_XZ: illegal value for filePrec'
                0237             CALL PRINT_ERROR( msgBuf, myThid )
                0238             STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_XZ'
                0239            ENDIF
                0240 C End of k loop
                0241          ENDDO
                0242         ELSE
                0243          WRITE(msgBuf,'(A)')
                0244      &     ' MDS_WRITE_SEC_XZ: I should never get to this point'
                0245          CALL PRINT_ERROR( msgBuf, myThid )
                0246          STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_XZ'
                0247         ENDIF
                0248 C If we were writing to a tiled MDS file then we close it here
                0249         IF (fileIsOpen .AND. (.NOT. globalFile)) THEN
                0250          CLOSE( dUnit )
                0251          fileIsOpen = .FALSE.
                0252         ENDIF
                0253 C End of bi,bj loops
                0254        ENDDO
                0255       ENDDO
                0256 
                0257 C If global file was opened then close it
                0258       IF (fileIsOpen .AND. globalFile) THEN
                0259        CLOSE( dUnit )
                0260        fileIsOpen = .FALSE.
                0261       ENDIF
                0262 
                0263       _END_MASTER( myThid )
                0264 
                0265 C     ------------------------------------------------------------------
                0266       RETURN
                0267       END
                0268 
                0269 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
                0270 
                0271 CBOP
                0272 C !ROUTINE: MDS_WRITE_SEC_YZ
                0273 C !INTERFACE:
                0274       SUBROUTINE MDS_WRITE_SEC_YZ(
                0275      I   fName,
                0276      I   filePrec,
                0277      I   globalFile,
                0278      I   useCurrentDir,
                0279      I   arrType,
57622776fd Jean*0280      I   kSize, kLo, kHi,
9c019881ee Jean*0281      I   fldRL, fldRS,
                0282      I   irecord,
                0283      I   myIter,
                0284      I   myThid )
                0285 
                0286 C !DESCRIPTION
                0287 C Arguments:
                0288 C
                0289 C fName       string  :: base name for file to read
                0290 C filePrec    integer :: number of bits per word in file (32 or 64)
                0291 C globalFile  logical :: selects between writing a global or tiled file
                0292 C useCurrentDir logic :: always write to the current directory (even if
                0293 C                        "mdsioLocalDir" is set)
3daafce20b Jean*0294 C arrType     char(2) :: which array (fldRL/RS) to write, either "RL" or "RS"
57622776fd Jean*0295 C kSize       integer :: size of second dimension: normally either 1 or Nr
                0296 C kLo         integer :: 1rst vertical level (of array fldRL/RS) to write
                0297 C kHi         integer :: last vertical level (of array fldRL/RS) to write
9c019881ee Jean*0298 C fldRL         RL    :: array to write if arrType="RL", fldRL(:,kSize,:,:)
                0299 C fldRS         RS    :: array to write if arrType="RS", fldRS(:,kSize,:,:)
                0300 C irecord     integer :: record number to read
                0301 C myIter      integer :: time step number
                0302 C myThid      integer :: thread identifier
                0303 C
                0304 C MDS_WRITE_SEC_YZ creates either a file of the form "fName.data"
                0305 C if the logical flag "globalFile" is set true. Otherwise
                0306 C it creates MDS tiled files of the form "fName.xxx.yyy.data".
                0307 C The precision of the file is decsribed by filePrec, set either
                0308 C  to floatPrec32 or floatPrec64. The char*(2) string arrType, either "RL"
                0309 C  or "RS", selects which array is written, either fldRL or fldRS.
                0310 C This routine writes vertical slices (Y-Z) including overlap regions.
                0311 C irecord is the record number to be read and must be >= 1.
                0312 C NOTE: It is currently assumed that
                0313 C the highest record number in the file was the last record written.
                0314 C
                0315 C Modified: 06/02/00 spk@ocean.mit.edu
                0316 CEOP
                0317 
                0318 C !USES:
                0319       IMPLICIT NONE
                0320 C Global variables / common blocks
                0321 #include "SIZE.h"
                0322 #include "EEPARAMS.h"
                0323 #include "PARAMS.h"
87c5bcbdbd Oliv*0324 #ifdef ALLOW_EXCH2
                0325 #include "W2_EXCH2_SIZE.h"
                0326 #include "W2_EXCH2_TOPOLOGY.h"
                0327 #include "W2_EXCH2_PARAMS.h"
                0328 #endif /* ALLOW_EXCH2 */
9c019881ee Jean*0329 
                0330 C !INPUT PARAMETERS:
                0331       CHARACTER*(*) fName
                0332       INTEGER filePrec
                0333       LOGICAL globalFile
                0334       LOGICAL useCurrentDir
                0335       CHARACTER*(2) arrType
57622776fd Jean*0336       INTEGER kSize, kLo, kHi
9c019881ee Jean*0337       _RL  fldRL(*)
                0338       _RS  fldRS(*)
                0339       INTEGER irecord
                0340       INTEGER myIter
                0341       INTEGER myThid
                0342 C !OUTPUT PARAMETERS:
                0343 
                0344 C !FUNCTIONS:
                0345       INTEGER ILNBLNK
                0346       INTEGER MDS_RECLEN
                0347       EXTERNAL ILNBLNK, MDS_RECLEN
                0348 
                0349 C !LOCAL VARIABLES:
57622776fd Jean*0350       CHARACTER*(MAX_LEN_FNAM) dataFName, pfName
                0351       INTEGER IL, pIL, dUnit, nLev, irec
                0352       INTEGER iG, jG, bi, bj, k, kL
9c019881ee Jean*0353       Real*4 r4seg(sNy)
                0354       Real*8 r8seg(sNy)
                0355       INTEGER length_of_rec
                0356       LOGICAL fileIsOpen
57622776fd Jean*0357       CHARACTER*(MAX_LEN_MBUF) msgBuf
87c5bcbdbd Oliv*0358 #ifdef ALLOW_EXCH2
57622776fd Jean*0359       INTEGER tGy, tNy, tN
87c5bcbdbd Oliv*0360 #endif /* ALLOW_EXCH2 */
9c019881ee Jean*0361 C     ------------------------------------------------------------------
                0362 
                0363 C Only do I/O if I am the master thread
                0364       _BEGIN_MASTER( myThid )
                0365 
                0366 C Record number must be >= 1
                0367       IF (irecord .LT. 1) THEN
                0368        WRITE(msgBuf,'(A,I9.8)')
                0369      &   ' MDS_WRITE_SEC_YZ: argument irecord = ',irecord
                0370        CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
                0371      &                     SQUEEZE_RIGHT , myThid)
                0372        WRITE(msgBuf,'(A)')
                0373      &   ' MDS_WRITE_SEC_YZ: invalid value for irecord'
                0374        CALL PRINT_ERROR( msgBuf, myThid )
                0375        STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_YZ'
                0376       ENDIF
                0377 
                0378 C Assume nothing
                0379       fileIsOpen=.FALSE.
                0380       IL  = ILNBLNK( fName )
                0381       pIL = ILNBLNK( mdsioLocalDir )
                0382 
                0383 C Assign special directory
                0384       IF ( useCurrentDir .OR. pIL.EQ.0 ) THEN
                0385        pfName= fName
                0386       ELSE
                0387        WRITE(pfName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
                0388       ENDIF
                0389       pIL=ILNBLNK( pfName )
                0390 
57622776fd Jean*0391 C Set number of levels to write:
                0392       nLev = kHi - kLo + 1
                0393 
9c019881ee Jean*0394 C Assign a free unit number as the I/O channel for this routine
                0395       CALL MDSFINDUNIT( dUnit, myThid )
                0396 
                0397 C If we are writing to a global file then we open it here
                0398       IF (globalFile) THEN
                0399        WRITE(dataFName,'(2A)') fName(1:IL),'.data'
                0400        IF (irecord .EQ. 1) THEN
                0401         length_of_rec = MDS_RECLEN( filePrec, sNy, myThid )
                0402         OPEN( dUnit, file=dataFName, status=_NEW_STATUS,
                0403      &        access='direct', recl=length_of_rec )
                0404         fileIsOpen=.TRUE.
                0405        ELSE
                0406         length_of_rec = MDS_RECLEN( filePrec, sNy, myThid )
                0407         OPEN( dUnit, file=dataFName, status='old',
                0408      &        access='direct', recl=length_of_rec )
                0409         fileIsOpen=.TRUE.
                0410        ENDIF
                0411       ENDIF
                0412 
                0413 C Loop over all tiles
                0414       DO bj=1,nSy
                0415        DO bi=1,nSx
                0416 C If we are writing to a tiled MDS file then we open each one here
                0417         IF (.NOT. globalFile) THEN
                0418          iG=bi+(myXGlobalLo-1)/sNx
                0419          jG=bj+(myYGlobalLo-1)/sNy
                0420          WRITE(dataFName,'(2A,I3.3,A,I3.3,A)')
                0421      &              pfName(1:pIL),'.',iG,'.',jG,'.data'
                0422          IF (irecord .EQ. 1) THEN
                0423           length_of_rec = MDS_RECLEN( filePrec, sNy, myThid )
                0424           OPEN( dUnit, file=dataFName, status=_NEW_STATUS,
                0425      &          access='direct', recl=length_of_rec )
                0426           fileIsOpen=.TRUE.
                0427          ELSE
                0428           length_of_rec = MDS_RECLEN( filePrec, sNy, myThid )
                0429           OPEN( dUnit, file=dataFName, status='old',
                0430      &          access='direct', recl=length_of_rec )
                0431           fileIsOpen=.TRUE.
                0432          ENDIF
                0433         ENDIF
                0434         IF (fileIsOpen) THEN
87c5bcbdbd Oliv*0435 #ifdef ALLOW_EXCH2
                0436 C layout of global y-z section files is "yStack"
                0437          tN = W2_myTileList(bi,bj)
                0438          tGy = exch2_tyYStackLo(tN)
                0439          tNy = exch2_tNy(tN)
                0440 #endif /* ALLOW_EXCH2 */
57622776fd Jean*0441          DO k=1,nLev
                0442            kL = k + kLo - 1
9c019881ee Jean*0443            IF (globalFile) THEN
87c5bcbdbd Oliv*0444 #ifdef ALLOW_EXCH2
                0445 C record length is sNy==tNy
                0446             irec = 1 + ( tGy-1
57622776fd Jean*0447      &                   + ( k-1 + (irecord-1)*nLev )*exch2_yStack_Ny
87c5bcbdbd Oliv*0448      &                 )/tNy
                0449 #else /* ALLOW_EXCH2 */
9c019881ee Jean*0450             iG = (myXGlobalLo-1)/sNx + (bi-1)
                0451             jG = myYGlobalLo-1 + (bj-1)*sNy
57622776fd Jean*0452             irec = 1 + INT(jG/sNy) + nSy*nPy*(k-1)
                0453      &           + nSy*nPy*nLev*(irecord-1)
87c5bcbdbd Oliv*0454 #endif /* ALLOW_EXCH2 */
9c019881ee Jean*0455            ELSE
                0456             iG = 0
                0457             jG = 0
57622776fd Jean*0458             irec = k + nLev*(irecord-1)
9c019881ee Jean*0459            ENDIF
                0460            IF (filePrec .EQ. precFloat32) THEN
                0461             IF (arrType .EQ. 'RS') THEN
57622776fd Jean*0462              CALL MDS_SEG4toRS_2D( sNy,OLy,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0463      &                             r4seg,fldRS )
                0464             ELSEIF (arrType .EQ. 'RL') THEN
57622776fd Jean*0465              CALL MDS_SEG4toRL_2D( sNy,OLy,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0466      &                             r4seg,fldRL )
                0467             ELSE
                0468              WRITE(msgBuf,'(A)')
                0469      &         ' MDS_WRITE_SEC_YZ: illegal value for arrType'
                0470              CALL PRINT_ERROR( msgBuf, myThid )
                0471              STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_YZ'
                0472             ENDIF
                0473 #ifdef _BYTESWAPIO
                0474             CALL MDS_BYTESWAPR4(sNy,r4seg)
                0475 #endif
                0476             WRITE(dUnit,rec=irec) r4seg
                0477            ELSEIF (filePrec .EQ. precFloat64) THEN
                0478             IF (arrType .EQ. 'RS') THEN
57622776fd Jean*0479              CALL MDS_SEG8toRS_2D( sNy,OLy,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0480      &                             r8seg,fldRS )
                0481             ELSEIF (arrType .EQ. 'RL') THEN
57622776fd Jean*0482              CALL MDS_SEG8toRL_2D( sNy,OLy,kSize,bi,bj,kL,.FALSE.,
9c019881ee Jean*0483      &                             r8seg,fldRL )
                0484             ELSE
                0485              WRITE(msgBuf,'(A)')
                0486      &         ' MDS_WRITE_SEC_YZ: illegal value for arrType'
                0487              CALL PRINT_ERROR( msgBuf, myThid )
                0488              STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_YZ'
                0489             ENDIF
                0490 #ifdef _BYTESWAPIO
                0491             CALL MDS_BYTESWAPR8( sNy, r8seg )
                0492 #endif
                0493             WRITE(dUnit,rec=irec) r8seg
                0494            ELSE
                0495             WRITE(msgBuf,'(A)')
                0496      &        ' MDS_WRITE_SEC_YZ: illegal value for filePrec'
                0497             CALL PRINT_ERROR( msgBuf, myThid )
                0498             STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_YZ'
                0499            ENDIF
                0500 C End of k loop
                0501          ENDDO
                0502         ELSE
                0503          WRITE(msgBuf,'(A)')
                0504      &     ' MDS_WRITE_SEC_YZ: I should never get to this point'
                0505          CALL PRINT_ERROR( msgBuf, myThid )
                0506          STOP 'ABNORMAL END: S/R MDS_WRITE_SEC_YZ'
                0507         ENDIF
                0508 C If we were writing to a tiled MDS file then we close it here
                0509         IF (fileIsOpen .AND. (.NOT. globalFile)) THEN
                0510          CLOSE( dUnit )
                0511          fileIsOpen = .FALSE.
                0512         ENDIF
                0513 C End of bi,bj loops
                0514        ENDDO
                0515       ENDDO
                0516 
                0517 C If global file was opened then close it
                0518       IF (fileIsOpen .AND. globalFile) THEN
                0519        CLOSE( dUnit )
                0520        fileIsOpen = .FALSE.
                0521       ENDIF
                0522 
                0523       _END_MASTER( myThid )
                0524 
                0525 C     ------------------------------------------------------------------
                0526       RETURN
                0527       END