OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
getGCMDKeywords.cpp
Go to the documentation of this file.
1 #include <productInfo.h>
2 
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <genutils.h>
6 #include <string>
7 #include <ctype.h>
8 #include <algorithm>
9 
10 #include <pugixml.hpp>
11 
12 using namespace std;
13 using namespace pugi;
14 
15 extern "C" const char* getGCMDKeywords(const char* suite) {
16 
17  static string keyStr;
18 
19  xml_document rootNode;
20  xml_node GCMDKeywordsNode;
21 
22  char *dataRoot;
23  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
24  printf("-E- OCDATAROOT environment variable is not defined.\n");
25  exit(1);
26  }
27  string GCMDKeywordsXMLFileName = (string) dataRoot + "/common/GCMDKeywords.xml";
28 
29  xml_parse_result xmlResult = rootNode.load_file(GCMDKeywordsXMLFileName.c_str());
30  if (!xmlResult) {
31 
32  // if the XML file does not exist then we will not bother with the GCMDKeywords
33 // if (xmlResult.status == status_file_not_found)
34 // return NULL;
35 
36  printf("-E- %s Line %d: Can not load %s. %s\n", __FILE__, __LINE__,
37  GCMDKeywordsXMLFileName.c_str(), xmlResult.description());
38  exit(EXIT_FAILURE);
39  }
40 
41  GCMDKeywordsNode = rootNode.child("GCMDKeywords");
42  if (!GCMDKeywordsNode) {
43  printf("-E- %s Line %d: could not find GCMDKeywords tag in XML file = %s\n",
44  __FILE__, __LINE__, GCMDKeywordsXMLFileName.c_str());
45  exit(EXIT_FAILURE);
46  }
47 
48  // search for the requested suite name
49  xml_node suiteNode = GCMDKeywordsNode.find_child_by_attribute("suite", "name", suite);
50  if (!suiteNode)
51  return NULL;
52 
53  xml_node keywordNode = suiteNode.child("keyword");
54  bool firstOne = true;
55  while (keywordNode) {
56  if(firstOne) {
57  firstOne = false;
58  keyStr.clear();
59  } else {
60  keyStr += "; ";
61  }
62  keyStr += keywordNode.child_value();
63  keywordNode = keywordNode.next_sibling("keyword");
64  }
65 
66  if(firstOne)
67  return NULL;
68  else
69  return keyStr.c_str();
70 }
const char * getGCMDKeywords(const char *suite)
#define NULL
Definition: decode_rs.h:63
@ string