summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hl/examples/ex_table_04.c33
-rw-r--r--hl/examples/ex_table_05.c30
-rw-r--r--hl/src/H5TB.c56
-rw-r--r--hl/test/test_table.c55
4 files changed, 83 insertions, 91 deletions
diff --git a/hl/examples/ex_table_04.c b/hl/examples/ex_table_04.c
index 55f4ee8..072d640 100644
--- a/hl/examples/ex_table_04.c
+++ b/hl/examples/ex_table_04.c
@@ -24,9 +24,10 @@
*-------------------------------------------------------------------------
*/
-#define NFIELDS (hsize_t) 5
-#define NRECORDS (hsize_t) 8
-#define TABLE_NAME "table"
+#define NFIELDS (hsize_t) 5
+#define NRECORDS (hsize_t) 8
+#define NRECORDS_ADD (hsize_t) 3
+#define TABLE_NAME "table"
int main( void )
{
@@ -84,27 +85,17 @@ int main( void )
herr_t status;
int i;
Particle *p_data = NULL; /* Initially no data */
- float pressure_in [NRECORDS] = /* Define new values for the field "Pressure" */
- { 0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f };
- Position position_in[NRECORDS] = { /* Define new values for "Latitude,Longitude" */
+ float pressure_in [NRECORDS_ADD] = /* Define new values for the field "Pressure" */
+ { 0.0f,1.0f,2.0f};
+ Position position_in[NRECORDS_ADD] = {/* Define new values for "Latitude,Longitude" */
{0,0},
{10,10},
- {20,20},
- {30,30},
- {40,40},
- {50,50},
- {60,60},
- {70,70} };
- NamePressure namepre_in[NRECORDS] = /* Define new values for "Name,Pressure" */
+ {20,20}};
+ NamePressure namepre_in[NRECORDS_ADD] =/* Define new values for "Name,Pressure" */
{ {"zero",0.0f},
{"one", 1.0f},
{"two", 2.0f},
- {"three", 3.0f},
- {"four", 4.0f},
- {"five", 5.0f},
- {"six", 6.0f},
- {"seven", 7.0f},
- };
+ };
size_t field_sizes_pos[2]=
{
sizeof(position_in[0].longi),
@@ -139,13 +130,13 @@ int main( void )
/* Write the pressure field starting at record 2 */
start = 2;
- nrecords = 3;
+ nrecords = NRECORDS_ADD;
status=H5TBwrite_fields_name( file_id, TABLE_NAME, "Pressure", start, nrecords,
sizeof( float ), 0, field_sizes_pre, pressure_in );
/* Write the new longitude and latitude information starting at record 2 */
start = 2;
- nrecords = 3;
+ nrecords = NRECORDS_ADD;
status=H5TBwrite_fields_name( file_id, TABLE_NAME, "Latitude,Longitude", start, nrecords,
sizeof( Position ), field_offset_pos, field_sizes_pos, position_in );
diff --git a/hl/examples/ex_table_05.c b/hl/examples/ex_table_05.c
index b39ef1d..e962d0a 100644
--- a/hl/examples/ex_table_05.c
+++ b/hl/examples/ex_table_05.c
@@ -25,9 +25,12 @@
*-------------------------------------------------------------------------
*/
-#define NFIELDS (hsize_t) 5
-#define NRECORDS (hsize_t) 8
-#define TABLE_NAME "table"
+#define NFIELDS (hsize_t) 5
+#define NRECORDS (hsize_t) 8
+#define NRECORDS_ADD (hsize_t) 3
+#define TABLE_NAME "table"
+
+
int main( void )
{
@@ -91,21 +94,15 @@ int main( void )
int i;
/* Define new values for the field "Pressure" */
- float pressure_in [NRECORDS] =
- { 0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f };
-
+ float pressure_in [NRECORDS_ADD] =
+ { 0.0f,1.0f,2.0f};
int field_index_pre[1] = { 3 };
int field_index_pos[2] = { 1,2 };
/* Define new values for the fields "Latitude,Longitude" */
- Position position_in[NRECORDS] = { {0,0},
+ Position position_in[NRECORDS_ADD] = { {0,0},
{10,10},
- {20,20},
- {30,30},
- {40,40},
- {50,50},
- {60,60},
- {70,70} };
+ {20,20} };
size_t field_sizes_pos[2]=
{
@@ -138,17 +135,19 @@ int main( void )
/* Write the pressure field starting at record 2 */
nfields = 1;
start = 2;
- nrecords = 3;
+ nrecords = NRECORDS_ADD;
status=H5TBwrite_fields_index( file_id, TABLE_NAME, nfields, field_index_pre, start, nrecords,
sizeof( float ), 0, field_sizes_pre, pressure_in );
+
/* Write the new longitude and latitude information starting at record 2 */
nfields = 2;
start = 2;
- nrecords = 3;
+ nrecords = NRECORDS_ADD;
status=H5TBwrite_fields_index( file_id, TABLE_NAME, nfields, field_index_pos, start, nrecords,
sizeof( Position ), field_offset_pos, field_sizes_pos, position_in );
+
/* read the table */
status=H5TBread_table( file_id, TABLE_NAME, dst_size, dst_offset, dst_sizes, dst_buf );
@@ -163,6 +162,7 @@ int main( void )
printf ("\n");
}
+
/* Close the file. */
H5Fclose( file_id );
diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c
index 4d9ec84..a7f9ebf 100644
--- a/hl/src/H5TB.c
+++ b/hl/src/H5TB.c
@@ -502,8 +502,9 @@ herr_t H5TBwrite_fields_name( hid_t loc_id,
hid_t member_type_id;
hid_t nmtype_id;
hsize_t count[1];
- hsize_t offset[1];
- hid_t sid=-1;
+ hsize_t offset[1];
+ hid_t mem_space_id=-1;
+ hid_t file_space_id=-1;
char *member_name;
hssize_t nfields;
hssize_t i, j;
@@ -587,34 +588,34 @@ herr_t H5TBwrite_fields_name( hid_t loc_id,
}
/* Get the dataspace handle */
- if ( (sid = H5Dget_space( did )) < 0 )
+ if ( (file_space_id = H5Dget_space( did )) < 0 )
+ goto out;
+ if ( (mem_space_id = H5Screate_simple(1, &nrecords, NULL)) < 0 )
goto out;
/* Define a hyperslab in the dataset */
offset[0] = start;
count[0] = nrecords;
- if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ if ( H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
goto out;
/* Write */
- if ( H5Dwrite( did, write_type_id, H5S_ALL, sid, PRESERVE, data ) < 0 )
+ if ( H5Dwrite( did, write_type_id, mem_space_id, file_space_id, PRESERVE, data ) < 0 )
goto out;
- /* End access to the write id */
+ /* close */
if ( H5Tclose( write_type_id ) )
goto out;
-
- /* Release the datatype. */
if ( H5Tclose( tid ) < 0 )
return -1;
-
- /* End access to the dataset */
if ( H5Dclose( did ) < 0 )
return -1;
-
- /* End access to the property list */
if ( H5Pclose( PRESERVE ) < 0 )
return -1;
+ if ( H5Sclose( file_space_id ) < 0 )
+ return -1;
+ if ( H5Sclose( mem_space_id ) < 0 )
+ return -1;
return 0;
@@ -623,7 +624,8 @@ out:
H5E_BEGIN_TRY {
H5Pclose(PRESERVE);
H5Dclose(did);
- H5Sclose(sid);
+ H5Sclose(file_space_id);
+ H5Sclose(mem_space_id);
H5Tclose(write_type_id);
H5Tclose(tid);
} H5E_END_TRY;
@@ -673,7 +675,8 @@ herr_t H5TBwrite_fields_index( hid_t loc_id,
hid_t nmtype_id;
hsize_t count[1];
hsize_t offset[1];
- hid_t sid=-1;
+ hid_t mem_space_id=-1;
+ hid_t file_space_id=-1;
char *member_name;
hsize_t i, j;
hid_t PRESERVE;
@@ -744,35 +747,35 @@ herr_t H5TBwrite_fields_index( hid_t loc_id,
}
- /* Get the dataspace handle */
- if ( (sid = H5Dget_space( did )) < 0 )
+ /* Get the dataspace handles */
+ if ( (file_space_id = H5Dget_space( did )) < 0 )
+ goto out;
+ if ( (mem_space_id = H5Screate_simple(1, &nrecords, NULL)) < 0 )
goto out;
/* Define a hyperslab in the dataset */
offset[0] = start;
count[0] = nrecords;
- if ( H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
+ if ( H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0 )
goto out;
/* Write */
- if ( H5Dwrite( did, write_type_id, H5S_ALL, sid, PRESERVE, data ) < 0 )
+ if ( H5Dwrite( did, write_type_id, mem_space_id, file_space_id, PRESERVE, data ) < 0 )
goto out;
- /* End access to the write id */
+ /* close */
if ( H5Tclose( write_type_id ) )
goto out;
-
- /* Release the datatype. */
if ( H5Tclose( tid ) < 0 )
return -1;
-
- /* End access to the dataset */
if ( H5Dclose( did ) < 0 )
return -1;
-
- /* End access to the property list */
if ( H5Pclose( PRESERVE ) < 0 )
return -1;
+ if ( H5Sclose( file_space_id ) < 0 )
+ return -1;
+ if ( H5Sclose( mem_space_id ) < 0 )
+ return -1;
return 0;
@@ -781,7 +784,8 @@ out:
H5E_BEGIN_TRY {
H5Pclose(PRESERVE);
H5Dclose(did);
- H5Sclose(sid);
+ H5Sclose(file_space_id);
+ H5Sclose(mem_space_id);
H5Tclose(write_type_id);
H5Tclose(tid);
} H5E_END_TRY;
diff --git a/hl/test/test_table.c b/hl/test/test_table.c
index ff238f7..f0098b4 100644
--- a/hl/test/test_table.c
+++ b/hl/test/test_table.c
@@ -46,9 +46,11 @@
*-------------------------------------------------------------------------
*/
-#define TITLE "Title"
-#define NFIELDS (hsize_t)5
-#define NRECORDS (hsize_t)8
+#define TITLE "Title"
+#define NFIELDS (hsize_t)5
+#define NRECORDS (hsize_t)8
+#define NRECORDS_ADD (hsize_t)3
+
/*-------------------------------------------------------------------------
* structure used for all tests, a particle with properties
@@ -183,15 +185,10 @@ test_table(hid_t fid, int do_write)
float pressure_out [NRECORDS];
int buf_new[NRECORDS] = { 0,1,2,3,4,5,6,7 };
/* buffers for the fields "Latitude,Longitude" */
- position_t position_out[NRECORDS];
- position_t position_in[NRECORDS] = { {0,0},
+ position_t position_out[NRECORDS_ADD];
+ position_t position_in[NRECORDS_ADD] = { {0,0},
{10,10},
- {20,20},
- {30,30},
- {40,40},
- {50,50},
- {60,60},
- {70,70} };
+ {20,20}};
/* buffers for the fields "Name,Pressure" */
namepressure_t namepre_out[NRECORDS];
namepressure_t namepre_in[NRECORDS] =
@@ -906,14 +903,14 @@ test_table(hid_t fid, int do_write)
/* write the pressure field starting at record 2 */
start = 2;
- nrecords = 3;
+ 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;
+ nrecords = NRECORDS_ADD;
if (H5TBwrite_fields_name(fid,"table9","Latitude,Longitude",start,nrecords,sizeof(position_t),
field_offset_pos,field_sizes_pos,position_in)<0)
goto out;
@@ -929,9 +926,9 @@ test_table(hid_t fid, int do_write)
{
if ( i >= 2 && i <= 4 )
{
- if ( rbuf[i].lati != position_in[i].lati ||
- rbuf[i].longi != position_in[i].longi ||
- rbuf[i].pressure != pressure_in[i] )
+ if ( rbuf[i].lati != position_in[i-NRECORDS_ADD+1].lati ||
+ rbuf[i].longi != position_in[i-NRECORDS_ADD+1].longi ||
+ rbuf[i].pressure != pressure_in[i-NRECORDS_ADD+1] )
{
fprintf(stderr,"%ld %f %d\n",
rbuf[i].longi,rbuf[i].pressure,rbuf[i].lati);
@@ -968,7 +965,7 @@ test_table(hid_t fid, int do_write)
/* write the pressure field to all the records */
start = 0;
- nrecords = NRECORDS;
+ nrecords = NRECORDS_ADD;
if ( H5TBwrite_fields_name(fid,"table10","Pressure",start,nrecords,
sizeof( float ),0,field_sizes_pre,pressure_in)<0)
goto out;
@@ -976,13 +973,13 @@ test_table(hid_t fid, int do_write)
/* read the "Pressure" field */
start = 0;
- nrecords = NRECORDS;
+ nrecords = NRECORDS_ADD;
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++ )
+ for( i = 0; i < NRECORDS_ADD; i++ )
{
if ( pressure_out[i] != pressure_in[i] ) {
goto out;
@@ -997,7 +994,7 @@ test_table(hid_t fid, int do_write)
{
/* Write the new longitude and latitude information to all the records */
start = 0;
- nrecords = NRECORDS;
+ nrecords = NRECORDS_ADD;
if ( H5TBwrite_fields_name(fid,"table10", "Latitude,Longitude", start, nrecords,
sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 )
goto out;
@@ -1005,13 +1002,13 @@ test_table(hid_t fid, int do_write)
/* Read the "Latitude,Longitude" fields */
start = 0;
- nrecords = NRECORDS;
+ 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; i++ )
+ for( i = 0; i < NRECORDS_ADD; i++ )
{
if ( position_out[i].lati != position_in[i].lati ||
position_out[i].longi != position_in[i].longi )
@@ -1098,7 +1095,7 @@ test_table(hid_t fid, int do_write)
/* write the pressure field starting at record 2 */
nfields = 1;
start = 2;
- nrecords = 3;
+ nrecords = NRECORDS_ADD;
if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pre, start, nrecords,
sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 )
goto out;
@@ -1107,7 +1104,7 @@ test_table(hid_t fid, int do_write)
/* write the new longitude and latitude information starting at record 2 */
nfields = 2;
start = 2;
- nrecords = 3;
+ nrecords = NRECORDS_ADD;
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;
@@ -1125,9 +1122,9 @@ test_table(hid_t fid, int do_write)
{
if ( i >= 2 && i <= 4 )
{
- if ( rbuf[i].lati != position_in[i].lati ||
- rbuf[i].longi != position_in[i].longi ||
- rbuf[i].pressure != pressure_in[i] )
+ if ( rbuf[i].lati != position_in[i-NRECORDS_ADD+1].lati ||
+ rbuf[i].longi != position_in[i-NRECORDS_ADD+1].longi ||
+ rbuf[i].pressure != pressure_in[i-NRECORDS_ADD+1] )
goto out;
}
}
@@ -1203,13 +1200,13 @@ test_table(hid_t fid, int do_write)
/* read the "Latitude,Longitude" fields */
nfields = 2;
start = 0;
- nrecords = NRECORDS;
+ nrecords = NRECORDS_ADD;
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; i++ )
+ for( i = 0; i < NRECORDS_ADD; i++ )
{
if ( position_out[i].lati != position_in[i].lati ||
position_out[i].longi != position_in[i].longi ) {