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 //cout<<"inside ncfiles..."<<filepath<<endl;
27  if (is_NCDF(filepath)) {
28  filelist.push_back(filepath);
29 // cout<<"if..."<<filepath<<endl;
30  } else {
31 // cout<<"else..."<<filepath<<endl;
32  string line;
33  ifstream infile(filepath);
34  if (infile) {
35  while (getline(infile,line)) {
36  if (is_NCDF(line))
37  filelist.push_back(line);
38  }
39  infile.close();
40  }
41  }
42 
43  return(filelist);
44 }
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