summaryrefslogtreecommitdiffstats
path: root/hl/test/test_table.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2009-04-09 19:56:54 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2009-04-09 19:56:54 (GMT)
commitc8f6207556a42f2408eb075d5c037699751fef8d (patch)
tree0e1c929e392902c99a9d95acca87d087c1aa0b62 /hl/test/test_table.c
parent16985151d7332580d8100187b757b107c323a063 (diff)
downloadhdf5-c8f6207556a42f2408eb075d5c037699751fef8d.zip
hdf5-c8f6207556a42f2408eb075d5c037699751fef8d.tar.gz
hdf5-c8f6207556a42f2408eb075d5c037699751fef8d.tar.bz2
[svn-r16719] clean linux warnings
tested: linux
Diffstat (limited to 'hl/test/test_table.c')
-rw-r--r--hl/test/test_table.c646
1 files changed, 318 insertions, 328 deletions
diff --git a/hl/test/test_table.c b/hl/test/test_table.c
index bd8dd79..fd08ed9 100644
--- a/hl/test/test_table.c
+++ b/hl/test/test_table.c
@@ -1,17 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* Copyright by The HDF Group. *
+* Copyright by the Board of Trustees of the University of Illinois. *
+* All rights reserved. *
+* *
+* This file is part of HDF5. The full HDF5 copyright notice, including *
+* terms governing use, modification, and redistribution, is contained in *
+* the files COPYING and Copyright.html. COPYING can be found at the root *
+* of the source code distribution tree; Copyright.html can be found at the *
+* root level of an installed copy of the electronic HDF5 document set and *
+* is linked from the top-level documents page. It can also be found at *
+* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+* access to either file, you may request a copy from help@hdfgroup.org. *
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdlib.h>
#include <string.h>
@@ -24,28 +24,28 @@
/*-------------------------------------------------------------------------
- * Table API test
- *
- * Functions tested:
- *
- * H5TBmake_table
- * H5TBread_table
- * H5TBwrite_records
- * H5TBread_records
- * H5TBappend_records
- * H5TBinsert_record
- * H5TBdelete_record
- * H5TBcombine_tables
- * H5TBwrite_fields_name
- * H5TBread_fields_name
- * H5TBwrite_fields_index
- * H5TBinsert_field
- * H5TBdelete_field
- * H5TBget_table_info
- * H5TBget_field_info
- *
- *-------------------------------------------------------------------------
- */
+* Table API test
+*
+* Functions tested:
+*
+* H5TBmake_table
+* H5TBread_table
+* H5TBwrite_records
+* H5TBread_records
+* H5TBappend_records
+* H5TBinsert_record
+* H5TBdelete_record
+* H5TBcombine_tables
+* H5TBwrite_fields_name
+* H5TBread_fields_name
+* H5TBwrite_fields_index
+* H5TBinsert_field
+* H5TBdelete_field
+* H5TBget_table_info
+* H5TBget_field_info
+*
+*-------------------------------------------------------------------------
+*/
#define TITLE "Title"
#define NFIELDS 5
@@ -55,9 +55,9 @@
#define TESTING2(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);}
/*-------------------------------------------------------------------------
- * structure used for all tests, a particle with properties
- *-------------------------------------------------------------------------
- */
+* structure used for all tests, a particle with properties
+*-------------------------------------------------------------------------
+*/
typedef struct particle_t
{
char name[16];
@@ -68,19 +68,9 @@ typedef struct particle_t
} particle_t;
/*-------------------------------------------------------------------------
- * local auxiliary functions
- *-------------------------------------------------------------------------
- */
-
-static hid_t h5file_open(const char *fname, unsigned flags);
-static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf );
-static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords,
- particle_t *rbuf, particle_t *wbuf);
-
-/*-------------------------------------------------------------------------
- * a subset of particle_t, with latitude and longitude fields
- *-------------------------------------------------------------------------
- */
+* a subset of particle_t, with latitude and longitude fields
+*-------------------------------------------------------------------------
+*/
typedef struct position_t
{
long longi;
@@ -88,9 +78,9 @@ typedef struct position_t
} position_t;
/*-------------------------------------------------------------------------
- * a subset of particle_t, with name and pressure fields
- *-------------------------------------------------------------------------
- */
+* a subset of particle_t, with name and pressure fields
+*-------------------------------------------------------------------------
+*/
typedef struct namepressure_t
{
char name[16];
@@ -98,9 +88,9 @@ typedef struct namepressure_t
} namepressure_t;
/*-------------------------------------------------------------------------
- * an extended particle, used in the insert field test
- *-------------------------------------------------------------------------
- */
+* an extended particle, used in the insert field test
+*-------------------------------------------------------------------------
+*/
typedef struct particle2_t
{
char name[16];
@@ -112,9 +102,9 @@ typedef struct particle2_t
} particle2_t;
/*-------------------------------------------------------------------------
- * a particle with one field less, used in the delete field test
- *-------------------------------------------------------------------------
- */
+* a particle with one field less, used in the delete field test
+*-------------------------------------------------------------------------
+*/
typedef struct particle3_t
{
char name[16];
@@ -126,16 +116,16 @@ typedef struct particle3_t
/*-------------------------------------------------------------------------
- * function to open an HDF5 file and return its file identifier
- *-------------------------------------------------------------------------
- */
+* function to open an HDF5 file and return its file identifier
+*-------------------------------------------------------------------------
+*/
static hid_t h5file_open(const char *fname, unsigned flags)
{
-
+
hid_t fid; /* identifier for the file */
char *srcdir = getenv("srcdir"); /* the source directory */
char data_file[512]=""; /* buffer to hold name of existing file */
-
+
/* compose the name of the file to open, using the srcdir, if appropriate */
if (srcdir)
{
@@ -143,21 +133,21 @@ static hid_t h5file_open(const char *fname, unsigned flags)
strcat(data_file,"/");
}
strcat(data_file,fname);
-
+
/* open */
if ((fid = H5Fopen(data_file,flags,H5P_DEFAULT))<0)
{
fprintf(stderr,"Error: Cannot open file <%s>\n",data_file );
exit(1);
}
-
+
return fid;
}
/*-------------------------------------------------------------------------
- * function that compares one particle
- *-------------------------------------------------------------------------
- */
+* function that compares one particle
+*-------------------------------------------------------------------------
+*/
static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf )
{
if ( ( strcmp( rbuf[i].name, wbuf[j].name ) != 0 ) ||
@@ -177,9 +167,9 @@ static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf )
}
/*-------------------------------------------------------------------------
- * function to compare deleted records
- *-------------------------------------------------------------------------
- */
+* function to compare deleted records
+*-------------------------------------------------------------------------
+*/
static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords,
particle_t *rbuf, particle_t *wbuf)
{
@@ -204,11 +194,11 @@ static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords,
/*-------------------------------------------------------------------------
- * the test program
- *-------------------------------------------------------------------------
- */
+* the test program
+*-------------------------------------------------------------------------
+*/
-int test_table(hid_t fid, int write)
+static int test_table(hid_t fid, int do_write)
{
hid_t fid1;
hid_t fid2;
@@ -277,39 +267,39 @@ int test_table(hid_t fid, int write)
{"six", 6.0f},
{"seven", 7.0f},
};
-
-
+
+
/*-------------------------------------------------------------------------
* initialize table parameters
* field offsets and sizes used in the fields functions
*-------------------------------------------------------------------------
*/
-
+
size_t field_offset_pos[2]=
{
HOFFSET( position_t, longi ),
- HOFFSET( position_t, lati )
+ HOFFSET( position_t, lati )
};
size_t field_offset_namepre[2]=
{
HOFFSET( namepressure_t, name ),
- HOFFSET( namepressure_t, pressure )
+ HOFFSET( namepressure_t, pressure )
};
size_t field_sizes_pos[2]=
{
sizeof(position_in[0].longi),
- sizeof(position_in[0].lati)
+ sizeof(position_in[0].lati)
};
size_t field_sizes_namepre[2]=
{
sizeof(namepre_in[0].name),
- sizeof(namepre_in[0].pressure)
+ sizeof(namepre_in[0].pressure)
};
size_t field_sizes_pre[1]=
{
sizeof(namepre_in[0].pressure)
};
-
+
/*-------------------------------------------------------------------------
* query table test
*-------------------------------------------------------------------------
@@ -318,7 +308,7 @@ int test_table(hid_t fid, int write)
size_t sizes_out[NFIELDS];
size_t offset_out[NFIELDS];
size_t size_out;
-
+
/*-------------------------------------------------------------------------
* initialize table parameters
* field indexes (zero based) used in the fields functions
@@ -329,7 +319,7 @@ int test_table(hid_t fid, int write)
int field_index_pos[2] = { 1,4 };
int field_index_namepre[2] = { 0,2 };
int field_index[NFIELDS] = { 0,1,2,3,4 };
-
+
/*-------------------------------------------------------------------------
* initialize table parameters
* size and the offsets of struct members in memory
@@ -351,48 +341,48 @@ int test_table(hid_t fid, int write)
sizeof( rbuf2[0].temperature),
sizeof( rbuf2[0].lati),
sizeof( rbuf2[0].new_field)};
- /*-------------------------------------------------------------------------
- * initialize table parameters
- * size and the offsets of struct members in memory
- * these are used for the delete field test
- *-------------------------------------------------------------------------
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * size and the offsets of struct members in memory
+ * these are used for the delete field test
+ *-------------------------------------------------------------------------
*/
size_t dst_size3 = sizeof( particle3_t );
size_t dst_offset3[NFIELDS-1] = { HOFFSET( particle3_t, name ),
HOFFSET( particle3_t, longi ),
HOFFSET( particle3_t, temperature ),
HOFFSET( particle3_t, lati )};
-
+
size_t dst_sizes3[NFIELDS-1] = { sizeof( rbuf3[0].name),
sizeof( rbuf3[0].longi),
sizeof( rbuf3[0].temperature),
sizeof( rbuf3[0].lati)};
-
-
- /*-------------------------------------------------------------------------
- * initialize table parameters
- * 1) size and the offsets of struct members in memory
- * 2) field names
- * 3) define a HDF5 type for the fields
- *-------------------------------------------------------------------------
+
+
+ /*-------------------------------------------------------------------------
+ * initialize table parameters
+ * 1) size and the offsets of struct members in memory
+ * 2) field names
+ * 3) define a HDF5 type for the fields
+ *-------------------------------------------------------------------------
*/
-
+
size_t type_size_mem = sizeof( particle_t );
size_t field_offset[NFIELDS]=
{
HOFFSET( particle_t, name ),
- HOFFSET( particle_t, longi ),
- HOFFSET( particle_t, pressure ),
- HOFFSET( particle_t, temperature ),
- HOFFSET( particle_t, lati )
+ HOFFSET( particle_t, longi ),
+ HOFFSET( particle_t, pressure ),
+ HOFFSET( particle_t, temperature ),
+ HOFFSET( particle_t, lati )
};
size_t field_size[NFIELDS] =
{
sizeof( rbuf[0].name),
- sizeof( rbuf[0].longi),
- sizeof( rbuf[0].pressure),
- sizeof( rbuf[0].temperature),
- sizeof( rbuf[0].lati)
+ sizeof( rbuf[0].longi),
+ sizeof( rbuf[0].pressure),
+ sizeof( rbuf[0].temperature),
+ sizeof( rbuf[0].lati)
};
const char *field_names[NFIELDS] =
{ "Name","Longitude","Pressure","Temperature","Latitude" };
@@ -404,7 +394,7 @@ int test_table(hid_t fid, int write)
field_type[2] = H5T_NATIVE_FLOAT;
field_type[3] = H5T_NATIVE_DOUBLE;
field_type[4] = H5T_NATIVE_INT;
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -414,37 +404,37 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("making table");
-
+
if (H5TBmake_table(TITLE,fid,"table1",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill,compress,wbuf)<0)
goto out;
PASSED();
}
-
+
TESTING2("reading table");
-
+
/*-------------------------------------------------------------------------
* read the table
*-------------------------------------------------------------------------
*/
-
+
if (H5TBread_table(fid,"table1",type_size_mem,field_offset,field_size,rbuf)<0)
goto out;
-
+
/* compare the extracted table with the original array */
for( i = 0; i < NRECORDS; i++ )
{
if (cmp_par(i,i,rbuf,wbuf)<0)
goto out;
}
-
+
PASSED();
-
-
+
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -453,16 +443,16 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("writing records");
-
+
/* create an empty table */
if (H5TBmake_table(TITLE,fid,"table2",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill,compress,0)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* write records, start at 0, write 8
* pos = 0 1 2 3 4 5 6 7
@@ -474,21 +464,21 @@ int test_table(hid_t fid, int write)
if (H5TBwrite_records(fid,"table2",wstart,wrecords,type_size_mem,field_offset,
field_size,wbuf)<0)
goto out;
-
+
/* read it back */
if (H5TBread_table(fid,"table2",type_size_mem,field_offset,field_size,rbuf)<0)
goto out;
-
+
/* compare */
for( i = 0; i < NRECORDS; i++ )
{
if (cmp_par(i,i,rbuf,wbuf)<0)
goto out;
}
-
+
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -497,32 +487,32 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
+
TESTING2("reading records");
-
+
/*-------------------------------------------------------------------------
* read records, start at 0, read 8
* pos = 0 1 2 3 4 5 6 7
* data= 0 1 2 3 4 5 6 7
*-------------------------------------------------------------------------
*/
-
+
/*-------------------------------------------------------------------------
* for the read test we cannot use "table2" because it has been appended
* we use the original "table1" instead
*-------------------------------------------------------------------------
*/
- if(write)
+ if(do_write)
strcpy(tname,"table2");
else
strcpy(tname,"table1");
-
+
rstart=0;
rrecords=8;
if (H5TBread_records(fid,tname,rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
goto out;
-
+
/* compare */
for( i=(int)rstart; i<(int)rrecords; i++)
{
@@ -530,7 +520,7 @@ int test_table(hid_t fid, int write)
goto out;
}
PASSED();
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -540,10 +530,10 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("appending records");
-
+
/*-------------------------------------------------------------------------
* append 2 records
* pos = 0 1 2 3 4 5 6 7 8 9
@@ -553,15 +543,15 @@ int test_table(hid_t fid, int write)
arecords=2;
if (H5TBappend_records(fid,"table2",arecords,type_size_mem,field_offset,field_size,abuf)<0)
return 1;
-
+
if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0)
return 1;
-
+
rstart=0; rrecords=NRECORDS+arecords;
if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
return 1;
-
+
/* compare */
wrecords=8;
for( i=(int)rstart; i<(int)wrecords; i++)
@@ -576,7 +566,7 @@ int test_table(hid_t fid, int write)
}
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -586,10 +576,10 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("inserting records");
-
+
/*-------------------------------------------------------------------------
* insert 2 records
* pos = 0 1 2 3 4 5 6 7 8 9 10 11
@@ -599,14 +589,14 @@ int test_table(hid_t fid, int write)
istart=1; irecords=2;
if (H5TBinsert_record(fid,"table2",istart,irecords,type_size_mem,field_offset,field_size,ibuf)<0)
return 1;
-
+
if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0)
return 1;
-
+
if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
return 1;
-
+
/* compare */
for( i=0; i<12; i++)
{
@@ -636,7 +626,7 @@ int test_table(hid_t fid, int write)
}
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -646,17 +636,17 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("deleting records");
-
+
/*-------------------------------------------------------------------------
* Create a table
* pos = 0 1 2 3 4 5 6 7
* data= 0 1 2 3 4 5 6 7
*-------------------------------------------------------------------------
*/
-
+
for( i=0; i<NRECORDS; i++)
{
wbufd[i].lati = wbuf[i].lati;
@@ -664,15 +654,15 @@ int test_table(hid_t fid, int write)
wbufd[i].pressure = wbuf[i].pressure;
wbufd[i].temperature = wbuf[i].temperature;
strcpy(wbufd[i].name, wbuf[i].name );
-
+
}
-
-
+
+
if (H5TBmake_table(TITLE,fid,"table3",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill,compress,wbufd)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* Delete records, start at 2, delete 3
* pos = 0 1 2 3 4
@@ -682,21 +672,21 @@ int test_table(hid_t fid, int write)
dstart=2; drecords=3;
if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
goto out;
-
+
if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
goto out;
-
+
rstart=0;
if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
goto out;
-
+
/* compare */
nrecords=NRECORDS;
assert(rrecords == nrecords-drecords);
if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
@@ -706,7 +696,7 @@ int test_table(hid_t fid, int write)
{
wbufd[i] = rbuf[i];
}
-
+
/*-------------------------------------------------------------------------
* Delete records, start at 0, delete 2
* pos = 0 1 2
@@ -716,20 +706,20 @@ int test_table(hid_t fid, int write)
dstart=0; drecords=2;
if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
goto out;
-
+
if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
goto out;
-
+
rstart=0;
if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
goto out;
-
+
/* Compare */
assert(rrecords == nrecords-drecords);
if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
@@ -739,7 +729,7 @@ int test_table(hid_t fid, int write)
{
wbufd[i] = rbuf[i];
}
-
+
/*-------------------------------------------------------------------------
* Delete records, start at 1, delete 1
* pos = 0 1
@@ -749,20 +739,20 @@ int test_table(hid_t fid, int write)
dstart=1; drecords=1;
if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
goto out;
-
+
if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
goto out;
-
+
rstart=0;
if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
goto out;
-
+
/* Compare */
assert(rrecords == nrecords-drecords);
if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
@@ -772,7 +762,7 @@ int test_table(hid_t fid, int write)
{
wbufd[i] = rbuf[i];
}
-
+
/*-------------------------------------------------------------------------
* Delete records, start at 0, delete 1
* pos = 0
@@ -782,20 +772,20 @@ int test_table(hid_t fid, int write)
dstart=0; drecords=1;
if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
goto out;
-
+
if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
goto out;
-
+
rstart=0;
if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset,
field_size,rbuf)<0)
goto out;
-
+
/* Compare */
assert(rrecords == nrecords-drecords);
if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* reset compare buffer
*-------------------------------------------------------------------------
@@ -805,11 +795,11 @@ int test_table(hid_t fid, int write)
{
wbufd[i] = rbuf[i];
}
-
+
/* Read complete table */
if (H5TBread_table(fid,"table3",type_size_mem,field_offset,field_size,rbuf)<0)
goto out;
-
+
/* Compare */
for( i=0; i<rrecords; i++)
{
@@ -828,16 +818,16 @@ int test_table(hid_t fid, int write)
dstart=0; drecords=1;
if (H5TBdelete_record(fid,"table3",dstart,drecords)<0)
goto out;
-
+
if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0)
goto out;
-
+
if (rrecords)
goto out;
-
+
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -847,11 +837,11 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
- if (write)
+
+ if (do_write)
{
TESTING2("adding records");
-
+
/* create 2 tables */
if (H5TBmake_table(TITLE,fid,"table4",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
@@ -861,18 +851,18 @@ int test_table(hid_t fid, int write)
field_names,field_offset,field_type,
chunk_size,fill,compress,wbuf)<0)
goto out;
-
+
/* add the records from "table4" to "table5" */
start1 = 3;
nrecords = 2;
start2 = 6;
if ( H5TBadd_records_from(fid,"table4",start1,nrecords,"table5",start2)<0)
goto out;
-
+
/* read final table */
if (H5TBread_table(fid,"table5",type_size_mem,field_offset,field_size,rbuf)<0)
goto out;
-
+
/* compare */
for( i = 0; i < NRECORDS+2; i++ )
{
@@ -894,10 +884,10 @@ int test_table(hid_t fid, int write)
goto out;
}
}
-
+
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -907,11 +897,11 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
- if (write)
+
+ if (do_write)
{
TESTING2("combining tables");
-
+
/* create 2 tables */
if (H5TBmake_table(TITLE,fid,"table6",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
@@ -921,15 +911,15 @@ int test_table(hid_t fid, int write)
field_names,field_offset,field_type,
chunk_size,fill,compress,wbuf)<0)
goto out;
-
+
/* combine the two tables into a third */
if ( H5TBcombine_tables(fid,"table6",fid,"table7","table8")<0)
goto out;
-
+
/* read merged table */
if (H5TBread_table(fid,"table8",type_size_mem,field_offset,field_size,rbufc)<0)
goto out;
-
+
/* compare */
for( i = 0; i < NRECORDS*2; i++ )
{
@@ -944,16 +934,16 @@ int test_table(hid_t fid, int write)
goto out;
}
}
-
+
/*-------------------------------------------------------------------------
* multi file test
*-------------------------------------------------------------------------
*/
-
+
/* create 2 files using default properties. */
fid1 = H5Fcreate("combine_tables1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
fid2 = H5Fcreate("combine_tables2.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
-
+
/* create 2 tables, one in each file */
if (H5TBmake_table(TITLE,fid1,"table1",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
@@ -963,15 +953,15 @@ int test_table(hid_t fid, int write)
field_names,field_offset,field_type,
chunk_size,fill,compress,wbuf)<0)
goto out;
-
+
/* combine the two tables into a third */
if ( H5TBcombine_tables(fid1,"table1",fid2,"table2","table3")<0)
goto out;
-
+
/* read merged table */
if (H5TBread_table(fid1,"table3",type_size_mem,field_offset,field_size,rbufc)<0)
goto out;
-
+
/* compare */
for( i = 0; i < NRECORDS*2; i++ )
{
@@ -986,15 +976,15 @@ int test_table(hid_t fid, int write)
goto out;
}
}
-
+
/* close files */
H5Fclose(fid1);
H5Fclose(fid2);
-
+
PASSED();
}
-
-
+
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1003,39 +993,39 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("writing fields by name");
-
+
/* make an empty table with fill values */
if (H5TBmake_table(TITLE,fid,"table9",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill1,compress,0)<0)
goto out;
-
+
/* write the pressure field starting at record 2 */
start = 2;
nrecords = NRECORDS_ADD;
if (H5TBwrite_fields_name(fid,"table9","Pressure",start,nrecords,sizeof(float),
0,field_sizes_pre,pressure_in)<0)
goto out;
-
+
/* write the new longitude and latitude information starting at record 2 */
start = 2;
nrecords = 3;
if (H5TBwrite_fields_name(fid,"table9","Latitude,Longitude",start,nrecords,sizeof(position_t),
field_offset_pos,field_sizes_pos,position_in)<0)
goto out;
-
+
/* read back the all table */
start = 0;
nrecords = NRECORDS;
if (H5TBread_table(fid,"table9",type_size_mem,field_offset,field_size,rbuf)<0)
goto out;
-
+
{
-
-
+
+
/* compare the read values with the initial values */
for( i = 0; i < NRECORDS; i++ )
{
@@ -1054,12 +1044,12 @@ int test_table(hid_t fid, int write)
}
}
}
-
-
-
+
+
+
PASSED();
} /*write*/
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1069,18 +1059,18 @@ int test_table(hid_t fid, int write)
*-------------------------------------------------------------------------
*/
TESTING2("reading fields by name");
-
+
/*-------------------------------------------------------------------------
* write and read the "Pressure" field
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
if (H5TBmake_table(TITLE,fid,"table10",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill1,compress,0)<0)
goto out;
-
+
/* write the pressure field to all the records */
start = 0;
nrecords = NRECORDS;
@@ -1088,15 +1078,15 @@ int test_table(hid_t fid, int write)
sizeof( float ),0,field_sizes_pre,pressure_in)<0)
goto out;
}
-
+
/* read the "Pressure" field */
start = 0;
nrecords = NRECORDS;
if ( H5TBread_fields_name(fid,"table10","Pressure",start,nrecords,
sizeof(float),0,field_sizes_pre,pressure_out)<0)
goto out;
-
-
+
+
/* Compare the extracted table with the initial values */
for( i = 0; i < NRECORDS; i++ )
{
@@ -1104,12 +1094,12 @@ int test_table(hid_t fid, int write)
goto out;
}
}
-
+
/*-------------------------------------------------------------------------
* Write and read the "Latitude,Longitude" fields
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
/* Write the new longitude and latitude information to all the records */
start = 0;
@@ -1118,15 +1108,15 @@ int test_table(hid_t fid, int write)
sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
goto out;
}/*write*/
-
+
/* Read the "Latitude,Longitude" fields */
start = 0;
nrecords = NRECORDS_ADD;
if ( H5TBread_fields_name( fid, "table10", "Latitude,Longitude",
start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 )
goto out;
-
-
+
+
/* Compare the extracted table with the initial values */
for( i = 0; i < NRECORDS_ADD; i++ )
{
@@ -1134,13 +1124,13 @@ int test_table(hid_t fid, int write)
position_out[i].longi != position_in[i].longi )
goto out;
}
-
-
+
+
/*-------------------------------------------------------------------------
* Write and read the "Name,Pressure" fields
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
/* Write the new name and pressure information to all the records */
start = 0;
@@ -1149,7 +1139,7 @@ int test_table(hid_t fid, int write)
sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 )
goto out;
}/*write*/
-
+
/* Read the "Name,Pressure" fields */
start = 0;
nrecords = NRECORDS;
@@ -1157,24 +1147,24 @@ int test_table(hid_t fid, int write)
start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre,
namepre_out ) < 0 )
goto out;
-
-
+
+
/* Compare the extracted table with the initial values */
for( i = 0; i < NRECORDS; i++ )
{
if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) ||
namepre_out[i].pressure != namepre_in[i].pressure ) {
- goto out;
+ goto out;
}
}
-
+
/* reset buffer */
for( i = 0; i < NRECORDS; i++ )
{
strcpy( namepre_out[i].name, "\0" );
namepre_out[i].pressure = -1;
}
-
+
/*-------------------------------------------------------------------------
* read only 3 records of the "Name,Pressure" fields, starting at record 2
*-------------------------------------------------------------------------
@@ -1185,22 +1175,22 @@ int test_table(hid_t fid, int write)
start, nrecords, sizeof(namepressure_t), field_offset_namepre,
field_sizes_namepre, namepre_out ) < 0 )
goto out;
-
-
+
+
/* Compare the extracted table with the initial values */
for( i = 0; i < 3; i++ )
{
int iistart = (int) start;
if ( ( strcmp( namepre_out[i].name, namepre_in[iistart+i].name ) != 0 ) ||
namepre_out[i].pressure != namepre_in[iistart+i].pressure ) {
- goto out;
+ goto out;
}
}
-
-
-
+
+
+
PASSED();
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1209,16 +1199,16 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("writing fields by index");
-
+
/* make an empty table */
if (H5TBmake_table(TITLE,fid,"table11",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill,compress,NULL)<0)
goto out;
-
+
/* write the pressure field starting at record 2 */
nfields = 1;
start = 2;
@@ -1226,8 +1216,8 @@ int test_table(hid_t fid, int write)
if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pre, start, nrecords,
sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
goto out;
-
-
+
+
/* write the new longitude and latitude information starting at record 2 */
nfields = 2;
start = 2;
@@ -1235,7 +1225,7 @@ int test_table(hid_t fid, int write)
if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pos, start, nrecords,
sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
goto out;
-
+
/* read back the all table */
nfields = 5;
start = 0;
@@ -1243,7 +1233,7 @@ int test_table(hid_t fid, int write)
if ( H5TBread_fields_index(fid, "table11", nfields, field_index,
start, nrecords, type_size_mem, field_offset, field_size, rbuf ) < 0 )
goto out;
-
+
/* Compare the extracted table with the initial values */
for( i = 0; i < NRECORDS; i++ )
{
@@ -1255,11 +1245,11 @@ int test_table(hid_t fid, int write)
goto out;
}
}
-
+
PASSED();
}
-
-
+
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1268,22 +1258,22 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
+
TESTING2("reading fields by index");
-
- if (write)
+
+ if (do_write)
{
/* make an empty table */
if (H5TBmake_table(TITLE,fid,"table12",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill,compress,NULL)<0)
goto out;
-
+
/*-------------------------------------------------------------------------
* write and read the "Pressure" field
*-------------------------------------------------------------------------
*/
-
+
/* write the pressure field to all the records */
nfields = 1;
start = 0;
@@ -1292,7 +1282,7 @@ int test_table(hid_t fid, int write)
sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
goto out;
}
-
+
/* read the "Pressure" field */
nfields = 1;
start = 0;
@@ -1300,7 +1290,7 @@ int test_table(hid_t fid, int write)
if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pre,
start, nrecords, sizeof(float), 0, field_sizes_pre, pressure_out ) < 0 )
goto out;
-
+
/* compare the extracted table with the initial values */
for( i = 0; i < NRECORDS; i++ )
{
@@ -1308,12 +1298,12 @@ int test_table(hid_t fid, int write)
goto out;
}
}
-
+
/*-------------------------------------------------------------------------
* write and read the "Latitude,Longitude" fields
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
/* write the new longitude and latitude information to all the records */
nfields = 2;
@@ -1323,7 +1313,7 @@ int test_table(hid_t fid, int write)
sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
goto out;
} /*write*/
-
+
/* read the "Latitude,Longitude" fields */
nfields = 2;
start = 0;
@@ -1331,22 +1321,22 @@ int test_table(hid_t fid, int write)
if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pos,
start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 )
goto out;
-
+
/* compare the extracted table with the initial values */
for( i = 0; i < NRECORDS_ADD; i++ )
{
if ( position_out[i].lati != position_in[i].lati ||
position_out[i].longi != position_in[i].longi ) {
- goto out;
+ goto out;
}
}
-
+
/*-------------------------------------------------------------------------
* write and read the "Name,Pressure" fields
*-------------------------------------------------------------------------
*/
-
- if (write)
+
+ if (do_write)
{
/* write the new name and pressure information to all the records */
nfields = 2;
@@ -1356,7 +1346,7 @@ int test_table(hid_t fid, int write)
sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 )
goto out;
}
-
+
/* read the "Name,Pressure" fields */
nfields = 2;
start = 0;
@@ -1365,28 +1355,28 @@ int test_table(hid_t fid, int write)
start, nrecords, sizeof(namepressure_t), field_offset_namepre,
field_sizes_namepre, namepre_out ) < 0 )
goto out;
-
+
/* compare the extracted table with the initial values */
for( i = 0; i < NRECORDS; i++ )
{
if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) ||
namepre_out[i].pressure != namepre_in[i].pressure ) {
- goto out;
+ goto out;
}
}
-
+
/* reset buffer */
for( i = 0; i < NRECORDS; i++ )
{
strcpy( namepre_out[i].name, "\0" );
namepre_out[i].pressure = -1;
}
-
+
/*-------------------------------------------------------------------------
* read only 3 records of the "Name,Pressure" fields, starting at record 2
*-------------------------------------------------------------------------
*/
-
+
/* write the new name and pressure information to all the records */
nfields = 2;
start = 2;
@@ -1395,20 +1385,20 @@ int test_table(hid_t fid, int write)
start, nrecords, sizeof(namepressure_t), field_offset_namepre,
field_sizes_namepre, namepre_out ) < 0 )
goto out;
-
+
/* compare the extracted table with the initial values */
for( i = 0; i < 3; i++ )
{
int iistart = (int) start;
if ( ( strcmp( namepre_out[i].name, wbuf[iistart+i].name ) != 0 ) ||
namepre_out[i].pressure != wbuf[iistart+i].pressure ) {
- goto out;
+ goto out;
}
}
-
+
PASSED();
-
-
+
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1417,27 +1407,27 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
- if (write)
+
+ if (do_write)
{
TESTING2("inserting fields");
-
+
/* make a table */
if (H5TBmake_table(TITLE,fid,"table13",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill1,compress,wbuf)<0)
goto out;
-
+
/* insert the new field at the end of the field list */
position = NFIELDS;
if ( H5TBinsert_field( fid, "table13", "New Field", field_type_new, position,
fill1_new, buf_new ) < 0 )
goto out;
-
+
/* read the table */
if ( H5TBread_table( fid, "table13", dst_size2, dst_offset2, dst_sizes2, rbuf2 ) < 0 )
goto out;
-
+
/* compare the extracted table with the original array */
for( i = 0; i < NRECORDS; i++ )
{
@@ -1447,12 +1437,12 @@ int test_table(hid_t fid, int write)
rbuf2[i].pressure != wbuf[i].pressure ||
rbuf2[i].temperature != wbuf[i].temperature ||
rbuf2[i].new_field != buf_new[i] ) {
- goto out;
+ goto out;
}
}
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1461,24 +1451,24 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
- if (write)
+ if (do_write)
{
TESTING2("deleting fields");
-
+
/* make a table */
if (H5TBmake_table(TITLE,fid,"table14",FIELDS,RECORDS,type_size_mem,
field_names,field_offset,field_type,
chunk_size,fill,compress,wbuf)<0)
goto out;
-
+
/* delete the field */
if ( H5TBdelete_field(fid, "table14", "Pressure" ) < 0 )
goto out;
-
+
/* read the table */
if ( H5TBread_table(fid, "table14", dst_size3, dst_offset3, dst_sizes3, rbuf3 ) < 0 )
goto out;
-
+
/* compare the extracted table with the original array */
for( i = 0; i < NRECORDS; i++ )
{
@@ -1486,13 +1476,13 @@ int test_table(hid_t fid, int write)
rbuf3[i].lati != wbuf[i].lati ||
rbuf3[i].longi != wbuf[i].longi ||
rbuf3[i].temperature != wbuf[i].temperature ) {
- goto out;
+ goto out;
}
}
-
+
PASSED();
}
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1502,19 +1492,19 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
+
TESTING2("getting table info");
-
+
/* get table info */
if ( H5TBget_table_info (fid, "table1", &rfields, &rrecords ) < 0 )
goto out;
-
+
if ( NFIELDS != rfields || rrecords != NRECORDS ) {
goto out;
}
-
+
PASSED();
-
+
/*-------------------------------------------------------------------------
*
* Functions tested:
@@ -1523,36 +1513,36 @@ int test_table(hid_t fid, int write)
*
*-------------------------------------------------------------------------
*/
-
+
TESTING2("getting field info");
-
+
/* alocate */
- names_out = malloc( sizeof(char*) * (size_t)NFIELDS );
+ names_out = (char**) malloc( sizeof(char*) * (size_t)NFIELDS );
for ( i = 0; i < NFIELDS; i++)
{
- names_out[i] = malloc( sizeof(char) * 255 );
+ names_out[i] = (char*) malloc( sizeof(char) * 255 );
}
-
+
/* Get field info */
if ( H5TBget_field_info(fid, "table1", names_out, sizes_out, offset_out, &size_out ) < 0 )
goto out;
-
+
for ( i = 0; i < NFIELDS; i++)
{
if ( (strcmp( field_names[i], names_out[i] ) != 0)) {
goto out;
}
}
-
+
/* release */
for ( i = 0; i < NFIELDS; i++)
{
free ( names_out[i] );
}
free ( names_out );
-
+
PASSED();
-
+
/*-------------------------------------------------------------------------
* end
*-------------------------------------------------------------------------
@@ -1565,77 +1555,77 @@ out:
/*-------------------------------------------------------------------------
- * the main program
- *-------------------------------------------------------------------------
- */
+* the main program
+*-------------------------------------------------------------------------
+*/
int main(void)
{
hid_t fid; /* identifier for the file */
unsigned flags=H5F_ACC_RDONLY;
-
+
/*-------------------------------------------------------------------------
* test1: create a file for the write/read test
*-------------------------------------------------------------------------
*/
-
+
/* create a file using default properties */
fid=H5Fcreate("test_table.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
-
+
puts("Testing table with file creation mode (read/write in native architecture):");
-
+
/* test, do write */
if (test_table(fid,1)<0)
goto out;
-
+
/* close */
H5Fclose(fid);
-
+
/*-------------------------------------------------------------------------
* test2: open a file written in test1 on a big-endian machine
*-------------------------------------------------------------------------
*/
puts("Testing table with file open mode (read big-endian data):");
-
+
fid=h5file_open(TEST_FILE_BE,flags);
-
+
/* test, do not write */
if (test_table(fid,0)<0)
goto out;
-
+
/* close */
H5Fclose(fid);
-
+
/*-------------------------------------------------------------------------
* test3: open a file written in test1 on a little-endian machine
*-------------------------------------------------------------------------
*/
puts("Testing table with file open mode (read little-endian data):");
-
+
fid=h5file_open(TEST_FILE_LE,flags);
-
+
/* test, do not write */
if (test_table(fid,0)<0)
goto out;
-
+
/* close */
H5Fclose(fid);
-
+
/*-------------------------------------------------------------------------
* test4: open a file written in test1 on the Cray T3 machine
*-------------------------------------------------------------------------
*/
puts("Testing table with file open mode (read Cray data):");
-
+
fid=h5file_open(TEST_FILE_CRAY,flags);
-
+
/* test, do not write */
if (test_table(fid,0)<0)
goto out;
-
+
/* close */
H5Fclose(fid);
-
+
return 0;
out:
H5Fclose(fid);