58#define ESCAPE_STRING_ATTRIBUTES 1
62 const string printable =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;<,>.?/'\"\n\t\r";
63 const string ESC =
"\\";
65#if ESCAPE_STRING_ATTRIBUTES
66 const string DOUBLE_ESC = ESC + ESC;
67 const string QUOTE =
"\"";
68 const string ESCQUOTE = ESC + QUOTE;
72 while ((ind = s.find(ESC, ind)) != string::npos) {
73 s.replace(ind, 1, DOUBLE_ESC);
74 ind += DOUBLE_ESC.size();
79 while ((ind = s.find(QUOTE, ind)) != string::npos) {
80 s.replace(ind, 1, ESCQUOTE);
81 ind += ESCQUOTE.size();
87 while ((ind = s.find_first_not_of(printable, ind)) != string::npos)
88 s.replace(ind, 1, ESC +
octstring(s[ind]));
98 buf << oct << setw(3) << setfill(
'0')
99 <<
static_cast<unsigned int>(val);
105void HDF5CFDAPUtil::replace_double_quote(
string & str) {
107 const string offend_char =
"\"";
108 const string replace_str =
""e";
109 size_t found_quote = 0;
110 size_t start_pos = 0;
111 while (found_quote != string::npos) {
112 found_quote = str.find(offend_char,start_pos);
113 if (found_quote!= string::npos){
114 str.replace(found_quote,offend_char.size(),replace_str);
115 start_pos = found_quote+1;
121string HDF5CFDAPUtil::print_type(H5DataType type) {
125 string DAPUNSUPPORTED =
"Unsupported";
126 string DAPBYTE =
"Byte";
127 string DAPINT16 =
"Int16";
128 string DAPUINT16 =
"Uint16";
129 string DAPINT32 =
"Int32";
130 string DAPUINT32 =
"Uint32";
131 string DAPFLOAT32 =
"Float32";
132 string DAPFLOAT64 =
"Float64";
133 string DAP4INT64 =
"Int64";
134 string DAP4UINT64 =
"UInt64";
135 string DAPSTRING =
"String";
173 return DAPUNSUPPORTED;
176 return DAPUNSUPPORTED;
181D4AttributeType HDF5CFDAPUtil::print_type_dap4(H5DataType type) {
195 return attr_uint16_c;
201 return attr_uint32_c;
207 return attr_uint64_c;
210 return attr_float32_c;
213 return attr_float64_c;
231HDF5CFDAPUtil::get_mem_dtype(H5DataType dtype,
size_t mem_dtype_size ) {
235 return ((H5INT16 == dtype) && (1 == mem_dtype_size))?H5CHAR:dtype;
239HDF5CFDAPUtil:: print_attr(H5DataType type,
unsigned int loc,
void *vals)
251 unsigned long long *ullp;
261 gp.ucp = (
unsigned char *) vals;
271 gp.cp = (
char *) vals;
285 gp.sp = (
short *) vals;
293 gp.usp = (
unsigned short *) vals;
294 rep << *(gp.usp+loc);
301 gp.ip = (
int *) vals;
308 gp.uip = (
unsigned int *) vals;
309 rep << *(gp.uip+loc);
314 gp.llp = (
long long *) vals;
315 rep << *(gp.llp+loc);
321 gp.ullp = (
unsigned long long *) vals;
322 rep << *(gp.ullp+loc);
330 float attr_val = *(
float*)vals;
334 gp.fp = (
float *) vals;
336 rep << setprecision(10);
339 bool is_a_fin = isfinite(attr_val);
340 string tmp_rep_str = rep.str();
341 if (tmp_rep_str.find(
'.') == string::npos
342 && tmp_rep_str.find(
'e') == string::npos
343 && tmp_rep_str.find(
'E') == string::npos
344 && (
true == is_a_fin)){
348 if ((rep.str().find_first_of(
".eE")==string::npos) && isfinite(attr_val))
356 double attr_val = *(
double*)vals;
360 gp.dp = (
double *) vals;
361 rep << std::showpoint;
362 rep << std::setprecision(17);
365 bool is_a_fin = isfinite(attr_val);
366 string tmp_rep_str = rep.str();
367 if (tmp_rep_str.find(
'.') == string::npos
368 && tmp_rep_str.find(
'e') == string::npos
369 && tmp_rep_str.find(
'E') == string::npos
370 && (
true == is_a_fin)) {
374 if ((rep.str().find_first_of(
".eE")==string::npos) && isfinite(attr_val))
380 return string(
"UNKNOWN");
391 else if (s ==
"Int8")
393 else if (s ==
"UInt8")
395 else if (s ==
"Int16")
397 else if (s ==
"UInt16")
398 return attr_uint16_c;
399 else if (s ==
"Int32")
401 else if (s ==
"UInt32")
402 return attr_uint32_c;
403 else if (s ==
"Int64")
405 else if (s ==
"UInt64")
406 return attr_uint64_c;
407 else if (s ==
"Float32")
408 return attr_float32_c;
409 else if (s ==
"Float64")
410 return attr_float64_c;
411 else if (s ==
"String")
static string escattr(string s)
static D4AttributeType daptype_strrep_to_dap4_attrtype(const string &s)
static string octstring(unsigned char val)
Helper function for escattr.
Helper functions for generating DAS attributes and a function to check BES Key.