OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
filetypeXml.cpp
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 
7 #include <cfloat>
8 #include <cmath>
9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 #include <pugixml.hpp>
13 #include <vector>
14 #include <boost/foreach.hpp>
15 
16 #include <dfutils.h>
17 #include <genutils.h>
18 #include <sensorDefs.h>
19 #include <timeutils.h>
20 
21 #include <boost/algorithm/string.hpp>
22 
23 #include "filetype.h"
24 
25 
43 extern "C" file_format chk_safe_xml(char *filename) {
44  file_format ret = {FT_INVALID, -1, -1};
45  pugi::xml_document rootNode;
46  pugi::xml_node dataNode;
47 
48  const char *productName;
49  const char *platformName;
50 
51  if (!rootNode.load_file(filename)) {
52  return ret;
53  }
54 
55  productName = rootNode.first_element_by_path("xfdu:XFDU/informationPackageMap/xfdu:contentUnit").attribute("textInfo").value();
56  if (strstr(productName, "OLCI") != NULL && strstr(productName, "SENTINEL-3") != NULL && strstr(productName, "Level 1") != NULL) {
57  dataNode = rootNode.first_element_by_path("xfdu:XFDU/metadataSection").find_child_by_attribute("metadataObject", "ID", "platform");
58  platformName = dataNode.first_element_by_path("metadataWrap/xmlData/sentinel-safe:platform/sentinel-safe:number").child_value();
59  if(strcmp("A", platformName) == 0) {
60  if (want_verbose != 0){
61  printf("Found OLCI Sentinel-3A product: %s\n", productName);
62  }
63  ret.type = FT_OLCI;
64  ret.sensor_id = OLCIS3A;
65  ret.subsensor_id = OLCI_S3A;
66  } else if(strcmp("B", platformName) == 0) {
67  if (want_verbose != 0){
68  printf("Found OLCI Sentinel-3B product: %s\n", productName);
69  }
70  ret.type = FT_OLCI;
71  ret.sensor_id = OLCIS3B;
72  ret.subsensor_id = OLCI_S3B;
73  } else {
74  printf("Unknown platform: %s for product: %s\n", platformName, productName);
75  exit(EXIT_FAILURE);
76  }
77  } else if (strstr(productName, "MSI") != NULL && strstr(productName, "SENTINEL-2") != NULL && strstr(productName, "Level-1C") != NULL) {
78  dataNode = rootNode.first_element_by_path("xfdu:XFDU/metadataSection").find_child_by_attribute("metadataObject", "ID", "platform");
79  platformName = dataNode.first_element_by_path("metadataWrap/xmlData/safe:platform/safe:number").child_value();
80  if(!strcmp(platformName, "2A")) {
81  if (want_verbose != 0){
82  printf("Found MSI Sentinel-2A product: %s\n", productName);
83  }
84  ret.type = FT_MSIL1C;
85  ret.sensor_id = MSIS2A;
86  ret.subsensor_id = MSI_S2A;
87  } else if(!strcmp(platformName, "2B")) {
88  if (want_verbose != 0){
89  printf("Found MSI Sentinel-2B product: %s\n", productName);
90  }
91  ret.type = FT_MSIL1C;
92  ret.sensor_id = MSIS2B;
93  ret.subsensor_id = MSI_S2B;
94  } else {
95  printf("Unknown platform: %s for product: %s\n", platformName, productName);
96  exit(EXIT_FAILURE);
97  }
98  } else if (strstr(productName, "MERIS") != NULL && strstr(productName, "ENVISAT") != NULL && strstr(productName, "Level 1") != NULL) {
99  if (want_verbose != 0){
100  printf("Found MERIS L1B SAFE product: %s\n", productName);
101  }
102  ret.type = FT_MERISL1BSAFE;
103  ret.sensor_id = MERIS;
104  ret.subsensor_id = -1;
105  }
106  return ret;
107 }
108 
int32_t subsensor_id
Definition: filetype.h:69
#define OLCIS3A
Definition: sensorDefs.h:32
#define MSI_S2B
Definition: sensorDefs.h:62
@ FT_OLCI
Definition: filetype.h:39
#define MSIS2B
Definition: sensorDefs.h:38
#define NULL
Definition: decode_rs.h:63
#define MSI_S2A
Definition: sensorDefs.h:61
#define MERIS
Definition: sensorDefs.h:22
file_type type
Definition: filetype.h:67
@ FT_MERISL1BSAFE
Definition: filetype.h:29
int want_verbose
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
file_format chk_safe_xml(char *filename)
Definition: filetypeXml.cpp:43
int32_t sensor_id
Definition: filetype.h:68
#define MSIS2A
Definition: sensorDefs.h:34
@ FT_INVALID
Definition: filetype.h:12
@ FT_MSIL1C
Definition: filetype.h:56
#define OLCIS3B
Definition: sensorDefs.h:41
#define OLCI_S3A
Definition: sensorDefs.h:63
#define OLCI_S3B
Definition: sensorDefs.h:64