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

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

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


Revision 1.5 - (show annotations) (download)
Wed Jan 19 23:20:24 2011 UTC (13 years, 5 months ago) by gforget
Branch: MAIN
Changes since 1.4: +26 -23 lines
- pkg/autodiff: checkpoint_lev2_directives.h etc.
	bug fix
- pkg/mdsio: mdsio_write_whalos.F/mdsio_read_whalos.F
	remove mdsioLocalDir and useSingleCpuIO (to handle those externally)
	pass locSingleCPUIO as a parameter (that may be useSingleCpuIO)
	if non zero file id is provided, then omit file opening/closing
- pkg/autodiff: adread_adwrite.F
	pass useSingleCpuIO as the locSingleCPUIO parameter

1 C $Header: /u/gcmpack/MITgcm/pkg/mdsio/mdsio_write_whalos.F,v 1.4 2010/12/23 18:05:00 jmc Exp $
2 C $fName: $
3
4 #include "MDSIO_OPTIONS.h"
5
6 CBOP
7 C !ROUTINE: mds_write_whalos
8 C !INTERFACE:
9 subroutine mds_write_whalos(
10 I fName,
11 I len,
12 I filePrec,
13 I fid,
14 I n2d,
15 I fldRL,
16 I irec,
17 I locSingleCPUIO,
18 I mythid
19 & )
20
21 C !DESCRIPTION: \bv
22 c ==================================================================
23 c SUBROUTINE mds_write_whalos
24 c ==================================================================
25 c o Write file that includes halos. The main purpose is for
26 c adjoint related "tape I/O". The secondary purpose is debugging.
27 c ==================================================================
28 c SUBROUTINE mds_write_whalos
29 c ==================================================================
30 C \ev
31
32 C !USES:
33 implicit none
34
35 c == global variables ==
36 #include "EEPARAMS.h"
37 #include "SIZE.h"
38 #include "PARAMS.h"
39 #ifdef ALLOW_WHIO
40 # include "MDSIO_BUFF_WH.h"
41 #endif
42
43 C !INPUT/OUTPUT PARAMETERS:
44 c == routine arguments ==
45 c fName - extended tape fName.
46 c len - number of characters in fName.
47 c filePrec - number of bits per word in file (32 or 64).
48 c fid - file unit (its use is not implemented yet).
49 C n2d - size of the fldRL third dimension.
50 c fldRL - array to read.
51 c irec - record number to be written.
52 c mythid - number of the thread or instance of the program.
53
54 integer mythid
55 character*(*) fName
56 integer len
57 integer fid
58 integer filePrec
59 integer n2d
60 integer irec
61 _RL fldRL(1-Olx:sNx+Olx,1-Oly:sNy+Oly,n2d,nSx,nSy)
62 logical locSingleCPUIO
63 CEOP
64
65 #ifdef ALLOW_WHIO
66 C !LOCAL VARIABLES:
67 c == local variables ==
68
69 C sNxWh :: x tile size with halo included
70 C sNyWh :: y tile size with halo included
71 C pocNyWh :: processor sum of sNyWh
72 C gloNyWh :: global sum of sNyWh
73 INTEGER sNxWh
74 INTEGER sNyWh
75 INTEGER procNyWh
76 INTEGER gloNyWh
77 PARAMETER ( sNxWh = sNx+2*Olx )
78 PARAMETER ( sNyWh = sNy+2*Oly )
79 PARAMETER ( procNyWh = sNyWh*nSy*nSx )
80 PARAMETER ( gloNyWh = procNyWh*nPy*nPx )
81
82 C !LOCAL VARIABLES:
83 c == local variables ==
84 character*(MAX_LEN_FNAM) pfName
85 character*(MAX_LEN_MBUF) msgBuf
86 integer IL
87 integer bx,by
88
89 integer length2d, length3d, length_of_rec
90 integer i2d, i3d
91 integer i,j,k,bi,bj,ii
92 integer dUnit, irec2d
93 LOGICAL iAmDoingIO
94
95 _RL fld2d(1:sNxWh,1:sNyWh,nSx,nSy)
96
97 c == functions ==
98 INTEGER ILNBLNK
99 INTEGER MDS_RECLEN
100 EXTERNAL ILNBLNK
101 EXTERNAL MDS_RECLEN
102
103 c == end of interface ==
104
105 length2d=sNxWh*procNyWh
106 length3d=length2d*nr
107
108 C Only do I/O if I am the master thread (and mpi process 0 IF locSingleCpuIO):
109 iAmDoingIO = .FALSE.
110 IF ( .NOT.locSingleCpuIO .OR. myProcId.EQ.0 ) THEN
111 _BEGIN_MASTER( myThid )
112 iAmDoingIO = .TRUE.
113 _END_MASTER( myThid )
114 ENDIF
115
116 IF ( iAmDoingIO ) THEN
117 c get the unit and open file
118 IL = ILNBLNK( fName )
119 IF ( .NOT.locSingleCpuIO ) THEN
120 WRITE(pfName,'(2A,I3.3,A)') fName(1:IL),'.',myProcId,'.data'
121 length_of_rec = MDS_RECLEN( filePrec,sNxWh*procNyWh,myThid )
122 ELSE
123 WRITE(pfName,'(2A)') fName(1:IL),'.data'
124 length_of_rec = MDS_RECLEN( filePrec,sNxWh*gloNyWh,myThid)
125 ENDIF
126 IF (fid.EQ.0) THEN
127 CALL MDSFINDUNIT( dUnit, myThid )
128 OPEN( dUnit, file=pfName, status='unknown',
129 & access='direct', recl=length_of_rec )
130 ELSE
131 dUnit=fid
132 ENDIF
133 ENDIF
134
135
136 do i2d=1,n2d
137
138 IF (filePrec .EQ. precFloat32) THEN
139 CALL MDS_PASS_R4toRL( fld2d_procbuff_r4, fldRL,
140 & OLx, OLy, 1, i2d, n2d, 0, 0, .FALSE., myThid )
141 IF ( locSingleCpuIO ) then
142 CALL BAR2( myThid )
143 CALL GATHER_2D_WH_R4( fld2d_globuff_r4,
144 & fld2d_procbuff_r4,myThid)
145 ENDIF
146 ELSE
147 CALL MDS_PASS_R8toRL( fld2d_procbuff_r8, fldRL,
148 & OLx, OLy, 1, i2d, n2d, 0, 0, .FALSE., myThid )
149 IF ( locSingleCpuIO ) then
150 CALL BAR2( myThid )
151 CALL GATHER_2D_WH_R8( fld2d_globuff_r8,
152 & fld2d_procbuff_r8,myThid)
153 ENDIF
154 ENDIF
155
156 _BARRIER
157 IF ( iAmDoingIO ) THEN
158 irec2d=i2d+n2d*(irec-1)
159 IF ( .NOT.locSingleCpuIO ) then
160 IF (filePrec .EQ. precFloat32) THEN
161 WRITE(dUnit,rec=irec2d) fld2d_procbuff_r4
162 ELSE
163 WRITE(dUnit,rec=irec2d) fld2d_procbuff_r8
164 ENDIF
165 ELSE
166 IF (filePrec .EQ. precFloat32) THEN
167 WRITE(dUnit,rec=irec2d) fld2d_globuff_r4
168 ELSE
169 WRITE(dUnit,rec=irec2d) fld2d_globuff_r8
170 ENDIF
171 ENDIF
172 ENDIF
173 _BARRIER
174
175 enddo
176
177 IF ( iAmDoingIO.AND.(fid.EQ.0) ) THEN
178 CLOSE( dUnit )
179 ENDIF
180
181 #endif
182
183 return
184 end
185

  ViewVC Help
Powered by ViewVC 1.1.22