52 subroutine mpp_io_init( flags, maxunit )
53 integer,
intent(in),
optional :: flags, maxunit
54 integer :: io_status, unit
55 integer :: logunit, outunit, inunit, errunit
57 real(r8_kind) :: doubledata = 0
60 if( module_is_initialized )
return
67 call mpp_domains_init(flags)
69 maxunits = _max_file_units
70 if(
PRESENT(maxunit) )maxunits = maxunit
71 if(
PRESENT(flags) )
then
72 debug = flags.EQ.mpp_debug
73 verbose = flags.EQ.mpp_verbose .OR. debug
77 read (input_nml_file, mpp_io_nml, iostat=io_status)
78 if (io_status > 0)
then
79 call mpp_error(fatal,
'=>mpp_io_init: Error reading mpp_io_nml')
83 outunit = stdout(); logunit=stdlog()
84 write(outunit, mpp_io_nml)
85 write(logunit, mpp_io_nml)
91 if(deflate_level .GE. 0) deflate = 1
92 if(deflate .NE. 0)
then
93 if(deflate_level <0 .OR. deflate > 9)
then
94 call mpp_error(fatal,
"mpp_io_mod(mpp_io_init): mpp_io_nml variable must be between 0 and 9 when set")
99 pack_size =
size(transfer(doubledata, realarray))
100 if( pack_size .NE. 1 .AND. pack_size .NE. 2)
call mpp_error(fatal, &
101 &
'mpp_io_mod(mpp_io_init): pack_size should be 1 or 2')
104 default_field%name =
'noname'
105 default_field%units =
'nounits'
106 default_field%longname =
'noname'
107 default_field%id = -1
108 default_field%type = -1
109 default_field%natt = -1
110 default_field%ndim = -1
111 default_field%checksum = 0
113 default_field%min = -huge(1._4)
114 default_field%max = huge(1._4)
115 default_field%missing = mpp_fill_double
116 default_field%fill = mpp_fill_double
117 default_field%scale = 1.0
118 default_field%add = 0.0
119 default_field%pack = 1
120 default_field%time_axis_index = -1
122 default_axis%name =
'noname'
123 default_axis%units =
'nounits'
124 default_axis%longname =
'noname'
125 default_axis%cartesian =
'none'
126 default_axis%compressed =
'unspecified'
127 default_axis%calendar =
'unspecified'
128 default_axis%sense = 0
129 default_axis%len = -1
131 default_axis%did = -1
132 default_axis%type = -1
133 default_axis%natt = -1
135 default_att%name =
'noname'
136 default_att%type = -1
138 default_att%catt =
'none'
143 allocate( mpp_file(nullunit:2*maxunits) )
145 mpp_file(:)%name =
' '
146 mpp_file(:)%action = -1
147 mpp_file(:)%format = -1
148 mpp_file(:)%threading = -1
149 mpp_file(:)%fileset = -1
150 mpp_file(:)%record = -1
151 mpp_file(:)%ncid = -1
152 mpp_file(:)%opened = .false.
153 mpp_file(:)%initialized = .false.
154 mpp_file(:)%write_on_this_pe = .false.
155 mpp_file(:)%io_domain_exist = .false.
156 mpp_file(:)%time_level = 0
157 mpp_file(:)%time = nulltime
159 mpp_file(:)%valid = .false.
160 mpp_file(:)%ndim = -1
161 mpp_file(:)%nvar = -1
163 mpp_file(nullunit)%threading = mpp_single
164 mpp_file(nullunit)%opened = .true.
165 mpp_file(nullunit)%valid = .true.
166 mpp_file(nullunit)%initialized = .true.
170 if (outunit > nullunit .AND. outunit < 2*maxunits) mpp_file(outunit)%opened = .true.
171 if (logunit > nullunit .AND. logunit < 2*maxunits) mpp_file(logunit)%opened = .true.
173 if (inunit > nullunit .AND. inunit < 2*maxunits) mpp_file(inunit)%opened = .true.
175 if (errunit > nullunit .AND. errunit < 2*maxunits) mpp_file(errunit)%opened = .true.
177 if( pe.EQ.mpp_root_pe() )
then
179 write( unit,
'(/a)' )
'MPP_IO module '//trim(version)
181 text = nf_inq_libvers()
182 write( unit,
'(/a)' )
'Using netCDF library version '//trim(text)
188 if( io_clocks_on )
then
189 mpp_read_clock = mpp_clock_id(
'mpp_read')
190 mpp_write_clock = mpp_clock_id(
'mpp_write')
191 mpp_open_clock = mpp_clock_id(
'mpp_open')
192 mpp_close_clock = mpp_clock_id(
'mpp_close')
194 module_is_initialized = .true.
196 end subroutine mpp_io_init
214 subroutine mpp_io_exit(string)
215 character(len=*),
optional :: string
216 integer :: unit,istat
219 if( .NOT.module_is_initialized )
call mpp_error( fatal,
'MPP_IO_EXIT: must first call mpp_io_init.' )
221 if(
PRESENT(string) )
then
222 dosync = .NOT.( trim(string).EQ.
'NOSYNC' )
225 do unit = unit_begin,unit_end
226 if( mpp_file(unit)%opened )
FLUSH(unit)
229 do unit = unit_begin,unit_end
230 if( mpp_file(unit)%opened )
close(unit)
234 do unit = maxunits+1,2*maxunits
235 if( mpp_file(unit)%opened )error = nf_close(mpp_file(unit)%ncid)
241 if( pe.EQ.mpp_root_pe() )
then
246 module_is_initialized = .false.
248 end subroutine mpp_io_exit
251 subroutine netcdf_err( err, file, axis, field, attr, string )
252 integer,
intent(in) :: err
253 type(filetype),
optional :: file
254 type(axistype),
optional :: axis
255 type(fieldtype),
optional :: field
256 type(atttype),
optional :: attr
257 character(len=*),
optional :: string
258 character(len=256) :: errmsg
261 if( err.EQ.nf_noerr )
return
262 errmsg = nf_strerror(err)
263 if(
PRESENT(file) )errmsg = trim(errmsg)//
' File='//file%name
264 if(
PRESENT(axis) )errmsg = trim(errmsg)//
' Axis='//axis%name
265 if(
PRESENT(field) )errmsg = trim(errmsg)//
' Field='//field%name
266 if(
PRESENT(attr) )errmsg = trim(errmsg)//
' Attribute='//attr%name
267 if(
PRESENT(string) )errmsg = trim(errmsg)//string
268 call mpp_io_exit(
'NOSYNC')
269 call mpp_error( fatal,
'NETCDF ERROR: '//trim(errmsg) )
272 end subroutine netcdf_err
275 subroutine mpp_flush(unit)
277 integer,
intent(in) :: unit
279 if( .NOT.module_is_initialized )
call mpp_error( fatal,
'MPP_FLUSH: must first call mpp_io_init.' )
280 if( .NOT.mpp_file(unit)%write_on_this_pe)
return
281 if( .NOT.mpp_file(unit)%opened )
call mpp_error( fatal,
'MPP_FLUSH: invalid unit number.' )
282 if( .NOT.mpp_file(unit)%initialized )
call mpp_error( fatal, &
283 &
'MPP_FLUSH: cannot flush a file during writing of metadata.' )
285 if( mpp_file(unit)%format.EQ.mpp_netcdf )
then
287 error = nf_sync(mpp_file(unit)%ncid);
call netcdf_err( error, mpp_file(unit) )
293 end subroutine mpp_flush
304 logical function do_cf_compliance()
305 do_cf_compliance = cf_compliance
306 end function do_cf_compliance
subroutine mpp_io_set_stack_size(n)
Set the mpp_io_stack variable to be at least n LONG words long.
integer function mpp_get_maxunits()
Return the maximum number of MPP file units available.
subroutine mpp_sync(pelist, do_self)
Synchronize PEs in list.