MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
ncmodelexportmodule Module Reference

This module contains the NCModelExportModule. More...

Data Types

type  exportpackagetype
type  ncexportannotation
 netcdf export attribute annotations More...
type  ncmodelexporttype
 base class for an export model More...
type  ncbasemodelexporttype
 abstract type for model netcdf export type More...
interface  model_define
 abstract interfaces for model netcdf export type More...
interface  model_step
interface  package_export
interface  package_export_ilayer

Enumerations

enum  { netcdf_undef = 0 , netcdf_structured = 1 , netcdf_mesh2d = 2 }
 netcdf export types enumerator More...

Functions/Subroutines

subroutine epkg_init (this, mf6_input, mshape, naux, param_names, nparam)
 initialize dynamic package export object
subroutine update_state (this)
 Update input in effect from the period block read states.
subroutine set_state (invar, has_value)
 Set input in effect from a read state.
logical(lgp) function param_state (this, iparam)
 .true. if a param has input in effect to export
logical(lgp) function aux_state (this, iaux)
 .true. if an auxiliary variable has input in effect to export
subroutine user_nodes (this, vals, nodes)
 Set user node values from a loaded period array.
subroutine epkg_destroy (this)
 destroy dynamic package export object
subroutine set (this, modelname, modeltype, modelfname, nctype, disenum)
 set netcdf file scoped attributes
subroutine export_init (this, modelname, modeltype, modelfname, nc_fname, disenum, nctype, iout)
 initialization of model netcdf export
class(exportpackagetype) function, pointer export_get (this, idx)
 retrieve dynamic export object from package list
character(len=linelength) function input_attribute (this, pkgname, idt)
 build modflow_input attribute string
integer(i4b) function istp (this)
 step index for timeseries data
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
subroutine export_input (this)
 netcdf dynamic package period export
character(len=linelength) function, public wkt_to_cf_gridmapping (wkt)
 map a WKT string to a CF-1.13 grid_mapping_name
real(dp) function wkt_find_param (wkt, name, found)
 find the first number following a quoted parameter name
subroutine wkt_find_ellipsoid (wkt, semi_major_axis, inverse_flattening, found)
 find semi-major axis and inverse flattening from a WKT string
subroutine, public wkt_transverse_mercator_params (wkt, longitude_of_central_meridian, latitude_of_projection_origin, scale_factor_at_central_meridian, false_easting, false_northing, semi_major_axis, inverse_flattening, found)
 extract CF transverse_mercator grid_mapping parameters
subroutine, public wkt_lambert_conformal_conic_params (wkt, standard_parallel_1, standard_parallel_2, longitude_of_central_meridian, latitude_of_projection_origin, false_easting, false_northing, semi_major_axis, inverse_flattening, is_2sp, found)
 extract CF lambert_conformal_conic grid_mapping parameters
subroutine, public wkt_albers_conical_equal_area_params (wkt, standard_parallel_1, standard_parallel_2, longitude_of_central_meridian, latitude_of_projection_origin, false_easting, false_northing, semi_major_axis, inverse_flattening, found)
 extract CF albers_conical_equal_area grid_mapping parameters
character(len=lenbigline) function, public wrap_rotated_crs (wkt, xorigin, yorigin, angrot)
 wrap a WKT2 PROJCRS in a derived CRS encoding grid rotation
subroutine export_destroy (this)
 destroy model netcdf export object

Detailed Description

This module defines a model export and base type for supported netcdf files and is not dependent on netcdf libraries.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
netcdf_undef 

undefined netcdf export type

netcdf_structured 

netcdf structrured export

netcdf_mesh2d 

netcdf ugrid layered mesh export

Definition at line 36 of file NCModel.f90.

Function/Subroutine Documentation

◆ aux_state()

logical(lgp) function ncmodelexportmodule::aux_state ( class(exportpackagetype), intent(in) this,
integer(i4b), intent(in) iaux )
private

Definition at line 268 of file NCModel.f90.

269 class(ExportPackageType), intent(in) :: this
270 integer(I4B), intent(in) :: iaux
271 logical(LGP) :: exported
272 exported = this%aux_value(iaux)

◆ epkg_destroy()

subroutine ncmodelexportmodule::epkg_destroy ( class(exportpackagetype), intent(inout) this)
private

Definition at line 302 of file NCModel.f90.

304 class(ExportPackageType), intent(inout) :: this
305 if (allocated(this%param_names)) deallocate (this%param_names)
306 if (allocated(this%param_value)) deallocate (this%param_value)
307 if (allocated(this%aux_value)) deallocate (this%aux_value)
308 nullify (this%aux_reads)
Input definition module.
Input parameter definition. Describes an input parameter.

◆ epkg_init()

subroutine ncmodelexportmodule::epkg_init ( class(exportpackagetype), intent(inout) this,
type(modflowinputtype), intent(in) mf6_input,
integer(i4b), dimension(:), intent(in), pointer, contiguous mshape,
integer(i4b), intent(in) naux,
character(len=linelength), dimension(:), intent(in), allocatable param_names,
integer(i4b), intent(in) nparam )
private
Parameters
[in]mshapemodel shape

Definition at line 159 of file NCModel.f90.

165 class(ExportPackageType), intent(inout) :: this
166 type(ModflowInputType), intent(in) :: mf6_input
167 integer(I4B), dimension(:), pointer, contiguous, intent(in) :: mshape !< model shape
168 integer(I4B), intent(in) :: naux
169 character(len=LINELENGTH), dimension(:), allocatable, &
170 intent(in) :: param_names
171 integer(I4B), intent(in) :: nparam
172 integer(I4B) :: n
173 character(len=LENVARNAME) :: rs_varname
174 character(len=LENMEMPATH) :: input_mempath
175 integer(I4B), pointer :: rsvar
176
177 this%mf6_input = mf6_input
178 this%mshape => mshape
179 this%nparam = nparam
180 this%naux = naux
181 this%eper = 0
182
183 input_mempath = create_mem_path(component=mf6_input%component_name, &
184 subcomponent=mf6_input%subcomponent_name, &
185 context=idm_context)
186
187 ! allocate param arrays
188 allocate (this%param_names(nparam))
189 allocate (this%param_reads(nparam))
190 allocate (this%varids_param(nparam, mshape(1)))
191 allocate (this%varids_aux(naux, mshape(1)))
192
193 ! set param arrays
194 do n = 1, nparam
195 this%param_names(n) = param_names(n)
196 rs_varname = rsv_name(param_names(n))
197 call mem_setptr(rsvar, rs_varname, mf6_input%mempath)
198 this%param_reads(n)%invar => rsvar
199 end do
200
201 ! set pointer to loaded input period
202 call mem_setptr(this%iper, 'IPER', mf6_input%mempath)
203
204 ! read state of each auxiliary variable
205 call mem_setptr(this%aux_reads, 'INAUXVARS', mf6_input%mempath)
206
207 ! input in effect before the first period: the layer index array
208 ! (e.g. IRCH, IEVT) is 1, other arrays have no input
209 allocate (this%param_value(nparam))
210 allocate (this%aux_value(naux))
211 this%param_value = .false.
212 this%aux_value = .false.
213 do n = 1, nparam
214 if (param_names(n) == 'I'//trim(mf6_input%subcomponent_type(1:3))) &
215 this%param_value(n) = .true.
216 end do
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains simulation variables.
character(len=linelength) idm_context
Here is the call graph for this function:

◆ export_destroy()

subroutine ncmodelexportmodule::export_destroy ( class(ncmodelexporttype), intent(inout) this)
private

Definition at line 1119 of file NCModel.f90.

1122 class(NCModelExportType), intent(inout) :: this
1123 ! override in derived class
1124 deallocate (this%deflate)
1125 deallocate (this%shuffle)
1126 deallocate (this%input_attr)
1127 deallocate (this%chunk_time)
1128 ! Deallocate idm memory
1129 if (this%ncf_mempath /= '') then
1130 call memorystore_remove(this%modelname, 'NCF', idm_context)
1131 end if
subroutine, public memorystore_remove(component, subcomponent, context)
Here is the call graph for this function:

◆ export_get()

class(exportpackagetype) function, pointer ncmodelexportmodule::export_get ( class(ncmodelexporttype), intent(inout) this,
integer(i4b), intent(in) idx )
private

Definition at line 510 of file NCModel.f90.

511 use listmodule, only: listtype
512 class(NCModelExportType), intent(inout) :: this
513 integer(I4B), intent(in) :: idx
514 class(ExportPackageType), pointer :: res
515 class(*), pointer :: obj
516 nullify (res)
517 obj => this%pkglist%GetItem(idx)
518 if (associated(obj)) then
519 select type (obj)
520 class is (exportpackagetype)
521 res => obj
522 end select
523 end if
A generic heterogeneous doubly-linked list.
Definition List.f90:14

◆ export_init()

subroutine ncmodelexportmodule::export_init ( class(ncmodelexporttype), intent(inout) this,
character(len=*), intent(in) modelname,
character(len=*), intent(in) modeltype,
character(len=*), intent(in) modelfname,
character(len=*), intent(in) nc_fname,
integer(i4b), intent(in) disenum,
integer(i4b), intent(in) nctype,
integer(i4b), intent(in) iout )
private

Definition at line 388 of file NCModel.f90.

390 use tdismodule, only: datetime0, nper, nstp
394 use inputoutputmodule, only: lowcase
397 class(NCModelExportType), intent(inout) :: this
398 character(len=*), intent(in) :: modelname
399 character(len=*), intent(in) :: modeltype
400 character(len=*), intent(in) :: modelfname
401 character(len=*), intent(in) :: nc_fname
402 integer(I4B), intent(in) :: disenum
403 integer(I4B), intent(in) :: nctype
404 integer(I4B), intent(in) :: iout
405 character(len=LENMEMPATH) :: model_mempath
406 type(UtlNcfParamFoundType) :: ncf_found
407
408 ! allocate
409 allocate (this%deflate)
410 allocate (this%shuffle)
411 allocate (this%input_attr)
412 allocate (this%chunk_time)
413
414 ! initialize
415 this%modelname = modelname
416 this%modeltype = modeltype
417 this%modelfname = modelfname
418 this%nc_fname = nc_fname
419 this%gridmap_name = ''
420 this%ncf_mempath = ''
421 this%wkt = ''
422 this%crs_wkt = ''
423 this%datetime = ''
424 this%xname = ''
425 this%lenunits = ''
426 this%disenum = disenum
427 this%ncid = 0
428 this%totnstp = 0
429 this%deflate = -1
430 this%shuffle = 0
431 this%input_attr = 1
432 this%chunk_time = -1
433 this%iout = iout
434 this%chunking_active = .false.
435
436 ! set file scoped attributes
437 call this%annotation%set(modelname, modeltype, modelfname, nctype, disenum)
438
439 ! set dependent variable basename
440 select case (modeltype)
441 case ('GWF')
442 this%xname = 'head'
443 case ('GWT')
444 this%xname = 'concentration'
445 case ('GWE')
446 this%xname = 'temperature'
447 case default
448 errmsg = trim(modeltype)//' models not supported for NetCDF export.'
449 call store_error(errmsg)
450 call store_error_filename(modelfname)
451 end select
452
453 ! set discretization input mempath
454 if (disenum == dis) then
455 this%dis_mempath = create_mem_path(modelname, 'DIS', idm_context)
456 else if (disenum == disu) then
457 this%dis_mempath = create_mem_path(modelname, 'DISU', idm_context)
458 else if (disenum == disv) then
459 this%dis_mempath = create_mem_path(modelname, 'DISV', idm_context)
460 end if
461
462 ! set dependent variable pointer
463 model_mempath = create_mem_path(component=modelname)
464 call mem_setptr(this%x, 'X', model_mempath)
465
466 ! set ncf_mempath if provided
467 if (filein_fname(this%ncf_mempath, 'NCF6_MEMPATH', this%dis_mempath, &
468 modelfname)) then
469 call mem_set_value(this%wkt, 'WKT', this%ncf_mempath, &
470 ncf_found%wkt)
471 call mem_set_value(this%crs_wkt, 'CRS_WKT', this%ncf_mempath, &
472 ncf_found%crs_wkt)
473 call mem_set_value(this%deflate, 'DEFLATE', this%ncf_mempath, &
474 ncf_found%deflate)
475 call mem_set_value(this%shuffle, 'SHUFFLE', this%ncf_mempath, &
476 ncf_found%shuffle)
477 call mem_set_value(this%input_attr, 'ATTR_OFF', this%ncf_mempath, &
478 ncf_found%attr_off)
479 call mem_set_value(this%chunk_time, 'CHUNK_TIME', this%ncf_mempath, &
480 ncf_found%chunk_time)
481 end if
482
483 if (ncf_found%wkt .or. ncf_found%crs_wkt) then
484 this%gridmap_name = 'projection'
485 end if
486
487 ! ATTR_OFF turns off modflow 6 input attributes
488 if (ncf_found%attr_off) then
489 this%input_attr = 0
490 end if
491
492 ! set datetime string
493 if (datetime0 /= '') then
494 this%datetime = 'days since '//trim(datetime0)
495 else
496 ! January 1, 1970 at 00:00:00 UTC
497 this%datetime = 'days since 1970-01-01T00:00:00'
498 end if
499
500 ! set total nstp
501 if (isim_mode == mvalidate) then
502 this%totnstp = nper
503 else
504 this%totnstp = sum(nstp)
505 end if
subroutine, public lowcase(word)
Convert to lower case.
This module contains the SourceCommonModule.
logical(lgp) function, public filein_fname(filename, tagname, input_mempath, input_fname)
enforce and set a single input filename provided via FILEIN keyword
integer(i4b), dimension(:), pointer, public, contiguous nstp
number of time steps in each stress period
Definition tdis.f90:42
character(len=lendatetime), pointer, public datetime0
starting date and time for the simulation
Definition tdis.f90:44
integer(i4b), pointer, public nper
number of stress period
Definition tdis.f90:24
Here is the call graph for this function:

◆ export_input()

subroutine ncmodelexportmodule::export_input ( class(ncbasemodelexporttype), intent(inout) this)
private

Definition at line 655 of file NCModel.f90.

656 use tdismodule, only: kper
657 class(NCBaseModelExportType), intent(inout) :: this
658 integer(I4B) :: idx
659 class(ExportPackageType), pointer :: export_pkg
660 do idx = 1, this%pkglist%Count()
661 export_pkg => this%get(idx)
662 ! period input already exported
663 if (export_pkg%eper >= kper) cycle
664 ! update export package
665 call this%package_step(export_pkg)
666 ! update exported iper
667 export_pkg%eper = kper
668 end do
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26

◆ export_longname()

character(len=linelength) function, public ncmodelexportmodule::export_longname ( character(len=*), intent(in) longname,
character(len=*), intent(in) pkgname,
character(len=*), intent(in) tagname,
character(len=*), intent(in) mempath,
integer(i4b), intent(in), optional layer,
integer(i4b), intent(in), optional iaux,
character(len=*), intent(in), optional component_type,
character(len=*), intent(in), optional subcomponent_type )

Definition at line 601 of file NCModel.f90.

605 use inputoutputmodule, only: lowcase
607 character(len=*), intent(in) :: longname
608 character(len=*), intent(in) :: pkgname
609 character(len=*), intent(in) :: tagname
610 character(len=*), intent(in) :: mempath
611 integer(I4B), optional, intent(in) :: layer
612 integer(I4B), optional, intent(in) :: iaux
613 character(len=*), optional, intent(in) :: component_type
614 character(len=*), optional, intent(in) :: subcomponent_type
615 character(len=LINELENGTH) :: lname
616 type(CharacterStringType), dimension(:), pointer, &
617 contiguous :: auxnames
618 character(len=LINELENGTH) :: pname, vname, auxname
619 pname = pkgname
620 vname = tagname
621 call lowcase(pname)
622 call lowcase(vname)
623 if (longname == '') then
624 lname = trim(pname)//' '//trim(vname)
625 else
626 lname = longname
627 if (present(component_type) .and. present(subcomponent_type)) then
628 if (idm_multi_package(component_type, subcomponent_type)) then
629 lname = trim(pname)//' '//trim(lname)
630 end if
631 end if
632 end if
633
634 if (present(iaux)) then
635 if (iaux > 0) then
636 if (tagname == 'AUX') then
637 ! reset vname to auxiliary variable name
638 call mem_setptr(auxnames, 'AUXILIARY', mempath)
639 auxname = auxnames(iaux)
640 call lowcase(auxname)
641 lname = trim(lname)//' '//trim(auxname)
642 end if
643 end if
644 end if
645
646 if (present(layer)) then
647 if (layer > 0) then
648 write (lname, '(a,i0)') trim(lname)//' layer ', layer
649 end if
650 end if
logical function, public idm_multi_package(component, subcomponent)
This class is used to store a single deferred-length character string. It was designed to work in an ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_varname()

character(len=linelength) function, public ncmodelexportmodule::export_varname ( character(len=*), intent(in) pkgname,
character(len=*), intent(in) tagname,
character(len=*), intent(in) mempath,
integer(i4b), intent(in), optional layer,
integer(i4b), intent(in), optional iaux )

Definition at line 560 of file NCModel.f90.

564 use inputoutputmodule, only: lowcase
565 character(len=*), intent(in) :: pkgname
566 character(len=*), intent(in) :: tagname
567 character(len=*), intent(in) :: mempath
568 integer(I4B), optional, intent(in) :: layer
569 integer(I4B), optional, intent(in) :: iaux
570 character(len=LINELENGTH) :: varname
571 type(CharacterStringType), dimension(:), pointer, &
572 contiguous :: auxnames
573 character(len=LINELENGTH) :: pname, vname
574 vname = tagname
575 pname = pkgname
576
577 if (present(iaux)) then
578 if (iaux > 0) then
579 if (tagname == 'AUX') then
580 ! reset vname to auxiliary variable name
581 call mem_setptr(auxnames, 'AUXILIARY', mempath)
582 vname = auxnames(iaux)
583 end if
584 end if
585 end if
586
587 call lowcase(vname)
588 call lowcase(pname)
589 varname = trim(pname)//'_'//trim(vname)
590
591 if (present(layer)) then
592 if (layer > 0) then
593 !write (varname, '(a,i0)') trim(varname)//'_L', layer
594 write (varname, '(a,i0)') trim(varname)//'_l', layer
595 end if
596 end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ input_attribute()

character(len=linelength) function ncmodelexportmodule::input_attribute ( class(ncmodelexporttype), intent(inout) this,
character(len=*), intent(in) pkgname,
type(inputparamdefinitiontype), intent(in), pointer idt )
private

Definition at line 528 of file NCModel.f90.

529 use inputoutputmodule, only: lowcase
532 class(NCModelExportType), intent(inout) :: this
533 character(len=*), intent(in) :: pkgname
534 type(InputParamDefinitionType), pointer, intent(in) :: idt
535 character(len=LINELENGTH) :: attr
536 attr = ''
537 if (this%input_attr > 0) then
538 attr = trim(this%modelname)//mempathseparator//trim(pkgname)// &
539 mempathseparator//trim(idt%tagname)
540 call lowcase(attr)
541 end if
character(len=lenmemseparator), parameter mempathseparator
used to build up the memory address for the stored variables
Here is the call graph for this function:

◆ istp()

integer(i4b) function ncmodelexportmodule::istp ( class(ncmodelexporttype), intent(inout) this)
private

Definition at line 546 of file NCModel.f90.

547 use tdismodule, only: kstp, kper, nstp
548 class(NCModelExportType), intent(inout) :: this
549 integer(I4B) :: n, istp
550 istp = kstp
551 if (kper > 1) then
552 do n = 1, kper - 1
553 istp = istp + nstp(n)
554 end do
555 end if
integer(i4b), pointer, public kstp
current time step number
Definition tdis.f90:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ param_state()

logical(lgp) function ncmodelexportmodule::param_state ( class(exportpackagetype), intent(in) this,
integer(i4b), intent(in) iparam )
private

The auxiliary variable param has input if any auxiliary variable has.

Definition at line 255 of file NCModel.f90.

256 class(ExportPackageType), intent(in) :: this
257 integer(I4B), intent(in) :: iparam
258 logical(LGP) :: exported
259 if (this%param_names(iparam) == 'AUX') then
260 exported = any(this%aux_value)
261 else
262 exported = this%param_value(iparam)
263 end if

◆ set()

subroutine ncmodelexportmodule::set ( class(ncexportannotation), intent(inout) this,
character(len=*), intent(in) modelname,
character(len=*), intent(in) modeltype,
character(len=*), intent(in) modelfname,
integer(i4b), intent(in) nctype,
integer(i4b), intent(in) disenum )
private

Definition at line 313 of file NCModel.f90.

314 use versionmodule, only: fullversion
315 use inputoutputmodule, only: lowcase
316 class(NCExportAnnotation), intent(inout) :: this
317 character(len=*), intent(in) :: modelname
318 character(len=*), intent(in) :: modeltype
319 character(len=*), intent(in) :: modelfname
320 integer(I4B), intent(in) :: nctype
321 integer(I4B), intent(in) :: disenum
322 integer :: values(8)
323
324 this%title = ''
325 this%model = ''
326 this%mesh = ''
327 this%grid = ''
328 this%history = ''
329 this%source = ''
330 this%conventions = ''
331 this%stdname = ''
332 this%longname = ''
333
334 ! set file conventions
335 this%conventions = 'CF-1.13'
336 if (nctype == netcdf_mesh2d) this%conventions = &
337 trim(this%conventions)//' UGRID-1.0'
338
339 ! set model specific attributes
340 select case (modeltype)
341 case ('GWF')
342 this%title = trim(modelname)//' hydraulic head'
343 this%longname = 'head'
344 case ('GWT')
345 this%title = trim(modelname)//' concentration'
346 this%longname = 'concentration'
347 case ('GWE')
348 this%title = trim(modelname)//' temperature'
349 this%longname = 'temperature'
350 case default
351 errmsg = trim(modeltype)//' models not supported for NetCDF export.'
352 call store_error(errmsg)
353 call store_error_filename(modelfname)
354 end select
355
356 if (isim_mode == mvalidate) then
357 this%title = trim(this%title)//' array input'
358 end if
359
360 ! set mesh type
361 if (nctype == netcdf_mesh2d) then
362 this%mesh = 'layered'
363 end if
364
365 ! set grid type
366 if (disenum == dis) then
367 this%grid = 'structured'
368 else if (disenum == disv) then
369 this%grid = 'vertex'
370 end if
371
372 ! model description string (lowercase, no version suffix, matching CF convention)
373 this%model = trim(modeltype)//': '//trim(modelname)
374 call lowcase(this%model)
375
376 ! modflow6 version string
377 this%source = 'MODFLOW 6 '//trim(adjustl(fullversion))
378
379 ! create timestamp
380 call date_and_time(values=values)
381 write (this%history, '(a,i0,a,i0,a,i0,a,i0,a,i0,a,i0,a,i0)') &
382 'first created ', values(1), '/', values(2), '/', values(3), ' ', &
383 values(5), ':', values(6), ':', values(7), '.', values(8)
This module contains version information.
Definition version.f90:7
character(len= *), parameter fullversion
Definition version.f90:24
Here is the call graph for this function:

◆ set_state()

subroutine ncmodelexportmodule::set_state ( integer(i4b), intent(in) invar,
logical(lgp), intent(inout) has_value )
private

Definition at line 240 of file NCModel.f90.

241 integer(I4B), intent(in) :: invar
242 logical(LGP), intent(inout) :: has_value
243 select case (invar)
244 case (rs_values, rs_netcdf)
245 has_value = .true.
246 case (rs_series)
247 has_value = .false.
248 end select
Here is the caller graph for this function:

◆ update_state()

subroutine ncmodelexportmodule::update_state ( class(exportpackagetype), intent(inout) this)
private

A block gives an array as values or as a time-array series. Arrays not given keep their input. An array linked to a series has no input to export, and none after the link until it is given values.

Definition at line 225 of file NCModel.f90.

226 use tdismodule, only: kper
227 class(ExportPackageType), intent(inout) :: this
228 integer(I4B) :: n
229 if (this%iper /= kper) return
230 do n = 1, this%nparam
231 call set_state(this%param_reads(n)%invar, this%param_value(n))
232 end do
233 do n = 1, this%naux
234 call set_state(this%aux_reads(n), this%aux_value(n))
235 end do
Here is the call graph for this function:

◆ user_nodes()

subroutine ncmodelexportmodule::user_nodes ( class(exportpackagetype), intent(in) this,
real(dp), dimension(:), intent(in) vals,
real(dp), dimension(:), intent(inout) nodes )
private

Grid array input is indexed by boundary (NODEULIST, NBOUND), or by user node when NODEULIST is empty. Other user nodes keep their value in nodes.

Parameters
[in]valsloaded period array
[in,out]nodesuser node values

Definition at line 281 of file NCModel.f90.

283 class(ExportPackageType), intent(in) :: this
284 real(DP), dimension(:), intent(in) :: vals !< loaded period array
285 real(DP), dimension(:), intent(inout) :: nodes !< user node values
286 integer(I4B), dimension(:), pointer, contiguous :: nodeulist
287 integer(I4B), pointer :: nbound
288 integer(I4B) :: n
289 call mem_setptr(nodeulist, 'NODEULIST', this%mf6_input%mempath)
290 if (size(nodeulist) == 0) then
291 nodes(1:size(vals)) = vals
292 else
293 call mem_setptr(nbound, 'NBOUND', this%mf6_input%mempath)
294 do n = 1, nbound
295 nodes(nodeulist(n)) = vals(n)
296 end do
297 end if

◆ wkt_albers_conical_equal_area_params()

subroutine, public ncmodelexportmodule::wkt_albers_conical_equal_area_params ( character(len=*), intent(in) wkt,
real(dp), intent(out) standard_parallel_1,
real(dp), intent(out) standard_parallel_2,
real(dp), intent(out) longitude_of_central_meridian,
real(dp), intent(out) latitude_of_projection_origin,
real(dp), intent(out) false_easting,
real(dp), intent(out) false_northing,
real(dp), intent(out) semi_major_axis,
real(dp), intent(out) inverse_flattening,
logical(lgp), intent(out) found )

Best-effort extraction from a WKT1 or WKT2 string – MF6 has no CRS parsing library. found=.false. if any parameter cannot be located.

Definition at line 974 of file NCModel.f90.

982 character(len=*), intent(in) :: wkt
983 real(DP), intent(out) :: standard_parallel_1
984 real(DP), intent(out) :: standard_parallel_2
985 real(DP), intent(out) :: longitude_of_central_meridian
986 real(DP), intent(out) :: latitude_of_projection_origin
987 real(DP), intent(out) :: false_easting
988 real(DP), intent(out) :: false_northing
989 real(DP), intent(out) :: semi_major_axis
990 real(DP), intent(out) :: inverse_flattening
991 logical(LGP), intent(out) :: found
992 logical(LGP) :: f1, f2, f3, f4, f5, f6, f7
993
994 standard_parallel_1 = wkt_find_param(wkt, 'standard_parallel_1', f1)
995 if (.not. f1) standard_parallel_1 = &
996 wkt_find_param(wkt, 'Latitude of 1st standard parallel', f1)
997
998 standard_parallel_2 = wkt_find_param(wkt, 'standard_parallel_2', f2)
999 if (.not. f2) standard_parallel_2 = &
1000 wkt_find_param(wkt, 'Latitude of 2nd standard parallel', f2)
1001
1002 longitude_of_central_meridian = wkt_find_param(wkt, 'longitude_of_center', f3)
1003 if (.not. f3) longitude_of_central_meridian = &
1004 wkt_find_param(wkt, 'Longitude of false origin', f3)
1005
1006 latitude_of_projection_origin = wkt_find_param(wkt, 'latitude_of_center', f4)
1007 if (.not. f4) latitude_of_projection_origin = &
1008 wkt_find_param(wkt, 'Latitude of false origin', f4)
1009
1010 false_easting = wkt_find_param(wkt, 'false_easting', f5)
1011 if (.not. f5) false_easting = &
1012 wkt_find_param(wkt, 'Easting at false origin', f5)
1013
1014 false_northing = wkt_find_param(wkt, 'false_northing', f6)
1015 if (.not. f6) false_northing = &
1016 wkt_find_param(wkt, 'Northing at false origin', f6)
1017
1018 call wkt_find_ellipsoid(wkt, semi_major_axis, inverse_flattening, f7)
1019
1020 found = f1 .and. f2 .and. f3 .and. f4 .and. f5 .and. f6 .and. f7
Here is the call graph for this function:

◆ wkt_find_ellipsoid()

subroutine ncmodelexportmodule::wkt_find_ellipsoid ( character(len=*), intent(in) wkt,
real(dp), intent(out) semi_major_axis,
real(dp), intent(out) inverse_flattening,
logical(lgp), intent(out) found )
private

Matches SPHEROID["name",A,B,...] (WKT1) or ELLIPSOID["name",A,B,...] (WKT2). Best-effort only. found=.false. if neither keyword is present or the two numbers cannot be read.

Definition at line 805 of file NCModel.f90.

806 use inputoutputmodule, only: upcase
807 character(len=*), intent(in) :: wkt
808 real(DP), intent(out) :: semi_major_axis
809 real(DP), intent(out) :: inverse_flattening
810 logical(LGP), intent(out) :: found
811 character(len=LENBIGLINE) :: wkt_upper
812 integer :: ipos, i, iend, ios, wkt_len, nquote
813
814 found = .false.
815 semi_major_axis = dzero
816 inverse_flattening = dzero
817 wkt_len = len_trim(wkt)
818 wkt_upper = wkt
819 call upcase(wkt_upper)
820
821 ipos = index(wkt_upper(1:wkt_len), 'SPHEROID[')
822 if (ipos == 0) ipos = index(wkt_upper(1:wkt_len), 'ELLIPSOID[')
823 if (ipos == 0) return
824
825 ! skip past the quoted ellipsoid name (its closing quote)
826 i = ipos
827 nquote = 0
828 do while (i <= wkt_len)
829 if (wkt(i:i) == '"') nquote = nquote + 1
830 if (nquote == 2) exit
831 i = i + 1
832 end do
833 if (nquote < 2) return
834 i = i + 1
835 if (wkt(i:i) == ',') i = i + 1
836
837 iend = i
838 do while (iend <= wkt_len)
839 if (wkt(iend:iend) == ',') exit
840 iend = iend + 1
841 end do
842 if (iend <= i) return
843 read (wkt(i:iend - 1), *, iostat=ios) semi_major_axis
844 if (ios /= 0) return
845
846 i = iend + 1
847 iend = i
848 do while (iend <= wkt_len)
849 if (wkt(iend:iend) == ',' .or. wkt(iend:iend) == ']') exit
850 iend = iend + 1
851 end do
852 if (iend <= i) return
853 read (wkt(i:iend - 1), *, iostat=ios) inverse_flattening
854 if (ios == 0) found = .true.
subroutine, public upcase(word)
Convert to upper case.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wkt_find_param()

real(dp) function ncmodelexportmodule::wkt_find_param ( character(len=*), intent(in) wkt,
character(len=*), intent(in) name,
logical(lgp), intent(out) found )
private

Matches e.g. PARAMETER["central_meridian",-117] (WKT1) or PARAMETER["Longitude of natural origin",-117,...] (WKT2). Best-effort only – MF6 has no CRS parsing library. found=.false. if name is not present or no number follows it.

Definition at line 763 of file NCModel.f90.

764 use inputoutputmodule, only: upcase
765 character(len=*), intent(in) :: wkt
766 character(len=*), intent(in) :: name
767 logical(LGP), intent(out) :: found
768 real(DP) :: value
769 character(len=LENBIGLINE) :: wkt_upper
770 character(len=LINELENGTH) :: target_upper
771 integer :: ipos, istart, iend, ios, wkt_len
772
773 found = .false.
774 value = dzero
775 wkt_len = len_trim(wkt)
776 target_upper = '"'//trim(name)//'"'
777 wkt_upper = wkt
778 call upcase(wkt_upper)
779 call upcase(target_upper)
780 ipos = index(wkt_upper(1:wkt_len), trim(target_upper))
781 if (ipos == 0) return
782
783 istart = ipos + len_trim(target_upper)
784 do while (istart <= wkt_len)
785 if (wkt(istart:istart) == ',') exit
786 istart = istart + 1
787 end do
788 istart = istart + 1
789 iend = istart
790 do while (iend <= wkt_len)
791 if (wkt(iend:iend) == ',' .or. wkt(iend:iend) == ']') exit
792 iend = iend + 1
793 end do
794 if (iend <= istart) return
795 read (wkt(istart:iend - 1), *, iostat=ios) value
796 if (ios == 0) found = .true.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wkt_lambert_conformal_conic_params()

subroutine, public ncmodelexportmodule::wkt_lambert_conformal_conic_params ( character(len=*), intent(in) wkt,
real(dp), intent(out) standard_parallel_1,
real(dp), intent(out) standard_parallel_2,
real(dp), intent(out) longitude_of_central_meridian,
real(dp), intent(out) latitude_of_projection_origin,
real(dp), intent(out) false_easting,
real(dp), intent(out) false_northing,
real(dp), intent(out) semi_major_axis,
real(dp), intent(out) inverse_flattening,
logical(lgp), intent(out) is_2sp,
logical(lgp), intent(out) found )

Best-effort extraction from a WKT1 or WKT2 string – MF6 has no CRS parsing library. 2SP (two standard parallels) only: CF's lambert_conformal_conic has no scale_factor attribute, so a 1SP (scale-factor-based) WKT cannot be exactly represented without trigonometric conversion MF6 has no library for. is_2sp=.false. if a second standard parallel is not present (i.e. likely 1SP); found=.false. if is_2sp but any other parameter cannot be located.

Definition at line 914 of file NCModel.f90.

921 character(len=*), intent(in) :: wkt
922 real(DP), intent(out) :: standard_parallel_1
923 real(DP), intent(out) :: standard_parallel_2
924 real(DP), intent(out) :: longitude_of_central_meridian
925 real(DP), intent(out) :: latitude_of_projection_origin
926 real(DP), intent(out) :: false_easting
927 real(DP), intent(out) :: false_northing
928 real(DP), intent(out) :: semi_major_axis
929 real(DP), intent(out) :: inverse_flattening
930 logical(LGP), intent(out) :: is_2sp
931 logical(LGP), intent(out) :: found
932 logical(LGP) :: f1, f2, f3, f4, f5, f6, f7
933
934 standard_parallel_2 = wkt_find_param(wkt, 'standard_parallel_2', f2)
935 if (.not. f2) standard_parallel_2 = &
936 wkt_find_param(wkt, 'Latitude of 2nd standard parallel', f2)
937 is_2sp = f2
938 if (.not. is_2sp) then
939 found = .false.
940 return
941 end if
942
943 standard_parallel_1 = wkt_find_param(wkt, 'standard_parallel_1', f1)
944 if (.not. f1) standard_parallel_1 = &
945 wkt_find_param(wkt, 'Latitude of 1st standard parallel', f1)
946
947 longitude_of_central_meridian = wkt_find_param(wkt, 'central_meridian', f3)
948 if (.not. f3) longitude_of_central_meridian = &
949 wkt_find_param(wkt, 'Longitude of false origin', f3)
950
951 latitude_of_projection_origin = wkt_find_param(wkt, 'latitude_of_origin', f4)
952 if (.not. f4) latitude_of_projection_origin = &
953 wkt_find_param(wkt, 'Latitude of false origin', f4)
954
955 false_easting = wkt_find_param(wkt, 'false_easting', f5)
956 if (.not. f5) false_easting = &
957 wkt_find_param(wkt, 'Easting at false origin', f5)
958
959 false_northing = wkt_find_param(wkt, 'false_northing', f6)
960 if (.not. f6) false_northing = &
961 wkt_find_param(wkt, 'Northing at false origin', f6)
962
963 call wkt_find_ellipsoid(wkt, semi_major_axis, inverse_flattening, f7)
964
965 found = f1 .and. f3 .and. f4 .and. f5 .and. f6 .and. f7
Here is the call graph for this function:

◆ wkt_to_cf_gridmapping()

character(len=linelength) function, public ncmodelexportmodule::wkt_to_cf_gridmapping ( character(len=*), intent(in) wkt)

Accepts either WKT1 (OGC 01-009, PROJECTION["name"]) or WKT2 (ISO 19162:2019, METHOD["name"]) format. WKT1 is tried first; if PROJECTION[ is absent the WKT2 METHOD[ path is attempted. Returns '' for geographic CRS or unrecognised projection names. Only common groundwater projections included. Matching is case-insensitive.

Definition at line 680 of file NCModel.f90.

681 use inputoutputmodule, only: upcase
682 character(len=*), intent(in) :: wkt
683 character(len=LINELENGTH) :: gmname
684 character(len=LINELENGTH) :: proj_name
685 character(len=LENBIGLINE) :: wkt_upper
686 integer :: istart, iend
687
688 gmname = ''
689 proj_name = ''
690
691 ! uppercase copy for case-insensitive keyword search
692 wkt_upper = wkt
693 call upcase(wkt_upper)
694
695 ! --- WKT1 path: PROJECTION["name"] ---
696 istart = index(wkt_upper, 'PROJECTION[')
697 if (istart /= 0) then
698 istart = istart + len('PROJECTION[')
699 do while (istart <= len(wkt))
700 if (wkt(istart:istart) == '"') exit
701 istart = istart + 1
702 end do
703 if (istart > len(wkt)) return
704 istart = istart + 1
705 iend = index(wkt(istart:), '"')
706 if (iend == 0) return
707 iend = istart + iend - 2
708 if (iend < istart) return
709 proj_name = wkt(istart:iend)
710 call upcase(proj_name)
711 select case (trim(proj_name))
712 case ('TRANSVERSE_MERCATOR')
713 gmname = 'transverse_mercator'
714 case ('LAMBERT_CONFORMAL_CONIC_2SP', 'LAMBERT_CONFORMAL_CONIC_1SP')
715 gmname = 'lambert_conformal_conic'
716 case ('ALBERS_CONIC_EQUAL_AREA')
717 gmname = 'albers_conical_equal_area'
718 case ('MERCATOR_1SP', 'MERCATOR_2SP')
719 gmname = 'mercator'
720 case ('POLAR_STEREOGRAPHIC')
721 gmname = 'polar_stereographic'
722 end select
723 return
724 end if
725
726 ! --- WKT2 path: METHOD["name"] ---
727 istart = index(wkt_upper, 'METHOD[')
728 if (istart == 0) return
729 istart = istart + len('METHOD[')
730 do while (istart <= len(wkt))
731 if (wkt(istart:istart) == '"') exit
732 istart = istart + 1
733 end do
734 if (istart > len(wkt)) return
735 istart = istart + 1
736 iend = index(wkt(istart:), '"')
737 if (iend == 0) return
738 iend = istart + iend - 2
739 if (iend < istart) return
740 proj_name = wkt(istart:iend)
741 call upcase(proj_name)
742 select case (trim(proj_name))
743 case ('TRANSVERSE MERCATOR')
744 gmname = 'transverse_mercator'
745 case ('LAMBERT CONIC CONFORMAL (2SP)', 'LAMBERT CONIC CONFORMAL (1SP)')
746 gmname = 'lambert_conformal_conic'
747 case ('ALBERS EQUAL AREA')
748 gmname = 'albers_conical_equal_area'
749 case ('MERCATOR (VARIANT A)', 'MERCATOR (VARIANT B)')
750 gmname = 'mercator'
751 case ('POLAR STEREOGRAPHIC (VARIANT A)', 'POLAR STEREOGRAPHIC (VARIANT B)')
752 gmname = 'polar_stereographic'
753 end select
Here is the call graph for this function:

◆ wkt_transverse_mercator_params()

subroutine, public ncmodelexportmodule::wkt_transverse_mercator_params ( character(len=*), intent(in) wkt,
real(dp), intent(out) longitude_of_central_meridian,
real(dp), intent(out) latitude_of_projection_origin,
real(dp), intent(out) scale_factor_at_central_meridian,
real(dp), intent(out) false_easting,
real(dp), intent(out) false_northing,
real(dp), intent(out) semi_major_axis,
real(dp), intent(out) inverse_flattening,
logical(lgp), intent(out) found )

Best-effort extraction from a WKT1 or WKT2 string – MF6 has no CRS parsing library. Tries WKT1 parameter names first, falling back to WKT2 names. found=.false. if any parameter cannot be located.

Definition at line 864 of file NCModel.f90.

870 character(len=*), intent(in) :: wkt
871 real(DP), intent(out) :: longitude_of_central_meridian
872 real(DP), intent(out) :: latitude_of_projection_origin
873 real(DP), intent(out) :: scale_factor_at_central_meridian
874 real(DP), intent(out) :: false_easting
875 real(DP), intent(out) :: false_northing
876 real(DP), intent(out) :: semi_major_axis
877 real(DP), intent(out) :: inverse_flattening
878 logical(LGP), intent(out) :: found
879 logical(LGP) :: f1, f2, f3, f4, f5, f6
880
881 longitude_of_central_meridian = wkt_find_param(wkt, 'central_meridian', f1)
882 if (.not. f1) longitude_of_central_meridian = &
883 wkt_find_param(wkt, 'Longitude of natural origin', f1)
884
885 latitude_of_projection_origin = wkt_find_param(wkt, 'latitude_of_origin', f2)
886 if (.not. f2) latitude_of_projection_origin = &
887 wkt_find_param(wkt, 'Latitude of natural origin', f2)
888
889 scale_factor_at_central_meridian = wkt_find_param(wkt, 'scale_factor', f3)
890 if (.not. f3) scale_factor_at_central_meridian = &
891 wkt_find_param(wkt, 'Scale factor at natural origin', f3)
892
893 false_easting = wkt_find_param(wkt, 'false_easting', f4)
894 if (.not. f4) false_easting = wkt_find_param(wkt, 'False easting', f4)
895
896 false_northing = wkt_find_param(wkt, 'false_northing', f5)
897 if (.not. f5) false_northing = wkt_find_param(wkt, 'False northing', f5)
898
899 call wkt_find_ellipsoid(wkt, semi_major_axis, inverse_flattening, f6)
900
901 found = f1 .and. f2 .and. f3 .and. f4 .and. f5 .and. f6
Here is the call graph for this function:

◆ wrap_rotated_crs()

character(len=lenbigline) function, public ncmodelexportmodule::wrap_rotated_crs ( character(len=*), intent(in) wkt,
real(dp), intent(in) xorigin,
real(dp), intent(in) yorigin,
real(dp), intent(in) angrot )

Builds a DerivedProjectedCRS wrapping the given WKT2 PROJCRS in an EPSG:9624 (affine parametric transformation) deriving conversion parameterized from xorigin/yorigin/angrot (degrees). Per ISO 19111, a deriving conversion is directed base->derived, so the parameters encode the world->local (inverse) rotation; a CRS-aware consumer applies the inverse to resolve true position from local coordinates. Returns '' if wkt is not recognized as a WKT2 PROJCRS – a best-effort structural check only, as MF6 has no CRS parsing library and does not validate the WKT beyond this.

Definition at line 1035 of file NCModel.f90.

1036 use inputoutputmodule, only: upcase
1037 character(len=*), intent(in) :: wkt
1038 real(DP), intent(in) :: xorigin, yorigin, angrot
1039 character(len=LENBIGLINE) :: derived_wkt
1040 character(len=LENBIGLINE) :: wkt_trim, wkt_upper, base_body, conversion
1041 character(len=30) :: a0s, a1s, a2s, b0s, b1s, b2s
1042 integer :: nstart, i, depth, closures, iend, wkt_len
1043 real(DP) :: ang, a0, a1, a2, b0, b1, b2
1044
1045 derived_wkt = ''
1046
1047 ! best-effort check that wkt is a WKT2 PROJCRS
1048 wkt_trim = trim(adjustl(wkt))
1049 wkt_len = len_trim(wkt_trim)
1050 wkt_upper = wkt_trim
1051 call upcase(wkt_upper)
1052 if (wkt_len < 9 .or. wkt_upper(1:8) /= 'PROJCRS[') return
1053
1054 ! locate the end of PROJCRS's 2nd top-level child (the mandatory
1055 ! BASEGEOGCRS/BASEGEODCRS and CONVERSION elements, in that order),
1056 ! by tracking bracket depth from just inside the opening '['
1057 nstart = 9
1058 depth = 0
1059 closures = 0
1060 iend = 0
1061 do i = nstart, wkt_len
1062 if (wkt_trim(i:i) == '[') then
1063 depth = depth + 1
1064 else if (wkt_trim(i:i) == ']') then
1065 depth = depth - 1
1066 if (depth == 0) then
1067 closures = closures + 1
1068 if (closures == 2) then
1069 iend = i
1070 exit
1071 end if
1072 end if
1073 end if
1074 end do
1075 if (iend == 0) return
1076 base_body = wkt_trim(nstart:iend)
1077
1078 ! EPSG:9624 affine parameters, base(world) -> derived(local grid)
1079 ang = angrot * dpio180
1080 a0 = -(xorigin * cos(ang) + yorigin * sin(ang))
1081 a1 = cos(ang)
1082 a2 = sin(ang)
1083 b0 = xorigin * sin(ang) - yorigin * cos(ang)
1084 b1 = -sin(ang)
1085 b2 = cos(ang)
1086 write (a0s, '(es22.15)') a0
1087 write (a1s, '(es22.15)') a1
1088 write (a2s, '(es22.15)') a2
1089 write (b0s, '(es22.15)') b0
1090 write (b1s, '(es22.15)') b1
1091 write (b2s, '(es22.15)') b2
1092
1093 conversion = 'DERIVINGCONVERSION["MODFLOW 6 grid rotation",'// &
1094 'METHOD["Affine parametric transformation",'// &
1095 'ID["EPSG",9624]],'// &
1096 'PARAMETER["A0",'//trim(adjustl(a0s))// &
1097 ',LENGTHUNIT["metre",1]],'// &
1098 'PARAMETER["A1",'//trim(adjustl(a1s))// &
1099 ',SCALEUNIT["unity",1]],'// &
1100 'PARAMETER["A2",'//trim(adjustl(a2s))// &
1101 ',SCALEUNIT["unity",1]],'// &
1102 'PARAMETER["B0",'//trim(adjustl(b0s))// &
1103 ',LENGTHUNIT["metre",1]],'// &
1104 'PARAMETER["B1",'//trim(adjustl(b1s))// &
1105 ',SCALEUNIT["unity",1]],'// &
1106 'PARAMETER["B2",'//trim(adjustl(b2s))// &
1107 ',SCALEUNIT["unity",1]]]'
1108
1109 derived_wkt = 'DERIVEDPROJCRS["MODFLOW 6 rotated grid CRS",'// &
1110 'BASEPROJCRS['//trim(base_body)//'],'// &
1111 trim(conversion)//','// &
1112 'CS[Cartesian,2],'// &
1113 'AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1]],'// &
1114 'AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1]]]'
Here is the call graph for this function: