OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
ncfileinfo.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 #include <vector>
5 #include <netcdf>
6 
7 using namespace std;
8 using namespace netCDF;
9 using namespace netCDF::exceptions;
10 
11 bool is_NCDF(const string filepath) {
12  try {
13  NcFile nc(filepath, NcFile::read);
14  nc.close();
15  return true;
16  } catch (NcException const & e) {
17  return false;
18  }
19 }
20 
21 vector<string> ncfiles(const char* filepath) {
22  /* Returns a string vector of NetCDF filenames, listed in filepath.
23  If filepath is a NetCDF file, vector will contain only that file.
24  */
25  vector<string> filelist;
26 
27  if (is_NCDF(filepath)) {
28  filelist.push_back(filepath);
29  } else {
30  string line;
31  ifstream infile(filepath);
32  if (infile) {
33  while (getline(infile,line)) {
34  if (is_NCDF(line))
35  filelist.push_back(line);
36  }
37  infile.close();
38  }
39  }
40 
41  return(filelist);
42 }
vector< string > ncfiles(const char *filepath)
Definition: ncfileinfo.cpp:21
bool is_NCDF(const string filepath)
Definition: ncfileinfo.cpp:11
string filepath
Definition: color_dtdb.py:207