[Top] [Prev] [Next]
create_vdatas.c
#include "hdf.h"
#define FILE1_NAME "General_Vdatas.hdf"
#define FILE2_NAME "Two_Vdatas.hdf"
#define VDATA_NAME "Vdata 1"
#define VDATA_CLASS "Empty Vdatas"
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file1_id, file2_id,
vdata_id, vdata1_id, vdata2_id,
vdata_ref = -1; /* ref number of a vdata, set to -1 to create */
/********************** End of variable declaration **********************/
/*
* Create the first HDF file.
*/
file1_id = Hopen (FILE1_NAME, DFACC_CREATE, 0);
/*
* Initialize the VS interface associated with the first HDF file.
*/
status_n = Vstart (file1_id);
/*
* Create a vdata in the first HDF file.
*/
vdata_id = VSattach (file1_id, vdata_ref, "w");
/*
* Assign a name to the vdata.
*/
status_32 = VSsetname (vdata_id, VDATA_NAME);
/*
* Other operations on the vdata identified by vdata_id can be carried
* out starting from this point.
*/
/*
* Create the second HDF file.
*/
file2_id = Hopen (FILE2_NAME, DFACC_CREATE, 0);
/*
* Initialize the VS interface associated with the second HDF file.
*/
status_n = Vstart (file2_id);
/*
* Create the first vdata in the second HDF file.
*/
vdata1_id = VSattach (file2_id, vdata_ref, "w");
/*
* Create the second vdata in the second HDF file.
*/
vdata2_id = VSattach (file2_id, vdata_ref, "w");
/*
* Assign a class name to these vdatas.
*/
status_32 = VSsetclass (vdata1_id, VDATA_CLASS);
status_32 = VSsetclass (vdata2_id, VDATA_CLASS);
/*
* Other operations on the vdatas identified by vdata1_id and vdata2_id
* can be carried out starting from this point.
*/
/*
* Terminate access to the first vdata in the second HDF file.
*/
status_32 = VSdetach (vdata1_id);
/*
* Terminate access to the second vdata in the second HDF file.
*/
status_32 = VSdetach (vdata2_id);
/*
* From this point on, any operations on the vdatas identified by vdata1_id
and vdata2_id are invalid but not on the vdata identified by vdata_id.
*/
/*
* Terminate access to the VS interface associated with the second HDF file.
*/
status_n = Vend (file2_id);
/*
* Close the second HDF file.
*/
status_n = Hclose (file2_id);
/*
* Terminate access to the vdata in the first HDF file.
*/
status_32 = VSdetach (vdata_id);
/*
* Terminate access to the VS interface associated with the first HDF file.
*/
status_n = Vend (file1_id);
/*
* Close the first HDF file.
*/
status_n = Hclose (file1_id);
}
create_vdatas.f
program create_vdatas
implicit none
C
C Parameter declaration
C
character*18 FILE1_NAME
character*14 FILE2_NAME
character*7 VDATA_NAME
character*12 VDATA_CLASS
C
parameter (FILE1_NAME = `General_Vdatas.hdf',
+ FILE2_NAME = `Two_Vdatas.hdf',
+ VDATA_NAME = `Vdata 1',
+ VDATA_CLASS = `Empty Vdatas')
integer DFACC_CREATE
parameter (DFACC_CREATE = 4)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsfatch, vsfsnam, vsfscls, vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file1_id, file2_id
integer vdata_id, vdata1_id, vdata2_id
integer vdata_ref
C
C**** End of variable declaration ************************************
C
C
C Create the first HDF file.
C
file1_id = hopen(FILE1_NAME, DFACC_CREATE, 0)
C
C Initialize the VS interface associated with the first HDF file.
C
status = vfstart(file1_id)
C
C Create a vdata in the first HDF file.
C
vdata_ref = -1
vdata_id = vsfatch(file1_id, vdata_ref, `w')
C
C Assign a name to the vdata.
C
status = vsfsnam(vdata_id, VDATA_NAME)
C
C Other operations on the vdata identified by vdata_id can be carried out
C starting from this point.
C
C Create the second HDF file.
C
file2_id = hopen(FILE2_NAME, DFACC_CREATE, 0)
C
C Initialize the VS interface associated with the second HDF file.
C
status = vfstart(file2_id)
C
C Create the first vdata in the second HDF file.
C
vdata1_id = vsfatch(file2_id, vdata_ref, `w')
C
C Create the second vdata in the second HDF file.
C
vdata2_id = vsfatch(file2_id, vdata_ref, `w')
C
C Assign a class name to these vdatas.
C
status = vsfscls(vdata1_id, VDATA_CLASS)
status = vsfscls(vdata2_id, VDATA_CLASS)
C
C Other operations on the vdatas identified by vdata1_id and vdata2_id
C can be carried out starting from this point.
C
C
C Terminate access to the first vdata in the second HDF file.
C
status = vsfdtch(vdata1_id)
C
C Terminate access to the second vdata in the second HDF file.
C
status = vsfdtch(vdata2_id)
C
C Terminate access to the VS interface associated with the second HDF file.
C
status = vfend(file2_id)
C
C Close the second HDF file.
C
status = hclose(file2_id)
C
C Terminate access to the vdata in the first HDF file.
C
status = vsfdtch(vdata_id)
C
C terminate access to the VS interface associated with the first HDF file.
C
status = vfend(file1_id)
C
C Close the first HDF file.
C
status = hclose(file1_id)
end
create_onefield_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define CLASS1_NAME "5x1 Array"
#define CLASS2_NAME "6x4 Array"
#define VDATA1_NAME "First Vdata"
#define VDATA2_NAME "Second Vdata"
#define FIELD1_NAME "Single-component Field"
#define FIELD2_NAME "Multi-component Field"
#define N_RECORDS_1 5 /* number of records the first vdata contains */
#define N_RECORDS_2 6 /* number of records the second vdata contains */
#define ORDER_2 4 /* order of the field in the second vdata */
/* Note that the order of the field in the first vdata is 1 */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32; /* returned status for functions returning an int32 */
int32 file_id, vdata1_ref, vdata2_ref;
/*
* Define an array to buffer the data of the first vdata.
*/
char8 vdata1_buf [N_RECORDS_1] = {`V', `D', `A', `T', `A'};
/*
* Define an array to buffer the data of the second vdata.
*/
int32 vdata2_buf [N_RECORDS_2][ORDER_2] = {{1, 2, 3, 4}, {2, 4, 6, 8},
{3, 6, 9, 12}, {4, 8, 12, 16},
{5, 10, 15, 20}, {6, 12, 18, 24}};
/********************** End of variable declaration **********************/
/*
* Open the HDF file for writing.
*/
file_id = Hopen (FILE_NAME, DFACC_WRITE, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Create the first vdata and populate it with data from the vdata1_buf
* array. Note that the buffer vdata1_buf is cast to (uint8 *) for the
* benefit of generic data type.
*/
vdata1_ref = VHstoredata (file_id, FIELD1_NAME, (uint8 *)vdata1_buf,
N_RECORDS_1, DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME);
/*
* Create the second vdata and populate it with data from the vdata2_buf
* array.
*/
vdata2_ref = VHstoredatam (file_id, FIELD2_NAME, (uint8 *)vdata2_buf,
N_RECORDS_2, DFNT_INT32, VDATA2_NAME, CLASS2_NAME, ORDER_2);
/*
* Terminate access to the VS interface and close the HDF file.
*/
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
create_onefield_vdata.f
program create_onefield_vdatas
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*9 CLASS1_NAME
character*9 CLASS2_NAME
character*11 VDATA1_NAME
character*12 VDATA2_NAME
character*22 FIELD1_NAME
character*21 FIELD2_NAME
integer N_RECORDS_1, N_RECORDS_2
integer ORDER_2
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ CLASS1_NAME = `5x1 Array',
+ CLASS2_NAME = `6x4 Array',
+ VDATA1_NAME = `First Vdata',
+ VDATA2_NAME = `Second Vdata',
+ FIELD1_NAME = `Single-component Field',
+ FIELD2_NAME = `Multi-component Field')
parameter (N_RECORDS_1 = 5,
+ N_RECORDS_2 = 6,
+ ORDER_2 = 4)
integer DFACC_WRITE, DFNT_CHAR8, DFNT_INT32
parameter (DFACC_WRITE = 2,
+ DFNT_CHAR8 = 4,
+ DFNT_INT32 = 24)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vhfscd, vhfsdm, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id
integer vdata1_ref, vdata2_ref
character vdata1_buf(N_RECORDS_1)
integer vdata2_buf(ORDER_2, N_RECORDS_2)
data vdata1_buf /'V','D','A','T','A'/
data vdata2_buf / 1, 2, 3, 4,
+ 2, 4, 6, 8,
+ 3, 6, 9, 12,
+ 4, 8, 12, 16,
+ 5, 10, 15, 20,
+ 6, 12, 18, 24/
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for writing.
C
file_id = hopen(FILE_NAME, DFACC_WRITE, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
C
C Create the first vdata and populate it with data from vdata1_buf array.
C
vdata1_ref = vhfscd(file_id, FIELD1_NAME, vdata1_buf, N_RECORDS_1,
+ DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME)
C
C Create the second vdata and populate it with data from vdata2_buf array.
C
vdata2_ref = vhfsdm(file_id, FIELD2_NAME, vdata2_buf, N_RECORDS_2,
+ DFNT_INT32, VDATA2_NAME, CLASS2_NAME,
+ ORDER_2)
C
C Terminate access to the VS interface and close the HDF file.
C
status = vfend(file_id)
status = hclose(file_id)
end
write_to_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define N_RECORDS 10 /* number of records the vdata contains */
#define ORDER_1 3 /* order of first field */
#define ORDER_2 1 /* order of second field */
#define ORDER_3 2 /* order of third field */
#define CLASS_NAME "Particle Data"
#define VDATA_NAME "Solid Particle"
#define FIELD1_NAME "Position" /* contains x, y, z values */
#define FIELD2_NAME "Mass" /* contains weight values */
#define FIELD3_NAME "Temperature" /* contains min and max values */
#define FIELDNAME_LIST "Position,Mass,Temperature" /* No spaces b/w names */
/* number of values per record */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2 + ORDER_3)
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref = -1, /* ref number of a vdata, set to -1 to create */
num_of_records; /* number of records actually written to vdata */
int16 rec_num; /* current record number */
float32 data_buf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for writing.
*/
file_id = Hopen (FILE_NAME, DFACC_WRITE, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Create a new vdata.
*/
vdata_id = VSattach (file_id, vdata_ref, "w");
/*
* Set name and class name of the vdata.
*/
status_32 = VSsetname (vdata_id, VDATA_NAME);
status_32 = VSsetclass (vdata_id, CLASS_NAME);
/*
* Introduce each field's name, data type, and order. This is the first
* part in defining a field.
*/
status_n = VSfdefine (vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER_1 );
status_n = VSfdefine (vdata_id, FIELD2_NAME, DFNT_FLOAT32, ORDER_2 );
status_n = VSfdefine (vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER_3 );
/*
* Finalize the definition of the fields.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Buffer the data by the record for fully interlaced mode. Note that the
* first three elements contain the three values of the first field, the
* fourth element contains the value of the second field, and the last two
* elements contain the two values of the third field.
*/
for (rec_num = 0; rec_num < N_RECORDS; rec_num++)
{
data_buf[rec_num][0] = 1.0 * rec_num;
data_buf[rec_num][1] = 2.0 * rec_num;
data_buf[rec_num][2] = 3.0 * rec_num;
data_buf[rec_num][3] = 0.1 + rec_num;
data_buf[rec_num][4] = 0.0;
data_buf[rec_num][5] = 65.0;
}
/*
* Write the data from data_buf to the vdata with full interlacing mode.
*/
num_of_records = VSwrite (vdata_id, (uint8 *)data_buf, N_RECORDS,
FULL_INTERLACE);
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
write_to_vdata.f
program write_to_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*13 CLASS_NAME
character*14 VDATA_NAME
character*8 FIELD1_NAME
character*4 FIELD2_NAME
character*11 FIELD3_NAME
character*27 FIELDNAME_LIST
integer N_RECORDS
integer ORDER_1, ORDER_2, ORDER_3
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ CLASS_NAME = `Particle Data',
+ VDATA_NAME = `Solid Particle',
+ FIELD1_NAME = `Position',
+ FIELD2_NAME = `Mass',
+ FIELD3_NAME = `Temperature',
+ FIELDNAME_LIST = `Position,Mass,Temperature')
parameter (N_RECORDS = 10,
+ ORDER_1 = 3,
+ ORDER_2 = 1,
+ ORDER_3 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 + ORDER_3)
integer DFACC_WRITE, DFNT_FLOAT32, FULL_INTERLACE
parameter (DFACC_WRITE = 2,
+ DFNT_FLOAT32 = 5,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsfatch, vsfsnam, vsfscls, vsffdef, vsfsfld,
+ vsfwrt, vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id
integer vdata_ref, rec_num, num_of_records
real data_buf(N_VALS_PER_REC, N_RECORDS)
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for writing.
C
file_id = hopen(FILE_NAME, DFACC_WRITE, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
C
C Create a new vdata.
C
vdata_ref = -1
vdata_id = vsfatch(file_id, vdata_ref, `w')
C
C Set name and class name of the vdata.
C
status = vsfsnam(vdata_id, VDATA_NAME)
status = vsfscls(vdata_id, CLASS_NAME)
C
C Introduce each field's name, data type, and order. This is the
C first part in defining a field.
C
status = vsffdef(vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER_1)
status = vsffdef(vdata_id, FIELD2_NAME, DFNT_FLOAT32, ORDER_2)
status = vsffdef(vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER_3)
C
C Finalize the definition of the fields.
C
status = vsfsfld(vdata_id, FIELDNAME_LIST)
C
C Buffer the data by the record for fully interlaced mode. Note that the
C first three elements contain the three values of the first field,
C the forth element contains the value of the second field, and the last two
C elements contain the two values of the third field.
C
do 10 rec_num = 1, N_RECORDS
data_buf(1, rec_num) = 1.0 * rec_num
data_buf(2, rec_num) = 2.0 * rec_num
data_buf(3, rec_num) = 3.0 * rec_num
data_buf(4, rec_num) = 0.1 + rec_num
data_buf(5, rec_num) = 0.0
data_buf(6, rec_num) = 65.0
10 continue
C
C Write the data from data_buf to the vdata with the full interlacing mode.
C
num_of_records = vsfwrt(vdata_id, data_buf, N_RECORDS,
+ FULL_INTERLACE)
C
C Terminate access to the vdata and to the VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
write_mixed_vdata.c
#include "hdf.h"
#define FILE_NAME "Packed_Vdata.hdf"
#define VDATA_NAME "Mixed Data Vdata"
#define CLASS_NAME "General Data Class"
#define FIELD1_NAME "Temp"
#define FIELD2_NAME "Height"
#define FIELD3_NAME "Speed"
#define FIELD4_NAME "Ident"
#define ORDER 1 /* number of values in the field */
#define N_RECORDS 20 /* number of records the vdata contains */
#define N_FIELDS 4 /* number of fields in the vdata */
#define FIELDNAME_LIST "Temp,Height,Speed,Ident" /* No spaces b/w names */
/* number of bytes of the data to be written, i.e., the size of all the
field values combined times the number of records */
#define BUF_SIZE (2*sizeof(float32) + sizeof(int16) + sizeof(char)) * N_RECORDS
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref = -1, /* vdata's reference number, set to -1 to create */
num_of_records; /* number of records actually written to the vdata */
float32 temp[N_RECORDS]; /* buffer to hold values of first field */
int16 height[N_RECORDS]; /* buffer to hold values of second field */
float32 speed[N_RECORDS]; /* buffer to hold values of third field */
char8 ident[N_RECORDS]; /* buffer to hold values of fourth field */
VOIDP fldbufptrs[N_FIELDS];/*pointers to be pointing to the field buffers*/
uint16 databuf[BUF_SIZE]; /* buffer to hold the data after being packed*/
int i;
/********************** End of variable declaration **********************/
/*
* Create an HDF file.
*/
file_id = Hopen (FILE_NAME, DFACC_CREATE, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Create a new vdata.
*/
vdata_id = VSattach (file_id, vdata_ref, "w");
/*
* Set name and class name of the vdata.
*/
status_32 = VSsetname (vdata_id, VDATA_NAME);
status_32 = VSsetclass (vdata_id, CLASS_NAME);
/*
* Introduce each field's name, data type, and order. This is the first
* part in defining a vdata field.
*/
status_n = VSfdefine (vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER);
status_n = VSfdefine (vdata_id, FIELD2_NAME, DFNT_INT16, ORDER);
status_n = VSfdefine (vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER);
status_n = VSfdefine (vdata_id, FIELD4_NAME, DFNT_CHAR8, ORDER);
/*
* Finalize the definition of the fields of the vdata.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Enter data values into the field buffers by the records.
*/
for (i = 0; i < N_RECORDS; i++)
{
temp[i] = 1.11 * (i+1);
height[i] = i;
speed[i] = 1.11 * (i+1);
ident[i] = `A' + i;
}
/*
* Build an array of pointers each of which points to a field buffer that
* holds all values of the field.
*/
fldbufptrs[0] = &temp[0];
fldbufptrs[1] = &height[0];
fldbufptrs[2] = &speed[0];
fldbufptrs[3] = &ident[0];
/*
* Pack all data in the field buffers that are pointed to by the set of
* pointers fldbufptrs, and store the packed data into the buffer
* databuf. Note that the second parameter is _HDF_VSPACK for packing.
*/
status_n = VSfpack (vdata_id,_HDF_VSPACK, NULL, (VOIDP)databuf,
BUF_SIZE, N_RECORDS, NULL, (VOIDP)fldbufptrs);
/*
* Write all records of the packed data to the vdata.
*/
num_of_records = VSwrite (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Terminate access to the vdata and the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
write_mixed_vdata.f
program write_mixed_vdata
implicit none
C
C Parameter declaration
C
character*16 FILE_NAME
character*18 CLASS_NAME
character*16 VDATA_NAME
character*4 FIELD1_NAME
character*6 FIELD2_NAME
character*5 FIELD3_NAME
character*5 FIELD4_NAME
character*23 FIELDNAME_LIST
integer N_RECORDS, N_FIELDS, ORDER
integer BUF_SIZE
C
parameter (FILE_NAME = `Packed_Vdata.hdf',
+ CLASS_NAME = `General Data Class',
+ VDATA_NAME = `Mixed Data Vdata',
+ FIELD1_NAME = `Temp',
+ FIELD2_NAME = `Height',
+ FIELD3_NAME = `Speed',
+ FIELD4_NAME = `Ident',
+ FIELDNAME_LIST = `Temp,Height,Speed,Ident')
parameter (N_RECORDS = 20,
+ N_FIELDS = 4,
+ ORDER = 1,
+ BUF_SIZE = (4 + 2 + 4 + 1)*N_RECORDS)
integer DFACC_WRITE, DFNT_FLOAT32, DFNT_INT16, DFNT_CHAR8,
+ FULL_INTERLACE, HDF_VSPACK
parameter (DFACC_WRITE = 2,
+ DFNT_FLOAT32 = 5,
+ DFNT_INT16 = 22,
+ DFNT_CHAR8 = 4,
+ FULL_INTERLACE = 0,
+ HDF_VSPACK = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsfatch, vsfsnam, vsfscls, vsffdef, vsfsfld,
+ vsfnpak, vsfcpak, vsfwrit, vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id
integer vdata_ref, num_of_records
real temp(N_RECORDS)
integer*2 height(N_RECORDS)
real speed(N_RECORDS)
character ident(N_RECORDS)
integer i
C
C Buffer for packed data should be big enough to hold N_RECORDS.
C
integer databuf(BUF_SIZE/4 + 1)
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for writing.
C
file_id = hopen(FILE_NAME, DFACC_WRITE, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
C
C Create a new vdata.
C
vdata_ref = -1
vdata_id = vsfatch(file_id, vdata_ref, `w')
C
C Set name and class name of the vdata.
C
status = vsfsnam(vdata_id, VDATA_NAME)
status = vsfscls(vdata_id, CLASS_NAME)
C
C Introduce each field's name, data type, and order. This is the
C first part in defining a field.
C
status = vsffdef(vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER)
status = vsffdef(vdata_id, FIELD2_NAME, DFNT_INT16, ORDER)
status = vsffdef(vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER)
status = vsffdef(vdata_id, FIELD4_NAME, DFNT_CHAR8, ORDER)
C
C Finalize the definition of the fields.
C
status = vsfsfld(vdata_id, FIELDNAME_LIST)
C
C Enter data values into the field databufs by the records.
C
do 10 i = 1, N_RECORDS
temp(i) = 1.11 * i
height(i) = i - 1
speed(i) = 1.11 * i
ident(i) = char(64+i)
10 continue
C
C Pack N_RECORDS of data into databuf. In Fortran, each field is packed
C using separate calls to vsfnpak or vsfcpak.
C
status = vsfnpak(vdata_id, HDF_VSPACK, ` `, databuf, BUF_SIZE,
+ N_RECORDS, FIELD1_NAME, temp)
status = vsfnpak(vdata_id, HDF_VSPACK, ` `, databuf, BUF_SIZE,
+ N_RECORDS, FIELD2_NAME, height)
status = vsfnpak(vdata_id, HDF_VSPACK, ` `, databuf, BUF_SIZE,
+ N_RECORDS, FIELD3_NAME, speed)
status = vsfcpak(vdata_id, HDF_VSPACK, ` `, databuf, BUF_SIZE,
+ N_RECORDS, FIELD4_NAME, ident)
C
C Write all the records of the packed data to the vdata.
C
num_of_records = vsfwrit(vdata_id, databuf, N_RECORDS,
+ FULL_INTERLACE)
C
C Terminate access to the vdata and to the VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,
+ FULL_INTERLACE = 0)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, VS interface, and
C close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
read_from_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define N_RECORDS 5 /* number of records the vdata contains */
#define RECORD_INDEX 3 /* position where reading starts - 4th record */
#define ORDER_1 3 /* order of first field to be read */
#define ORDER_2 2 /* order of second field to be read */
#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */
#define N_VALS_PER_REC (ORDER_1 + ORDER_2)
/* number of values per record */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
file_id, vdata_id,
vdata_ref, /* vdata's reference number */
num_of_records, /* number of records actually written to the vdata */
record_pos; /* position of the current record */
int16 i, rec_num; /* current record number in the vdata */
float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */
/********************** End of variable declaration **********************/
/*
* Open the HDF file for reading.
*/
file_id = Hopen (FILE_NAME, DFACC_READ, 0);
/*
* Initialize the VS interface.
*/
status_n = Vstart (file_id);
/*
* Get the reference number of the vdata, whose name is specified in
* VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for reading if it is found, otherwise
* exit the program.
*/
if (vdata_ref == 0) exit;
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields (vdata_id, FIELDNAME_LIST);
/*
* Place the current point to the position specified in RECORD_INDEX.
*/
record_pos = VSseek (vdata_id, RECORD_INDEX);
/*
* Read the next N_RECORDS records from the vdata and store the data
* in the buffer databuf with fully interlaced mode.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Display the read data as many records as the number of records
* returned by VSread.
*/
printf ("\n Particle Position Temperature Range\n\n");
for (rec_num = 0; rec_num < num_of_records; rec_num++)
{
printf (" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n",
databuf[rec_num][0], databuf[rec_num][1], databuf[rec_num][2],
databuf[rec_num][3], databuf[rec_num][4]);
}
/*
* Terminate access to the vdata and to the VS interface, then close
* the HDF file.
*/
status_32 = VSdetach (vdata_id);
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
read_from_vdata.f
program read_from_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*20 FIELDNAME_LIST
integer N_RECORDS, RECORD_INDEX
integer ORDER_1, ORDER_2
integer N_VALS_PER_REC
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELDNAME_LIST = `Position,Temperature')
parameter (N_RECORDS = 5,
+ RECORD_INDEX = 3,
+ ORDER_1 = 3,
+ ORDER_2 = 2,
+ N_VALS_PER_REC = ORDER_1 + ORDER_2 )
integer DFACC_READ, FULL_INTERLACE
parameter (DFACC_READ = 1,