1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDS_Tool.cxx
24 // Created : Mon Oct 21 16:24:34 2002
25 // Author : Sergey RUIN
44 #define dir_separator '\\'
46 #define dir_separator '/'
49 void Move(const std::string& fName, const std::string& fNameDst);
50 bool Exists(const std::string thePath);
51 bool CreateAttributeFromASCII(HDFinternalObject *father, FILE* fp);
52 bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp);
53 bool CreateGroupFromASCII(HDFcontainerObject *father, FILE *fp);
55 void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident);
56 void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident);
57 void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident);
59 std::string GetTmpDir();
60 char* makeName(char* name);
61 char* restoreName(char* name);
62 void write_float64(FILE* fp, hdf_float64* value);
63 void read_float64(FILE* fp, hdf_float64* value);
65 void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size );
67 #define MAX_STRING_SIZE 65535
68 #define MAX_ID_SIZE 20
69 #define NB_FLOAT_IN_ROW 3
70 #define NB_INTEGER_IN_ROW 9
72 #define ASCIIHDF_ID "ASCIIHDF"
73 #define ATTRIBUTE_ID "ATTRIBUTE"
74 #define DATASET_ID "DATASET"
75 #define GROUP_ID "GROUP"
77 #define ASCIIHDF_ID_END "ASCIIHDF_END"
78 #define ATTRIBUTE_ID_END "ATTRIBUTE_END"
79 #define DATASET_ID_END "DATASET_END"
80 #define GROUP_ID_END "GROUP_END"
83 //============================================================================
85 // purpose : Returns True if the file is a converted to ASCII HDF file
86 //============================================================================
87 bool HDFascii::isASCII(const char* thePath) {
89 if(!(fd = open(thePath, O_RDONLY))) return false;
90 char* aBuffer = new char[9];
95 bool res = (strcmp(aBuffer, ASCIIHDF_ID) == 0);
102 //############################## HDF => ASCII ################################
104 //============================================================================
105 // function : ConvertFromHDFToASCII
106 // purpose : Converts a file pointed by thePath to ASCII format
107 // If isReplace is true the newly created file will replace the existent one.
108 // If isReplace is false theExtension will be added to a created file name
109 // Returns the file name of ASCII file
110 //============================================================================
111 char* HDFascii::ConvertFromHDFToASCII(const char* thePath,
113 const char* theExtension)
115 std::string aPath(thePath);
117 if(theExtension == NULL) aPath += ".asc";
118 else aPath += (char*)theExtension;
121 std::string aFileName(aPath);
122 if(isReplace) aFileName=aPath+".ascii_tmp";
124 HDFfile *hdf_file = new HDFfile((char*)thePath);
125 hdf_file->OpenOnDisk(HDF_RDONLY);
127 char name[HDF_NAME_MAX_LEN+1];
128 int nbsons = hdf_file->nInternalObjects(), nbAttr = hdf_file->nAttributes();
130 FILE* fp = fopen(aFileName.c_str(), "wb");
131 fprintf(fp, "%s\n", ASCIIHDF_ID);
132 fprintf(fp, "%i\n", nbsons+nbAttr);
134 for(int j=0; j<nbAttr; j++) {
135 char* attr_name = hdf_file->GetAttributeName(j);
136 HDFattribute *hdf_attribute = new HDFattribute(attr_name, hdf_file);
138 SaveAttributeInASCIIfile(hdf_attribute, fp, 0);
142 for (int i=0; i<nbsons; i++) {
143 hdf_file->InternalObjectIndentify(i,name);
144 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
146 hdf_object_type type = hdf_file->InternalObjectType(name);
148 if(type == HDF_DATASET) {
149 HDFdataset* hdf_dataset = new HDFdataset(name, hdf_file);
150 SaveDatasetInASCIIfile(hdf_dataset, fp, 0);
152 } else if(type == HDF_GROUP) {
153 HDFgroup *hdf_group = new HDFgroup(name, hdf_file);
154 SaveGroupInASCIIfile(hdf_group, fp, 0);
159 fprintf(fp, "%s", ASCIIHDF_ID_END);
163 hdf_file->CloseOnDisk();
167 if(Exists(aFileName))
168 Move(aFileName, aPath);
173 int length = strlen(aPath.c_str());
174 char *new_str = new char[ 1+length ];
175 strcpy(new_str , aPath.c_str()) ;
181 //============================================================================
182 // function : SaveGroupInASCIIfile
184 //============================================================================
185 void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident)
187 hdf_group->OpenOnDisk();
189 int nbsons = hdf_group->nInternalObjects(), nbAttr = hdf_group->nAttributes();
191 fprintf(fp, "%s\n", GROUP_ID);
193 char* name = makeName(hdf_group->GetName());
195 fprintf(fp, "%s %i\n", name, nbsons+nbAttr);
198 for(int j=0; j<nbAttr; j++) {
199 name = hdf_group->GetAttributeName(j);
200 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_group);
202 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
206 char objName[HDF_NAME_MAX_LEN+1];
208 for (int i=0; i<nbsons; i++) {
209 hdf_group->InternalObjectIndentify(i, objName);
211 if (strncmp(objName, "INTERNAL_COMPLEX",16) == 0) continue;
213 hdf_object_type type = hdf_group->InternalObjectType(objName);
215 if (type == HDF_DATASET) {
216 HDFdataset* hdf_dataset = new HDFdataset(objName, hdf_group);
217 SaveDatasetInASCIIfile(hdf_dataset, fp, ident+1);
219 } else if (type == HDF_GROUP) {
220 HDFgroup *hdf_subgroup = new HDFgroup(objName, hdf_group);
221 SaveGroupInASCIIfile(hdf_subgroup, fp, ident+1);
226 fprintf(fp, "%s\n", GROUP_ID_END);
228 hdf_group->CloseOnDisk();
231 //============================================================================
232 // function : SaveDatasetInASCIIfile
234 //============================================================================
235 void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident)
237 hdf_dataset->OpenOnDisk();
239 long size = (long) hdf_dataset->GetSize();
240 long ndim = hdf_dataset->nDim(); //Get number of dimesions
241 hdf_size *dim = new hdf_size[ndim];
242 hdf_type type = hdf_dataset->GetType();
243 hdf_byte_order order = hdf_dataset->GetOrder();
244 int nbAttr = hdf_dataset->nAttributes();
246 char* name = makeName(hdf_dataset->GetName());
248 fprintf(fp, "%s\n", DATASET_ID);
249 fprintf(fp, "%s %i %i\n", name, type, nbAttr);
252 hdf_dataset->GetDim(dim);
253 fprintf(fp, " %i\n", ndim);
255 for(int i = 0;i < ndim;i++) {
256 fprintf(fp, " %i", dim[i]);
262 fprintf(fp, "%li %i:", size, order);
263 if( type == HDF_ARRAY ) {
264 HDFarray *array = new HDFarray(hdf_dataset);
265 hdf_type data_type = array->GetDataType();
267 fprintf(fp, " %i\n", data_type ); //Write array data type
269 //Write nDim of the array
270 int arr_ndim = array->nDim();
271 fprintf(fp, " %i\n", arr_ndim);
272 hdf_size *arr_dim = new hdf_size[arr_ndim];
273 array->GetDim(arr_dim);
275 for( int i = 0;i < arr_ndim; i++ ) {
276 fprintf(fp, " %i", arr_dim[i]);
279 //And write the data array
280 WriteSimpleData( fp, hdf_dataset, data_type, size);
282 WriteSimpleData( fp, hdf_dataset, type, size);
287 for ( int j=0; j<nbAttr; j++ )
289 name = hdf_dataset->GetAttributeName(j);
290 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_dataset);
292 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
296 fprintf(fp, "%s\n", DATASET_ID_END);
298 hdf_dataset->CloseOnDisk();
302 //============================================================================
303 // function : SaveAttributeInASCIIfile
305 //============================================================================
306 void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident)
308 hdf_attribute->OpenOnDisk();
310 hdf_type type = hdf_attribute->GetType();
312 char* name = makeName(hdf_attribute->GetName());
313 int size = hdf_attribute->GetSize();
315 fprintf(fp, "%s\n", ATTRIBUTE_ID);
316 fprintf(fp, "%s %i %i\n", name, type, size);
320 if (type == HDF_STRING) {
321 char* val = new char[size+1];
322 hdf_attribute->ReadFromDisk(val);
324 fwrite(val, 1, size, fp);
327 } else if (type == HDF_FLOAT64) {
329 hdf_attribute->ReadFromDisk(&val);
330 write_float64(fp, &val);
332 } else if(type == HDF_INT64) {
334 hdf_attribute->ReadFromDisk(&val);
335 fprintf(fp, "%li \n", val);
336 } else if(type == HDF_INT32) {
338 hdf_attribute->ReadFromDisk(&val);
339 fprintf(fp, "%i \n", val);
342 fprintf(fp, "%s\n", ATTRIBUTE_ID_END);
344 hdf_attribute->CloseOnDisk();
347 //############################## ASCII => HDF ################################
349 //============================================================================
350 // function : ConvertFromASCIIToHDF
351 // purpose : Converts a file pointed by thePath to HDF format
352 // Returns a name of directory where a created HDF file is placed
353 // The created file is named "hdf_from_ascii.hdf"
354 //============================================================================
355 char* HDFascii::ConvertFromASCIIToHDF(const char* thePath,
358 std::string aTmpDir, aFullName;
360 // Get a temporary directory to store a file
361 aTmpDir = GetTmpDir();
362 // Build a full file name of temporary file
363 aFullName = aTmpDir + "hdf_from_ascii.hdf";
367 aFullName = std::string(thePath)+".ascii_tmp";
370 FILE *fp = fopen(thePath, "rb");
373 HDFfile *hdf_file = new HDFfile((char*)aFullName.c_str());
374 hdf_file->CreateOnDisk();
378 fscanf(fp, "%s", type);
379 fscanf(fp, "%i",&nbsons);
381 if(strcmp(type, ASCIIHDF_ID) != 0) return NULL;
383 for(i = 0; i < nbsons; i++) {
384 char id_of_begin[MAX_ID_SIZE];
385 fscanf(fp, "%s\n", id_of_begin);
387 if(strcmp(id_of_begin, GROUP_ID) == 0) {
388 if(!CreateGroupFromASCII(hdf_file, fp)) {
389 std::cout << "ConvertFromASCIIToHDF : Can not create group number " << i << std::endl;
393 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
394 if(!CreateDatasetFromASCII(hdf_file, fp)) {
395 std::cout << "ConvertFromASCIIToHDF :Can not create dataset number " << i << std::endl;
399 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
400 if(!CreateAttributeFromASCII(hdf_file, fp)) {
401 std::cout << "ConvertFromASCIIToHDF :Can not create attribute number " << i << std::endl;
406 std::cout << "ConvertFromASCIIToHDF : Unrecognized type " << id_of_begin << std::endl;
409 char id_of_end[MAX_ID_SIZE];
410 fscanf(fp, "%s", id_of_end);
411 if(strcmp(id_of_end, ASCIIHDF_ID_END) != 0) {
412 std::cout << "ConvertFromASCIIToHDF : Can not find the end ASCII token " << std::endl;
416 hdf_file->CloseOnDisk();
420 if(Exists(aFullName))
421 Move(aFullName, thePath);
426 int length = strlen(aTmpDir.c_str());
427 char *new_str = new char[ 1+length ];
428 strcpy(new_str , aTmpDir.c_str()) ;
436 //============================================================================
437 // function : CreateGroupFromASCII
438 // purpose : Creates a HDF group from a set attributes situated under theLabel
439 //============================================================================
440 bool CreateGroupFromASCII(HDFcontainerObject *father, FILE *fp)
442 char name[HDF_NAME_MAX_LEN+1];
444 fscanf(fp, "%s %i\n", name, &nbsons);
446 char* new_name = restoreName(name);
448 HDFgroup* hdf_group = new HDFgroup(new_name, father);
452 hdf_group->CreateOnDisk();
454 for(i = 0; i < nbsons; i++) {
455 char id_of_begin[MAX_ID_SIZE];
456 fscanf(fp, "%s\n", id_of_begin);
458 if(strcmp(id_of_begin, GROUP_ID) == 0) {
459 if(!CreateGroupFromASCII(hdf_group, fp)) {
460 std::cout << "Can not create subgroup " << i << " for group " << name << std::endl;
464 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
465 if(!CreateDatasetFromASCII(hdf_group, fp)) {
466 std::cout << "Can not create dataset " << i << " for group " << name << std::endl;
470 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
471 if(!CreateAttributeFromASCII(hdf_group, fp)) {
472 std::cout << "Can not create attribute " << i << " for group " << name << std::endl;
477 std::cout << "CreateGroupFromASCII : Unrecognized type " << id_of_begin << std::endl;
480 hdf_group->CloseOnDisk();
481 hdf_group = 0; //will be deleted by father destructor
483 char id_of_end[MAX_ID_SIZE];
484 fscanf(fp, "%s\n", id_of_end);
485 if(strcmp(id_of_end, GROUP_ID_END) != 0) {
486 std::cout << "CreateGroupFromASCII : Invalid end token : " << id_of_end << std::endl;
494 //============================================================================
495 // function : CreateDatasetFromASCII
496 // purpose : Creates a HDF dataset from a set attributes situated under theLabel
497 //============================================================================
498 bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp)
500 char name[HDF_NAME_MAX_LEN+1];
502 hdf_byte_order order;
506 fscanf(fp, "%s %i %i\n", name, &type, &nbAttr);
507 char* new_name = restoreName(name);
509 fscanf(fp, "%i\n", &nbDim);
511 hdf_size* sizeArray = new hdf_size[nbDim];
513 for(i = 0; i<nbDim; i++) {
514 fscanf(fp, "%i\n", &dim);
518 // order (2-d member) was not written in earlier versions
520 int nbRead = fscanf(fp, "%li %i%c", &size, &order, &tmp);
521 if ( nbRead < 2 ) { // fscanf stops before ":"
522 fscanf(fp, "%c", &tmp);
523 order = H5T_ORDER_NONE;
525 if ( type != HDF_FLOAT64 ) // use order only for FLOAT64
526 order = H5T_ORDER_NONE;
529 HDFarray* anArray = 0;
530 if( type == HDF_ARRAY ){
531 //Get array information
532 hdf_type arr_data_type;
534 fscanf(fp, "%c", &tmp);
535 fscanf(fp, " %i\n", &arr_data_type ); //Get array data type
536 fscanf(fp, " %i\n", &arr_ndim ); //Get array nDim
537 hdf_size *arr_dim = new hdf_size[arr_ndim];
540 for( int i = 0;i < arr_ndim; i++ ) {
541 fscanf(fp, " %i", &tdim);
544 anArray = new HDFarray(0, arr_data_type, arr_ndim, arr_dim);
545 anArray->CreateOnDisk();
547 type = arr_data_type;
551 HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : type, sizeArray, nbDim, order);
554 hdf_dataset->SetArrayId(anArray->GetId());
559 hdf_dataset->CreateOnDisk();
561 if (type == HDF_STRING) {
562 char *val = new char[size+1];
563 fread(val, 1, size, fp);
564 hdf_dataset->WriteOnDisk(val);
566 } else if (type == HDF_FLOAT64) {
567 hdf_float64* val = new hdf_float64[size];
568 for(i=0; i<size; i++) {
569 read_float64(fp, &(val[i]));
571 hdf_dataset->WriteOnDisk(val);
573 } else if(type == HDF_INT64) {
574 hdf_int64* val = new hdf_int64[size];
575 for(i=0; i<size; i++) {
576 fscanf(fp, " %li", &(val[i]));
578 hdf_dataset->WriteOnDisk(val);
580 } else if(type == HDF_INT32) {
581 hdf_int32* val = new hdf_int32[size];
582 for(i=0; i<size; i++) {
583 fscanf(fp, " %i", &(val[i]));
585 hdf_dataset->WriteOnDisk(val);
587 } else if(type == HDF_CHAR) {
588 hdf_char* val = new hdf_char[size];
589 for(i=0; i<size; i++) {
590 fscanf(fp, " %i", &(val[i]));
592 hdf_dataset->WriteOnDisk(val);
596 char token[MAX_ID_SIZE];
598 for(i = 0; i < nbAttr; i++) {
599 fscanf(fp, "%s\n", token);
601 if(strcmp(token, ATTRIBUTE_ID) == 0) {
602 if(!CreateAttributeFromASCII(hdf_dataset, fp)) {
603 std::cout << "Can not create attribute " << i << " for dataset " << name << std::endl;
608 std::cout << "CreateGroupFromASCII : Unrecognized type " << token << std::endl;
613 fscanf(fp, "%s\n", token);
614 if(strcmp(token, DATASET_ID_END) != 0) {
615 std::cout << "CreateDatasetFromASCII : Invalid end token : " << token << std::endl;
619 hdf_dataset->CloseOnDisk();
620 hdf_dataset = 0; //will be deleted by father destructor
623 anArray->CloseOnDisk();
624 anArray = 0; //will be deleted by father destructor
631 //============================================================================
632 // function : CreateAttributeFromASCII
633 // purpose : Creates a HDF attribute from a set attributes situated under theLabel
634 //============================================================================
635 bool CreateAttributeFromASCII(HDFinternalObject *father, FILE* fp)
637 char name[HDF_NAME_MAX_LEN+1];
641 fscanf(fp, "%s %i %i\n", name, &type, &size);
642 char* new_name = restoreName(name);
643 HDFattribute* hdf_attribute = new HDFattribute(new_name, father, type, size);
645 hdf_attribute->CreateOnDisk();
649 if (type == HDF_STRING) {
651 fscanf(fp, "%c", &tmp);
652 char *val = new char[size+1];
654 fread(val, 1, size, fp);
655 hdf_attribute->WriteOnDisk(val);
657 } else if (type == HDF_FLOAT64) {
659 read_float64(fp, &val);
660 hdf_attribute->WriteOnDisk(&val);
661 } else if(type == HDF_INT64) {
663 fscanf(fp, "%li", &val);
664 hdf_attribute->WriteOnDisk(&val);
665 } else if(type == HDF_INT32) {
667 fscanf(fp, "%i", &val);
668 hdf_attribute->WriteOnDisk(&val);
671 hdf_attribute->CloseOnDisk();
672 hdf_attribute = 0; //will be deleted by father destructor
675 char id_of_end[MAX_ID_SIZE];
676 fscanf(fp, "%s\n", id_of_end);
677 if(strcmp(id_of_end, ATTRIBUTE_ID_END) != 0) {
678 std::cout << "CreateAttributeFromASCII : Invalid end token : " << id_of_end << std::endl;
686 //============================================================================
687 // function : GetTempDir
688 // purpose : Return a temp directory to store created files like "/tmp/sub_dir/"
689 //============================================================================
690 std::string GetTmpDir()
692 //Find a temporary directory to store a file
694 char *Tmp_dir = getenv("SALOME_TMP_DIR");
695 if(Tmp_dir != NULL) {
696 aTmpDir = std::string(Tmp_dir);
697 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
701 aTmpDir = std::string("C:\\");
703 aTmpDir = std::string("/tmp/");
707 srand((unsigned int)time(NULL));
708 int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
710 sprintf(buffer, "%d", aRND);
711 std:: string aSubDir(buffer);
712 if(aSubDir.size() <= 1) aSubDir = std::string("123409876");
714 aTmpDir += aSubDir; //Get RND sub directory
716 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
718 std::string aDir = aTmpDir;
720 for(aRND = 0; Exists(aDir); aRND++) {
721 sprintf(buffer, "%d", aRND);
722 aDir = aTmpDir+buffer; //Build a unique directory name
726 //fuction CreateDirectory create only final directory, but not intermediate
727 CreateDirectory(aTmpDir.c_str(), NULL);
728 CreateDirectory(aDir.c_str(), NULL);
730 mkdir(aDir.c_str(), 0x1ff);
733 return aDir + dir_separator;
736 char* makeName(char* name)
738 std::string aName(name), aNewName;
739 int i, length = aName.size();
740 char replace = (char)19;
742 for(i=0; i<length; i++) {
743 if(aName[i] == ' ') aNewName+=replace;
744 else aNewName += aName[i];
747 length = strlen(aNewName.c_str());
748 char *new_str = new char[ 1+length ];
749 strcpy(new_str , aNewName.c_str()) ;
753 char* restoreName(char* name)
755 std::string aName(name), aNewName;
756 int i, length = aName.size();
757 char replace = (char)19;
759 for(i=0; i<length; i++) {
760 if(aName[i] == replace) aNewName+=' ';
761 else aNewName += aName[i];
764 length = strlen(aNewName.c_str());
765 char *new_str = new char[ 1+length ];
766 strcpy(new_str , aNewName.c_str()) ;
770 void write_float64(FILE* fp, hdf_float64* value)
772 unsigned char* array = (unsigned char*)value;
773 for(int i = 0; i < sizeof(hdf_float64); i++) {
774 unsigned tmp = (unsigned short)array[i];
775 fprintf(fp, " %2x", tmp);
779 void read_float64(FILE* fp, hdf_float64* value)
781 unsigned char* array = (unsigned char*)value;
782 for(int i = 0; i < sizeof(hdf_float64); i++) {
784 fscanf(fp, " %x", &tmp);
785 array[i] = (unsigned char)tmp;
789 bool Exists(const std::string thePath)
792 if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
793 DWORD errorId = GetLastError ();
794 if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
798 int status = access ( thePath.c_str() , F_OK );
799 if (status != 0) return false;
804 void Move(const std::string& fName, const std::string& fNameDst)
807 MoveFileEx (fName.c_str(), fNameDst.c_str(),MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
809 rename(fName.c_str(), fNameDst.c_str());
813 void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size ) {
814 if (type == HDF_STRING) {
815 char* val = new char[size];
816 hdf_dataset->ReadFromDisk(val);
817 fwrite(val, 1, size, fp);
819 } else if (type == HDF_FLOAT64) {
820 hdf_float64* val = new hdf_float64[size];
821 hdf_dataset->ReadFromDisk(val);
823 for (int i = 0, j = 0; i < size; i++) {
824 write_float64(fp, &val[i]);
825 if(++j == NB_FLOAT_IN_ROW) {
829 else fprintf(fp," ");
832 } else if(type == HDF_INT64) {
833 hdf_int64* val = new hdf_int64[size];
834 hdf_dataset->ReadFromDisk(val);
836 for (int i = 0, j = 0; i < size; i++) {
837 fprintf(fp, " %li", val[i]);
838 if(++j == NB_INTEGER_IN_ROW) {
844 } else if(type == HDF_INT32) {
845 hdf_int32* val = new hdf_int32[size];
846 hdf_dataset->ReadFromDisk(val);
848 for (int i = 0, j = 0; i < size; i++) {
849 fprintf(fp, " %i", val[i]);
850 if(++j == NB_INTEGER_IN_ROW) {
856 }else if(type == HDF_CHAR) {
857 hdf_char* val = new hdf_char[size];
858 hdf_dataset->ReadFromDisk(val);
860 for (int i = 0, j = 0; i < size; i++) {
861 fprintf(fp, " %i", val[i]);
862 if(++j == NB_INTEGER_IN_ROW) {