File indexing completed on 2018-03-02 18:41:50 UTC
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
6d54cf9ca1 Ed H*0001 #include "MDSIO_OPTIONS.h"
5ae46f2adb Patr*0002
b714306922 Jean*0003
0004
0005
0006
0007
0008
0009
0010
5ae46f2adb Patr*0011
0012 SUBROUTINE MDSREADFIELD_3D_GL(
ffa487b126 Alis*0013 I fName,
0014 I filePrec,
0015 I arrType,
0016 I nNz,
0017 O arr_gl,
0018 I irecord,
0019 I myThid )
0020
0021
0022
eb5e2b9a92 Jean*0023
0024
0025
0026
0027
0028
0029
ffa487b126 Alis*0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
5ae46f2adb Patr*0046
ffa487b126 Alis*0047
0048 implicit none
0049
0050 #include "SIZE.h"
0051 #include "EEPARAMS.h"
0052 #include "PARAMS.h"
0053
0054
0055 character*(*) fName
0056 integer filePrec
0057 character*(2) arrType
0058 integer nNz
5ae46f2adb Patr*0059 _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,Nr)
ffa487b126 Alis*0060 integer irecord
0061 integer myThid
de7dc9fe18 Oliv*0062
0063 #ifdef ALLOW_CTRL
0064
ffa487b126 Alis*0065
0066 integer ILNBLNK
0067 integer MDS_RECLEN
0068
47c8a35ff3 Jean*0069 character*(MAX_LEN_FNAM) dataFName
7ac755d99f Patr*0070 integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
ffa487b126 Alis*0071 logical exst
0072 _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,Nr,nSx,nSy)
0073 Real*4 r4seg(sNx)
0074 Real*8 r8seg(sNx)
0075 logical globalFile,fileIsOpen
0076 integer length_of_rec
0077 character*(max_len_mbuf) msgbuf
eda676cb0f Patr*0078
0079 integer ii,jj
47c8a35ff3 Jean*0080
0081 integer x_size,y_size
eda676cb0f Patr*0082 PARAMETER ( x_size = Nx )
0083 PARAMETER ( y_size = Ny )
0084 Real*4 xy_buffer_r4(x_size,y_size)
0085 Real*8 xy_buffer_r8(x_size,y_size)
0086 Real*8 global(Nx,Ny)
47c8a35ff3 Jean*0087
eda676cb0f Patr*0088
6a53f18a53 Patr*0089
0090 integer pIL
0091
eda676cb0f Patr*0092
ffa487b126 Alis*0093
0094
0095
0096 _BEGIN_MASTER( myThid )
0097
b2fffc7e1a Jean*0098 #ifndef REAL4_IS_SLOW
0099 if (arrType .eq. 'RS') then
0100 write(msgbuf,'(a)')
0101 & ' MDSREADFIELD_GL is wrong for arrType="RS" (=real*4)'
0102 call print_error( msgbuf, mythid )
0103 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0104 endif
0105 #endif
0106
ffa487b126 Alis*0107
0108 if (irecord .LT. 1) then
0109 write(msgbuf,'(a,i9.8)')
0110 & ' MDSREADFIELD_GL: argument irecord = ',irecord
0111 call print_message( msgbuf, standardmessageunit,
0112 & SQUEEZE_RIGHT , mythid)
0113 write(msgbuf,'(a)')
0114 & ' MDSREADFIELD_GL: Invalid value for irecord'
0115 call print_error( msgbuf, mythid )
0116 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0117 endif
0118
0119
0120 globalFile = .FALSE.
0121 fileIsOpen = .FALSE.
0122 IL=ILNBLNK( fName )
6a53f18a53 Patr*0123
0124 pIL = ILNBLNK( mdsioLocalDir )
0125
0126
0127
0128 if ( pIL.NE.0 ) then
0129 write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
0130 endif
0131
ffa487b126 Alis*0132
0133
0134 call MDSFINDUNIT( dUnit, mythid )
0135
eda676cb0f Patr*0136 if ( useSingleCPUIO ) then
0137
0138 #ifdef ALLOW_USE_MPI
b714306922 Jean*0139 IF( myProcId .EQ. 0 ) THEN
eda676cb0f Patr*0140 #else
0141 IF ( .TRUE. ) THEN
0142 #endif /* ALLOW_USE_MPI */
0143
ffa487b126 Alis*0144
eda676cb0f Patr*0145 dataFName = fName
0146 inquire( file=dataFname, exist=exst )
0147 if (exst) globalFile = .TRUE.
ffa487b126 Alis*0148
0149
eda676cb0f Patr*0150 if (.NOT. globalFile) then
47c8a35ff3 Jean*0151 write(dataFname,'(2a)') fName(1:IL),'.data'
eda676cb0f Patr*0152 inquire( file=dataFname, exist=exst )
0153 if (exst) globalFile = .TRUE.
0154 endif
0155
0156
0157
0158 if ( globalFile) then
0159 length_of_rec=MDS_RECLEN( filePrec, x_size*y_size, mythid )
0160 open( dUnit, file=dataFName, status='old',
0161 & access='direct', recl=length_of_rec )
0162 else
b714306922 Jean*0163 write(msgbuf,'(2a)')
47c8a35ff3 Jean*0164 & ' MDSREADFIELD: filename: ',dataFName(1:IL)
eda676cb0f Patr*0165 call print_message( msgbuf, standardmessageunit,
0166 & SQUEEZE_RIGHT , mythid)
0167 call print_error( msgbuf, mythid )
0168 write(msgbuf,'(a)')
0169 & ' MDSREADFIELD: File does not exist'
0170 call print_message( msgbuf, standardmessageunit,
0171 & SQUEEZE_RIGHT , mythid)
0172 call print_error( msgbuf, mythid )
0173 stop 'ABNORMAL END: S/R MDSREADFIELD'
0174 endif
0175
0176 ENDIF
0177
0178
0179 else
0180
0181
0182
0183 dataFName = fName
ffa487b126 Alis*0184 inquire( file=dataFname, exist=exst )
0185 if (exst) then
0186 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*0187 & ' MDSREADFIELD: opening global file: ',dataFName(1:IL)
ffa487b126 Alis*0188 call print_message( msgbuf, standardmessageunit,
0189 & SQUEEZE_RIGHT , mythid)
0190 endif
eda676cb0f Patr*0191
0192
0193 if (.NOT. globalFile) then
47c8a35ff3 Jean*0194 write(dataFname,'(2a)') fName(1:IL),'.data'
eda676cb0f Patr*0195 inquire( file=dataFname, exist=exst )
0196 if (exst) then
0197 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*0198 & ' MDSREADFIELD_GL: opening global file: ',dataFName(1:IL+5)
eda676cb0f Patr*0199 call print_message( msgbuf, standardmessageunit,
0200 & SQUEEZE_RIGHT , mythid)
0201 globalFile = .TRUE.
0202 endif
0203 endif
0204
0205
ffa487b126 Alis*0206 endif
023d5a3a61 Patr*0207
eda676cb0f Patr*0208 if ( .not. useSingleCpuIO ) then
989416fbdf Patr*0209
eda676cb0f Patr*0210 if ( .not. ( globalFile ) ) then
023d5a3a61 Patr*0211
0212
0213 if (globalFile) then
0214 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
0215 open( dUnit, file=dataFName, status='old',
0216 & access='direct', recl=length_of_rec )
0217 fileIsOpen=.TRUE.
0218 endif
0219
b714306922 Jean*0220
ffa487b126 Alis*0221 do jp=1,nPy
0222 do ip=1,nPx
0223
0224 do bj=1,nSy
0225 do bi=1,nSx
0226
0227 if (.NOT. globalFile) then
0228 iG=bi+(ip-1)*nsx
0229 jG=bj+(jp-1)*nsy
47c8a35ff3 Jean*0230 write(dataFname,'(2a,i3.3,a,i3.3,a)')
ffa487b126 Alis*0231 & fName(1:IL),'.',iG,'.',jG,'.data'
0232 inquire( file=dataFname, exist=exst )
0233
0234
0235 if (exst) then
ae605e558b Jean*0236 if ( debugLevel .GE. debLevB ) then
494ad43bae Patr*0237 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*0238 & ' MDSREADFIELD_GL: opening file: ',dataFName(1:IL+13)
494ad43bae Patr*0239 call print_message( msgbuf, standardmessageunit,
ffa487b126 Alis*0240 & SQUEEZE_RIGHT , mythid)
494ad43bae Patr*0241 endif
ffa487b126 Alis*0242 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
0243 open( dUnit, file=dataFName, status='old',
0244 & access='direct', recl=length_of_rec )
0245 fileIsOpen=.TRUE.
0246 else
0247 fileIsOpen=.FALSE.
0248 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*0249 & ' MDSREADFIELD_GL: filename: ',dataFName(1:IL+13)
ffa487b126 Alis*0250 call print_message( msgbuf, standardmessageunit,
0251 & SQUEEZE_RIGHT , mythid)
48a21b9599 Patr*0252 call print_error( msgbuf, mythid )
ffa487b126 Alis*0253 write(msgbuf,'(a)')
0254 & ' MDSREADFIELD_GL: File does not exist'
48a21b9599 Patr*0255 call print_message( msgbuf, standardmessageunit,
0256 & SQUEEZE_RIGHT , mythid)
ffa487b126 Alis*0257 call print_error( msgbuf, mythid )
0258 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0259 endif
0260 endif
0261
0262 if (fileIsOpen) then
5ae46f2adb Patr*0263 do k=1,Nr
ffa487b126 Alis*0264 do j=1,sNy
023d5a3a61 Patr*0265 if (globalFile) then
0266 iG=bi+(ip-1)*nsx
0267 jG=bj+(jp-1)*nsy
0268 irec=1 + INT(iG/sNx) + nSx*nPx*(jG+j-1) + nSx*nPx*Ny*(k-1)
0269 & + nSx*nPx*Ny*nNz*(irecord-1)
0270 else
ffa487b126 Alis*0271 iG = 0
0272 jG = 0
5ae46f2adb Patr*0273 irec=j + sNy*(k-1) + sNy*Nr*(irecord-1)
023d5a3a61 Patr*0274 endif
ffa487b126 Alis*0275 if (filePrec .eq. precFloat32) then
0276 read(dUnit,rec=irec) r4seg
0277 #ifdef _BYTESWAPIO
0278 call MDS_BYTESWAPR4( sNx, r4seg )
0279 #endif
0280 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*0281 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*0282 call MDS_SEG4toRS( j,bi,bj,k,Nr, r4seg, .TRUE., arr )
b2fffc7e1a Jean*0283 #endif
ffa487b126 Alis*0284 elseif (arrType .eq. 'RL') then
5ae46f2adb Patr*0285 call MDS_SEG4toRL( j,bi,bj,k,Nr, r4seg, .TRUE., arr )
ffa487b126 Alis*0286 else
0287 write(msgbuf,'(a)')
0288 & ' MDSREADFIELD_GL: illegal value for arrType'
0289 call print_error( msgbuf, mythid )
0290 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0291 endif
0292 elseif (filePrec .eq. precFloat64) then
0293 read(dUnit,rec=irec) r8seg
0294 #ifdef _BYTESWAPIO
0295 call MDS_BYTESWAPR8( sNx, r8seg )
0296 #endif
0297 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*0298 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*0299 call MDS_SEG8toRS( j,bi,bj,k,Nr, r8seg, .TRUE., arr )
b2fffc7e1a Jean*0300 #endif
ffa487b126 Alis*0301 elseif (arrType .eq. 'RL') then
5ae46f2adb Patr*0302 call MDS_SEG8toRL( j,bi,bj,k,Nr, r8seg, .TRUE., arr )
ffa487b126 Alis*0303 else
0304 write(msgbuf,'(a)')
0305 & ' MDSREADFIELD_GL: illegal value for arrType'
0306 call print_error( msgbuf, mythid )
0307 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0308 endif
0309 else
0310 write(msgbuf,'(a)')
0311 & ' MDSREADFIELD_GL: illegal value for filePrec'
0312 call print_error( msgbuf, mythid )
0313 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0314 endif
0315 do ii=1,sNx
0316 arr_gl(ii,bi,ip,j,bj,jp,k)=arr(ii,j,k,bi,bj)
0317 enddo
0318
0319
0320 enddo
0321
0322 enddo
0323 if (.NOT. globalFile) then
0324 close( dUnit )
0325 fileIsOpen = .FALSE.
0326 endif
0327 endif
0328
0329 enddo
0330 enddo
0331
0332 enddo
0333 enddo
0334
0335
0336 if (fileIsOpen .AND. globalFile) then
0337 close( dUnit )
0338 fileIsOpen = .FALSE.
0339 endif
0340
eda676cb0f Patr*0341
0342 endif
0343
989416fbdf Patr*0344
eda676cb0f Patr*0345 else
0346
0347 DO k=1,nNz
0348
0349 #ifdef ALLOW_USE_MPI
b714306922 Jean*0350 IF( myProcId .EQ. 0 ) THEN
eda676cb0f Patr*0351 #else
0352 IF ( .TRUE. ) THEN
0353 #endif /* ALLOW_USE_MPI */
0354 irec = k+nNz*(irecord-1)
0355 if (filePrec .eq. precFloat32) then
0356 read(dUnit,rec=irec) xy_buffer_r4
0357 #ifdef _BYTESWAPIO
0358 call MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 )
0359 #endif
0360 DO J=1,Ny
0361 DO I=1,Nx
0362 global(I,J) = xy_buffer_r4(I,J)
0363 ENDDO
0364 ENDDO
0365 elseif (filePrec .eq. precFloat64) then
0366 read(dUnit,rec=irec) xy_buffer_r8
0367 #ifdef _BYTESWAPIO
0368 call MDS_BYTESWAPR8( x_size*y_size, xy_buffer_r8 )
0369 #endif
0370 DO J=1,Ny
0371 DO I=1,Nx
0372 global(I,J) = xy_buffer_r8(I,J)
0373 ENDDO
0374 ENDDO
0375 else
0376 write(msgbuf,'(a)')
0377 & ' MDSREADFIELD: illegal value for filePrec'
0378 call print_error( msgbuf, mythid )
0379 stop 'ABNORMAL END: S/R MDSREADFIELD'
0380 endif
0381 ENDIF
0382 DO jp=1,nPy
0383 DO ip=1,nPx
0384 DO bj = myByLo(myThid), myByHi(myThid)
0385 DO bi = myBxLo(myThid), myBxHi(myThid)
0386 DO J=1,sNy
0387 JJ=((jp-1)*nSy+(bj-1))*sNy+J
0388 DO I=1,sNx
0389 II=((ip-1)*nSx+(bi-1))*sNx+I
0390 arr_gl(i,bi,ip,j,bj,jp,k) = global(II,JJ)
0391 ENDDO
0392 ENDDO
0393 ENDDO
0394 ENDDO
0395 ENDDO
0396 ENDDO
0397
0398 ENDDO
0399
0400
0401 close( dUnit )
0402
023d5a3a61 Patr*0403 endif
0404
0405
ffa487b126 Alis*0406 _END_MASTER( myThid )
0407
b714306922 Jean*0408 #else /* ALLOW_CTRL */
0409 STOP 'ABNORMAL END: S/R MDSREADFIELD_3D_GL is empty'
de7dc9fe18 Oliv*0410 #endif /* ALLOW_CTRL */
ffa487b126 Alis*0411
b714306922 Jean*0412 RETURN
0413 END
0414
0415
ffa487b126 Alis*0416
5ae46f2adb Patr*0417 SUBROUTINE MDSWRITEFIELD_3D_GL(
ffa487b126 Alis*0418 I fName,
0419 I filePrec,
0420 I arrType,
0421 I nNz,
0422 I arr_gl,
0423 I irecord,
0424 I myIter,
0425 I myThid )
0426
0427
0428
eb5e2b9a92 Jean*0429
0430
0431
0432
0433
0434
0435
0436
ffa487b126 Alis*0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 implicit none
0464
0465 #include "SIZE.h"
0466 #include "EEPARAMS.h"
0467 #include "PARAMS.h"
0468
0469
0470 character*(*) fName
0471 integer filePrec
0472 character*(2) arrType
0473 integer nNz
0474
0475
5ae46f2adb Patr*0476 _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,Nr)
ffa487b126 Alis*0477
0478 integer irecord
0479 integer myIter
0480 integer myThid
de7dc9fe18 Oliv*0481
0482 #ifdef ALLOW_CTRL
0483
ffa487b126 Alis*0484
0485 integer ILNBLNK
0486 integer MDS_RECLEN
0487
47c8a35ff3 Jean*0488 character*(MAX_LEN_FNAM) dataFName,metaFName
023d5a3a61 Patr*0489 integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
ffa487b126 Alis*0490 Real*4 r4seg(sNx)
0491 Real*8 r8seg(sNx)
0492 _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,Nr,nSx,nSy)
b714306922 Jean*0493 INTEGER dimList(3,3), nDims, map2gl(2)
0494 _RL dummyRL(1)
0495 CHARACTER*8 blank8c
ffa487b126 Alis*0496 integer length_of_rec
0497 logical fileIsOpen
0498 character*(max_len_mbuf) msgbuf
023d5a3a61 Patr*0499
47c8a35ff3 Jean*0500 #ifdef ALLOW_USE_MPI
023d5a3a61 Patr*0501 integer ii,jj
98ddeeaedb Jean*0502
0503 integer x_size,y_size
023d5a3a61 Patr*0504 PARAMETER ( x_size = Nx )
0505 PARAMETER ( y_size = Ny )
0506 Real*4 xy_buffer_r4(x_size,y_size)
0507 Real*8 xy_buffer_r8(x_size,y_size)
0508 Real*8 global(Nx,Ny)
47c8a35ff3 Jean*0509 #endif
023d5a3a61 Patr*0510
6a53f18a53 Patr*0511
0512 integer pIL
0513
023d5a3a61 Patr*0514
b714306922 Jean*0515 DATA dummyRL(1) / 0. _d 0 /
0516 DATA blank8c / ' ' /
0517
ffa487b126 Alis*0518
0519
0520
0521 _BEGIN_MASTER( myThid )
0522
b2fffc7e1a Jean*0523 #ifndef REAL4_IS_SLOW
0524 if (arrType .eq. 'RS') then
0525 write(msgbuf,'(a)')
0526 & ' MDSWRITEFIELD_GL is wrong for arrType="RS" (=real*4)'
0527 call print_error( msgbuf, mythid )
0528 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
0529 endif
0530 #endif
0531
ffa487b126 Alis*0532
0533 if (irecord .LT. 1) then
0534 write(msgbuf,'(a,i9.8)')
0535 & ' MDSWRITEFIELD_GL: argument irecord = ',irecord
0536 call print_message( msgbuf, standardmessageunit,
0537 & SQUEEZE_RIGHT , mythid)
0538 write(msgbuf,'(a)')
0539 & ' MDSWRITEFIELD_GL: invalid value for irecord'
0540 call print_error( msgbuf, mythid )
0541 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
0542 endif
0543
0544
0545 fileIsOpen=.FALSE.
0546 IL=ILNBLNK( fName )
6a53f18a53 Patr*0547
0548 pIL = ILNBLNK( mdsioLocalDir )
0549
0550
0551
0552 if ( pIL.NE.0 ) then
0553 write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
0554 endif
0555
ffa487b126 Alis*0556
0557
0558 call MDSFINDUNIT( dUnit, mythid )
0559
023d5a3a61 Patr*0560
0561 #ifdef ALLOW_USE_MPI
0562 _END_MASTER( myThid )
0563
0564
0565 if (useSingleCpuIO) then
0566
0567
0568 _BEGIN_MASTER( myThid )
b714306922 Jean*0569 IF( myProcId .EQ. 0 ) THEN
47c8a35ff3 Jean*0570 write(dataFname,'(2a)') fName(1:IL),'.data'
023d5a3a61 Patr*0571 length_of_rec=MDS_RECLEN(filePrec,x_size*y_size,mythid)
0572 if (irecord .EQ. 1) then
0573 open( dUnit, file=dataFName, status=_NEW_STATUS,
0574 & access='direct', recl=length_of_rec )
0575 else
0576 open( dUnit, file=dataFName, status=_OLD_STATUS,
0577 & access='direct', recl=length_of_rec )
0578 endif
0579 ENDIF
0580 _END_MASTER( myThid )
0581
0582
0583 DO k=1,nNz
b714306922 Jean*0584
023d5a3a61 Patr*0585 do jp=1,nPy
0586 do ip=1,nPx
0587 DO bj = myByLo(myThid), myByHi(myThid)
0588 DO bi = myBxLo(myThid), myBxHi(myThid)
0589 DO J=1,sNy
0590 JJ=((jp-1)*nSy+(bj-1))*sNy+J
0591 DO I=1,sNx
0592 II=((ip-1)*nSx+(bi-1))*sNx+I
0593 global(II,JJ) = arr_gl(i,bi,ip,j,bj,jp,k)
0594 ENDDO
0595 ENDDO
0596 ENDDO
0597 ENDDO
0598 enddo
0599 enddo
0600 _BEGIN_MASTER( myThid )
b714306922 Jean*0601 IF( myProcId .EQ. 0 ) THEN
023d5a3a61 Patr*0602 irec=k+nNz*(irecord-1)
0603 if (filePrec .eq. precFloat32) then
0604 DO J=1,Ny
0605 DO I=1,Nx
0606 xy_buffer_r4(I,J) = global(I,J)
0607 ENDDO
0608 ENDDO
0609 #ifdef _BYTESWAPIO
0610 call MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 )
0611 #endif
0612 write(dUnit,rec=irec) xy_buffer_r4
0613 elseif (filePrec .eq. precFloat64) then
0614 DO J=1,Ny
0615 DO I=1,Nx
0616 xy_buffer_r8(I,J) = global(I,J)
0617 ENDDO
0618 ENDDO
0619 #ifdef _BYTESWAPIO
0620 call MDS_BYTESWAPR8( x_size*y_size, xy_buffer_r8 )
0621 #endif
0622 write(dUnit,rec=irec) xy_buffer_r8
0623 else
0624 write(msgbuf,'(a)')
0625 & ' MDSWRITEFIELD: illegal value for filePrec'
0626 call print_error( msgbuf, mythid )
0627 stop 'ABNORMAL END: S/R MDSWRITEFIELD'
0628 endif
0629 ENDIF
0630 _END_MASTER( myThid )
0631 ENDDO
0632
0633
0634 _BEGIN_MASTER( myThid )
b714306922 Jean*0635 IF( myProcId .EQ. 0 ) THEN
023d5a3a61 Patr*0636 close( dUnit )
47c8a35ff3 Jean*0637 write(metaFName,'(2a)') fName(1:IL),'.meta'
023d5a3a61 Patr*0638 dimList(1,1)=Nx
0639 dimList(2,1)=1
0640 dimList(3,1)=Nx
0641 dimList(1,2)=Ny
0642 dimList(2,2)=1
0643 dimList(3,2)=Ny
0644 dimList(1,3)=nNz
0645 dimList(2,3)=1
0646 dimList(3,3)=nNz
b714306922 Jean*0647 nDims=3
0648 if (nNz .EQ. 1) nDims=2
0649 map2gl(1) = 0
0650 map2gl(2) = 1
0651 CALL MDS_WRITE_META(
0652 I metaFName, dataFName, the_run_name, ' ',
0653 I filePrec, nDims, dimList, map2gl, 0, blank8c,
a50692f9cd Jean*0654 I 0, dummyRL, oneRL, irecord, myIter, myThid )
023d5a3a61 Patr*0655 ENDIF
0656 _END_MASTER( myThid )
0657
0658 _BARRIER
0659
0660 elseif ( .NOT. useSingleCpuIO ) then
0661 _BEGIN_MASTER( myThid )
0662 #endif /* ALLOW_USE_MPI */
0663
ffa487b126 Alis*0664
b714306922 Jean*0665
ffa487b126 Alis*0666 do jp=1,nPy
0667 do ip=1,nPx
0668
0669 do bj=1,nSy
0670 do bi=1,nSx
0671
0672 iG=bi+(ip-1)*nsx
0673 jG=bj+(jp-1)*nsy
47c8a35ff3 Jean*0674 write(dataFname,'(2a,i3.3,a,i3.3,a)')
ffa487b126 Alis*0675 & fName(1:IL),'.',iG,'.',jG,'.data'
0676 if (irecord .EQ. 1) then
0677 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
0678 open( dUnit, file=dataFName, status=_NEW_STATUS,
0679 & access='direct', recl=length_of_rec )
0680 fileIsOpen=.TRUE.
0681 else
0682 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
0683 open( dUnit, file=dataFName, status=_OLD_STATUS,
0684 & access='direct', recl=length_of_rec )
0685 fileIsOpen=.TRUE.
0686 endif
0687 if (fileIsOpen) then
5ae46f2adb Patr*0688 do k=1,Nr
ffa487b126 Alis*0689 do j=1,sNy
47c8a35ff3 Jean*0690 do i=1,sNx
0691 arr(i,j,k,bi,bj)=arr_gl(i,bi,ip,j,bj,jp,k)
ffa487b126 Alis*0692 enddo
0693 iG = 0
0694 jG = 0
5ae46f2adb Patr*0695 irec=j + sNy*(k-1) + sNy*Nr*(irecord-1)
ffa487b126 Alis*0696 if (filePrec .eq. precFloat32) then
0697 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*0698 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*0699 call MDS_SEG4toRS( j,bi,bj,k,Nr, r4seg, .FALSE., arr )
b2fffc7e1a Jean*0700 #endif
ffa487b126 Alis*0701 elseif (arrType .eq. 'RL') then
5ae46f2adb Patr*0702 call MDS_SEG4toRL( j,bi,bj,k,Nr, r4seg, .FALSE., arr )
ffa487b126 Alis*0703 else
0704 write(msgbuf,'(a)')
0705 & ' MDSWRITEFIELD_GL: illegal value for arrType'
0706 call print_error( msgbuf, mythid )
0707 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
0708 endif
0709 #ifdef _BYTESWAPIO
0710 call MDS_BYTESWAPR4( sNx, r4seg )
0711 #endif
0712 write(dUnit,rec=irec) r4seg
0713 elseif (filePrec .eq. precFloat64) then
0714 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*0715 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*0716 call MDS_SEG8toRS( j,bi,bj,k,Nr, r8seg, .FALSE., arr )
b2fffc7e1a Jean*0717 #endif
ffa487b126 Alis*0718 elseif (arrType .eq. 'RL') then
5ae46f2adb Patr*0719 call MDS_SEG8toRL( j,bi,bj,k,Nr, r8seg, .FALSE., arr )
ffa487b126 Alis*0720 else
0721 write(msgbuf,'(a)')
0722 & ' MDSWRITEFIELD_GL: illegal value for arrType'
0723 call print_error( msgbuf, mythid )
0724 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
0725 endif
0726 #ifdef _BYTESWAPIO
0727 call MDS_BYTESWAPR8( sNx, r8seg )
0728 #endif
0729 write(dUnit,rec=irec) r8seg
0730 else
0731 write(msgbuf,'(a)')
0732 & ' MDSWRITEFIELD_GL: illegal value for filePrec'
0733 call print_error( msgbuf, mythid )
0734 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
0735 endif
0736
0737 enddo
0738
0739 enddo
0740 else
0741 write(msgbuf,'(a)')
0742 & ' MDSWRITEFIELD_GL: I should never get to this point'
0743 call print_error( msgbuf, mythid )
0744 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
0745 endif
0746
0747 if (fileIsOpen) then
0748 close( dUnit )
0749 fileIsOpen = .FALSE.
0750 endif
0751
0752 iG=bi+(ip-1)*nsx
0753 jG=bj+(jp-1)*nsy
47c8a35ff3 Jean*0754 write(metaFname,'(2a,i3.3,a,i3.3,a)')
ffa487b126 Alis*0755 & fName(1:IL),'.',iG,'.',jG,'.meta'
0756 dimList(1,1)=Nx
0757 dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1
0758 dimList(3,1)=((ip-1)*nSx+bi)*sNx
0759 dimList(1,2)=Ny
0760 dimList(2,2)=((jp-1)*nSy+(bj-1))*sNy+1
0761 dimList(3,2)=((jp-1)*nSy+bj)*sNy
0762 dimList(1,3)=Nr
0763 dimList(2,3)=1
0764 dimList(3,3)=Nr
b714306922 Jean*0765 nDims=3
0766 if (Nr .EQ. 1) nDims=2
0767 map2gl(1) = 0
0768 map2gl(2) = 1
0769 CALL MDS_WRITE_META(
0770 I metaFName, dataFName, the_run_name, ' ',
0771 I filePrec, nDims, dimList, map2gl, 0, blank8c,
a50692f9cd Jean*0772 I 0, dummyRL, oneRL, irecord, myIter, myThid )
ffa487b126 Alis*0773
0774 enddo
0775 enddo
0776
0777 enddo
0778 enddo
0779
0780 _END_MASTER( myThid )
0781
023d5a3a61 Patr*0782
0783 #ifdef ALLOW_USE_MPI
0784
0785 endif
0786 #endif /* ALLOW_USE_MPI */
0787
0788
b714306922 Jean*0789 #else /* ALLOW_CTRL */
0790 STOP 'ABNORMAL END: S/R MDSWRITEFIELD_3D_GL is empty'
de7dc9fe18 Oliv*0791 #endif /* ALLOW_CTRL */
5ae46f2adb Patr*0792
b714306922 Jean*0793 RETURN
0794 END
0795
0796
5ae46f2adb Patr*0797
0798 SUBROUTINE MDSREADFIELD_2D_GL(
0799 I fName,
0800 I filePrec,
0801 I arrType,
0802 I nNz,
0803 O arr_gl,
0804 I irecord,
0805 I myThid )
0806
0807
0808
eb5e2b9a92 Jean*0809
0810
0811
0812
0813
0814
0815
5ae46f2adb Patr*0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834 implicit none
0835
0836 #include "SIZE.h"
0837 #include "EEPARAMS.h"
0838 #include "PARAMS.h"
0839
0840
0841 character*(*) fName
0842 integer filePrec
0843 character*(2) arrType
0844 integer nNz, nLocz
0845 parameter (nLocz = 1)
0846 _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,nLocz)
0847 integer irecord
0848 integer myThid
de7dc9fe18 Oliv*0849
0850 #ifdef ALLOW_CTRL
0851
5ae46f2adb Patr*0852
0853 integer ILNBLNK
0854 integer MDS_RECLEN
0855
47c8a35ff3 Jean*0856 character*(MAX_LEN_FNAM) dataFName
7ac755d99f Patr*0857 integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
5ae46f2adb Patr*0858 logical exst
0859 _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nLocz,nSx,nSy)
0860 Real*4 r4seg(sNx)
0861 Real*8 r8seg(sNx)
0862 logical globalFile,fileIsOpen
0863 integer length_of_rec
0864 character*(max_len_mbuf) msgbuf
eda676cb0f Patr*0865
0866 integer ii,jj
47c8a35ff3 Jean*0867
0868 integer x_size,y_size
eda676cb0f Patr*0869 PARAMETER ( x_size = Nx )
0870 PARAMETER ( y_size = Ny )
0871 Real*4 xy_buffer_r4(x_size,y_size)
0872 Real*8 xy_buffer_r8(x_size,y_size)
0873 Real*8 global(Nx,Ny)
47c8a35ff3 Jean*0874
eda676cb0f Patr*0875
6a53f18a53 Patr*0876
0877 integer pIL
0878
eda676cb0f Patr*0879
5ae46f2adb Patr*0880
0881
0882
0883 _BEGIN_MASTER( myThid )
0884
b2fffc7e1a Jean*0885 #ifndef REAL4_IS_SLOW
0886 if (arrType .eq. 'RS') then
0887 write(msgbuf,'(a)')
0888 & ' MDSREADFIELD_GL is wrong for arrType="RS" (=real*4)'
0889 call print_error( msgbuf, mythid )
0890 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0891 endif
0892 #endif
0893
5ae46f2adb Patr*0894
0895 if (irecord .LT. 1) then
0896 write(msgbuf,'(a,i9.8)')
0897 & ' MDSREADFIELD_GL: argument irecord = ',irecord
0898 call print_message( msgbuf, standardmessageunit,
0899 & SQUEEZE_RIGHT , mythid)
0900 write(msgbuf,'(a)')
0901 & ' MDSREADFIELD_GL: Invalid value for irecord'
0902 call print_error( msgbuf, mythid )
0903 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
0904 endif
0905
0906
0907 globalFile = .FALSE.
0908 fileIsOpen = .FALSE.
0909 IL=ILNBLNK( fName )
6a53f18a53 Patr*0910
0911 pIL = ILNBLNK( mdsioLocalDir )
0912
0913
0914
0915 if ( pIL.NE.0 ) then
0916 write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
0917 endif
0918
5ae46f2adb Patr*0919
0920
0921 call MDSFINDUNIT( dUnit, mythid )
0922
eda676cb0f Patr*0923 if ( useSingleCPUIO ) then
0924
0925
0926 #ifdef ALLOW_USE_MPI
b714306922 Jean*0927 IF( myProcId .EQ. 0 ) THEN
eda676cb0f Patr*0928 #else
0929 IF ( .TRUE. ) THEN
0930 #endif /* ALLOW_USE_MPI */
0931
5ae46f2adb Patr*0932
eda676cb0f Patr*0933 dataFName = fName
0934 inquire( file=dataFname, exist=exst )
0935 if (exst) globalFile = .TRUE.
5ae46f2adb Patr*0936
0937
eda676cb0f Patr*0938 if (.NOT. globalFile) then
47c8a35ff3 Jean*0939 write(dataFname,'(2a)') fName(1:IL),'.data'
eda676cb0f Patr*0940 inquire( file=dataFname, exist=exst )
0941 if (exst) globalFile = .TRUE.
0942 endif
0943
0944
0945
0946 if ( globalFile) then
0947 length_of_rec=MDS_RECLEN( filePrec, x_size*y_size, mythid )
0948 open( dUnit, file=dataFName, status='old',
0949 & access='direct', recl=length_of_rec )
0950 else
b714306922 Jean*0951 write(msgbuf,'(2a)')
47c8a35ff3 Jean*0952 & ' MDSREADFIELD: filename: ',dataFName(1:IL)
eda676cb0f Patr*0953 call print_message( msgbuf, standardmessageunit,
0954 & SQUEEZE_RIGHT , mythid)
0955 call print_error( msgbuf, mythid )
0956 write(msgbuf,'(a)')
0957 & ' MDSREADFIELD: File does not exist'
0958 call print_message( msgbuf, standardmessageunit,
0959 & SQUEEZE_RIGHT , mythid)
0960 call print_error( msgbuf, mythid )
0961 stop 'ABNORMAL END: S/R MDSREADFIELD'
0962 endif
0963
0964 ENDIF
0965
0966
0967 else
0968
0969
0970 dataFName = fName
5ae46f2adb Patr*0971 inquire( file=dataFname, exist=exst )
0972 if (exst) then
0973 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*0974 & ' MDSREADFIELD: opening global file: ',dataFName(1:IL)
5ae46f2adb Patr*0975 call print_message( msgbuf, standardmessageunit,
0976 & SQUEEZE_RIGHT , mythid)
0977 endif
eda676cb0f Patr*0978
0979
0980 if (.NOT. globalFile) then
47c8a35ff3 Jean*0981 write(dataFname,'(2a)') fName(1:IL),'.data'
eda676cb0f Patr*0982 inquire( file=dataFname, exist=exst )
0983 if (exst) then
0984 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*0985 & ' MDSREADFIELD_GL: opening global file: ',dataFName(1:IL+5)
eda676cb0f Patr*0986 call print_message( msgbuf, standardmessageunit,
0987 & SQUEEZE_RIGHT , mythid)
0988 globalFile = .TRUE.
0989 endif
0990 endif
0991
0992
5ae46f2adb Patr*0993 endif
023d5a3a61 Patr*0994
eda676cb0f Patr*0995 if ( .not. useSingleCpuIO ) then
0996
0997 if ( .not. ( globalFile ) ) then
023d5a3a61 Patr*0998
0999
1000 if (globalFile) then
1001 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
1002 open( dUnit, file=dataFName, status='old',
1003 & access='direct', recl=length_of_rec )
1004 fileIsOpen=.TRUE.
1005 endif
1006
b714306922 Jean*1007
5ae46f2adb Patr*1008 do jp=1,nPy
1009 do ip=1,nPx
1010
1011 do bj=1,nSy
1012 do bi=1,nSx
1013
1014 if (.NOT. globalFile) then
1015 iG=bi+(ip-1)*nsx
1016 jG=bj+(jp-1)*nsy
47c8a35ff3 Jean*1017 write(dataFname,'(2a,i3.3,a,i3.3,a)')
5ae46f2adb Patr*1018 & fName(1:IL),'.',iG,'.',jG,'.data'
1019 inquire( file=dataFname, exist=exst )
1020
1021
1022 if (exst) then
ae605e558b Jean*1023 if ( debugLevel .GE. debLevB ) then
494ad43bae Patr*1024 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*1025 & ' MDSREADFIELD_GL: opening file: ',dataFName(1:IL+13)
494ad43bae Patr*1026 call print_message( msgbuf, standardmessageunit,
5ae46f2adb Patr*1027 & SQUEEZE_RIGHT , mythid)
494ad43bae Patr*1028 endif
5ae46f2adb Patr*1029 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
1030 open( dUnit, file=dataFName, status='old',
1031 & access='direct', recl=length_of_rec )
1032 fileIsOpen=.TRUE.
1033 else
1034 fileIsOpen=.FALSE.
1035 write(msgbuf,'(a,a)')
47c8a35ff3 Jean*1036 & ' MDSREADFIELD_GL: filename: ',dataFName(1:IL+13)
5ae46f2adb Patr*1037 call print_message( msgbuf, standardmessageunit,
1038 & SQUEEZE_RIGHT , mythid)
48a21b9599 Patr*1039 call print_error( msgbuf, mythid )
5ae46f2adb Patr*1040 write(msgbuf,'(a)')
1041 & ' MDSREADFIELD_GL: File does not exist'
48a21b9599 Patr*1042 call print_message( msgbuf, standardmessageunit,
1043 & SQUEEZE_RIGHT , mythid)
5ae46f2adb Patr*1044 call print_error( msgbuf, mythid )
1045 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
1046 endif
1047 endif
1048
1049 if (fileIsOpen) then
1050 do k=1,nLocz
1051 do j=1,sNy
023d5a3a61 Patr*1052 if (globalFile) then
1053 iG=bi+(ip-1)*nsx
1054 jG=bj+(jp-1)*nsy
1055 irec=1 + INT(iG/sNx) + nSx*nPx*(jG+j-1) + nSx*nPx*Ny*(k-1)
1056 & + nSx*nPx*Ny*nLocz*(irecord-1)
1057 else
5ae46f2adb Patr*1058 iG = 0
1059 jG = 0
1060 irec=j + sNy*(k-1) + sNy*nLocz*(irecord-1)
023d5a3a61 Patr*1061 endif
5ae46f2adb Patr*1062 if (filePrec .eq. precFloat32) then
1063 read(dUnit,rec=irec) r4seg
1064 #ifdef _BYTESWAPIO
1065 call MDS_BYTESWAPR4( sNx, r4seg )
ffa487b126 Alis*1066 #endif
5ae46f2adb Patr*1067 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*1068 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*1069 call MDS_SEG4toRS( j,bi,bj,k,nLocz, r4seg, .TRUE., arr )
b2fffc7e1a Jean*1070 #endif
5ae46f2adb Patr*1071 elseif (arrType .eq. 'RL') then
1072 call MDS_SEG4toRL( j,bi,bj,k,nLocz, r4seg, .TRUE., arr )
1073 else
1074 write(msgbuf,'(a)')
1075 & ' MDSREADFIELD_GL: illegal value for arrType'
1076 call print_error( msgbuf, mythid )
1077 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
1078 endif
1079 elseif (filePrec .eq. precFloat64) then
1080 read(dUnit,rec=irec) r8seg
1081 #ifdef _BYTESWAPIO
1082 call MDS_BYTESWAPR8( sNx, r8seg )
1083 #endif
1084 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*1085 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*1086 call MDS_SEG8toRS( j,bi,bj,k,nLocz, r8seg, .TRUE., arr )
b2fffc7e1a Jean*1087 #endif
5ae46f2adb Patr*1088 elseif (arrType .eq. 'RL') then
1089 call MDS_SEG8toRL( j,bi,bj,k,nLocz, r8seg, .TRUE., arr )
1090 else
1091 write(msgbuf,'(a)')
1092 & ' MDSREADFIELD_GL: illegal value for arrType'
1093 call print_error( msgbuf, mythid )
1094 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
1095 endif
1096 else
1097 write(msgbuf,'(a)')
1098 & ' MDSREADFIELD_GL: illegal value for filePrec'
1099 call print_error( msgbuf, mythid )
1100 stop 'ABNORMAL END: S/R MDSREADFIELD_GL'
1101 endif
1102 do ii=1,sNx
1103 arr_gl(ii,bi,ip,j,bj,jp,k)=arr(ii,j,k,bi,bj)
1104 enddo
1105
1106
1107 enddo
1108
1109 enddo
1110 if (.NOT. globalFile) then
1111 close( dUnit )
1112 fileIsOpen = .FALSE.
1113 endif
1114 endif
1115
1116 enddo
1117 enddo
1118
1119 enddo
1120 enddo
1121
1122
1123 if (fileIsOpen .AND. globalFile) then
1124 close( dUnit )
1125 fileIsOpen = .FALSE.
1126 endif
1127
eda676cb0f Patr*1128
1129 endif
1130
1131
1132 else
1133
1134 DO k=1,nLocz
1135
1136 #ifdef ALLOW_USE_MPI
b714306922 Jean*1137 IF( myProcId .EQ. 0 ) THEN
eda676cb0f Patr*1138 #else
1139 IF ( .TRUE. ) THEN
1140 #endif /* ALLOW_USE_MPI */
1141 irec = k+nNz*(irecord-1)
1142 if (filePrec .eq. precFloat32) then
1143 read(dUnit,rec=irec) xy_buffer_r4
1144 #ifdef _BYTESWAPIO
1145 call MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 )
1146 #endif
1147 DO J=1,Ny
1148 DO I=1,Nx
1149 global(I,J) = xy_buffer_r4(I,J)
1150 ENDDO
1151 ENDDO
1152 elseif (filePrec .eq. precFloat64) then
1153 read(dUnit,rec=irec) xy_buffer_r8
1154 #ifdef _BYTESWAPIO
1155 call MDS_BYTESWAPR8( x_size*y_size, xy_buffer_r8 )
1156 #endif
1157 DO J=1,Ny
1158 DO I=1,Nx
1159 global(I,J) = xy_buffer_r8(I,J)
1160 ENDDO
1161 ENDDO
1162 else
1163 write(msgbuf,'(a)')
1164 & ' MDSREADFIELD: illegal value for filePrec'
1165 call print_error( msgbuf, mythid )
1166 stop 'ABNORMAL END: S/R MDSREADFIELD'
1167 endif
1168 ENDIF
1169 DO jp=1,nPy
1170 DO ip=1,nPx
1171 DO bj = myByLo(myThid), myByHi(myThid)
1172 DO bi = myBxLo(myThid), myBxHi(myThid)
1173 DO J=1,sNy
1174 JJ=((jp-1)*nSy+(bj-1))*sNy+J
1175 DO I=1,sNx
1176 II=((ip-1)*nSx+(bi-1))*sNx+I
1177 arr_gl(i,bi,ip,j,bj,jp,k) = global(II,JJ)
1178 ENDDO
1179 ENDDO
1180 ENDDO
1181 ENDDO
1182 ENDDO
1183 ENDDO
1184
1185 ENDDO
1186
1187
1188 close( dUnit )
1189
023d5a3a61 Patr*1190 endif
1191
1192
5ae46f2adb Patr*1193 _END_MASTER( myThid )
1194
b714306922 Jean*1195 #else /* ALLOW_CTRL */
1196 STOP 'ABNORMAL END: S/R MDSREADFIELD_2D_GL is empty'
de7dc9fe18 Oliv*1197 #endif /* ALLOW_CTRL */
5ae46f2adb Patr*1198
b714306922 Jean*1199 RETURN
1200 END
1201
1202
5ae46f2adb Patr*1203
1204 SUBROUTINE MDSWRITEFIELD_2D_GL(
1205 I fName,
1206 I filePrec,
1207 I arrType,
1208 I nNz,
1209 I arr_gl,
1210 I irecord,
1211 I myIter,
1212 I myThid )
1213
1214
1215
eb5e2b9a92 Jean*1216
1217
1218
1219
1220
1221
1222
1223
5ae46f2adb Patr*1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250 implicit none
1251
1252 #include "SIZE.h"
1253 #include "EEPARAMS.h"
1254 #include "PARAMS.h"
1255
1256
1257 character*(*) fName
1258 integer filePrec
1259 character*(2) arrType
1260 integer nNz, nLocz
1261 parameter (nLocz = 1)
1262
1263
1264 _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,nLocz)
1265
1266 integer irecord
1267 integer myIter
1268 integer myThid
de7dc9fe18 Oliv*1269
1270 #ifdef ALLOW_CTRL
1271
5ae46f2adb Patr*1272
1273 integer ILNBLNK
1274 integer MDS_RECLEN
1275
47c8a35ff3 Jean*1276 character*(MAX_LEN_FNAM) dataFName,metaFName
023d5a3a61 Patr*1277 integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
5ae46f2adb Patr*1278 Real*4 r4seg(sNx)
1279 Real*8 r8seg(sNx)
1280 _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nLocz,nSx,nSy)
b714306922 Jean*1281 INTEGER dimList(3,3), nDims, map2gl(2)
1282 _RL dummyRL(1)
1283 CHARACTER*8 blank8c
5ae46f2adb Patr*1284 integer length_of_rec
1285 logical fileIsOpen
1286 character*(max_len_mbuf) msgbuf
023d5a3a61 Patr*1287
47c8a35ff3 Jean*1288 #ifdef ALLOW_USE_MPI
023d5a3a61 Patr*1289 integer ii,jj
98ddeeaedb Jean*1290
1291 integer x_size,y_size
023d5a3a61 Patr*1292 PARAMETER ( x_size = Nx )
1293 PARAMETER ( y_size = Ny )
1294 Real*4 xy_buffer_r4(x_size,y_size)
1295 Real*8 xy_buffer_r8(x_size,y_size)
1296 Real*8 global(Nx,Ny)
47c8a35ff3 Jean*1297 #endif
023d5a3a61 Patr*1298
6a53f18a53 Patr*1299
1300 integer pIL
1301
023d5a3a61 Patr*1302
b714306922 Jean*1303 DATA dummyRL(1) / 0. _d 0 /
1304 DATA blank8c / ' ' /
1305
5ae46f2adb Patr*1306
1307
1308
1309 _BEGIN_MASTER( myThid )
1310
b2fffc7e1a Jean*1311 #ifndef REAL4_IS_SLOW
1312 if (arrType .eq. 'RS') then
1313 write(msgbuf,'(a)')
1314 & ' MDSWRITEFIELD_GL is wrong for arrType="RS" (=real*4)'
1315 call print_error( msgbuf, mythid )
1316 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
1317 endif
1318 #endif
1319
5ae46f2adb Patr*1320
1321 if (irecord .LT. 1) then
1322 write(msgbuf,'(a,i9.8)')
1323 & ' MDSWRITEFIELD_GL: argument irecord = ',irecord
1324 call print_message( msgbuf, standardmessageunit,
1325 & SQUEEZE_RIGHT , mythid)
1326 write(msgbuf,'(a)')
1327 & ' MDSWRITEFIELD_GL: invalid value for irecord'
1328 call print_error( msgbuf, mythid )
1329 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
1330 endif
1331
1332
1333 fileIsOpen=.FALSE.
1334 IL=ILNBLNK( fName )
6a53f18a53 Patr*1335
1336 pIL = ILNBLNK( mdsioLocalDir )
1337
1338
1339
1340 if ( pIL.NE.0 ) then
1341 write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
1342 endif
1343
5ae46f2adb Patr*1344
1345
1346 call MDSFINDUNIT( dUnit, mythid )
1347
1348
023d5a3a61 Patr*1349
1350 #ifdef ALLOW_USE_MPI
1351 _END_MASTER( myThid )
1352
1353
1354 if (useSingleCpuIO) then
1355
1356
1357 _BEGIN_MASTER( myThid )
b714306922 Jean*1358 IF( myProcId .EQ. 0 ) THEN
47c8a35ff3 Jean*1359 write(dataFname,'(2a)') fName(1:IL),'.data'
023d5a3a61 Patr*1360 length_of_rec=MDS_RECLEN(filePrec,x_size*y_size,mythid)
1361 if (irecord .EQ. 1) then
1362 open( dUnit, file=dataFName, status=_NEW_STATUS,
1363 & access='direct', recl=length_of_rec )
1364 else
1365 open( dUnit, file=dataFName, status=_OLD_STATUS,
1366 & access='direct', recl=length_of_rec )
1367 endif
1368 ENDIF
1369 _END_MASTER( myThid )
1370
1371
1372 DO k=1,nLocz
b714306922 Jean*1373
023d5a3a61 Patr*1374 do jp=1,nPy
1375 do ip=1,nPx
1376 DO bj = myByLo(myThid), myByHi(myThid)
1377 DO bi = myBxLo(myThid), myBxHi(myThid)
1378 DO J=1,sNy
1379 JJ=((jp-1)*nSy+(bj-1))*sNy+J
1380 DO I=1,sNx
1381 II=((ip-1)*nSx+(bi-1))*sNx+I
1382 global(II,JJ) = arr_gl(i,bi,ip,j,bj,jp,k)
1383 ENDDO
1384 ENDDO
1385 ENDDO
1386 ENDDO
1387 enddo
1388 enddo
1389 _BEGIN_MASTER( myThid )
b714306922 Jean*1390 IF( myProcId .EQ. 0 ) THEN
023d5a3a61 Patr*1391 irec=k+nLocz*(irecord-1)
1392 if (filePrec .eq. precFloat32) then
1393 DO J=1,Ny
1394 DO I=1,Nx
1395 xy_buffer_r4(I,J) = global(I,J)
1396 ENDDO
1397 ENDDO
1398 #ifdef _BYTESWAPIO
1399 call MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 )
1400 #endif
1401 write(dUnit,rec=irec) xy_buffer_r4
1402 elseif (filePrec .eq. precFloat64) then
1403 DO J=1,Ny
1404 DO I=1,Nx
1405 xy_buffer_r8(I,J) = global(I,J)
1406 ENDDO
1407 ENDDO
1408 #ifdef _BYTESWAPIO
1409 call MDS_BYTESWAPR8( x_size*y_size, xy_buffer_r8 )
1410 #endif
1411 write(dUnit,rec=irec) xy_buffer_r8
1412 else
1413 write(msgbuf,'(a)')
1414 & ' MDSWRITEFIELD: illegal value for filePrec'
1415 call print_error( msgbuf, mythid )
1416 stop 'ABNORMAL END: S/R MDSWRITEFIELD'
1417 endif
1418 ENDIF
1419 _END_MASTER( myThid )
1420 ENDDO
1421
1422
1423 _BEGIN_MASTER( myThid )
b714306922 Jean*1424 IF( myProcId .EQ. 0 ) THEN
023d5a3a61 Patr*1425 close( dUnit )
47c8a35ff3 Jean*1426 write(metaFName,'(2a)') fName(1:IL),'.meta'
023d5a3a61 Patr*1427 dimList(1,1)=Nx
1428 dimList(2,1)=1
1429 dimList(3,1)=Nx
1430 dimList(1,2)=Ny
1431 dimList(2,2)=1
1432 dimList(3,2)=Ny
1433 dimList(1,3)=nLocz
1434 dimList(2,3)=1
1435 dimList(3,3)=nLocz
b714306922 Jean*1436 nDims=3
1437 if (nLocz .EQ. 1) nDims=2
1438 map2gl(1) = 0
1439 map2gl(2) = 1
1440 CALL MDS_WRITE_META(
1441 I metaFName, dataFName, the_run_name, ' ',
1442 I filePrec, nDims, dimList, map2gl, 0, blank8c,
a50692f9cd Jean*1443 I 0, dummyRL, oneRL, irecord, myIter, myThid )
023d5a3a61 Patr*1444 ENDIF
1445 _END_MASTER( myThid )
1446
1447 _BARRIER
1448
1449 elseif ( .NOT. useSingleCpuIO ) then
1450 _BEGIN_MASTER( myThid )
1451 #endif /* ALLOW_USE_MPI */
1452
1453
b714306922 Jean*1454
5ae46f2adb Patr*1455 do jp=1,nPy
1456 do ip=1,nPx
1457
1458 do bj=1,nSy
1459 do bi=1,nSx
1460
1461 iG=bi+(ip-1)*nsx
1462 jG=bj+(jp-1)*nsy
47c8a35ff3 Jean*1463 write(dataFname,'(2a,i3.3,a,i3.3,a)')
5ae46f2adb Patr*1464 & fName(1:IL),'.',iG,'.',jG,'.data'
1465 if (irecord .EQ. 1) then
1466 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
1467 open( dUnit, file=dataFName, status=_NEW_STATUS,
1468 & access='direct', recl=length_of_rec )
1469 fileIsOpen=.TRUE.
1470 else
1471 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
1472 open( dUnit, file=dataFName, status=_OLD_STATUS,
1473 & access='direct', recl=length_of_rec )
1474 fileIsOpen=.TRUE.
1475 endif
1476 if (fileIsOpen) then
1477 do k=1,nLocz
1478 do j=1,sNy
47c8a35ff3 Jean*1479 do i=1,sNx
1480 arr(i,j,k,bi,bj)=arr_gl(i,bi,ip,j,bj,jp,k)
5ae46f2adb Patr*1481 enddo
1482 iG = 0
1483 jG = 0
1484 irec=j + sNy*(k-1) + sNy*nLocz*(irecord-1)
1485 if (filePrec .eq. precFloat32) then
1486 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*1487 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*1488 call MDS_SEG4toRS( j,bi,bj,k,nLocz, r4seg, .FALSE., arr )
b2fffc7e1a Jean*1489 #endif
5ae46f2adb Patr*1490 elseif (arrType .eq. 'RL') then
1491 call MDS_SEG4toRL( j,bi,bj,k,nLocz, r4seg, .FALSE., arr )
1492 else
1493 write(msgbuf,'(a)')
1494 & ' MDSWRITEFIELD_GL: illegal value for arrType'
1495 call print_error( msgbuf, mythid )
1496 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
1497 endif
1498 #ifdef _BYTESWAPIO
1499 call MDS_BYTESWAPR4( sNx, r4seg )
1500 #endif
1501 write(dUnit,rec=irec) r4seg
1502 elseif (filePrec .eq. precFloat64) then
1503 if (arrType .eq. 'RS') then
b2fffc7e1a Jean*1504 #ifdef REAL4_IS_SLOW
5ae46f2adb Patr*1505 call MDS_SEG8toRS( j,bi,bj,k,nLocz, r8seg, .FALSE., arr )
b2fffc7e1a Jean*1506 #endif
5ae46f2adb Patr*1507 elseif (arrType .eq. 'RL') then
1508 call MDS_SEG8toRL( j,bi,bj,k,nLocz, r8seg, .FALSE., arr )
1509 else
1510 write(msgbuf,'(a)')
1511 & ' MDSWRITEFIELD_GL: illegal value for arrType'
1512 call print_error( msgbuf, mythid )
1513 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
1514 endif
1515 #ifdef _BYTESWAPIO
1516 call MDS_BYTESWAPR8( sNx, r8seg )
1517 #endif
1518 write(dUnit,rec=irec) r8seg
1519 else
1520 write(msgbuf,'(a)')
1521 & ' MDSWRITEFIELD_GL: illegal value for filePrec'
1522 call print_error( msgbuf, mythid )
1523 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
1524 endif
1525
1526 enddo
1527
1528 enddo
1529 else
1530 write(msgbuf,'(a)')
1531 & ' MDSWRITEFIELD_GL: I should never get to this point'
1532 call print_error( msgbuf, mythid )
1533 stop 'ABNORMAL END: S/R MDSWRITEFIELD_GL'
1534 endif
1535
1536 if (fileIsOpen) then
1537 close( dUnit )
1538 fileIsOpen = .FALSE.
1539 endif
1540
1541 iG=bi+(ip-1)*nsx
1542 jG=bj+(jp-1)*nsy
47c8a35ff3 Jean*1543 write(metaFname,'(2a,i3.3,a,i3.3,a)')
5ae46f2adb Patr*1544 & fName(1:IL),'.',iG,'.',jG,'.meta'
1545 dimList(1,1)=Nx
1546 dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1
1547 dimList(3,1)=((ip-1)*nSx+bi)*sNx
1548 dimList(1,2)=Ny
1549 dimList(2,2)=((jp-1)*nSy+(bj-1))*sNy+1
1550 dimList(3,2)=((jp-1)*nSy+bj)*sNy
1551 dimList(1,3)=Nr
1552 dimList(2,3)=1
1553 dimList(3,3)=Nr
b714306922 Jean*1554 nDims=3
1555 if (nLocz .EQ. 1) nDims=2
1556 map2gl(1) = 0
1557 map2gl(2) = 1
1558 CALL MDS_WRITE_META(
1559 I metaFName, dataFName, the_run_name, ' ',
1560 I filePrec, nDims, dimList, map2gl, 0, blank8c,
a50692f9cd Jean*1561 I 0, dummyRL, oneRL, irecord, myIter, myThid )
5ae46f2adb Patr*1562
1563 enddo
1564 enddo
1565
1566 enddo
1567 enddo
1568
1569 _END_MASTER( myThid )
ffa487b126 Alis*1570
023d5a3a61 Patr*1571 #ifdef ALLOW_USE_MPI
1572
1573 endif
1574 #endif /* ALLOW_USE_MPI */
1575
b714306922 Jean*1576 #else /* ALLOW_CTRL */
1577 STOP 'ABNORMAL END: S/R MDSWRITEFIELD_2D_GL is empty'
de7dc9fe18 Oliv*1578 #endif /* ALLOW_CTRL */
ffa487b126 Alis*1579
b714306922 Jean*1580 RETURN
1581 END