1 // Copyright (C) 2007-2021 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
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 if (!(fd = _wopen(aPath, O_RDONLY))) return false;
95 if(!(fd = open(thePath, O_RDONLY))) return false;
97 char* aBuffer = new char[9];
101 bool res = (strcmp(aBuffer, ASCIIHDF_ID) == 0);
107 //############################## HDF => ASCII ################################
109 //============================================================================
110 // function : ConvertFromHDFToASCII
111 // purpose : Converts a file pointed by thePath to ASCII format
112 // If isReplace is true the newly created file will replace the existent one.
113 // If isReplace is false theExtension will be added to a created file name
114 // Returns the file name of ASCII file
115 //============================================================================
116 char* HDFascii::ConvertFromHDFToASCII(const char* thePath,
118 const char* theExtension)
120 std::string aPath(thePath);
122 if(theExtension == NULL) aPath += ".asc";
123 else aPath += (char*)theExtension;
126 std::string aFileName(aPath);
127 if(isReplace) aFileName=aPath+".ascii_tmp";
129 HDFfile *hdf_file = new HDFfile((char*)thePath);
130 hdf_file->OpenOnDisk(HDF_RDONLY);
132 char name[HDF_NAME_MAX_LEN+1];
133 int nbsons = hdf_file->nInternalObjects(), nbAttr = hdf_file->nAttributes();
135 FILE* fp = fopen(aFileName.c_str(), "wb");
136 fprintf(fp, "%s\n", ASCIIHDF_ID);
137 fprintf(fp, "%i\n", nbsons+nbAttr);
139 for(int j=0; j<nbAttr; j++) {
140 char* attr_name = hdf_file->GetAttributeName(j);
141 HDFattribute *hdf_attribute = new HDFattribute(attr_name, hdf_file);
143 SaveAttributeInASCIIfile(hdf_attribute, fp, 0);
147 for (int i=0; i<nbsons; i++) {
148 hdf_file->InternalObjectIndentify(i,name);
149 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
151 hdf_object_type type = hdf_file->InternalObjectType(name);
153 if(type == HDF_DATASET) {
154 HDFdataset* hdf_dataset = new HDFdataset(name, hdf_file);
155 SaveDatasetInASCIIfile(hdf_dataset, fp, 0);
157 } else if(type == HDF_GROUP) {
158 HDFgroup *hdf_group = new HDFgroup(name, hdf_file);
159 SaveGroupInASCIIfile(hdf_group, fp, 0);
164 fprintf(fp, "%s", ASCIIHDF_ID_END);
168 hdf_file->CloseOnDisk();
172 if(Exists(aFileName))
173 Move(aFileName, aPath);
178 size_t length = strlen(aPath.c_str());
179 char *new_str = new char[ 1+length ];
180 strcpy(new_str , aPath.c_str()) ;
186 //============================================================================
187 // function : SaveGroupInASCIIfile
189 //============================================================================
190 void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident)
192 hdf_group->OpenOnDisk();
194 int nbsons = hdf_group->nInternalObjects(), nbAttr = hdf_group->nAttributes();
196 fprintf(fp, "%s\n", GROUP_ID);
198 char* name = makeName(hdf_group->GetName());
200 fprintf(fp, "%s %i\n", name, nbsons+nbAttr);
203 for(int j=0; j<nbAttr; j++) {
204 name = hdf_group->GetAttributeName(j);
205 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_group);
207 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
211 char objName[HDF_NAME_MAX_LEN+1];
213 for (int i=0; i<nbsons; i++) {
214 hdf_group->InternalObjectIndentify(i, objName);
216 if (strncmp(objName, "INTERNAL_COMPLEX",16) == 0) continue;
218 hdf_object_type type = hdf_group->InternalObjectType(objName);
220 if (type == HDF_DATASET) {
221 HDFdataset* hdf_dataset = new HDFdataset(objName, hdf_group);
222 SaveDatasetInASCIIfile(hdf_dataset, fp, ident+1);
224 } else if (type == HDF_GROUP) {
225 HDFgroup *hdf_subgroup = new HDFgroup(objName, hdf_group);
226 SaveGroupInASCIIfile(hdf_subgroup, fp, ident+1);
231 fprintf(fp, "%s\n", GROUP_ID_END);
233 hdf_group->CloseOnDisk();
236 //============================================================================
237 // function : SaveDatasetInASCIIfile
239 //============================================================================
240 void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident)
242 hdf_dataset->OpenOnDisk();
244 long size = (long) hdf_dataset->GetSize();
245 long ndim = hdf_dataset->nDim(); //Get number of dimesions
246 hdf_size *dim = new hdf_size[ndim];
247 hdf_type type = hdf_dataset->GetType();
248 hdf_byte_order order = hdf_dataset->GetOrder();
249 int nbAttr = hdf_dataset->nAttributes();
251 char* name = makeName(hdf_dataset->GetName());
253 fprintf(fp, "%s\n", DATASET_ID);
254 fprintf(fp, "%s %i %i\n", name, type, nbAttr);
257 hdf_dataset->GetDim(dim);
258 fprintf(fp, " %li\n", ndim);
260 for(int i = 0;i < ndim;i++) {
261 fprintf(fp, " %lu", (unsigned long)dim[i]);
267 fprintf(fp, "%li %i:", size, order);
268 if( type == HDF_ARRAY ) {
269 HDFarray *array = new HDFarray(hdf_dataset);
270 hdf_type data_type = array->GetDataType();
272 fprintf(fp, " %i\n", data_type ); //Write array data type
274 //Write nDim of the array
275 int arr_ndim = array->nDim();
276 fprintf(fp, " %i\n", arr_ndim);
277 hdf_size *arr_dim = new hdf_size[arr_ndim];
278 array->GetDim(arr_dim);
280 for( int i = 0;i < arr_ndim; i++ ) {
281 fprintf(fp, " %lu", (unsigned long)arr_dim[i]);
284 //And write the data array
285 WriteSimpleData( fp, hdf_dataset, data_type, size);
287 WriteSimpleData( fp, hdf_dataset, type, size);
292 for ( int j=0; j<nbAttr; j++ )
294 name = hdf_dataset->GetAttributeName(j);
295 HDFattribute *hdf_attribute = new HDFattribute(name, hdf_dataset);
297 SaveAttributeInASCIIfile(hdf_attribute, fp, ident+1);
301 fprintf(fp, "%s\n", DATASET_ID_END);
303 hdf_dataset->CloseOnDisk();
307 //============================================================================
308 // function : SaveAttributeInASCIIfile
310 //============================================================================
311 void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int /*ident*/)
313 hdf_attribute->OpenOnDisk();
315 hdf_type type = hdf_attribute->GetType();
317 char* name = makeName(hdf_attribute->GetName());
318 size_t size = hdf_attribute->GetSize();
320 fprintf(fp, "%s\n", ATTRIBUTE_ID);
321 fprintf(fp, "%s %i %lu\n", name, type, size);
325 if (type == HDF_STRING) {
326 char* val = new char[size+1];
327 hdf_attribute->ReadFromDisk(val);
329 fwrite(val, 1, size, fp);
332 } else if (type == HDF_FLOAT64) {
334 hdf_attribute->ReadFromDisk(&val);
335 write_float64(fp, &val);
337 } else if(type == HDF_INT64) {
339 hdf_attribute->ReadFromDisk(&val);
340 fprintf(fp, "%li \n", val);
341 } else if(type == HDF_INT32) {
343 hdf_attribute->ReadFromDisk(&val);
344 fprintf(fp, "%i \n", val);
347 fprintf(fp, "%s\n", ATTRIBUTE_ID_END);
349 hdf_attribute->CloseOnDisk();
352 //############################## ASCII => HDF ################################
354 //============================================================================
355 // function : ConvertFromASCIIToHDF
356 // purpose : Converts a file pointed by thePath to HDF format
357 // Returns a name of directory where a created HDF file is placed
358 // The created file is named "hdf_from_ascii.hdf"
359 //============================================================================
360 char* HDFascii::ConvertFromASCIIToHDF(const char* thePath,
363 std::string aTmpDir, aFullName;
365 // Get a temporary directory to store a file
366 aTmpDir = GetTmpDir();
367 // Build a full file name of temporary file
368 aFullName = aTmpDir + "hdf_from_ascii.hdf";
372 aFullName = std::string(thePath)+".ascii_tmp";
375 FILE *fp = fopen(thePath, "rb");
378 HDFfile *hdf_file = new HDFfile((char*)aFullName.c_str());
379 hdf_file->CreateOnDisk();
383 fscanf(fp, "%s", type);
384 fscanf(fp, "%i",&nbsons);
386 if(strcmp(type, ASCIIHDF_ID) != 0) return NULL;
388 for(i = 0; i < nbsons; i++) {
389 char id_of_begin[MAX_ID_SIZE];
390 fscanf(fp, "%s\n", id_of_begin);
392 if(strcmp(id_of_begin, GROUP_ID) == 0) {
393 if(!CreateGroupFromASCII(hdf_file, fp)) {
394 std::cout << "ConvertFromASCIIToHDF : Can not create group number " << i << std::endl;
398 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
399 if(!CreateDatasetFromASCII(hdf_file, fp)) {
400 std::cout << "ConvertFromASCIIToHDF :Can not create dataset number " << i << std::endl;
404 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
405 if(!CreateAttributeFromASCII(hdf_file, fp)) {
406 std::cout << "ConvertFromASCIIToHDF :Can not create attribute number " << i << std::endl;
411 std::cout << "ConvertFromASCIIToHDF : Unrecognized type " << id_of_begin << std::endl;
414 char id_of_end[MAX_ID_SIZE];
415 fscanf(fp, "%s", id_of_end);
416 if(strcmp(id_of_end, ASCIIHDF_ID_END) != 0) {
417 std::cout << "ConvertFromASCIIToHDF : Can not find the end ASCII token " << std::endl;
421 hdf_file->CloseOnDisk();
425 if(Exists(aFullName))
426 Move(aFullName, thePath);
431 size_t length = strlen(aTmpDir.c_str());
432 char *new_str = new char[ 1+length ];
433 strcpy(new_str , aTmpDir.c_str()) ;
441 //============================================================================
442 // function : CreateGroupFromASCII
443 // purpose : Creates a HDF group from a set attributes situated under theLabel
444 //============================================================================
445 bool CreateGroupFromASCII(HDFcontainerObject *father, FILE *fp)
447 char name[HDF_NAME_MAX_LEN+1];
449 fscanf(fp, "%s %i\n", name, &nbsons);
451 char* new_name = restoreName(name);
453 HDFgroup* hdf_group = new HDFgroup(new_name, father);
457 hdf_group->CreateOnDisk();
459 for(i = 0; i < nbsons; i++) {
460 char id_of_begin[MAX_ID_SIZE];
461 fscanf(fp, "%s\n", id_of_begin);
463 if(strcmp(id_of_begin, GROUP_ID) == 0) {
464 if(!CreateGroupFromASCII(hdf_group, fp)) {
465 std::cout << "Can not create subgroup " << i << " for group " << name << std::endl;
469 else if(strcmp(id_of_begin, DATASET_ID) == 0) {
470 if(!CreateDatasetFromASCII(hdf_group, fp)) {
471 std::cout << "Can not create dataset " << i << " for group " << name << std::endl;
475 else if(strcmp(id_of_begin, ATTRIBUTE_ID) == 0) {
476 if(!CreateAttributeFromASCII(hdf_group, fp)) {
477 std::cout << "Can not create attribute " << i << " for group " << name << std::endl;
482 std::cout << "CreateGroupFromASCII : Unrecognized type " << id_of_begin << std::endl;
485 hdf_group->CloseOnDisk();
486 hdf_group = 0; //will be deleted by father destructor
488 char id_of_end[MAX_ID_SIZE];
489 fscanf(fp, "%s\n", id_of_end);
490 if(strcmp(id_of_end, GROUP_ID_END) != 0) {
491 std::cout << "CreateGroupFromASCII : Invalid end token : " << id_of_end << std::endl;
499 //============================================================================
500 // function : CreateDatasetFromASCII
501 // purpose : Creates a HDF dataset from a set attributes situated under theLabel
502 //============================================================================
503 bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp)
505 char name[HDF_NAME_MAX_LEN+1];
511 fscanf(fp, "%s %i %i\n", name, &type, &nbAttr);
512 char* new_name = restoreName(name);
514 fscanf(fp, "%i\n", &nbDim);
516 hdf_size* sizeArray = new hdf_size[nbDim];
518 for(i = 0; i<nbDim; i++) {
519 fscanf(fp, "%i\n", &dim);
523 // order (2-d member) was not written in earlier versions
525 int nbRead = fscanf(fp, "%li %i%c", &size, &order, &tmp);
526 if ( nbRead < 2 ) { // fscanf stops before ":"
527 fscanf(fp, "%c", &tmp);
528 order = H5T_ORDER_NONE;
530 if ( type != HDF_FLOAT64 ) // use order only for FLOAT64
531 order = H5T_ORDER_NONE;
534 HDFarray* anArray = 0;
535 if( type == HDF_ARRAY ){
536 //Get array information
539 fscanf(fp, "%c", &tmp);
540 fscanf(fp, " %i\n", &arr_data_type ); //Get array data type
541 fscanf(fp, " %i\n", &arr_ndim ); //Get array nDim
542 hdf_size *arr_dim = new hdf_size[arr_ndim];
545 for( int i = 0;i < arr_ndim; i++ ) {
546 fscanf(fp, " %i", &tdim);
549 anArray = new HDFarray(0, (hdf_type)arr_data_type, arr_ndim, arr_dim);
550 anArray->CreateOnDisk();
552 type = arr_data_type;
556 HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : (hdf_type)type, sizeArray, nbDim, (hdf_byte_order)order);
559 hdf_dataset->SetArrayId(anArray->GetId());
564 hdf_dataset->CreateOnDisk();
566 if (type == HDF_STRING) {
567 char *val = new char[size+1];
568 fread(val, 1, size, fp);
569 hdf_dataset->WriteOnDisk(val);
571 } else if (type == HDF_FLOAT64) {
572 hdf_float64* val = new hdf_float64[size];
573 for(i=0; i<size; i++) {
574 read_float64(fp, &(val[i]));
576 hdf_dataset->WriteOnDisk(val);
578 } else if(type == HDF_INT64) {
579 hdf_int64* val = new hdf_int64[size];
580 for(i=0; i<size; i++) {
581 fscanf(fp, " %li", &(val[i]));
583 hdf_dataset->WriteOnDisk(val);
585 } else if(type == HDF_INT32) {
586 hdf_int32* val = new hdf_int32[size];
587 for(i=0; i<size; i++) {
588 fscanf(fp, " %i", &(val[i]));
590 hdf_dataset->WriteOnDisk(val);
592 } else if(type == HDF_CHAR) {
593 hdf_char* val = new hdf_char[size];
594 for(i=0; i<size; i++) {
595 fscanf(fp, " %c", &(val[i]));
597 hdf_dataset->WriteOnDisk(val);
601 char token[MAX_ID_SIZE];
603 for(i = 0; i < nbAttr; i++) {
604 fscanf(fp, "%s\n", token);
606 if(strcmp(token, ATTRIBUTE_ID) == 0) {
607 if(!CreateAttributeFromASCII(hdf_dataset, fp)) {
608 std::cout << "Can not create attribute " << i << " for dataset " << name << std::endl;
613 std::cout << "CreateGroupFromASCII : Unrecognized type " << token << std::endl;
618 fscanf(fp, "%s\n", token);
619 if(strcmp(token, DATASET_ID_END) != 0) {
620 std::cout << "CreateDatasetFromASCII : Invalid end token : " << token << std::endl;
624 hdf_dataset->CloseOnDisk();
625 hdf_dataset = 0; //will be deleted by father destructor
628 anArray->CloseOnDisk();
629 anArray = 0; //will be deleted by father destructor
636 //============================================================================
637 // function : CreateAttributeFromASCII
638 // purpose : Creates a HDF attribute from a set attributes situated under theLabel
639 //============================================================================
640 bool CreateAttributeFromASCII(HDFinternalObject *father, FILE* fp)
642 char name[HDF_NAME_MAX_LEN+1];
646 fscanf(fp, "%s %i %i\n", name, &type, &size);
647 char* new_name = restoreName(name);
648 HDFattribute* hdf_attribute = new HDFattribute(new_name, father, (hdf_type)type, size);
650 hdf_attribute->CreateOnDisk();
654 if (type == HDF_STRING) {
656 fscanf(fp, "%c", &tmp);
657 char *val = new char[size+1];
659 fread(val, 1, size, fp);
660 hdf_attribute->WriteOnDisk(val);
662 } else if (type == HDF_FLOAT64) {
664 read_float64(fp, &val);
665 hdf_attribute->WriteOnDisk(&val);
666 } else if(type == HDF_INT64) {
668 fscanf(fp, "%li", &val);
669 hdf_attribute->WriteOnDisk(&val);
670 } else if(type == HDF_INT32) {
672 fscanf(fp, "%i", &val);
673 hdf_attribute->WriteOnDisk(&val);
676 hdf_attribute->CloseOnDisk();
677 hdf_attribute = 0; //will be deleted by father destructor
680 char id_of_end[MAX_ID_SIZE];
681 fscanf(fp, "%s\n", id_of_end);
682 if(strcmp(id_of_end, ATTRIBUTE_ID_END) != 0) {
683 std::cout << "CreateAttributeFromASCII : Invalid end token : " << id_of_end << std::endl;
691 //============================================================================
692 // function : GetTempDir
693 // purpose : Return a temp directory to store created files like "/tmp/sub_dir/"
694 //============================================================================
695 std::string GetTmpDir()
697 //Find a temporary directory to store a file
700 wchar_t *Tmp_dir = _wgetenv(L"SALOME_TMP_DIR");
702 char *Tmp_dir = getenv("SALOME_TMP_DIR");
704 if(Tmp_dir != NULL) {
706 aTmpDir = Kernel_Utils::utf8_encode_s(Tmp_dir);
708 aTmpDir = std::string(Tmp_dir);
710 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
714 aTmpDir = std::string("C:\\");
716 aTmpDir = std::string("/tmp/");
720 srand((unsigned int)time(NULL));
721 int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
723 sprintf(buffer, "%d", aRND);
724 std:: string aSubDir(buffer);
725 if(aSubDir.size() <= 1) aSubDir = std::string("123409876");
727 aTmpDir += aSubDir; //Get RND sub directory
729 if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
731 std::string aDir = aTmpDir;
733 for(aRND = 0; Exists(aDir); aRND++) {
734 sprintf(buffer, "%d", aRND);
735 aDir = aTmpDir+buffer; //Build a unique directory name
740 std::wstring aTmpDirToCreate = Kernel_Utils::utf8_decode_s(aTmpDir);
741 std::wstring aDirToCreate = Kernel_Utils::utf8_decode_s(aDir);
743 std::string aTmpDirToCreate = aTmpDir;
744 std::string aDirToCreate = aDir;
746 //function CreateDirectory create only final directory, but not intermediate
747 CreateDirectory(aTmpDirToCreate.c_str(), NULL);
748 CreateDirectory(aDirToCreate.c_str(), NULL);
750 mkdir(aDir.c_str(), 0x1ff);
753 return aDir + dir_separator;
756 char* makeName(char* name)
758 std::string aName(name), aNewName;
759 size_t i, length = aName.size();
760 char replace = (char)19;
762 for(i=0; i<length; i++) {
763 if(aName[i] == ' ') aNewName+=replace;
764 else aNewName += aName[i];
767 length = strlen(aNewName.c_str());
768 char *new_str = new char[ 1+length ];
769 strcpy(new_str , aNewName.c_str()) ;
773 char* restoreName(char* name)
775 std::string aName(name), aNewName;
776 size_t i, length = aName.size();
777 char replace = (char)19;
779 for(i=0; i<length; i++) {
780 if(aName[i] == replace) aNewName+=' ';
781 else aNewName += aName[i];
784 length = strlen(aNewName.c_str());
785 char *new_str = new char[ 1+length ];
786 strcpy(new_str , aNewName.c_str()) ;
790 void write_float64(FILE* fp, hdf_float64* value)
792 unsigned char* array = (unsigned char*)value;
793 for(int i = 0; i < (int)sizeof(hdf_float64); i++) {
794 unsigned tmp = (unsigned short)array[i];
795 fprintf(fp, " %2x", tmp);
799 void read_float64(FILE* fp, hdf_float64* value)
801 unsigned char* array = (unsigned char*)value;
802 for(int i = 0; i < (int)sizeof(hdf_float64); i++) {
804 fscanf(fp, " %x", &tmp);
805 array[i] = (unsigned char)tmp;
809 bool Exists(const std::string thePath)
813 std::wstring aPathToCheck = Kernel_Utils::utf8_decode_s( thePath );
815 std::string aPathToCheck = thePath;
817 if ( GetFileAttributes ( aPathToCheck.c_str() ) == 0xFFFFFFFF ) {
818 DWORD errorId = GetLastError ();
819 if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
823 int status = access ( thePath.c_str() , F_OK );
824 if (status != 0) return false;
829 void Move(const std::string& fName, const std::string& fNameDst)
833 std::wstring fNameToMove = Kernel_Utils::utf8_decode_s( fName );
834 std::wstring fNameDestination = Kernel_Utils::utf8_decode_s( fNameDst );
836 std::string fNameToMove = fName;
837 std::string fNameDestination = fNameDst;
839 MoveFileEx ( fNameToMove.c_str(), fNameDestination.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
841 rename( fName.c_str(), fNameDst.c_str() );
845 void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long size ) {
846 if (type == HDF_STRING) {
847 char* val = new char[size];
848 hdf_dataset->ReadFromDisk(val);
849 fwrite(val, 1, size, fp);
851 } else if (type == HDF_FLOAT64) {
852 hdf_float64* val = new hdf_float64[size];
853 hdf_dataset->ReadFromDisk(val);
855 for (int i = 0, j = 0; i < size; i++) {
856 write_float64(fp, &val[i]);
857 if(++j == NB_FLOAT_IN_ROW) {
861 else fprintf(fp," ");
864 } else if(type == HDF_INT64) {
865 hdf_int64* val = new hdf_int64[size];
866 hdf_dataset->ReadFromDisk(val);
868 for (int i = 0, j = 0; i < size; i++) {
869 fprintf(fp, " %li", val[i]);
870 if(++j == NB_INTEGER_IN_ROW) {
876 } else if(type == HDF_INT32) {
877 hdf_int32* val = new hdf_int32[size];
878 hdf_dataset->ReadFromDisk(val);
880 for (int i = 0, j = 0; i < size; i++) {
881 fprintf(fp, " %i", val[i]);
882 if(++j == NB_INTEGER_IN_ROW) {
888 }else if(type == HDF_CHAR) {
889 hdf_char* val = new hdf_char[size];
890 hdf_dataset->ReadFromDisk(val);
892 for (int i = 0, j = 0; i < size; i++) {
893 fprintf(fp, " %i", val[i]);
894 if(++j == NB_INTEGER_IN_ROW) {