1 // Copyright (C) 2007-2011 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.
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 if(strcmp(aBuffer, ASCIIHDF_ID) == 0) return true;
100 //############################## HDF => ASCII ################################
102 //============================================================================
103 // function : ConvertFromHDFToASCII
104 // purpose : Converts a file pointed by thePath to ASCII format
105 // If isReplace is true the newly created file will replace the existent one.
106 // If isReplace is false theExtension will be added to a created file name
107 // Returns the file name of ASCII file
108 //============================================================================
109 char* HDFascii::ConvertFromHDFToASCII(const char* thePath,
111 const char* theExtension)
113 std::string aPath(thePath);
115 if(theExtension == NULL) aPath += ".asc";
116 else aPath += (char*)theExtension;
119 std::string aFileName(aPath);
120 if(isReplace) aFileName=aPath+".ascii_tmp";
122 HDFfile *hdf_file = new HDFfile((char*)thePath);
123 hdf_file->OpenOnDisk(HDF_RDONLY);
125 char name[HDF_NAME_MAX_LEN+1];
126 int nbsons = hdf_file->nInternalObjects(), nbAttr = hdf_file->nAttributes();
128 FILE* fp = fopen(aFileName.c_str(), "wb");
129 fprintf(fp, "%s\n", ASCIIHDF_ID);
130 fprintf(fp, "%i\n", nbsons+nbAttr);
132 for(int j=0; j<nbAttr; j++) {
133 char* attr_name = hdf_file->GetAttributeName(j);
134 HDFattribute *hdf_attribute = new HDFattribute(attr_name, hdf_file);
136 SaveAttributeInASCIIfile(hdf_attribute, fp, 0);
140 for (int i=0; i<nbsons; i++) {
141 hdf_file->InternalObjectIndentify(i,name);
142 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
144 hdf_object_type type = hdf_file->InternalObjectType(name);
146 if(type == HDF_DATASET) {
147 HDFdataset* hdf_dataset = new HDFdataset(name, hdf_file);
148 SaveDatasetInASCIIfile(hdf_dataset, fp, 0);
150 } else if(type == HDF_GROUP) {
151 HDFgroup *hdf_group = new HDFgroup(name, hdf_file);
152 SaveGroupInASCIIfile(hdf_group, fp, 0);
157 fprintf(fp, "%s", ASCIIHDF_ID_END);
161 hdf_file->CloseOnDisk();
165 if(Exists(aFileName))
166 Move(aFileName, aPath);
171 int length = strlen(aPath.c_str());
172 char *new_str = new char[ 1+length ];
173 strcpy(new_str , aPath.c_str()) ;
179 //============================================================================
180 // function : SaveGroupInASCIIfile
182 //============================================================================
183 void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident)
185 hdf_group->OpenOnDisk();
187 int nbsons = hdf_group->nInternalObjects(), nbAttr = hdf_group->nAttributes();
189 fprintf(fp, "%s\n", GROUP_ID);
191 char* name = makeName(hdf_group->GetName());
193 fprintf(fp, "%s %i\n", name, nbsons+nbAttr);
196 for(int j=0; j<nbAttr; j++) {
197 name = hdf_group->GetAttributeName(j);
198 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_group);
200 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
204 char objName[HDF_NAME_MAX_LEN+1];
206 for (int i=0; i<nbsons; i++) {
207 hdf_group->InternalObjectIndentify(i, objName);
209 if (strncmp(objName, "INTERNAL_COMPLEX",16) == 0) continue;
211 hdf_object_type type = hdf_group->InternalObjectType(objName);
213 if (type == HDF_DATASET) {
214 HDFdataset* hdf_dataset = new HDFdataset(objName, hdf_group);
215 SaveDatasetInASCIIfile(hdf_dataset, fp, ident+1);
217 } else if (type == HDF_GROUP) {
218 HDFgroup *hdf_subgroup = new HDFgroup(objName, hdf_group);
219 SaveGroupInASCIIfile(hdf_subgroup, fp, ident+1);
224 fprintf(fp, "%s\n", GROUP_ID_END);
226 hdf_group->CloseOnDisk();
229 //============================================================================
230 // function : SaveDatasetInASCIIfile
232 //============================================================================
233 void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident)
235 hdf_dataset->OpenOnDisk();
237 long size = (long) hdf_dataset->GetSize();
238 long ndim = hdf_dataset->nDim(); //Get number of dimesions
239 hdf_size *dim = new hdf_size[ndim];
240 hdf_type type = hdf_dataset->GetType();
241 hdf_byte_order order = hdf_dataset->GetOrder();
242 int nbAttr = hdf_dataset->nAttributes();
244 char* name = makeName(hdf_dataset->GetName());
246 fprintf(fp, "%s\n", DATASET_ID);
247 fprintf(fp, "%s %i %i\n", name, type, nbAttr);
250 hdf_dataset->GetDim(dim);
251 fprintf(fp, " %i\n", ndim);
253 for(int i = 0;i < ndim;i++) {
254 fprintf(fp, " %i", dim[i]);
260 fprintf(fp, "%li %i:", size, order);
261 if( type == HDF_ARRAY ) {
262 HDFarray *array = new HDFarray(hdf_dataset);
263 hdf_type data_type = array->GetDataType();
265 fprintf(fp, " %i\n", data_type ); //Write array data type
267 //Write nDim of the array
268 int arr_ndim = array->nDim();
269 fprintf(fp, " %i\n", arr_ndim);
270 hdf_size *arr_dim = new hdf_size[arr_ndim];
271 array->GetDim(arr_dim);
273 for( int i = 0;i < arr_ndim; i++ ) {
274 fprintf(fp, " %i", arr_dim[i]);
277 //And write the data array
278 WriteSimpleData( fp, hdf_dataset, data_type, size);
280 WriteSimpleData( fp, hdf_dataset, type, size);
285 for ( int j=0; j<nbAttr; j++ )
287 name = hdf_dataset->GetAttributeName(j);
288 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_dataset);
290 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
294 fprintf(fp, "%s\n", DATASET_ID_END);
296 hdf_dataset->CloseOnDisk();
300 //============================================================================
301 // function : SaveAttributeInASCIIfile
303 //============================================================================
304 void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident)
306 hdf_attribute->OpenOnDisk();
308 hdf_type type = hdf_attribute->GetType();
310 char* name = makeName(hdf_attribute->GetName());
311 int size = hdf_attribute->GetSize();
313 fprintf(fp, "%s\n", ATTRIBUTE_ID);
314 fprintf(fp, "%s %i %i\n", name, type, size);
318 if (type == HDF_STRING) {
319 char* val = new char[size+1];
320 hdf_attribute->ReadFromDisk(val);
322 fwrite(val, 1, size, fp);
325 } else if (type == HDF_FLOAT64) {
327 hdf_attribute->ReadFromDisk(&val);
328 write_float64(fp, &val);
330 } else if(type == HDF_INT64) {
332 hdf_attribute->ReadFromDisk(&val);
333 fprintf(fp, "%li \n", val);
334 } else if(type == HDF_INT32) {
336 hdf_attribute->ReadFromDisk(&val);
337 fprintf(fp, "%i \n", val);
340 fprintf(fp, "%s\n", ATTRIBUTE_ID_END);
342 hdf_attribute->CloseOnDisk();
345 //############################## ASCII => HDF ################################
347 //============================================================================
348 // function : ConvertFromASCIIToHDF
349 // purpose : Converts a file pointed by thePath to HDF format
350 // Returns a name of directory where a created HDF file is placed
351 // The created file is named "hdf_from_ascii.hdf"
352 //============================================================================
353 char* HDFascii::ConvertFromASCIIToHDF(const char* thePath,
356 std::string aTmpDir, aFullName;
358 // Get a temporary directory to store a file
359 aTmpDir = GetTmpDir();
360 // Build a full file name of temporary file
361 aFullName = aTmpDir + "hdf_from_ascii.hdf";
365 aFullName = std::string(thePath)+".ascii_tmp";
368 FILE *fp = fopen(thePath, "rb");
371 HDFfile *hdf_file = new HDFfile((char*)aFullName.c_str());
372 hdf_file->CreateOnDisk();
376 fscanf(fp, "%s", type);
377 fscanf(fp, "%i",&nbsons);
379 if(strcmp(type, ASCIIHDF_ID) != 0) return NULL;
381 for(i = 0; i < nbsons; i++) {
382 char id_of_begin[MAX_ID_SIZE];
383 fscanf(fp, "%s\n", id_of_begin);
385 if(strcmp(id_of_begin, GROUP_ID) == 0) {
386 if(!CreateGroupFromASCII(hdf_file, fp)) {
387 std::cout << "ConvertFromASCIIToHDF : Can not create group number " << i << std::endl;
391 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
392 if(!CreateDatasetFromASCII(hdf_file, fp)) {
393 std::cout << "ConvertFromASCIIToHDF :Can not create dataset number " << i << std::endl;
397 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
398 if(!CreateAttributeFromASCII(hdf_file, fp)) {
399 std::cout << "ConvertFromASCIIToHDF :Can not create attribute number " << i << std::endl;
404 std::cout << "ConvertFromASCIIToHDF : Unrecognized type " << id_of_begin << std::endl;
407 char id_of_end[MAX_ID_SIZE];
408 fscanf(fp, "%s", id_of_end);
409 if(strcmp(id_of_end, ASCIIHDF_ID_END) != 0) {
410 std::cout << "ConvertFromASCIIToHDF : Can not find the end ASCII token " << std::endl;
414 hdf_file->CloseOnDisk();
418 if(Exists(aFullName))
419 Move(aFullName, thePath);
424 int length = strlen(aTmpDir.c_str());
425 char *new_str = new char[ 1+length ];
426 strcpy(new_str , aTmpDir.c_str()) ;
434 //============================================================================
435 // function : CreateGroupFromASCII
436 // purpose : Creates a HDF group from a set attributes situated under theLabel
437 //============================================================================
438 bool CreateGroupFromASCII(HDFcontainerObject *father, FILE *fp)
440 char name[HDF_NAME_MAX_LEN+1];
442 fscanf(fp, "%s %i\n", name, &nbsons);
444 char* new_name = restoreName(name);
446 HDFgroup* hdf_group = new HDFgroup(new_name, father);
450 hdf_group->CreateOnDisk();
452 for(i = 0; i < nbsons; i++) {
453 char id_of_begin[MAX_ID_SIZE];
454 fscanf(fp, "%s\n", id_of_begin);
456 if(strcmp(id_of_begin, GROUP_ID) == 0) {
457 if(!CreateGroupFromASCII(hdf_group, fp)) {
458 std::cout << "Can not create subgroup " << i << " for group " << name << std::endl;
462 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
463 if(!CreateDatasetFromASCII(hdf_group, fp)) {
464 std::cout << "Can not create dataset " << i << " for group " << name << std::endl;
468 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
469 if(!CreateAttributeFromASCII(hdf_group, fp)) {
470 std::cout << "Can not create attribute " << i << " for group " << name << std::endl;
475 std::cout << "CreateGroupFromASCII : Unrecognized type " << id_of_begin << std::endl;
478 hdf_group->CloseOnDisk();
479 hdf_group = 0; //will be deleted by father destructor
481 char id_of_end[MAX_ID_SIZE];
482 fscanf(fp, "%s\n", id_of_end);
483 if(strcmp(id_of_end, GROUP_ID_END) != 0) {
484 std::cout << "CreateGroupFromASCII : Invalid end token : " << id_of_end << std::endl;
492 //============================================================================
493 // function : CreateDatasetFromASCII
494 // purpose : Creates a HDF dataset from a set attributes situated under theLabel
495 //============================================================================
496 bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp)
498 char name[HDF_NAME_MAX_LEN+1];
500 hdf_byte_order order;
504 fscanf(fp, "%s %i %i\n", name, &type, &nbAttr);
505 char* new_name = restoreName(name);
507 fscanf(fp, "%i\n", &nbDim);
509 hdf_size* sizeArray = new hdf_size[nbDim];
511 for(i = 0; i<nbDim; i++) {
512 fscanf(fp, "%i\n", &dim);
516 // order (2-d member) was not written in earlier versions
518 int nbRead = fscanf(fp, "%li %i%c", &size, &order, &tmp);
519 if ( nbRead < 2 ) { // fscanf stops before ":"
520 fscanf(fp, "%c", &tmp);
521 order = H5T_ORDER_NONE;
523 if ( type != HDF_FLOAT64 ) // use order only for FLOAT64
524 order = H5T_ORDER_NONE;
527 HDFarray* anArray = 0;
528 if( type == HDF_ARRAY ){
529 //Get array information
530 hdf_type arr_data_type;
532 fscanf(fp, "%c", &tmp);
533 fscanf(fp, " %i\n", &arr_data_type ); //Get array data type
534 fscanf(fp, " %i\n", &arr_ndim ); //Get array nDim
535 hdf_size *arr_dim = new hdf_size[arr_ndim];
538 for( int i = 0;i < arr_ndim; i++ ) {
539 fscanf(fp, " %i", &tdim);
542 anArray = new HDFarray(0, arr_data_type, arr_ndim, arr_dim);
543 anArray->CreateOnDisk();
545 type = arr_data_type;
549 HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : type, sizeArray, nbDim, order);
552 hdf_dataset->SetArrayId(anArray->GetId());
557 hdf_dataset->CreateOnDisk();
559 if (type == HDF_STRING) {
560 char *val = new char[size+1];
561 fread(val, 1, size, fp);
562 hdf_dataset->WriteOnDisk(val);
564 } else if (type == HDF_FLOAT64) {
565 hdf_float64* val = new hdf_float64[size];
566 for(i=0; i<size; i++) {
567 read_float64(fp, &(val[i]));
569 hdf_dataset->WriteOnDisk(val);
571 } else if(type == HDF_INT64) {
572 hdf_int64* val = new hdf_int64[size];
573 for(i=0; i<size; i++) {
574 fscanf(fp, " %li", &(val[i]));
576 hdf_dataset->WriteOnDisk(val);
578 } else if(type == HDF_INT32) {
579 hdf_int32* val = new hdf_int32[size];
580 for(i=0; i<size; i++) {
581 fscanf(fp, " %i", &(val[i]));
583 hdf_dataset->WriteOnDisk(val);
585 } else if(type == HDF_CHAR) {
586 hdf_char* val = new hdf_char[size];
587 for(i=0; i<size; i++) {
588 fscanf(fp, " %i", &(val[i]));
590 hdf_dataset->WriteOnDisk(val);
594 char token[MAX_ID_SIZE];
596 for(i = 0; i < nbAttr; i++) {
597 fscanf(fp, "%s\n", token);
599 if(strcmp(token, ATTRIBUTE_ID) == 0) {
600 if(!CreateAttributeFromASCII(hdf_dataset, fp)) {
601 std::cout << "Can not create attribute " << i << " for dataset " << name << std::endl;
606 std::cout << "CreateGroupFromASCII : Unrecognized type " << token << std::endl;
611 fscanf(fp, "%s\n", token);
612 if(strcmp(token, DATASET_ID_END) != 0) {
613 std::cout << "CreateDatasetFromASCII : Invalid end token : " << token << std::endl;
617 hdf_dataset->CloseOnDisk();
618 hdf_dataset = 0; //will be deleted by father destructor
621 anArray->CloseOnDisk();
622 anArray = 0; //will be deleted by father destructor
629 //============================================================================
630 // function : CreateAttributeFromASCII
631 // purpose : Creates a HDF attribute from a set attributes situated under theLabel
632 //============================================================================
633 bool CreateAttributeFromASCII(HDFinternalObject *father, FILE* fp)
635 char name[HDF_NAME_MAX_LEN+1];
639 fscanf(fp, "%s %i %i\n", name, &type, &size);
640 char* new_name = restoreName(name);
641 HDFattribute* hdf_attribute = new HDFattribute(new_name, father, type, size);
643 hdf_attribute->CreateOnDisk();
647 if (type == HDF_STRING) {
649 fscanf(fp, "%c", &tmp);
650 char *val = new char[size+1];
652 fread(val, 1, size, fp);
653 hdf_attribute->WriteOnDisk(val);
655 } else if (type == HDF_FLOAT64) {
657 read_float64(fp, &val);
658 hdf_attribute->WriteOnDisk(&val);
659 } else if(type == HDF_INT64) {
661 fscanf(fp, "%li", &val);
662 hdf_attribute->WriteOnDisk(&val);
663 } else if(type == HDF_INT32) {
665 fscanf(fp, "%i", &val);
666 hdf_attribute->WriteOnDisk(&val);
669 hdf_attribute->CloseOnDisk();
670 hdf_attribute = 0; //will be deleted by father destructor
673 char id_of_end[MAX_ID_SIZE];
674 fscanf(fp, "%s\n", id_of_end);
675 if(strcmp(id_of_end, ATTRIBUTE_ID_END) != 0) {
676 std::cout << "CreateAttributeFromASCII : Invalid end token : " << id_of_end << std::endl;
684 //============================================================================
685 // function : GetTempDir
686 // purpose : Return a temp directory to store created files like "/tmp/sub_dir/"
687 //============================================================================
688 std::string GetTmpDir()
690 //Find a temporary directory to store a file
692 char *Tmp_dir = getenv("SALOME_TMP_DIR");
693 if(Tmp_dir != NULL) {
694 aTmpDir = std::string(Tmp_dir);
695 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
699 aTmpDir = std::string("C:\\");
701 aTmpDir = std::string("/tmp/");
705 srand((unsigned int)time(NULL));
706 int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
708 sprintf(buffer, "%d", aRND);
709 std:: string aSubDir(buffer);
710 if(aSubDir.size() <= 1) aSubDir = std::string("123409876");
712 aTmpDir += aSubDir; //Get RND sub directory
714 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
716 std::string aDir = aTmpDir;
718 for(aRND = 0; Exists(aDir); aRND++) {
719 sprintf(buffer, "%d", aRND);
720 aDir = aTmpDir+buffer; //Build a unique directory name
724 //fuction CreateDirectory create only final directory, but not intermediate
725 CreateDirectory(aTmpDir.c_str(), NULL);
726 CreateDirectory(aDir.c_str(), NULL);
728 mkdir(aDir.c_str(), 0x1ff);
731 return aDir + dir_separator;
734 char* makeName(char* name)
736 std::string aName(name), aNewName;
737 int i, length = aName.size();
738 char replace = (char)19;
740 for(i=0; i<length; i++) {
741 if(aName[i] == ' ') aNewName+=replace;
742 else aNewName += aName[i];
745 length = strlen(aNewName.c_str());
746 char *new_str = new char[ 1+length ];
747 strcpy(new_str , aNewName.c_str()) ;
751 char* restoreName(char* name)
753 std::string aName(name), aNewName;
754 int i, length = aName.size();
755 char replace = (char)19;
757 for(i=0; i<length; i++) {
758 if(aName[i] == replace) aNewName+=' ';
759 else aNewName += aName[i];
762 length = strlen(aNewName.c_str());
763 char *new_str = new char[ 1+length ];
764 strcpy(new_str , aNewName.c_str()) ;
768 void write_float64(FILE* fp, hdf_float64* value)
770 unsigned char* array = (unsigned char*)value;
771 for(int i = 0; i < sizeof(hdf_float64); i++) {
772 unsigned tmp = (unsigned short)array[i];
773 fprintf(fp, " %2x", tmp);
777 void read_float64(FILE* fp, hdf_float64* value)
779 unsigned char* array = (unsigned char*)value;
780 for(int i = 0; i < sizeof(hdf_float64); i++) {
782 fscanf(fp, " %x", &tmp);
783 array[i] = (unsigned char)tmp;
787 bool Exists(const std::string thePath)
790 if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
791 DWORD errorId = GetLastError ();
792 if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
796 int status = access ( thePath.c_str() , F_OK );
797 if (status != 0) return false;
802 void Move(const std::string& fName, const std::string& fNameDst)
805 MoveFileEx (fName.c_str(), fNameDst.c_str(),MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
807 rename(fName.c_str(), fNameDst.c_str());
811 void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size ) {
812 if (type == HDF_STRING) {
813 char* val = new char[size];
814 hdf_dataset->ReadFromDisk(val);
815 fwrite(val, 1, size, fp);
817 } else if (type == HDF_FLOAT64) {
818 hdf_float64* val = new hdf_float64[size];
819 hdf_dataset->ReadFromDisk(val);
821 for (int i = 0, j = 0; i < size; i++) {
822 write_float64(fp, &val[i]);
823 if(++j == NB_FLOAT_IN_ROW) {
827 else fprintf(fp," ");
830 } else if(type == HDF_INT64) {
831 hdf_int64* val = new hdf_int64[size];
832 hdf_dataset->ReadFromDisk(val);
834 for (int i = 0, j = 0; i < size; i++) {
835 fprintf(fp, " %li", val[i]);
836 if(++j == NB_INTEGER_IN_ROW) {
842 } else if(type == HDF_INT32) {
843 hdf_int32* val = new hdf_int32[size];
844 hdf_dataset->ReadFromDisk(val);
846 for (int i = 0, j = 0; i < size; i++) {
847 fprintf(fp, " %i", val[i]);
848 if(++j == NB_INTEGER_IN_ROW) {
854 }else if(type == HDF_CHAR) {
855 hdf_char* val = new hdf_char[size];
856 hdf_dataset->ReadFromDisk(val);
858 for (int i = 0, j = 0; i < size; i++) {
859 fprintf(fp, " %i", val[i]);
860 if(++j == NB_INTEGER_IN_ROW) {