cd /news/developer-tools/simple-netcdf-writer-xarray-compatib… · home topics developer-tools article
[ARTICLE · art-68755] src=fortran-lang.discourse.group ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Simple netcdf writer xarray compatible

A developer released fortxarray, a small Fortran library for writing NETCDF files compatible with Python's xarray library, designed for simplicity and ease of use. The library, which leverages Google Gemini for development, allows users to write NETCDF files with minimal code, such as three calls to create, add a variable, and close. It includes routines for reading data back and supports both explicit dimension definitions and automatic dimension creation.

read1 min views1 publishedJul 22, 2026

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.

── more in #developer-tools 4 stories · sorted by recency
── more on @fortxarray 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/simple-netcdf-writer…] indexed:0 read:1min 2026-07-22 ·