Skip to content

Fortran ​

Exodus series and pipeline Version 2 ​

type(mio_exodus_series) owns a netCDF-enabled series. Call %create(path), %write_points_cells(mesh), then %write_data(time, mesh) per step; %flush(), %finalize(), %finalized() and %num_steps() expose the lifecycle. %free() is explicit and idempotent, like mesh handles. Mutators accept optional stat/errmsg; missing netCDF is a named failure. Point/side sets and attributes belong to the fixed grid, not a step. See Exodus.

Existing pipeline status/report routines accept Version 2 JSON with per-step Inputs and terminal {key}/{part} outputs. No bind(C) layout changed; transient sequence documents remain Version 1.

Pipeline reports ​

Structured pipeline reports use call mio_pipeline_run_file_report(path, report, stat, errmsg) or mio_pipeline_run_json_report(text, report, ...), plus the corresponding mio_sequence_pipeline_run_*_report routines. The allocatable report string is JSON with steps and warnings; the native handle is released automatically. Failure returns an empty string and follows the existing stat/errmsg convention. See pipeline reports.

MED named meshes ​

call mio_med_mesh_names(path, names, stat, errmsg) returns an allocatable character array in file link order. call mio_med_read_named(path, name, mesh, time_step=0, lenient=.false., stat=stat, errmsg=errmsg) replaces the output mesh only after success; free it with call mesh%free(). call mio_med_write_multi(path, meshes, names, version='4.1.0', stat=stat, errmsg=errmsg) writes an array of borrowed meshes with one unique name per mesh. These APIs require HDF5 and expand ordinary nodal/element profiles with NaN fill. See MED.

call m%write('cloud.pcd', codec='lzf') selects PCD compressed binary without an optional codec library; explicit ASCII or non-PCD combinations fail. encoding, codec and float_format are optional keyword arguments appended after the existing status arguments; encoding='binary' on a .frd writes CalculiX's binary result layout. Parameterized glTF uses type(mio_gltf_options) :: opts and call m%write_gltf('colored.glb', options=opts); set opts%color_by, %cmap, %up_axis (0 auto, 1 Z, 2 Y, 3 X) and %scale as needed. %component is 1-based and only used with %component_set=.true.; %vmin_set/%vmax_set control optional bounds. Native reads also support XDMF2/3 DataItem references and Netgen names/periodic arrays; Netgen periodic arrays are numeric field data with 1-based file node ids, and .vol.gz requires zlib.

XDMF series write_points_cells(mesh) now stores the mesh's fixed point/cell/side regions once with the shared topology. Existing step, flush and append calls retain them without new arguments. See shared named regions.

The shared native reader supports multiple pieces without welding and appended raw/base64 arrays in vtu, vtp, vts, vtr and vti, with UInt32/UInt64 headers and either byte order. VTP/VTS/VTR/VTI writers remain inline; optional codecs follow the C library build. Legacy vtk also reads structured points, structured grids and rectilinear grids in ASCII and big-endian binary through the existing read API. See formats.

meshio++ ships a modern object-oriented Fortran 2008 module, meshioplusplus, layered on the C API via ISO_C_BINDING — in the HDF5/PETSc style, aimed at Fortran HPC codes:

fortran
use meshioplusplus
type(mio_mesh) :: m

call m%read("bracket.msh")
print *, m%num_points(), "points,", m%num_cell_blocks(), "cell blocks"
call m%write("bracket.vtu")
call m%free()

Building ​

sh
build/configure.sh --fortran --build     # implies --c-api
cmake --install build/cpp-release --prefix /opt/meshioplusplus

installs libmeshioplusplus_fortran.so next to libmeshioplusplus.so, plus include/meshioplusplus/fortran/meshioplusplus.mod and the module source meshioplusplus.f90. Compile and link:

sh
gfortran my_solver.f90 -I /opt/meshioplusplus/include/meshioplusplus/fortran \
  -L /opt/meshioplusplus/lib -lmeshioplusplus_fortran -lmeshioplusplus -o my_solver

.mod files are compiler-specific

A .mod compiled by gfortran N is unreadable by gfortran N±2, ifort, or flang. If your compiler rejects the installed .mod, recompile the module from the installed meshioplusplus.f90 with your own compiler and link the same libraries — that is exactly why the source is installed (the HDF5 approach). CMake consumers can instead find_package(meshioplusplus) and link meshioplusplus::meshioplusplus_fortran from the same build.

Array layout and 1-based indexing ​

The C core stores points as row-major (num_points, dim) and connectivity as (num_cells, nodes_per_cell). Because Fortran is column-major, the same memory is naturally the Fortran arrays

fortran
real(real64)   :: points(dim, num_points)     ! points(:, i) = coordinates of point i
integer(int64) :: conn(nodes_per_cell, num_cells)

so nothing is ever transposed. Node indices are 1-based in this module; the ±1 shift happens inside the copying setters/getters (where a copy is made anyway):

fortran
call m%set_points(points)                     ! copies
call m%add_cell_block("tetra", conn)          ! copies, shifts to the core's 0-based
call m%get_cell_block(1, rconn)               ! allocates, copies, shifts back to 1-based

Vector data uses the same rule — a per-point field of c components is data(c, num_points) in Fortran and round-trips as the C API's (num_points, c).

Zero-copy borrows exist where no index shift is needed:

fortran
real(real64), pointer :: p(:, :)
call m%points_ptr(p)     ! p(dim, num_points) aliases mesh memory --
                         ! valid until the next mutating call or m%free()

Error handling ​

Every fallible procedure takes optional stat and errmsg arguments:

fortran
integer :: ierr
character(:), allocatable :: msg

call m%read("missing.vtu", stat=ierr, errmsg=msg)
if (ierr /= 0) print *, "read failed: ", msg

If stat is absent and the call fails, the message is printed and the program error stops — convenient for straight-line tools, pass stat when you need to recover. mio_error_message() returns the most recent failure message on the calling thread.

API summary ​

m%region_adjacency([regions(:)]) returns conforming shared facets; m%find_interface(region_a, region_b [, mesh_b, mode, master, tolerances]) matches Cell-region boundaries and returns an owned facet mesh plus 0-based local-facet Side entries; m%contact_pairs(slave_points, master_cells [, master_mesh, tolerance, require_complete]) projects a Point region and returns copied arrays; and m%split_interface(side [, add_cohesive, counts]) splits point fans along a Side region. Global point/cell ids in Fortran results are 1-based, but local-facet ordinals remain 0-based. See interfaces and contact.

Lifecyclem%create() (implicit in read/setters), m%read(path [, format]), m%write(path [, format]), m%free(), m%is_valid()

m%read reads compressed files transparently (m%read('cube.msh.gz'): .gz, .bz2, .xz, .zst or a single-member .zip), through the codecs the native library links. See compressed files. | Building | m%set_points(points), m%add_cell_block(type, conn) (int32 or int64), m%add_point_data(name, data) (rank-1 or rank-2), m%add_cell_data(name, data) (once per block, in order), m%add_field_data(name, data) | | Counts | m%num_points(), m%point_dim(), m%num_cell_blocks(), m%num_point_data(), m%num_cell_data(), m%num_field_data(), m%cell_data_num_blocks(name) | | Cell blocks (1-based) | m%cell_block_type(i), m%cell_block_num_cells(i), m%cell_block_nodes_per_cell(i), m%cell_block_is_ragged(i), m%cell_block_is_polyhedron(i), m%get_cell_block(i, conn) | | Ragged cell blocks | Cells of varying size, carried as a 1-based flat CSR pair or triple (see Polyhedra and ragged cells). Building: m%add_polygon_block(type, row_offsets, nodes), m%add_polyhedron_block(type, cell_offsets, face_offsets, nodes). Reading: m%get_polygon_block(i, row_offsets, nodes), m%get_polyhedron_block(i, cell_offsets, face_offsets, nodes). The offsets are shifted to 1-based along with the node ids, because they index a Fortran array — so cell c is nodes(row_offsets(c) : row_offsets(c + 1) - 1), and face f of cell c is nodes(face_offsets(j) : face_offsets(j + 1) - 1) with j = cell_offsets(c) + f - 1 | | Data (copies, real64) | m%get_points(points), m%get_point_data(name, data) (rank-1 or rank-2), m%get_cell_data(name, block, data), m%get_field_data(name, data); names via m%point_data_name(i) etc. (sorted order) | | Zero-copy | m%points_ptr(p) | | Isogeometric | info%iga_refine([subdivisions, elevate, sample_subdivisions, trim_samples, edges, trim, refined]), info%iga_sample(...) (each returns the sampled mio_mesh; refined / mapped receive the model for m%write_with_info) and info%iga_evaluate(patch, params(d, N) [, derivatives, trim_samples]) returning a mio_iga_evaluation with points() (space dim, N), derivatives(), normals(), inside(), field(k) and num_fields(); see isogeometric layer | info%iga_bezier_extract([patch]) (1-based, default 1) returns one patch of an MFEM NURBS model as VTK Bezier cells (mio_mesh). info%iga_remove_knots([direction, knots, tolerance, patch, sample_subdivisions, reduced, report_knots, requested, removed]) (1-based direction and patch) removes knots from one patch within a tolerance. info%iga_closest_point(patch, points(space_dim, N) [, params, distances]) returns the closest points (space_dim, N). | Mesh generation from CAD | info%mesh_cad_surface(target_size [, max_chordal_deviation, min_points_per_edge, tolerance, record_face_ids, edges, match_unreferenced_trims, strict, max_points, report, warnings, min_angle, smooth_iterations, smooth_method, order, grading, curvature_deviation, cells_across_gaps, pole_rings, face_size_faces, face_sizes, edge_size_edges, edge_sizes, background, background_array, metric, virtual_edges, reparam_condition_number, model_tolerances, virtual_faces, lop_corners, metric_background, metric_array, metric_error, untangle, quads, quad_pairs]) on a cad_json, step or iges handle returns the conforming triangle mio_mesh; report is a mio_mesh_cad_surface_report (layout-checked against the C struct, 200 bytes), and mio_mesh_cad_face_status(face) / mio_mesh_cad_face_reason(face) (1-based faces, MIO_MESH_CAD_*) read the last call's per-face outcome. min_angle refines to a smallest angle on the surface and smooth_iterations smooths (smooth_method MIO_MESH_CAD_SMOOTH_LAPLACIAN or MIO_MESH_CAD_SMOOTH_ODT), and order 2 or 3 (v17.16.0) writes curved triangle6 or triangle10 elements, the report's num_curved_straightened counting those kept straight-sided; mio_mesh_cad_angle_histogram() returns the last call's 18 angle bins, and mio_mesh_cad_num_corners() / mio_mesh_cad_get_corner(k) its corners under 60 degrees and poles (a mio_mesh_cad_corner, 1-based face and point). curvature_deviation and cells_across_gaps (v17.18.0) size the mesh by the model's curvature and gaps, grading bounds the size's growth and pole_rings grades the poles, the mio_mesh_cad_surface_opts type's last fields. Since v17.19.0 the optional face_size_faces / face_sizes and edge_size_edges / edge_sizes (1-based indices, equal lengths), background (a mio_mesh) with background_array, metric (MIO_MESH_CAD_METRIC_MEAN or _VARYING) and virtual_edges go through mio_mesh_cad_surface2 in a layout-checked mio_mesh_cad_surface_opts_ex_t, and mio_mesh_cad_face_size_limits(face) returns the 1-based edges limiting a face's given size. Since v17.20.0 the optional reparam_condition_number, model_tolerances, virtual_faces and lop_corners take the same route (model_tolerances and virtual_faces default to .true. since v19.0.0), as do metric_background (a mio_mesh whose 9-component point data metric_array is a field's Hessian, or whose 1-component one is the field itself) and metric_error, the anisotropic metric of roadmap 6.10.2 (mio_mesh_cad_min_metric_angle() returns the least corner angle in the metric, 0 without one), untangle (6.6.3, read back by mio_mesh_cad_num_untangled()) and quads (MIO_MESH_CAD_QUADS_*, 6.8, read back by mio_mesh_cad_get_quad_stats(quads, left, min_scaled_jacobian); with order 2 or 3 either mode writes curved quad9 or quad16 cells, and MIO_MESH_CAD_QUADS_ALL takes no virtual_edges) with quad_pairs (MIO_MESH_CAD_QUAD_PAIRS_MATCHING, the default maximum-weight matching, or MIO_MESH_CAD_QUAD_PAIRS_GREEDY, 6.8.1), and mio_mesh_cad_num_reparametrised() / mio_mesh_cad_get_reparametrised(k, …), mio_mesh_cad_num_merged_faces() / mio_mesh_cad_get_merged_face(k, …) and mio_mesh_cad_num_tolerance_uses() / mio_mesh_cad_get_tolerance_use(k, …) (where one of MIO_MESH_CAD_TOLERANCE_CLOSED_START, _CORNER, _PROJECTION; 1-based faces and edges) and mio_mesh_cad_num_lopped_corners() / mio_mesh_cad_get_lopped_corner(k, face, point, angle, lfs0, radius, turning, bound, num_forced, min_forced, within_two_radii, guaranteed) / mio_mesh_cad_lopped_corner_reason(k) read what they decided; see mesh generation from CAD | | Operations | The MMG operations, free functions failing with a non-zero stat naming MESHIOPLUSPLUS_WITH_MMG without the backend: mio_adapt(mesh, hsiz=, size_field=, metric=, hmin=, hmax=, hausd=, ..., frozen=, required=, report=) (1-based frozen; mio_mmg_report), mio_discretize_levelset(mesh, level_set, isovalue=, hausd=, hmax=, report=), mio_mesh_domain(boundary, hsiz=, holes=, report=, num_subdomains=) (holes(2, n)), mio_move(mesh, displacement, moving(:), lagrangian=, report=), mio_metric_from_hessian(mesh, hessian, ...) (no MMG needed) and mio_has_mmg(), mio_has_mmg_elas(), mio_mmg_index_bits(); m%extract_surface([record_parent_ids]), m%extract_skin([linearize]), m%normals([point_normals, cell_normals, weight, split_angle, record_parent_ids, region, num_added_points, …]) (point and cell normals of a surface, optionally splitting vertices at creases — see normals), m%check_conformity([tolerance, attach_flags, report, warnings]) (a mio_conformity_report; interface_mode a MIO_CONFORMITY_* code — see conformity), m%check_tetrahedra([zero_volume_factor, warnings, stat, errmsg]) (the inverted, degenerate and overlapping tetrahedra as a mio_check_tetrahedra_report: num_tetrahedra, num_inverted, num_degenerate, num_overlaps, min_volume, max_volume and valid; 96 bytes — see check_tetrahedra), m%feature_edges([feature_angle, feature, boundary, non_manifold, inconsistent, region, num_feature, …]) (the sharp/open/non-manifold/inconsistent edges as a line mesh — see feature edges), m%tessellate([levels, curved, fields, record_stencil, num_source_points, num_source_cells, num_curved_source_cells, num_pass_through_source_cells, num_points, num_cells, num_boundary_facets, num_interior_facets, num_facets_with_bad_count, stat, errmsg]) (isoparametric tessellation of curved quadratic cells into triangles and tetrahedra with tessellate:* provenance data; levels is int64 and defaults to 2 — see tessellation), m%optimize_volume([..., objective, max_ring_size, num_edge_removals, num_multi_face_removals, num_worst_smoothed, min_dihedral_before, min_dihedral_after]) (since ABI 37, through mio_optimize_volume_ex; objective='worst' by default — see optimize_volume), m%select_region(name[, kind, box_lo, box_hi, plane_point, plane_normal, sphere_center, sphere_radius, where_array, where_op, where_value, quality_metric, quality_op, quality_value, component, seed, feature_angle, normal_tolerance, mode, all_facets, tag, num_candidates, num_selected, num_grown, num_components]) (one named region; component 1-based; not select, which Fortran reads as a construct — see select), m%segment([feature_angle, normal_tolerance, curvature_tolerance, min_patch_cells, region, prefix, num_patches, num_merged, …, method, tolerance]) (smooth patches; method='primitive' one per plane, cylinder, cone, sphere or torus — see segment), m%fit_primitives([patch_data, tolerance, relative, min_inlier_fraction, types, max_iterations, num_plane, …, num_unfitted, region, seeds, feature_angle, rim_angle, output_region, used_points, num_feature_cells, criterion]) (seeds a 3 x n array; roadmap 7.1.1, 7.1.2; criterion 'minimum_zone', 'min_circumscribed' or 'max_inscribed', roadmap 7.1.4) (types is the bit mask 2**type, 62 for all five — see fit primitives), m%refine_patches([tolerance, relative, normal_weight, epsilon, feature_angle, max_iterations, min_patch_cells, ransac_seed, allow_split, allow_merge, num_patches, num_splits, num_merges, explained_area_fraction, stat, errmsg, types, prefix, num_iterations, num_primitive]) (v17.11.0; refines the segment:patch labels by variational shape approximation until each patch is one primitive or a freeform proxy, and returns a new mesh with the patches, regions and fit:* data rewritten; tolerance 1e-3 of the diagonal while relative (default), ransac_seed an integer(c_int64_t) holding the C uint64_t bits, defaulting to the bytes of "meshio++"; the mio_refine_patches_opts_t mirror's 144 bytes are checked once per process — see refine patches), m%fit_cad([step_path, tolerance, exact_edges, types, mesh_deflection, max_demotion_rounds, valid, volume_ratio, max_deviation, num_faces, num_faceted_faces, num_demoted, freeform, freeform_degree, freeform_max_control, num_bspline, freeform_split, fillets, threads, num_split_patches, num_fillet, num_helical, num_variable_fillet, num_blend, num_rounded_thread, num_vertex_blend, num_chamfer, num_conic_blend, num_tapered_thread, num_variable_pitch_thread, merge_faces, backend, used_native, refine_segmentation, max_refine_iterations, refine_epsilon, normal_weight, allow_merge, allow_split, ransac_seed, refine_tolerance, relative_tolerance, refined, num_refine_splits, num_refine_merges, explained_area_fraction, freeform_general, freeform_tolerance, freeform_smoothing, max_freeform_poles, max_freeform_iterations, max_freeform_splits, sew_tolerance, extend_surfaces, snap_junctions, face_deviation, closed, num_freeform_general, num_freeform_refinements, avg_freeform_poles, num_extended_edges, num_snapped_junctions, hausdorff_max, hausdorff_rms, refinement_kept, freeform_mode, freeform_parameterization, extraordinary_vertex, local_refine, freeform_g1_tolerance_deg, freeform_max_control_points, layout_target_patch_size, layout_max_valence_deviation, resegment_rounds, layout_snap_to_features, validate_by_surface_sampling, brep_checked, facet_area_fraction, num_freeform_adaptive, num_network_patches, num_network_edges, num_extraordinary_vertices, num_resegmented, num_escalations, max_g1_angle_deg, max_freeform_distance, rms_freeform_distance, num_face_records, constrain_primitives, num_constrained_primitives, num_constraint_groups, validation_report, validation_acceptance, validation_reported, cad_to_mesh_max, ..., total_freeform_control_points]) (the fitted patches as a CAD solid with analytic faces, and rolling-ball fillet and blend, helical thread and B-spline faces for what no primitive explains, the logical freeform, freeform_split, fillets, threads and merge_faces on by default; backend 'occt' needs a library built with OpenCASCADE, which the free function mio_has_occt() reports, 'native' writes the fitted primitives as analytic STEP faces with no CAD kernel, 'auto' (the default) picks OpenCASCADE when present, and used_native says which ran; since v17.11.0 the logical refine_segmentation (off by default) first refines the patches as m%refine_patches does, through mio_fit_cad2, with refine_tolerance (relative while relative_tolerance), normal_weight, refine_epsilon, max_refine_iterations, allow_split, allow_merge and ransac_seed, and refined, num_refine_splits, num_refine_merges, explained_area_fraction and refinement_kept (whether the solid was built from the refined patches) report it; the logical freeform_general (off) tries a patch the plane and cylinder freeform fit leaves unexplained as a general B-spline face (freeform_tolerance, freeform_smoothing, max_freeform_poles, max_freeform_iterations, max_freeform_splits; reported by num_freeform_general, num_freeform_refinements and avg_freeform_poles), and, OpenCASCADE only, sew_tolerance sets the sewing tolerance, extend_surfaces extends freeform surfaces past their patches (num_extended_edges), snap_junctions places the corners where analytic faces meet by least squares (num_snapped_junctions) and face_deviation measures each face against the skin (hausdorff_max, hausdorff_rms, NaN when not measured, and the fit_cad:face_hausdorff / fit_cad:face_rms field data); closed says whether every shell is closed; since v17.12.0 the freeform modes go through mio_fit_cad3, the enums as strings: freeform_mode ('legacy', the default, 'adaptive', 'network', 'auto'), freeform_parameterization ('auto', the default, 'projection', 'lscm', 'harmonic'), extraordinary_vertex ('g0', 'g1', 'g1x', the default, 'g1xx') and local_refine ('knots', the default, 'thb'), an unknown word failing through stat/errmsg, with freeform_g1_tolerance_deg (1), freeform_max_control_points (400), layout_target_patch_size (0.1), layout_max_valence_deviation (2), resegment_rounds (2) and the logical layout_snap_to_features and validate_by_surface_sampling (on); brep_checked, facet_area_fraction, num_freeform_adaptive, num_network_patches, num_network_edges, num_extraordinary_vertices, num_resegmented, num_escalations, max_g1_angle_deg, max_freeform_distance, rms_freeform_distance and num_face_records report it on every run, the logical constrain_primitives (off) fits related primitives together on either backend (constrained primitives), counted by num_constrained_primitives and num_constraint_groups, the logicals validation_report and validation_acceptance (off) the validation report (unreleased), returned through the optional validation_reported, cad_to_mesh_max, cad_to_mesh_p95, cad_to_mesh_p99, mesh_to_cad_max, mesh_to_cad_p95, mesh_to_cad_p99, normal_deviation_max_deg, normal_deviation_p95_deg, step_round_trip_checked, step_round_trip_valid, step_round_trip_volume_ratio and total_freeform_control_points (through mio_fit_cad4), the strings freeform_fit_schedule ('legacy', 'continuation') and freeform_objective ('default', 'pdm', 'tdm', 'sdm') the fit's schedule and objective, kinematic_surfaces=.true. first tries a patch no primitive explains as a kinematic surface (unreleased) and reports num_extrusion, num_revolution and num_kinematic_helical, freeform_g1_solve= ('sweeps', 'coupled') is the coupled G1 solve, reporting max_g1_angle_away_deg, max_g1_angle_at_ev_deg and num_coupled_regions, and outside 'legacy' the returned mesh carries the face records as fit_cad:face_table field data; the mio_fit_cad_opts_ex2_t and mio_fit_cad_report_ex3_t mirrors' 128 and 184 bytes are checked — see fit CAD), m%hausdorff_distance(other [, face_samples, region_a, region_b, a_to_b, b_to_a, …]) (→ real(real64); see Hausdorff distance), m%edit_regions(op, inputs(:) [, output, kind, dim, tag, keep_inputs]) and m%remove_region(index) (1-based; see editing regions), call m%match_periodic_nodes(slave, master, slave_ids, master_ids [, translate(3), matrix(16), atol, require_complete, unmatched, num_fixed, max_residual]) (1-based ids; matrix row-major — see periodic node pairs), out = m%geodesic_distance([sources(:), source_region, time_factor, tolerance, max_iterations, num_unreached, max_distance, converged, stat, errmsg]) (1-based sources — see geodesic distance), out = m%parameterize([padding, max_depth, max_stretch, num_charts, num_flipped, stretch, packing_efficiency, stat, errmsg]) (see parameterize), out = m%laplacian_eigenmodes([num_modes, tolerance, max_iterations, iterations, max_residual, converged, stat, errmsg]) (the lowest Laplace–Beltrami eigenpairs — see eigenmodes), out = m%morph(array [, fix_boundary, constrained_array, stiffening, steps, allow_inverted, num_inverted, max_displacement, stat, errmsg]) (boundary-driven morphing — see morphing), out = m%untangle([fix_boundary, rings, smooth, max_sweeps, num_inverted_after, min_quality_after, stat, errmsg]) (repair inverted tetrahedra and hexahedra — see untangling), out = m%prepare_metric(arrays(:) [, output, target_vertices, norm, hmin, hmax, gradation, complexity_after, stat, errmsg]) (the metric toolbox — see metric toolbox), out = m%convert_coordinates([system, axis, origin, reference, arrays(:), inverse, record_coordinates, num_arrays, num_singular, stat, errmsg]) (cylindrical or spherical components — see coordinates), out = m%convex_hull([dimension, num_vertices, num_facets, area, volume, perimeter, stat, errmsg]) and out = m%delaunay_2d([num_triangles, num_duplicates, num_boundary, stat, errmsg]) (the convex hull of the points, hull:point_id 0-based, and their Delaunay triangulation in x, y — see hull), out = m%estimate_normals([k, orientation, viewpoint, record_variation, num_degenerate, num_components, stat, errmsg]) (point-cloud normals — see point-cloud normals), out = m%reconstruct_surface([normals, k, cell_size, resolution, max_distance, estimate_normals, num_triangles, num_components, spacing, stat, errmsg]) (a triangle surface through an oriented point cloud — see surface reconstruction), call m%register_rigid(target, matrix(4, 4) [, method, max_iterations, tolerance, max_distance, rms, iterations, converged, stat, errmsg, initial, symmetric_check, source_region, target_region, adaptive_trim, num_rejected]) (rigid registration, matrix(i, :) row i of the motion; initial='auto' the global start — see rigid registration), call mio_register_landmarks(src(3, n), dst(3, n), matrix(4, 4) [, weights, residuals, rms, stat, errmsg]), call mio_find_symmetry_plane(mesh, report [, seed_origin, seed_normal, tolerance, min_share, max_samples, stat, errmsg]) (mio_symmetry_plane_report) and aligned = mio_auto_align(mesh [, angle_tolerance, subdivisions, region, rotate_vector_data, report, stat, errmsg]) (mio_auto_align_report, mode 0 face, 1 axis), call m%adjacency(indptr, indices [, kind, stat, errmsg]) (the "node", "clique" or "cell" graph in CSR form, both arrays 1-based as METIS's Fortran numbering) and call m%write_graph(path [, kind, file_format, num_vertices, num_edges, max_degree, stat, errmsg]) (a METIS .graph or Scotch .grf file — see adjacency graphs), m%attach_quality(), m%quality_counts(...), m%check_quality([spec, max_inverted, max_degenerate, num_checks, num_failed, summary]) (the quality gate; → logical passed), m%reorder(method [, node_perm]) (method "rcm"/"morton"/"hilbert"; node_perm is an optional allocatable 1-based old→new node permutation), m%compute_bandwidth(), and comparison: m%equals(other [, atol, rtol, unordered]) (logical) / m%diff(other [, atol, rtol, unordered]) (verdict 0=identical / 1=equal within tolerance / 2=different), and merging: the module-level mio_merge(meshes [, weld, atol, source_tag, data_policy, drop_duplicate_cells]) (an array of type(mio_mesh) → a new type(mio_mesh); data_policy is "intersection" or "fill"), and the editing/stats bundle: m%transform(matrix(16) [, rotate_vector_data]), m%clean([weld, atol, remove_orphans, drop_degenerate, drop_duplicate_cells, points_welded, ...]), m%crop_bbox(lo, hi [, mode, record_ids]) / m%crop_plane(point, normal [, mode, record_ids]) (mode "all"/"any") / m%crop_predicate(array [, compare, value, record_ids]) (v9.25.0; keeps the cells whose scalar cell_data value satisfies a comparison — "<", "<=", ">", ">=", "==", "!=", the same vocabulary m%refine's where_op uses. A non-finite cell value never matches. There is deliberately no mode: a per-cell value has nothing for an all/any rule to reduce), m%split(by [, tag_name, keys]) (→ an allocatable array of type(mio_mesh)), m%stats() (→ a type(mio_stats_report) of scalar geometric measures), and m%convert_cells(mode [, record_parent_ids, point_map]) (mode "linearize"/"simplexify"/"elevate"; point_map is an optional allocatable 1-based input→output point map, 0 where the point was pruned), m%subdivide([record_parent_ids]) (polyhedral refinement: one polyhedral child per face of every eligible 3D cell, connected to a new interior point — no per-type template table, tabulated types and existing polyhedron blocks handled uniformly, and automatically conforming, unlike m%refine; → a new type(mio_mesh) with no point map, unlike m%convert_cells, since subdivide never prunes or renumbers a point; fails through stat/errmsg naming the cell when its faces are not a closed orientable surface), m%agglomerate([target_group_size, stat, errmsg, merge_coplanar_faces, coplanar_angle, min_sphericity, num_faces_merged, num_rejected]) (the options and counts of agglomerate, through mio_agglomerate_ex) (polyhedral coarsening, the many-to-one counterpart to m%subdivide: greedy seed-and-grow over the mesh's shared-face dual, absorbing face-adjacent neighbours by accumulated shared-face area until each group reaches target_group_size (default 8) members, then emitting one polyhedron per group whose faces are exactly its external boundary — conserving volume exactly, since internal faces are dropped rather than re-triangulated; → a new type(mio_mesh) with, like m%subdivide, no point map at all — the flat input→output cell map the underlying mio_agglomerate_result carries is a documented flat-binding gap here, not exposed on this wrapper, since an agglomerated cell's output index is a function of which group it joined rather than a per-block quantity Fortran's existing point_map/allocatable-array idioms fit; fails through stat/errmsg naming the face when the input is non-manifold), m%tet_to_poly([stat, errmsg, feature_angle, point_data_to_cell_data, record_vertex_ids, num_new_points, num_boundary_faces, num_split_vertices]) (the median dual, one polyhedron per vertex — see tetrahedral ⇄ polyhedral), m%poly_to_tet([record_parent_ids, stat, errmsg, num_exact_tets, num_fanned_cells]) (simplexify, keeping a polyhedron that already is a tetrahedron as one tetra), and m%refine(levels [, record_parent_ids, point_map, cells, region, where_array, where_op, where_value, closure, record_levels, record_hierarchy]) (subdivision into same-type children; levels defaults to 1. At most one of cells (global block-major, 1-based here), region and where_array + where_op + where_value selects a subset to refine, and the hanging nodes that leaves are resolved by closure — "redgreen" keeps the extra refinement local, "propagate" works for every cell type but reaches the whole edge-connected component. record_levels attaches the refine:level array; record_hierarchy attaches refine:cell_id/refine:parent_id — the persistent parent/child hierarchy a multigrid caller resolves across the sequence of meshes it keeps, and it also forces refine:entity to be attached even when the closure leaves no hanging node), and partitioning: m%partition(nparts [, method, imbalance, mode, seed, record_ids, ghost_layers, weights_key]) (→ an allocatable array of exactly nparts type(mio_mesh) pieces, part id = index − 1; method "sfc"/"kahip"/"auto") and m%partition_labels(nparts [, method, imbalance, mode, seed, weights_key]) (→ a flat block-major integer(int64) array of part ids in [0, nparts) — the values are ids, not indices, so no 1-based shift applies), and smoothing: m%smooth(method, iterations [, lambda, mu, fix_boundary, preserve_features, feature_angle, guard_inversion, nodes_moved, max_displacement, skipped_inversion, frozen]) (method "taubin"/"laplacian"; a negative lambda means the method's own default; frozen an optional 1-based integer(int64) point-id array, shifted to 0-based across the ABI; → a new type(mio_mesh) with the same cells and data and only its point coordinates moved, plus optional run-summary out-arguments), and green-element undo: projection back onto the CAD: the module-level mio_project_to_cad(mesh, info [, face_array, edge_array, max_distance, trim_samples, report, stat, errmsg]) (a mio_project_to_cad_report, whose num_on_curves counts the points on edges put onto the edge's own 3-D curve; mio_project_to_cad_outside_trim() returns the last call's points outside their face's trims, 1-based; see project to CAD), boundary layers: mio_boundary_layer(mesh, first_height [, num_layers, growth, reverse, collision_fraction, smooth_iterations, max_shrink, report, stat, errmsg, collapse, normal_smooth_iterations, front_check]) (collapse 'points' (default) or 'layers', front_check .true. by default; a mio_boundary_layer_report, with num_fewer_layers and num_front_crossings; see boundary layers), sweeps: mio_extrude(mesh [, direction, num_layers, ratio, offsets, record_layers, max_cells, report, stat, errmsg]) and mio_revolve(mesh [, axis, axis_point, angle, num_layers, tolerance, record_layers, max_cells, report, stat, errmsg]) (a mio_sweep_report; see sweeps), a reflection: mio_mirror(mesh [, origin, normal, keep_original, weld, tolerance, reflect_vector_data, report, stat, errmsg]) (a mio_mirror_report; see mirror), self-intersections and interpenetration: mio_find_intersections(mesh [, other, region, region_other, max_pairs, segments, other_flagged, pairs, report, stat, errmsg]) (pairs a 1-based (2, n) array, a mio_find_intersections_report; see intersections), wall thickness and clearance: mio_thickness(mesh [, other, direction, max_distance, threshold, region, region_other, report, stat, errmsg, method, cone_angle, cone_rays, two_sided, max_normal_deviation]) (a mio_thickness_report; see thickness), mio_deviation(scan, reference [, tolerance, bins, range_min, range_max, max_normal_angle, reference_region, report, stat, errmsg]) and mio_deviation_primitive(scan, ptype, params [, tolerance, bins, range_min, range_max, report, stat, errmsg]) (a mio_deviation_report; see deviation), mio_deviation_regions(mesh, tolerance [, field, prefix, min_area, report, stat, errmsg]) and mio_deviation_region(index [, stat]) (1-based; a mio_deviation_region_info), mio_exaggerate(mesh [, field, scale, clamp, smooth_fraction, report, stat, errmsg]), mio_colorize(mesh, field [, cmap, vmin, vmax, symmetric, steps, nan_color, component, report, stat, errmsg]) (see colorize), tetrahedra filling a closed triangle surface: mio_tetrahedralize(mesh [, max_size, max_volume, grading, optimize_steps, max_cells, face_array, backend, report, stat, errmsg, post_optimize]) (post_optimize, a logical, runs optimize_volume on each region afterwards, the boundary and the points kept) (backend 'auto' (Netgen when built in, else the octree backend), 'netgen' (the surface kept), 'octree' (native, the boundary fitted) or another name of mio_tet_mesher_name(i), i up to mio_tet_mesher_count() ('tetgen' and 'gmsh' run those installed programs, the surface kept); a mio_tetrahedralize_report with num_tetrahedra, num_points, num_new_points, num_regions, num_boundary_triangles, hausdorff_to_surface, min_dihedral_deg, max_dihedral_deg, volume, boundary_preserved and backend (1 for Netgen, 2 for the octree backend, 3 for another named mesher, whose name mio_tetrahedralize_backend_name(report) gives), mio_remesh_quads(mesh [, target_faces, backend, sharp, boundary, adaptive, dominant, seed, max_cells, report, stat, errmsg]) (field-aligned quads through an installed QuadriFlow or Instant Meshes, remesh_quads; a mio_remesh_quads_report whose remesher mio_remesh_quads_backend_name(report) names; mio_quad_remesher_count() and mio_quad_remesher_name(i) list them); 'netgen' without Netgen, which the free function mio_has_netgen() reports, fails naming MESHIOPLUSPLUS_WITH_NETGEN; see tetrahedralize), and green-element undo: the module-level mio_undo_green(coarse, fine [, num_groups_undone, num_cells_removed, stat, errmsg]) (a TWO-mesh function like mio_interpolate/mio_merge, not type-bound; fine must carry refine:cell_id/refine:parent_id/refine:level, i.e. must come from m%refine(..., record_hierarchy=.true., record_levels=.true.), and coarse must be the mesh that call was run on) → a new type(mio_mesh) restoring fine's transitional (green) sibling groups to the row coarse already has for them verbatim — a lookup, not a reconstruction, since refine never renumbers or prunes points — with the six reserved refine:* arrays always dropped and only a single-pass (levels=1) hierarchy supported; the per-block cell maps are a documented flat-ABI gap here, like m%agglomerate's, and mass-preserving field transfer: the module-level mio_conservative_interpolate(source, target [, arrays, default_value, on_conflict, stat, errmsg]) (a TWO-mesh function like mio_interpolate/mio_merge, not type-bound; unlike mio_interpolate, an omitted/zero-sized arrays means every source point_data AND cell_data array — one algorithm regardless of location) → a new type(mio_mesh) conserving sum(value * measure) over the region the two meshes share (both meshes simplexified first, accepting ragged/polyhedron blocks for free), unlike mio_interpolate's pointwise sampling; deliberately no extrapolate argument, since a silent fallback would break that guarantee, and the two cutters: m%slice(origin, normal [, record_parent_ids, stat, errmsg, chain, min_length]) (the planar cross-section, one topological dimension below the cut cells; chain walks a surface's section into polylines) and mio_sections(mesh, direction, offsets(:) [, min_length, record_parent_ids]) (chained sections at parallel planes), mio_fit_curves(sections [, tolerance, snap_angle, normal, min_arc_points, min_arc_sweep, report]) and mio_fit_curves_piece(i, piece) (lines, arcs and circles from them), mio_silhouette(mesh [, normal, clearance, round_angle, arc_segments, extrude, region, merge_tolerance, report]) (the outline along a direction; mio_silhouette_report), call mio_write_step_elements(path, mesh [, patches, segments, report]) (fitted primitives as STEP geometry; mio_step_elements_report), mio_measure(mesh, spec [, report, report_json]), mio_align_datums(mesh, primary, secondary [, origin, matrix]) and call mio_measure_element_primitive(mesh, name, type, params) (measure), mio_remove_islands(mesh [, connectivity, min_diagonal, min_area, min_cells, relative, dry_run, report]) (mio_remove_islands_report; remove islands), mio_flip_normals(mesh [, region, num_flipped]) (flip normals) and mio_clip(mesh, origin, normal [, keep_below, cap, report]) (mio_clip_report; clip), mio_offset_surface(mesh, distance [, smooth_iterations, report]), mio_thicken(mesh, thickness [, side, smooth_iterations, report]) and mio_hollow(mesh, wall [, smooth_iterations, report]) (mio_offset_report; offset), mio_face_support(solid, scan [, tolerance, measured_share, inferred_share, hole_data, report]), mio_fit_cad_iterate(scan [, step_path, part_class, target_within, target_explained, segment_tolerance, fit_tolerance, max_rounds, worst_faces, refine_factor, backend, report]) (closing the CAD loop) and mio_constrain_primitives(mesh [, face_tolerance, angle_tolerance, distance_tolerance, min_fraction, force(3, n), forbid(3, n), report]) with call mio_constrain_primitives_relation(k, ...) (constraining primitives) and mio_profile_solid(sketch, features [, step_path, scan, provider, deflection, report]) (features as text; profile solids) and its data-driven sibling m%isosurface(array, isovalues(:) [, component, record_parent_ids]) (the level set of a scalar point_data array; component defaults to −1 meaning the row magnitude, several isovalues land in one mesh tagged per cell with iso:value/iso:index, and a cell_data name fails through stat — convert it with m%data_cell_to_point first), and field differentiation: m%gradient(array [, op, method, location, output, component, overwrite, num_skipped, num_fallback]) (the gradient, divergence or curl of a point_data array; op "gradient"/"divergence"/"curl", method "green-gauss"/"least-squares", location "cell"/"point". component defaults to −1 meaning every component — the opposite of m%isosurface's sentinel. Cells that cannot be differentiated yield NaN and are reported in num_skipped; least-squares cells with a degenerate neighbourhood fall back to Green-Gauss and are reported in num_fallback), and second derivatives: m%hessian(array [, method, location, output, overwrite, num_skipped, num_fallback]) (the Hessian of a scalar point_data field -- m%gradient's companion one order further, a composition of TWO m%gradient calls, not a new kernel: the field is differentiated once at location="point" regardless of the caller's own location, then that (n,3) gradient is differentiated again with the default operator, producing (n,9) -- the flattened row-major 3x3 Hessian. method is forwarded to BOTH internal passes. A field that is at most linear has an exactly zero Hessian everywhere -- the one mesh-shape-independent guarantee; a genuinely quadratic field's composition is exact on a structured/symmetric mesh away from its own boundary and approximate on an irregular mesh (see doc/hessian.md). Input must have exactly one component -- a vector field's Hessian is a separate quantity per component, rejected naming the per-component workaround. A curvature-driven refinement indicator needs no new procedure: norm(...) in m%data_calc on the 9-component output is exactly its Frobenius norm, ready for m%refine's where_array/where_op/where_value selector), and error estimation: m%estimate_error(array [, method, marking, marking_value, output, marked, overwrite, global_error, num_skipped, num_marked]) (the Zienkiewicz-Zhu recovery-based error indicator of a point_data field — a composition of m%gradient with the point↔cell averaging round trip, not a new kernel — plus optional marking; method "zz", marking "none"/"absolute"/"fraction"/"dorfler". error:zz is always attached; error:marked too when marking is not "none", so m%refine's own where_array/where_op/where_value needs no change to consume it. Cells that cannot be evaluated read NaN in error:zz and 0 in error:marked, counted in num_skipped and excluded from global_error/num_marked), a size field from that indicator: m%error_size(target_error [, error_array, order, min_size, max_size, output, overwrite, report, stat, errmsg]) (roadmap 6.10.2; the Zienkiewicz-Zhu adaptive procedure, a cell of diameter h and indicator eta asking h * (target_error / sqrt(N) / eta)**(1 / order), clamped to [min_size, max_size] (0: no bound), each point the least of its cells', written as point data output ("size", what mesh_cad_surface's background reads); report is the public bind(C) type(mio_error_size_report) (num_cells, num_skipped, num_clamped, min_size, max_size), the 80-byte options struct layout-checked against C), and field integration: m%data_integrate([arrays, keys, totals, means, domain_measures, num_nans]) (→ an allocatable array of type(mio_field_integral_info){num_components, num_cells, num_skipped}, one per requested cell_data array (omitted arrays = every array); the four optional out-arguments are flat, array-major, per-component buffers, mesh_regions's own flat-buffer idiom — gradient's integration counterpart, a cell-measure-weighted total/mean, never a fallback weight of 1 for an unmeasurable cell or non-finite value) plus m%data_integrate_region(array_name [, keys, totals, means, domain_measures, num_nans]) for one named array's per-region breakdown — split into a second call rather than nesting array × region × component into one, mirroring m%data_integrate's own shape but one array at a time; every named Cell region present gets its own independent entry (not a partition: a cell in two regions contributes fully to both), and a point_data-only name fails through stat/errmsg naming m%data_point_to_cell as the fix | mio_grid(...), m%voxelize(..., plane) (plane 'auto', 'xy', 'xz' or 'yz' for 2-D pixels, resolution(3) = 0), m%octree([root_cells, min_level, max_level, bounds, padding, padding_relative, dimension, sample_distance, balance, fill, sign, watertight_check, attach_distance, even_odd, max_cells, num_leaves, num_hanging, finest_level, root_size]) (an octree or quadtree around a skin — see octree), m%octree_mesh([output, min_size, max_size, max_level, bounds, padding, padding_relative, curvature_angle, feature_angle, corner_angle, feature_size, gap_cells, gap_outside, size_array, surface_region, grading_layers, skin_grading, surface_size, winding_threshold, winding_beta, conformity, alpha_long, alpha_short, preserve_features, fit_iterations, dihedral_floor_guard, fill, keep_outside, attach_distance, attach_quality, pillow, hex_grading, untangle_iterations, max_cells, max_tets, volume_fix, zero_volume_factor, cap_flatness, crossing_margin, crossing_gap, report, warnings, leaves_per_level, stage_names, stage_seconds]) (mesh the inside of a skin on a balanced octree: tetrahedra by default, output='castellated' for the hexahedral leaves; every option left out keeps the mio_octree_mesh_opts_init default, the strings output/conformity/skin_grading/fill fail by name when unknown, the summary comes back in the public bind(C) type(mio_octree_mesh_report) and the warnings (and, through the optional stage_names, stage_seconds and leaves_per_level, the per-stage timings and the leaves at each level) as one newline-separated string — see octree_mesh), m%watertight_check(), m%sample_distance(points), m%distance_to_surface(surface) (v9.24.0), and m%compute_sdf([structure, resolution, cell_size, bounds, padding, padding_relative, root_resolution, max_depth, band_cells, record_levels, max_cells, sign, weight, location, band, watertight_check, dims, origin, spacing, depth, num_banded, quality]) (v9.25.0 — the grid and the field in one call; structure "voxel"/"octree", the latter sizing itself from root_resolution/max_depth, so resolution/cell_size with it is an error. spacing reports the finest cell, dims the root counts). mio_adapt(mesh, hsiz=, size_field=, metric=, hmin=, hmax=, hausd=, hgrad=, angle_detection=, frozen=, required=, report=) remeshes with MMG (1-based frozen; fails naming MESHIOPLUSPLUS_WITH_MMG without it: mio_has_mmg(), mio_has_mmg_elas(), mio_mmg_index_bits()), and mio_metric_from_hessian(mesh, hessian, [error, hmin, hmax, output]) makes its metric without MMG. Level-set cutting (cut): mio_cut_level_set(mesh, level_sets=, planes=, selection=, include_uncut=, backend=, degree=, triangulate=, record_parent_ids=, report=) and mio_cut_quadrature(mesh, ..., order=, report=), planes shaped (6, n) (origin, then normal), mio_cut_report with mio_cut_backend_name(report); mio_has_cutcells(), and without it a non-zero stat naming MESHIOPLUSPLUS_WITH_CUTCELLS. Tet-mesh coarsening (decimate_volume): m%decimate_volume([ratio, target_cells, max_error, placement, preserve_boundary, preserve_features, feature_angle, tets_removed, points_removed, collapses_rejected, max_error_applied, point_map, stat, errmsg, frozen]), the tet sibling of m%decimate through mio_decimate_volume_ex; exactly one of ratio/target_cells/max_error is required (none or two fails through stat), preserve_boundary defaults to .false. (boundary vertices participate, unlike m%decimate), frozen takes 1-based point ids, point_map is 1-based with 0 where the survivor was pruned, and its mio_decimate_volume_opts_t is checked once per process against the C struct's 96 bytes. The per-block cell maps are not exposed, as for m%decimate. mesh%mass_properties(density=, density_array=, region=, thickness=, about=, body_kind=, total=, regions=, region_names=, warnings=) returns the total mass (-1 on failure) and fills mio_mass_entry records (measure, mass, centre, inertia, principal_moments, principal_axes (a row-major 3x3 as nine numbers), gyration_radii; see mass properties). mesh%cast_rays(origins, directions, max_distance=, region=, hit=, distance=, point=, normal=, cell=) (origins(3, n), directions(3, 1) or (3, n); returns the number of hits, cell 1-based and 0 on a miss) and mesh%locate_points(points, tolerance=, cell=, nodes=, barycentric=) (points(3, n); nodes(4, n) 1-based, 0 for none; returns the number located); see ray casting and point location. mesh%filter_points(statistical_k=, std_ratio=, radius=, min_neighbors=, voxel_size=, min_distance=, point_map=, num_removed=) returns the point cloud (point_map 1-based, num_removed(4)); see point-cloud conditioning. | Data operations | Act on the mesh's data arrays; the geometry is never modified (see data operations). m%data_drop(location, names [, ignore_missing]), m%data_keep(...), m%data_rename(location, from, to), m%data_point_to_cell([names, suffix]), m%data_cell_to_point([names, weight, suffix]), m%data_calc(expression, output_name [, location, overwrite]), m%data_condition(location [, names, mode, lo, hi, scope, nan_policy, nan_replacement, suffix]), m%tensor_invariants(location [, names, outputs, prefix, suffix, overwrite]) — each returns a new type(mio_mesh) — and m%data_info([keys]) → an allocatable array of type(mio_data_array_info). location is MIO_DATA_POINT / _CELL / _FIELD; the other enumerations are MIO_WEIGHT_*, MIO_COND_*, MIO_SCOPE_*, MIO_NAN_* and MIO_TINV_* (a bitmask, OR together with ior). The module also exports STRBUF_LEN, the fixed width of the keys out-argument arrays used by m%split, m%data_info and m%regions | | Named regions | Named groups of points, cells or cell facets (see Named regions). m%regions([keys, entries]) → an allocatable array of type(mio_region_info), with the group names in keys and the flat integer(int64) entries in entries, laid out back to back in report order; m%add_region(name, kind, entries [, dim, tag]). kind is MIO_REGION_POINT / _CELL / _SIDE. Point and cell indices are shifted to Fortran's 1-based convention by the copying getter and setter; the facet column of a side region is not, matching the partition_labels rule that a value which is not an index stays as it is | | Module-level | mio_convert(in, out [, in_format, out_format]), mio_version(), mio_mesh_backend(), mio_cell_type_dimension(name) (the topological dimension 0-3 of a meshio cell-type name, Python's topological_dimension; -1 for an unknown name), mio_cell_type_num_nodes(name) (fixed nodes per cell; -1 for a variable-size type such as polygon or an unknown name), mio_detect(path) (the ranked detection report as format<TAB>confidence<TAB>reason lines, best first; CLI detect), mio_format_readable(f), mio_format_writable(f), mio_load_plugins(paths) (loads provider plugins, returns how many registered), mio_error_message(), and the settings pipeline: mio_pipeline_run_file(settings_path [, stat, errmsg]) / mio_pipeline_run_json(json_text [, stat, errmsg]) run a whole settings.json (read → operation chain → write), and mio_pipeline_has_json() reports whether the linked library carries the JSON parser (a build without it fails through stat naming -DMESHIOPLUSPLUS_WITH_JSON=ON) |

Format inference is the shared registry's, the C API's: the extension picks the format, with seven exceptions: a .mesh file whose first line names an MFEM mesh is read as mfem rather than medit (v16.5.0), Z88's fixed file names (z88i1.txt, z88o2.txt, …) are z88 rather than xyz (v16.7.0), a .dat file that opens as an MSC Marc input deck is marc rather than tecplot (v16.8.0), a file named d3plot, which has no extension, is LS-DYNA's lsdyna_d3plot (v16.9.0), a file named like crashA001 (a stem, A and three or more digits, no extension) is an OpenRadioss animation file, radioss_anim (v16.11.0), a file named binout (or binout0000…) is LS-DYNA's lsdyna_binout, and one named like crashT01 (a stem, T and two digits, no extension) an OpenRadioss time-history file, radioss_th (both v16.12.0). The two content checks are for reading: a write goes by the extension alone, so a .dat is written as Tecplot and a .mesh as Medit whatever the file being replaced holds (v16.17.0), and a Marc deck is written by naming marc. Formats added to the registry (Patran, Femap and MFEM in v16.5.0; libMesh, Z88, Abaqus .fil and Radioss in v16.7.0; Marc's marc and marc_t19 and the ansys_rst_cyclic full rotor in v16.8.0; lsdyna_d3plot and nastran_op2 in v16.9.0; Tecplot's binary .plt in v16.10.0; radioss_anim, the libMesh writer and its .gz/.bz2 names in v16.11.0; lsdyna_binout and radioss_th in v16.12.0; vtx, DOLFINx's ADIOS2 .bp directories, and szplt, Tecplot SZL, in v16.13.0, when the library was built with ADIOS2 and TecIO; the radioss and marc writers in v16.17.0, the radioss_th, nastran_op2, lsdyna_binout and abaqus_fil writers after them, and medit_sol, Medit's .sol/.solb solutions, v17.23.0) reach this binding with no code change; mio_format_readable/mio_format_writable report what the linked library holds.

The complete CI-tested example lives at doc/examples/fortran_example.f90; format support and the remaining limitations (side-channel metadata) are identical to the C API, which this module wraps; ragged blocks are no longer among them (see the table above). Copy-getters deliver real(real64) regardless of the stored dtype (float32/int32/int64 are converted); Fortran on Windows/MSVC is untested in v1.

m%read(path, 'gmsh') accepts non-periodic 4.0 files as well as 2.2/4.1, in ASCII or binary (4- or 8-byte producer counts). For periodic files use read_with_info / write_with_info; writes stay 4.1 (gmsh) or 2.2 (gmsh22). Info-less reads refuse $Periodic rather than lose it. See Gmsh.

Tetrahedral remeshing (adapt_volume) ​

out = m%adapt_volume(hmin=, hmax=, hgrad=, hausd=, hausd_relative=, preserve_boundary=, preserve_features=, quality_metric=, quality_min=, max_iterations=, collapse=, split=, swap=, smooth=, report=rep, stat=ierr, boundary_sizing=) remeshes a tetrahedral mesh to a graded size field (adapt_volume); rep is a type(mio_adapt_volume_report_t), the C report's interop mirror, with every count. size_array, frozen and the material arrays are on the C, C++ and Python APIs. mio_octree_mesh_opts_t gains post_adapt and adapt (a c_loc of a mio_adapt_volume_opts_t).

Selective reads and file summaries ​

Sets↔data conversions return a new mesh through m%sets_to_data(MIO_DATA_POINT [, data_name, join_char, order, stat, errmsg]) and m%data_to_sets(MIO_DATA_CELL, key [, stat, errmsg]). Only point/cell locations are accepted. Set order defaults to native region-name order; an explicit order lists every set name once. Labels are scalar integer values, not indices: they stay zero-based with -1 for uncovered entities. See sets/data semantics.

read takes optional points_only, arrays, time_step, lenient and (last, so positional stat/errmsg callers keep working) piece and drop_ghosts, and the module-level mio_read_metadata returns a type(mio_metadata):

fortran
type(mio_mesh) :: m
type(mio_metadata) :: meta

call m%read('big.msh', points_only=.true.)
call m%read('big.msh', arrays=['u   ', 'p   '])   ! fixed-length, as Fortran requires
call m%read('run.exo', time_step=-1)              ! the last step; 0 (default) is the first

meta = mio_read_metadata('run.exo')
print *, meta%num_points, meta%num_cells
print *, meta%fell_back_to_full_read      ! .true. => the file was read in full
print *, size(meta%time_values)           ! how many steps `time_step` may name

time_step picks a step of a multi-step file (0 = the first, negative counts from the end). Out of range is an error naming the available count, never a silent clamp; meta%time_values is allocated to size 0 for a format with no time concept.

A zero-sized arrays means no arrays, which is distinct from omitting the argument (every array). Names are trimmed and NUL-terminated internally; the copies outlive the call.

meta%cell_blocks is an array of type(mio_cell_block_info), and the name lists use the exported STRBUF_LEN convention, as split and data_info do.

Transient (time-series) XDMF writing ​

type(mio_xdmf_series) is the write half of what time_step and meta%time_values expose above, and the one writer m%write() cannot express: a series is a stateful multi-call object, so it gets its own handle rather than a write argument. The grid goes out once and each solve appends a cheap step. See XDMF time series.

fortran
type(mio_mesh) :: m
type(mio_xdmf_series) :: series
integer :: k

call series%create('simulation.xdmf')          ! "HDF" by default
call series%write_points_cells(m)              ! the static grid, once
do k = 0, nsteps - 1
    call solve(m)
    call series%write_data(k*dt, m)            ! point_data/cell_data only
end do
print *, series%num_steps()
call series%finalize()                         ! free() would do this too
call series%free()
Lifecycleseries%create(path [, data_format, gzip_level]), series%free(), series%is_valid()
Writingseries%write_points_cells(mesh), series%write_data(time, mesh), series%finalize(), series%num_steps()

data_format is 'HDF' (the default; needs an HDF5-enabled build), 'XML' (everything inline in the .xdmf) or 'Binary'; gzip_level applies to 'HDF' datasets only and is negative (no compression) by default. An unknown format, or 'HDF' against a library built without HDF5, fails through stat/errmsg like every other fallible procedure.

Two things worth knowing before reading the result back:

  • the .xdmf light data is buffered until the series is finalized, so the file is only readable after series%finalize() (or series%free(), which finalizes first);
  • free() swallows a write failure during that implicit finalize — call finalize() explicitly, with stat, to see one.

Handles are freed explicitly, exactly like type(mio_mesh); there is no finalizer. Reading a finished series back is the ordinary m%read(path, time_step=k), with mio_read_metadata(path)%time_values reporting the steps.

Software rendering (v16.34.0) ​

A deterministic software rasterizer and its terminal, HTML and PNG encodings, with no display or GPU: see terminal rendering for what is drawn and every option. Options are the plain-Fortran mio_render_settings (allocatable strings, .true./.false. flags, an allocated vmin, vmax, clip_low or clip_high meaning "set", colours as integer(int64) 0xRRGGBBAA from mio_rgba(r, g, b, a)), whose defaults are the C ones.

fortran
type(mio_render_settings) :: set
type(mio_frame) :: frame
integer, allocatable :: rgba(:, :, :), png(:)

set%width = 800; set%height = 600; set%supersample = 2
set%color_by = 'temperature'; set%colorbar = .true.
allocate (set%clip_low, source=2.0_real64)
frame = mesh%render(set, stat=ierr)          ! frame%is_valid(), %width(), %height(), %range(vmin, vmax)
call frame%get_rgba(rgba)                    ! rgba(4, width, height), channels 0..255, row 1 on top
call frame%png(png)                          ! the file's bytes as 0..255 values
call frame%free()

text = mesh%render_text(set, tset)           ! tset%cols x tset%rows cells; mio_text_settings
call mesh%write_snapshot('part.png', set)    ! .png .txt .ansi .html .cast

Cut-aways (v16.36.0). set%cutaways is an allocatable real(real64) array of one or two planes, six numbers each (a point, then the normal of the side kept), and set%cutaway_tint a colour (mio_rgba); the geometry on the far side is clipped away, the cut through a volume or a closed surface is capped, and the back faces of an open one now in view are tinted. A length that is not 6 or 12, or a zero normal, is refused by name: set%cutaways = [0.5_real64, 0.0_real64, 0.0_real64, 1.0_real64, 0.0_real64, 0.0_real64].

Streamlines (v16.37.0). set%streamlines names a vector point array to follow; set%stream_seeds (default 40), set%stream_length (model diagonals each way, default 0.5) and set%stream_color (mio_rgba) shape the lines. An unknown array or a seed count outside 1 to 10000 is refused by name: set%streamlines = 'velocity'.

frame%get_cell_ids(ids) gives the input cell at each pixel (ids(width, height), -1 for none), frame%num_notes() and frame%note(i) the colour range, ticks and keys, and frame%text(tset) encodes a frame whose size fits the encoding's cell grid. mio_detect_color_depth(no_color=, color_term=, term=) returns a MIO_COLOR_* constant. The MIO_SHADING_*, MIO_EDGES_*, MIO_SCALE_*, MIO_DIAGNOSTIC_*, MIO_ENCODING_*, MIO_COLOR_* and MIO_TEXT_* constants name the enum values. Without stat= a failure stops the program with the library's message, as everywhere in this module.

Parametric generators ​

mio_rectangle, mio_box, mio_disk, mio_uv_sphere, mio_icosa_sphere, mio_cylinder, mio_reference_triangle, mio_ngon, mio_annulus, mio_lshape, mio_plate_with_hole, mio_honeycomb, mio_line, mio_circle, mio_helix, mio_sphere_points, mio_box_points, mio_tetra_sphere, mio_octa_sphere, mio_cube_sphere, mio_geo_sphere, mio_torus, mio_moebius, mio_tube, mio_cone, mio_capsule, mio_box_surface, mio_platonic, mio_ball, mio_spherical_shell, mio_pipe, mio_fichera, mio_solid_torus and mio_reference_cells are module functions returning a mio_mesh, like mio_grid, with every argument optional: dims, lengths (a rectangle's or box's side lengths), origin, radius, height, n, nu, nv, subdivisions, nxy, nz, sides, rings, inner_radius, outer_radius, ntheta, nr, nt, angle, size (a bounding or plate side), edge, center, start_point, end_point (a line's ends), pitch, turns, seed, major_radius, minor_radius, width, num_twists, ncap, ratio, name (a platonic solid), cell_type, split ('zigzag', 'up', 'down', 'center'), order (3 to 10 for the VTK Lagrange family), max_cells, complete (a logical: full-Lagrange order 2, the last optional argument so keyword use is needed), and for mio_reference_cells a comma-separated types string and pairs. They fill a mio_gen_opts_t, whose 160-byte layout is checked once per process. An unknown cell_type or split is reported through stat/errmsg. See parametric primitives.

v9.1.0 additions ​

  • m%read(..., lenient=.true.) — see doc/selective_read.md.
  • m%read(path, piece=k) — keep one piece of a partitioned file (VTKHDF partitions or composite blocks): 0 is the first, negative counts from the end, omitted merges every piece into one mesh with one cell region per piece; out of range fails, never clamps. On a type(mio_read_opts_t) set piece and piece_set = 1 (piece_set is what selects; a zeroed struct merges). See doc/selective_read.md.
  • m%read(path, drop_ghosts=.true.) — remove the ghost cells (halo) of a partitioned .pvtu, .pvtp or .pvd (every cell with a vtkGhostType bit set, and the points only they used); omitted keeps them, and every other reader ignores it. On a type(mio_read_opts_t) set drop_ghosts = 1 (it took the fifth former reserved slot; size unchanged). See doc/selective_read.md.
  • XDMF series: s%flush(), s%finalized(), and s%create(..., mode='append', auto_flush=...).

Gap, deliberate: four Python-only formats — pmsh, zarr, cae and usd (v10.35.0, the physics-ML data path) — are registered in the Python layer only, not in the shared C++ dispatch registry, so this surface cannot read or write them; see formats. And there is no Fortran counterpart to the solver-array write_data overload. An array of derived types holding interop pointers is a poor fit for Fortran, and a Fortran solver already holds an mio_mesh handle it can add_point_data into before write_data. MdpaInfo is reached through mio_format_info (below).

Format side channels ​

Gmsh read_with_info keeps periodic links and 4.1 bounding-entity tags. info%gmsh_count(MIO_GMSH_PERIODIC) counts links; gmsh_tags(section, i) copies bounding tags (MIO_GMSH_BOUNDING_ENTITIES) or [dimension, slave entity tag, master entity tag] (MIO_GMSH_PERIODIC). gmsh_affine(i) copies 0 or 16 coefficients; gmsh_pairs(i) copies (2, N) slave/master 1-based point rows, keeping ordering and duplicates. Item indices are 1-based, entity tags stay raw file ids. write_with_info(path, info, 'gmsh') or 'gmsh22' restores the links; mesh operations do not remap them, so rebuild info after point/topology edits.

MFEM NURBS meshes (v16.40.0) keep their patches the same way: read_with_info(path, info, 'mfem'), then info%nurbs_count(MIO_NURBS_PATCHES), nurbs_degrees(p), nurbs_knots(p, dir), nurbs_control_points(p) ((space dimension, points), direction 1 fastest), nurbs_weights(p), nurbs_field(p, k) ((components, points)), nurbs_field_name(k), nurbs_int(section, i, field) and nurbs_ids(section, field), which copies a MIO_NURBS_TOPOLOGY or MIO_NURBS_CELL_MAP index array as (columns, rows) (a one-dimensional one as (1, n)). Patches, directions and fields are 1-based, and so are the vertices, patches and knot spans the arrays hold; attributes and the edges' knot-vector ids stay as the file spelled them. write_with_info(path, info, 'mfem') writes the patches back as an MFEM NURBS mesh (MFEM).

Kratos CAD JSON (and, with OpenCASCADE, STEP and IGES) keep their B-rep the same way: read_with_info(path, info, 'cad_json'), then info%brep_count(MIO_BREP_FACES), brep_int(section, i, field), brep_values(section, i, field) (a Float64 array: weights, knots, an active range), brep_points(section, i, field) ((3, points)), brep_ids(section, i, field) (an Int64 array: control-point ids, a brep's faces) and brep_string(section, i, field), with the MIO_BREP_* sections and the field numbers of the C API. Items are 1-based, and so is an int field that indexes another section (a face's patch, first loop or first trim; a loop's or trim's face; a trim's loop; an edge's or vertex's first topology entry; 0 for none), and a brep's face, edge and vertex lists; ids, flags, counts and trim indices stay as the file spells them. write_with_info(path, info, 'cad_json') writes the B-rep back as CAD JSON.

MDPA sub-model-part membership is available through info%mdpa_ids(MIO_MDPA_SUBMODELPARTS, i, field): field 0 is tables, field 1 geometry ids and field 2 constraint ids. The item index i is 1-based, but these values are raw file ids (no index shift), retain ordering and duplicates and are not remapped by mesh operations. write_with_info restores nested membership-only parts; constraints remain opaque.

call m%read_with_info(path, info [, format, lenient, stat, errmsg, deflection, angular_deflection, heal, sew_tolerance]) (the last four for STEP and IGES: the triangulation's deflections, and healing, STEP reading) fills a type(mio_format_info) for a format with a side channel (MDPA: tables, geometries, Mesh blocks, sub-model-part data, text ModelPartData, raw blocks such as Constraints); call m%write_with_info(path, info) writes it back and call info%free() releases it. Accessors take a MIO_MDPA_* section and a 1-based item index: info%mdpa_count, mdpa_string, mdpa_int, mdpa_ids, mdpa_table(i) (a (rows, cols) array), mdpa_geometry(i) (conn(nodes, n), 1-based points) and mdpa_data_* for key/value entries. See MDPA.

Sequences (transient / multi-file datasets) ​

type(mio_sequence) wraps the C API's ordered plan over a set of files (or the steps inside one multi-step file). Ordering is natural-numeric, so out_9.vtu precedes out_10.vtu; nothing is read until %read_step, and the sequence caches nothing, so a 500-step dataset is traversable without materialising it.

fortran
type(mio_sequence) :: seq
type(mio_mesh) :: step
integer :: i

call seq%open('out_*.vtu')
do i = 1, int(seq%count())
    step = seq%read_step(i)          ! OWNED; free it yourself
    print *, seq%time(i), seq%time_source(i)
    call step%free()
end do
call seq%to_timeseries('series.xdmf')            ! fan-in
call seq%resample('u_{index}.vtu', [0.0_real64, 0.5_real64, 1.0_real64], &
                  method='linear', clamp=.false.)  ! onto new times
call seq%free()

call mio_timeseries_to_sequence('series.xdmf', 'step_{step}.vtu')  ! fan-out
call mio_sequence_pipeline_run_file('transient.json')              ! per-step chain

Indices are 1-based, like every other Fortran accessor, and handles are freed explicitly (%free()) exactly as mio_mesh is — there is no finalizer. Every fallible procedure takes the usual optional stat/errmsg.

seq%resample(out_path, times [, method, clamp, blend_points, out_format, stat, errmsg]) resamples onto new times (method 'linear', 'nearest' or 'previous'), and the module function mio_blend_steps(a, b, w [, blend_points, stat, errmsg]) blends two steps of one topology into a new mesh. See Resampling onto new times.

See sequences for the ordering rule, the time-value precedence and the streaming guarantee.

Subdivision, units, CRS, booleans and the surface query ​

mesh%subdivide_surface(scheme=MIO_SUBDIVIDE_LOOP, levels=, crease_angle=, ...), mesh%set_field_unit(array, unit), mesh%field_unit(array, unit8) (a logical), mesh%convert_units(system=, strict=), mesh%crs(), mesh%set_crs(crs), mesh%convert_coordinates_crs(target), mio_has_crs_provider(), mio_mesh_boolean(a, b, op=MIO_BOOLEAN_UNION, backend=), mio_has_boolean_provider(), mio_undo_green_fine(fine), and type(mio_surface_query) (create(mesh, region=), cast_rays, closest_points, num_triangles, free; indices 1-based). mesh%refine gains undo_green_first and the "mixed_green" closure, mesh%partition connected_parts, and mesh%convert_cells order and full. See smooth subdivision, units and CRS, surface booleans and the surface query.

Released under the MIT License.