from copy import deepcopy
from netCDF4 import Dataset
from mpi4py import MPI

def to_chimere_format(self, path, keep_open=True):
    # Open NetCDF
    if self.info:
        print("Rank {0:03d}: Creating {1}".format(self.rank, path))
    if self.size > 1:
        netcdf = Dataset(
            path,
            format="NETCDF4",
            mode="w",
            parallel=True,
            comm=self.comm,
            info=MPI.Info(),
        )
    else:
        netcdf = Dataset(path, format="NETCDF4", mode="w", parallel=False)
    if self.info:
        print("Rank {0:03d}: NetCDF ready to write".format(self.rank))

    set_global_attributes(self)


def set_global_attributes(self):
    current_attributes = deepcopy(self.global_attrs)
    del self.global_attrs
    self.global_attributes = {
        "Title": "CHIMERE SUITE",
        "Sub-title": "Emissions file - Surfacic + Point sources + Fires",
        "Generating_process": "Generated by Hermes_delta",
        "Conventions": "",
        "Domain": "EU027n",
        "history": "",
    }
