95 void check_data_types()
97 if (
sizeof(
Index) != 4 )
98 throw runtime_error(
"An Index is expected to be 4 bytes.");
99 if (
sizeof(
float) != 4 )
100 throw runtime_error(
"A float is expected to be 4 bytes.");
101 if (
sizeof(
double) != 8 )
102 throw runtime_error(
"A double is expected to be 8 bytes.");
103 if (
sizeof(
char) != 1 )
104 throw runtime_error(
"A char is expected to be 1 byte.");
127 fid = Hopen( filename.c_str(), DFACC_CREATE, 0 );
131 os <<
"Cannot create output file: " << filename <<
'\n'
132 <<
"Maybe you don't have write access to the directory or the file?";
133 throw runtime_error(os.str());
135 out2 <<
" Opened file " << filename <<
" for writing.\n";
138 if ( Vstart( fid ) < 0 )
141 os <<
"Cannot initialize the VS interafce in file: " << filename;
142 throw runtime_error(os.str());
167 if ( Hishdf( filename.c_str() ) < 0 )
170 os <<
"The file " << filename <<
" is not a HDF file.\n";
171 throw runtime_error(os.str());
175 fid = Hopen( filename.c_str(), DFACC_READ, 0 );
179 os <<
"Cannot open input file: " << filename <<
'\n'
180 <<
"Maybe you don't have read access to the directory or the file?";
181 throw runtime_error(os.str());
183 out2 <<
" Opened file " << filename <<
" for reading.\n";
186 if ( Vstart( fid ) < 0 )
189 os <<
"Cannot initialize the VS interafce in file: " << filename;
190 throw runtime_error(os.str());
214 if ( Vend( fid ) < 0 )
217 os <<
"Cannot terminate access to the VS interface in: " << filename;
218 throw runtime_error(os.str());
222 if ( Hclose( fid ) < 0 )
225 os <<
"Cannot close file: " << filename;
226 throw runtime_error(os.str());
229 out2 <<
" Closed file " << filename <<
"\n";
251 void binfile_write_size(
262 if ( VSsetattr( vdata_id, _HDF_VDATA,
"SIZE", DFNT_UINT32, 2, v ) < 0 )
265 os <<
"Cannot write size data for " << dataname <<
" in file " << filename;
266 throw runtime_error(os.str());
294 void binfile_read_init(
301 const String& storagetype,
303 const Index& ncols0 )
306 int vdata_ref = VSfind( fid, dataname.c_str() );
307 if ( vdata_ref <= 0 )
310 os <<
"Cannot find the data " << dataname <<
" in file " <<filename<<
"\n"
311 <<
"Maybe the file contains data of other type";
312 throw runtime_error(os.str());
316 vdata_id = VSattach( fid, vdata_ref,
"r" );
320 os <<
"Cannot attach the data " << dataname <<
" in file " << filename;
321 throw runtime_error(os.str());
326 if ( VSgetattr( vdata_id, _HDF_VDATA, 0, v ) < 0 )
329 os <<
"Cannot determine the size of " << dataname <<
"\n"
330 <<
"in file " << filename;
331 throw runtime_error(os.str());
337 if ( (nrows0>0) && (nrows!=nrows0) )
340 os << nrows0 <<
" rows were expected, but the data have " <<nrows<<
" rows";
341 throw runtime_error(os.str());
343 if ( (ncols0>0) && (ncols!=ncols0) )
346 os << ncols0 <<
" columns were expected, but the data have " << ncols
348 throw runtime_error(os.str());
352 if ( (nrows>0) && (ncols>0) )
354 if ( VSsetfields( vdata_id, storagetype.c_str() ) < 0 )
356 cout << dataname << endl;
358 os <<
"Cannot find the field " << storagetype <<
" in file " << filename
359 <<
"\n" <<
"Maybe the file contains data of other type";
360 throw runtime_error(os.str());
380 void binfile_read_end(
385 if ( VSdetach( vdata_id ) < 0 )
388 os <<
"Cannot detach the field " << dataname <<
" in file " << filename;
389 throw runtime_error(os.str());
405 void binfile_get_datatype(
407 const int& vdata_id )
410 VSgetclass( vdata_id, c );
444 const String& storagetype,
448 const uint8* dpointer )
453 out3 <<
" Writing: " << dataname <<
"\n";
456 int vdata_id = VSattach( fid, -1,
"w" );
460 os <<
"Cannot create a new vdata in file " << filename;
461 throw runtime_error(os.str());
465 if ( VSsetname( vdata_id, dataname.c_str() ) < 0 )
468 os <<
"Cannot name the vdata " << dataname <<
" in file " << filename;
469 throw runtime_error(os.str());
473 binfile_write_size( filename, dataname, vdata_id, nrows, ncols );
476 int status1, status2;
478 if ( atomictype ==
"INDEX" )
480 status1 = VSsetclass( vdata_id,
"UINT" );
481 status2 = VSfdefine( vdata_id, storagetype.c_str(), DFNT_UINT32, 1);
483 else if ( atomictype ==
"NUMERIC" )
487 status1 = VSsetclass( vdata_id,
"FLOAT" );
488 status2 = VSfdefine( vdata_id, storagetype.c_str(), DFNT_FLOAT32, 1);
492 status1 = VSsetclass( vdata_id,
"DOUBLE" );
493 status2 = VSfdefine( vdata_id, storagetype.c_str(), DFNT_FLOAT64, 1);
497 else if ( atomictype ==
"CHAR" )
499 status1 = VSsetclass( vdata_id,
"CHAR" );
500 status2 = VSfdefine( vdata_id, storagetype.c_str(), DFNT_CHAR, 1);
505 os <<
"The atomic data type " << atomictype <<
" is not handled";
506 throw runtime_error(os.str());
513 os <<
"Cannot set class on " << dataname <<
" in file "<<filename;
514 throw runtime_error(os.str());
519 os <<
"Cannot create the field " << storagetype <<
" in file "<<filename;
520 throw runtime_error(os.str());
524 if ( VSsetfields( vdata_id, storagetype.c_str() ) < 0 )
527 os <<
"Cannot set the field " << storagetype <<
" in file " << filename;
528 throw runtime_error(os.str());
532 if ( (nrows>0) && (ncols>0) )
535 const Index nout = nrows*ncols;
536 Index ndone = VSwrite( vdata_id, dpointer, nout, FULL_INTERLACE );
540 os <<
"Could not write all data to field " << storagetype <<
"in file "
541 << filename <<
"\nOut of memory?";
542 throw runtime_error(os.str());
547 if ( VSdetach( vdata_id ) < 0 )
550 os <<
"Cannot detach the vdata " << dataname <<
" in file " << filename;
551 throw runtime_error(os.str());
586 out3 <<
" Reading: " << dataname <<
"\n";
590 binfile_get_datatype( type_in_file, vdata_id );
598 if ( type_in_file ==
"UINT" )
600 VSread( vdata_id, (uint8*)&x[0], n, FULL_INTERLACE );
613 os <<
"Files with data type " << type_in_file <<
" are not handled";
614 throw runtime_error(os.str());
656 out3 <<
" Reading: " << dataname <<
"\n";
660 binfile_get_datatype( type_in_file, vdata_id );
665 if ( (nrows > 0) && (ncols > 0) )
668 if ( type_in_file ==
"FLOAT" )
672 VSread( vdata_id, (uint8*)&x(0,0), nrows*ncols, FULL_INTERLACE );
676 float *a =
new float[nrows*ncols];
678 VSread( vdata_id, (uint8*)a, nrows*ncols, FULL_INTERLACE );
679 for ( i=0; i<nrows; i++ )
682 for ( j=0; j<ncols; j++ )
688 else if ( type_in_file ==
"DOUBLE" )
692 VSread( vdata_id, (uint8*)&x(0,0), nrows*ncols, FULL_INTERLACE );
696 double *a =
new double[nrows*ncols];
698 VSread( vdata_id, (uint8*)a, nrows*ncols, FULL_INTERLACE );
699 for ( i=0; i<nrows; i++ )
702 for ( j=0; j<ncols; j++ )
711 os <<
"Files with data type " << type_in_file <<
" are not handled";
712 throw runtime_error(os.str());
748 out3 <<
" Reading: " << dataname <<
"\n";
752 binfile_get_datatype( type_in_file, vdata_id );
760 if ( type_in_file ==
"CHAR" )
762 VSread( vdata_id, (uint8*)&x[0], n, FULL_INTERLACE );
775 os <<
"Files with data type " << type_in_file <<
" are not handled";
776 throw runtime_error(os.str());
811 binfile_write( fid, filename, dataname,
"SCALAR",
"INDEX", 1, 1,
839 binfile_read_init( vdata_id, nrows, ncols, fid, filename, dataname,
841 binfile_read1( a, vdata_id, nrows, filename, dataname );
843 binfile_read_end( vdata_id, filename, dataname );
868 binfile_write( fid, filename, dataname,
"SCALAR",
"NUMERIC", 1, 1,
896 binfile_read_init( vdata_id, nrows, ncols, fid, filename, dataname,
898 binfile_read2( a, vdata_id, nrows, ncols, filename, dataname );
900 binfile_read_end( vdata_id, filename, dataname );
926 for (
Index i=0; i<n; i++ )
929 binfile_write( fid, filename, dataname,
"VECTOR",
"NUMERIC", n, 1,
959 binfile_read_init( vdata_id, nrows, ncols, fid, filename, dataname,
961 binfile_read2( a, vdata_id, nrows, ncols, filename, dataname );
963 for (
Index i=0; i<nrows; i++ )
965 binfile_read_end( vdata_id, filename, dataname );
996 for (
Index r=0; r<nrows; r++ )
997 for (
Index c=0; c<ncols; c++ )
998 a[r*ncols+c] = x(r,c);
1000 binfile_write( fid, filename, dataname,
"MATRIX",
"NUMERIC", nrows, ncols,
1028 binfile_read_init( vdata_id, nrows, ncols, fid, filename, dataname,
1030 binfile_read2( x, vdata_id, nrows, ncols, filename, dataname );
1031 binfile_read_end( vdata_id, filename, dataname );
1063 binfile_write( fid, filename, dataname,
"ARRAY",
"INDEX", n, 1,
1090 binfile_read_init( vdata_id, nrows, ncols, fid, filename, dataname,
1092 binfile_read1( x, vdata_id, nrows, filename, dataname );
1093 binfile_read_end( vdata_id, filename, dataname );
1122 for (
Index i=0; i<n; i++ )
1125 os << dataname << i;
1156 for (
Index i=0; i<n; i++ )
1159 os << dataname << i;
1190 for (
Index i=0; i<n; i++ )
1193 os << dataname << i;
1224 for (
Index i=0; i<n; i++ )
1227 os << dataname << i;
1254 binfile_write( fid, filename, dataname,
"STRING",
"CHAR", n, 1,
1255 (uint8*)s.c_str() );
1281 binfile_read_init( vdata_id, nrows, ncols, fid, filename, dataname,
1283 binfile_read3( x, vdata_id, nrows, filename, dataname );
1284 binfile_read_end( vdata_id, filename, dataname );
1313 for (
Index i=0; i<n; i++ )
1316 os << dataname << i;
1347 for (
Index i=0; i<n; i++ )
1350 os << dataname << i;
1355 #endif // HDF_SUPPORT
1391 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1393 #endif // HDF_SUPPORT
1425 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1427 #endif // HDF_SUPPORT
1457 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1459 #endif // HDF_SUPPORT
1489 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1491 #endif // HDF_SUPPORT
1523 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1525 #endif // HDF_SUPPORT
1555 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1557 #endif // HDF_SUPPORT
1589 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1591 #endif // HDF_SUPPORT
1621 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1623 #endif // HDF_SUPPORT
1655 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1657 #endif // HDF_SUPPORT
1687 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1689 #endif // HDF_SUPPORT
1721 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1723 #endif // HDF_SUPPORT
1753 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1755 #endif // HDF_SUPPORT
1787 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1789 #endif // HDF_SUPPORT
1819 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1821 #endif // HDF_SUPPORT
1853 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1855 #endif // HDF_SUPPORT
1885 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1887 #endif // HDF_SUPPORT
1919 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1921 #endif // HDF_SUPPORT
1951 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1953 #endif // HDF_SUPPORT
1992 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
1994 #endif // HDF_SUPPORT
2031 throw runtime_error(
"This method is only available when arts is compiled with HDF support.");
2033 #endif // HDF_SUPPORT