/[MITgcm]/MITgcm/pkg/mdsio/mdsio_gl.F
ViewVC logotype

Diff of /MITgcm/pkg/mdsio/mdsio_gl.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.8 by heimbach, Wed Jan 12 20:33:13 2005 UTC revision 1.16 by jahn, Tue Dec 30 00:14:05 2008 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2    C $Name$
3    
4  #include "MDSIO_OPTIONS.h"  #include "MDSIO_OPTIONS.h"
5    
# Line 78  C Routine arguments Line 79  C Routine arguments
79        _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,Nr)        _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,Nr)
80        integer irecord        integer irecord
81        integer myThid        integer myThid
82    
83    #ifdef ALLOW_CTRL
84    
85  C Functions  C Functions
86        integer ILNBLNK        integer ILNBLNK
87        integer MDS_RECLEN        integer MDS_RECLEN
88  C Local variables  C Local variables
89        character*(80) dataFName        character*(MAX_LEN_FNAM) dataFName
90        integer ip,jp,iG,jG,irec,bi,bj,ii,j,k,dUnit,IL        integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
91        logical exst        logical exst
92        _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,Nr,nSx,nSy)        _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,Nr,nSx,nSy)
93        Real*4 r4seg(sNx)        Real*4 r4seg(sNx)
# Line 91  C Local variables Line 95  C Local variables
95        logical globalFile,fileIsOpen        logical globalFile,fileIsOpen
96        integer length_of_rec        integer length_of_rec
97        character*(max_len_mbuf) msgbuf        character*(max_len_mbuf) msgbuf
98    cph-usesingle(
99          integer ii,jj
100    c     integer iG_IO,jG_IO,npe
101          integer x_size,y_size
102          PARAMETER ( x_size = Nx )
103          PARAMETER ( y_size = Ny )
104          Real*4 xy_buffer_r4(x_size,y_size)
105          Real*8 xy_buffer_r8(x_size,y_size)
106          Real*8 global(Nx,Ny)
107    c     _RL    local(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
108    cph-usesingle)
109    CMM(
110          integer pIL
111    CMM)
112    
113  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
114    
115  C Only do I/O if I am the master thread  C Only do I/O if I am the master thread
# Line 112  C Assume nothing Line 131  C Assume nothing
131        globalFile = .FALSE.        globalFile = .FALSE.
132        fileIsOpen = .FALSE.        fileIsOpen = .FALSE.
133        IL=ILNBLNK( fName )        IL=ILNBLNK( fName )
134    CMM(
135          pIL = ILNBLNK( mdsioLocalDir )
136    CMM)
137    CMM(
138    C Assign special directory
139          if ( pIL.NE.0 ) then
140           write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
141          endif
142    CMM)
143    
144  C Assign a free unit number as the I/O channel for this routine  C Assign a free unit number as the I/O channel for this routine
145        call MDSFINDUNIT( dUnit, mythid )        call MDSFINDUNIT( dUnit, mythid )
146    
147          if ( useSingleCPUIO ) then
148    
149    #ifdef ALLOW_USE_MPI
150            IF( mpiMyId .EQ. 0 ) THEN
151    #else
152            IF ( .TRUE. ) THEN
153    #endif /* ALLOW_USE_MPI */
154    
155  C Check first for global file with simple name (ie. fName)  C Check first for global file with simple name (ie. fName)
156        dataFName = fName           dataFName = fName
157        inquire( file=dataFname, exist=exst )           inquire( file=dataFname, exist=exst )
158        if (exst) then           if (exst) globalFile = .TRUE.
        write(msgbuf,'(a,a)')  
      &   ' MDSREADFIELD: opening global file: ',dataFName  
        call print_message( msgbuf, standardmessageunit,  
      &                     SQUEEZE_RIGHT , mythid)  
       endif  
159    
160  C If negative check for global file with MDS name (ie. fName.data)  C If negative check for global file with MDS name (ie. fName.data)
161        if (.NOT. globalFile) then           if (.NOT. globalFile) then
162         write(dataFname(1:80),'(2a)') fName(1:IL),'.data'            write(dataFname,'(2a)') fName(1:IL),'.data'
163              inquire( file=dataFname, exist=exst )
164              if (exst) globalFile = .TRUE.
165             endif
166    
167    C If global file is visible to process 0, then open it here.
168    C Otherwise stop program.
169             if ( globalFile) then
170              length_of_rec=MDS_RECLEN( filePrec, x_size*y_size, mythid )
171              open( dUnit, file=dataFName, status='old',
172         &         access='direct', recl=length_of_rec )
173             else
174              write(msgbuf,'(2a)')
175         &      ' MDSREADFIELD: filename: ',dataFName(1:IL)
176              call print_message( msgbuf, standardmessageunit,
177         &                        SQUEEZE_RIGHT , mythid)
178              call print_error( msgbuf, mythid )
179              write(msgbuf,'(a)')
180         &      ' MDSREADFIELD: File does not exist'
181              call print_message( msgbuf, standardmessageunit,
182         &                        SQUEEZE_RIGHT , mythid)
183              call print_error( msgbuf, mythid )
184              stop 'ABNORMAL END: S/R MDSREADFIELD'
185             endif
186    
187            ENDIF
188    
189    c-- useSingleCpuIO
190          else
191    C Only do I/O if I am the master thread
192    
193    C Check first for global file with simple name (ie. fName)
194           dataFName = fName
195         inquire( file=dataFname, exist=exst )         inquire( file=dataFname, exist=exst )
196         if (exst) then         if (exst) then
197          write(msgbuf,'(a,a)')          write(msgbuf,'(a,a)')
198       &    ' MDSREADFIELD_GL: opening global file: ',dataFName       &    ' MDSREADFIELD: opening global file: ',dataFName(1:IL)
199          call print_message( msgbuf, standardmessageunit,          call print_message( msgbuf, standardmessageunit,
200       &                      SQUEEZE_RIGHT , mythid)       &                      SQUEEZE_RIGHT , mythid)
         globalFile = .TRUE.  
201         endif         endif
202    
203    C If negative check for global file with MDS name (ie. fName.data)
204           if (.NOT. globalFile) then
205            write(dataFname,'(2a)') fName(1:IL),'.data'
206            inquire( file=dataFname, exist=exst )
207            if (exst) then
208             write(msgbuf,'(a,a)')
209         &     ' MDSREADFIELD_GL: opening global file: ',dataFName(1:IL+5)
210             call print_message( msgbuf, standardmessageunit,
211         &                       SQUEEZE_RIGHT , mythid)
212             globalFile = .TRUE.
213            endif
214           endif
215    
216    c-- useSingleCpuIO
217        endif        endif
218    
219        if ( .not. ( globalFile .and. useSingleCPUIO ) ) then        if ( .not. useSingleCpuIO ) then
220    cph      if ( .not. ( globalFile .and. useSingleCPUIO ) ) then
221          if ( .not. ( globalFile ) ) then
222    
223  C If we are reading from a global file then we open it here  C If we are reading from a global file then we open it here
224        if (globalFile) then        if (globalFile) then
# Line 159  C If we are reading from a tiled MDS fil Line 238  C If we are reading from a tiled MDS fil
238          if (.NOT. globalFile) then          if (.NOT. globalFile) then
239           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles
240           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles
241           write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')           write(dataFname,'(2a,i3.3,a,i3.3,a)')
242       &              fName(1:IL),'.',iG,'.',jG,'.data'       &              fName(1:IL),'.',iG,'.',jG,'.data'
243           inquire( file=dataFname, exist=exst )           inquire( file=dataFname, exist=exst )
244  C Of course, we only open the file if the tile is "active"  C Of course, we only open the file if the tile is "active"
# Line 167  C (This is a place-holder for the active Line 246  C (This is a place-holder for the active
246           if (exst) then           if (exst) then
247            if ( debugLevel .GE. debLevA ) then            if ( debugLevel .GE. debLevA ) then
248             write(msgbuf,'(a,a)')             write(msgbuf,'(a,a)')
249       &      ' MDSREADFIELD_GL: opening file: ',dataFName       &      ' MDSREADFIELD_GL: opening file: ',dataFName(1:IL+13)
250             call print_message( msgbuf, standardmessageunit,             call print_message( msgbuf, standardmessageunit,
251       &                        SQUEEZE_RIGHT , mythid)       &                        SQUEEZE_RIGHT , mythid)
252            endif            endif
# Line 178  C (This is a place-holder for the active Line 257  C (This is a place-holder for the active
257           else           else
258            fileIsOpen=.FALSE.            fileIsOpen=.FALSE.
259            write(msgbuf,'(a,a)')            write(msgbuf,'(a,a)')
260       &      ' MDSREADFIELD_GL: filename: ',dataFName       &      ' MDSREADFIELD_GL: filename: ',dataFName(1:IL+13)
261            call print_message( msgbuf, standardmessageunit,            call print_message( msgbuf, standardmessageunit,
262       &                        SQUEEZE_RIGHT , mythid)       &                        SQUEEZE_RIGHT , mythid)
263            call print_error( msgbuf, mythid )            call print_error( msgbuf, mythid )
# Line 266  C If global file was opened then close i Line 345  C If global file was opened then close i
345         fileIsOpen = .FALSE.         fileIsOpen = .FALSE.
346        endif        endif
347    
348    c      end of if ( .not. ( globalFile ) ) then
349          endif
350    
351    c      else of if ( .not. ( globalFile .and. useSingleCPUIO ) ) then
352          else
353    
354           DO k=1,nNz
355    
356    #ifdef ALLOW_USE_MPI
357             IF( mpiMyId .EQ. 0 ) THEN
358    #else
359             IF ( .TRUE. ) THEN
360    #endif /* ALLOW_USE_MPI */
361              irec = k+nNz*(irecord-1)
362              if (filePrec .eq. precFloat32) then
363               read(dUnit,rec=irec) xy_buffer_r4
364    #ifdef _BYTESWAPIO
365               call MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 )
366    #endif
367               DO J=1,Ny
368                DO I=1,Nx
369                 global(I,J) = xy_buffer_r4(I,J)
370                ENDDO
371               ENDDO
372              elseif (filePrec .eq. precFloat64) then
373               read(dUnit,rec=irec) xy_buffer_r8
374    #ifdef _BYTESWAPIO
375               call MDS_BYTESWAPR8( x_size*y_size, xy_buffer_r8 )
376    #endif
377               DO J=1,Ny
378                DO I=1,Nx
379                 global(I,J) = xy_buffer_r8(I,J)
380                ENDDO
381               ENDDO
382              else
383               write(msgbuf,'(a)')
384         &            ' MDSREADFIELD: illegal value for filePrec'
385               call print_error( msgbuf, mythid )
386               stop 'ABNORMAL END: S/R MDSREADFIELD'
387              endif
388             ENDIF
389            DO jp=1,nPy
390             DO ip=1,nPx
391              DO bj = myByLo(myThid), myByHi(myThid)
392               DO bi = myBxLo(myThid), myBxHi(myThid)
393                DO J=1,sNy
394                 JJ=((jp-1)*nSy+(bj-1))*sNy+J
395                 DO I=1,sNx
396                  II=((ip-1)*nSx+(bi-1))*sNx+I
397                  arr_gl(i,bi,ip,j,bj,jp,k) = global(II,JJ)
398                 ENDDO
399                ENDDO
400               ENDDO
401              ENDDO
402             ENDDO
403            ENDDO
404    
405           ENDDO
406    c      ENDDO k=1,nNz
407    
408            close( dUnit )
409    
410        endif        endif
411  c      end of if ( .not. ( globalFile .and. useSingleCPUIO ) ) then  c      end of if ( .not. ( globalFile .and. useSingleCPUIO ) ) then
412    
413        _END_MASTER( myThid )        _END_MASTER( myThid )
414    
415    #endif /* ALLOW_CTRL */
416  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
417        return        return
418        end        end
# Line 342  cph) Line 484  cph)
484        integer irecord        integer irecord
485        integer myIter        integer myIter
486        integer myThid        integer myThid
487    
488    #ifdef ALLOW_CTRL
489    
490  C Functions  C Functions
491        integer ILNBLNK        integer ILNBLNK
492        integer MDS_RECLEN        integer MDS_RECLEN
493  C Local variables  C Local variables
494        character*(80) dataFName,metaFName        character*(MAX_LEN_FNAM) dataFName,metaFName
495        integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL        integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
496        Real*4 r4seg(sNx)        Real*4 r4seg(sNx)
497        Real*8 r8seg(sNx)        Real*8 r8seg(sNx)
# Line 356  C Local variables Line 501  C Local variables
501        logical fileIsOpen        logical fileIsOpen
502        character*(max_len_mbuf) msgbuf        character*(max_len_mbuf) msgbuf
503  cph-usesingle(  cph-usesingle(
504    #ifdef ALLOW_USE_MPI
505        integer ii,jj        integer ii,jj
506        integer x_size,y_size,iG_IO,jG_IO,npe  c     integer iG_IO,jG_IO,npe
507          integer x_size,y_size
508        PARAMETER ( x_size = Nx )        PARAMETER ( x_size = Nx )
509        PARAMETER ( y_size = Ny )        PARAMETER ( y_size = Ny )
510        Real*4 xy_buffer_r4(x_size,y_size)        Real*4 xy_buffer_r4(x_size,y_size)
511        Real*8 xy_buffer_r8(x_size,y_size)        Real*8 xy_buffer_r8(x_size,y_size)
512        Real*8 global(Nx,Ny)        Real*8 global(Nx,Ny)
513    #endif
514  cph-usesingle)  cph-usesingle)
515    CMM(
516          integer pIL
517    CMM)
518    
519  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
520    
# Line 385  C Record number must be >= 1 Line 536  C Record number must be >= 1
536  C Assume nothing  C Assume nothing
537        fileIsOpen=.FALSE.        fileIsOpen=.FALSE.
538        IL=ILNBLNK( fName )        IL=ILNBLNK( fName )
539    CMM(
540          pIL = ILNBLNK( mdsioLocalDir )
541    CMM)
542    CMM(
543    C Assign special directory
544          if ( pIL.NE.0 ) then
545           write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
546          endif
547    CMM)
548    
549  C Assign a free unit number as the I/O channel for this routine  C Assign a free unit number as the I/O channel for this routine
550        call MDSFINDUNIT( dUnit, mythid )        call MDSFINDUNIT( dUnit, mythid )
# Line 399  C globalFile is too slow, then try using Line 559  C globalFile is too slow, then try using
559  C Master thread of process 0, only, opens a global file  C Master thread of process 0, only, opens a global file
560         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
561          IF( mpiMyId .EQ. 0 ) THEN          IF( mpiMyId .EQ. 0 ) THEN
562           write(dataFname(1:80),'(2a)') fName(1:IL),'.data'           write(dataFname,'(2a)') fName(1:IL),'.data'
563           length_of_rec=MDS_RECLEN(filePrec,x_size*y_size,mythid)           length_of_rec=MDS_RECLEN(filePrec,x_size*y_size,mythid)
564           if (irecord .EQ. 1) then           if (irecord .EQ. 1) then
565            open( dUnit, file=dataFName, status=_NEW_STATUS,            open( dUnit, file=dataFName, status=_NEW_STATUS,
# Line 466  C Close data-file and create meta-file Line 626  C Close data-file and create meta-file
626         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
627          IF( mpiMyId .EQ. 0 ) THEN          IF( mpiMyId .EQ. 0 ) THEN
628           close( dUnit )           close( dUnit )
629           write(metaFName(1:80),'(2a)') fName(1:IL),'.meta'           write(metaFName,'(2a)') fName(1:IL),'.meta'
630           dimList(1,1)=Nx           dimList(1,1)=Nx
631           dimList(2,1)=1           dimList(2,1)=1
632           dimList(3,1)=Nx           dimList(3,1)=Nx
# Line 499  C Loop over all tiles Line 659  C Loop over all tiles
659  C If we are writing to a tiled MDS file then we open each one here  C If we are writing to a tiled MDS file then we open each one here
660           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles
661           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles
662           write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')           write(dataFname,'(2a,i3.3,a,i3.3,a)')
663       &              fName(1:IL),'.',iG,'.',jG,'.data'       &              fName(1:IL),'.',iG,'.',jG,'.data'
664           if (irecord .EQ. 1) then           if (irecord .EQ. 1) then
665            length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )            length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
# Line 515  C If we are writing to a tiled MDS file Line 675  C If we are writing to a tiled MDS file
675          if (fileIsOpen) then          if (fileIsOpen) then
676           do k=1,Nr           do k=1,Nr
677            do j=1,sNy            do j=1,sNy
678               do ii=1,sNx               do i=1,sNx
679                  arr(ii,j,k,bi,bj)=arr_gl(ii,bi,ip,j,bj,jp,k)                  arr(i,j,k,bi,bj)=arr_gl(i,bi,ip,j,bj,jp,k)
680               enddo               enddo
681              iG = 0              iG = 0
682              jG = 0              jG = 0
# Line 575  C If we were writing to a tiled MDS file Line 735  C If we were writing to a tiled MDS file
735  C Create meta-file for each tile if we are tiling  C Create meta-file for each tile if we are tiling
736           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles
737           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles
738           write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)')           write(metaFname,'(2a,i3.3,a,i3.3,a)')
739       &              fName(1:IL),'.',iG,'.',jG,'.meta'       &              fName(1:IL),'.',iG,'.',jG,'.meta'
740           dimList(1,1)=Nx           dimList(1,1)=Nx
741           dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1           dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1
# Line 606  C endif useSingleCpuIO Line 766  C endif useSingleCpuIO
766  #endif /* ALLOW_USE_MPI */  #endif /* ALLOW_USE_MPI */
767  cph-usesingle)  cph-usesingle)
768    
769    #endif /* ALLOW_CTRL */
770  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
771        return        return
772        end        end
# Line 664  C Routine arguments Line 825  C Routine arguments
825        _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,nLocz)        _RL arr_gl(sNx,nSx,nPx,sNy,nSy,nPy,nLocz)
826        integer irecord        integer irecord
827        integer myThid        integer myThid
828    
829    #ifdef ALLOW_CTRL
830    
831  C Functions  C Functions
832        integer ILNBLNK        integer ILNBLNK
833        integer MDS_RECLEN        integer MDS_RECLEN
834  C Local variables  C Local variables
835        character*(80) dataFName        character*(MAX_LEN_FNAM) dataFName
836        integer ip,jp,iG,jG,irec,bi,bj,ii,j,k,dUnit,IL        integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
837        logical exst        logical exst
838        _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nLocz,nSx,nSy)        _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nLocz,nSx,nSy)
839        Real*4 r4seg(sNx)        Real*4 r4seg(sNx)
# Line 677  C Local variables Line 841  C Local variables
841        logical globalFile,fileIsOpen        logical globalFile,fileIsOpen
842        integer length_of_rec        integer length_of_rec
843        character*(max_len_mbuf) msgbuf        character*(max_len_mbuf) msgbuf
844    cph-usesingle(
845          integer ii,jj
846    c     integer iG_IO,jG_IO,npe
847          integer x_size,y_size
848          PARAMETER ( x_size = Nx )
849          PARAMETER ( y_size = Ny )
850          Real*4 xy_buffer_r4(x_size,y_size)
851          Real*8 xy_buffer_r8(x_size,y_size)
852          Real*8 global(Nx,Ny)
853    c     _RL    local(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
854    cph-usesingle)
855    CMM(
856          integer pIL
857    CMM)
858    
859  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
860    
861  C Only do I/O if I am the master thread  C Only do I/O if I am the master thread
# Line 698  C Assume nothing Line 877  C Assume nothing
877        globalFile = .FALSE.        globalFile = .FALSE.
878        fileIsOpen = .FALSE.        fileIsOpen = .FALSE.
879        IL=ILNBLNK( fName )        IL=ILNBLNK( fName )
880    CMM(
881          pIL = ILNBLNK( mdsioLocalDir )
882    CMM)
883    CMM(
884    C Assign special directory
885          if ( pIL.NE.0 ) then
886           write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
887          endif
888    CMM)
889    
890  C Assign a free unit number as the I/O channel for this routine  C Assign a free unit number as the I/O channel for this routine
891        call MDSFINDUNIT( dUnit, mythid )        call MDSFINDUNIT( dUnit, mythid )
892    
893          if ( useSingleCPUIO ) then
894    
895    C master thread of process 0, only, opens a global file
896    #ifdef ALLOW_USE_MPI
897            IF( mpiMyId .EQ. 0 ) THEN
898    #else
899            IF ( .TRUE. ) THEN
900    #endif /* ALLOW_USE_MPI */
901    
902  C Check first for global file with simple name (ie. fName)  C Check first for global file with simple name (ie. fName)
903        dataFName = fName           dataFName = fName
904        inquire( file=dataFname, exist=exst )           inquire( file=dataFname, exist=exst )
905        if (exst) then           if (exst) globalFile = .TRUE.
        write(msgbuf,'(a,a)')  
      &   ' MDSREADFIELD: opening global file: ',dataFName  
        call print_message( msgbuf, standardmessageunit,  
      &                     SQUEEZE_RIGHT , mythid)  
       endif  
906    
907  C If negative check for global file with MDS name (ie. fName.data)  C If negative check for global file with MDS name (ie. fName.data)
908        if (.NOT. globalFile) then           if (.NOT. globalFile) then
909         write(dataFname(1:80),'(2a)') fName(1:IL),'.data'            write(dataFname,'(2a)') fName(1:IL),'.data'
910              inquire( file=dataFname, exist=exst )
911              if (exst) globalFile = .TRUE.
912             endif
913    
914    C If global file is visible to process 0, then open it here.
915    C Otherwise stop program.
916             if ( globalFile) then
917              length_of_rec=MDS_RECLEN( filePrec, x_size*y_size, mythid )
918              open( dUnit, file=dataFName, status='old',
919         &         access='direct', recl=length_of_rec )
920             else
921              write(msgbuf,'(2a)')
922         &      ' MDSREADFIELD: filename: ',dataFName(1:IL)
923              call print_message( msgbuf, standardmessageunit,
924         &                        SQUEEZE_RIGHT , mythid)
925              call print_error( msgbuf, mythid )
926              write(msgbuf,'(a)')
927         &      ' MDSREADFIELD: File does not exist'
928              call print_message( msgbuf, standardmessageunit,
929         &                        SQUEEZE_RIGHT , mythid)
930              call print_error( msgbuf, mythid )
931              stop 'ABNORMAL END: S/R MDSREADFIELD'
932             endif
933    
934            ENDIF
935    
936    c-- useSingleCpuIO
937          else
938    
939    C Check first for global file with simple name (ie. fName)
940           dataFName = fName
941         inquire( file=dataFname, exist=exst )         inquire( file=dataFname, exist=exst )
942         if (exst) then         if (exst) then
943          write(msgbuf,'(a,a)')          write(msgbuf,'(a,a)')
944       &    ' MDSREADFIELD_GL: opening global file: ',dataFName       &    ' MDSREADFIELD: opening global file: ',dataFName(1:IL)
945          call print_message( msgbuf, standardmessageunit,          call print_message( msgbuf, standardmessageunit,
946       &                      SQUEEZE_RIGHT , mythid)       &                      SQUEEZE_RIGHT , mythid)
         globalFile = .TRUE.  
947         endif         endif
948    
949    C If negative check for global file with MDS name (ie. fName.data)
950           if (.NOT. globalFile) then
951            write(dataFname,'(2a)') fName(1:IL),'.data'
952            inquire( file=dataFname, exist=exst )
953            if (exst) then
954             write(msgbuf,'(a,a)')
955         &     ' MDSREADFIELD_GL: opening global file: ',dataFName(1:IL+5)
956             call print_message( msgbuf, standardmessageunit,
957         &                       SQUEEZE_RIGHT , mythid)
958             globalFile = .TRUE.
959            endif
960           endif
961    
962    c-- useSingleCpuIO
963        endif        endif
964    
965        if ( .not. ( globalFile .and. useSingleCPUIO ) ) then        if ( .not. useSingleCpuIO ) then
966    cph      if ( .not. ( globalFile .and. useSingleCPUIO ) ) then
967          if ( .not. ( globalFile ) ) then
968    
969  C If we are reading from a global file then we open it here  C If we are reading from a global file then we open it here
970        if (globalFile) then        if (globalFile) then
# Line 745  C If we are reading from a tiled MDS fil Line 984  C If we are reading from a tiled MDS fil
984          if (.NOT. globalFile) then          if (.NOT. globalFile) then
985           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles
986           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles
987           write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')           write(dataFname,'(2a,i3.3,a,i3.3,a)')
988       &              fName(1:IL),'.',iG,'.',jG,'.data'       &              fName(1:IL),'.',iG,'.',jG,'.data'
989           inquire( file=dataFname, exist=exst )           inquire( file=dataFname, exist=exst )
990  C Of course, we only open the file if the tile is "active"  C Of course, we only open the file if the tile is "active"
# Line 753  C (This is a place-holder for the active Line 992  C (This is a place-holder for the active
992           if (exst) then           if (exst) then
993            if ( debugLevel .GE. debLevA ) then            if ( debugLevel .GE. debLevA ) then
994             write(msgbuf,'(a,a)')             write(msgbuf,'(a,a)')
995       &      ' MDSREADFIELD_GL: opening file: ',dataFName       &      ' MDSREADFIELD_GL: opening file: ',dataFName(1:IL+13)
996             call print_message( msgbuf, standardmessageunit,             call print_message( msgbuf, standardmessageunit,
997       &                        SQUEEZE_RIGHT , mythid)       &                        SQUEEZE_RIGHT , mythid)
998            endif            endif
# Line 764  C (This is a place-holder for the active Line 1003  C (This is a place-holder for the active
1003           else           else
1004            fileIsOpen=.FALSE.            fileIsOpen=.FALSE.
1005            write(msgbuf,'(a,a)')            write(msgbuf,'(a,a)')
1006       &      ' MDSREADFIELD_GL: filename: ',dataFName       &      ' MDSREADFIELD_GL: filename: ',dataFName(1:IL+13)
1007            call print_message( msgbuf, standardmessageunit,            call print_message( msgbuf, standardmessageunit,
1008       &                        SQUEEZE_RIGHT , mythid)       &                        SQUEEZE_RIGHT , mythid)
1009            call print_error( msgbuf, mythid )            call print_error( msgbuf, mythid )
# Line 852  C If global file was opened then close i Line 1091  C If global file was opened then close i
1091         fileIsOpen = .FALSE.         fileIsOpen = .FALSE.
1092        endif        endif
1093    
1094    c      end of if ( .not. ( globalFile ) ) then
1095          endif
1096    
1097    c      else of if ( .not. ( globalFile .and. useSingleCPUIO ) ) then
1098          else
1099    
1100           DO k=1,nLocz
1101    
1102    #ifdef ALLOW_USE_MPI
1103             IF( mpiMyId .EQ. 0 ) THEN
1104    #else
1105             IF ( .TRUE. ) THEN
1106    #endif /* ALLOW_USE_MPI */
1107              irec = k+nNz*(irecord-1)
1108              if (filePrec .eq. precFloat32) then
1109               read(dUnit,rec=irec) xy_buffer_r4
1110    #ifdef _BYTESWAPIO
1111               call MDS_BYTESWAPR4( x_size*y_size, xy_buffer_r4 )
1112    #endif
1113               DO J=1,Ny
1114                DO I=1,Nx
1115                 global(I,J) = xy_buffer_r4(I,J)
1116                ENDDO
1117               ENDDO
1118              elseif (filePrec .eq. precFloat64) then
1119               read(dUnit,rec=irec) xy_buffer_r8
1120    #ifdef _BYTESWAPIO
1121               call MDS_BYTESWAPR8( x_size*y_size, xy_buffer_r8 )
1122    #endif
1123               DO J=1,Ny
1124                DO I=1,Nx
1125                 global(I,J) = xy_buffer_r8(I,J)
1126                ENDDO
1127               ENDDO
1128              else
1129               write(msgbuf,'(a)')
1130         &            ' MDSREADFIELD: illegal value for filePrec'
1131               call print_error( msgbuf, mythid )
1132               stop 'ABNORMAL END: S/R MDSREADFIELD'
1133              endif
1134             ENDIF
1135            DO jp=1,nPy
1136             DO ip=1,nPx
1137              DO bj = myByLo(myThid), myByHi(myThid)
1138               DO bi = myBxLo(myThid), myBxHi(myThid)
1139                DO J=1,sNy
1140                 JJ=((jp-1)*nSy+(bj-1))*sNy+J
1141                 DO I=1,sNx
1142                  II=((ip-1)*nSx+(bi-1))*sNx+I
1143                  arr_gl(i,bi,ip,j,bj,jp,k) = global(II,JJ)
1144                 ENDDO
1145                ENDDO
1146               ENDDO
1147              ENDDO
1148             ENDDO
1149            ENDDO
1150    
1151           ENDDO
1152    c      ENDDO k=1,nNz
1153    
1154            close( dUnit )
1155    
1156        endif        endif
1157  c      end of if ( .not. ( globalFile .and. useSingleCPUIO ) ) then  c      end of if ( .not. ( globalFile .and. useSingleCPUIO ) ) then
1158    
1159        _END_MASTER( myThid )        _END_MASTER( myThid )
1160    
1161    #endif /* ALLOW_CTRL */
1162  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
1163        return        return
1164        end        end
# Line 929  cph) Line 1231  cph)
1231        integer irecord        integer irecord
1232        integer myIter        integer myIter
1233        integer myThid        integer myThid
1234    
1235    #ifdef ALLOW_CTRL
1236    
1237  C Functions  C Functions
1238        integer ILNBLNK        integer ILNBLNK
1239        integer MDS_RECLEN        integer MDS_RECLEN
1240  C Local variables  C Local variables
1241        character*(80) dataFName,metaFName        character*(MAX_LEN_FNAM) dataFName,metaFName
1242        integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL        integer ip,jp,iG,jG,irec,bi,bj,i,j,k,dUnit,IL
1243        Real*4 r4seg(sNx)        Real*4 r4seg(sNx)
1244        Real*8 r8seg(sNx)        Real*8 r8seg(sNx)
# Line 943  C Local variables Line 1248  C Local variables
1248        logical fileIsOpen        logical fileIsOpen
1249        character*(max_len_mbuf) msgbuf        character*(max_len_mbuf) msgbuf
1250  cph-usesingle(  cph-usesingle(
1251    #ifdef ALLOW_USE_MPI
1252        integer ii,jj        integer ii,jj
1253        integer x_size,y_size,iG_IO,jG_IO,npe  c     integer iG_IO,jG_IO,npe
1254          integer x_size,y_size
1255        PARAMETER ( x_size = Nx )        PARAMETER ( x_size = Nx )
1256        PARAMETER ( y_size = Ny )        PARAMETER ( y_size = Ny )
1257        Real*4 xy_buffer_r4(x_size,y_size)        Real*4 xy_buffer_r4(x_size,y_size)
1258        Real*8 xy_buffer_r8(x_size,y_size)        Real*8 xy_buffer_r8(x_size,y_size)
1259        Real*8 global(Nx,Ny)        Real*8 global(Nx,Ny)
1260    #endif
1261  cph-usesingle)  cph-usesingle)
1262    CMM(
1263          integer pIL
1264    CMM)
1265    
1266  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
1267    
# Line 972  C Record number must be >= 1 Line 1283  C Record number must be >= 1
1283  C Assume nothing  C Assume nothing
1284        fileIsOpen=.FALSE.        fileIsOpen=.FALSE.
1285        IL=ILNBLNK( fName )        IL=ILNBLNK( fName )
1286    CMM(
1287          pIL = ILNBLNK( mdsioLocalDir )
1288    CMM)
1289    CMM(
1290    C Assign special directory
1291          if ( pIL.NE.0 ) then
1292           write(fName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL)
1293          endif
1294    CMM)
1295    
1296  C Assign a free unit number as the I/O channel for this routine  C Assign a free unit number as the I/O channel for this routine
1297        call MDSFINDUNIT( dUnit, mythid )        call MDSFINDUNIT( dUnit, mythid )
# Line 987  C globalFile is too slow, then try using Line 1307  C globalFile is too slow, then try using
1307  C Master thread of process 0, only, opens a global file  C Master thread of process 0, only, opens a global file
1308         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
1309          IF( mpiMyId .EQ. 0 ) THEN          IF( mpiMyId .EQ. 0 ) THEN
1310           write(dataFname(1:80),'(2a)') fName(1:IL),'.data'           write(dataFname,'(2a)') fName(1:IL),'.data'
1311           length_of_rec=MDS_RECLEN(filePrec,x_size*y_size,mythid)           length_of_rec=MDS_RECLEN(filePrec,x_size*y_size,mythid)
1312           if (irecord .EQ. 1) then           if (irecord .EQ. 1) then
1313            open( dUnit, file=dataFName, status=_NEW_STATUS,            open( dUnit, file=dataFName, status=_NEW_STATUS,
# Line 1054  C Close data-file and create meta-file Line 1374  C Close data-file and create meta-file
1374         _BEGIN_MASTER( myThid )         _BEGIN_MASTER( myThid )
1375          IF( mpiMyId .EQ. 0 ) THEN          IF( mpiMyId .EQ. 0 ) THEN
1376           close( dUnit )           close( dUnit )
1377           write(metaFName(1:80),'(2a)') fName(1:IL),'.meta'           write(metaFName,'(2a)') fName(1:IL),'.meta'
1378           dimList(1,1)=Nx           dimList(1,1)=Nx
1379           dimList(2,1)=1           dimList(2,1)=1
1380           dimList(3,1)=Nx           dimList(3,1)=Nx
# Line 1087  C Loop over all tiles Line 1407  C Loop over all tiles
1407  C If we are writing to a tiled MDS file then we open each one here  C If we are writing to a tiled MDS file then we open each one here
1408           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles
1409           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles
1410           write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')           write(dataFname,'(2a,i3.3,a,i3.3,a)')
1411       &              fName(1:IL),'.',iG,'.',jG,'.data'       &              fName(1:IL),'.',iG,'.',jG,'.data'
1412           if (irecord .EQ. 1) then           if (irecord .EQ. 1) then
1413            length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )            length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
# Line 1103  C If we are writing to a tiled MDS file Line 1423  C If we are writing to a tiled MDS file
1423          if (fileIsOpen) then          if (fileIsOpen) then
1424           do k=1,nLocz           do k=1,nLocz
1425            do j=1,sNy            do j=1,sNy
1426               do ii=1,sNx               do i=1,sNx
1427                  arr(ii,j,k,bi,bj)=arr_gl(ii,bi,ip,j,bj,jp,k)                  arr(i,j,k,bi,bj)=arr_gl(i,bi,ip,j,bj,jp,k)
1428               enddo               enddo
1429              iG = 0              iG = 0
1430              jG = 0              jG = 0
# Line 1163  C If we were writing to a tiled MDS file Line 1483  C If we were writing to a tiled MDS file
1483  C Create meta-file for each tile if we are tiling  C Create meta-file for each tile if we are tiling
1484           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles           iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles
1485           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles           jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles
1486           write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)')           write(metaFname,'(2a,i3.3,a,i3.3,a)')
1487       &              fName(1:IL),'.',iG,'.',jG,'.meta'       &              fName(1:IL),'.',iG,'.',jG,'.meta'
1488           dimList(1,1)=Nx           dimList(1,1)=Nx
1489           dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1           dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1
# Line 1192  C endif useSingleCpuIO Line 1512  C endif useSingleCpuIO
1512        endif        endif
1513  #endif /* ALLOW_USE_MPI */  #endif /* ALLOW_USE_MPI */
1514    
1515    #endif /* ALLOW_CTRL */
1516  C     ------------------------------------------------------------------  C     ------------------------------------------------------------------
1517        return        return
1518        end        end

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.22