File indexing completed on 2022-04-14 05:09:28 UTC
view on githubraw file Latest commit 3d93c0a0 on 2022-04-13 15:21:38 UTC
11aeef3734 Jean*0001 #include "MDSIO_OPTIONS.h"
0002
0003
0004
0005
0006 SUBROUTINE MDS_READ_META(
0007 I fileName,
0008 O simulName,
0009 O titleLine,
0010 O filePrec,
0011 U nDims, nFlds, nTimRec,
0012 O dimList, fldList, timList,
8a1d1934ce Jean*0013 O misVal, nRecords, fileIter,
11aeef3734 Jean*0014 I useCurrentDir,
0015 I myThid )
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 IMPLICIT NONE
0026
0027
0028 #include "SIZE.h"
0029 #include "EEPARAMS.h"
0030 #include "PARAMS.h"
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
8a1d1934ce Jean*0052
11aeef3734 Jean*0053
0054
0055
0056 CHARACTER*(*) fileName
0057 CHARACTER*(*) simulName
0058 CHARACTER*(*) titleLine
0059 INTEGER filePrec
0060 INTEGER nDims
0061 INTEGER dimList(3,*)
0062
0063 INTEGER nFlds
0064 CHARACTER*(8) fldList(*)
0065 INTEGER nTimRec
0066 _RL timList(*)
8a1d1934ce Jean*0067 _RL misVal
11aeef3734 Jean*0068 INTEGER nRecords
0069 INTEGER fileIter
0070 LOGICAL useCurrentDir
0071 INTEGER myThid
0072
0073
0074
700a36f4de Jean*0075 INTEGER ILNBLNK
0076 EXTERNAL ILNBLNK
11aeef3734 Jean*0077
0078
700a36f4de Jean*0079
afdbe20224 Jean*0080
11aeef3734 Jean*0081
0082
0083
0084
700a36f4de Jean*0085 INTEGER i,j,ii
afdbe20224 Jean*0086 INTEGER iG,jG
0087 INTEGER iL,pL,iLm
11aeef3734 Jean*0088 INTEGER mUnit, errIO
0089 INTEGER nDimFil, nFldFil, nTimFil
0090 LOGICAL fileExist, globalFile
0091 CHARACTER*(MAX_LEN_MBUF) msgBuf
0092 CHARACTER*(MAX_LEN_MBUF) lineBuf
0093 CHARACTER*(MAX_LEN_FNAM) mFileName, pfName
0094
0095
0096
0097
0098 simulName = ' '
0099 titleLine = ' '
0100 filePrec = 0
0101 nRecords = 0
0102 fileIter = 0
0103
0104
afdbe20224 Jean*0105 DO j=1,nDims
0106 DO i=1,3
0107 dimList(i,j) = 0
11aeef3734 Jean*0108 ENDDO
0109 ENDDO
0110 DO i=1,nFlds
0111 fldList(i)= ' '
0112 ENDDO
0113 DO i=1,nTimRec
0114 timList(i) = 0.
0115 ENDDO
8a1d1934ce Jean*0116 misVal = oneRL
11aeef3734 Jean*0117
0118 fileExist = .FALSE.
0119 globalFile = .FALSE.
0120 nDimFil = 0
0121 nFldFil = 0
0122 nTimFil = 0
0123
0124
0125
0126
0127 _BEGIN_MASTER( myThid )
0128
0129
0130 iL = ILNBLNK(fileName)
0131 pL = ILNBLNK( mdsioLocalDir )
0132 IF ( useCurrentDir .OR. pL.EQ.0 ) THEN
0133 pfName = fileName
0134 ELSE
0135 WRITE(pfName,'(2A)') mdsioLocalDir(1:pL), fileName(1:iL)
0136 ENDIF
0137 pL = ILNBLNK( pfName )
0138
0139
0140
0141 mFileName = fileName(1:iL)
0142 iLm = iL
0143
0144 IF ( .NOT.fileExist ) THEN
0145
0146 WRITE(mFileName,'(2A)') fileName(1:iL), '.meta'
0147 iLm = iL+5
0148 INQUIRE( FILE=mFileName, EXIST=fileExist )
0149 ENDIF
0150 IF ( fileExist ) THEN
0151 globalFile = .TRUE.
0152 ELSE
0153
0154 iG = 1+(myXGlobalLo-1)/sNx
0155 jG = 1+(myYGlobalLo-1)/sNy
0156 WRITE(mFileName,'(2A,I3.3,A,I3.3,A)')
0157 & pfName(1:pL),'.',iG,'.',jG,'.meta'
0158 iLm = pL+8+5
0159 INQUIRE( FILE=mFileName, EXIST=fileExist )
0160 ENDIF
0161 IF ( .NOT.fileExist ) THEN
0162
0163 WRITE(mFileName,'(2A,I3.3,A,I3.3,A)')
0164 & pfName(1:pL),'.',1,'.',1,'.meta'
0165 iLm = pL+8+5
0166 INQUIRE( FILE=mFileName, EXIST=fileExist )
0167 ENDIF
0168 IF ( .NOT.fileExist ) THEN
0169 WRITE(msgBuf,'(4A)') 'WARNING >> MDS_READ_META: file: ',
0170 & fileName(1:iL), '.meta , ', mFileName(1:iLm)
0171
0172 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
0173 & SQUEEZE_RIGHT , myThid )
0174 WRITE(msgBuf,'(A)')
0175 & 'WARNING >> MDS_READ_META: Files DO not exist'
0176 CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
0177 & SQUEEZE_RIGHT , myThid )
0178 nFldFil = -1
0179 ELSE
0180
0181
ae605e558b Jean*0182 IF ( debugLevel .GE. debLevB ) THEN
11aeef3734 Jean*0183 WRITE(msgBuf,'(2A)') ' MDS_READ_META: opening file: ',
0184 & mFileName(1:iLm)
0185 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
0186 & SQUEEZE_RIGHT , myThid)
0187 ENDIF
0188
0189
0190 CALL MDSFINDUNIT( mUnit, myThid )
0191
0192
3d93c0a01e Ou W*0193 OPEN( mUnit, FILE=mFileName, STATUS='old', _READONLY_ACTION
11aeef3734 Jean*0194 & FORM='formatted', IOSTAT=errIO )
0195
0196 IF ( errIO .NE. 0 ) THEN
0197 WRITE(msgBuf,'(A,A)') 'MDS_READ_META: Unable to open file: ',
0198 & mFileName(1:iLm)
0199 CALL PRINT_ERROR( msgBuf , myThid )
0200 STOP 'ABNORMAL END: S/R MDS_READ_META'
0201 ENDIF
0202
0203
0204
0205 DO WHILE ( .TRUE. )
0206 READ( mUnit, FMT='(A)', END=1001 ) lineBuf
0207
0208 iL = ILNBLNK(lineBuf)
0209
0210
0211 IF ( iL.GE.22 .AND. lineBuf(1:14).EQ.' simulation = ' ) THEN
0212 ii = LEN(simulName)
0213
0214 ii = MIN(ii+17,iL-4)
0215 simulName = lineBuf(18:ii)
0216 iL = 0
0217 ENDIF
0218
0219
0220 IF ( nDimFil.EQ.0 .AND.
0221 & iL.GE.15 .AND. lineBuf(1:9).EQ.' nDims = ' ) THEN
0222 READ(lineBuf(12:iL),'(I3)') nDimFil
0223 IF ( nDimFil.GT.nDims .AND. nDims.GE.1 ) THEN
0224 WRITE(msgBuf,'(2(A,I3),A)') ' MDS_READ_META: nDims=',
0225 & nDimFil, ' too large ( >', nDims, ' )'
0226 CALL PRINT_ERROR( msgBuf, myThid )
0227 STOP 'ABNORMAL END: S/R MDS_READ_META'
0228 ENDIF
0229 iL = 0
0230 ENDIF
0231
0232
0233 IF ( nDims.GE.1 .AND. nDimFil.GE.1 .AND.
0234 & iL.GE.11 .AND. lineBuf(1:11).EQ.' dimList = ' ) THEN
0235
0236
0237
0238
afdbe20224 Jean*0239 DO j=1,nDimFil
0240
0241 READ( mUnit, FMT='(A)', END=1001 ) lineBuf
700a36f4de Jean*0242 ii = ILNBLNK(lineBuf)
0243 IF ( ii.LT.20 ) THEN
afdbe20224 Jean*0244
079512f56f Jean*0245
afdbe20224 Jean*0246 READ(lineBuf, FMT='(3(1X,I5))', ERR=1002, END=1002 )
0247 & (dimList(i,j),i=1,3)
700a36f4de Jean*0248 ELSEIF ( ii.LT.30 ) THEN
0249
0250
0251 READ(lineBuf, FMT='(9X,3(1X,I5))', ERR=1002, END=1002 )
0252 & (dimList(i,j),i=1,3)
079512f56f Jean*0253 ELSE
0254
0255
0256 READ(lineBuf, FMT='(3(1X,I10))', ERR=1002, END=1002 )
0257 & (dimList(i,j),i=1,3)
afdbe20224 Jean*0258 ENDIF
11aeef3734 Jean*0259 ENDDO
0260 READ( mUnit, FMT='(A)', END=1001 ) lineBuf
0261 iL = 0
0262 ENDIF
0263
0264
0265
0266
0267
0268
0269
0270
0271 IF ( iL.GE.20 .AND. lineBuf(1:12).EQ.' dataprec = ' ) THEN
0272 IF ( lineBuf(16:22).EQ. 'float32' ) THEN
0273 filePrec = precFloat32
0274 ELSEIF ( lineBuf(16:22).EQ. 'float64' ) THEN
0275 filePrec = precFloat64
0276 ELSE
0277 WRITE(msgBuf,'(A)') ' MDS_READ_META: invalid dataprec'
0278 CALL PRINT_ERROR( msgBuf, myThid )
0279 CALL PRINT_ERROR(lineBuf, myThid )
0280 STOP 'ABNORMAL END: S/R MDS_READ_META'
0281 ENDIF
0282 iL = 0
0283 ENDIF
0284
0285 IF ( filePrec.EQ.0 .AND.
0286 & iL.GE.18 .AND. lineBuf(1:10).EQ.' format = ' ) THEN
0287 IF ( lineBuf(14:20).EQ. 'float32' ) THEN
0288 filePrec = precFloat32
0289 ELSEIF ( lineBuf(14:20).EQ. 'float64' ) THEN
0290 filePrec = precFloat64
0291 ELSE
0292 WRITE(msgBuf,'(A)') ' MDS_READ_META: invalid dataprec'
0293 CALL PRINT_ERROR( msgBuf, myThid )
0294 CALL PRINT_ERROR(lineBuf, myThid )
0295 STOP 'ABNORMAL END: S/R MDS_READ_META'
0296 ENDIF
0297 iL = 0
0298 ENDIF
0299
0300
0301 IF ( nRecords.EQ.0 .AND.
0302 & iL.GE.20 .AND. lineBuf(1:12).EQ.' nrecords = ' ) THEN
66046ae6a1 Brun*0303 IF ( iL.GE.25 ) THEN
0304 READ(lineBuf(15:iL),'(I10)') nRecords
0305 ELSE
0306 READ(lineBuf(15:iL),'(I5)') nRecords
0307 ENDIF
11aeef3734 Jean*0308 iL = 0
0309 ENDIF
0310
0311
0312 IF ( fileIter.EQ.0 .AND. iL.GE.31 .AND.
0313 & lineBuf(1:18).EQ.' timeStepNumber = ' ) THEN
0314 READ(lineBuf(21:iL),'(I10)') fileIter
0315 iL = 0
0316 ENDIF
0317
8a1d1934ce Jean*0318
11aeef3734 Jean*0319 IF ( nTimFil.EQ.0 .AND.
8a1d1934ce Jean*0320 & iL.GE.38 .AND. lineBuf(1:16).EQ.' timeInterval = ' ) THEN
11aeef3734 Jean*0321
0322
8a1d1934ce Jean*0323 nTimFil = INT((iL-17-3)/20)
11aeef3734 Jean*0324 IF ( nTimRec.GE.1 ) THEN
0325 IF ( nTimFil.GT.nTimRec ) THEN
0326 WRITE(msgBuf,'(2(A,I6),A)') ' MDS_READ_META: nTimRec=',
0327 & nTimFil, ' too large ( >', nTimRec, ' )'
0328 CALL PRINT_ERROR( msgBuf, myThid )
0329 STOP 'ABNORMAL END: S/R MDS_READ_META'
0330 ENDIF
8a1d1934ce Jean*0331 READ(lineBuf(18:iL-3),'(1P20E20.12)',ERR=1003)
11aeef3734 Jean*0332 & (timList(i),i=1,nTimFil)
0333 ENDIF
0334 iL = 0
8a1d1934ce Jean*0335 ENDIF
0336
0337 IF ( iL.GE.8 .AND. lineBuf(1:4).EQ.' /* ' ) THEN
11aeef3734 Jean*0338 IF ( lineBuf(iL-2:iL).EQ.' */' ) THEN
0339
0340 ii = LEN(titleLine)
0341
0342 ii = MIN(ii+4,iL-3)
0343 titleLine = lineBuf(5:ii)
0344 iL = 0
0345 ENDIF
0346 ENDIF
0347
8a1d1934ce Jean*0348
0349 IF ( misVal.EQ.oneRL .AND. iL.GE.40 .AND.
0350 & lineBuf(1:16).EQ.' missingValue = ' ) THEN
0351 READ(lineBuf(19:iL),'(1PE21.14)') misVal
0352 iL = 0
0353 ENDIF
0354
11aeef3734 Jean*0355
0356 IF ( nFldFil.EQ.0 .AND.
0357 & iL.GE.16 .AND. lineBuf(1:9).EQ.' nFlds = ' ) THEN
0358 READ(lineBuf(12:iL),'(I4)') nFldFil
0359 IF ( nFldFil.GT.nFlds .AND. nFlds.GE.1 ) THEN
0360 WRITE(msgBuf,'(2(A,I6),A)') ' MDS_READ_META: nFlds=',
0361 & nFldFil, ' too large ( >', nFlds, ' )'
0362 CALL PRINT_ERROR( msgBuf, myThid )
0363 STOP 'ABNORMAL END: S/R MDS_READ_META'
0364 ENDIF
0365 iL = 0
0366 ENDIF
0367
0368
0369 IF ( nFldFil.GE.1 .AND. nFlds.GE.1 .AND.
0370 & iL.GE.11 .AND. lineBuf(1:11).EQ.' fldList = ' ) THEN
afdbe20224 Jean*0371 DO j=1,nFldFil,20
11aeef3734 Jean*0372 READ( mUnit, FMT='(20(2X,A8,1X))', ERR=1004, END=1004 )
afdbe20224 Jean*0373 & (fldList(i),i=j,MIN(nFldFil,j+19))
11aeef3734 Jean*0374 ENDDO
0375 READ( mUnit, FMT='(A)', END=1001 ) lineBuf
0376 iL = 0
0377 ENDIF
0378
0379
0380 ENDDO
0381 1004 CONTINUE
0382 WRITE(msgBuf,'(2(A,I4),A)')
0383 & ' MDS_READ_META: error reading Fields: nFlds=',
afdbe20224 Jean*0384 & nFldFil, ' , j=', j
11aeef3734 Jean*0385 CALL PRINT_ERROR( msgBuf, myThid )
0386 STOP 'ABNORMAL END: S/R MDS_READ_META'
0387 1003 CONTINUE
0388 WRITE(msgBuf,'(2(A,I4),A)')
8a1d1934ce Jean*0389 & ' MDS_READ_META: error reading Time-Interval: nTimRec=',
11aeef3734 Jean*0390 & nTimFil, ' , iL=', iL
0391 CALL PRINT_ERROR( msgBuf, myThid )
0392 CALL PRINT_ERROR(lineBuf, myThid )
0393 STOP 'ABNORMAL END: S/R MDS_READ_META'
0394 1002 CONTINUE
afdbe20224 Jean*0395 WRITE(msgBuf,'(3(A,I3),A)')
11aeef3734 Jean*0396 & ' MDS_READ_META: error reading Dim-List: nDims=',
afdbe20224 Jean*0397 & nDimFil, ' , j=', j, ' , ii=', ii
11aeef3734 Jean*0398 CALL PRINT_ERROR( msgBuf, myThid )
afdbe20224 Jean*0399 CALL PRINT_ERROR(lineBuf, myThid )
11aeef3734 Jean*0400 STOP 'ABNORMAL END: S/R MDS_READ_META'
0401 1001 CONTINUE
0402
0403
0404 CLOSE(mUnit)
0405
0406
0407 ENDIF
0408
0409 _END_MASTER( myThid )
0410
0411
0412 nDims = nDimFil
0413 nFlds = nFldFil
0414 nTimRec = nTimFil
0415
0416
0417
0418 RETURN
0419 END