OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
hcutil.cc
Go to the documentation of this file.
1 // This file is part of the hdf4 data handler for the OPeNDAP data server.
2 
3 // Copyright (c) 2005 OPeNDAP, Inc.
4 // Author: James Gallagher <jgallagher@opendap.org>
5 //
6 // This is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your
9 // option) any later version.
10 //
11 // This software is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this software; if not, write to the Free Software Foundation,
18 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
21 
23 // Copyright 1996, by the California Institute of Technology.
24 // ALL RIGHTS RESERVED. United States Government Sponsorship
25 // acknowledged. Any commercial use must be negotiated with the
26 // Office of Technology Transfer at the California Institute of
27 // Technology. This software may be subject to U.S. export control
28 // laws and regulations. By accepting this software, the user
29 // agrees to comply with all applicable U.S. export laws and
30 // regulations. User has the responsibility to obtain export
31 // licenses, or other export authority as may be required before
32 // exporting such information to foreign countries or providing
33 // access to foreign persons.
34 
35 // U.S. Government Sponsorship under NASA Contract
36 // NAS7-1260 is acknowledged.
37 //
38 // Author: Todd.K.Karakashian@jpl.nasa.gov
39 //
40 // $RCSfile: hcutil.cc,v $ - misc utility routines for HDFClass
41 //
43 
44 #include "config_hdf.h"
45 
46 #include <string>
47 #include <vector>
48 
49 using std::vector;
50 using std::string;
51 
52 #include <mfhdf.h>
53 
54 #include <BESDebug.h>
55 
56 #if 0
57 
58 // This function is not used and is broken. The loop depends on i being less
59 // than zero for termination, but i is an unsigned type.
60 vector < string > split(const string & str, const string & delim)
61 {
62  vector < string > rv;
63 
64  string::size_type len = str.length();
65  string::size_type dlen = delim.length();
66  for (string::size_type i = 0, previ = -dlen;; previ = i) {
67  i = str.find(delim, previ + dlen);
68  if (i == 0)
69  continue;
70  if (i < 0) {
71  if (previ + dlen < len)
72  rv.push_back(str.
73  substr(previ + dlen, (len - previ - dlen)));
74  break;
75  }
76  rv.push_back(str.substr(previ + dlen, (i - previ - dlen)));
77  }
78 
79  return rv;
80 }
81 #endif
82 
83 string join(const vector < string > &sv, const string & delim)
84 {
85  string str;
86  if (sv.size() > 0) {
87  str = sv[0];
88  for (int i = 1; i < (int) sv.size(); ++i)
89  str += (delim + sv[i]);
90  }
91  return str;
92 }
93 
94 bool SDSExists(const char *filename, const char *sdsname)
95 {
96 
97  int32 sd_id, index;
98  if ((sd_id = SDstart(filename, DFACC_RDONLY)) < 0) {
99  BESDEBUG("h4", "hcutil:96 SDstart for " << filename << " error" << endl);
100  return false;
101  }
102 
103  index = SDnametoindex(sd_id, (char *) sdsname);
104  if (SDend(sd_id) < 0)
105  BESDEBUG("h4", "hcutil: SDend error: " << HEstring((hdf_err_code_t)HEvalue(1)) << endl);
106 
107  return (index >= 0);
108 }
109 
110 bool GRExists(const char *filename, const char *grname)
111 {
112 
113  int32 file_id, gr_id, index;
114  if ((file_id = Hopen(filename, DFACC_RDONLY, 0)) < 0)
115  return false;
116  if ((gr_id = GRstart(file_id)) < 0)
117  return false;
118 
119  index = GRnametoindex(gr_id, (char *) grname);
120  GRend(gr_id);
121  Hclose(file_id);
122 
123  return (index >= 0);
124 }
125 
126 bool VdataExists(const char *filename, const char *vdname)
127 {
128 
129  int32 file_id, ref;
130  if ((file_id = Hopen(filename, DFACC_RDONLY, 0)) < 0)
131  return false;
132  Vstart(file_id);
133  ref = VSfind(file_id, vdname);
134  Vend(file_id);
135  Hclose(file_id);
136 
137  return (ref > 0);
138 }
bool SDSExists(const char *filename, const char *sdsname)
Definition: hcutil.cc:94
bool GRExists(const char *filename, const char *grname)
Definition: hcutil.cc:110
bool VdataExists(const char *filename, const char *vdname)
Definition: hcutil.cc:126
string join(const vector< string > &sv, const string &delim)
Definition: hcutil.cc:83
vector< string > & split(const string &s, char delim, vector< string > &elems)
Splits the string on the passed char.
Definition: ugrid_utils.cc:436
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64