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

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

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

revision 1.1 by heimbach, Wed Jul 16 16:36:28 2003 UTC revision 1.2 by heimbach, Fri Jul 18 21:10:50 2003 UTC
# Line 0  Line 1 
1    C $Header$
2    
3    #include "CPP_OPTIONS.h"
4    
5    #undef  SAFE_IO
6    
7    #ifdef SAFE_IO
8    #define _NEW_STATUS 'new'
9    #else
10    #define _NEW_STATUS 'unknown'
11    #endif
12    
13    C=======================================================================
14          SUBROUTINE MDSREADFIELDXZ_LOC(
15         I   fName,
16         I   filePrec,
17         I   arrType,
18         I   nNz,
19         |   arr,
20         I   irecord,
21         I   myThid )
22    C
23    C Arguments:
24    C
25    C fName         string  base name for file to read
26    C filePrec      integer number of bits per word in file (32 or 64)
27    C arrType       char(2) declaration of "arr": either "RS" or "RL"
28    C nNz           integer size of third dimension: normally either 1 or Nr
29    C arr           RS/RL   array to read into, arr(:,:,nNz,:,:)
30    C irecord       integer record number to read
31    C myThid        integer thread identifier
32    C
33    C MDSREADFIELD first checks to see if the file "fName" exists, then
34    C if the file "fName.data" exists and finally the tiled files of the
35    C form "fName.xxx.yyy.data" exist.
36    C The precision of the file is decsribed by filePrec, set either
37    C to floatPrec32 or floatPrec64. The precision or declaration of
38    C the array argument must be consistently described by the char*(2)
39    C string arrType, either "RS" or "RL".
40    C This routine reads vertical slices (X-Z) including the overlap region.
41    C irecord is the record number to be read and must be >= 1.
42    C The file data is stored in arr *but* the overlaps are *not* updated.
43    C
44    C Created: 06/03/00 spk@ocean.mit.edu
45    C
46    
47          implicit none
48    C Global variables / common blocks
49    #include "SIZE.h"
50    #include "EEPARAMS.h"
51    #include "PARAMS.h"
52    
53    C Routine arguments
54          character*(*) fName
55          integer filePrec
56          character*(2) arrType
57          integer nNz
58          Real arr(*)
59          integer irecord
60          integer myThid
61    C Functions
62          integer ILNBLNK
63          integer MDS_RECLEN
64    C Local variables
65          character*(80) dataFName
66          integer iG,jG,irec,bi,bj,k,dUnit,IL
67          logical exst
68          Real*4 r4seg(sNx)
69          Real*8 r8seg(sNx)
70          logical globalFile,fileIsOpen
71          integer length_of_rec
72          character*(max_len_mbuf) msgbuf
73    C     ------------------------------------------------------------------
74    
75    C Only do I/O if I am the master thread
76          _BEGIN_MASTER( myThid )
77    
78    C Record number must be >= 1
79          if (irecord .LT. 1) then
80           write(msgbuf,'(a,i9.8)')
81         &   ' MDSREADFIELDXZ: argument irecord = ',irecord
82           call print_message( msgbuf, standardmessageunit,
83         &                     SQUEEZE_RIGHT , mythid)
84           write(msgbuf,'(a)')
85         &   ' MDSREADFIELDXZ: Invalid value for irecord'
86           call print_error( msgbuf, mythid )
87           stop 'ABNORMAL END: S/R MDSREADFIELDXZ'
88          endif
89    
90    C Assume nothing
91          globalFile = .FALSE.
92          fileIsOpen = .FALSE.
93          IL=ILNBLNK( fName )
94    
95    C Assign a free unit number as the I/O channel for this routine
96          call MDSFINDUNIT( dUnit, mythid )
97    
98    C Check first for global file with simple name (ie. fName)
99          dataFName = fName
100          inquire( file=dataFname, exist=exst )
101          if (exst) then
102           if ( debugLevel .GE. debLevA ) then
103            write(msgbuf,'(a,a)')
104         &   ' MDSREADFIELDXZ: opening global file: ',dataFName
105            call print_message( msgbuf, standardmessageunit,
106         &                     SQUEEZE_RIGHT , mythid)
107           endif
108           globalFile = .TRUE.
109          endif
110    
111    C If negative check for global file with MDS name (ie. fName.data)
112          if (.NOT. globalFile) then
113           write(dataFname(1:80),'(2a)') fName(1:IL),'.data'
114           inquire( file=dataFname, exist=exst )
115           if (exst) then
116            if ( debugLevel .GE. debLevA ) then
117             write(msgbuf,'(a,a)')
118         &    ' MDSREADFIELDXZ: opening global file: ',dataFName
119             call print_message( msgbuf, standardmessageunit,
120         &                      SQUEEZE_RIGHT , mythid)
121            endif
122            globalFile = .TRUE.
123           endif
124          endif
125    
126    C If we are reading from a global file then we open it here
127          if (globalFile) then
128           length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
129           open( dUnit, file=dataFName, status='old',
130         &      access='direct', recl=length_of_rec )
131           fileIsOpen=.TRUE.
132          endif
133    
134    C Loop over all tiles
135          do bj=1,nSy
136           do bi=1,nSx
137    C If we are reading from a tiled MDS file then we open each one here
138            if (.NOT. globalFile) then
139             iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
140             jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
141             write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')
142         &              fName(1:IL),'.',iG,'.',jG,'.data'
143             inquire( file=dataFname, exist=exst )
144    C Of course, we only open the file if the tile is "active"
145    C (This is a place-holder for the active/passive mechanism
146             if (exst) then
147              if ( debugLevel .GE. debLevA ) then
148               write(msgbuf,'(a,a)')
149         &      ' MDSREADFIELDXZ: opening file: ',dataFName
150               call print_message( msgbuf, standardmessageunit,
151         &                        SQUEEZE_RIGHT , mythid)
152              endif
153              length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
154              open( dUnit, file=dataFName, status='old',
155         &        access='direct', recl=length_of_rec )
156              fileIsOpen=.TRUE.
157             else
158              fileIsOpen=.FALSE.
159              write(msgbuf,'(a,a)')
160         &      ' MDSREADFIELDXZ: filename: ',dataFName
161              call print_message( msgbuf, standardmessageunit,
162         &                        SQUEEZE_RIGHT , mythid)
163              write(msgbuf,'(a)')
164         &      ' MDSREADFIELDXZ: File does not exist'
165              call print_error( msgbuf, mythid )
166              stop 'ABNORMAL END: S/R MDSREADFIELDXZ'
167             endif
168            endif
169    
170            if (fileIsOpen) then
171             do k=1,nNz
172               if (globalFile) then
173                iG = myXGlobalLo-1 + (bi-1)*sNx
174                jG = (myYGlobalLo-1)/sNy + (bj-1)
175                irec=1 + INT(iG/sNx) + nSx*nPx*jG + nSx*nPx*nSy*nPy*(k-1)
176         &           + nSx*nPx*nSy*nPy*nNz*(irecord-1)
177               else
178                iG = 0
179                jG = 0
180                irec=k + nNz*(irecord-1)
181               endif
182               if (filePrec .eq. precFloat32) then
183                read(dUnit,rec=irec) r4seg
184    #ifdef _BYTESWAPIO
185                call MDS_BYTESWAPR4(sNx,r4seg)
186    #endif
187                if (arrType .eq. 'RS') then
188                 call MDS_SEG4toRS_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r4seg,arr)
189                elseif (arrType .eq. 'RL') then
190                 call MDS_SEG4toRL_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r4seg,arr)
191                else
192                 write(msgbuf,'(a)')
193         &         ' MDSREADFIELDXZ: illegal value for arrType'
194                 call print_error( msgbuf, mythid )
195                 stop 'ABNORMAL END: S/R MDSREADFIELDXZ'
196                endif
197               elseif (filePrec .eq. precFloat64) then
198                read(dUnit,rec=irec) r8seg
199    #ifdef _BYTESWAPIO
200                call MDS_BYTESWAPR8( sNx, r8seg )
201    #endif
202                if (arrType .eq. 'RS') then
203                 call MDS_SEG8toRS_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r8seg,arr)
204                elseif (arrType .eq. 'RL') then
205                 call MDS_SEG8toRL_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r8seg,arr)
206                else
207                 write(msgbuf,'(a)')
208         &         ' MDSREADFIELDXZ: illegal value for arrType'
209                 call print_error( msgbuf, mythid )
210                 stop 'ABNORMAL END: S/R MDSREADFIELDXZ'
211                endif
212               else
213                write(msgbuf,'(a)')
214         &        ' MDSREADFIELDXZ: illegal value for filePrec'
215                call print_error( msgbuf, mythid )
216                stop 'ABNORMAL END: S/R MDSREADFIELDXZ'
217               endif
218    C End of k loop
219             enddo
220             if (.NOT. globalFile) then
221              close( dUnit )
222              fileIsOpen = .FALSE.
223             endif
224            endif
225    C End of bi,bj loops
226           enddo
227          enddo
228    
229    C If global file was opened then close it
230          if (fileIsOpen .AND. globalFile) then
231           close( dUnit )
232           fileIsOpen = .FALSE.
233          endif
234    
235          _END_MASTER( myThid )
236    
237    C     ------------------------------------------------------------------
238          return
239          end
240    C=======================================================================
241    
242    C=======================================================================
243          SUBROUTINE MDSREADFIELDYZ_LOC(
244         I   fName,
245         I   filePrec,
246         I   arrType,
247         I   nNz,
248         |   arr,
249         I   irecord,
250         I   myThid )
251    C
252    C Arguments:
253    C
254    C fName         string  base name for file to read
255    C filePrec      integer number of bits per word in file (32 or 64)
256    C arrType       char(2) declaration of "arr": either "RS" or "RL"
257    C nNz           integer size of third dimension: normally either 1 or Nr
258    C arr           RS/RL   array to read into, arr(:,:,nNz,:,:)
259    C irecord       integer record number to read
260    C myThid        integer thread identifier
261    C
262    C MDSREADFIELD first checks to see if the file "fName" exists, then
263    C if the file "fName.data" exists and finally the tiled files of the
264    C form "fName.xxx.yyy.data" exist.
265    C The precision of the file is decsribed by filePrec, set either
266    C to floatPrec32 or floatPrec64. The precision or declaration of
267    C the array argument must be consistently described by the char*(2)
268    C string arrType, either "RS" or "RL".
269    C This routine reads vertical slices (Y-Z) including overlap regions.
270    C irecord is the record number to be read and must be >= 1.
271    C The file data is stored in arr *but* the overlaps are *not* updated.
272    C
273    C Created: 06/03/00 spk@ocean.mit.edu
274    C
275    
276          implicit none
277    C Global variables / common blocks
278    #include "SIZE.h"
279    #include "EEPARAMS.h"
280    #include "PARAMS.h"
281    
282    C Routine arguments
283          character*(*) fName
284          integer filePrec
285          character*(2) arrType
286          integer nNz
287          Real arr(*)
288          integer irecord
289          integer myThid
290    C Functions
291          integer ILNBLNK
292          integer MDS_RECLEN
293    C Local variables
294          character*(80) dataFName
295          integer iG,jG,irec,bi,bj,k,dUnit,IL
296          logical exst
297          Real*4 r4seg(sNy)
298          Real*8 r8seg(sNy)
299          logical globalFile,fileIsOpen
300          integer length_of_rec
301          character*(max_len_mbuf) msgbuf
302    C     ------------------------------------------------------------------
303    
304    C Only do I/O if I am the master thread
305          _BEGIN_MASTER( myThid )
306    
307    C Record number must be >= 1
308          if (irecord .LT. 1) then
309           write(msgbuf,'(a,i9.8)')
310         &   ' MDSREADFIELDYZ: argument irecord = ',irecord
311           call print_message( msgbuf, standardmessageunit,
312         &                     SQUEEZE_RIGHT , mythid)
313           write(msgbuf,'(a)')
314         &   ' MDSREADFIELDYZ: Invalid value for irecord'
315           call print_error( msgbuf, mythid )
316           stop 'ABNORMAL END: S/R MDSREADFIELDYZ'
317          endif
318    
319    C Assume nothing
320          globalFile = .FALSE.
321          fileIsOpen = .FALSE.
322          IL=ILNBLNK( fName )
323    
324    C Assign a free unit number as the I/O channel for this routine
325          call MDSFINDUNIT( dUnit, mythid )
326    
327    C Check first for global file with simple name (ie. fName)
328          dataFName = fName
329          inquire( file=dataFname, exist=exst )
330          if (exst) then
331           if ( debugLevel .GE. debLevA ) then
332            write(msgbuf,'(a,a)')
333         &   ' MDSREADFIELDYZ: opening global file: ',dataFName
334            call print_message( msgbuf, standardmessageunit,
335         &                     SQUEEZE_RIGHT , mythid)
336           endif
337           globalFile = .TRUE.
338          endif
339    
340    C If negative check for global file with MDS name (ie. fName.data)
341          if (.NOT. globalFile) then
342           write(dataFname(1:80),'(2a)') fName(1:IL),'.data'
343           inquire( file=dataFname, exist=exst )
344           if (exst) then
345            if ( debugLevel .GE. debLevA ) then
346             write(msgbuf,'(a,a)')
347         &    ' MDSREADFIELDYZ: opening global file: ',dataFName
348             call print_message( msgbuf, standardmessageunit,
349         &                      SQUEEZE_RIGHT , mythid)
350            endif
351            globalFile = .TRUE.
352           endif
353          endif
354    
355    C If we are reading from a global file then we open it here
356          if (globalFile) then
357           length_of_rec=MDS_RECLEN( filePrec, sNy, mythid )
358           open( dUnit, file=dataFName, status='old',
359         &      access='direct', recl=length_of_rec )
360           fileIsOpen=.TRUE.
361          endif
362    
363    C Loop over all tiles
364          do bj=1,nSy
365           do bi=1,nSx
366    C If we are reading from a tiled MDS file then we open each one here
367            if (.NOT. globalFile) then
368             iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
369             jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
370             write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')
371         &              fName(1:IL),'.',iG,'.',jG,'.data'
372             inquire( file=dataFname, exist=exst )
373    C Of course, we only open the file if the tile is "active"
374    C (This is a place-holder for the active/passive mechanism
375             if (exst) then
376              if ( debugLevel .GE. debLevA ) then
377               write(msgbuf,'(a,a)')
378         &      ' MDSREADFIELDYZ: opening file: ',dataFName
379               call print_message( msgbuf, standardmessageunit,
380         &                        SQUEEZE_RIGHT , mythid)
381              endif
382              length_of_rec=MDS_RECLEN( filePrec, sNy, mythid )
383              open( dUnit, file=dataFName, status='old',
384         &        access='direct', recl=length_of_rec )
385              fileIsOpen=.TRUE.
386             else
387              fileIsOpen=.FALSE.
388              write(msgbuf,'(a,a)')
389         &      ' MDSREADFIELDYZ: filename: ',dataFName
390              call print_message( msgbuf, standardmessageunit,
391         &                        SQUEEZE_RIGHT , mythid)
392              write(msgbuf,'(a)')
393         &      ' MDSREADFIELDYZ: File does not exist'
394              call print_error( msgbuf, mythid )
395              stop 'ABNORMAL END: S/R MDSREADFIELDYZ'
396             endif
397            endif
398    
399            if (fileIsOpen) then
400             do k=1,nNz
401               if (globalFile) then
402                iG = (myXGlobalLo-1)/sNx + (bi-1)
403                jG = myYGlobalLo-1 + (bj-1)*sNy
404                irec=1 + INT(jG/sNy) + nSy*nPy*iG + nSx*nPx*nSy*nPy*(k-1)
405         &           + nSx*nPx*nSy*nPy*nNz*(irecord-1)
406               else
407                iG = 0
408                jG = 0
409                irec=k + nNz*(irecord-1)
410               endif
411               if (filePrec .eq. precFloat32) then
412                read(dUnit,rec=irec) r4seg
413    #ifdef _BYTESWAPIO
414                call MDS_BYTESWAPR4(sNy,r4seg)
415    #endif
416                if (arrType .eq. 'RS') then
417                 call MDS_SEG4toRS_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r4seg,arr)
418                elseif (arrType .eq. 'RL') then
419                 call MDS_SEG4toRL_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r4seg,arr)
420                else
421                 write(msgbuf,'(a)')
422         &         ' MDSREADFIELDYZ: illegal value for arrType'
423                 call print_error( msgbuf, mythid )
424                 stop 'ABNORMAL END: S/R MDSREADFIELDYZ'
425                endif
426               elseif (filePrec .eq. precFloat64) then
427                read(dUnit,rec=irec) r8seg
428    #ifdef _BYTESWAPIO
429                call MDS_BYTESWAPR8( sNy, r8seg )
430    #endif
431                if (arrType .eq. 'RS') then
432                 call MDS_SEG8toRS_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r8seg,arr)
433                elseif (arrType .eq. 'RL') then
434                 call MDS_SEG8toRL_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r8seg,arr)
435                else
436                 write(msgbuf,'(a)')
437         &         ' MDSREADFIELDYZ: illegal value for arrType'
438                 call print_error( msgbuf, mythid )
439                 stop 'ABNORMAL END: S/R MDSREADFIELDYZ'
440                endif
441               else
442                write(msgbuf,'(a)')
443         &        ' MDSREADFIELDYZ: illegal value for filePrec'
444                call print_error( msgbuf, mythid )
445                stop 'ABNORMAL END: S/R MDSREADFIELDYZ'
446               endif
447    C End of k loop
448             enddo
449             if (.NOT. globalFile) then
450              close( dUnit )
451              fileIsOpen = .FALSE.
452             endif
453            endif
454    C End of bi,bj loops
455           enddo
456          enddo
457    
458    C If global file was opened then close it
459          if (fileIsOpen .AND. globalFile) then
460           close( dUnit )
461           fileIsOpen = .FALSE.
462          endif
463    
464          _END_MASTER( myThid )
465    
466    C     ------------------------------------------------------------------
467          return
468          end
469    C=======================================================================
470    
471    C=======================================================================
472          SUBROUTINE MDSWRITEFIELDXZ_LOC(
473         I   fName,
474         I   filePrec,
475         I   globalFile,
476         I   arrType,
477         I   nNz,
478         I   arr,
479         I   irecord,
480         I   myIter,
481         I   myThid )
482    C
483    C Arguments:
484    C
485    C fName         string  base name for file to written
486    C filePrec      integer number of bits per word in file (32 or 64)
487    C globalFile    logical selects between writing a global or tiled file
488    C C arrType     char(2) declaration of "arr": either "RS" or "RL"
489    C nNz           integer size of second dimension: Nr
490    C arr           RL      array to write, arr(:,nNz,:,:)
491    C irecord       integer record number to read
492    C myIter        integer time step number
493    C myThid        integer thread identifier
494    C
495    C MDSWRITEFIELDXZ creates either a file of the form "fName.data"  
496    C if the logical flag "globalFile" is set true. Otherwise
497    C it creates MDS tiled files of the form "fName.xxx.yyy.data".
498    C The precision of the file is decsribed by filePrec, set either
499    C to floatPrec32 or floatPrec64. The precision or declaration of
500    C the array argument must be consistently described by the char*(2)
501    C string arrType, either "RS" or "RL".
502    C This routine writes vertical slices (X-Z) including overlap regions.
503    C irecord is the record number to be read and must be >= 1.
504    C NOTE: It is currently assumed that
505    C the highest record number in the file was the last record written.
506    C
507    C Modified: 06/02/00 spk@ocean.mit.edu
508    
509          implicit none
510    C Global variables / common blocks
511    #include "SIZE.h"
512    #include "EEPARAMS.h"
513    #include "PARAMS.h"
514    
515    C Routine arguments
516          character*(*) fName
517          integer filePrec
518          logical globalFile
519          character*(2) arrType
520          integer nNz
521          Real arr(*)
522          integer irecord
523          integer myIter
524          integer myThid
525    C Functions
526          integer ILNBLNK
527          integer MDS_RECLEN
528    C Local variables
529          character*(80) dataFName
530          integer iG,jG,irec,bi,bj,k,dUnit,IL
531          Real*4 r4seg(sNx)
532          Real*8 r8seg(sNx)
533          integer length_of_rec
534          logical fileIsOpen
535          character*(max_len_mbuf) msgbuf
536    C     ------------------------------------------------------------------
537    
538    C Only do I/O if I am the master thread
539          _BEGIN_MASTER( myThid )
540    
541    C Record number must be >= 1
542          if (irecord .LT. 1) then
543           write(msgbuf,'(a,i9.8)')
544         &   ' MDSWRITEFIELDXZ: argument irecord = ',irecord
545           call print_message( msgbuf, standardmessageunit,
546         &                     SQUEEZE_RIGHT , mythid)
547           write(msgbuf,'(a)')
548         &   ' MDSWRITEFIELDXZ: invalid value for irecord'
549           call print_error( msgbuf, mythid )
550           stop 'ABNORMAL END: S/R MDSWRITEFIELDXZ'
551          endif
552    
553    C Assume nothing
554          fileIsOpen=.FALSE.
555          IL=ILNBLNK( fName )
556    
557    C Assign a free unit number as the I/O channel for this routine
558          call MDSFINDUNIT( dUnit, mythid )
559    
560    C If we are writing to a global file then we open it here
561          if (globalFile) then
562           write(dataFname(1:80),'(2a)') fName(1:IL),'.data'
563           if (irecord .EQ. 1) then
564            length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
565            open( dUnit, file=dataFName, status=_NEW_STATUS,
566         &      access='direct', recl=length_of_rec )
567            fileIsOpen=.TRUE.
568           else
569            length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
570            open( dUnit, file=dataFName, status='old',
571         &      access='direct', recl=length_of_rec )
572            fileIsOpen=.TRUE.
573           endif
574          endif
575    
576    C Loop over all tiles
577          do bj=1,nSy
578           do bi=1,nSx
579    C If we are writing to a tiled MDS file then we open each one here
580            if (.NOT. globalFile) then
581             iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
582             jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
583             write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')
584         &              fName(1:IL),'.',iG,'.',jG,'.data'
585             if (irecord .EQ. 1) then
586              length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
587              open( dUnit, file=dataFName, status=_NEW_STATUS,
588         &       access='direct', recl=length_of_rec )
589              fileIsOpen=.TRUE.
590             else
591              length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
592              open( dUnit, file=dataFName, status='old',
593         &       access='direct', recl=length_of_rec )
594              fileIsOpen=.TRUE.
595             endif
596            endif
597            if (fileIsOpen) then
598             do k=1,nNz
599               if (globalFile) then
600                iG = myXGlobalLo-1 + (bi-1)*sNx
601                jG = (myYGlobalLo-1)/sNy + (bj-1)
602                irec=1 + INT(iG/sNx) + nSx*nPx*jG + nSx*nPx*nSy*nPy*(k-1)
603         &           + nSx*nPx*nSy*nPy*nNz*(irecord-1)
604               else
605                iG = 0
606                jG = 0
607                irec=k + nNz*(irecord-1)
608               endif
609               if (filePrec .eq. precFloat32) then
610                if (arrType .eq. 'RS') then
611                 call MDS_SEG4toRS_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r4seg,arr)
612                elseif (arrType .eq. 'RL') then
613                 call MDS_SEG4toRL_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r4seg,arr)
614                else
615                 write(msgbuf,'(a)')
616         &         ' MDSWRITEFIELDXZ: illegal value for arrType'
617                 call print_error( msgbuf, mythid )
618                 stop 'ABNORMAL END: S/R MDSWRITEFIELDXZ'
619                endif
620    #ifdef _BYTESWAPIO
621                call MDS_BYTESWAPR4(sNx,r4seg)
622    #endif
623                write(dUnit,rec=irec) r4seg
624               elseif (filePrec .eq. precFloat64) then
625                if (arrType .eq. 'RS') then
626                 call MDS_SEG8toRS_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r8seg,arr)
627                elseif (arrType .eq. 'RL') then
628                 call MDS_SEG8toRL_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r8seg,arr)
629                else
630                 write(msgbuf,'(a)')
631         &         ' MDSWRITEFIELDXZ: illegal value for arrType'
632                 call print_error( msgbuf, mythid )
633                 stop 'ABNORMAL END: S/R MDSWRITEFIELDXZ'
634                endif              
635    #ifdef _BYTESWAPIO
636                call MDS_BYTESWAPR8( sNx, r8seg )
637    #endif
638                write(dUnit,rec=irec) r8seg
639               else
640                write(msgbuf,'(a)')
641         &        ' MDSWRITEFIELDXZ: illegal value for filePrec'
642                call print_error( msgbuf, mythid )
643                stop 'ABNORMAL END: S/R MDSWRITEFIELDXZ'
644               endif
645    C End of k loop
646             enddo
647            else
648             write(msgbuf,'(a)')
649         &     ' MDSWRITEFIELDXZ: I should never get to this point'
650             call print_error( msgbuf, mythid )
651             stop 'ABNORMAL END: S/R MDSWRITEFIELDXZ'
652            endif
653    C If we were writing to a tiled MDS file then we close it here
654            if (fileIsOpen .AND. (.NOT. globalFile)) then
655             close( dUnit )
656             fileIsOpen = .FALSE.
657            endif
658    C End of bi,bj loops
659           enddo
660          enddo
661    
662    C If global file was opened then close it
663          if (fileIsOpen .AND. globalFile) then
664           close( dUnit )
665           fileIsOpen = .FALSE.
666          endif
667    
668    C We put a barrier here to ensure that all processes have finished
669    C writing their data before we update the meta-file
670           _BARRIER
671    
672          _END_MASTER( myThid )
673    
674    C     ------------------------------------------------------------------
675          return
676          end
677    C=======================================================================
678    
679    C=======================================================================
680          SUBROUTINE MDSWRITEFIELDYZ_LOC(
681         I   fName,
682         I   filePrec,
683         I   globalFile,
684         I   arrType,
685         I   nNz,
686         I   arr,
687         I   irecord,
688         I   myIter,
689         I   myThid )
690    C
691    C Arguments:
692    C
693    C fName         string  base name for file to written
694    C filePrec      integer number of bits per word in file (32 or 64)
695    C globalFile    logical selects between writing a global or tiled file
696    C C arrType     char(2) declaration of "arr": either "RS" or "RL"
697    C nNz           integer size of second dimension: Nr
698    C arr           RL      array to write, arr(:,nNz,:,:)
699    C irecord       integer record number to read
700    C myIter        integer time step number
701    C myThid        integer thread identifier
702    C
703    C MDSWRITEFIELDYZ creates either a file of the form "fName.data"  
704    C if the logical flag "globalFile" is set true. Otherwise
705    C it creates MDS tiled files of the form "fName.xxx.yyy.data".
706    C The precision of the file is decsribed by filePrec, set either
707    C to floatPrec32 or floatPrec64. The precision or declaration of
708    C the array argument must be consistently described by the char*(2)
709    C string arrType, either "RS" or "RL".
710    C This routine writes vertical slices (Y-Z) including overlap regions.
711    C irecord is the record number to be read and must be >= 1.
712    C NOTE: It is currently assumed that
713    C the highest record number in the file was the last record written.
714    C
715    C Modified: 06/02/00 spk@ocean.mit.edu
716    
717    
718          implicit none
719    C Global variables / common blocks
720    #include "SIZE.h"
721    #include "EEPARAMS.h"
722    #include "PARAMS.h"
723    
724    C Routine arguments
725          character*(*) fName
726          integer filePrec
727          logical globalFile
728          character*(2) arrType
729          integer nNz
730          Real arr(*)
731          integer irecord
732          integer myIter
733          integer myThid
734    C Functions
735          integer ILNBLNK
736          integer MDS_RECLEN
737    C Local variables
738          character*(80) dataFName
739          integer iG,jG,irec,bi,bj,k,dUnit,IL
740          Real*4 r4seg(sNy)
741          Real*8 r8seg(sNy)
742          integer length_of_rec
743          logical fileIsOpen
744          character*(max_len_mbuf) msgbuf
745    C     ------------------------------------------------------------------
746    
747    C Only do I/O if I am the master thread
748          _BEGIN_MASTER( myThid )
749    
750    C Record number must be >= 1
751          if (irecord .LT. 1) then
752           write(msgbuf,'(a,i9.8)')
753         &   ' MDSWRITEFIELDYZ: argument irecord = ',irecord
754           call print_message( msgbuf, standardmessageunit,
755         &                     SQUEEZE_RIGHT , mythid)
756           write(msgbuf,'(a)')
757         &   ' MDSWRITEFIELDYZ: invalid value for irecord'
758           call print_error( msgbuf, mythid )
759           stop 'ABNORMAL END: S/R MDSWRITEFIELDYZ'
760          endif
761    
762    C Assume nothing
763          fileIsOpen=.FALSE.
764          IL=ILNBLNK( fName )
765    
766    C Assign a free unit number as the I/O channel for this routine
767          call MDSFINDUNIT( dUnit, mythid )
768    
769    C If we are writing to a global file then we open it here
770          if (globalFile) then
771           write(dataFname(1:80),'(2a)') fName(1:IL),'.data'
772           if (irecord .EQ. 1) then
773            length_of_rec=MDS_RECLEN( filePrec, sNy, mythid )
774            open( dUnit, file=dataFName, status=_NEW_STATUS,
775         &      access='direct', recl=length_of_rec )
776            fileIsOpen=.TRUE.
777           else
778            length_of_rec=MDS_RECLEN( filePrec, sNy, mythid )
779            open( dUnit, file=dataFName, status='old',
780         &      access='direct', recl=length_of_rec )
781            fileIsOpen=.TRUE.
782           endif
783          endif
784    
785    C Loop over all tiles
786          do bj=1,nSy
787           do bi=1,nSx
788    C If we are writing to a tiled MDS file then we open each one here
789            if (.NOT. globalFile) then
790             iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
791             jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
792             write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')
793         &              fName(1:IL),'.',iG,'.',jG,'.data'
794             if (irecord .EQ. 1) then
795              length_of_rec=MDS_RECLEN( filePrec, sNy, mythid )
796              open( dUnit, file=dataFName, status=_NEW_STATUS,
797         &       access='direct', recl=length_of_rec )
798              fileIsOpen=.TRUE.
799             else
800              length_of_rec=MDS_RECLEN( filePrec, sNy, mythid )
801              open( dUnit, file=dataFName, status='old',
802         &       access='direct', recl=length_of_rec )
803              fileIsOpen=.TRUE.
804             endif
805            endif
806            if (fileIsOpen) then
807             do k=1,nNz
808               if (globalFile) then
809                iG = (myXGlobalLo-1)/sNx + (bi-1)
810                jG = myYGlobalLo-1 + (bj-1)*sNy
811                irec=1 + INT(jG/sNy) + nSy*nPy*iG + nSx*nPx*nSy*nPy*(k-1)
812         &           + nSx*nPx*nSy*nPy*nNz*(irecord-1)
813               else
814                iG = 0
815                jG = 0
816                irec=k + nNz*(irecord-1)
817               endif
818               if (filePrec .eq. precFloat32) then
819                if (arrType .eq. 'RS') then
820                 call MDS_SEG4toRS_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r4seg,arr)
821                elseif (arrType .eq. 'RL') then
822                 call MDS_SEG4toRL_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r4seg,arr)
823                else
824                 write(msgbuf,'(a)')
825         &         ' MDSWRITEFIELDYZ: illegal value for arrType'
826                 call print_error( msgbuf, mythid )
827                 stop 'ABNORMAL END: S/R MDSWRITEFIELDYZ'
828                endif
829    #ifdef _BYTESWAPIO
830                call MDS_BYTESWAPR4(sNy,r4seg)
831    #endif
832                write(dUnit,rec=irec) r4seg
833               elseif (filePrec .eq. precFloat64) then
834                if (arrType .eq. 'RS') then
835                 call MDS_SEG8toRS_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r8seg,arr)
836                elseif (arrType .eq. 'RL') then
837                 call MDS_SEG8toRL_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r8seg,arr)
838                else
839                 write(msgbuf,'(a)')
840         &         ' MDSWRITEFIELDYZ: illegal value for arrType'
841                 call print_error( msgbuf, mythid )
842                 stop 'ABNORMAL END: S/R MDSWRITEFIELDYZ'
843                endif            
844    #ifdef _BYTESWAPIO
845                call MDS_BYTESWAPR8( sNy, r8seg )
846    #endif
847                write(dUnit,rec=irec) r8seg
848               else
849                write(msgbuf,'(a)')
850         &        ' MDSWRITEFIELDYZ: illegal value for filePrec'
851                call print_error( msgbuf, mythid )
852                stop 'ABNORMAL END: S/R MDSWRITEFIELDYZ'
853               endif
854    C End of k loop
855             enddo
856            else
857             write(msgbuf,'(a)')
858         &     ' MDSWRITEFIELDYZ: I should never get to this point'
859             call print_error( msgbuf, mythid )
860             stop 'ABNORMAL END: S/R MDSWRITEFIELDYZ'
861            endif
862    C If we were writing to a tiled MDS file then we close it here
863            if (fileIsOpen .AND. (.NOT. globalFile)) then
864             close( dUnit )
865             fileIsOpen = .FALSE.
866            endif
867    C End of bi,bj loops
868           enddo
869          enddo
870    
871    C If global file was opened then close it
872          if (fileIsOpen .AND. globalFile) then
873           close( dUnit )
874           fileIsOpen = .FALSE.
875          endif
876    
877    C We put a barrier here to ensure that all processes have finished
878    C writing their data before we update the meta-file
879           _BARRIER
880    
881          _END_MASTER( myThid )
882    
883    C     ------------------------------------------------------------------
884          return
885          end
886    C=======================================================================
887    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.22