NeXus  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
NeXusFile.cpp
Go to the documentation of this file.
1 #include <cstring>
2 // REMOVE
3 #include <iostream>
4 #include <sstream>
5 #include <typeinfo>
6 #include "napiconfig.h"
7 #include "NeXusFile.hpp"
8 #include "NeXusException.hpp"
9 
10 using namespace NeXus;
11 using std::map;
12 using std::pair;
13 using std::string;
14 using std::stringstream;
15 using std::vector;
16 
22 static const string NULL_STR = "NULL";
23 
24 namespace { // anonymous namespace to keep it in the file
25 template <typename NumT>
26 static string toString(const vector<NumT>& data) {
27  stringstream result;
28  result << "[";
29  size_t size = data.size();
30  for (size_t i = 0; i < size; i++) {
31  result << data[i];
32  if (i+1 < size) {
33  result << ",";
34  }
35  }
36  result << "]";
37  return result.str();
38 }
39 
40 static vector<int64_t> toInt64(const vector<int> & small_v) {
41  // copy the dims over to call the int64_t version
42  vector<int64_t> big_v;
43  big_v.reserve(small_v.size());
44  for (vector<int>::const_iterator it = small_v.begin(); it != small_v.end(); ++it)
45  {
46  big_v.push_back(static_cast<int64_t>(*it));
47  }
48  return big_v;
49 }
50 
51 } // end of anonymous namespace
52 
53 namespace NeXus {
54 
55  // catch for undefined types
56  template <typename NumT>
57  NXnumtype getType(NumT number) {
58  stringstream msg;
59  msg << "NeXus::getType() does not know type of " << typeid(number).name();
60  throw Exception(msg.str());
61  }
62 
63  template<>
64  NXDLL_EXPORT NXnumtype getType(char number) {
65  return CHAR;
66  }
67 
68  // template specialisations for types we know
69  template<>
70  NXDLL_EXPORT NXnumtype getType(float number) {
71  return FLOAT32;
72  }
73 
74  template<>
75  NXDLL_EXPORT NXnumtype getType(double number) {
76  return FLOAT64;
77  }
78 
79  template<>
80  NXDLL_EXPORT NXnumtype getType(int8_t number) {
81  return INT8;
82  }
83 
84  template<>
85  NXDLL_EXPORT NXnumtype getType(uint8_t number) {
86  return UINT8;
87  }
88 
89  template<>
90  NXDLL_EXPORT NXnumtype getType(int16_t number) {
91  return INT16;
92  }
93 
94  template<>
95  NXDLL_EXPORT NXnumtype getType(uint16_t number) {
96  return UINT16;
97  }
98 
99  template<>
100  NXDLL_EXPORT NXnumtype getType(int32_t number) {
101  return INT32;
102  }
103 
104  template<>
105  NXDLL_EXPORT NXnumtype getType(uint32_t number) {
106  return UINT32;
107  }
108 
109  template<>
110  NXDLL_EXPORT NXnumtype getType(int64_t number) {
111  return INT64;
112  }
113 
114  template<>
115  NXDLL_EXPORT NXnumtype getType(uint64_t number) {
116  return UINT64;
117  }
118 
119 
120 }
121 
122 // check type sizes - uses a trick that you cannot allocate an
123 // array of negative length
124 #ifdef _MSC_VER
125 #define ARRAY_OFFSET 1 /* cannot dimension an array with zero elements */
126 #else
127 #define ARRAY_OFFSET 0 /* can dimension an array with zero elements */
128 #endif /* _MSC_VER */
129 
130 static int check_float_too_big[4 - sizeof(float) + ARRAY_OFFSET]; // error if float > 4 bytes
131 static int check_float_too_small[sizeof(float) - 4 + ARRAY_OFFSET]; // error if float < 4 bytes
132 static int check_double_too_big[8 - sizeof(double) + ARRAY_OFFSET]; // error if double > 8 bytes
133 static int check_double_too_small[sizeof(double) - 8 + ARRAY_OFFSET]; // error if double < 8 bytes
134 static int check_char_too_big[1 - sizeof(char) + ARRAY_OFFSET]; // error if char > 1 byte
135 
136 namespace {
137 
138 static void inner_malloc(void* & data, const std::vector<int64_t>& dims, NXnumtype type) {
139  int rank = dims.size();
140  int64_t c_dims[NX_MAXRANK];
141  for (int i = 0; i < rank; i++) {
142  c_dims[i] = dims[i];
143  }
144  NXstatus status = NXmalloc64(&data, rank, c_dims, type);
145  if (status != NX_OK) {
146  throw Exception("NXmalloc failed", status);
147  }
148 }
149 
150 
151 static void inner_free(void* & data) {
152  NXstatus status = NXfree(&data);
153  if (status != NX_OK) {
154  throw Exception("NXfree failed", status);
155  }
156 }
157 
158 } // end of anonymous namespace
159 
160 namespace NeXus {
161 File::File(NXhandle handle, bool close_handle) : m_file_id(handle), m_close_handle(close_handle) {
162 }
163 
164 File::File(const string& filename, const NXaccess access) : m_close_handle (true) {
165  this->initOpenFile(filename, access);
166 }
167 
168 File::File(const char *filename, const NXaccess access) : m_close_handle (true) {
169  this->initOpenFile(string(filename), access);
170 }
171 
172 void File::initOpenFile(const string& filename, const NXaccess access) {
173  if (filename.empty()) {
174  throw Exception("Filename specified is empty constructor");
175  }
176 
177  NXstatus status = NXopen(filename.c_str(), access, &(this->m_file_id));
178  if (status != NX_OK) {
179  stringstream msg;
180  msg << "NXopen(" << filename << ", " << access << ") failed";
181  throw Exception(msg.str(), status);
182  }
183 }
184 
186  if (m_close_handle && m_file_id != NULL) {
187  NXstatus status = NXclose(&(this->m_file_id));
188  this->m_file_id = NULL;
189  if (status != NX_OK) {
190  throw Exception("NXclose failed", status);
191  }
192  }
193 }
194 
195 void File::close() {
196  if (this->m_file_id != NULL) {
197  NXstatus status = NXclose(&(this->m_file_id));
198  this->m_file_id = NULL;
199  if (status != NX_OK) {
200  throw Exception("NXclose failed", status);
201  }
202  }
203 }
204 
205 void File::flush() {
206  NXstatus status = NXflush(&(this->m_file_id));
207  if (status != NX_OK) {
208  throw Exception("NXflush failed", status);
209  }
210 }
211 
212 void File::makeGroup(const string& name, const string& class_name, bool open_group) {
213  if (name.empty()) {
214  throw Exception("Supplied empty name to makeGroup");
215  }
216  if (class_name.empty()) {
217  throw Exception("Supplied empty class name to makeGroup");
218  }
219  NXstatus status = NXmakegroup(this->m_file_id, name.c_str(),
220  class_name.c_str());
221  if (status != NX_OK) {
222  stringstream msg;
223  msg << "NXmakegroup(" << name << ", " << class_name << ") failed";
224  throw Exception(msg.str(), status);
225  }
226  if (open_group) {
227  this->openGroup(name, class_name);
228  }
229 }
230 
231 void File::openGroup(const string& name, const string& class_name) {
232  if (name.empty()) {
233  throw Exception("Supplied empty name to openGroup");
234  }
235  if (class_name.empty()) {
236  throw Exception("Supplied empty class name to openGroup");
237  }
238  NXstatus status = NXopengroup(this->m_file_id, name.c_str(),
239  class_name.c_str());
240  if (status != NX_OK) {
241  stringstream msg;
242  msg << "NXopengroup(" << name << ", " << class_name << ") failed";
243  throw Exception(msg.str(), status);
244  }
245 }
246 
247 void File::openPath(const string& path) {
248  if (path.empty()) {
249  throw Exception("Supplied empty path to openPath");
250  }
251  NXstatus status = NXopenpath(this->m_file_id, path.c_str());
252  if (status != NX_OK) {
253  stringstream msg;
254  msg << "NXopenpath(" << path << ") failed";
255  throw Exception(msg.str(), status);
256  }
257 }
258 
259 void File::openGroupPath(const string& path) {
260  if (path.empty()) {
261  throw Exception("Supplied empty path to openGroupPath");
262  }
263  NXstatus status = NXopengrouppath(this->m_file_id, path.c_str());
264  if (status != NX_OK) {
265  stringstream msg;
266  msg << "NXopengrouppath(" << path << ") failed";
267  throw Exception(msg.str(), status);
268  }
269 }
270 
271 std::string File::getPath(){
272  char cPath[2048];
273 
274  memset(cPath,0,sizeof(cPath));
275  NXstatus status = NXgetpath(this->m_file_id,cPath, sizeof(cPath)-1);
276  if (status != NX_OK) {
277  stringstream msg;
278  msg << "NXgetpath() failed";
279  throw Exception(msg.str(), status);
280  }
281  return std::string(cPath);
282 }
283 
285  NXstatus status = NXclosegroup(this->m_file_id);
286  if (status != NX_OK) {
287  throw Exception("NXclosegroup failed", status);
288  }
289 }
290 
291 void File::makeData(const string& name, NXnumtype type,
292  const vector<int>& dims, bool open_data) {
293  this->makeData(name, type, toInt64(dims), open_data);
294 }
295 
296 void File::makeData(const string& name, NXnumtype type,
297  const vector<int64_t>& dims, bool open_data) {
298  // error check the parameters
299  if (name.empty()) {
300  throw Exception("Supplied empty label to makeData");
301  }
302  if (dims.empty()) {
303  throw Exception("Supplied empty dimensions to makeData");
304  }
305 
306  // do the work
307  NXstatus status = NXmakedata64(this->m_file_id, name.c_str(), (int)type,
308  dims.size(), const_cast<int64_t*>(&(dims[0])));
309  // report errors
310  if (status != NX_OK) {
311  stringstream msg;
312  msg << "NXmakedata(" << name << ", " << type << ", " << dims.size()
313  << ", " << toString(dims) << ") failed";
314  throw Exception(msg.str(), status);
315  }
316  if (open_data) {
317  this->openData(name);
318  }
319 }
320 
321 template <typename NumT>
322 void File::makeData(const string & name, const NXnumtype type,
323  const NumT length, bool open_data) {
324  vector<int64_t> dims;
325  dims.push_back(static_cast<int64_t>(length));
326  this->makeData(name, type, dims, open_data);
327 }
328 
329 template <typename NumT>
330 void File::writeData(const string& name, const NumT& value) {
331  std::vector<NumT> v(1, value);
332  this->writeData(name, v);
333 }
334 
335 void File::writeData(const string& name, const char* value) {
336  this->writeData(name, std::string(value));
337 }
338 
339 void File::writeData(const string& name, const string& value)
340 {
341  string my_value(value);
342  // Allow empty strings by defaulting to a space
343  if (my_value.empty())
344  my_value = " ";
345  vector<int> dims;
346  dims.push_back(static_cast<int>(my_value.size()));
347  this->makeData(name, CHAR, dims, true);
348 
349  this->putData(&(my_value[0]));
350 
351  this->closeData();
352 }
353 
354 
355 
356 template <typename NumT>
357 void File::writeData(const string& name, const vector<NumT>& value) {
358  vector<int64_t> dims(1, value.size());
359  this->writeData(name, value, dims);
360 }
361 
362 template <typename NumT>
363 void File::writeData(const string& name, const vector<NumT>& value,
364  const vector<int>& dims) {
365  this->makeData(name, getType<NumT>(), dims, true);
366  this->putData(value);
367  this->closeData();
368 }
369 
370 template <typename NumT>
371 void File::writeData(const string& name, const vector<NumT>& value,
372  const vector<int64_t>& dims) {
373  this->makeData(name, getType<NumT>(), dims, true);
374  this->putData(value);
375  this->closeData();
376 }
377 
378 
379 template <typename NumT>
380 void File::writeExtendibleData(const string& name, vector<NumT>& value)
381 {
382  // Use a default chunk size of 4096 bytes. TODO: Is this optimal?
383  writeExtendibleData(name, value, 4096);
384 }
385 
386 template <typename NumT>
387 void File::writeExtendibleData(const string& name, vector<NumT>& value, const int64_t chunk)
388 {
389  vector<int64_t> dims(1, NX_UNLIMITED);
390  vector<int64_t> chunk_dims(1, chunk);
391  // Use chunking without using compression
392  this->makeCompData(name, getType<NumT>(), dims, NONE, chunk_dims, true );
393  this->putSlab(value, int64_t(0), int64_t(value.size()));
394  this->closeData();
395 }
396 
397 template <typename NumT>
398 void File::writeExtendibleData(const string& name, vector<NumT>& value,
399  vector<int64_t>& dims, std::vector<int64_t> & chunk)
400 {
401  // Create the data with unlimited 0th dimensions
402  std::vector<int64_t> unlim_dims(dims);
403  unlim_dims[0] = NX_UNLIMITED;
404  // Use chunking without using compression
405  this->makeCompData(name, getType<NumT>(), unlim_dims, NONE, chunk, true );
406  // And put that slab of that of that given size in there
407  std::vector<int64_t> start( dims.size(), 0 );
408  this->putSlab(value, start, dims);
409  this->closeData();
410 
411 }
412 
413 
414 template <typename NumT>
415 void File::writeUpdatedData(const std::string& name, std::vector<NumT>& value)
416 {
417  this->openData(name);
418  this->putSlab(value, int64_t(0), int64_t(value.size()));
419  this->closeData();
420 }
421 
422 template <typename NumT>
423 void File::writeUpdatedData(const std::string& name, std::vector<NumT>& value,
424  std::vector<int64_t>& dims)
425 {
426  this->openData(name);
427  std::vector<int64_t> start( dims.size(), 0 );
428  this->putSlab(value, start, dims);
429  this->closeData();
430 }
431 
432 
433 void File::makeCompData(const string& name, const NXnumtype type,
434  const vector<int>& dims, const NXcompression comp,
435  const vector<int>& bufsize, bool open_data) {
436  this->makeCompData(name, type, toInt64(dims), comp, toInt64(bufsize), open_data);
437 }
438 
439 void File::makeCompData(const string& name, const NXnumtype type,
440  const vector<int64_t>& dims, const NXcompression comp,
441  const vector<int64_t>& bufsize, bool open_data) {
442  // error check the parameters
443  if (name.empty()) {
444  throw Exception("Supplied empty name to makeCompData");
445  }
446  if (dims.empty()) {
447  throw Exception("Supplied empty dimensions to makeCompData");
448  }
449  if (bufsize.empty()) {
450  throw Exception("Supplied empty bufsize to makeCompData");
451  }
452  if (dims.size() != bufsize.size()) {
453  stringstream msg;
454  msg << "Supplied dims rank=" << dims.size()
455  << " must match supplied bufsize rank=" << bufsize.size()
456  << "in makeCompData";
457  throw Exception(msg.str());
458  }
459 
460  // do the work
461  int i_type = static_cast<int>(type);
462  int i_comp = static_cast<int>(comp);
463  NXstatus status = NXcompmakedata64(this->m_file_id, name.c_str(), i_type,
464  dims.size(),
465  const_cast<int64_t *>(&(dims[0])), i_comp,
466  const_cast<int64_t *>(&(bufsize[0])));
467 
468  // report errors
469  if (status != NX_OK) {
470  stringstream msg;
471  msg << "NXcompmakedata64(" << name << ", " << type << ", " << dims.size()
472  << ", " << toString(dims) << ", " << comp << ", " << toString(bufsize)
473  << ") failed";
474  throw Exception(msg.str(), status);
475  }
476  if (open_data) {
477  this->openData(name);
478  }
479 }
480 
481 template <typename NumT>
482 void File::writeCompData(const string & name, const vector<NumT> & value,
483  const vector<int> & dims, const NXcompression comp,
484  const vector<int> & bufsize) {
485  this->writeCompData(name, value, toInt64(dims), comp, toInt64(bufsize));
486 }
487 
488 template <typename NumT>
489 void File::writeCompData(const string & name, const vector<NumT> & value,
490  const vector<int64_t> & dims, const NXcompression comp,
491  const vector<int64_t> & bufsize) {
492  this->makeCompData(name, getType<NumT>(), dims, comp, bufsize, true);
493  this->putData(value);
494  this->closeData();
495 }
496 
497 void File::compress(NXcompression comp) {
498  stringstream msg;
499  msg << "compress(" << comp << ") is depricated - use makeCompData()";
500  throw Exception(msg.str());
501 }
502 
503 void File::openData(const string & name) {
504  if (name.empty()) {
505  throw Exception("Supplied empty name to openData");
506  }
507  NXstatus status = NXopendata(this->m_file_id, name.c_str());
508  if (status != NX_OK) {
509  throw Exception("NXopendata(" + name + ") failed", status);
510  }
511 }
512 
514  NXstatus status = NXclosedata(this->m_file_id);
515  if (status != NX_OK) {
516  throw Exception("NXclosedata() failed", status);
517  }
518 }
519 
520 void File::putData(const void* data) {
521  if (data == NULL) {
522  throw Exception("Data specified as null in putData");
523  }
524  NXstatus status = NXputdata(this->m_file_id, const_cast<void *>(data));
525  if (status != NX_OK) {
526  throw Exception("NXputdata(void *) failed", status);
527  }
528 }
529 
530 template <typename NumT>
531 void File::putData(const vector<NumT> & data) {
532  if (data.empty()) {
533  throw Exception("Supplied empty data to putData");
534  }
535  this->putData(&(data[0]));
536 }
537 
538 void File::putAttr(const AttrInfo& info, const void* data) {
539  if (info.name == NULL_STR) {
540  throw Exception("Supplied bad attribute name \"" + NULL_STR + "\"");
541  }
542  if (info.name.empty()) {
543  throw Exception("Supplied empty name to putAttr");
544  }
545  NXstatus status = NXputattr(this->m_file_id, info.name.c_str(),
546  const_cast<void *>(data), info.length,
547  (int)(info.type));
548  if (status != NX_OK) {
549  stringstream msg;
550  msg << "NXputattr(" << info.name << ", data, " << info.length << ", "
551  << info.type << ") failed";
552  throw Exception(msg.str(), status);
553  }
554 }
555 
556 template <typename NumT>
557 void File::putAttr(const std::string& name, const NumT value) {
558  AttrInfo info;
559  info.name = name;
560  info.length = 1;
561  info.type = getType<NumT>();
562  this->putAttr(info, &value);
563 }
564 
565 void File::putAttr(const char* name, const char* value) {
566  if (name == NULL) {
567  throw Exception("Specified name as null to putAttr");
568  }
569  if (value == NULL) {
570  throw Exception("Specified value as null to putAttr");
571  }
572  string s_name(name);
573  string s_value(value);
574  this->putAttr(s_name, s_value);
575 }
576 
577 void File::putAttr(const std::string& name, const std::string value) {
578  string my_value(value);
579  if (my_value.empty())
580  my_value = " "; // Make a default "space" to avoid errors.
581  AttrInfo info;
582  info.name = name;
583  info.length = static_cast<int>(my_value.size());
584  info.type = CHAR;
585  this->putAttr(info, &(my_value[0]));
586 }
587 
588 void File::putSlab(void* data, vector<int>& start, vector<int>& size) {
589  vector<int64_t> start_big = toInt64(start);
590  vector<int64_t> size_big = toInt64(size);
591  this->putSlab(data, start_big, size_big);
592 }
593 
594 void File::putSlab(void* data, vector<int64_t>& start, vector<int64_t>& size) {
595  if (data == NULL) {
596  throw Exception("Data specified as null in putSlab");
597  }
598  if (start.empty()) {
599  throw Exception("Supplied empty start to putSlab");
600  }
601  if (size.empty()) {
602  throw Exception("Supplied empty size to putSlab");
603  }
604  if (start.size() != size.size()) {
605  stringstream msg;
606  msg << "Supplied start rank=" << start.size()
607  << " must match supplied size rank=" << size.size()
608  << "in putSlab";
609  throw Exception(msg.str());
610  }
611  NXstatus status = NXputslab64(this->m_file_id, data, &(start[0]), &(size[0]));
612  if (status != NX_OK) {
613  stringstream msg;
614  msg << "NXputslab64(data, " << toString(start) << ", " << toString(size)
615  << ") failed";
616  throw Exception(msg.str(), status);
617  }
618 }
619 
620 template <typename NumT>
621 void File::putSlab(vector<NumT>& data, vector<int>& start,
622  vector<int>& size) {
623  vector<int64_t> start_big = toInt64(start);
624  vector<int64_t> size_big = toInt64(size);
625  this->putSlab(data, start_big, size_big);
626 }
627 
628 template <typename NumT>
629 void File::putSlab(vector<NumT>& data, vector<int64_t>& start,
630  vector<int64_t>& size) {
631  if (data.empty()) {
632  throw Exception("Supplied empty data to putSlab");
633  }
634  this->putSlab(&(data[0]), start, size);
635 }
636 
637 template <typename NumT>
638 void File::putSlab(vector<NumT>& data, int start, int size) {
639  this->putSlab(data, static_cast<int64_t>(start), static_cast<int64_t>(size));
640 }
641 
642 template <typename NumT>
643 void File::putSlab(vector<NumT>& data, int64_t start, int64_t size) {
644  vector<int64_t> start_v;
645  start_v.push_back(start);
646  vector<int64_t> size_v;
647  size_v.push_back(size);
648  this->putSlab(data, start_v, size_v);
649 }
650 
651 NXlink File::getDataID() {
652  NXlink link;
653  NXstatus status = NXgetdataID(this->m_file_id, &link);
654  if (status != NX_OK) {
655  throw Exception("NXgetdataID failed", status);
656  }
657  return link;
658 }
659 
661 {
662  NXlink id;
663  if(NXgetdataID(this->m_file_id,&id) == NX_ERROR)
664  {
665  return false;
666  }
667  else
668  {
669  return true;
670  }
671 }
672 /*----------------------------------------------------------------------*/
673 
674 void File::makeLink(NXlink& link) {
675  NXstatus status = NXmakelink(this->m_file_id, &link);
676  if (status != NX_OK) {
677  throw Exception("NXmakelink failed", status);
678  }
679 }
680 
681 void File::makeNamedLink(const string& name, NXlink& link) {
682  if (name.empty()) {
683  throw Exception("Supplied empty name to makeNamedLink");
684  }
685  NXstatus status = NXmakenamedlink(this->m_file_id, name.c_str(), &link);
686  if (status != NX_OK) {
687  throw Exception("NXmakenamedlink(" + name + ", link)", status);
688  }
689 }
690 
692  NXstatus status = NXopensourcegroup(this->m_file_id);
693  if (status != NX_OK) {
694  throw Exception("NXopensourcegroup failed");
695  }
696 }
697 
698 void File::getData(void* data) {
699  if (data == NULL) {
700  throw Exception("Supplied null pointer to getData");
701  }
702  NXstatus status = NXgetdata(this->m_file_id, data);
703  if (status != NX_OK) {
704  throw Exception("NXgetdata failed", status);
705  }
706 }
707 
708 template <typename NumT>
709 std::vector<NumT> * File::getData() {
710  Info info = this->getInfo();
711  if (info.type != getType<NumT>()) {
712  throw Exception("NXgetdata failed - invalid vector type");
713  }
714 
715  // determine the number of elements
716  int64_t length=1;
717  for (vector<int64_t>::const_iterator it = info.dims.begin();
718  it != info.dims.end(); it++) {
719  length *= *it;
720  }
721 
722  // allocate memory to put the data into
723  void * temp;
724  inner_malloc(temp, info.dims, info.type);
725 
726  // fetch the data
727  this->getData(temp);
728 
729  // put it in the vector
730  vector<NumT> * result = new vector<NumT>(static_cast<NumT *>(temp),
731  static_cast<NumT *>(temp)
732  + static_cast<size_t>(length));
733 
734  inner_free(temp);
735  return result;
736 }
737 
738 template <typename NumT>
739 void File::getData(vector<NumT>& data) {
740  Info info = this->getInfo();
741 
742  if (info.type != getType<NumT>())
743  {
744  throw Exception("NXgetdata failed - invalid vector type");
745  }
746  // determine the number of elements
747  int64_t length=1;
748  for (vector<int64_t>::const_iterator it = info.dims.begin();
749  it != info.dims.end(); it++) {
750  length *= *it;
751  }
752 
753  // allocate memory to put the data into
754  // need to use resize() rather than reserve() so vector length gets set
755  data.resize(length);
756 
757  // fetch the data
758  this->getData(&(data[0]));
759 }
760 
761 
762 void File::getDataCoerce(vector<int> &data)
763 {
764  Info info = this->getInfo();
765  if (info.type == INT8)
766  {
767  vector<int8_t> result;
768  this->getData(result);
769  data.assign(result.begin(), result.end());
770  }
771  else if (info.type == UINT8)
772  {
773  vector<uint8_t> result;
774  this->getData(result);
775  data.assign(result.begin(), result.end());
776  }
777  else if (info.type == INT16)
778  {
779  vector<int16_t> result;
780  this->getData(result);
781  data.assign(result.begin(), result.end());
782  }
783  else if (info.type == UINT16)
784  {
785  vector<uint16_t> result;
786  this->getData(result);
787  data.assign(result.begin(), result.end());
788  }
789  else if (info.type == INT32)
790  {
791  vector<int32_t> result;
792  this->getData(result);
793  data.assign(result.begin(), result.end());
794  }
795  else if (info.type == UINT32)
796  {
797  vector<uint32_t> result;
798  this->getData(result);
799  data.assign(result.begin(), result.end());
800  }
801  else
802  {
803  throw Exception("NexusFile::getDataCoerce(): Could not coerce to int.");
804  }
805 }
806 
807 void File::getDataCoerce(vector<double> &data)
808 {
809  Info info = this->getInfo();
810  if (info.type == INT8)
811  {
812  vector<int8_t> result;
813  this->getData(result);
814  data.assign(result.begin(), result.end());
815  }
816  else if (info.type == UINT8)
817  {
818  vector<uint8_t> result;
819  this->getData(result);
820  data.assign(result.begin(), result.end());
821  }
822  else if (info.type == INT16)
823  {
824  vector<int16_t> result;
825  this->getData(result);
826  data.assign(result.begin(), result.end());
827  }
828  else if (info.type == UINT16)
829  {
830  vector<uint16_t> result;
831  this->getData(result);
832  data.assign(result.begin(), result.end());
833  }
834  else if (info.type == INT32)
835  {
836  vector<int32_t> result;
837  this->getData(result);
838  data.assign(result.begin(), result.end());
839  }
840  else if (info.type == UINT32)
841  {
842  vector<uint32_t> result;
843  this->getData(result);
844  data.assign(result.begin(), result.end());
845  }
846  else if (info.type == FLOAT32)
847  {
848  vector<float> result;
849  this->getData(result);
850  data.assign(result.begin(), result.end());
851  }
852  else if (info.type == FLOAT64)
853  {
854  this->getData(data);
855  }
856  else
857  {
858  throw Exception("NexusFile::getDataCoerce(): Could not coerce to double.");
859  }
860 }
861 
862 template <typename NumT>
863 void File::readData(const std::string & dataName, std::vector<NumT>& data)
864 {
865  this->openData(dataName);
866  this->getData(data);
867  this->closeData();
868 }
869 
870 template <typename NumT>
871 void File::readData(const std::string & dataName, NumT & data)
872 {
873  std::vector<NumT> dataVector;
874  this->openData(dataName);
875  this->getData(dataVector);
876  if (dataVector.size() > 0)
877  data = dataVector[0];
878  this->closeData();
879 }
880 
881 void File::readData(const std::string & dataName, std::string& data)
882 {
883  this->openData(dataName);
884  data = this->getStrData();
885  this->closeData();
886 }
887 
889 {
890  Info info = this->getInfo();
891  switch(info.type)
892  {
893  case INT8:
894  case UINT8:
895  case INT16:
896  case UINT16:
897  case INT32:
898  case UINT32:
899  return true;
900  default:
901  return false;
902  }
903 }
904 
905 
906 
908  string res;
909  Info info = this->getInfo();
910  if (info.type != NX_CHAR) {
911  stringstream msg;
912  msg << "Cannot use getStrData() on non-character data. Found type="
913  << info.type;
914  throw Exception(msg.str());
915  }
916  if (info.dims.size() != 1) {
917  stringstream msg;
918  msg << "getStrData() only understand rank=1 data. Found rank="
919  << info.dims.size();
920  throw Exception(msg.str());
921  }
922  char* value = new char[info.dims[0]+1]; // probably do not need +1, but being safe
923  try{
924  this->getData(value);
925  }
926  catch (const Exception& e)
927  {
928  delete[] value;
929  throw e;
930  }
931  res = string(value, info.dims[0]);
932  delete[] value;
933  return res;
934 }
935 
937  //vector<int> & dims, NXnumtype & type) {
938  int64_t dims[NX_MAXRANK];
939  int type;
940  int rank;
941  NXstatus status = NXgetinfo64(this->m_file_id, &rank, dims, &type);
942  if (status != NX_OK) {
943  throw Exception("NXgetinfo failed", status);
944  }
945  Info info;
946  info.type = static_cast<NXnumtype>(type);
947  for (int i = 0; i < rank; i++) {
948  info.dims.push_back(dims[i]);
949  }
950  return info;
951 }
952 
953 pair<string, string> File::getNextEntry() {
954  // set up temporary variables to get the information
955  char name[NX_MAXNAMELEN];
956  char class_name[NX_MAXNAMELEN];
957  int datatype;
958 
959  NXstatus status = NXgetnextentry(this->m_file_id, name, class_name,
960  &datatype);
961  if (status == NX_OK) {
962  string str_name(name);
963  string str_class(class_name);
964  return pair<string,string>(str_name, str_class);
965  }
966  else if (status == NX_EOD) {
967  return pair<string,string>(NULL_STR, NULL_STR); // TODO return the correct thing
968  }
969  else {
970  throw Exception("NXgetnextentry failed", status);
971  }
972 }
973 
974 map<string, string> File::getEntries()
975 {
976  map<string, string> result;
977  this->getEntries(result);
978  return result;
979 }
980 
981 void File::getEntries(std::map<std::string, std::string> & result)
982 {
983  result.clear();
984  this->initGroupDir();
985  pair<string,string> temp;
986  while (true) {
987  temp = this->getNextEntry();
988  if (temp.first == NULL_STR && temp.second == NULL_STR) { // TODO this needs to be changed when getNextEntry is fixed
989  break;
990  }
991  else {
992  result.insert(temp);
993  }
994  }
995 }
996 
997 
998 void File::getSlab(void* data, const vector<int>& start,
999  const vector<int>& size) {
1000  this->getSlab(data, toInt64(start), toInt64(size));
1001 }
1002 
1003 void File::getSlab(void* data, const vector<int64_t>& start,
1004  const vector<int64_t>& size) {
1005  if (data == NULL) {
1006  throw Exception("Supplied null pointer to getSlab");
1007  }
1008  if (start.size() <= 0) {
1009  stringstream msg;
1010  msg << "Supplied empty start offset, rank = " << start.size()
1011  << " in getSlab";
1012  throw Exception(msg.str());
1013  }
1014  if (start.size() != size.size()) {
1015  stringstream msg;
1016  msg << "In getSlab start rank=" << start.size() << " must match size rank="
1017  << size.size();
1018  throw Exception(msg.str());
1019  }
1020 
1021  NXstatus status = NXgetslab64(this->m_file_id, data, &(start[0]), &(size[0]));
1022  if (status != NX_OK) {
1023  throw Exception("NXgetslab failed", status);
1024  }
1025 }
1026 
1028  //string & name, int & length, NXnumtype type) {
1029  char name[NX_MAXNAMELEN];
1030  int type;
1031  int length;
1032  NXstatus status = NXgetnextattr(this->m_file_id, name, &length, &type);
1033  if (status == NX_OK) {
1034  AttrInfo info;
1035  info.type = static_cast<NXnumtype>(type);
1036  info.length = length;
1037  info.name = string(name);
1038  return info;
1039  }
1040  else if (status == NX_EOD) {
1041  AttrInfo info;
1042  info.name = NULL_STR;
1043  info.length = 0;
1044  return info;
1045  }
1046  else {
1047  throw Exception("NXgetnextattr failed", status);
1048  }
1049 }
1050 
1051 void File::getAttr(const AttrInfo& info, void* data, int length) {
1052  char name[NX_MAXNAMELEN];
1053  strcpy(name, info.name.c_str());
1054  int type = info.type;
1055  if (length < 0)
1056  {
1057  length = info.length;
1058  }
1059  NXstatus status = NXgetattr(this->m_file_id, name, data, &length,
1060  &type);
1061  if (status != NX_OK) {
1062  throw Exception("NXgetattr(" + info.name + ") failed", status);
1063  }
1064  if (type != info.type) {
1065  stringstream msg;
1066  msg << "NXgetattr(" << info.name << ") changed type [" << info.type
1067  << "->" << type << "]";
1068  throw Exception(msg.str());
1069  }
1070  // char attributes are always NULL terminated and so may change length
1071  if (static_cast<unsigned>(length) != info.length && type != NX_CHAR) {
1072  stringstream msg;
1073  msg << "NXgetattr(" << info.name << ") change length [" << info.length
1074  << "->" << length << "]";
1075  throw Exception(msg.str());
1076  }
1077 }
1078 
1079 
1080 template <typename NumT>
1081 NumT File::getAttr(const AttrInfo& info) {
1082  NumT value;
1083  this->getAttr(info, &value);
1084  return value;
1085 }
1086 
1087 template <>
1088 NXDLL_EXPORT void File::getAttr(const std::string& name, std::string& value)
1089 {
1090  AttrInfo info;
1091  info.type = getType<char>();
1092  info.length = 2000;
1093  info.name = name;
1094  value = this->getStrAttr(info);
1095 }
1096 
1097 template <typename NumT>
1098 void File::getAttr(const std::string& name, NumT& value)
1099 {
1100  AttrInfo info;
1101  info.type = getType<NumT>();
1102  info.length = 1;
1103  info.name = name;
1104  value = this->getAttr<NumT>(info);
1105 }
1106 
1107 
1108 string File::getStrAttr(const AttrInfo & info) {
1109  string res;
1110  if (info.type != CHAR) {
1111  stringstream msg;
1112  msg << "getStrAttr only works with strings (type=" << CHAR
1113  << ") found type=" << info.type;
1114  throw Exception(msg.str());
1115  }
1116  char* value = new char[info.length + 1];
1117  try
1118  {
1119  this->getAttr(info, value, info.length+1);
1120  }
1121  catch (Exception& e)
1122  {
1123  //Avoid memory leak
1124  delete [] value;
1125  throw e; //re-throw
1126  }
1127 
1128  //res = string(value, info.length);
1129  //allow the constructor to find the ending point of the string. Janik Zikovsky, sep 22, 2010
1130  res = string(value);
1131  delete [] value;
1132 
1133  return res;
1134 }
1135 
1136 vector<AttrInfo> File::getAttrInfos() {
1137  vector<AttrInfo> infos;
1138  this->initAttrDir();
1139  AttrInfo temp;
1140  while(true) {
1141  temp = this->getNextAttr();
1142  if (temp.name == NULL_STR) {
1143  break;
1144  }
1145  infos.push_back(temp);
1146  }
1147  return infos;
1148 }
1149 
1150 bool File::hasAttr(const std::string & name)
1151 {
1152  this->initAttrDir();
1153  AttrInfo temp;
1154  while(true) {
1155  temp = this->getNextAttr();
1156  if (temp.name == NULL_STR) {
1157  break;
1158  }
1159  if (temp.name == name)
1160  return true;
1161  }
1162  return false;
1163 }
1164 
1165 
1167  NXlink link;
1168  NXstatus status = NXgetgroupID(this->m_file_id, &link);
1169  if (status != NX_OK) {
1170  throw Exception("NXgetgroupID failed", status);
1171  }
1172  return link;
1173 }
1174 
1175 bool File::sameID(NXlink& first, NXlink& second) {
1176  NXstatus status = NXsameID(this->m_file_id, &first, &second);
1177  return (status == NX_OK);
1178 }
1179 
1180 void File::printLink(NXlink & link) {
1181  NXstatus status = NXIprintlink(this->m_file_id, &link);
1182  if (status != NX_OK) {
1183  throw Exception("NXprintlink failed");
1184  }
1185 }
1186 
1187 void File::initGroupDir() {
1188  int status = NXinitgroupdir(this->m_file_id);
1189  if (status != NX_OK) {
1190  throw Exception("NXinitgroupdir failed", status);
1191  }
1192 }
1193 
1194 void File::initAttrDir() {
1195  int status = NXinitattrdir(this->m_file_id);
1196  if (status != NX_OK) {
1197  throw Exception("NXinitattrdir failed", status);
1198  }
1199 }
1200 
1201 void File::setNumberFormat(NXnumtype& type, const string& format) {
1202  if (format.empty()) {
1203  throw Exception("Supplied empty format to setNumberFormat");
1204  }
1205  char c_format[NX_MAXNAMELEN];
1206  strcpy(c_format, format.c_str());
1207  NXstatus status = NXsetnumberformat(this->m_file_id, type, c_format);
1208  if (status != NX_OK) {
1209  stringstream msg;
1210  msg << "NXsetnumberformat(" << format << ") failed";
1211  throw Exception(msg.str(), status);
1212  }
1213 }
1214 
1215 string File::inquireFile(const int buff_length) {
1216  string filename;
1217  char* c_filename = new char[buff_length];
1218  NXstatus status = NXinquirefile(this->m_file_id, c_filename, buff_length);
1219  if (status != NX_OK) {
1220  delete[] c_filename;
1221  stringstream msg;
1222  msg << "NXinquirefile(" << buff_length << ") failed";
1223  throw Exception(msg.str(), status);
1224  }
1225  filename = c_filename;
1226  delete[] c_filename;
1227  return filename;
1228 }
1229 
1230 string File::isExternalGroup(const string& name, const string& type,
1231  const unsigned buff_length) {
1232  string url;
1233  if (name.empty()) {
1234  throw Exception("Supplied empty name to isExternalGroup");
1235  }
1236  if (type.empty()) {
1237  throw Exception("Supplied empty type to isExternalGroup");
1238  }
1239  char* c_url = new char[buff_length];
1240  NXstatus status = NXisexternalgroup(this->m_file_id, name.c_str(),
1241  type.c_str(), c_url, buff_length);
1242  if (status != NX_OK) {
1243  delete[] c_url;
1244  stringstream msg;
1245  msg << "NXisexternalgroup(" << type << ", " << buff_length << ")";
1246  throw Exception(msg.str(), buff_length);
1247  }
1248  url = c_url;
1249  delete[] c_url;
1250  return url;
1251 }
1252 
1253 void File::linkExternal(const string& name, const string& type,
1254  const string& url) {
1255  if (name.empty()) {
1256  throw Exception("Supplied empty name to linkExternal");
1257  }
1258  if (type.empty()) {
1259  throw Exception("Supplied empty type to linkExternal");
1260  }
1261  if (url.empty()) {
1262  throw Exception("Supplied empty url to linkExternal");
1263  }
1264  NXstatus status = NXlinkexternal(this->m_file_id, name.c_str(), type.c_str(),
1265  url.c_str());
1266  if (status != NX_OK) {
1267  stringstream msg;
1268  msg << "NXlinkexternal(" << name << ", " << type << ", " << url
1269  << ") failed";
1270  throw Exception(msg.str(), status);
1271  }
1272 }
1273 
1274 const string File::makeCurrentPath(const string currpath, const string subpath) {
1275  std::ostringstream temp;
1276  temp << currpath << "/" << subpath;
1277  return temp.str();
1278 }
1279 
1280 void File::walkFileForTypeMap(const string path, const string class_name, TypeMap& tmap) {
1281  if (!path.empty()) {
1282  tmap.insert(std::make_pair(class_name, path));
1283  }
1284  map<string, string> dirents = this->getEntries();
1285  map<string, string>::iterator pos;
1286  for (pos = dirents.begin(); pos != dirents.end(); ++pos) {
1287  if (pos->second == "SDS") {
1288  tmap.insert(std::make_pair(pos->second, this->makeCurrentPath(path, pos->first)));
1289  }
1290  else if (pos->second == "CDF0.0") {
1291  // Do nothing with this
1292  ;
1293  }
1294  else {
1295  this->openGroup(pos->first, pos->second);
1296  this->walkFileForTypeMap(this->makeCurrentPath(path, pos->first), pos->second, tmap);
1297  }
1298  }
1299  this->closeGroup();
1300 }
1301 
1303  TypeMap *tmap = new TypeMap();
1304  // Ensure that we're at the top of the file.
1305  this->openPath("/");
1306  this->walkFileForTypeMap("", "", *tmap);
1307  return tmap;
1308 }
1309 
1310 template<typename NumT>
1311 void File::malloc(NumT*& data, const Info& info)
1312 {
1313  if (getType<NumT>() != info.type)
1314  {
1315  throw Exception("Type mismatch in malloc()");
1316  }
1317  inner_malloc((void*&)data, info.dims, info.type);
1318 }
1319 
1320 template<typename NumT>
1321 void File::free(NumT*& data)
1322 {
1323  inner_free((void*&)data);
1324 }
1325 
1326 }
1327 
1328 /* ---------------------------------------------------------------- */
1329 /* Concrete instantiations of template definitions. */
1330 /* ---------------------------------------------------------------- */
1331 template
1332 NXDLL_EXPORT void File::putAttr(const string& name, const float value);
1333 template
1334 NXDLL_EXPORT void File::putAttr(const string& name, const double value);
1335 template
1336 NXDLL_EXPORT void File::putAttr(const string& name, const int8_t value);
1337 template
1338 NXDLL_EXPORT void File::putAttr(const string& name, const uint8_t value);
1339 template
1340 NXDLL_EXPORT void File::putAttr(const string& name, const int16_t value);
1341 template
1342 NXDLL_EXPORT void File::putAttr(const string& name, const uint16_t value);
1343 template
1344 NXDLL_EXPORT void File::putAttr(const string& name, const int32_t value);
1345 template
1346 NXDLL_EXPORT void File::putAttr(const string& name, const uint32_t value);
1347 template
1348 NXDLL_EXPORT void File::putAttr(const string& name, const int64_t value);
1349 template
1350 NXDLL_EXPORT void File::putAttr(const string& name, const uint64_t value);
1351 template
1352 NXDLL_EXPORT void File::putAttr(const string& name, const char value);
1353 
1354 template
1355 NXDLL_EXPORT float File::getAttr(const AttrInfo& info);
1356 template
1357 NXDLL_EXPORT double File::getAttr(const AttrInfo& info);
1358 template
1359 NXDLL_EXPORT int8_t File::getAttr(const AttrInfo& info);
1360 template
1361 NXDLL_EXPORT uint8_t File::getAttr(const AttrInfo& info);
1362 template
1363 NXDLL_EXPORT int16_t File::getAttr(const AttrInfo& info);
1364 template
1365 NXDLL_EXPORT uint16_t File::getAttr(const AttrInfo& info);
1366 template
1367 NXDLL_EXPORT int32_t File::getAttr(const AttrInfo& info);
1368 template
1369 NXDLL_EXPORT uint32_t File::getAttr(const AttrInfo& info);
1370 template
1371 NXDLL_EXPORT int64_t File::getAttr(const AttrInfo& info);
1372 template
1373 NXDLL_EXPORT uint64_t File::getAttr(const AttrInfo& info);
1374 template
1375 NXDLL_EXPORT char File::getAttr(const AttrInfo& info);
1376 
1377 template
1378 NXDLL_EXPORT void File::makeData(const string & name, const NXnumtype type,
1379  const int length, bool open_data);
1380 template
1381 NXDLL_EXPORT void File::makeData(const string & name, const NXnumtype type,
1382  const int64_t length, bool open_data);
1383 
1384 template
1385 NXDLL_EXPORT void File::writeData(const string& name, const float& value);
1386 template
1387 NXDLL_EXPORT void File::writeData(const string& name, const double& value);
1388 template
1389 NXDLL_EXPORT void File::writeData(const string& name, const int8_t& value);
1390 template
1391 NXDLL_EXPORT void File::writeData(const string& name, const uint8_t& value);
1392 template
1393 NXDLL_EXPORT void File::writeData(const string& name, const int16_t& value);
1394 template
1395 NXDLL_EXPORT void File::writeData(const string& name, const uint16_t& value);
1396 template
1397 NXDLL_EXPORT void File::writeData(const string& name, const int32_t& value);
1398 template
1399 NXDLL_EXPORT void File::writeData(const string& name, const uint32_t& value);
1400 template
1401 NXDLL_EXPORT void File::writeData(const string& name, const int64_t& value);
1402 template
1403 NXDLL_EXPORT void File::writeData(const string& name, const uint64_t& value);
1404 template
1405 NXDLL_EXPORT void File::writeData(const string& name, const char& value);
1406 
1407 template
1408 NXDLL_EXPORT void File::writeData(const string& name, const vector<float>& value);
1409 template
1410 NXDLL_EXPORT void File::writeData(const string& name, const vector<double>& value);
1411 template
1412 NXDLL_EXPORT void File::writeData(const string& name, const vector<int8_t>& value);
1413 template
1414 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint8_t>& value);
1415 template
1416 NXDLL_EXPORT void File::writeData(const string& name, const vector<int16_t>& value);
1417 template
1418 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint16_t>& value);
1419 template
1420 NXDLL_EXPORT void File::writeData(const string& name, const vector<int32_t>& value);
1421 template
1422 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint32_t>& value);
1423 template
1424 NXDLL_EXPORT void File::writeData(const string& name, const vector<int64_t>& value);
1425 template
1426 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint64_t>& value);
1427 template
1428 NXDLL_EXPORT void File::writeData(const string& name, const vector<char>& value);
1429 
1430 template
1431 NXDLL_EXPORT void File::writeData(const string& name, const vector<float>& value, const std::vector<int>& dims);
1432 template
1433 NXDLL_EXPORT void File::writeData(const string& name, const vector<double>& value, const std::vector<int>& dims);
1434 template
1435 NXDLL_EXPORT void File::writeData(const string& name, const vector<int8_t>& value, const std::vector<int>& dims);
1436 template
1437 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint8_t>& value, const std::vector<int>& dims);
1438 template
1439 NXDLL_EXPORT void File::writeData(const string& name, const vector<int16_t>& value, const std::vector<int>& dims);
1440 template
1441 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint16_t>& value, const std::vector<int>& dims);
1442 template
1443 NXDLL_EXPORT void File::writeData(const string& name, const vector<int32_t>& value, const std::vector<int>& dims);
1444 template
1445 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint32_t>& value, const std::vector<int>& dims);
1446 template
1447 NXDLL_EXPORT void File::writeData(const string& name, const vector<int64_t>& value, const std::vector<int>& dims);
1448 template
1449 NXDLL_EXPORT void File::writeData(const string& name, const vector<uint64_t>& value, const std::vector<int>& dims);
1450 
1451 template
1452 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value);
1453 template
1454 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value);
1455 template
1456 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value);
1457 template
1458 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value);
1459 template
1460 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value);
1461 template
1462 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value);
1463 template
1464 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value);
1465 template
1466 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value);
1467 template
1468 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value);
1469 template
1470 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value);
1471 template
1472 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value);
1473 
1474 template
1475 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value, const int64_t chunk);
1476 template
1477 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value, const int64_t chunk);
1478 template
1479 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value, const int64_t chunk);
1480 template
1481 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value, const int64_t chunk);
1482 template
1483 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value, const int64_t chunk);
1484 template
1485 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value, const int64_t chunk);
1486 template
1487 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value, const int64_t chunk);
1488 template
1489 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value, const int64_t chunk);
1490 template
1491 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value, const int64_t chunk);
1492 template
1493 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value, const int64_t chunk);
1494 template
1495 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value, const int64_t chunk);
1496 
1497 template
1498 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1499 template
1500 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1501 template
1502 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1503 template
1504 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1505 template
1506 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1507 template
1508 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1509 template
1510 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1511 template
1512 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1513 template
1514 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1515 template
1516 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1517 template
1518 NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1519 
1520 template
1521 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<float>& value);
1522 template
1523 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<double>& value);
1524 template
1525 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int8_t>& value);
1526 template
1527 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint8_t>& value);
1528 template
1529 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int16_t>& value);
1530 template
1531 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint16_t>& value);
1532 template
1533 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int32_t>& value);
1534 template
1535 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint32_t>& value);
1536 template
1537 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int64_t>& value);
1538 template
1539 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint64_t>& value);
1540 template
1541 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<char>& value);
1542 
1543 template
1544 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<float>& value, std::vector<int64_t> & dims);
1545 template
1546 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<double>& value, std::vector<int64_t> & dims);
1547 template
1548 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int8_t>& value, std::vector<int64_t> & dims);
1549 template
1550 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint8_t>& value, std::vector<int64_t> & dims);
1551 template
1552 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int16_t>& value, std::vector<int64_t> & dims);
1553 template
1554 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint16_t>& value, std::vector<int64_t> & dims);
1555 template
1556 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int32_t>& value, std::vector<int64_t> & dims);
1557 template
1558 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint32_t>& value, std::vector<int64_t> & dims);
1559 template
1560 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int64_t>& value, std::vector<int64_t> & dims);
1561 template
1562 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint64_t>& value, std::vector<int64_t> & dims);
1563 template
1564 NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<char>& value, std::vector<int64_t> & dims);
1565 
1566 template
1567 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<float> & value,
1568  const vector<int> & dims, const NXcompression comp,
1569  const vector<int> & bufsize);
1570 template
1571 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<float> & value,
1572  const vector<int64_t> & dims, const NXcompression comp,
1573  const vector<int64_t> & bufsize);
1574 template
1575 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<double> & value,
1576  const vector<int> & dims, const NXcompression comp,
1577  const vector<int> & bufsize);
1578 template
1579 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<double> & value,
1580  const vector<int64_t> & dims, const NXcompression comp,
1581  const vector<int64_t> & bufsize);
1582 template
1583 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int8_t> & value,
1584  const vector<int> & dims, const NXcompression comp,
1585  const vector<int> & bufsize);
1586 template
1587 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int8_t> & value,
1588  const vector<int64_t> & dims, const NXcompression comp,
1589  const vector<int64_t> & bufsize);
1590 template
1591 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint8_t> & value,
1592  const vector<int> & dims, const NXcompression comp,
1593  const vector<int> & bufsize);
1594 template
1595 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint8_t> & value,
1596  const vector<int64_t> & dims, const NXcompression comp,
1597  const vector<int64_t> & bufsize);
1598 template
1599 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int16_t> & value,
1600  const vector<int> & dims, const NXcompression comp,
1601  const vector<int> & bufsize);
1602 template
1603 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int16_t> & value,
1604  const vector<int64_t> & dims, const NXcompression comp,
1605  const vector<int64_t> & bufsize);
1606 template
1607 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint16_t> & value,
1608  const vector<int> & dims, const NXcompression comp,
1609  const vector<int> & bufsize);
1610 template
1611 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint16_t> & value,
1612  const vector<int64_t> & dims, const NXcompression comp,
1613  const vector<int64_t> & bufsize);
1614 template
1615 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int32_t> & value,
1616  const vector<int> & dims, const NXcompression comp,
1617  const vector<int> & bufsize);
1618 template
1619 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int32_t> & value,
1620  const vector<int64_t> & dims, const NXcompression comp,
1621  const vector<int64_t> & bufsize);
1622 template
1623 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint32_t> & value,
1624  const vector<int> & dims, const NXcompression comp,
1625  const vector<int> & bufsize);
1626 template
1627 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint32_t> & value,
1628  const vector<int64_t> & dims, const NXcompression comp,
1629  const vector<int64_t> & bufsize);
1630 template
1631 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int64_t> & value,
1632  const vector<int> & dims, const NXcompression comp,
1633  const vector<int> & bufsize);
1634 template
1635 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<int64_t> & value,
1636  const vector<int64_t> & dims, const NXcompression comp,
1637  const vector<int64_t> & bufsize);
1638 template
1639 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint64_t> & value,
1640  const vector<int> & dims, const NXcompression comp,
1641  const vector<int> & bufsize);
1642 template
1643 NXDLL_EXPORT void File::writeCompData(const string & name, const vector<uint64_t> & value,
1644  const vector<int64_t> & dims, const NXcompression comp,
1645  const vector<int64_t> & bufsize);
1646 
1647 template
1648 NXDLL_EXPORT vector<float> * File::getData();
1649 template
1650 NXDLL_EXPORT vector<double> * File::getData();
1651 template
1652 NXDLL_EXPORT vector<int8_t> * File::getData();
1653 template
1654 NXDLL_EXPORT vector<uint8_t> * File::getData();
1655 template
1656 NXDLL_EXPORT vector<int16_t> * File::getData();
1657 template
1658 NXDLL_EXPORT vector<uint16_t> * File::getData();
1659 template
1660 NXDLL_EXPORT vector<int32_t> * File::getData();
1661 template
1662 NXDLL_EXPORT vector<uint32_t> * File::getData();
1663 template
1664 NXDLL_EXPORT vector<int64_t> * File::getData();
1665 template
1666 NXDLL_EXPORT vector<uint64_t> * File::getData();
1667 template
1668 NXDLL_EXPORT vector<char> * File::getData();
1669 
1670 template
1671 NXDLL_EXPORT void File::getData(vector<float>& data);
1672 template
1673 NXDLL_EXPORT void File::getData(vector<double>& data);
1674 template
1675 NXDLL_EXPORT void File::getData(vector<int8_t>& data);
1676 template
1677 NXDLL_EXPORT void File::getData(vector<uint8_t>& data);
1678 template
1679 NXDLL_EXPORT void File::getData(vector<int16_t>& data);
1680 template
1681 NXDLL_EXPORT void File::getData(vector<uint16_t>& data);
1682 template
1683 NXDLL_EXPORT void File::getData(vector<int32_t>& data);
1684 template
1685 NXDLL_EXPORT void File::getData(vector<uint32_t>& data);
1686 template
1687 NXDLL_EXPORT void File::getData(vector<int64_t>& data);
1688 template
1689 NXDLL_EXPORT void File::getData(vector<uint64_t>& data);
1690 template
1691 NXDLL_EXPORT void File::getData(vector<char>& data);
1692 
1693 template
1694 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<float>& data);
1695 template
1696 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<double>& data);
1697 template
1698 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int8_t>& data);
1699 template
1700 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint8_t>& data);
1701 template
1702 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int16_t>& data);
1703 template
1704 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint16_t>& data);
1705 template
1706 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int32_t>& data);
1707 template
1708 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint32_t>& data);
1709 template
1710 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int64_t>& data);
1711 template
1712 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint64_t>& data);
1713 template
1714 NXDLL_EXPORT void File::readData(const std::string & dataName, vector<char>& data);
1715 
1716 template
1717 NXDLL_EXPORT void File::readData(const std::string & dataName, float& data);
1718 template
1719 NXDLL_EXPORT void File::readData(const std::string & dataName, double& data);
1720 template
1721 NXDLL_EXPORT void File::readData(const std::string & dataName, int8_t& data);
1722 template
1723 NXDLL_EXPORT void File::readData(const std::string & dataName, uint8_t& data);
1724 template
1725 NXDLL_EXPORT void File::readData(const std::string & dataName, int16_t& data);
1726 template
1727 NXDLL_EXPORT void File::readData(const std::string & dataName, uint16_t& data);
1728 template
1729 NXDLL_EXPORT void File::readData(const std::string & dataName, int32_t& data);
1730 template
1731 NXDLL_EXPORT void File::readData(const std::string & dataName, uint32_t& data);
1732 template
1733 NXDLL_EXPORT void File::readData(const std::string & dataName, int64_t& data);
1734 template
1735 NXDLL_EXPORT void File::readData(const std::string & dataName, uint64_t& data);
1736 
1737 template
1738 NXDLL_EXPORT void File::putSlab(std::vector<float>& data, int start, int size);
1739 template
1740 NXDLL_EXPORT void File::putSlab(std::vector<double>& data, int start, int size);
1741 template
1742 NXDLL_EXPORT void File::putSlab(std::vector<int8_t>& data, int start, int size);
1743 template
1744 NXDLL_EXPORT void File::putSlab(std::vector<uint8_t>& data, int start, int size);
1745 template
1746 NXDLL_EXPORT void File::putSlab(std::vector<int16_t>& data, int start, int size);
1747 template
1748 NXDLL_EXPORT void File::putSlab(std::vector<uint16_t>& data, int start, int size);
1749 template
1750 NXDLL_EXPORT void File::putSlab(std::vector<int32_t>& data, int start, int size);
1751 template
1752 NXDLL_EXPORT void File::putSlab(std::vector<uint32_t>& data, int start, int size);
1753 template
1754 NXDLL_EXPORT void File::putSlab(std::vector<int64_t>& data, int start, int size);
1755 template
1756 NXDLL_EXPORT void File::putSlab(std::vector<uint64_t>& data, int start, int size);
1757 
1758 template
1759 NXDLL_EXPORT void File::putSlab(std::vector<float>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1760 template
1761 NXDLL_EXPORT void File::putSlab(std::vector<double>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1762 template
1763 NXDLL_EXPORT void File::putSlab(std::vector<int8_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1764 template
1765 NXDLL_EXPORT void File::putSlab(std::vector<uint8_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1766 template
1767 NXDLL_EXPORT void File::putSlab(std::vector<int16_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1768 template
1769 NXDLL_EXPORT void File::putSlab(std::vector<uint16_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1770 template
1771 NXDLL_EXPORT void File::putSlab(std::vector<int32_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1772 template
1773 NXDLL_EXPORT void File::putSlab(std::vector<uint32_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1774 template
1775 NXDLL_EXPORT void File::putSlab(std::vector<int64_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1776 template
1777 NXDLL_EXPORT void File::putSlab(std::vector<uint64_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1778 
1779 template
1780 NXDLL_EXPORT void File::getAttr(const std::string& name, double& value);
1781 template
1782 NXDLL_EXPORT void File::getAttr(const std::string& name, int& value);
1783 
1784 template
1785 NXDLL_EXPORT void File::malloc(int*& data, const Info& info);
1786 template
1787 NXDLL_EXPORT void File::malloc(float*& data, const Info& info);
1788 template
1789 NXDLL_EXPORT void File::malloc(double*& data, const Info& info);
1790 
1791 template
1792 NXDLL_EXPORT void File::free(int*& data);
1793 template
1794 NXDLL_EXPORT void File::free(float*& data);
1795 template
1796 NXDLL_EXPORT void File::free(double*& data);