Ignore:
Timestamp:
11/26/14 12:06:21 (10 years ago)
Author:
rlacroix
Message:

Add a new attribute to the file definition so that the output format can be controlled.

Currently the supported formats are "netcdf4" and "netcdf4_classic". The "format" attribute is optional. The "netcdf4" format will be used when no format is explicitly defined. Since "netcdf4" is the format which was previously used by XIOS, existing configuration files will not be affected by this change.

If "netcdf4_classic" is used, the output file(s) will be created using the classic NetCDF format. This format can be used with the attribute "type" set to "one_file" if the NetCDF4 library was compiled with Parallel NetCDF support (--enable-pnetcdf).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/output/onetcdf4.cpp

    r501 r517  
    1111 
    1212      CONetCDF4::CONetCDF4 
    13          (const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile) 
     13         (const StdString & filename, bool exist, bool useClassicFormat, const MPI_Comm * comm, bool multifile) 
    1414            : path() 
     15            , useClassicFormat(useClassicFormat) 
    1516      { 
    1617         this->wmpi = (comm != NULL) && !multifile; 
    17          this->initialize(filename, exist, comm,multifile); 
     18         this->initialize(filename, exist, useClassicFormat, comm,multifile); 
    1819      } 
    1920 
     
    2930 
    3031      void CONetCDF4::initialize 
    31          (const StdString & filename, bool exist, const MPI_Comm * comm, bool multifile) 
    32       { 
     32         (const StdString & filename, bool exist, bool useClassicFormat, const MPI_Comm * comm, bool multifile) 
     33      { 
     34         this->useClassicFormat = useClassicFormat; 
     35 
     36         int mode = useClassicFormat ? 0 : NC_NETCDF4; 
     37         if (!multifile) 
     38            mode |= useClassicFormat ? NC_PNETCDF : NC_MPIIO; 
     39 
    3340         if (!exist) 
    3441         { 
    3542            if (comm != NULL) 
    3643            { 
    37                if (!multifile) (CNetCdfInterface::createPar(filename, NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, (this->ncidp))); 
    38                else (CNetCdfInterface::create(filename, NC_NETCDF4, this->ncidp)); 
     44               if (!multifile) CNetCdfInterface::createPar(filename, mode, *comm, MPI_INFO_NULL, this->ncidp); 
     45               else CNetCdfInterface::create(filename, mode, this->ncidp); 
    3946            } 
    40             else (CNetCdfInterface::create(filename, NC_NETCDF4, this->ncidp)); 
     47            else CNetCdfInterface::create(filename, mode, this->ncidp); 
    4148         } 
    4249         else 
     
    4451            if (comm != NULL) 
    4552            { 
    46                if (!multifile) (CNetCdfInterface::openPar(filename, NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, this->ncidp)); 
    47                else (CNetCdfInterface::open(filename, NC_NETCDF4, this->ncidp)); 
     53               if (!multifile) CNetCdfInterface::openPar(filename, mode, *comm, MPI_INFO_NULL, this->ncidp); 
     54               else CNetCdfInterface::open(filename, mode, this->ncidp); 
    4855            } 
    49             else  (CNetCdfInterface::open(filename, NC_NETCDF4, this->ncidp)); 
    50          } 
     56            else CNetCdfInterface::open(filename, mode, this->ncidp); 
     57         } 
     58 
     59         // If the classic NetCDF format is used, we enable the "no-fill mode" globally. 
     60         // This is done per variable for the NetCDF4 format. 
     61         if (useClassicFormat) 
     62            CNetCdfInterface::setFill(this->ncidp, false);     
    5163      } 
    5264 
     
    264276         } 
    265277 
    266          (CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &(dimids[0]), varid)); 
    267  
    268 // set chunksize : size of one record 
    269 // but must not be > 2GB (netcdf or HDF5 problem) 
    270          totalSize=1 ; 
    271          for(vector<StdSize>::reverse_iterator it=dimsizes.rbegin(); it!=dimsizes.rend();++it) 
    272          { 
    273            totalSize*= *it ; 
    274            if (totalSize>=maxSize) *it=1 ; 
    275          } 
    276  
    277          (CNetCdfInterface::defVarChunking(grpid, varid, NC_CHUNKED, &(dimsizes[0]))); 
    278          (CNetCdfInterface::defVarFill(grpid, varid, true, NULL)); 
     278         CNetCdfInterface::defVar(grpid, name, type, dimids.size(), &(dimids[0]), varid); 
     279 
     280         // The classic NetCDF format does not support chunking nor fill parameters 
     281         if (!useClassicFormat) 
     282         { 
     283            // set chunksize : size of one record 
     284            // but must not be > 2GB (netcdf or HDF5 problem) 
     285            totalSize = 1; 
     286            for (vector<StdSize>::reverse_iterator it = dimsizes.rbegin(); it != dimsizes.rend(); ++it) 
     287            { 
     288              totalSize *= *it; 
     289              if (totalSize >= maxSize) *it = 1; 
     290            } 
     291 
     292            CNetCdfInterface::defVarChunking(grpid, varid, NC_CHUNKED, &dimsizes[0]); 
     293            CNetCdfInterface::defVarFill(grpid, varid, true, NULL); 
     294         } 
     295 
    279296         return (varid); 
    280297      } 
Note: See TracChangeset for help on using the changeset viewer.