source: XIOS/dev/dev_trunk_omp/src/io/netCdfInterface.cpp @ 1670

Last change on this file since 1670 was 1665, checked in by yushan, 5 years ago

MARK: branch merged with trunk @1660. Add option --omp to enable multithreading.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 42.1 KB
Line 
1/*!
2   \file netCdfInterface.cpp
3   \author Ha NGUYEN
4   \date 08 Oct 2014
5   \since 03 Oct 2014
6
7   \brief Wrapper of netcdf functions.
8 */
9
10#include "netCdfInterface.hpp"
11#include "netCdfException.hpp"
12#include "ep_mpi.hpp"
13
14namespace xios
15{
16/*!
17This function creates a new netcdf file and return its id
18\param [in] fileName Name of the file
19\param [in] cMode create mode
20\param [in/out] ncId id of the created file
21\return Status code
22*/
23int CNetCdfInterface::create(const StdString& fileName, int cMode, int& ncId)
24{
25  int status;
26  #pragma omp critical (_netcdf)
27  {
28    info(200)<<"start nc_create"<<std::endl;
29    status = nc_create(fileName.c_str(), cMode, &ncId);
30    info(200)<<"end nc_create"<<std::endl;
31  }
32  if (NC_NOERR != status)
33  {
34    StdString errormsg(nc_strerror(status));
35    StdStringStream sstr;
36    sstr << "Error when calling function: nc_create(fileName.c_str(), cMode, &ncId) " << std::endl
37         << errormsg << std::endl
38         << "Unable to create file, given its name: " << fileName
39         << " and its creation mode " << creationMode2String(cMode) << std::endl;
40    StdString e = sstr.str();
41    throw CNetCdfException(e);
42  }
43
44  return status;
45}
46
47/*!
48This function creates a new netcdf file on parallel file system
49\param [in] fileName Name of the file
50\param [in] cMode create mode
51\param [in] comm MPI communicator
52\param [in] info MPI information
53\param [in/out] ncId id of the created file
54\return Status code
55*/
56int CNetCdfInterface::createPar(const StdString& fileName, int cMode, MPI_Comm comm, MPI_Info info, int& ncId)
57{
58  #ifdef _usingEP
59  int status = xios::nc_create_par(fileName.c_str(), cMode, comm, to_mpi_info(MPI_INFO_NULL), &ncId);
60  #else
61  int status = xios::nc_create_par(fileName.c_str(), cMode, comm, MPI_INFO_NULL, &ncId);
62  #endif
63
64  if (NC_NOERR != status)
65  {
66    StdString errormsg(nc_strerror(status));
67    StdStringStream sstr;
68    sstr << "Error when calling function: nc_create_par(fileName.c_str(), cMode, comm, info, &ncId) " << std::endl
69         << errormsg << std::endl
70         << "Unable to create file on parallel file system, given its name: " << std::endl
71         << "and its creation mode " << creationMode2String(cMode) << std::endl;
72    StdString e = sstr.str();
73    throw CNetCdfException(e);
74  }
75
76  return status;
77}
78
79/*!
80This function opens a netcdf file, given its name and open mode, return its id
81\param [in] fileName Name of the file
82\param [in] oMode open mode
83\param [in/out] ncId id of the opening file
84\return Status code
85*/
86int CNetCdfInterface::open(const StdString& fileName, int oMode, int& ncId)
87{
88  int status;
89  #pragma omp critical (_netcdf)
90  {
91    info(200)<<"start nc_open"<<std::endl;
92    status = nc_open(fileName.c_str(), oMode, &ncId);
93    info(200)<<"end nc_open"<<std::endl;
94  }
95  if (NC_NOERR != status)
96  {
97    StdString errormsg(nc_strerror(status));
98    StdStringStream sstr;
99    sstr << "Error when calling function: nc_open(fileName.c_str(), oMode, &ncId) "<< std::endl
100         << errormsg << std::endl
101         << "Unable to open file, given its name: " << fileName
102         << "and its open mode " << openMode2String(oMode) << std::endl;
103    StdString e = sstr.str();
104    throw CNetCdfException(e);
105  }
106
107  return status;
108}
109
110
111/*!
112This function opens a new netcdf file on parallel file system
113\param [in] fileName Name of the file
114\param [in] oMode open mode
115\param [in] comm MPI communicator
116\param [in] info MPI information
117\param [in/out] ncId id of the opened file
118\return Status code
119*/
120int CNetCdfInterface::openPar(const StdString& fileName, int oMode, MPI_Comm comm, MPI_Info info, int& ncId)
121{
122  #ifdef _usingEP
123  int status = xios::nc_open_par(fileName.c_str(), oMode, comm, to_mpi_info(MPI_INFO_NULL), &ncId);
124  #else
125  int status = xios::nc_open_par(fileName.c_str(), oMode, comm, MPI_INFO_NULL, &ncId);
126  #endif
127 
128  if (NC_NOERR != status)
129  {
130    StdString errormsg(nc_strerror(status));
131    StdStringStream sstr;
132    sstr << "Error when calling function nc_open_par(fileName.c_str(), oMode, comm, info, &ncId) " << std::endl
133         << errormsg << std::endl
134         << "Unable to open file on parallel file system, given its name: " << fileName
135         << "and its open mode " << openMode2String(oMode) << std::endl;
136    StdString e = sstr.str();
137    throw CNetCdfException(e);
138  }
139
140  return status;
141}
142
143/*!
144This function closes a netcdf file, given its id
145\param [in] ncId id of the opening netcdf file
146\return Status code
147*/
148int CNetCdfInterface::close(int ncId)
149{
150  int status = NC_NOERR;
151  #pragma omp critical (_netcdf)
152  {
153    info(200)<<"start nc_close"<<std::endl;
154    status = nc_close(ncId);
155    info(200)<<"end nc_close"<<std::endl;
156  }
157     
158  if (NC_NOERR != status)
159  {
160    StdString errormsg(nc_strerror(status));
161    StdStringStream sstr;
162    sstr << "Error when calling function nc_close(ncId)" << std::endl
163         << errormsg << std::endl
164         << "Unable to close file, given its id: " << ncId << std::endl;
165    StdString e = sstr.str();
166    throw CNetCdfException(e);
167  }
168
169  return status;
170}
171
172/*!
173This function put a netcdf file into define mode, given its id
174\param [in] ncId id of the opening netcdf file to be put into define mode
175\return Status code
176*/
177int CNetCdfInterface::reDef(int ncId)
178{
179  int status;
180  #pragma omp critical (_netcdf)
181  {
182    info(200)<<"start nc_reDef"<<std::endl;
183    status = nc_redef(ncId);
184    info(200)<<"end nc_reDef"<<std::endl;
185  }
186 
187  if (NC_NOERR != status)
188  {
189    StdString errormsg(nc_strerror(status));
190    StdStringStream sstr;
191    sstr << "Error when calling function nc_redef(ncId)" << std::endl
192      << errormsg << std::endl
193      << "Unable to put this file into define mode given its id: " << ncId << std::endl;
194    StdString e = sstr.str();
195    throw CNetCdfException(e);
196  }
197
198  return status;
199}
200
201/*!
202This function ends a netcdf file define mode, given its id
203\param [in] ncId id of the opening netcdf file to be put into define mode
204\return Status code
205*/
206int CNetCdfInterface::endDef(int ncId)
207{
208  int status;
209  #pragma omp critical (_netcdf)
210  {
211    info(200)<<"start nc_enddef"<<std::endl;
212    status = nc_enddef(ncId);
213    info(200)<<"end nc_enddef"<<std::endl;
214  }
215  if (NC_NOERR != status)
216  {
217    StdString errormsg(nc_strerror(status));
218    StdStringStream sstr;
219
220    sstr << "Error when calling function nc_enddef(ncId)" << std::endl
221         << errormsg << std::endl
222         << "Unable to end define mode of this file, given its id: " << ncId << std::endl;
223    StdString e = sstr.str();
224    throw CNetCdfException(e);
225  }
226
227  return status;
228}
229
230/*!
231This function makes a request to netcdf with ncid and group name then return ncid of the named group
232\param [in] ncid Groupd id (or File Id)
233\param [in] grpName Name of the desired group (or file)
234\param [in/out] grpId Group id if the group is found
235\return Status code
236*/
237int CNetCdfInterface::inqNcId(int ncid, const StdString& grpName, int& grpId)
238{
239  int status;
240  #pragma omp critical (_netcdf)
241  {
242    info(200)<<"start nc_inq_ncid"<<std::endl;
243    status = nc_inq_ncid(ncid, grpName.c_str(), &grpId);
244    info(200)<<"end nc_inq_ncid"<<std::endl;
245  }
246 
247  if (NC_NOERR != status)
248  {
249    StdString errormsg(nc_strerror(status));
250    StdStringStream sstr;
251
252    sstr << "Error when calling function nc_inq_ncid(ncid, grpName.c_str(), &grpId)" << std::endl
253         << errormsg << std::endl
254         << "Unable to get id of a group (File), given its name: " << grpName << std::endl;
255    StdString e = sstr.str();
256    throw CNetCdfException(e);
257  }
258
259  return status;
260}
261
262
263/*!
264This function makes a request to netcdf with ncid and variable name then return ncid of the named variable
265\param [in] ncid Groupd id (or File Id)
266\param [in] varName Name of the desired variable
267\param [in/out] varId Variable id if this variable is found
268\return Status code
269*/
270int CNetCdfInterface::inqVarId(int ncid, const StdString& varName, int& varId)
271{
272  int status;
273  #pragma omp critical (_netcdf)
274  {
275    info(200)<<"start nc_inq_varid"<<std::endl;
276    status = nc_inq_varid(ncid, varName.c_str(), &varId);
277    info(200)<<"end nc_inq_varid"<<std::endl;
278  }
279  if (NC_NOERR != status)
280  {
281    StdString errormsg(nc_strerror(status));
282    StdStringStream sstr;
283
284    sstr << "Error when calling function: nc_inq_varid(ncid, varName.c_str(), &varId)" << std::endl
285         << (errormsg) << std::endl
286         << "Unable to get id of variable with name: " << varName << std::endl;
287    StdString e = sstr.str();
288    throw CNetCdfException(e);
289  }
290
291  return status;
292}
293
294/*!
295This function makes a request to netcdf with a netCdf dimension name then return ncid of the named dimension
296\param [in] ncid Groupd id (or File Id)
297\param [in] dimName Name of the desired dimension
298\param [in/out] dimId Dimension id if this dimension is found
299\return Status code
300*/
301int CNetCdfInterface::inqDimId(int ncid, const StdString& dimName, int& dimId)
302{
303  int status;
304  #pragma omp critical (_netcdf)
305  {
306    info(200)<<"start nc_inq_dimid"<<std::endl;
307    status = nc_inq_dimid(ncid, dimName.c_str(), &dimId);
308    info(200)<<"end nc_inq_dimid"<<std::endl;
309  }
310 
311  if (NC_NOERR != status)
312  {
313    StdString errormsg(nc_strerror(status));
314    StdStringStream sstr;
315
316    sstr << "Error when calling function nc_inq_dimid(ncid, dimName.c_str(), &dimId)" << std::endl
317         << errormsg << std::endl
318         << "Unable to get id of dimension, given its name: " << dimName << std::endl;
319    StdString e = sstr.str();
320    throw CNetCdfException(e);
321  }
322
323  return status;
324}
325
326/*!
327This function queries the name of a variable given its id.
328\param [in] ncid Groupd id (or File Id)
329\param [in] varId Id of desired variable
330\param [out] varName name of desired variable
331\return Status code
332*/
333int CNetCdfInterface::inqVarName(int ncid, int varId, StdString& varName)
334{
335  char varNameBuff[NC_MAX_NAME + 1];
336  int status;
337  #pragma omp critical (_netcdf)
338  {
339    info(200)<<"start nc_inq_varname"<<std::endl;
340    status = nc_inq_varname(ncid, varId, varNameBuff);
341    info(200)<<"end nc_inq_varname"<<std::endl;
342  }
343  if (NC_NOERR != status)
344  {
345    StdString errormsg(nc_strerror(status));
346    StdStringStream sstr;
347
348    sstr << "Error when calling function nc_inq_varname(ncid, varId, varNameBuff)" << std::endl
349         << errormsg << std::endl
350         << "Unable to get variable name: "<< varName << " given its id: " << varId << std::endl;
351    StdString e = sstr.str();
352    throw CNetCdfException(e);
353  }
354  varName = varNameBuff;
355  return status;
356}
357
358/*!
359This function makes a request to netcdf with a netCdf dimension name then return ncid of the named dimension
360\param [in] ncid Groupd id (or File Id)
361\param [in/out] dimId Dimension id if this dimension is found
362\return Status code
363*/
364int CNetCdfInterface::inqUnLimDim(int ncid, int& dimId)
365{
366  int status;
367  #pragma omp critical (_netcdf)
368  {
369    info(200)<<"start nc_inq_unlimdim"<<std::endl;
370    status = nc_inq_unlimdim(ncid, &dimId);
371    info(200)<<"end nc_inq_unlimdim"<<std::endl;
372  }
373  if (NC_NOERR != status)
374  {
375    StdString errormsg(nc_strerror(status));
376    StdStringStream sstr;
377
378    sstr << "Error when calling function nc_inq_dimid" << std::endl
379      << errormsg << std::endl
380      << "Unable to get id of unlimited dimension " << std::endl;
381    StdString e = sstr.str();
382    throw CNetCdfException(e);
383 }
384
385  return status;
386}
387
388/*!
389This function makes a request to netcdf, returns name of a dimension, given its id
390\param [in] ncid Groupd id (or File Id)
391\param [in] dimId Id of desired dimension
392\param [out] dimName Name of desired dimension
393\return Status code
394*/
395int CNetCdfInterface::inqDimName(int ncid, int dimId, StdString& dimName)
396{
397  char fullNameIn[NC_MAX_NAME + 1];
398  int status;
399  #pragma omp critical (_netcdf)
400  {
401    info(200)<<"start nc_inq_dimname"<<std::endl;
402    status = nc_inq_dimname(ncid, dimId, fullNameIn);
403    info(200)<<"end nc_inq_dimname"<<std::endl;
404  }
405  if (NC_NOERR != status)
406  {
407    StdString errormsg(nc_strerror(status));
408    StdStringStream sstr;
409
410    sstr << "Error when calling function nc_inq_dimname(ncid, dimId, fullNameIn)" << std::endl
411         << errormsg << std::endl
412         << "Unable to get dimension name: " << dimName << " given its id: " << dimId << std::endl;
413    StdString e = sstr.str();
414    throw CNetCdfException(e);
415  }
416  dimName = StdString(fullNameIn);
417  return status;
418}
419
420/*!
421This function makes a request to netcdf, returns length of a dimension, given its id
422\param [in] ncid Groupd id (or File Id)
423\param [in] dimId Id of desired dimension
424\param [in/out] dimLen Length of desired dimension
425\return Status code
426*/
427int CNetCdfInterface::inqDimLen(int ncid, int dimId, StdSize& dimLen)
428{
429  int status;
430  #pragma omp critical (_netcdf)
431  {
432    info(200)<<"start nc_inq_dimlen"<<std::endl;
433    status = nc_inq_dimlen(ncid, dimId, &dimLen);
434    info(200)<<"end nc_inq_dimlen"<<std::endl;
435  }
436  if (NC_NOERR != status)
437  {
438    StdString errormsg(nc_strerror(status));
439    StdStringStream sstr;
440
441    sstr << "Error when calling function nc_inq_dimlen(ncid, dimId, &dimLen)" << std::endl
442         << errormsg << std::endl
443         << "Unable to get dimension length given its id: " << dimId << std::endl;
444    StdString e = sstr.str();
445    throw CNetCdfException(e);
446  }
447
448  return status;
449}
450
451/*!
452This function makes a request to netcdf, returns number of dimensions of a variable, given its id
453\param [in] ncid Groupd id (or File Id)
454\param [in] varId Id of variable
455\param [in/out] ndims number of dimension of the variable
456\return Status code
457*/
458int CNetCdfInterface::inqVarNDims(int ncid, int varId, int& nDims)
459{
460  int status;
461  #pragma omp critical (_netcdf)
462  {
463    info(200)<<"start nc_inq_varndims"<<std::endl;
464    status = nc_inq_varndims(ncid, varId, &nDims);
465    info(200)<<"end nc_inq_varndims"<<std::endl;
466  }
467  if (NC_NOERR != status)
468  {
469    StdString errormsg(nc_strerror(status));
470    StdStringStream sstr;
471
472    sstr << "Error when calling function nc_inq_varndims(ncid, varId, &nDims)" << std::endl
473         << errormsg << std::endl
474         << "Unable to get the number of dimension of variable with Id: " << varId << std::endl;
475    StdString e = sstr.str();
476    throw CNetCdfException(e);
477  }
478
479  return status;
480}
481
482/*!
483This function makes a request to netcdf, returns a list of dimension ID describing the shape of the variable, given its id
484\param [in] ncid Groupd id (or File Id)
485\param [in] varId Id of variable
486\param [in/out] dimIds list of dimension of the variable
487\return Status code
488*/
489int CNetCdfInterface::inqVarDimId(int ncid, int varId, int* dimIds)
490{
491  int status;
492  #pragma omp critical (_netcdf)
493  {
494    info(200)<<"start nc_inq_vardimid"<<std::endl;
495    status = nc_inq_vardimid(ncid, varId, dimIds);
496    info(200)<<"end nc_inq_vardimid"<<std::endl;
497  }
498  if (NC_NOERR != status)
499  {
500    StdString errormsg(nc_strerror(status));
501    StdStringStream sstr;
502
503    sstr << "Error when calling function nc_inq_vardimid(ncid, varId, dimIds)" << std::endl
504         << errormsg << std::endl
505         << "Unable to get list of dimension id of the variable with id " << varId << std::endl;
506    StdString e = sstr.str();
507    throw CNetCdfException(e);
508  }
509
510  return status;
511}
512
513/*!
514This function makes a request to netcdf, to find all dimension in a group
515\param [in] ncid Groupd id (or File Id)
516\param [in/out] nDims number of list of dimension
517\param [in/out] dimIds list of dimension in a group or any of its parent
518\param [in] includeParents number of parents
519\return Status code
520*/
521int CNetCdfInterface::inqDimIds(int ncid, int& nDims, int* dimIds, int includeParents)
522{
523  int status;
524  #pragma omp critical (_netcdf)
525  {
526    info(200)<<"start nc_inq_dimids"<<std::endl;
527    status = nc_inq_dimids(ncid, &nDims, dimIds, includeParents);
528    info(200)<<"end nc_inq_dimids"<<std::endl;
529  }
530  if (NC_NOERR != status)
531  {
532    StdString errormsg(nc_strerror(status));
533    StdStringStream sstr;
534
535    sstr << "Error when calling function nc_inq_dimids(ncid, &nDims, dimIds, includeParents)" << std::endl;
536    sstr << errormsg << std::endl;
537    sstr << "Unable to retrieve number of dimension in the group with id: " << ncid << std::endl;
538    sstr << "With number of Parents " << includeParents << std::endl;
539    StdString e = sstr.str();
540    throw CNetCdfException(e);
541  }
542
543  return status;
544}
545
546/*!
547This function queries the full name of a group given its id.
548\param [in] ncid Groupd id (or File Id)
549\param [in/out] grpFullName the full name of the group
550\return Status code
551*/
552int CNetCdfInterface::inqGrpFullName(int ncid, StdString& grpFullName)
553{
554  StdSize strlen = 0;
555  std::vector<char> buff;
556  int status;
557  #pragma omp critical (_netcdf)
558  {
559    info(200)<<"start nc_inq_grpname_full"<<std::endl;
560    status = nc_inq_grpname_full(ncid, &strlen, NULL);
561    info(200)<<"end nc_inq_grpname_full"<<std::endl;
562 
563    if (NC_NOERR == status)
564    {
565      buff.resize(strlen + 1);
566      status = nc_inq_grpname_full(ncid, NULL, &buff[0]);
567    }
568    info(200)<<"start nc_inq_grpname_full"<<std::endl;
569  }
570
571  if (NC_NOERR != status)
572  {
573    StdString errormsg(nc_strerror(status));
574    StdStringStream sstr;
575
576    sstr << "Error when calling function nc_inq_grpname_full(ncid, &strlen, &buff[0])" << std::endl
577         << errormsg << std::endl
578         << "Unable to get the full group name given its id: " << ncid << std::endl;
579    StdString e = sstr.str();
580    throw CNetCdfException(e);
581  }
582
583  grpFullName.assign(buff.begin(), buff.end());
584
585  return status;
586}
587
588/*!
589This function queries the list of group ids given a location id.
590\param [in] ncid Groupd id (or File Id)
591\param [in/out] numgrps number of groups
592\param [in/out] ncids list of group ids
593\return Status code
594*/
595int CNetCdfInterface::inqGrpIds(int ncid, int& numgrps, int* ncids)
596{
597  int status;
598  #pragma omp critical (_netcdf)
599  {
600    info(200)<<"start nc_inq_grps"<<std::endl;
601    status = nc_inq_grps(ncid, &numgrps, ncids);
602    info(200)<<"end nc_inq_grps"<<std::endl;
603  }
604  if (NC_NOERR != status)
605  {
606    StdString errormsg(nc_strerror(status));
607    StdStringStream sstr;
608
609    sstr << "Error when calling function nc_inq_grps(ncid, &numgrps, ncids)" << std::endl;
610    sstr << errormsg << std::endl;
611    sstr << "Unable to retrieve the list of groups for location id: " << ncid << std::endl;
612    StdString e = sstr.str();
613    throw CNetCdfException(e);
614  }
615
616  return status;
617}
618
619/*!
620This function queries the list of variable ids given a location id.
621\param [in] ncid Groupd id (or File Id)
622\param [in/out] nvars number of variables
623\param [in/out] varids list of variable ids
624\return Status code
625*/
626int CNetCdfInterface::inqVarIds(int ncid, int& nvars, int* varids)
627{
628  int status;
629  #pragma omp critical (_netcdf)
630  {
631    info(200)<<"start nc_inq_varids"<<std::endl;
632    status = nc_inq_varids(ncid, &nvars, varids);
633    info(200)<<"end nc_inq_varids"<<std::endl;
634  }
635  if (NC_NOERR != status)
636  {
637    StdString errormsg(nc_strerror(status));
638    StdStringStream sstr;
639
640    sstr << "Error when calling function nc_inq_varids(ncid, &nvars, varids)" << std::endl;
641    sstr << errormsg << std::endl;
642    sstr << "Unable to retrieve the list of variables for location id: " << ncid << std::endl;
643    StdString e = sstr.str();
644    throw CNetCdfException(e);
645  }
646
647  return status;
648}
649
650/*!
651This function queries the type and the size of an attribute given its name and the id of the variable to which it is attached.
652\param [in] ncid Groupd id (or File Id)
653\param [in] varid the id of the variable to which the attribute is attached
654\param [in] name the name of the attribute
655\param [out] type the type of the attribute
656\param [out] len the size of the attribute
657\return Status code
658*/
659int CNetCdfInterface::inqAtt(int ncid, int varid, const StdString& name, nc_type& type, size_t& len)
660{
661  int status;
662  #pragma omp critical (_netcdf)
663  {
664    info(200)<<"start nc_inq_att"<<std::endl;
665    status = nc_inq_att(ncid, varid, name.c_str(), &type, &len);
666    info(200)<<"end nc_inq_att"<<std::endl;
667  }
668 
669  if (NC_NOERR != status)
670  {
671    StdString errormsg(nc_strerror(status));
672    StdStringStream sstr;
673
674    sstr << "Error when calling function nc_inq_att(ncid, varid, name.c_str(), &type, &len)" << std::endl;
675    sstr << errormsg << std::endl;
676    sstr << "Unable to query the attribute information given its name: " << name << " and its variable id:" << varid << std::endl;
677    StdString e = sstr.str();
678    throw CNetCdfException(e);
679  }
680
681  return status;
682}
683
684/*!
685This function queries the number of global attributes given a location id.
686\param [in] ncid Groupd id (or File Id)
687\param [out] ngatts the number of global attributes
688\return Status code
689*/
690int CNetCdfInterface::inqNAtts(int ncid, int& ngatts)
691{
692  int status;
693  #pragma omp critical (_netcdf)
694  {
695    info(200)<<"start nc_inq_natts"<<std::endl;
696    status = nc_inq_natts(ncid, &ngatts);
697    info(200)<<"end nc_inq_natts"<<std::endl;
698  }
699  if (NC_NOERR != status)
700  {
701    StdString errormsg(nc_strerror(status));
702    StdStringStream sstr;
703
704    sstr << "Error when calling function nc_inq_natts(ncid, &ngatts)" << std::endl;
705    sstr << errormsg << std::endl;
706    sstr << "Unable to query the number of global attributes given the location id:" << ncid << std::endl;
707    StdString e = sstr.str();
708    throw CNetCdfException(e);
709  }
710
711  return status;
712}
713
714/*!
715This function queries the number of global attributes given a location id and a variable id.
716\param [in] ncid Groupd id (or File Id)
717\param [in] varid the id of the variable
718\param [out] natts the number of global attributes
719\return Status code
720*/
721int CNetCdfInterface::inqVarNAtts(int ncid, int varid, int& natts)
722{
723  int status;
724  #pragma omp critical (_netcdf)
725  {
726    info(200)<<"start nc_inq_varnatts"<<std::endl;
727    status = nc_inq_varnatts(ncid, varid, &natts);
728    info(200)<<"end nc_inq_varnatts"<<std::endl;
729  }
730  if (NC_NOERR != status)
731  {
732    StdString errormsg(nc_strerror(status));
733    StdStringStream sstr;
734
735    sstr << "Error when calling function nc_inq_varnatts(ncid, varid, &natts)" << std::endl;
736    sstr << errormsg << std::endl;
737    sstr << "Unable to query the number of attributes given the location id:" << ncid << " and the variable id:" << varid << std::endl;
738    StdString e = sstr.str();
739    throw CNetCdfException(e);
740  }
741
742  return status;
743}
744
745
746//! Query the name of an attribute given a location id, a variable id and the attribute number
747int CNetCdfInterface::inqAttName(int ncid, int varid, int attnum, StdString& name)
748{
749  std::vector<char> attName(NC_MAX_NAME + 1,' ');
750  int status;
751  #pragma omp critical (_netcdf)
752  {
753    info(200)<<"start nc_inq_attname"<<std::endl;
754    status = nc_inq_attname(ncid, varid, attnum, &attName[0]);
755    info(200)<<"end nc_inq_attname"<<std::endl;
756  }
757  if (NC_NOERR != status)
758  {
759    StdString errormsg(nc_strerror(status));
760    StdStringStream sstr;
761
762    sstr << "Error when calling function nc_inq_attname(ncid, varid, attnum, attName)" << std::endl;
763    sstr << errormsg << std::endl;
764    sstr << "Unable to query the name: " << name << " of attribute " << attnum << " given the location id:" << ncid << " and the variable id:" << varid << std::endl;
765    StdString e = sstr.str();
766    throw CNetCdfException(e);
767  }
768
769  int nameSize = 0;
770  while ((nameSize < NC_MAX_NAME) && (' ' != attName[nameSize] )) ++nameSize;
771  name.resize(nameSize);
772//  for (int idx = 0; idx < nameSize; ++idx) name.at(idx) = attName[idx];
773  std::copy(&attName[0], &attName[nameSize-1], name.begin());
774
775  return status;
776}
777
778/*!
779This function makes a request to netcdf with a id of a prent groupd and then return id of the created group, given its name
780\param [in] parentNcid Id of parent groupd(or File Id)
781\param [in] grpName Name of the desired group
782\param [in/out] grpId Group id if this group is created sucessfully
783\return Status code
784*/
785int CNetCdfInterface::defGrp(int parentNcid, const StdString& grpName, int& grpId)
786{
787  int status;
788  #pragma omp critical (_netcdf)
789  {
790    info(200)<<"start nc_def_grp"<<std::endl;
791    status = nc_def_grp(parentNcid, grpName.c_str(), &grpId);
792    info(200)<<"end nc_def_grp"<<std::endl;
793  }
794  if (NC_NOERR != status)
795  {
796    StdString errormsg(nc_strerror(status));
797    StdStringStream sstr;
798
799    sstr << "Error when calling function nc_def_grp(parentNcid, grpName.c_str(), &grpId)" << std::endl;
800    sstr << errormsg << std::endl;
801    sstr << "Unable to create group Id, given its name: " << grpName << std::endl;
802    StdString e = sstr.str();
803    throw CNetCdfException(e);
804  }
805
806  return status;
807}
808
809/*!
810This function makes a request to netcdf, add a new dimension to an open netcdf in define mode
811\param [in] ncid Id of groupd(or File Id)
812\param [in] dimName Name of the desired dimension
813\param [in/out] grpId Group id if this group is created sucessfully
814\return Status code
815*/
816int CNetCdfInterface::defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId)
817{
818  int status;
819  #pragma omp critical (_netcdf)
820  {
821    info(200)<<"start nc_def_dim"<<std::endl;
822    status = nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId);
823    info(200)<<"end nc_def_dim"<<std::endl;
824  }
825  if (NC_NOERR != status)
826  {
827    StdString errormsg(nc_strerror(status));
828    StdStringStream sstr;
829
830    sstr << "Error when calling function nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId)" << std::endl;
831    sstr << errormsg << std::endl;
832    sstr << "Unable to create dimension with name: " << dimName
833         << " and with length " << dimLen << std::endl;
834    StdString e = sstr.str();
835    throw CNetCdfException(e);
836  }
837
838  return status;
839}
840
841/*!
842This function makes a request to netcdf with its id, to add a new variable to an open netCdf in define mode,
843return a variable id, given its name, type, the number of dimensions and list of dimension id
844\param [in] ncid Id of groupd(or File Id)
845\param [in] varName Name of the desired dimension
846\param [in] xtypes One of the set of predefined netCDF data types
847\param [in] nDims Number of dimension for the variable
848\param [in] dimIds List of ndims dimension ids corresponding to the variable dimensions
849\param [in/out] varId Variable id if it is added sucessfully
850\return Status code
851*/
852int CNetCdfInterface::defVar(int ncid, const StdString& varName, nc_type xtype,
853                             int nDims, const int dimIds[], int& varId)
854{
855  int status;
856  #pragma omp critical (_netcdf)
857  {
858    info(200)<<"start nc_def_var"<<std::endl;
859    status = nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId);
860    info(200)<<"end nc_def_var"<<std::endl;
861  }
862  if (NC_NOERR != status)
863  {
864    StdString errormsg(nc_strerror(status));
865    StdStringStream sstr;
866
867    sstr << "Error when calling function  nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId)" << std::endl;
868    sstr << errormsg << std::endl;
869    sstr << "Unable to add a new variable with name: " << varName
870         << " with type " << xtype
871         << " and number of dimension " << nDims << std::endl;
872    StdString e = sstr.str();
873    throw CNetCdfException(e);
874  }
875
876  return status;
877}
878
879/*!
880This function makes a request to netcdf with a ncid, to set the chunking size of a variable,
881given variable id and type of storage
882\param [in] ncid Id groupd(or File Id)
883\param [in] varId Id of the variable
884\param [in] storage Type of storage (It can be: NC_CONTIGUOUS, NC_CHUNKED)
885\param [in/out] chunkSize array list of chunk sizes
886\return Status code
887*/
888int CNetCdfInterface::defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[])
889{
890  int status;
891  #pragma omp critical (_netcdf)
892  {
893    info(200)<<"start nc_def_var_chunking"<<std::endl;
894    status = nc_def_var_chunking(ncid, varId, storage, chunkSize);
895    info(200)<<"end nc_def_var_chunking"<<std::endl;
896  }
897  if (NC_NOERR != status)
898  {
899    StdString errormsg(nc_strerror(status));
900    StdStringStream sstr;
901
902    sstr << "Error when calling function nc_def_var_chunking(ncid, varId, storage, chunkSize)" << std::endl;
903    sstr << errormsg << std::endl;
904    sstr << "Unable to set chunk size of the variable with id: " << varId
905      << " and storage type " << storage << std::endl;
906    StdString e = sstr.str();
907    throw CNetCdfException(e);
908  }
909
910  return status;
911}
912
913/*!
914This function sets the compression level to the specified variable
915\param [in] ncid Groud id (or file id)
916\param [in] varId Id of the variable
917\param [in] compressionLevel The compression level from 0 to 9 (0 disables the compression, 9 is the higher compression)
918\return Status code
919*/
920int CNetCdfInterface::defVarDeflate(int ncid, int varId, int compressionLevel)
921{
922 
923  if (compressionLevel == 0) return NC_NOERR ;
924  int status;
925  #pragma omp critical (_netcdf)
926  {
927    info(200)<<"start nc_def_var_deflate"<<std::endl;
928    status = nc_def_var_deflate(ncid, varId, (compressionLevel > 0), (compressionLevel > 0), compressionLevel);
929    info(200)<<"end nc_def_var_deflate"<<std::endl;
930  }
931  if (NC_NOERR != status)
932  {
933    StdString errormsg(nc_strerror(status));
934    StdStringStream sstr;
935
936    sstr << "Error when calling function nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl;
937    sstr << errormsg << std::endl;
938    sstr << "Unable to set the compression level of the variable with id: " << varId
939         << " and compression level: " << compressionLevel << std::endl;
940    StdString e = sstr.str();
941    throw CNetCdfException(e);
942  }
943
944  return status;
945}
946
947/*!
948Set or unset the fill mode for a NetCDF file specified by its file id.
949\param [in] ncid File id
950\param [in] fill Define whether the fill mode should be enabled or not
951\return Status code
952*/
953int CNetCdfInterface::setFill(int ncid, bool fill)
954{
955  int old_fill_mode;
956  int status;
957  #pragma omp critical (_netcdf)
958  {
959    info(200)<<"start nc_set_fill"<<std::endl;
960    status = nc_set_fill(ncid, fill ? NC_FILL: NC_NOFILL, &old_fill_mode);
961    info(200)<<"end nc_set_fill"<<std::endl;
962  }
963  if (NC_NOERR != status)
964  {
965    StdString errormsg(nc_strerror(status));
966    StdStringStream sstr;
967
968    sstr << "Error when calling function nc_set_fill(ncid, fill ? NC_FILL: NC_NOFILL, &old_fill_mode)" << std::endl;
969    sstr << errormsg << std::endl;
970    sstr << "Unable to set the fill mode to: " << (fill ? "NC_FILL": "NC_NOFILL") << std::endl;
971    StdString e = sstr.str();
972    throw CNetCdfException(e);
973  }
974
975  return status;
976}
977
978/*!
979This function makes a request to netcdf with a ncid, to set the fill parameters for a variable,
980given variable id and type of fill
981\param [in] ncid Id groupd(or File Id)
982\param [in] varId Id of the variable
983\param [in] noFill turn on/off nofill mode on a variable
984\param [in/out] fillValue
985\return Status code
986*/
987int CNetCdfInterface::defVarFill(int ncid, int varId, int noFill, void* fillValue)
988{
989  int status;
990  #pragma omp critical (_netcdf)
991  {
992    info(200)<<"start nc_def_var_fill"<<std::endl;
993    status = nc_def_var_fill(ncid, varId, noFill, fillValue);
994    info(200)<<"end nc_def_var_fill"<<std::endl;
995  }
996  if (NC_NOERR != status)
997  {
998    StdString errormsg(nc_strerror(status));
999    StdStringStream sstr;
1000
1001    sstr << "Error when calling function nc_def_var_fill(ncid, varId, noFill, fillValue)" << std::endl;
1002    sstr << errormsg << std::endl;
1003    sstr << "Unable to set fill parameters of the variable with id: " << varId
1004      << " and fill option " << noFill << std::endl;
1005    StdString e = sstr.str();
1006    throw CNetCdfException(e);
1007  }
1008
1009  return status;
1010}
1011
1012/*!
1013This function makes a request to netcdf with a ncid, to change the way read/write operations are performed
1014collectively or independently on the variable.
1015\param [in] ncid Id groupd(or File Id)
1016\param [in] varId Id of the variable
1017\param [in] noFill turn on/off nofill mode on a variable
1018\param [in/out] fillValue
1019\return Status code
1020*/
1021int CNetCdfInterface::varParAccess(int ncid, int varId, int access)
1022{
1023  int status;
1024  #pragma omp critical (_netcdf)
1025  {
1026    info(200)<<"start nc_var_par_access"<<std::endl;
1027    status = nc_var_par_access(ncid, varId, access);
1028    info(200)<<"end nc_var_par_access"<<std::endl;
1029  }
1030  if (NC_NOERR != status)
1031  {
1032    StdString errormsg(nc_strerror(status));
1033    StdStringStream sstr;
1034
1035    sstr << "Error when calling function nc_var_par_access(ncid, varId, access)" << std::endl;
1036    sstr << errormsg << std::endl;
1037    sstr << "Unable to change read/write option of the variable with id: " << varId << std::endl;
1038    StdString e = sstr.str();
1039    throw CNetCdfException(e);
1040  }
1041
1042  return status;
1043}
1044
1045/*!
1046This function makes a synchronisation of the disk copy of a netCDF dataset.
1047\param [in] ncid Id groupd(or File Id)
1048\return Status code
1049*/
1050int CNetCdfInterface::sync(int ncid)
1051{
1052  int status;
1053  #pragma omp critical (_netcdf)
1054  {
1055    info(200)<<"start nc_sync"<<std::endl;
1056    status = nc_sync(ncid);
1057    info(200)<<"end nc_sync"<<std::endl;
1058  }
1059  if (NC_NOERR != status)
1060  {
1061    StdString errormsg(nc_strerror(status));
1062    StdStringStream sstr;
1063
1064    sstr << "Error when calling function nc_sync(ncid)" << std::endl;
1065    sstr << errormsg << std::endl;
1066    sstr << "Unable to make a synchronization of a netCDF file with id: " << ncid << std::endl;
1067    StdString e = sstr.str();
1068    throw CNetCdfException(e);
1069  }
1070
1071  return status;
1072}
1073
1074// Some specializations of getAttributeType
1075template<>
1076int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, double* data)
1077{
1078  int status;
1079  #pragma omp critical (_netcdf)
1080  {
1081    info(200)<<"start nc_get_att_double"<<std::endl;
1082    status = nc_get_att_double(ncid, varid, attrName, data);
1083    info(200)<<"end nc_get_att_double"<<std::endl;
1084  }
1085  return status;
1086}
1087
1088template<>
1089int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, float* data)
1090{
1091  int status;
1092  #pragma omp critical (_netcdf)
1093  {
1094    info(200)<<"start nc_get_att_float"<<std::endl;
1095    status = nc_get_att_float(ncid, varid, attrName, data);
1096    info(200)<<"end nc_get_att_float"<<std::endl;
1097  }
1098  return status;
1099}
1100
1101template<>
1102int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, int* data)
1103{
1104  int status;
1105  #pragma omp critical (_netcdf)
1106  {
1107    info(200)<<"start nc_get_att_int"<<std::endl;
1108    status = nc_get_att_int(ncid, varid, attrName, data);
1109    info(200)<<"end nc_get_att_int"<<std::endl;
1110  }
1111  return status; 
1112}
1113
1114template<>
1115int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, long* data)
1116{
1117  int status;
1118  #pragma omp critical (_netcdf)
1119  {
1120    info(200)<<"start nc_get_att_long"<<std::endl;
1121    status = nc_get_att_long(ncid, varid, attrName, data);
1122    info(200)<<"end nc_get_att_long"<<std::endl;
1123  }
1124  return status;
1125}
1126
1127template<>
1128int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, short* data)
1129{
1130  int status;
1131  #pragma omp critical (_netcdf)
1132  {
1133    info(200)<<"start nc_get_att_short"<<std::endl;
1134    status = nc_get_att_short(ncid, varid, attrName, data);
1135    info(200)<<"end nc_get_att_short"<<std::endl;
1136  }
1137  return status;
1138}
1139
1140template<>
1141int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, char* data)
1142{
1143  int status;
1144  #pragma omp critical (_netcdf)
1145  {
1146    info(200)<<"start nc_get_att_text"<<std::endl;
1147    status = nc_get_att_text(ncid, varid, attrName, data);
1148    info(200)<<"end nc_get_att_text"<<std::endl;
1149  }
1150  return status;
1151}
1152
1153// Some specializations of putAttributeType
1154template<>
1155int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
1156                                   StdSize numVal, const double* data)
1157{
1158  int status;
1159  #pragma omp critical (_netcdf)
1160  {
1161    info(200)<<"start nc_put_att_double"<<std::endl;
1162    status = nc_put_att_double(ncid, varid, attrName, NC_DOUBLE, numVal, data);
1163    info(200)<<"end nc_put_att_double"<<std::endl;
1164  }
1165  return status;
1166}
1167
1168template<>
1169int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
1170                                   StdSize numVal, const float* data)
1171{
1172  int status;
1173  #pragma omp critical (_netcdf)
1174  {
1175    info(200)<<"start nc_put_att_float"<<std::endl;
1176    status = nc_put_att_float(ncid, varid, attrName, NC_FLOAT, numVal, data);
1177    info(200)<<"end nc_put_att_float"<<std::endl;
1178  }
1179  return status;
1180}
1181
1182template<>
1183int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
1184                                   StdSize numVal, const int* data)
1185{
1186  int status;
1187  #pragma omp critical (_netcdf)
1188  {
1189    info(200)<<"start nc_put_att_int"<<std::endl;
1190    status = nc_put_att_int(ncid, varid, attrName, NC_INT, numVal, data);
1191    info(200)<<"end nc_put_att_int"<<std::endl;
1192  }
1193  return status;
1194}
1195
1196template<>
1197int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
1198                                   StdSize numVal, const long* data)
1199{
1200  int status;
1201  #pragma omp critical (_netcdf)
1202  {
1203    info(200)<<"start nc_put_att_long"<<std::endl;
1204    status = nc_put_att_long(ncid, varid, attrName, NC_LONG, numVal, data);
1205    info(200)<<"end nc_put_att_long"<<std::endl;
1206  }
1207  return status;
1208}
1209
1210template<>
1211int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
1212                                   StdSize numVal, const short* data)
1213{
1214  int status;
1215  #pragma omp critical (_netcdf)
1216  {
1217    info(200)<<"start nc_put_att_short"<<std::endl;
1218    status = nc_put_att_short(ncid, varid, attrName, NC_SHORT, numVal, data);
1219    info(200)<<"end nc_put_att_short"<<std::endl;
1220  }
1221  return status;
1222}
1223
1224template<>
1225int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName,
1226                                   StdSize numVal, const char* data)
1227{
1228  int status;
1229  #pragma omp critical (_netcdf)
1230  {
1231    info(200)<<"start nc_put_att_text"<<std::endl;
1232    status = nc_put_att_text(ncid, varid, attrName, numVal, data);
1233    info(200)<<"end nc_put_att_text"<<std::endl;
1234  }
1235  return status;
1236}
1237
1238// Some specializations of getVariableType
1239template<>
1240int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, double* data)
1241{
1242  int status;
1243  #pragma omp critical (_netcdf)
1244  {
1245    info(200)<<"start nc_get_vara_double"<<std::endl;
1246    status = nc_get_vara_double(ncid, varid, start, count, data);
1247    info(200)<<"end nc_get_vara_double"<<std::endl;
1248  }
1249  return status;
1250}
1251
1252template<>
1253int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, float* data)
1254{
1255  int status;
1256  #pragma omp critical (_netcdf)
1257  {
1258    info(200)<<"start nc_get_vara_float"<<std::endl;
1259    status = nc_get_vara_float(ncid, varid, start, count, data);
1260    info(200)<<"end nc_get_vara_float"<<std::endl;
1261  }
1262  return status; 
1263}
1264
1265template<>
1266int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, int* data)
1267{
1268  int status;
1269  #pragma omp critical (_netcdf)
1270  {
1271    info(200)<<"start nc_get_vara_int"<<std::endl;
1272    status = nc_get_vara_int(ncid, varid, start, count, data);
1273    info(200)<<"end nc_get_vara_int"<<std::endl;
1274  }
1275  return status; 
1276}
1277
1278template<>
1279int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, char* data)
1280{
1281  int status;
1282  #pragma omp critical (_netcdf)
1283  {
1284    info(200)<<"start nc_get_vara_text"<<std::endl;
1285    status = nc_get_vara_text(ncid, varid, start, count, data);
1286    info(200)<<"end nc_get_vara_text"<<std::endl;
1287  }
1288  return status;
1289}
1290
1291// Some specializations of putVariableType
1292template<>
1293int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const double* data)
1294{
1295  int status;
1296  #pragma omp critical (_netcdf)
1297  {
1298    info(200)<<"start nc_put_vara_double"<<std::endl;
1299    status = nc_put_vara_double(ncid, varid, start, count, data);
1300    info(200)<<"end nc_put_vara_double"<<std::endl;
1301  }
1302  return status;
1303}
1304
1305template<>
1306int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const float* data)
1307{
1308  int status;
1309  #pragma omp critical (_netcdf)
1310  {
1311    info(200)<<"start nc_put_vara_float"<<std::endl;
1312    status = nc_put_vara_float(ncid, varid, start, count, data);
1313    info(200)<<"end nc_put_vara_float"<<std::endl;
1314  }
1315  return status;
1316}
1317
1318template<>
1319int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const int* data)
1320{
1321  int status;
1322  #pragma omp critical (_netcdf)
1323  {
1324    info(200)<<"start nc_put_vara_int"<<std::endl;
1325    status = nc_put_vara_int(ncid, varid, start, count, data);
1326    info(200)<<"end nc_put_vara_int"<<std::endl;
1327  }
1328  return status;
1329}
1330
1331template<>
1332int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const char* data)
1333{
1334  int status;
1335  #pragma omp critical (_netcdf)
1336  {
1337    info(200)<<"start nc_put_vara_text"<<std::endl;
1338    status = nc_put_vara_text(ncid, varid, start, count, data);
1339    info(200)<<"end nc_put_vara_text"<<std::endl;
1340  }
1341  return status;
1342}
1343
1344 /*!
1345 This function verifies an existence of a variable by using its name.
1346 Be careful, althoug false means variable doens't exist, it could show that netCDF file doesn't either
1347 \param [in] ncid Id of groupd(or File Id)
1348 \param [in] attrName Name of the variable
1349 \return Existence of variable
1350 */
1351bool CNetCdfInterface::isVarExisted(int ncId, const StdString& varName)
1352{
1353   int varId = 0;
1354   int status;
1355   #pragma omp critical (_netcdf)
1356   {
1357     info(200)<<"start isVarExisted"<<std::endl;
1358     status = nc_inq_varid(ncId, varName.c_str(), &varId);
1359     info(200)<<"end isVarExisted"<<std::endl;
1360   }
1361   return (NC_NOERR == status);
1362}
1363
1364bool CNetCdfInterface::isDimExisted(int ncId, const StdString& dimName)
1365{
1366   int dimId = 0;
1367   int status;
1368   #pragma omp critical (_netcdf)
1369   {
1370     info(200)<<"start isDimExisted"<<std::endl;
1371     status = nc_inq_dimid(ncId, dimName.c_str(), &dimId);
1372     info(200)<<"end isDimExisted"<<std::endl;
1373   }
1374   return (NC_NOERR == status);
1375}
1376
1377StdString CNetCdfInterface::openMode2String(int oMode)
1378{
1379  StdString modeMes;
1380  switch (oMode)
1381  {
1382  case NC_NOWRITE:
1383    modeMes = StdString("NC_NOWRITE: Opening netCDF file with read-only access with buffering and caching access");
1384    break;
1385  case NC_SHARE:
1386    modeMes = StdString("NC_SHARE: Several processes can read the file concurrently");
1387    break;
1388  case NC_WRITE:
1389    modeMes = StdString("NC_WRITE: NetCDF file is readable and writable");
1390    break;
1391  default:
1392    modeMes = StdString("In the composed opening mode");
1393    break;
1394  }
1395  return modeMes;
1396}
1397
1398StdString CNetCdfInterface::creationMode2String(int cMode)
1399{
1400  StdString modeMes;
1401  switch (cMode)
1402  {
1403  case NC_NOCLOBBER:
1404    modeMes = StdString("NC_NOCLOBBER: Not overwrite an exisiting netCDF file ");
1405    break;
1406  case NC_SHARE:
1407    modeMes = StdString("NC_SHARE: Several processes can read from and write into the file concurrently");
1408    break;
1409  case NC_64BIT_OFFSET:
1410    modeMes = StdString("NC_64BIT_OFFSET: NetCDF file is 64-bit offset");
1411    break;
1412  case NC_NETCDF4:
1413    modeMes = StdString("NC_NETCDF4: NetCDF file is HDF5/NetCDF-4");
1414    break;
1415  case NC_CLASSIC_MODEL:
1416    modeMes = StdString("NC_CLASSIC_MODEL: NetCDF file is classical model");
1417    break;
1418  default:
1419    modeMes = StdString("In the composed creation mode");
1420    break;
1421  }
1422  return modeMes;
1423}
1424
1425}
Note: See TracBrowser for help on using the repository browser.