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

Contents of /MITgcm/pkg/mdsio/mdsio_readtile.F

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


Revision 1.1 - (show annotations) (download)
Tue Mar 6 15:28:54 2001 UTC (23 years, 2 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, checkpoint40pre3, checkpoint40pre2, checkpoint40pre1, checkpoint51l_post, checkpoint40pre7, checkpoint40pre6, 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, checkpoint38, 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, checkpoint40pre4, 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, pre38tag1, 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, c37_adj, 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, pre38-close, eckpoint57e_pre, checkpoint46g_post, checkpoint51c_post, checkpoint39, checkpoint52a_pre, checkpoint37, 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, checkpoint40pre5, 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, pre38
Packaged mdsio.

Note: using a "feature" of genmake to keep original mdsio.F and mdsio_gl.F
in place during testing of mdsio package. To use original code simply
use genmake -disable=mdsio.
                                             Enjoy.

1 C $Header: $
2 C $Name: $
3
4 #include "MDSIO_OPTIONS.h"
5
6 SUBROUTINE MDSIO_READTILE(
7 I fName,
8 I filePrec,
9 I arrType,
10 I nNz,
11 O arr,
12 I bi, bj,
13 I irecord,
14 I myThid )
15 C
16 C Arguments:
17 C
18 C fName string base name for file to read
19 C filePrec integer number of bits per word in file (32 or 64)
20 C arrType char(2) declaration of "arr": either "RS" or "RL"
21 C nNz integer size of third dimension: normally either 1 or Nr
22 C arr RS/RL array to read into, arr(:,:,nNz,:,:)
23 C irecord integer record number to read
24 C myThid integer thread identifier
25 C
26 C MDSIO_READTILE first checks to see if the file "fName" exists, then
27 C if the file "fName.data" exists and finally the tiled files of the
28 C form "fName.xxx.yyy.data" exist. Currently, the meta-files are not
29 C read because it is difficult to parse files in fortran.
30 C The precision of the file is decsribed by filePrec, set either
31 C to floatPrec32 or floatPrec64. The precision or declaration of
32 C the array argument must be consistently described by the char*(2)
33 C string arrType, either "RS" or "RL". nNz allows for both 2-D and
34 C 3-D arrays to be handled. nNz=1 implies a 2-D model field and
35 C nNz=Nr implies a 3-D model field. irecord is the record number
36 C to be read and must be >= 1. The file data is stored in
37 C arr *but* the overlaps are *not* updated. ie. An exchange must
38 C be called. This is because the routine is sometimes called from
39 C within a MASTER_THID region.
40 C
41 C Created: 03/16/99 adcroft@mit.edu
42
43 implicit none
44 C Global variables / common blocks
45 #include "SIZE.h"
46 #include "EEPARAMS.h"
47 #include "PARAMS.h"
48
49 C Routine arguments
50 character*(*) fName
51 integer filePrec
52 character*(2) arrType
53 integer nNz
54 Real arr(*)
55 integer bi, bj
56 integer irecord
57 integer myThid
58 C Functions
59 integer ILNBLNK
60 integer MDS_RECLEN
61 C Local variables
62 character*(80) dataFName
63 integer iG,jG,irec,j,k,dUnit,IL
64 logical exst
65 Real*4 r4seg(sNx)
66 Real*8 r8seg(sNx)
67 logical globalFile,fileIsOpen
68 integer length_of_rec
69 character*(max_len_mbuf) msgbuf
70 C ------------------------------------------------------------------
71
72 C Only do I/O if I am the master thread
73 _BEGIN_MASTER( myThid )
74
75 C Record number must be >= 1
76 if (irecord .LT. 1) then
77 write(msgbuf,'(a,i9.8)')
78 & ' MDSIO_READTILE: argument irecord = ',irecord
79 call print_message( msgbuf, standardmessageunit,
80 & SQUEEZE_RIGHT , mythid)
81 write(msgbuf,'(a)')
82 & ' MDSIO_READTILE: Invalid value for irecord'
83 call print_error( msgbuf, mythid )
84 stop 'ABNORMAL END: S/R MDSIO_READTILE'
85 endif
86
87 C Assume nothing
88 globalFile = .FALSE.
89 fileIsOpen = .FALSE.
90 IL=ILNBLNK( fName )
91
92 C Assign a free unit number as the I/O channel for this routine
93 call MDSFINDUNIT( dUnit, mythid )
94
95 C Check first for global file with simple name (ie. fName)
96 dataFName = fName
97 inquire( file=dataFname, exist=exst )
98 if (exst) then
99 write(msgbuf,'(a,a)')
100 & ' MDSIO_READTILE: opening global file: ',dataFName
101 call print_message( msgbuf, standardmessageunit,
102 & SQUEEZE_RIGHT , mythid)
103 globalFile = .TRUE.
104 endif
105
106 C If negative check for global file with MDS name (ie. fName.data)
107 if (.NOT. globalFile) then
108 write(dataFname(1:80),'(2a)') fName(1:IL),'.data'
109 inquire( file=dataFname, exist=exst )
110 if (exst) then
111 write(msgbuf,'(a,a)')
112 & ' MDSIO_READTILE: opening global file: ',dataFName
113 call print_message( msgbuf, standardmessageunit,
114 & SQUEEZE_RIGHT , mythid)
115 globalFile = .TRUE.
116 endif
117 endif
118
119 C If we are reading from a global file then we open it here
120 if (globalFile) then
121 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
122 open( dUnit, file=dataFName, status='old',
123 & access='direct', recl=length_of_rec )
124 fileIsOpen=.TRUE.
125 endif
126
127 C Loop over all tiles
128 c do bj=1,nSy
129 c do bi=1,nSx
130
131 C If we are reading from a tiled MDS file then we open each one here
132 if (.NOT. globalFile) then
133 iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles
134 jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles
135 write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)')
136 & fName(1:IL),'.',iG,'.',jG,'.data'
137 inquire( file=dataFname, exist=exst )
138 C Of course, we only open the file if the tile is "active"
139 C (This is a place-holder for the active/passive mechanism
140 if (exst) then
141 write(msgbuf,'(a,a)')
142 & ' MDSIO_READTILE: opening file: ',dataFName
143 call print_message( msgbuf, standardmessageunit,
144 & SQUEEZE_RIGHT , mythid)
145 length_of_rec=MDS_RECLEN( filePrec, sNx, mythid )
146 open( dUnit, file=dataFName, status='old',
147 & access='direct', recl=length_of_rec )
148 fileIsOpen=.TRUE.
149 else
150 fileIsOpen=.FALSE.
151 write(msgbuf,'(a,a)')
152 & ' MDSIO_READTILE: filename: ',dataFName
153 call print_message( msgbuf, standardmessageunit,
154 & SQUEEZE_RIGHT , mythid)
155 write(msgbuf,'(a)')
156 & ' MDSIO_READTILE: File does not exist'
157 call print_error( msgbuf, mythid )
158 stop 'ABNORMAL END: S/R MDSIO_READTILE'
159 endif
160 endif
161
162 if (fileIsOpen) then
163 do k=1,nNz
164 do j=1,sNy
165 if (globalFile) then
166 iG = myXGlobalLo-1 + (bi-1)*sNx
167 jG = myYGlobalLo-1 + (bj-1)*sNy
168 irec=1 + INT(iG/sNx) + nSx*nPx*(jG+j-1) + nSx*nPx*Ny*(k-1)
169 & + nSx*nPx*Ny*nNz*(irecord-1)
170 else
171 iG = 0
172 jG = 0
173 irec=j + sNy*(k-1) + sNy*nNz*(irecord-1)
174 endif
175 if (filePrec .eq. precFloat32) then
176 read(dUnit,rec=irec) r4seg
177 #ifdef _BYTESWAPIO
178 call MDS_BYTESWAPR4( sNx, r4seg )
179 #endif
180 if (arrType .eq. 'RS') then
181 call MDS_SEG4toRS( j,bi,bj,k,nNz, r4seg, .TRUE., arr )
182 elseif (arrType .eq. 'RL') then
183 call MDS_SEG4toRL( j,bi,bj,k,nNz, r4seg, .TRUE., arr )
184 else
185 write(msgbuf,'(a)')
186 & ' MDSIO_READTILE: illegal value for arrType'
187 call print_error( msgbuf, mythid )
188 stop 'ABNORMAL END: S/R MDSIO_READTILE'
189 endif
190 elseif (filePrec .eq. precFloat64) then
191 read(dUnit,rec=irec) r8seg
192 #ifdef _BYTESWAPIO
193 call MDS_BYTESWAPR8( sNx, r8seg )
194 #endif
195 if (arrType .eq. 'RS') then
196 call MDS_SEG8toRS( j,bi,bj,k,nNz, r8seg, .TRUE., arr )
197 elseif (arrType .eq. 'RL') then
198 call MDS_SEG8toRL( j,bi,bj,k,nNz, r8seg, .TRUE., arr )
199 else
200 write(msgbuf,'(a)')
201 & ' MDSIO_READTILE: illegal value for arrType'
202 call print_error( msgbuf, mythid )
203 stop 'ABNORMAL END: S/R MDSIO_READTILE'
204 endif
205 else
206 write(msgbuf,'(a)')
207 & ' MDSIO_READTILE: illegal value for filePrec'
208 call print_error( msgbuf, mythid )
209 stop 'ABNORMAL END: S/R MDSIO_READTILE'
210 endif
211 C End of j loop
212 enddo
213 C End of k loop
214 enddo
215 if (.NOT. globalFile) then
216 close( dUnit )
217 fileIsOpen = .FALSE.
218 endif
219 endif
220
221 C End of bi,bj loops
222 c enddo
223 c enddo
224
225 C If global file was opened then close it
226 if (fileIsOpen .AND. globalFile) then
227 close( dUnit )
228 fileIsOpen = .FALSE.
229 endif
230
231 _END_MASTER( myThid )
232
233 C ------------------------------------------------------------------
234 return
235 end

  ViewVC Help
Powered by ViewVC 1.1.22