NetCDF I/O

In PARALLAX, input and output operations for various entities are handled through the NetCDF library, a widely-used file format with interfaces available for many programming languages and tools (e.g., Python, Matlab). For each PARALLAX entity, such as mesh, multigrid, csrmat, etc., I/O routines are provided that take a NetCDF identifier as input. This identifier can point to a NetCDF file or a specific group within a file, where the provided I/O routines allow seamless interaction with NetCDF files, making it easy to read and write data to and from PARALLAX entities.

The example below demonstrates how to write the mesh entity to a new NetCDF file, my_file.nc, and store it in the group my_mesh:

use NETCDF
! Status integer for NetCDF routines
integer :: nf90_stat
! File identifier
integer :: nf90_file_id
! Group identifier
integer :: nf90_group_id

! Create a new NetCDF file 'my_file.nc'
nf90_stat = nf90_create('my_file.nc', NF90_NETCDF4, nf90_file_id)
call handle_error_netcdf(nf90_stat, __LINE__, __FILE__)

! Define the group 'my_mesh' within the file 'my_file.nc'
nf90_stat = nf90_def_grp(nf90_file_id, 'my_mesh', nf90_group_id)
call handle_error_netcdf(nf90_stat, __LINE__, __FILE__)

! Write the 'mesh' entity to the NetCDF group via the group identifier
call mesh%write_netcdf(nf90_group_id)

! Close the NetCDF file
nf90_stat = nf90_close(nf90_file_id)
call handle_error_netcdf(nf90_stat, __LINE__, __FILE__)

After executing the code, the contents of the created NetCDF file could look like this:

$  ncdump -h my_file.nc

netcdf my_file {

group: my_mesh {
  dimensions:
    n_points = 17432 ;
    n_points_inner = 15000 ;
    n_points_boundary = 864 ;
    n_points_ghost = 1568 ;
    size_neighbor = 5 ;
  variables:
    int cart_i(n_points) ;
    int cart_j(n_points) ;
    int pinfo(n_points) ;
    int district(n_points) ;
    int inner_indices(n_points_inner) ;
    int boundary_indices(n_points_boundary) ;
    int ghost_indices(n_points_ghost) ;
    int index_neighbor(n_points, size_neighbor, size_neighbor) ;
    int redblack_indices(n_points) ;

  // Group attributes:
        :phi = 0. ;
        :lvl = 1 ;
        :lvst = 1 ;
        :spacing_f = 0.004 ;
        :spacing_c = 0.004 ;
        :xmin = -0.4 ;
        :ymin = -0.4 ;
        :nx_f = 200 ;
        :ny_f = 200 ;
        :size_ghost_layer = 2 ;
        :yperiodic = 0 ;
        :extend_beyond_wall = 0 ;
        :n_points_red = 7512 ;
        :n_points_black = 7488 ;
  } // group my_mesh
}

Entities in PARALLAX can have nested groups to various depths. For instance, the multigrid entity writes the meshes of different levels to separate groups within the NetCDF file.