# Preventing NetCDF files from corruption in case of NEMO crash

**URL:** https://nemo-ocean.discourse.group/t/preventing-netcdf-files-from-corruption-in-case-of-nemo-crash/455
**Category:** v4.2.x
**Created:** [10 March 2023 14:22 UTC](https://nemo-ocean.discourse.group/t/preventing-netcdf-files-from-corruption-in-case-of-nemo-crash/455 "2023-03-10T14:22:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![qtqw](https://avatars.discourse-cdn.com/v4/letter/q/77aa72/32.png) [@qtqw](https://nemo-ocean.discourse.group/u/qtqw)
#### Post date: [10 March 2023 14:22 UTC](https://nemo-ocean.discourse.group/t/preventing-netcdf-files-from-corruption-in-case-of-nemo-crash/455/1 "2023-03-10T14:22:18Z")

</div>

As I understand from the topic

> [@Corrupted XIOS netcdf files with zero record after a crash](https://nemo-ocean.discourse.group/t/corrupted-xios-netcdf-files-with-zero-record-after-a-crash/388):
>
> I remember years ago, Seb had a command line to recover netcdf files that were not closed properly after a nemo crash (and display zero record but quite a reasonable size for a non-zero record dimension), but have forgot it. Does someone do? My apology if was already posted.

there is no way to recover an output NetCDF file after a NEMO crash. The reason is that .nc-file is not closed properly.  
Is it possible to close .nc-file during NEMO modelling?  
Or maybe create separate .nc-file for each time?

---

<div class="post-metadata">

### Author: ![smasson](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@smasson](https://nemo-ocean.discourse.group/u/smasson)
#### Post date: [10 March 2023 17:55 UTC](https://nemo-ocean.discourse.group/t/preventing-netcdf-files-from-corruption-in-case-of-nemo-crash/455/2 "2023-03-10T17:55:07Z")

</div>

You don’t need to close the NetCDF file you are writing to update the value of its number of records. This can be done through a call to NF90\_SYNC: _“The function NF90\_SYNC offers a way to synchronize the disk copy of a netCDF dataset with in-memory buffers”._ see section 2.11 NF90\_SYNC in the [nf90 doc](https://docs.unidata.ucar.edu/netcdf-fortran/current/f90_datasets.html).

When you use xios, you can specify at which frequency you want that xios is calling `NF90_SYNC` by the means of the `sync_freq` keyword in the field\_def\_nemo-\*.xml. files.

For example, If you specify sync\_freq=“1ts” in your field\_def\_nemo-\*.xml, the value of the number of records already written in your NetCDF files will be updated at every time step.

Note that calling `NF90_SYNC` at high frequency can strongly degrade the model performances… This should not be done in production mode.
