source: trunk/bindings/cpp/NeXusFile.cpp @ 1822

Revision 1790, 57.1 KB checked in by Freddie Akeroyd, 6 months ago (diff)

Fix some warnings. Refs #286

  • Property svn:eol-style set to native
  • Property svn:keywords set to HeadURL LastChangedBy LastChangedRevision LastChangedDate
Line 
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
10using namespace NeXus;
11using std::map;
12using std::pair;
13using std::string;
14using std::stringstream;
15using std::vector;
16
17/**
18 * \file NeXusFile.cpp
19 * The implementation of the NeXus C++ API
20 */
21
22static const string NULL_STR = "NULL";
23
24namespace { // anonymous namespace to keep it in the file
25template <typename NumT>
26static 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
40static 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
53namespace 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
130static int check_float_too_big[4 - sizeof(float) + ARRAY_OFFSET]; // error if float > 4 bytes
131static int check_float_too_small[sizeof(float) - 4 + ARRAY_OFFSET]; // error if float < 4 bytes
132static int check_double_too_big[8 - sizeof(double) + ARRAY_OFFSET]; // error if double > 8 bytes
133static int check_double_too_small[sizeof(double) - 8 + ARRAY_OFFSET]; // error if double < 8 bytes
134static int check_char_too_big[1 - sizeof(char) + ARRAY_OFFSET]; // error if char > 1 byte
135
136namespace {
137
138static 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
151static 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
160namespace NeXus {
161File::File(NXhandle handle, bool close_handle) : m_file_id(handle), m_close_handle(close_handle) {
162}
163
164File::File(const string& filename, const NXaccess access) : m_close_handle (true) {
165  this->initOpenFile(filename, access);
166}
167
168File::File(const char *filename, const NXaccess access) : m_close_handle (true) {
169  this->initOpenFile(string(filename), access);
170}
171
172void 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
185File::~File() {
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
195void 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
205void File::flush() {
206  NXstatus status = NXflush(&(this->m_file_id));
207  if (status != NX_OK) {
208    throw Exception("NXflush failed", status);
209  }
210}
211
212void 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
231void 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
247void 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
259void 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
271std::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
284void File::closeGroup() {
285  NXstatus status = NXclosegroup(this->m_file_id);
286  if (status != NX_OK) {
287    throw Exception("NXclosegroup failed", status);
288  }
289}
290
291void 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
296void 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
321template <typename NumT>
322void 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
329template <typename NumT>
330void File::writeData(const string& name, const NumT& value) {
331  std::vector<NumT> v(1, value);
332  this->writeData(name, v);
333}
334
335void File::writeData(const string& name, const char* value) {
336  this->writeData(name, std::string(value));
337}
338
339void 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
356template <typename NumT>
357void 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
362template <typename NumT>
363void 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
370template <typename NumT>
371void 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
379template <typename NumT>
380void 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
386template <typename NumT>
387void 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
397template <typename NumT>
398void 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
414template <typename NumT>
415void 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
422template <typename NumT>
423void 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
433void 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
439void 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
481template <typename NumT>
482void 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
488template <typename NumT>
489void 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
497void File::compress(NXcompression comp) {
498  stringstream msg;
499  msg << "compress(" << comp << ") is depricated - use makeCompData()";
500  throw Exception(msg.str());
501}
502
503void 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
513void File::closeData() {
514  NXstatus status = NXclosedata(this->m_file_id);
515  if (status != NX_OK) {
516    throw Exception("NXclosedata() failed", status);
517  }
518}
519
520void 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
530template <typename NumT>
531void 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
538void 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
556template <typename NumT>
557void 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
565void 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
577void 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
588void 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
594void 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
620template <typename NumT>
621void 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
628template <typename NumT>
629void 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
637template <typename NumT>
638void 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
642template <typename NumT>
643void 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
651NXlink 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
660bool File::isDataSetOpen()
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
674void 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
681void 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
691void File::openSourceGroup() {
692  NXstatus status = NXopensourcegroup(this->m_file_id);
693  if (status != NX_OK) {
694    throw Exception("NXopensourcegroup failed");
695  }
696}
697
698void 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
708template <typename NumT>
709std::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
738template <typename NumT>
739void 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
762void 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
807void 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
862template <typename NumT>
863void File::readData(const std::string & dataName, std::vector<NumT>& data)
864{
865  this->openData(dataName);
866  this->getData(data);
867  this->closeData();
868}
869
870template <typename NumT>
871void 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
881void File::readData(const std::string & dataName, std::string& data)
882{
883  this->openData(dataName);
884  data = this->getStrData();
885  this->closeData();
886}
887
888bool File::isDataInt()
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
907string File::getStrData() {
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
936Info File::getInfo() {
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
953pair<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
974map<string, string> File::getEntries()
975{
976  map<string, string> result;
977  this->getEntries(result);
978  return result;
979}
980
981void 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
998void File::getSlab(void* data, const vector<int>& start,
999                   const vector<int>& size) {
1000  this->getSlab(data, toInt64(start), toInt64(size));
1001}
1002
1003void 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
1027AttrInfo File::getNextAttr() {
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
1051void 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
1080template <typename NumT>
1081NumT File::getAttr(const AttrInfo& info) {
1082  NumT value;
1083  this->getAttr(info, &value);
1084  return value;
1085}
1086
1087template <>
1088NXDLL_EXPORT void File::getAttr(const std::string& name, std::string& value)
1089{
1090    AttrInfo info;
1091    info.type = getType<char>();
1092    info.length = 2000; ///< @todo need to find correct length of attribute
1093    info.name = name;
1094    value = this->getStrAttr(info);
1095}
1096
1097template <typename NumT>
1098void 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
1108string 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
1136vector<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
1150bool 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
1166NXlink File::getGroupID() {
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
1175bool File::sameID(NXlink& first, NXlink& second) {
1176  NXstatus status = NXsameID(this->m_file_id, &first, &second);
1177  return (status == NX_OK);
1178}
1179
1180void 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
1187void File::initGroupDir() {
1188  int status = NXinitgroupdir(this->m_file_id);
1189  if (status != NX_OK) {
1190    throw Exception("NXinitgroupdir failed", status);
1191  }
1192}
1193
1194void File::initAttrDir() {
1195  int status = NXinitattrdir(this->m_file_id);
1196  if (status != NX_OK) {
1197    throw Exception("NXinitattrdir failed", status);
1198  }
1199}
1200
1201void 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
1215string 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
1230string 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
1253void 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
1274const string File::makeCurrentPath(const string currpath, const string subpath) {
1275        std::ostringstream temp;
1276        temp << currpath << "/" << subpath;
1277        return temp.str();
1278}
1279
1280void 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
1302TypeMap *File::getTypeMap() {
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
1310template<typename NumT>
1311void 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
1320template<typename NumT>
1321void File::free(NumT*& data)
1322{
1323    inner_free((void*&)data);
1324}
1325
1326}
1327
1328/* ---------------------------------------------------------------- */
1329/* Concrete instantiations of template definitions.                 */
1330/* ---------------------------------------------------------------- */
1331template
1332NXDLL_EXPORT void File::putAttr(const string& name, const float value);
1333template
1334NXDLL_EXPORT void File::putAttr(const string& name, const double value);
1335template
1336NXDLL_EXPORT void File::putAttr(const string& name, const int8_t value);
1337template
1338NXDLL_EXPORT void File::putAttr(const string& name, const uint8_t value);
1339template
1340NXDLL_EXPORT void File::putAttr(const string& name, const int16_t value);
1341template
1342NXDLL_EXPORT void File::putAttr(const string& name, const uint16_t value);
1343template
1344NXDLL_EXPORT void File::putAttr(const string& name, const int32_t value);
1345template
1346NXDLL_EXPORT void File::putAttr(const string& name, const uint32_t value);
1347template
1348NXDLL_EXPORT void File::putAttr(const string& name, const int64_t value);
1349template
1350NXDLL_EXPORT void File::putAttr(const string& name, const uint64_t value);
1351template
1352NXDLL_EXPORT void File::putAttr(const string& name, const char value);
1353
1354template
1355NXDLL_EXPORT float File::getAttr(const AttrInfo& info);
1356template
1357NXDLL_EXPORT double File::getAttr(const AttrInfo& info);
1358template
1359NXDLL_EXPORT int8_t File::getAttr(const AttrInfo& info);
1360template
1361NXDLL_EXPORT uint8_t  File::getAttr(const AttrInfo& info);
1362template
1363NXDLL_EXPORT int16_t File::getAttr(const AttrInfo& info);
1364template
1365NXDLL_EXPORT uint16_t  File::getAttr(const AttrInfo& info);
1366template
1367NXDLL_EXPORT int32_t File::getAttr(const AttrInfo& info);
1368template
1369NXDLL_EXPORT uint32_t  File::getAttr(const AttrInfo& info);
1370template
1371NXDLL_EXPORT int64_t File::getAttr(const AttrInfo& info);
1372template
1373NXDLL_EXPORT uint64_t  File::getAttr(const AttrInfo& info);
1374template
1375NXDLL_EXPORT char File::getAttr(const AttrInfo& info);
1376
1377template
1378NXDLL_EXPORT void File::makeData(const string & name, const NXnumtype type,
1379                                 const int length, bool open_data);
1380template
1381NXDLL_EXPORT void File::makeData(const string & name, const NXnumtype type,
1382                                 const int64_t length, bool open_data);
1383
1384template
1385NXDLL_EXPORT void File::writeData(const string& name, const float& value);
1386template
1387NXDLL_EXPORT void File::writeData(const string& name, const double& value);
1388template
1389NXDLL_EXPORT void File::writeData(const string& name, const int8_t& value);
1390template
1391NXDLL_EXPORT void File::writeData(const string& name, const uint8_t& value);
1392template
1393NXDLL_EXPORT void File::writeData(const string& name, const int16_t& value);
1394template
1395NXDLL_EXPORT void File::writeData(const string& name, const uint16_t& value);
1396template
1397NXDLL_EXPORT void File::writeData(const string& name, const int32_t& value);
1398template
1399NXDLL_EXPORT void File::writeData(const string& name, const uint32_t& value);
1400template
1401NXDLL_EXPORT void File::writeData(const string& name, const int64_t& value);
1402template
1403NXDLL_EXPORT void File::writeData(const string& name, const uint64_t& value);
1404template
1405NXDLL_EXPORT void File::writeData(const string& name, const char& value);
1406
1407template
1408NXDLL_EXPORT void File::writeData(const string& name, const vector<float>& value);
1409template
1410NXDLL_EXPORT void File::writeData(const string& name, const vector<double>& value);
1411template
1412NXDLL_EXPORT void File::writeData(const string& name, const vector<int8_t>& value);
1413template
1414NXDLL_EXPORT void File::writeData(const string& name, const vector<uint8_t>& value);
1415template
1416NXDLL_EXPORT void File::writeData(const string& name, const vector<int16_t>& value);
1417template
1418NXDLL_EXPORT void File::writeData(const string& name, const vector<uint16_t>& value);
1419template
1420NXDLL_EXPORT void File::writeData(const string& name, const vector<int32_t>& value);
1421template
1422NXDLL_EXPORT void File::writeData(const string& name, const vector<uint32_t>& value);
1423template
1424NXDLL_EXPORT void File::writeData(const string& name, const vector<int64_t>& value);
1425template
1426NXDLL_EXPORT void File::writeData(const string& name, const vector<uint64_t>& value);
1427template
1428NXDLL_EXPORT void File::writeData(const string& name, const vector<char>& value);
1429
1430template
1431NXDLL_EXPORT void File::writeData(const string& name, const vector<float>& value, const std::vector<int>& dims);
1432template
1433NXDLL_EXPORT void File::writeData(const string& name, const vector<double>& value, const std::vector<int>& dims);
1434template
1435NXDLL_EXPORT void File::writeData(const string& name, const vector<int8_t>& value, const std::vector<int>& dims);
1436template
1437NXDLL_EXPORT void File::writeData(const string& name, const vector<uint8_t>& value, const std::vector<int>& dims);
1438template
1439NXDLL_EXPORT void File::writeData(const string& name, const vector<int16_t>& value, const std::vector<int>& dims);
1440template
1441NXDLL_EXPORT void File::writeData(const string& name, const vector<uint16_t>& value, const std::vector<int>& dims);
1442template
1443NXDLL_EXPORT void File::writeData(const string& name, const vector<int32_t>& value, const std::vector<int>& dims);
1444template
1445NXDLL_EXPORT void File::writeData(const string& name, const vector<uint32_t>& value, const std::vector<int>& dims);
1446template
1447NXDLL_EXPORT void File::writeData(const string& name, const vector<int64_t>& value, const std::vector<int>& dims);
1448template
1449NXDLL_EXPORT void File::writeData(const string& name, const vector<uint64_t>& value, const std::vector<int>& dims);
1450
1451template
1452NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value);
1453template
1454NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value);
1455template
1456NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value);
1457template
1458NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value);
1459template
1460NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value);
1461template
1462NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value);
1463template
1464NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value);
1465template
1466NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value);
1467template
1468NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value);
1469template
1470NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value);
1471template
1472NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value);
1473
1474template
1475NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value, const int64_t chunk);
1476template
1477NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value, const int64_t chunk);
1478template
1479NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value, const int64_t chunk);
1480template
1481NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value, const int64_t chunk);
1482template
1483NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value, const int64_t chunk);
1484template
1485NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value, const int64_t chunk);
1486template
1487NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value, const int64_t chunk);
1488template
1489NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value, const int64_t chunk);
1490template
1491NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value, const int64_t chunk);
1492template
1493NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value, const int64_t chunk);
1494template
1495NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value, const int64_t chunk);
1496
1497template
1498NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<float>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1499template
1500NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<double>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1501template
1502NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int8_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1503template
1504NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint8_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1505template
1506NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int16_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1507template
1508NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint16_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1509template
1510NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int32_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1511template
1512NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint32_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1513template
1514NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<int64_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1515template
1516NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<uint64_t>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1517template
1518NXDLL_EXPORT void File::writeExtendibleData(const string& name, std::vector<char>& value, std::vector<int64_t> & dims, std::vector<int64_t> & chunk);
1519
1520template
1521NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<float>& value);
1522template
1523NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<double>& value);
1524template
1525NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int8_t>& value);
1526template
1527NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint8_t>& value);
1528template
1529NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int16_t>& value);
1530template
1531NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint16_t>& value);
1532template
1533NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int32_t>& value);
1534template
1535NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint32_t>& value);
1536template
1537NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int64_t>& value);
1538template
1539NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint64_t>& value);
1540template
1541NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<char>& value);
1542
1543template
1544NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<float>& value, std::vector<int64_t> & dims);
1545template
1546NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<double>& value, std::vector<int64_t> & dims);
1547template
1548NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int8_t>& value, std::vector<int64_t> & dims);
1549template
1550NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint8_t>& value, std::vector<int64_t> & dims);
1551template
1552NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int16_t>& value, std::vector<int64_t> & dims);
1553template
1554NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint16_t>& value, std::vector<int64_t> & dims);
1555template
1556NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int32_t>& value, std::vector<int64_t> & dims);
1557template
1558NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint32_t>& value, std::vector<int64_t> & dims);
1559template
1560NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<int64_t>& value, std::vector<int64_t> & dims);
1561template
1562NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<uint64_t>& value, std::vector<int64_t> & dims);
1563template
1564NXDLL_EXPORT void File::writeUpdatedData(const string& name, vector<char>& value, std::vector<int64_t> & dims);
1565
1566template
1567NXDLL_EXPORT void File::writeCompData(const string & name, const vector<float> & value,
1568                                    const vector<int> & dims, const NXcompression comp,
1569                                    const vector<int> & bufsize);
1570template
1571NXDLL_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);
1574template
1575NXDLL_EXPORT void File::writeCompData(const string & name, const vector<double> & value,
1576                                    const vector<int> & dims, const NXcompression comp,
1577                                    const vector<int> & bufsize);
1578template
1579NXDLL_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);
1582template
1583NXDLL_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);
1586template
1587NXDLL_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);
1590template
1591NXDLL_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);
1594template
1595NXDLL_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);
1598template
1599NXDLL_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);
1602template
1603NXDLL_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);
1606template
1607NXDLL_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);
1610template
1611NXDLL_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);
1614template
1615NXDLL_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);
1618template
1619NXDLL_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);
1622template
1623NXDLL_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);
1626template
1627NXDLL_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);
1630template
1631NXDLL_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);
1634template
1635NXDLL_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);
1638template
1639NXDLL_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);
1642template
1643NXDLL_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
1647template
1648NXDLL_EXPORT vector<float> * File::getData();
1649template
1650NXDLL_EXPORT vector<double> * File::getData();
1651template
1652NXDLL_EXPORT vector<int8_t> * File::getData();
1653template
1654NXDLL_EXPORT vector<uint8_t> * File::getData();
1655template
1656NXDLL_EXPORT vector<int16_t> * File::getData();
1657template
1658NXDLL_EXPORT vector<uint16_t> * File::getData();
1659template
1660NXDLL_EXPORT vector<int32_t> * File::getData();
1661template
1662NXDLL_EXPORT vector<uint32_t> * File::getData();
1663template
1664NXDLL_EXPORT vector<int64_t> * File::getData();
1665template
1666NXDLL_EXPORT vector<uint64_t> * File::getData();
1667template
1668NXDLL_EXPORT vector<char> * File::getData();
1669
1670template
1671NXDLL_EXPORT void File::getData(vector<float>& data);
1672template
1673NXDLL_EXPORT void File::getData(vector<double>& data);
1674template
1675NXDLL_EXPORT void File::getData(vector<int8_t>& data);
1676template
1677NXDLL_EXPORT void File::getData(vector<uint8_t>& data);
1678template
1679NXDLL_EXPORT void File::getData(vector<int16_t>& data);
1680template
1681NXDLL_EXPORT void File::getData(vector<uint16_t>& data);
1682template
1683NXDLL_EXPORT void File::getData(vector<int32_t>& data);
1684template
1685NXDLL_EXPORT void File::getData(vector<uint32_t>& data);
1686template
1687NXDLL_EXPORT void File::getData(vector<int64_t>& data);
1688template
1689NXDLL_EXPORT void File::getData(vector<uint64_t>& data);
1690template
1691NXDLL_EXPORT void File::getData(vector<char>& data);
1692
1693template
1694NXDLL_EXPORT void File::readData(const std::string & dataName, vector<float>& data);
1695template
1696NXDLL_EXPORT void File::readData(const std::string & dataName, vector<double>& data);
1697template
1698NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int8_t>& data);
1699template
1700NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint8_t>& data);
1701template
1702NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int16_t>& data);
1703template
1704NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint16_t>& data);
1705template
1706NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int32_t>& data);
1707template
1708NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint32_t>& data);
1709template
1710NXDLL_EXPORT void File::readData(const std::string & dataName, vector<int64_t>& data);
1711template
1712NXDLL_EXPORT void File::readData(const std::string & dataName, vector<uint64_t>& data);
1713template
1714NXDLL_EXPORT void File::readData(const std::string & dataName, vector<char>& data);
1715
1716template
1717NXDLL_EXPORT void File::readData(const std::string & dataName, float& data);
1718template
1719NXDLL_EXPORT void File::readData(const std::string & dataName, double& data);
1720template
1721NXDLL_EXPORT void File::readData(const std::string & dataName, int8_t& data);
1722template
1723NXDLL_EXPORT void File::readData(const std::string & dataName, uint8_t& data);
1724template
1725NXDLL_EXPORT void File::readData(const std::string & dataName, int16_t& data);
1726template
1727NXDLL_EXPORT void File::readData(const std::string & dataName, uint16_t& data);
1728template
1729NXDLL_EXPORT void File::readData(const std::string & dataName, int32_t& data);
1730template
1731NXDLL_EXPORT void File::readData(const std::string & dataName, uint32_t& data);
1732template
1733NXDLL_EXPORT void File::readData(const std::string & dataName, int64_t& data);
1734template
1735NXDLL_EXPORT void File::readData(const std::string & dataName, uint64_t& data);
1736
1737template
1738NXDLL_EXPORT void File::putSlab(std::vector<float>& data, int start, int size);
1739template
1740NXDLL_EXPORT void File::putSlab(std::vector<double>& data, int start, int size);
1741template
1742NXDLL_EXPORT void File::putSlab(std::vector<int8_t>& data, int start, int size);
1743template
1744NXDLL_EXPORT void File::putSlab(std::vector<uint8_t>& data, int start, int size);
1745template
1746NXDLL_EXPORT void File::putSlab(std::vector<int16_t>& data, int start, int size);
1747template
1748NXDLL_EXPORT void File::putSlab(std::vector<uint16_t>& data, int start, int size);
1749template
1750NXDLL_EXPORT void File::putSlab(std::vector<int32_t>& data, int start, int size);
1751template
1752NXDLL_EXPORT void File::putSlab(std::vector<uint32_t>& data, int start, int size);
1753template
1754NXDLL_EXPORT void File::putSlab(std::vector<int64_t>& data, int start, int size);
1755template
1756NXDLL_EXPORT void File::putSlab(std::vector<uint64_t>& data, int start, int size);
1757
1758template
1759NXDLL_EXPORT void File::putSlab(std::vector<float>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1760template
1761NXDLL_EXPORT void File::putSlab(std::vector<double>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1762template
1763NXDLL_EXPORT void File::putSlab(std::vector<int8_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1764template
1765NXDLL_EXPORT void File::putSlab(std::vector<uint8_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1766template
1767NXDLL_EXPORT void File::putSlab(std::vector<int16_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1768template
1769NXDLL_EXPORT void File::putSlab(std::vector<uint16_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1770template
1771NXDLL_EXPORT void File::putSlab(std::vector<int32_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1772template
1773NXDLL_EXPORT void File::putSlab(std::vector<uint32_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1774template
1775NXDLL_EXPORT void File::putSlab(std::vector<int64_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1776template
1777NXDLL_EXPORT void File::putSlab(std::vector<uint64_t>& data, std::vector<int64_t> & start, std::vector<int64_t> & size);
1778
1779template 
1780NXDLL_EXPORT void File::getAttr(const std::string& name, double& value);
1781template 
1782NXDLL_EXPORT void File::getAttr(const std::string& name, int& value);
1783
1784template
1785NXDLL_EXPORT void File::malloc(int*& data, const Info& info);
1786template
1787NXDLL_EXPORT void File::malloc(float*& data, const Info& info);
1788template
1789NXDLL_EXPORT void File::malloc(double*& data, const Info& info);
1790
1791template
1792NXDLL_EXPORT void File::free(int*& data);
1793template
1794NXDLL_EXPORT void File::free(float*& data);
1795template
1796NXDLL_EXPORT void File::free(double*& data);
Note: See TracBrowser for help on using the repository browser.