35 integer(I4B) :: nmesh_node
36 integer(I4B) :: nmesh_face
37 integer(I4B) :: max_nmesh_face_nodes
48 integer(I4B) :: mesh_node_x
49 integer(I4B) :: mesh_node_y
50 integer(I4B) :: mesh_face_x
51 integer(I4B) :: mesh_face_y
52 integer(I4B) :: mesh_face_xbnds
53 integer(I4B) :: mesh_face_ybnds
54 integer(I4B) :: mesh_face_nodes
56 integer(I4B) :: time_bnds
58 integer(I4B),
dimension(:),
allocatable :: export
59 integer(I4B),
dimension(:),
allocatable :: dependent
60 integer(I4B),
dimension(:),
allocatable :: elevation
70 integer(I4B),
pointer :: chunk_face
91 character(len=*),
intent(in) :: pkgtype
92 character(len=*),
intent(in) :: pkgname
93 character(len=*),
intent(in) :: mempath
107 subroutine mesh_init(this, modelname, modeltype, modelfname, nc_fname, &
108 disenum, nctype, lenuni, iout)
111 character(len=*),
intent(in) :: modelname
112 character(len=*),
intent(in) :: modeltype
113 character(len=*),
intent(in) :: modelfname
114 character(len=*),
intent(in) :: nc_fname
115 integer(I4B),
intent(in) :: disenum
116 integer(I4B),
intent(in) :: nctype
117 integer(I4B),
intent(in) :: lenuni
118 integer(I4B),
intent(in) :: iout
119 logical(LGP) :: found
120 integer(I4B) :: latsz, lonsz
123 call this%NCModelExportType%init(modelname, modeltype, modelfname, nc_fname, &
124 disenum, nctype, iout)
126 if (this%ncf_mempath /=
'')
then
129 call get_isize(
'LATITUDE', this%ncf_mempath, latsz)
130 call get_isize(
'LONGITUDE', this%ncf_mempath, lonsz)
131 if (latsz > 0 .or. lonsz > 0)
then
132 write (
warnmsg,
'(a)')
'LATITUDE and LONGITUDE griddata are not &
133 &supported for a NETCDF_MESH2D export and will be ignored. &
134 &Applies to file "'//trim(nc_fname)//
'".'
140 allocate (this%chunk_face)
144 if (this%ncf_mempath /=
'')
then
145 call mem_set_value(this%chunk_face,
'CHUNK_FACE', this%ncf_mempath, found)
148 if (this%chunk_time > 0 .and. this%chunk_face > 0)
then
149 this%chunking_active = .true.
150 else if (this%chunk_time > 0 .or. this%chunk_face > 0)
then
153 write (
warnmsg,
'(a)')
'Ignoring user provided NetCDF chunking parameter. &
154 &Define chunk_time and chunk_face input parameters to see an effect in &
155 &file "'//trim(nc_fname)//
'".'
159 if (lenuni == 1)
then
161 else if (lenuni == 3)
then
168 call nf_verify(nf90_create(this%nc_fname, &
169 ior(nf90_clobber, nf90_netcdf4), this%ncid), &
178 call nf_verify(nf90_close(this%ncid), this%nc_fname)
179 deallocate (this%chunk_face)
180 nullify (this%chunk_face)
190 do idx = 1, this%pkglist%Count()
191 export_pkg => this%get(idx)
192 call this%export_df(export_pkg)
204 integer(I4B) :: iparam, iaux, layer
207 do iparam = 1, export_pkg%nparam
214 export_pkg%mf6_input%component_type, &
215 export_pkg%mf6_input%subcomponent_type, &
216 'PERIOD', export_pkg%param_names(iparam),
'')
218 select case (idt%shape)
220 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
222 do layer = 1, this%nlay
223 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
226 do iaux = 1, export_pkg%naux
227 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
230 do iaux = 1, export_pkg%naux
231 do layer = 1, this%nlay
232 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
247 integer(I4B),
intent(in) :: iparam
248 integer(I4B),
intent(in) :: iaux
249 integer(I4B),
intent(in) :: layer
251 character(len=LINELENGTH) :: varname, longname, nc_tag
252 integer(I4B) :: varid
255 nc_tag = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
259 varname =
export_varname(export_pkg%mf6_input%subcomponent_name, &
260 idt%tagname, export_pkg%mf6_input%mempath, &
261 layer=layer, iaux=iaux)
263 export_pkg%mf6_input%subcomponent_name, &
264 idt%tagname, export_pkg%mf6_input%mempath, &
265 layer=layer, iaux=iaux, &
266 component_type=idt%component_type, &
267 subcomponent_type=idt%subcomponent_type)
270 select case (idt%datatype)
271 case (
'DOUBLE1D',
'DOUBLE2D')
272 call nf_verify(nf90_def_var(this%ncid, varname, nf90_double, &
273 (/this%dim_ids%nmesh_face, &
274 this%dim_ids%time/), &
277 call nf_verify(nf90_put_att(this%ncid, varid, &
281 call nf_verify(nf90_put_att(this%ncid, varid,
'cell_methods', &
282 'time: mean'), this%nc_fname)
284 call nf_verify(nf90_def_var(this%ncid, varname, nf90_int, &
285 (/this%dim_ids%nmesh_face, &
286 this%dim_ids%time/), &
289 call nf_verify(nf90_put_att(this%ncid, varid, &
290 '_FillValue', (/nf90_fill_int/)), &
295 if (this%chunking_active)
then
296 call nf_verify(nf90_def_var_chunking(this%ncid, &
300 this%chunk_time/)), &
306 this%shuffle, this%nc_fname)
309 call nf_verify(nf90_put_att(this%ncid, varid, &
310 'long_name', longname), this%nc_fname)
314 this%gridmap_name, layer, this%nc_fname)
315 call ncvar_mf6attr(this%ncid, varid, layer, iaux, nc_tag, this%nc_fname)
318 if (idt%tagname ==
'AUX')
then
320 export_pkg%varids_aux(iaux, layer) = varid
322 export_pkg%varids_aux(iaux, 1) = varid
326 export_pkg%varids_param(iparam, layer) = varid
328 export_pkg%varids_param(iparam, 1) = varid
338 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'title', &
339 this%annotation%title), this%nc_fname)
341 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'source', &
342 this%annotation%source), this%nc_fname)
344 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'modflow_grid', &
345 this%annotation%grid), this%nc_fname)
347 if (this%annotation%mesh /=
'')
then
348 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'modflow_mesh', &
349 this%annotation%mesh), this%nc_fname)
353 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'modflow_model', &
354 this%annotation%model), this%nc_fname)
356 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'history', &
357 this%annotation%history), this%nc_fname)
359 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'Conventions', &
360 this%annotation%conventions), &
369 character(len=*),
intent(in) :: pkgtype
370 character(len=*),
intent(in) :: pkgname
371 character(len=*),
intent(in) :: mempath
373 intent(in) :: param_dfns
375 integer(I4B) :: iparam, isize
377 do iparam = 1,
size(param_dfns)
379 idt => param_dfns(iparam)
381 if (idt%blockname ==
'GRIDDATA')
then
383 call get_isize(idt%mf6varname, mempath, isize)
385 call this%export_input_array(pkgtype, pkgname, mempath, idt)
402 character(LENCOMPONENTNAME) :: ptype, pname, pkgtype
403 character(len=LENMEMPATH) :: input_mempath
405 pointer :: pkgtypes => null()
407 pointer :: pkgnames => null()
409 pointer :: mempaths => null()
411 character(len=LENMEMPATH) :: mempath
413 integer(I4B),
pointer :: export_arrays
414 logical(LGP) :: found
419 call mem_setptr(pkgtypes,
'PKGTYPES', input_mempath)
420 call mem_setptr(pkgnames,
'PKGNAMES', input_mempath)
421 call mem_setptr(mempaths,
'MEMPATHS', input_mempath)
423 allocate (export_arrays)
425 do n = 1,
size(mempaths)
430 mempath = mempaths(n)
435 if (mempath /=
'')
then
437 call mem_set_value(export_arrays,
'EXPORT_NC', mempath, found, &
439 if (export_arrays > 0)
then
444 call this%export_input_arrays(ptype, pname, mempath, param_dfns)
450 deallocate (export_arrays)
457 character(len=LINELENGTH) :: varname, longname
467 write (varname,
'(a,i0)') trim(this%xname)//
'_l', k
468 write (longname,
'(a,i0,a)') trim(this%annotation%longname)// &
472 call nf_verify(nf90_def_var(this%ncid, varname, nf90_double, &
473 (/this%dim_ids%nmesh_face, &
474 this%dim_ids%time/), &
475 this%var_ids%dependent(k)), &
479 if (this%chunking_active)
then
480 call nf_verify(nf90_def_var_chunking(this%ncid, &
481 this%var_ids%dependent(k), &
484 this%chunk_time/)), &
489 call ncvar_deflate(this%ncid, this%var_ids%dependent(k), this%deflate, &
490 this%shuffle, this%nc_fname)
494 if (this%modeltype ==
'GWF')
then
495 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
496 'units', this%lenunits), this%nc_fname)
498 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
499 'long_name', longname), this%nc_fname)
500 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
501 '_FillValue', (/dhnoflo/)), &
509 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
510 'cell_methods',
'time: point'), &
515 this%gridmap_name, k, this%nc_fname)
518 call ncvar_layer(this%ncid, this%var_ids%dependent(k), k, &
527 integer(I4B) :: var_id
528 character(len=LINELENGTH) :: gmname
529 character(len=LENBIGLINE) :: effective_crs_wkt
532 if (this%wkt /=
'' .or. this%crs_wkt /=
'')
then
534 call nf_verify(nf90_redef(this%ncid), this%nc_fname)
535 call nf_verify(nf90_def_var(this%ncid, this%gridmap_name, nf90_int, &
536 var_id), this%nc_fname)
538 if (this%wkt /=
'')
then
539 call nf_verify(nf90_put_att(this%ncid, var_id,
'wkt', this%wkt), &
543 if (this%crs_wkt /=
'')
then
544 effective_crs_wkt = this%crs_wkt
546 effective_crs_wkt = this%wkt
548 call nf_verify(nf90_put_att(this%ncid, var_id,
'crs_wkt', &
549 trim(effective_crs_wkt)), this%nc_fname)
551 gmname = wkt_to_cf_gridmapping(trim(effective_crs_wkt))
552 if (gmname /=
'')
then
553 call nf_verify(nf90_put_att(this%ncid, var_id,
'grid_mapping_name', &
554 trim(gmname)), this%nc_fname)
556 call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
557 call nf_verify(nf90_put_var(this%ncid, var_id, 1), &
568 call nf_verify(nf90_def_var(this%ncid, this%mesh_name, nf90_int, &
569 this%var_ids%mesh), this%nc_fname)
572 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh,
'cf_role', &
573 'mesh_topology'), this%nc_fname)
574 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh,
'long_name', &
575 '2D mesh topology'), this%nc_fname)
576 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
577 'topology_dimension', 2), this%nc_fname)
578 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh,
'face_dimension', &
579 'nmesh_face'), this%nc_fname)
580 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
581 'node_coordinates',
'mesh_node_x mesh_node_y'), &
583 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
584 'face_coordinates',
'mesh_face_x mesh_face_y'), &
586 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
587 'face_node_connectivity',
'mesh_face_nodes'), &
591 call nf_verify(nf90_def_var(this%ncid,
'mesh_node_x', nf90_double, &
592 (/this%dim_ids%nmesh_node/), &
593 this%var_ids%mesh_node_x), this%nc_fname)
596 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
597 'units', this%lenunits), this%nc_fname)
598 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
599 'standard_name',
'projection_x_coordinate'), &
601 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
602 'long_name',
'Easting'), this%nc_fname)
604 if (this%gridmap_name /=
'')
then
606 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
607 'grid_mapping', this%gridmap_name), &
612 call nf_verify(nf90_def_var(this%ncid,
'mesh_node_y', nf90_double, &
613 (/this%dim_ids%nmesh_node/), &
614 this%var_ids%mesh_node_y), this%nc_fname)
617 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
618 'units', this%lenunits), this%nc_fname)
619 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
620 'standard_name',
'projection_y_coordinate'), &
622 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
623 'long_name',
'Northing'), this%nc_fname)
625 if (this%gridmap_name /=
'')
then
627 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
628 'grid_mapping', this%gridmap_name), &
633 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_x', nf90_double, &
634 (/this%dim_ids%nmesh_face/), &
635 this%var_ids%mesh_face_x), this%nc_fname)
638 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
639 'units', this%lenunits), this%nc_fname)
640 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
641 'standard_name',
'projection_x_coordinate'), &
643 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
644 'long_name',
'Easting'), this%nc_fname)
645 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x,
'bounds', &
646 'mesh_face_xbnds'), this%nc_fname)
647 if (this%gridmap_name /=
'')
then
649 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
650 'grid_mapping', this%gridmap_name), &
655 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_xbnds', nf90_double, &
656 (/this%dim_ids%max_nmesh_face_nodes, &
657 this%dim_ids%nmesh_face/), &
658 this%var_ids%mesh_face_xbnds), &
662 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_y', nf90_double, &
663 (/this%dim_ids%nmesh_face/), &
664 this%var_ids%mesh_face_y), this%nc_fname)
667 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
668 'units', this%lenunits), this%nc_fname)
669 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
670 'standard_name',
'projection_y_coordinate'), &
672 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
673 'long_name',
'Northing'), this%nc_fname)
674 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y,
'bounds', &
675 'mesh_face_ybnds'), this%nc_fname)
677 if (this%gridmap_name /=
'')
then
679 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
680 'grid_mapping', this%gridmap_name), &
685 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_ybnds', nf90_double, &
686 (/this%dim_ids%max_nmesh_face_nodes, &
687 this%dim_ids%nmesh_face/), &
688 this%var_ids%mesh_face_ybnds), &
692 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_nodes', nf90_int, &
693 (/this%dim_ids%max_nmesh_face_nodes, &
694 this%dim_ids%nmesh_face/), &
695 this%var_ids%mesh_face_nodes), &
699 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
700 'cf_role',
'face_node_connectivity'), &
702 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
704 'Vertices bounding cell (counterclockwise)'), &
706 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
707 '_FillValue', (/nf90_fill_int/)), &
709 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
710 'start_index', 1), this%nc_fname)
716 integer(I4B),
intent(in) :: ncid
717 integer(I4B),
intent(in) :: varid
718 integer(I4B),
intent(in) :: chunk_face
719 character(len=*),
intent(in) :: nc_fname
720 if (chunk_face > 0)
then
721 call nf_verify(nf90_def_var_chunking(ncid, varid, nf90_chunked, &
722 (/chunk_face/)), nc_fname)
729 integer(I4B),
intent(in) :: ncid
730 integer(I4B),
intent(in) :: varid
731 integer(I4B),
intent(in) :: deflate
732 integer(I4B),
intent(in) :: shuffle
733 character(len=*),
intent(in) :: nc_fname
734 if (deflate >= 0)
then
735 call nf_verify(nf90_def_var_deflate(ncid, varid, shuffle=shuffle, &
736 deflate=1, deflate_level=deflate), &
750 integer(I4B),
intent(in) :: ncid
751 integer(I4B),
intent(in) :: varid
752 character(len=*),
intent(in) :: gridmap_name
753 integer(I4B),
intent(in) :: layer
754 character(len=*),
intent(in) :: nc_fname
755 character(len=LINELENGTH) :: coords
757 call nf_verify(nf90_put_att(ncid, varid,
'mesh',
'mesh'), nc_fname)
758 call nf_verify(nf90_put_att(ncid, varid,
'location',
'face'), nc_fname)
760 write (coords,
'(a,i0)')
'mesh_face_x mesh_face_y z_l', layer
762 coords =
'mesh_face_x mesh_face_y'
764 call nf_verify(nf90_put_att(ncid, varid,
'coordinates', trim(coords)), &
767 if (gridmap_name /=
'')
then
768 call nf_verify(nf90_put_att(ncid, varid,
'grid_mapping', &
769 gridmap_name), nc_fname)
776 integer(I4B),
intent(in) :: ncid
777 integer(I4B),
intent(in) :: varid
778 integer(I4B),
intent(in) :: layer
779 integer(I4B),
intent(in) :: iaux
780 character(len=*),
intent(in) :: nc_tag
781 character(len=*),
intent(in) :: nc_fname
782 if (nc_tag /=
'')
then
783 call nf_verify(nf90_put_att(ncid, varid,
'modflow_input', &
787 call nf_verify(nf90_put_att(ncid, varid,
'modflow_iaux', &
801 integer(I4B),
intent(in) :: ncid
802 integer(I4B),
intent(in) :: varid
803 integer(I4B),
intent(in) :: layer
804 character(len=*),
intent(in) :: nc_fname
806 call nf_verify(nf90_put_att(ncid, varid,
'layer', layer), nc_fname)
abstract interfaces for derived ugrid netcd export types
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
integer(i4b), parameter lencomponentname
maximum length of a component name
real(dp), parameter dnodata
real no data constant
integer(i4b), parameter lenbigline
maximum length of a big line
real(dp), parameter dhnoflo
real no flow constant
integer(i4b), parameter lenmempath
maximum length of the memory path
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename, found)
Return parameter definition.
type(inputparamdefinitiontype) function, dimension(:), pointer, public param_definitions(component, subcomponent)
logical function, public idm_multi_package(component, subcomponent)
This module defines variable data types.
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public get_isize(name, mem_path, isize)
Get the number of elements for this variable.
This module contains the MeshModelModule.
subroutine, public ncvar_mf6attr(ncid, varid, layer, iaux, nc_tag, nc_fname)
put variable internal attributes
subroutine, public ncvar_gridmap(ncid, varid, gridmap_name, layer, nc_fname)
put variable gridmap attributes
subroutine define_gridmap(this)
create the file grid mapping container variable
subroutine create_timeseries(this, idt, iparam, iaux, layer, export_pkg)
create timeseries export variable
subroutine, public ncvar_chunk(ncid, varid, chunk_face, nc_fname)
define variable chunking
subroutine mesh_init(this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, lenuni, iout)
initialize
subroutine mesh_destroy(this)
initialize
subroutine add_global_att(this)
create file (group) attributes
subroutine add_pkg_data(this)
determine packages to write gridded input
subroutine df_export(this)
define timeseries input variables
subroutine export_df(this, export_pkg)
define export package
subroutine, public ncvar_layer(ncid, varid, layer, nc_fname)
put the layer attribute (only when layer > 0)
subroutine export_input_arrays(this, pkgtype, pkgname, mempath, param_dfns)
write package gridded input data
subroutine define_dependent(this)
create the model layer dependent variables
subroutine, public ncvar_deflate(ncid, varid, deflate, shuffle, nc_fname)
define variable compression
subroutine create_mesh(this)
create the file mesh container variable
This module contains the NCModelExportModule.
character(len=linelength) function, public wkt_to_cf_gridmapping(wkt)
map a WKT string to a CF-1.13 grid_mapping_name
character(len=linelength) function, public export_varname(pkgname, tagname, mempath, layer, iaux)
build netcdf variable name
character(len=linelength) function, public export_longname(longname, pkgname, tagname, mempath, layer, iaux, component_type, subcomponent_type)
build netcdf variable longname
This module contains the NetCDFCommonModule.
subroutine, public nf_verify(res, nc_fname)
error check a netcdf-fortran interface call
This module contains simulation methods.
subroutine, public store_warning(msg, substring)
Store warning message.
subroutine, public store_error(msg, terminate)
Store an error message.
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
character(len=linelength) idm_context
character(len=maxcharlen) warnmsg
warning message string
This module contains the SourceCommonModule.
character(len=lencomponentname) function, public idm_subcomponent_type(component, subcomponent)
component from package or model type
character(len=lenpackagename) function, public idm_subcomponent_name(component_type, subcomponent_type, sc_name)
model package subcomponent name
This class is used to store a single deferred-length character string. It was designed to work in an ...
base ugrid netcdf export type
type for storing model export dimension ids
type for storing model export variable ids
abstract type for model netcdf export type