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

Annotation of /MITgcm/pkg/mdsio/mdsio_writetile.F

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


Revision 1.1 - (hide annotations) (download)
Fri Aug 17 18:40:30 2001 UTC (22 years, 9 months ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint46n_post, checkpoint51k_post, checkpoint47e_post, checkpoint57m_post, checkpoint52l_pre, ecco_c44_e19, hrcube4, hrcube5, checkpoint46l_post, checkpoint57g_pre, checkpoint46g_pre, checkpoint47c_post, release1_p13_pre, checkpoint50c_post, checkpoint57s_post, checkpoint57b_post, checkpoint46f_post, checkpoint52d_pre, checkpoint57g_post, checkpoint48e_post, checkpoint56b_post, checkpoint50g_post, checkpoint46b_post, checkpoint52j_pre, checkpoint43a-release1mods, checkpoint51o_pre, checkpoint44g_post, checkpoint54d_post, checkpoint48c_post, checkpoint54e_post, ecco_c50_e32, ecco_c50_e33, ecco_c50_e30, ecco_c50_e31, release1_p13, checkpoint51l_post, checkpoint48i_post, checkpoint57r_post, checkpoint40pre9, checkpoint40pre8, checkpoint46l_pre, checkpoint57d_post, checkpoint57i_post, checkpoint50d_pre, checkpoint52k_post, chkpt44d_post, checkpoint55, checkpoint54, checkpoint57, checkpoint56, checkpoint51, checkpoint53, checkpoint52, release1_p8, release1_p9, checkpoint50d_post, release1_p1, release1_p2, release1_p3, release1_p4, release1_p5, release1_p6, release1_p7, checkpoint52f_post, checkpoint57n_post, checkpoint50b_pre, checkpoint44e_pre, checkpoint54f_post, checkpoint51f_post, release1_b1, checkpoint48b_post, ecco_c51_e34d, ecco_c51_e34e, ecco_c51_e34f, ecco_c51_e34g, ecco_c51_e34a, ecco_c51_e34b, ecco_c51_e34c, checkpoint43, checkpoint51d_post, checkpoint48c_pre, checkpoint55a_post, checkpoint51t_post, checkpoint51n_post, release1_chkpt44d_post, checkpoint55i_post, checkpoint57l_post, checkpoint52i_pre, checkpoint57h_post, hrcube_2, hrcube_3, checkpoint51s_post, checkpoint57t_post, checkpoint55c_post, checkpoint48d_pre, checkpoint51j_post, checkpoint47i_post, checkpoint52e_pre, checkpoint57v_post, release1_p11, checkpoint57f_post, checkpoint52e_post, checkpoint51n_pre, checkpoint47d_post, icebear5, icebear4, icebear3, icebear2, checkpoint53d_post, checkpoint46d_pre, checkpoint57a_post, checkpoint48d_post, release1-branch_tutorials, checkpoint57h_pre, checkpoint48f_post, checkpoint45d_post, checkpoint52b_pre, checkpoint54b_post, checkpoint46j_pre, ecco_c50_e28, checkpoint51l_pre, checkpoint52m_post, checkpoint47d_pre, chkpt44a_post, checkpoint55g_post, checkpoint44h_pre, checkpoint48h_post, checkpoint51q_post, ecco_c50_e29, checkpoint51b_pre, checkpoint46a_post, checkpoint47g_post, checkpoint52b_post, chkpt44c_post, checkpoint46j_post, checkpoint51h_pre, checkpoint46k_post, checkpoint46b_pre, chkpt44c_pre, checkpoint52h_pre, checkpoint45a_post, checkpoint57c_post, checkpoint50f_post, checkpoint50a_post, checkpoint50f_pre, hrcube_1, checkpoint51m_post, checkpoint52c_post, checkpoint44e_post, ecco_c44_e18, ecco_c44_e17, ecco_c44_e16, release1_p12, release1_p10, release1_p16, release1_p17, release1_p14, release1_p15, checkpoint47a_post, ecco_c50_e33a, checkpoint53c_post, checkpoint55d_pre, checkpoint57c_pre, checkpoint55j_post, branchpoint-genmake2, checkpoint54a_post, checkpoint46e_pre, checkpoint55h_post, checkpoint51r_post, checkpoint45b_post, checkpoint51i_post, checkpoint57e_post, release1-branch-end, release1_final_v1, checkpoint55b_post, checkpoint51b_post, release1_p12_pre, checkpoint46c_pre, checkpoint53a_post, checkpoint44f_post, checkpoint47b_post, checkpoint44b_post, checkpoint55f_post, ecco_c51_e34, checkpoint46h_pre, checkpoint52d_post, checkpoint53g_post, checkpoint46m_post, checkpoint57p_post, checkpint57u_post, checkpoint46a_pre, checkpoint50c_pre, checkpoint45c_post, checkpoint57q_post, ecco_ice2, ecco_ice1, checkpoint44h_post, eckpoint57e_pre, checkpoint46g_post, checkpoint51c_post, checkpoint52a_pre, checkpoint46i_post, checkpoint50h_post, checkpoint52i_post, checkpoint50e_pre, checkpoint50i_post, ecco_c44_e25, checkpoint54c_post, checkpoint51i_pre, checkpoint48a_post, checkpoint56a_post, checkpoint53f_post, checkpoint47j_post, checkpoint54a_pre, checkpoint53b_pre, branch-exfmods-tag, checkpoint57h_done, checkpoint52j_post, checkpoint47f_post, checkpoint50e_post, chkpt44a_pre, ecco_c44_e22, ecco_c44_e23, ecco_c44_e20, ecco_c44_e21, ecco_c44_e26, ecco_c44_e27, ecco_c44_e24, checkpoint57j_post, checkpoint57f_pre, checkpoint46c_post, ecco-branch-mod1, ecco-branch-mod2, ecco-branch-mod3, ecco-branch-mod4, ecco-branch-mod5, branch-netcdf, checkpoint52l_post, checkpoint52n_post, checkpoint46e_post, release1_beta1, checkpoint56c_post, checkpoint51e_post, checkpoint44b_pre, checkpoint42, checkpoint57a_pre, checkpoint40, checkpoint41, checkpoint46, checkpoint47, checkpoint44, checkpoint45, checkpoint48, checkpoint49, checkpoint57o_post, checkpoint46h_post, checkpoint51o_post, checkpoint50, checkpoint57k_post, checkpoint51f_pre, checkpoint53b_post, checkpoint47h_post, checkpoint52a_post, checkpoint44f_pre, checkpoint51g_post, ecco_c52_e35, checkpoint46d_post, checkpoint50b_post, release1-branch_branchpoint, checkpoint52f_pre, checkpoint53d_pre, checkpoint55e_post, checkpoint51a_post, checkpoint51p_post, checkpoint48g_post, checkpoint51u_post, checkpoint55d_post
Branch point for: c24_e25_ice, branch-exfmods-curt, release1_coupled, release1_final, release1-branch, branch-genmake2, release1, branch-nonh, tg2-branch, ecco-branch, release1_50yr, netcdf-sm0, icebear, checkpoint51n_branch
Added method for dumping intermediate local arrays:
 mdsio_writetile - same as mdsio_writefield except works from inside bi,bj loop
 mdsio_writelocal - same as mdsio_writetile except works for local arrays
 write_local_r? - higher-level wrapper for mdsio_writelocal

Controlled by diagFreq. Defaults to zero (ie. no dumps)

Example given at end of mom_vecinv.F that dumps some local arrays.

1 adcroft 1.1 C $Header: $
2     C $Name: $
3    
4     #include "MDSIO_OPTIONS.h"
5    
6     SUBROUTINE MDS_WRITETILE(
7     I fName,
8     I filePrec,
9     I globalFile,
10     I arrType,
11     I nNz,
12     I arr,
13     I bi, bj,
14     I irecord,
15     I myIter,
16     I myThid )
17     C
18     C Arguments:
19     C
20     C fName string base name for file to written
21     C filePrec integer number of bits per word in file (32 or 64)
22     C globalFile logical selects between writing a global or tiled file
23     C arrType char(2) declaration of "arr": either "RS" or "RL"
24     C nNz integer size of third dimension: normally either 1 or Nr
25     C arr RS/RL array to write, arr(:,:,nNz,:,:)
26     C irecord integer record number to read
27     C myIter integer time step number
28     C myThid integer thread identifier
29     C
30     C MDS_WRITETILE creates either a file of the form "fName.data" and
31     C "fName.meta" if the logical flag "globalFile" is set true. Otherwise
32     C it creates MDS tiled files of the form "fName.xxx.yyy.data" and
33     C "fName.xxx.yyy.meta". A meta-file is always created.
34     C Currently, the meta-files are not read because it is difficult
35     C to parse files in fortran. We should read meta information before
36     C adding records to an existing multi-record file.
37     C The precision of the file is decsribed by filePrec, set either
38     C to floatPrec32 or floatPrec64. The precision or declaration of
39     C the array argument must be consistently described by the char*(2)
40     C string arrType, either "RS" or "RL". nNz allows for both 2-D and
41     C 3-D arrays to be handled. nNz=1 implies a 2-D model field and
42     C nNz=Nr implies a 3-D model field. irecord is the record number
43     C to be read and must be >= 1. NOTE: It is currently assumed that
44     C the highest record number in the file was the last record written.
45     C Nor is there a consistency check between the routine arguments and file.
46     C ie. if your write record 2 after record 4 the meta information
47     C will record the number of records to be 2. This, again, is because
48     C we have read the meta information. To be fixed.
49     C
50     C Created: 03/16/99 adcroft@mit.edu
51     C
52     C Changed: 05/31/00 heimbach@mit.edu
53     C open(dUnit, ..., status='old', ... -> status='unknown'
54    
55     implicit none
56     C Global variables / common blocks
57     #include "SIZE.h"
58     #include "EEPARAMS.h"
59     #include "PARAMS.h"
60    
61     C Routine arguments
62     character*(*) fName
63     integer filePrec
64     logical globalFile
65     character*(2) arrType
66     integer nNz
67     _RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nNz,nSx,nSy)
68     integer bi, bj
69     integer irecord
70     integer myIter
71     integer myThid
72     C Functions
73     integer ILNBLNK
74     integer MDS_RECLEN
75     C Local variables
76     character*(80) dataFName,metaFName
77     integer iG,jG,irec,j,k,dUnit,IL
78     Real*4 r4seg(sNx)
79     Real*8 r8seg(sNx)
80     integer dimList(3,3),ndims
81     integer length_of_rec
82     logical fileIsOpen
83     character*(max_len_mbuf) msgbuf
84     C ------------------------------------------------------------------
85    
86     C Only do I/O if I am the master thread
87     _BEGIN_MASTER( myThid )
88    
89     C Record number must be >= 1
90     if (irecord .LT. 1) then
91     write(msgbuf,'(a,i9.8)')
92     & ' MDS_WRITETILE: argument irecord = ',irecord
93     call print_message( msgbuf, standardmessageunit,
94     & SQUEEZE_RIGHT , mythid)
95     write(msgbuf,'(a)')
96     & ' MDS_WRITETILE: invalid value for irecord'
97     call print_error( msgbuf, mythid )
98     stop 'ABNORMAL END: S/R MDS_WRITETILE'
99     endif
100    
101     C Assume nothing
102     fileIsOpen=.FALSE.
103     IL=ILNBLNK( fName )
104    
105     C Assign a free unit number as the I/O channel for this routine
106     call MDSFINDUNIT( dUnit, mythid )
107    
108     C If we are writing to a global file then we open it here
109     if (globalFile) then
110     write(dataFname(1:80),'(2a)') fName(1:IL),'.data'
111     if (irecord .EQ. 1) then
112     length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
113     open( dUnit, file=dataFName, status='unknown',
114     & access='direct', recl=length_of_rec )
115     fileIsOpen=.TRUE.
116     else
117     length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
118     open( dUnit, file=dataFName, status=_OLD_STATUS,
119     & access='direct', recl=length_of_rec )
120     fileIsOpen=.TRUE.
121     endif
122     endif
123    
124     C Loop over all tiles
125     c do bj=1,nSy
126     c do bi=1,nSx
127     C If we are writing to a tiled MDS file then we open each one here
128     if (.NOT. globalFile) then
129     iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
130     jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
131     write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')
132     & fName(1:IL),'.',iG,'.',jG,'.data'
133     if (irecord .EQ. 1) then
134     length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
135     open( dUnit, file=dataFName, status=_NEW_STATUS,
136     & access='direct', recl=length_of_rec )
137     fileIsOpen=.TRUE.
138     else
139     length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
140     open( dUnit, file=dataFName, status=_OLD_STATUS,
141     & access='direct', recl=length_of_rec )
142     fileIsOpen=.TRUE.
143     endif
144     endif
145     if (fileIsOpen) then
146     do k=1,nNz
147     do j=1,sNy
148     if (globalFile) then
149     iG = myXGlobalLo-1+(bi-1)*sNx
150     jG = myYGlobalLo-1+(bj-1)*sNy
151     irec=1+INT(iG/sNx)+nSx*nPx*(jG+j-1)+nSx*nPx*Ny*(k-1)
152     & +nSx*nPx*Ny*nNz*(irecord-1)
153     else
154     iG = 0
155     jG = 0
156     irec=j + sNy*(k-1) + sNy*nNz*(irecord-1)
157     endif
158     if (filePrec .eq. precFloat32) then
159     if (arrType .eq. 'RS') then
160     call MDS_SEG4toRS( j,bi,bj,k,nNz, r4seg, .FALSE., arr )
161     elseif (arrType .eq. 'RL') then
162     call MDS_SEG4toRL( j,bi,bj,k,nNz, r4seg, .FALSE., arr )
163     else
164     write(msgbuf,'(a)')
165     & ' MDS_WRITETILE: illegal value for arrType'
166     call print_error( msgbuf, mythid )
167     stop 'ABNORMAL END: S/R MDS_WRITETILE'
168     endif
169     #ifdef _BYTESWAPIO
170     call MDS_BYTESWAPR4( sNx, r4seg )
171     #endif
172     write(dUnit,rec=irec) r4seg
173     elseif (filePrec .eq. precFloat64) then
174     if (arrType .eq. 'RS') then
175     call MDS_SEG8toRS( j,bi,bj,k,nNz, r8seg, .FALSE., arr )
176     elseif (arrType .eq. 'RL') then
177     call MDS_SEG8toRL( j,bi,bj,k,nNz, r8seg, .FALSE., arr )
178     else
179     write(msgbuf,'(a)')
180     & ' MDS_WRITETILE: illegal value for arrType'
181     call print_error( msgbuf, mythid )
182     stop 'ABNORMAL END: S/R MDS_WRITETILE'
183     endif
184     #ifdef _BYTESWAPIO
185     call MDS_BYTESWAPR8( sNx, r8seg )
186     #endif
187     write(dUnit,rec=irec) r8seg
188     else
189     write(msgbuf,'(a)')
190     & ' MDS_WRITETILE: illegal value for filePrec'
191     call print_error( msgbuf, mythid )
192     stop 'ABNORMAL END: S/R MDS_WRITETILE'
193     endif
194     C End of j loop
195     enddo
196     C End of k loop
197     enddo
198     else
199     write(msgbuf,'(a)')
200     & ' MDS_WRITETILE: I should never get to this point'
201     call print_error( msgbuf, mythid )
202     stop 'ABNORMAL END: S/R MDS_WRITETILE'
203     endif
204     C If we were writing to a tiled MDS file then we close it here
205     if (fileIsOpen .AND. (.NOT. globalFile)) then
206     close( dUnit )
207     fileIsOpen = .FALSE.
208     endif
209     C Create meta-file for each tile if we are tiling
210     if (.NOT. globalFile) then
211     iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
212     jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
213     write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)')
214     & fName(1:IL),'.',iG,'.',jG,'.meta'
215     dimList(1,1)=Nx
216     dimList(2,1)=myXGlobalLo+(bi-1)*sNx
217     dimList(3,1)=myXGlobalLo+bi*sNx-1
218     dimList(1,2)=Ny
219     dimList(2,2)=myYGlobalLo+(bj-1)*sNy
220     dimList(3,2)=myYGlobalLo+bj*sNy-1
221     dimList(1,3)=Nr
222     dimList(2,3)=1
223     dimList(3,3)=Nr
224     ndims=3
225     if (nNz .EQ. 1) ndims=2
226     call MDSWRITEMETA( metaFName, dataFName,
227     & filePrec, ndims, dimList, irecord, myIter, mythid )
228     endif
229     C End of bi,bj loops
230     c enddo
231     c enddo
232    
233     C If global file was opened then close it
234     if (fileIsOpen .AND. globalFile) then
235     close( dUnit )
236     fileIsOpen = .FALSE.
237     endif
238    
239     C Create meta-file for the global-file
240     if (globalFile) then
241     C We can not do this operation using threads (yet) because of the
242     C "barrier" at the next step. The barrier could be removed but
243     C at the cost of "safe" distributed I/O.
244     if (nThreads.NE.1) then
245     write(msgbuf,'(a,a)')
246     & ' MDS_WRITETILE: A threads version of this routine',
247     & ' does not exist.'
248     call print_message( msgbuf, standardmessageunit,
249     & SQUEEZE_RIGHT , mythid)
250     write(msgbuf,'(a)')
251     & ' MDS_WRITETILE: This needs to be fixed...'
252     call print_message( msgbuf, standardmessageunit,
253     & SQUEEZE_RIGHT , mythid)
254     write(msgbuf,'(a,i3.2)')
255     & ' MDS_WRITETILE: nThreads = ',nThreads
256     call print_message( msgbuf, standardmessageunit,
257     & SQUEEZE_RIGHT , mythid)
258     write(msgbuf,'(a)')
259     & ' MDS_WRITETILE: Stopping because you are using threads'
260     call print_error( msgbuf, mythid )
261     stop 'ABNORMAL END: S/R MDS_WRITETILE'
262     endif
263     C We put a barrier here to ensure that all processes have finished
264     C writing their data before we update the meta-file
265     _BARRIER
266     write(metaFName(1:80),'(2a)') fName(1:IL),'.meta'
267     dimList(1,1)=Nx
268     dimList(2,1)=1
269     dimList(3,1)=Nx
270     dimList(1,2)=Ny
271     dimList(2,2)=1
272     dimList(3,2)=Ny
273     dimList(1,3)=Nr
274     dimList(2,3)=1
275     dimList(3,3)=Nr
276     ndims=3
277     if (nNz .EQ. 1) ndims=2
278     call MDSWRITEMETA( metaFName, dataFName,
279     & filePrec, ndims, dimList, irecord, myIter, mythid )
280     fileIsOpen=.TRUE.
281     endif
282    
283     _END_MASTER( myThid )
284    
285     C ------------------------------------------------------------------
286     return
287     end

  ViewVC Help
Powered by ViewVC 1.1.22