I wrote a small library for writing NETCDF files compatible with python xarray library.
It started a few year ago when I decided to write the output of code to NETCDF in a format compatible with xarray so it can be easily read.
I decided in the last few days to make a full library that is not going to use all the NETCDF possibilities but that would have been as easy to use as possible. I extensively used Google gemini to achieve that.
The ide is that you can write a netcdf as easily as:
program test_simple
use fortxarray, only: xarray_type
use iso_fortran_env, only: dp => real64
implicit none
integer, parameter :: NP = 5, NX = 3
type(xarray_type) :: xr
real(dp) :: z(NP, NX)
integer :: j, k
do concurrent(j=1:NP, k=1:NX)
z(j,k) = j*10 + k
end do
call xr%create_netcdf('temporary')
call xr%add_dimension('t', NP)
call xr%add_dimension('x', [real(dp) :: 10, 20, 30])
call xr%add_variable('z', z, ['t','x'])
call xr%add_variable('zz', z, ['tt', 'xx'], add_dimension=.true.)
call xr%close_netcdf()
end program test_simple
The really bare minimum is:
call xr%create_netcdf('temporary')
call xr%add_variable('zz', z, ['tt', 'xx'], add_dimension=.true.)
call xr%close_netcdf()
If you don’t care about the dimension being an array of something.
There are routines similar to those to read back the data.