{"slug": "simple-netcdf-writer-xarray-compatible", "title": "Simple netcdf writer xarray compatible", "summary": "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.", "body_md": "I wrote a small library for writing NETCDF files compatible with python xarray library.\n\nIt 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.\n\nI 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.\n\nThe ide is that you can write a netcdf as easily as:\n\n```\nprogram test_simple\n  use fortxarray, only: xarray_type\n  use iso_fortran_env, only: dp => real64\n  implicit none\n\n  integer, parameter ::  NP = 5, NX = 3\n  type(xarray_type) :: xr\n  real(dp) :: z(NP, NX)\n  integer :: j, k\n\n  do concurrent(j=1:NP, k=1:NX)\n      z(j,k) = j*10 + k\n  end do\n\n  call xr%create_netcdf('temporary')\n  call xr%add_dimension('t', NP)\n  call xr%add_dimension('x', [real(dp) :: 10, 20, 30])\n\n  call xr%add_variable('z', z, ['t','x'])\n  call xr%add_variable('zz', z, ['tt', 'xx'], add_dimension=.true.)\n  call xr%close_netcdf()\n\nend program test_simple\n```\n\nThe really bare minimum is:\n\n```\ncall xr%create_netcdf('temporary')\ncall xr%add_variable('zz', z, ['tt', 'xx'], add_dimension=.true.)\ncall xr%close_netcdf()\n```\n\nIf you don’t care about the dimension being an array of something.\n\nThere are routines similar to those to read back the data.", "url": "https://wpnews.pro/news/simple-netcdf-writer-xarray-compatible", "canonical_source": "https://fortran-lang.discourse.group/t/simple-netcdf-writer-xarray-compatible/11013#post_1", "published_at": "2026-07-22 15:09:13+00:00", "updated_at": "2026-07-22 15:09:53.625288+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["fortxarray", "xarray", "NETCDF", "Google Gemini", "Fortran"], "alternates": {"html": "https://wpnews.pro/news/simple-netcdf-writer-xarray-compatible", "markdown": "https://wpnews.pro/news/simple-netcdf-writer-xarray-compatible.md", "text": "https://wpnews.pro/news/simple-netcdf-writer-xarray-compatible.txt", "jsonld": "https://wpnews.pro/news/simple-netcdf-writer-xarray-compatible.jsonld"}}