35 integer(I4B) :: nmesh_node
36 integer(I4B) :: nmesh_face
37 integer(I4B) :: max_nmesh_face_nodes
47 integer(I4B) :: mesh_node_x
48 integer(I4B) :: mesh_node_y
49 integer(I4B) :: mesh_face_x
50 integer(I4B) :: mesh_face_y
51 integer(I4B) :: mesh_face_xbnds
52 integer(I4B) :: mesh_face_ybnds
53 integer(I4B) :: mesh_face_nodes
56 integer(I4B),
dimension(:),
allocatable :: export
57 integer(I4B),
dimension(:),
allocatable :: dependent
58 integer(I4B),
dimension(:),
allocatable :: elevation
68 integer(I4B),
pointer :: chunk_face
89 character(len=*),
intent(in) :: pkgtype
90 character(len=*),
intent(in) :: pkgname
91 character(len=*),
intent(in) :: mempath
105 subroutine mesh_init(this, modelname, modeltype, modelfname, nc_fname, &
106 disenum, nctype, lenuni, iout)
109 character(len=*),
intent(in) :: modelname
110 character(len=*),
intent(in) :: modeltype
111 character(len=*),
intent(in) :: modelfname
112 character(len=*),
intent(in) :: nc_fname
113 integer(I4B),
intent(in) :: disenum
114 integer(I4B),
intent(in) :: nctype
115 integer(I4B),
intent(in) :: lenuni
116 integer(I4B),
intent(in) :: iout
117 logical(LGP) :: found
118 integer(I4B) :: latsz, lonsz
121 call this%NCModelExportType%init(modelname, modeltype, modelfname, nc_fname, &
122 disenum, nctype, iout)
124 if (this%ncf_mempath /=
'')
then
127 call get_isize(
'LATITUDE', this%ncf_mempath, latsz)
128 call get_isize(
'LONGITUDE', this%ncf_mempath, lonsz)
129 if (latsz > 0 .or. lonsz > 0)
then
130 write (
warnmsg,
'(a)')
'LATITUDE and LONGITUDE griddata are not &
131 &supported for a NETCDF_MESH2D export and will be ignored. &
132 &Applies to file "'//trim(nc_fname)//
'".'
138 allocate (this%chunk_face)
142 if (this%ncf_mempath /=
'')
then
143 call mem_set_value(this%chunk_face,
'CHUNK_FACE', this%ncf_mempath, found)
146 if (this%chunk_time > 0 .and. this%chunk_face > 0)
then
147 this%chunking_active = .true.
148 else if (this%chunk_time > 0 .or. this%chunk_face > 0)
then
151 write (
warnmsg,
'(a)')
'Ignoring user provided NetCDF chunking parameter. &
152 &Define chunk_time and chunk_face input parameters to see an effect in &
153 &file "'//trim(nc_fname)//
'".'
157 if (lenuni == 1)
then
159 else if (lenuni == 3)
then
166 call nf_verify(nf90_create(this%nc_fname, &
167 ior(nf90_clobber, nf90_netcdf4), this%ncid), &
176 call nf_verify(nf90_close(this%ncid), this%nc_fname)
177 deallocate (this%chunk_face)
178 nullify (this%chunk_face)
188 do idx = 1, this%pkglist%Count()
189 export_pkg => this%get(idx)
190 call this%export_df(export_pkg)
202 integer(I4B) :: iparam, iaux, layer
205 do iparam = 1, export_pkg%nparam
212 export_pkg%mf6_input%component_type, &
213 export_pkg%mf6_input%subcomponent_type, &
214 'PERIOD', export_pkg%param_names(iparam),
'')
216 select case (idt%shape)
218 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
220 do layer = 1, this%nlay
221 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
224 do iaux = 1, export_pkg%naux
225 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
228 do iaux = 1, export_pkg%naux
229 do layer = 1, this%nlay
230 call this%create_timeseries(idt, iparam, iaux, layer, export_pkg)
245 integer(I4B),
intent(in) :: iparam
246 integer(I4B),
intent(in) :: iaux
247 integer(I4B),
intent(in) :: layer
249 character(len=LINELENGTH) :: varname, longname, nc_tag
250 integer(I4B) :: varid
253 nc_tag = this%input_attribute(export_pkg%mf6_input%subcomponent_name, &
257 varname = export_varname(export_pkg%mf6_input%subcomponent_name, &
258 idt%tagname, export_pkg%mf6_input%mempath, &
259 layer=layer, iaux=iaux)
260 longname = export_longname(idt%longname, &
261 export_pkg%mf6_input%subcomponent_name, &
262 idt%tagname, export_pkg%mf6_input%mempath, &
263 layer=layer, iaux=iaux, &
264 component_type=idt%component_type, &
265 subcomponent_type=idt%subcomponent_type)
268 select case (idt%datatype)
269 case (
'DOUBLE1D',
'DOUBLE2D')
270 call nf_verify(nf90_def_var(this%ncid, varname, nf90_double, &
271 (/this%dim_ids%nmesh_face, &
272 this%dim_ids%time/), &
275 call nf_verify(nf90_put_att(this%ncid, varid, &
279 call nf_verify(nf90_def_var(this%ncid, varname, nf90_int, &
280 (/this%dim_ids%nmesh_face, &
281 this%dim_ids%time/), &
284 call nf_verify(nf90_put_att(this%ncid, varid, &
285 '_FillValue', (/nf90_fill_int/)), &
290 if (this%chunking_active)
then
291 call nf_verify(nf90_def_var_chunking(this%ncid, &
295 this%chunk_time/)), &
301 this%shuffle, this%nc_fname)
304 call nf_verify(nf90_put_att(this%ncid, varid, &
305 'units', this%lenunits), this%nc_fname)
306 call nf_verify(nf90_put_att(this%ncid, varid, &
307 'long_name', longname), this%nc_fname)
311 this%gridmap_name, layer, this%nc_fname)
312 call ncvar_mf6attr(this%ncid, varid, layer, iaux, nc_tag, this%nc_fname)
315 if (idt%tagname ==
'AUX')
then
317 export_pkg%varids_aux(iaux, layer) = varid
319 export_pkg%varids_aux(iaux, 1) = varid
323 export_pkg%varids_param(iparam, layer) = varid
325 export_pkg%varids_param(iparam, 1) = varid
335 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'title', &
336 this%annotation%title), this%nc_fname)
338 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'source', &
339 this%annotation%source), this%nc_fname)
341 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'modflow_grid', &
342 this%annotation%grid), this%nc_fname)
344 if (this%annotation%mesh /=
'')
then
345 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'modflow_mesh', &
346 this%annotation%mesh), this%nc_fname)
350 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'modflow_model', &
351 this%annotation%model), this%nc_fname)
353 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'history', &
354 this%annotation%history), this%nc_fname)
356 call nf_verify(nf90_put_att(this%ncid, nf90_global,
'Conventions', &
357 this%annotation%conventions), &
366 character(len=*),
intent(in) :: pkgtype
367 character(len=*),
intent(in) :: pkgname
368 character(len=*),
intent(in) :: mempath
370 intent(in) :: param_dfns
372 integer(I4B) :: iparam, isize
374 do iparam = 1,
size(param_dfns)
376 idt => param_dfns(iparam)
378 if (idt%blockname ==
'GRIDDATA')
then
380 call get_isize(idt%mf6varname, mempath, isize)
382 call this%export_input_array(pkgtype, pkgname, mempath, idt)
398 character(LENCOMPONENTNAME) :: ptype, pname, pkgtype
399 character(len=LENMEMPATH) :: input_mempath
401 pointer :: pkgtypes => null()
403 pointer :: pkgnames => null()
405 pointer :: mempaths => null()
407 character(len=LENMEMPATH) :: mempath
409 integer(I4B),
pointer :: export_arrays
410 logical(LGP) :: found
415 call mem_setptr(pkgtypes,
'PKGTYPES', input_mempath)
416 call mem_setptr(pkgnames,
'PKGNAMES', input_mempath)
417 call mem_setptr(mempaths,
'MEMPATHS', input_mempath)
419 allocate (export_arrays)
421 do n = 1,
size(mempaths)
426 mempath = mempaths(n)
431 if (mempath /=
'')
then
433 call mem_set_value(export_arrays,
'EXPORT_NC', mempath, found, &
435 if (export_arrays > 0)
then
437 param_dfns => param_definitions(this%modeltype, pkgtype)
438 call this%export_input_arrays(ptype, pname, mempath, param_dfns)
444 deallocate (export_arrays)
451 character(len=LINELENGTH) :: varname, longname
461 write (varname,
'(a,i0)') trim(this%xname)//
'_l', k
462 write (longname,
'(a,i0,a)') trim(this%annotation%longname)// &
466 call nf_verify(nf90_def_var(this%ncid, varname, nf90_double, &
467 (/this%dim_ids%nmesh_face, &
468 this%dim_ids%time/), &
469 this%var_ids%dependent(k)), &
473 if (this%chunking_active)
then
474 call nf_verify(nf90_def_var_chunking(this%ncid, &
475 this%var_ids%dependent(k), &
478 this%chunk_time/)), &
483 call ncvar_deflate(this%ncid, this%var_ids%dependent(k), this%deflate, &
484 this%shuffle, this%nc_fname)
487 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
488 'units', this%lenunits), this%nc_fname)
489 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
490 'long_name', longname), this%nc_fname)
491 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
500 call nf_verify(nf90_put_att(this%ncid, this%var_ids%dependent(k), &
501 'cell_methods',
'time: point'), &
506 this%gridmap_name, k, this%nc_fname)
509 call ncvar_layer(this%ncid, this%var_ids%dependent(k), k, &
518 integer(I4B) :: var_id
519 character(len=LINELENGTH) :: gmname
520 character(len=LENBIGLINE) :: effective_crs_wkt
523 if (this%wkt /=
'' .or. this%crs_wkt /=
'')
then
525 call nf_verify(nf90_redef(this%ncid), this%nc_fname)
526 call nf_verify(nf90_def_var(this%ncid, this%gridmap_name, nf90_int, &
527 var_id), this%nc_fname)
529 if (this%wkt /=
'')
then
530 call nf_verify(nf90_put_att(this%ncid, var_id,
'wkt', this%wkt), &
534 if (this%crs_wkt /=
'')
then
535 effective_crs_wkt = this%crs_wkt
537 effective_crs_wkt = this%wkt
539 call nf_verify(nf90_put_att(this%ncid, var_id,
'crs_wkt', &
540 trim(effective_crs_wkt)), this%nc_fname)
543 if (gmname /=
'')
then
544 call nf_verify(nf90_put_att(this%ncid, var_id,
'grid_mapping_name', &
545 trim(gmname)), this%nc_fname)
547 call nf_verify(nf90_enddef(this%ncid), this%nc_fname)
548 call nf_verify(nf90_put_var(this%ncid, var_id, 1), &
559 call nf_verify(nf90_def_var(this%ncid, this%mesh_name, nf90_int, &
560 this%var_ids%mesh), this%nc_fname)
563 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh,
'cf_role', &
564 'mesh_topology'), this%nc_fname)
565 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh,
'long_name', &
566 '2D mesh topology'), this%nc_fname)
567 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
568 'topology_dimension', 2), this%nc_fname)
569 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh,
'face_dimension', &
570 'nmesh_face'), this%nc_fname)
571 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
572 'node_coordinates',
'mesh_node_x mesh_node_y'), &
574 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
575 'face_coordinates',
'mesh_face_x mesh_face_y'), &
577 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh, &
578 'face_node_connectivity',
'mesh_face_nodes'), &
582 call nf_verify(nf90_def_var(this%ncid,
'mesh_node_x', nf90_double, &
583 (/this%dim_ids%nmesh_node/), &
584 this%var_ids%mesh_node_x), this%nc_fname)
587 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
588 'units', this%lenunits), this%nc_fname)
589 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
590 'standard_name',
'projection_x_coordinate'), &
592 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
593 'long_name',
'Easting'), this%nc_fname)
595 if (this%gridmap_name /=
'')
then
597 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_x, &
598 'grid_mapping', this%gridmap_name), &
603 call nf_verify(nf90_def_var(this%ncid,
'mesh_node_y', nf90_double, &
604 (/this%dim_ids%nmesh_node/), &
605 this%var_ids%mesh_node_y), this%nc_fname)
608 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
609 'units', this%lenunits), this%nc_fname)
610 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
611 'standard_name',
'projection_y_coordinate'), &
613 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
614 'long_name',
'Northing'), this%nc_fname)
616 if (this%gridmap_name /=
'')
then
618 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_node_y, &
619 'grid_mapping', this%gridmap_name), &
624 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_x', nf90_double, &
625 (/this%dim_ids%nmesh_face/), &
626 this%var_ids%mesh_face_x), this%nc_fname)
629 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
630 'units', this%lenunits), this%nc_fname)
631 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
632 'standard_name',
'projection_x_coordinate'), &
634 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
635 'long_name',
'Easting'), this%nc_fname)
636 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x,
'bounds', &
637 'mesh_face_xbnds'), this%nc_fname)
638 if (this%gridmap_name /=
'')
then
640 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_x, &
641 'grid_mapping', this%gridmap_name), &
646 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_xbnds', nf90_double, &
647 (/this%dim_ids%max_nmesh_face_nodes, &
648 this%dim_ids%nmesh_face/), &
649 this%var_ids%mesh_face_xbnds), &
653 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_y', nf90_double, &
654 (/this%dim_ids%nmesh_face/), &
655 this%var_ids%mesh_face_y), this%nc_fname)
658 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
659 'units', this%lenunits), this%nc_fname)
660 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
661 'standard_name',
'projection_y_coordinate'), &
663 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
664 'long_name',
'Northing'), this%nc_fname)
665 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y,
'bounds', &
666 'mesh_face_ybnds'), this%nc_fname)
668 if (this%gridmap_name /=
'')
then
670 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_y, &
671 'grid_mapping', this%gridmap_name), &
676 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_ybnds', nf90_double, &
677 (/this%dim_ids%max_nmesh_face_nodes, &
678 this%dim_ids%nmesh_face/), &
679 this%var_ids%mesh_face_ybnds), &
683 call nf_verify(nf90_def_var(this%ncid,
'mesh_face_nodes', nf90_int, &
684 (/this%dim_ids%max_nmesh_face_nodes, &
685 this%dim_ids%nmesh_face/), &
686 this%var_ids%mesh_face_nodes), &
690 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
691 'cf_role',
'face_node_connectivity'), &
693 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
695 'Vertices bounding cell (counterclockwise)'), &
697 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
698 '_FillValue', (/nf90_fill_int/)), &
700 call nf_verify(nf90_put_att(this%ncid, this%var_ids%mesh_face_nodes, &
701 'start_index', 1), this%nc_fname)
707 integer(I4B),
intent(in) :: ncid
708 integer(I4B),
intent(in) :: varid
709 integer(I4B),
intent(in) :: chunk_face
710 character(len=*),
intent(in) :: nc_fname
711 if (chunk_face > 0)
then
712 call nf_verify(nf90_def_var_chunking(ncid, varid, nf90_chunked, &
713 (/chunk_face/)), nc_fname)
720 integer(I4B),
intent(in) :: ncid
721 integer(I4B),
intent(in) :: varid
722 integer(I4B),
intent(in) :: deflate
723 integer(I4B),
intent(in) :: shuffle
724 character(len=*),
intent(in) :: nc_fname
725 if (deflate >= 0)
then
726 call nf_verify(nf90_def_var_deflate(ncid, varid, shuffle=shuffle, &
727 deflate=1, deflate_level=deflate), &
741 integer(I4B),
intent(in) :: ncid
742 integer(I4B),
intent(in) :: varid
743 character(len=*),
intent(in) :: gridmap_name
744 integer(I4B),
intent(in) :: layer
745 character(len=*),
intent(in) :: nc_fname
746 character(len=LINELENGTH) :: coords
748 call nf_verify(nf90_put_att(ncid, varid,
'mesh',
'mesh'), nc_fname)
749 call nf_verify(nf90_put_att(ncid, varid,
'location',
'face'), nc_fname)
751 write (coords,
'(a,i0)')
'mesh_face_x mesh_face_y z_l', layer
753 coords =
'mesh_face_x mesh_face_y'
755 call nf_verify(nf90_put_att(ncid, varid,
'coordinates', trim(coords)), &
758 if (gridmap_name /=
'')
then
759 call nf_verify(nf90_put_att(ncid, varid,
'grid_mapping', &
760 gridmap_name), nc_fname)
767 integer(I4B),
intent(in) :: ncid
768 integer(I4B),
intent(in) :: varid
769 integer(I4B),
intent(in) :: layer
770 integer(I4B),
intent(in) :: iaux
771 character(len=*),
intent(in) :: nc_tag
772 character(len=*),
intent(in) :: nc_fname
773 if (nc_tag /=
'')
then
774 call nf_verify(nf90_put_att(ncid, varid,
'modflow_input', &
778 call nf_verify(nf90_put_att(ncid, varid,
'modflow_iaux', &
792 integer(I4B),
intent(in) :: ncid
793 integer(I4B),
intent(in) :: varid
794 integer(I4B),
intent(in) :: layer
795 character(len=*),
intent(in) :: nc_fname
797 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)
@ brief 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
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