File: tst_failure.cpp

package info (click to toggle)
netcdf-cxx-legacy 4.2-13
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,684 kB
  • sloc: sh: 10,521; cpp: 3,134; makefile: 105
file content (47 lines) | stat: -rw-r--r-- 1,295 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*********************************************************************
 * Copyright 2006, UCAR/Unidata See COPYRIGHT file for copying and
 * redistribution conditions.
 * 
 * This runs the C++ tests for netCDF to test for failure.
 * 
 * $Id: tst_failure.cpp,v 1.2 2007/05/14 14:10:59 ed Exp $
 *********************************************************************/

#include <config.h>
#include <iostream>
using namespace std;

#include <string.h>
#include "netcdfcpp.h"

#define FILE "tst_failure.nc"
#define LAT "lat"

int
main( void )	// test new netCDF interface
{
   const int NLATS = 4;

   // Cause program to exit horribly on failure.
   NcError *err = new NcError(NcError::verbose_fatal);

   // Create a file.
   NcFile nc(FILE, NcFile::Replace, NULL, 0, NcFile::Classic); 

   // Check if the file was opened successfully. But if it wasn't
   // return 0 to cause make check to fail (since make check is
   // expecting this program to return a non-zero value.)
   if (! nc.is_valid()) {
      cerr << "can't create netCDF file " << FILE << "\n";
      return 0;
   }

   // Create a dimension.
   NcDim* latd = nc.add_dim(LAT, NLATS);

   // This will fail, because the dim already exists.
   NcDim* latd1 = nc.add_dim(LAT, NLATS);

   // If we get here, that's bad.
   return 0;
}