1 // Copyright (C) 2007-2024 CEA, EDF, 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
31 #include "Basics_Utils.hxx"
46 #define dir_separator '\\'
48 #define dir_separator '/'
51 void Move(const std::string& fName, const std::string& fNameDst);
52 bool Exists(const std::string thePath);
53 bool CreateAttributeFromASCII(HDFinternalObject *father, FILE* fp);
54 bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp);
55 bool CreateGroupFromASCII(HDFcontainerObject *father, FILE *fp);
57 void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident);
58 void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident);
59 void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident);
61 std::string GetTmpDir();
62 char* makeName(char* name);
63 char* restoreName(char* name);
64 void write_float64(FILE* fp, hdf_float64* value);
65 void read_float64(FILE* fp, hdf_float64* value);
67 void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size );
69 #define MAX_STRING_SIZE 65535
70 #define MAX_ID_SIZE 20
71 #define NB_FLOAT_IN_ROW 3
72 #define NB_INTEGER_IN_ROW 9
74 #define ASCIIHDF_ID "ASCIIHDF"
75 #define ATTRIBUTE_ID "ATTRIBUTE"
76 #define DATASET_ID "DATASET"
77 #define GROUP_ID "GROUP"
79 #define ASCIIHDF_ID_END "ASCIIHDF_END"
80 #define ATTRIBUTE_ID_END "ATTRIBUTE_END"
81 #define DATASET_ID_END "DATASET_END"
82 #define GROUP_ID_END "GROUP_END"
85 //============================================================================
87 // purpose : Returns True if the file is a converted to ASCII HDF file
88 //============================================================================
89 bool HDFascii::isASCII(const char* thePath) {
91 #if defined(WIN32) && defined(UNICODE)
92 const wchar_t * aPath = Kernel_Utils::utf8_decode(thePath);
93 fd = _wopen(aPath, O_RDONLY);
94 if (fd == -1) return false;
96 if(!(fd = open(thePath, O_RDONLY))) return false;
98 char* aBuffer = new char[9];
100 read(fd, aBuffer, 8);
102 bool res = (strcmp(aBuffer, ASCIIHDF_ID) == 0);
108 //############################## HDF => ASCII ################################
110 //============================================================================
111 // function : ConvertFromHDFToASCII
112 // purpose : Converts a file pointed by thePath to ASCII format
113 // If isReplace is true the newly created file will replace the existent one.
114 // If isReplace is false theExtension will be added to a created file name
115 // Returns the file name of ASCII file
116 //============================================================================
117 char* HDFascii::ConvertFromHDFToASCII(const char* thePath,
119 const char* theExtension)
121 std::string aPath(thePath);
123 if(theExtension == NULL) aPath += ".asc";
124 else aPath += (char*)theExtension;
127 std::string aFileName(aPath);
128 if(isReplace) aFileName=aPath+".ascii_tmp";
130 HDFfile *hdf_file = new HDFfile((char*)thePath);
131 hdf_file->OpenOnDisk(HDF_RDONLY);
133 char name[HDF_NAME_MAX_LEN+1];
134 int nbsons = hdf_file->nInternalObjects(), nbAttr = hdf_file->nAttributes();
136 FILE* fp = fopen(aFileName.c_str(), "wb");
137 fprintf(fp, "%s\n", ASCIIHDF_ID);
138 fprintf(fp, "%i\n", nbsons+nbAttr);
140 for(int j=0; j<nbAttr; j++) {
141 char* attr_name = hdf_file->GetAttributeName(j);
142 HDFattribute *hdf_attribute = new HDFattribute(attr_name, hdf_file);
144 SaveAttributeInASCIIfile(hdf_attribute, fp, 0);
148 for (int i=0; i<nbsons; i++) {
149 hdf_file->InternalObjectIndentify(i,name);
150 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
152 hdf_object_type type = hdf_file->InternalObjectType(name);
154 if(type == HDF_DATASET) {
155 HDFdataset* hdf_dataset = new HDFdataset(name, hdf_file);
156 SaveDatasetInASCIIfile(hdf_dataset, fp, 0);
158 } else if(type == HDF_GROUP) {
159 HDFgroup *hdf_group = new HDFgroup(name, hdf_file);
160 SaveGroupInASCIIfile(hdf_group, fp, 0);
165 fprintf(fp, "%s", ASCIIHDF_ID_END);
169 hdf_file->CloseOnDisk();
173 if(Exists(aFileName))
174 Move(aFileName, aPath);
179 size_t length = strlen(aPath.c_str());
180 char *new_str = new char[ 1+length ];
181 strcpy(new_str , aPath.c_str()) ;
187 //============================================================================
188 // function : SaveGroupInASCIIfile
190 //============================================================================
191 void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident)
193 hdf_group->OpenOnDisk();
195 int nbsons = hdf_group->nInternalObjects(), nbAttr = hdf_group->nAttributes();
197 fprintf(fp, "%s\n", GROUP_ID);
199 char* name = makeName(hdf_group->GetName());
201 fprintf(fp, "%s %i\n", name, nbsons+nbAttr);
204 for(int j=0; j<nbAttr; j++) {
205 name = hdf_group->GetAttributeName(j);
206 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_group);
208 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
212 char objName[HDF_NAME_MAX_LEN+1];
214 for (int i=0; i<nbsons; i++) {
215 hdf_group->InternalObjectIndentify(i, objName);
217 if (strncmp(objName, "INTERNAL_COMPLEX",16) == 0) continue;
219 hdf_object_type type = hdf_group->InternalObjectType(objName);
221 if (type == HDF_DATASET) {
222 HDFdataset* hdf_dataset = new HDFdataset(objName, hdf_group);
223 SaveDatasetInASCIIfile(hdf_dataset, fp, ident+1);
225 } else if (type == HDF_GROUP) {
226 HDFgroup *hdf_subgroup = new HDFgroup(objName, hdf_group);
227 SaveGroupInASCIIfile(hdf_subgroup, fp, ident+1);
232 fprintf(fp, "%s\n", GROUP_ID_END);
234 hdf_group->CloseOnDisk();
237 //============================================================================
238 // function : SaveDatasetInASCIIfile
240 //============================================================================
241 void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident)
243 hdf_dataset->OpenOnDisk();
245 long size = (long) hdf_dataset->GetSize();
246 long ndim = hdf_dataset->nDim(); //Get number of dimesions
247 hdf_size *dim = new hdf_size[ndim];
248 hdf_type type = hdf_dataset->GetType();
249 hdf_byte_order order = hdf_dataset->GetOrder();
250 int nbAttr = hdf_dataset->nAttributes();
252 char* name = makeName(hdf_dataset->GetName());
254 fprintf(fp, "%s\n", DATASET_ID);
255 fprintf(fp, "%s %i %i\n", name, type, nbAttr);
258 hdf_dataset->GetDim(dim);
259 fprintf(fp, " %li\n", ndim);
261 for(int i = 0;i < ndim;i++) {
262 fprintf(fp, " %lu", (unsigned long)dim[i]);
268 fprintf(fp, "%li %i:", size, order);
269 if( type == HDF_ARRAY ) {
270 HDFarray *array = new HDFarray(hdf_dataset);
271 hdf_type data_type = array->GetDataType();
273 fprintf(fp, " %i\n", data_type ); //Write array data type
275 //Write nDim of the array
276 int arr_ndim = array->nDim();
277 fprintf(fp, " %i\n", arr_ndim);
278 hdf_size *arr_dim = new hdf_size[arr_ndim];
279 array->GetDim(arr_dim);
281 for( int i = 0;i < arr_ndim; i++ ) {
282 fprintf(fp, " %lu", (unsigned long)arr_dim[i]);
285 //And write the data array
286 WriteSimpleData( fp, hdf_dataset, data_type, size);
288 WriteSimpleData( fp, hdf_dataset, type, size);
293 for ( int j=0; j<nbAttr; j++ )
295 name = hdf_dataset->GetAttributeName(j);
296 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_dataset);
298 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
302 fprintf(fp, "%s\n", DATASET_ID_END);
304 hdf_dataset->CloseOnDisk();
308 //============================================================================
309 // function : SaveAttributeInASCIIfile
311 //============================================================================
312 void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int /*ident*/)
314 hdf_attribute->OpenOnDisk();
316 hdf_type type = hdf_attribute->GetType();
318 char* name = makeName(hdf_attribute->GetName());
319 size_t size = hdf_attribute->GetSize();
321 fprintf(fp, "%s\n", ATTRIBUTE_ID);
322 fprintf(fp, "%s %i %lu\n", name, type, size);
326 if (type == HDF_STRING) {
327 char* val = new char[size+1];
328 hdf_attribute->ReadFromDisk(val);
330 fwrite(val, 1, size, fp);
333 } else if (type == HDF_FLOAT64) {
335 hdf_attribute->ReadFromDisk(&val);
336 write_float64(fp, &val);
338 } else if(type == HDF_INT64) {
340 hdf_attribute->ReadFromDisk(&val);
341 fprintf(fp, "%li \n", val);
342 } else if(type == HDF_INT32) {
344 hdf_attribute->ReadFromDisk(&val);
345 fprintf(fp, "%i \n", val);
348 fprintf(fp, "%s\n", ATTRIBUTE_ID_END);
350 hdf_attribute->CloseOnDisk();
353 //############################## ASCII => HDF ################################
355 //============================================================================
356 // function : ConvertFromASCIIToHDF
357 // purpose : Converts a file pointed by thePath to HDF format
358 // Returns a name of directory where a created HDF file is placed
359 // The created file is named "hdf_from_ascii.hdf"
360 //============================================================================
361 char* HDFascii::ConvertFromASCIIToHDF(const char* thePath,
364 std::string aTmpDir, aFullName;
366 // Get a temporary directory to store a file
367 aTmpDir = GetTmpDir();
368 // Build a full file name of temporary file
369 aFullName = aTmpDir + "hdf_from_ascii.hdf";
373 aFullName = std::string(thePath)+".ascii_tmp";
376 FILE *fp = fopen(thePath, "rb");
379 HDFfile *hdf_file = new HDFfile((char*)aFullName.c_str());
380 hdf_file->CreateOnDisk();
384 fscanf(fp, "%s", type);
385 fscanf(fp, "%i",&nbsons);
387 if(strcmp(type, ASCIIHDF_ID) != 0) return NULL;
389 for(i = 0; i < nbsons; i++) {
390 char id_of_begin[MAX_ID_SIZE];
391 fscanf(fp, "%s\n", id_of_begin);
393 if(strcmp(id_of_begin, GROUP_ID) == 0) {
394 if(!CreateGroupFromASCII(hdf_file, fp)) {
395 std::cout << "ConvertFromASCIIToHDF : Can not create group number " << i << std::endl;
399 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
400 if(!CreateDatasetFromASCII(hdf_file, fp)) {
401 std::cout << "ConvertFromASCIIToHDF :Can not create dataset number " << i << std::endl;
405 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
406 if(!CreateAttributeFromASCII(hdf_file, fp)) {
407 std::cout << "ConvertFromASCIIToHDF :Can not create attribute number " << i << std::endl;
412 std::cout << "ConvertFromASCIIToHDF : Unrecognized type " << id_of_begin << std::endl;
415 char id_of_end[MAX_ID_SIZE];
416 fscanf(fp, "%s", id_of_end);
417 if(strcmp(id_of_end, ASCIIHDF_ID_END) != 0) {
418 std::cout << "ConvertFromASCIIToHDF : Can not find the end ASCII token " << std::endl;
422 hdf_file->CloseOnDisk();
426 if(Exists(aFullName))
427 Move(aFullName, thePath);
432 size_t length = strlen(aTmpDir.c_str());
433 char *new_str = new char[ 1+length ];
434 strcpy(new_str , aTmpDir.c_str()) ;
442 //============================================================================
443 // function : CreateGroupFromASCII
444 // purpose : Creates a HDF group from a set attributes situated under theLabel
445 //============================================================================
446 bool CreateGroupFromASCII(HDFcontainerObject *father, FILE *fp)
448 char name[HDF_NAME_MAX_LEN+1];
450 fscanf(fp, "%s %i\n", name, &nbsons);
452 char* new_name = restoreName(name);
454 HDFgroup* hdf_group = new HDFgroup(new_name, father);
458 hdf_group->CreateOnDisk();
460 for(i = 0; i < nbsons; i++) {
461 char id_of_begin[MAX_ID_SIZE];
462 fscanf(fp, "%s\n", id_of_begin);
464 if(strcmp(id_of_begin, GROUP_ID) == 0) {
465 if(!CreateGroupFromASCII(hdf_group, fp)) {
466 std::cout << "Can not create subgroup " << i << " for group " << name << std::endl;
470 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
471 if(!CreateDatasetFromASCII(hdf_group, fp)) {
472 std::cout << "Can not create dataset " << i << " for group " << name << std::endl;
476 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
477 if(!CreateAttributeFromASCII(hdf_group, fp)) {
478 std::cout << "Can not create attribute " << i << " for group " << name << std::endl;
483 std::cout << "CreateGroupFromASCII : Unrecognized type " << id_of_begin << std::endl;
486 hdf_group->CloseOnDisk();
487 hdf_group = 0; //will be deleted by father destructor
489 char id_of_end[MAX_ID_SIZE];
490 fscanf(fp, "%s\n", id_of_end);
491 if(strcmp(id_of_end, GROUP_ID_END) != 0) {
492 std::cout << "CreateGroupFromASCII : Invalid end token : " << id_of_end << std::endl;
500 //============================================================================
501 // function : CreateDatasetFromASCII
502 // purpose : Creates a HDF dataset from a set attributes situated under theLabel
503 //============================================================================
504 bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp)
506 char name[HDF_NAME_MAX_LEN+1];
512 fscanf(fp, "%s %i %i\n", name, &type, &nbAttr);
513 char* new_name = restoreName(name);
515 fscanf(fp, "%i\n", &nbDim);
517 hdf_size* sizeArray = new hdf_size[nbDim];
519 for(i = 0; i<nbDim; i++) {
520 fscanf(fp, "%i\n", &dim);
524 // order (2-d member) was not written in earlier versions
526 int nbRead = fscanf(fp, "%li %i%c", &size, &order, &tmp);
527 if ( nbRead < 2 ) { // fscanf stops before ":"
528 fscanf(fp, "%c", &tmp);
529 order = H5T_ORDER_NONE;
531 if ( type != HDF_FLOAT64 ) // use order only for FLOAT64
532 order = H5T_ORDER_NONE;
535 HDFarray* anArray = 0;
536 if( type == HDF_ARRAY ){
537 //Get array information
540 fscanf(fp, "%c", &tmp);
541 fscanf(fp, " %i\n", &arr_data_type ); //Get array data type
542 fscanf(fp, " %i\n", &arr_ndim ); //Get array nDim
543 hdf_size *arr_dim = new hdf_size[arr_ndim];
546 for( int i = 0;i < arr_ndim; i++ ) {
547 fscanf(fp, " %i", &tdim);
550 anArray = new HDFarray(0, (hdf_type)arr_data_type, arr_ndim, arr_dim);
551 anArray->CreateOnDisk();
553 type = arr_data_type;
557 HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : (hdf_type)type, sizeArray, nbDim, (hdf_byte_order)order);
560 hdf_dataset->SetArrayId(anArray->GetId());
565 hdf_dataset->CreateOnDisk();
567 if (type == HDF_STRING) {
568 char *val = new char[size+1];
569 fread(val, 1, size, fp);
570 hdf_dataset->WriteOnDisk(val);
572 } else if (type == HDF_FLOAT64) {
573 hdf_float64* val = new hdf_float64[size];
574 for(i=0; i<size; i++) {
575 read_float64(fp, &(val[i]));
577 hdf_dataset->WriteOnDisk(val);
579 } else if(type == HDF_INT64) {
580 hdf_int64* val = new hdf_int64[size];
581 for(i=0; i<size; i++) {
582 fscanf(fp, " %li", &(val[i]));
584 hdf_dataset->WriteOnDisk(val);
586 } else if(type == HDF_INT32) {
587 hdf_int32* val = new hdf_int32[size];
588 for(i=0; i<size; i++) {
589 fscanf(fp, " %i", &(val[i]));
591 hdf_dataset->WriteOnDisk(val);
593 } else if(type == HDF_CHAR) {
594 hdf_char* val = new hdf_char[size];
595 for(i=0; i<size; i++) {
596 fscanf(fp, " %c", &(val[i]));
598 hdf_dataset->WriteOnDisk(val);
602 char token[MAX_ID_SIZE];
604 for(i = 0; i < nbAttr; i++) {
605 fscanf(fp, "%s\n", token);
607 if(strcmp(token, ATTRIBUTE_ID) == 0) {
608 if(!CreateAttributeFromASCII(hdf_dataset, fp)) {
609 std::cout << "Can not create attribute " << i << " for dataset " << name << std::endl;
614 std::cout << "CreateGroupFromASCII : Unrecognized type " << token << std::endl;
619 fscanf(fp, "%s\n", token);
620 if(strcmp(token, DATASET_ID_END) != 0) {
621 std::cout << "CreateDatasetFromASCII : Invalid end token : " << token << std::endl;
625 hdf_dataset->CloseOnDisk();
626 hdf_dataset = 0; //will be deleted by father destructor
629 anArray->CloseOnDisk();
630 anArray = 0; //will be deleted by father destructor
637 //============================================================================
638 // function : CreateAttributeFromASCII
639 // purpose : Creates a HDF attribute from a set attributes situated under theLabel
640 //============================================================================
641 bool CreateAttributeFromASCII(HDFinternalObject *father, FILE* fp)
643 char name[HDF_NAME_MAX_LEN+1];
647 fscanf(fp, "%s %i %i\n", name, &type, &size);
648 char* new_name = restoreName(name);
649 HDFattribute* hdf_attribute = new HDFattribute(new_name, father, (hdf_type)type, size);
651 hdf_attribute->CreateOnDisk();
655 if (type == HDF_STRING) {
657 fscanf(fp, "%c", &tmp);
658 char *val = new char[size+1];
660 fread(val, 1, size, fp);
661 hdf_attribute->WriteOnDisk(val);
663 } else if (type == HDF_FLOAT64) {
665 read_float64(fp, &val);
666 hdf_attribute->WriteOnDisk(&val);
667 } else if(type == HDF_INT64) {
669 fscanf(fp, "%li", &val);
670 hdf_attribute->WriteOnDisk(&val);
671 } else if(type == HDF_INT32) {
673 fscanf(fp, "%i", &val);
674 hdf_attribute->WriteOnDisk(&val);
677 hdf_attribute->CloseOnDisk();
678 hdf_attribute = 0; //will be deleted by father destructor
681 char id_of_end[MAX_ID_SIZE];
682 fscanf(fp, "%s\n", id_of_end);
683 if(strcmp(id_of_end, ATTRIBUTE_ID_END) != 0) {
684 std::cout << "CreateAttributeFromASCII : Invalid end token : " << id_of_end << std::endl;
692 //============================================================================
693 // function : GetTempDir
694 // purpose : Return a temp directory to store created files like "/tmp/sub_dir/"
695 //============================================================================
696 std::string GetTmpDir()
698 //Find a temporary directory to store a file
701 wchar_t *Tmp_dir = _wgetenv(L"SALOME_TMP_DIR");
703 char *Tmp_dir = getenv("SALOME_TMP_DIR");
705 if(Tmp_dir != NULL) {
707 aTmpDir = Kernel_Utils::utf8_encode_s(Tmp_dir);
709 aTmpDir = std::string(Tmp_dir);
711 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
715 aTmpDir = std::string("C:\\");
717 aTmpDir = std::string("/tmp/");
721 srand((unsigned int)time(NULL));
722 int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
724 sprintf(buffer, "%d", aRND);
725 std:: string aSubDir(buffer);
726 if(aSubDir.size() <= 1) aSubDir = std::string("123409876");
728 aTmpDir += aSubDir; //Get RND sub directory
730 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
732 std::string aDir = aTmpDir;
734 for(aRND = 0; Exists(aDir); aRND++) {
735 sprintf(buffer, "%d", aRND);
736 aDir = aTmpDir+buffer; //Build a unique directory name
741 std::wstring aTmpDirToCreate = Kernel_Utils::utf8_decode_s(aTmpDir);
742 std::wstring aDirToCreate = Kernel_Utils::utf8_decode_s(aDir);
744 std::string aTmpDirToCreate = aTmpDir;
745 std::string aDirToCreate = aDir;
747 //function CreateDirectory create only final directory, but not intermediate
748 CreateDirectory(aTmpDirToCreate.c_str(), NULL);
749 CreateDirectory(aDirToCreate.c_str(), NULL);
751 mkdir(aDir.c_str(), 0x1ff);
754 return aDir + dir_separator;
757 char* makeName(char* name)
759 std::string aName(name), aNewName;
760 size_t i, length = aName.size();
761 char replace = (char)19;
763 for(i=0; i<length; i++) {
764 if(aName[i] == ' ') aNewName+=replace;
765 else aNewName += aName[i];
768 length = strlen(aNewName.c_str());
769 char *new_str = new char[ 1+length ];
770 strcpy(new_str , aNewName.c_str()) ;
774 char* restoreName(char* name)
776 std::string aName(name), aNewName;
777 size_t i, length = aName.size();
778 char replace = (char)19;
780 for(i=0; i<length; i++) {
781 if(aName[i] == replace) aNewName+=' ';
782 else aNewName += aName[i];
785 length = strlen(aNewName.c_str());
786 char *new_str = new char[ 1+length ];
787 strcpy(new_str , aNewName.c_str()) ;
791 void write_float64(FILE* fp, hdf_float64* value)
793 unsigned char* array = (unsigned char*)value;
794 for(int i = 0; i < (int)sizeof(hdf_float64); i++) {
795 unsigned tmp = (unsigned short)array[i];
796 fprintf(fp, " %2x", tmp);
800 void read_float64(FILE* fp, hdf_float64* value)
802 unsigned char* array = (unsigned char*)value;
803 for(int i = 0; i < (int)sizeof(hdf_float64); i++) {
805 fscanf(fp, " %x", &tmp);
806 array[i] = (unsigned char)tmp;
810 bool Exists(const std::string thePath)
814 std::wstring aPathToCheck = Kernel_Utils::utf8_decode_s( thePath );
816 std::string aPathToCheck = thePath;
818 if ( GetFileAttributes ( aPathToCheck.c_str() ) == 0xFFFFFFFF ) {
819 DWORD errorId = GetLastError ();
820 if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
824 int status = access ( thePath.c_str() , F_OK );
825 if (status != 0) return false;
830 void Move(const std::string& fName, const std::string& fNameDst)
834 std::wstring fNameToMove = Kernel_Utils::utf8_decode_s( fName );
835 std::wstring fNameDestination = Kernel_Utils::utf8_decode_s( fNameDst );
837 std::string fNameToMove = fName;
838 std::string fNameDestination = fNameDst;
840 MoveFileEx ( fNameToMove.c_str(), fNameDestination.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
842 rename( fName.c_str(), fNameDst.c_str() );
846 void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size ) {
847 if (type == HDF_STRING) {
848 char* val = new char[size];
849 hdf_dataset->ReadFromDisk(val);
850 fwrite(val, 1, size, fp);
852 } else if (type == HDF_FLOAT64) {
853 hdf_float64* val = new hdf_float64[size];
854 hdf_dataset->ReadFromDisk(val);
856 for (int i = 0, j = 0; i < size; i++) {
857 write_float64(fp, &val[i]);
858 if(++j == NB_FLOAT_IN_ROW) {
862 else fprintf(fp," ");
865 } else if(type == HDF_INT64) {
866 hdf_int64* val = new hdf_int64[size];
867 hdf_dataset->ReadFromDisk(val);
869 for (int i = 0, j = 0; i < size; i++) {
870 fprintf(fp, " %li", val[i]);
871 if(++j == NB_INTEGER_IN_ROW) {
877 } else if(type == HDF_INT32) {
878 hdf_int32* val = new hdf_int32[size];
879 hdf_dataset->ReadFromDisk(val);
881 for (int i = 0, j = 0; i < size; i++) {
882 fprintf(fp, " %i", val[i]);
883 if(++j == NB_INTEGER_IN_ROW) {
889 }else if(type == HDF_CHAR) {
890 hdf_char* val = new hdf_char[size];
891 hdf_dataset->ReadFromDisk(val);
893 for (int i = 0, j = 0; i < size; i++) {
894 fprintf(fp, " %i", val[i]);
895 if(++j == NB_INTEGER_IN_ROW) {