[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, vsfatch, vsfsfld, vsfrd, vsfseek,
+ vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id
integer vdata_ref, rec_num, num_of_records, rec_pos
real databuf(N_VALS_PER_REC, N_RECORDS)
integer i
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for reading.
C
file_id = hopen(FILE_NAME, DFACC_READ, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
C
C Get the reference number of the vdata, whose name is specified in
C VDATA_NAME, using vsffnd, which will be discussed in Section 4.7.3.
C
vdata_ref = vsffnd(file_id, VDATA_NAME)
C
C Attach to the vdata for reading if it is found,
C otherwise exit the program.
C
if (vdata_ref .eq. 0) stop
vdata_id = vsfatch(file_id, vdata_ref, `r')
C
C Specify the fields that will be read.
C
status = vsfsfld(vdata_id, FIELDNAME_LIST)
C
C Place the current point to the position specified in RECORD_INDEX.
C
rec_pos = vsfseek(vdata_id, RECORD_INDEX)
C
C Read the next N_RECORDS from the vdata and store the data in the buffer
C databuf with fully interlace mode.
C
num_of_records = vsfrd(vdata_id, databuf, N_RECORDS,
+ FULL_INTERLACE)
C
C Display the read data as many records as the number of records returned
C by vsfrd.
C
write(*,*) ` Particle Position Temperature Range'
write(*,*)
do 10 rec_num = 1, num_of_records
write(*,1000) (databuf(i, rec_num), i = 1, N_VALS_PER_REC)
10 continue
1000 format(1x,3(f6.2), 8x,2(f6.2))
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_mixed_vdata.c
#include "hdf.h"
#define N_RECORDS 20 /* number of records to be read */
#define N_FIELDS 2 /* number of fields to be read */
#define FILE_NAME "Packed_Vdata.hdf"
#define VDATA_NAME "Mixed Data Vdata"
#define FIELDNAME_LIST "Temp,Ident"
/* number of bytes of the data to be read */
#define BUFFER_SIZE ( sizeof(float32) + 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,
num_of_records, /* number of records actually read */
vdata_ref, /* reference number of the vdata to be read */
buffer_size; /* number of bytes the vdata can hold */
float32 itemp[N_RECORDS]; /* buffer to hold values of first field */
char idents[N_RECORDS]; /* buffer to hold values of fourth field */
uint8 databuf[BUFFER_SIZE]; /* buffer to hold read data, still packed */
VOIDP fldbufptrs[N_FIELDS];/*pointers to be pointing to the field buffers*/
int i;
/********************** 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.
*/
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Specify the fields that will be read.
*/
status_n = VSsetfields(vdata_id, FIELDNAME_LIST);
/*
* Read N_RECORDS records of the vdata and store the values into the
* buffer databuf.
*/
num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS,
FULL_INTERLACE);
/*
* Build an array of pointers each of which points to an array that
* will hold all values of a field after being unpacked.
*/
fldbufptrs[0] = &itemp[0];
fldbufptrs[1] = &idents[0];
/*
* Unpack the data from the buffer databuf and store the values into the
* appropriate field buffers pointed to by the set of pointers fldbufptrs.
* Note that the second parameter is _HDF_VSUNPACK for unpacking and the
* number of records is the one returned by VSread.
*/
status_n = VSfpack (vdata_id, _HDF_VSUNPACK, FIELDNAME_LIST, (VOIDP)databuf,
BUFFER_SIZE, num_of_records, NULL, (VOIDP)fldbufptrs);
/*
* Display the read data being stored in the field buffers.
*/
printf ("\n Temp Ident\n");
for (i=0; i < num_of_records; i++)
printf (" %6.2f %c\n", itemp[i], idents[i]);
/*
* 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);
}
read_mixed_vdata.f
program read_mixed_vdata
implicit none
C
C Parameter declaration
C
character*16 FILE_NAME
character*16 VDATA_NAME
character*4 FIELD1_NAME
character*5 FIELD2_NAME
character*10 FIELDNAME_LIST
integer N_RECORDS, N_FIELDS
integer BUFFER_SIZE
C
parameter (FILE_NAME = `Packed_Vdata.hdf',
+ VDATA_NAME = `Mixed Data Vdata',
+ FIELD1_NAME = `Temp',
+ FIELD2_NAME = `Ident',
+ FIELDNAME_LIST = `Temp,Ident')
parameter (N_RECORDS = 20,
+ N_FIELDS = 2,
+ BUFFER_SIZE = (4 + 1)*N_RECORDS)
integer DFACC_READ, DFNT_FLOAT32, DFNT_CHAR8,
+ FULL_INTERLACE, HDF_VSUNPACK
parameter (DFACC_READ = 1,
+ DFNT_FLOAT32 = 5,
+ DFNT_CHAR8 = 4,
+ FULL_INTERLACE = 0,
+ HDF_VSUNPACK = 1)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsfatch, vsffnd, vsfsfld,
+ vsfnpak, vsfcpak, vsfread, vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id
integer vdata_ref, num_of_records
real temp(N_RECORDS)
character ident(N_RECORDS)
integer i
C
C Buffer for read packed data should be big enough to hold N_RECORDS.
C
integer databuf(BUFFER_SIZE/4 + 1)
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for reading.
C
file_id = hopen(FILE_NAME, DFACC_READ, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
C
C Get the reference number of the vdata, whose name is specified in
C VDATA_NAME, using vsffnd, which will be discussed in Section 4.7.3.
C
vdata_ref = vsffnd(file_id, VDATA_NAME)
C
C Attach to the vdata for reading if it is found,
C otherwise exit the program.
C
if (vdata_ref .eq. 0) stop
vdata_id = vsfatch(file_id, vdata_ref, `r')
C
C Specify the fields that will be read.
C
status = vsfsfld(vdata_id, FIELDNAME_LIST)
C
C Read N_RECORDS records of the vdata and store the values into the databuf.
C
num_of_records = vsfread(vdata_id, databuf, N_RECORDS,
+ FULL_INTERLACE)
C
C Unpack N_RECORDS from databuf into temp and ident arrays.
C In Fortran, each field is unpacked using separate calls to
C vsfnpak or vsfcpak.
C
status = vsfnpak(vdata_id, HDF_VSUNPACK, FIELDNAME_LIST, databuf,
+ BUFFER_SIZE, num_of_records, FIELD1_NAME, temp)
status = vsfcpak(vdata_id, HDF_VSUNPACK, FIELDNAME_LIST, databuf,
+ BUFFER_SIZE, num_of_records, FIELD2_NAME, ident)
C
C Display the read data being stored in the field databufs.
C
write (*,*) ` Temp Ident'
do 10 i = 1, num_of_records
write(*,1000) temp(i), ident(i)
10 continue
1000 format (3x,F6.2, 4x, a)
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
locate_vdata.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define SEARCHED_FIELDS "Position,Temperature"
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,
index = 0; /* index of the vdata in the file - manually kept */
int8 found_fields; /* TRUE if the specified fields exist in the vdata */
/********************** 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);
/*
* Set the reference number to -1 to start the search from
* the beginning of file.
*/
vdata_ref = -1;
/*
* Assume that the specified fields are not found in the current vdata.
*/
found_fields = FALSE;
/*
* Use VSgetid to obtain each vdata by its reference number then
* attach to the vdata and search for the fields. The loop
* terminates when the last vdata is reached or when a vdata which
* contains the fields listed in SEARCHED_FIELDS is found.
*/
while ((vdata_ref = VSgetid (file_id, vdata_ref)) != FAIL)
{
vdata_id = VSattach (file_id, vdata_ref, "r");
if ((status_n = VSfexist (vdata_id, SEARCHED_FIELDS)) != FAIL)
{
found_fields = TRUE;
break;
}
/*
* Detach from the current vdata before continuing searching.
*/
status_32 = VSdetach (vdata_id);
index++; /* advance the index by 1 for the next vdata */
}
/*
* Print the index of the vdata containing the fields or a "not found"
* message if no such vdata is found. Also detach from the vdata found.
*/
if (!found_fields)
printf ("Fields Position and Temperature were not found.\n");
else
{
printf
("Fields Position and Temperature found in the vdata at position %d\n",
index);
status_32 = VSdetach (vdata_id);
}
/*
* Terminate access to the VS interface and close the HDF file.
*/
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
locate_vdata.f
program locate_vdata
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*20 SEARCHED_FIELDS
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ SEARCHED_FIELDS = `Position,Temperature')
integer DFACC_READ
parameter (DFACC_READ = 1)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsfatch, vsfgid, vsfex, vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id, vdata_ref
integer index
logical found_fields
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for reading.
C
file_id = hopen(FILE_NAME, DFACC_READ, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
index = 0
C
C Set the reference number to -1 to start the search from the beginning
C of the file.
C
vdata_ref = -1
C
C Assume that the specified fields are not found in the current vdata.
C
found_fields = .FALSE.
10 continue
C
C Use vsfgid to obtain each vdata by its reference number then
C attach to the vdata and search for the fields. The loop terminates
C when the last vdata is reached or when a vdata which contains the
C fields listed in SEARCHED_FIELDS is found.
C
vdata_ref = vsfgid(file_id, vdata_ref)
if (vdata_ref .eq. -1) goto 100
vdata_id = vsfatch(file_id, vdata_ref, `r')
status = vsfex(vdata_id, SEARCHED_FIELDS)
if (status .ne. -1) then
found_fields = .TRUE.
goto 100
endif
status = vsfdtch(vdata_id)
index = index + 1
goto 10
100 continue
C
C Print the index of the vdata containing the fields or a `not found'
C message if no such vdata is found. Also detach from the vdata found.
C
if(.NOT.found_fields) then
write(*,*) `Fields Positions and Temperature were not found'
else
write(*,*)
+ `Fields Positions and Temperature were found in the vdata',
+ ` at position `, index
C
C Terminate access to the vdata
C
status = vsfdtch(vdata_id)
endif
C
C Terminate access to the VS interface and close the HDF file.
C
status = vsfdtch(vdata_id)
status = vfend(file_id)
status = hclose(file_id)
end
set_get_vdata_attr.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define VDATA_NAME "Solid Particle"
#define FIELD_NAME "Mass"
#define VATTR_NAME "Site Ident" /* name of the vdata attribute */
#define FATTR_NAME "Scales" /* name of the field attribute */
#define VATTR_N_VALUES 3 /* number of values in the vdata attribute */
#define FATTR_N_VALUES 4 /* number of values in the field attribute */
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_ref, vdata_id,
field_index, /* index of a field within the vdata */
n_vdattrs, /* number of vdata attributes */
n_fldattrs, /* number of field attributes */
vdata_type, /* to hold the type of vdata's attribute */
vdata_n_values,/* to hold the number of vdata's attribute values */
vdata_size, /* to hold the size of vdata's attribute values */
field_type, /* to hold the type of field's attribute */
field_n_values,/* to hold the number of field's attribute values */
field_size; /* to hold the size of field's attribute values */
char vd_attr[VATTR_N_VALUES] = {`A', `B', `C'};/* vdata attribute values*/
int32 fld_attr[FATTR_N_VALUES] = {2, 4, 6, 8}; /* field attribute values*/
char vattr_buf[VATTR_N_VALUES]; /* to hold vdata attribute's values */
int32 fattr_buf[FATTR_N_VALUES]; /* to hold field attribute's values */
char vattr_name[30], /* name of vdata attribute */
fattr_name[30]; /* name of field attribute */
/********************** 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);
/*
* Get the reference number of the vdata named VDATA_NAME.
*/
vdata_ref = VSfind (file_id, VDATA_NAME);
/*
* Attach to the vdata for writing.
*/
vdata_id = VSattach (file_id, vdata_ref, "w");
/*
* Attach an attribute to the vdata, i.e., indicated by the second parameter.
*/
status_n = VSsetattr (vdata_id, _HDF_VDATA, VATTR_NAME, DFNT_CHAR,
VATTR_N_VALUES, vd_attr);
/*
* Get the index of the field FIELD_NAME within the vdata.
*/
status_n = VSfindex (vdata_id, FIELD_NAME, &field_index);
/*
* Attach an attribute to the field field_index.
*/
status_n = VSsetattr (vdata_id, field_index, FATTR_NAME, DFNT_INT32,
FATTR_N_VALUES, fld_attr);
/*
* Get the number of attributes attached to the vdata's first
* field - should be 0.
*/
n_fldattrs = VSfnattrs (vdata_id, 0);
printf ( "Number of attributes of the first field of the vdata: %d\n",
n_fldattrs);
/*
* Get the number of attributes attached to the field specified by
* field_index - should be 1.
*/
n_fldattrs = VSfnattrs (vdata_id, field_index);
printf ( "Number of attributes of field %s: %d\n", FIELD_NAME, n_fldattrs);
/*
* Get the total number of the field's and vdata's attributes - should be 2.
*/
n_vdattrs = VSnattrs (vdata_id);
printf ( "Number of attributes of the vdata and its fields: %d\n",
n_vdattrs);
/*
* Get information about the vdata's first attribute, indicated
* by the third parameter which is the index of the attribute.
*/
status_n = VSattrinfo (vdata_id, _HDF_VDATA, 0, vattr_name,
&vdata_type, &vdata_n_values, &vdata_size);
/*
* Get information about the first attribute of the field specified by
* field_index.
*/
status_n = VSattrinfo (vdata_id, field_index, 0, fattr_name, &field_type,
&field_n_values, &field_size);
/*
* Get the vdata's first attribute.
*/
status_n = VSgetattr (vdata_id, _HDF_VDATA, 0, vattr_buf);
printf("Values of the vdata attribute = %c %c %c\n", vattr_buf[0],
vattr_buf[1], vattr_buf[2]);
/*
* Get the first attribute of the field specified by field_index.
*/
status_n = VSgetattr (vdata_id, field_index, 0, fattr_buf);
printf("Values of the field attribute = %d %d %d %d\n", fattr_buf[0],
fattr_buf[1], fattr_buf[2], fattr_buf[3]);
/*
* 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);
}
set_get_vdata_attr.f
program vdata_attributes
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
character*14 VDATA_NAME
character*4 FIELD_NAME
character*10 VATTR_NAME
character*6 FATTR_NAME
integer VATTR_N_VALUES, FATTR_N_VALUES
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ VDATA_NAME = `Solid Particle',
+ FIELD_NAME = `Mass',
+ VATTR_NAME = `Site Ident',
+ FATTR_NAME = `Scales')
parameter (VATTR_N_VALUES = 3,
+ FATTR_N_VALUES = 4)
integer DFACC_WRITE, FULL_INTERLACE, HDF_VDATA
integer DFNT_INT32, DFNT_CHAR8
parameter (DFACC_WRITE = 2,
+ FULL_INTERLACE = 0,
+ HDF_VDATA = -1,
+ DFNT_INT32 = 24,
+ DFNT_CHAR8 = 4)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsffnd, vsfatch, vsfscat, vsfsnat,
+ vsffnas, vsffidx, vsfnats, vsfainf, vsfgcat, vsfgnat,
+ vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id, vdata_ref
integer field_index, n_vdattrs, n_fldattrs
integer vdata_type, vdata_n_values, vdata_size
integer field_type, field_n_values, field_size
character vd_attr(VATTR_N_VALUES)
integer fld_attr(FATTR_N_VALUES)
character vattr_buf(VATTR_N_VALUES)
integer fattr_buf(FATTR_N_VALUES)
character vattr_name_out(30), fattr_name_out(30)
data vd_attr /'A', `B', `C'/
data fld_attr /2, 4, 6, 8/
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 Get the reference number of the vdata named VDATA_NAME.
C
vdata_ref = vsffnd(file_id, VDATA_NAME)
C
C Attach to the vdata for writing.
C
vdata_id = vsfatch(file_id, vdata_ref, `w')
C
C Attach an attribute to the vdata, as it is indicated by second parameter.
C
status = vsfscat(vdata_id, HDF_VDATA, VATTR_NAME, DFNT_CHAR8,
+ VATTR_N_VALUES, vd_attr)
C
C Get the index of the field FIELD_NAME within the vdata.
C
status = vsffidx(vdata_id, FIELD_NAME, field_index)
C
C Attach an attribute to the field with the index field_index.
C
status = vsfsnat(vdata_id, field_index, FATTR_NAME, DFNT_INT32,
+ FATTR_N_VALUES, fld_attr)
C
C Get the number of attributes attached to the vdata's first
C field - should be 0.
C
n_fldattrs = vsffnas(vdata_id, 0)
write(*,*) `Number of attributes of the first field'
write(*,*) ` of the vdata: `, n_fldattrs
C
C Get the number of the attributes attached to the field specified by
C index field_index - should be 1.
C
n_fldattrs = vsffnas(vdata_id, field_index)
write(*,*) `Number of attributes of field `, FIELD_NAME,
+ n_fldattrs
C
C Get the total number of the field's and vdata's attributes - should be 2.
C
n_vdattrs = vsfnats(vdata_id)
write(*,*) `Number of attributes of the vdata and its fields: `,
+ n_vdattrs
C
C Get information about the vdata's first attribute, indicated by
C the third parameter, which is the index of the attribute.
C
status = vsfainf(vdata_id, HDF_VDATA, 0, vattr_name_out,
+ vdata_type, vdata_n_values, vdata_size)
C
C Get information about the first attribute of the field specified by
C field_index.
C
status = vsfainf(vdata_id, field_index, 0, fattr_name_out,
+ field_type, field_n_values, field_size)
C
C Get the vdata's first attribute.
C
status = vsfgcat(vdata_id, HDF_VDATA, 0, vattr_buf)
write(*,*) `Values of vdata attribute `, vattr_buf
C
C Get the first attribute of the field specified by field_index.
C
status = vsfgnat(vdata_id, field_index, 0, fattr_buf)
write(*,*) `Values of the field attribute = `, fattr_buf
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
get_vdata_info.c
#include "hdf.h"
#define FILE_NAME "General_Vdatas.hdf"
#define FIELD_SIZE 80 /* maximum length of all the field names */
main( )
{
/************************* Variable declaration **************************/
intn status_n; /* returned status for functions returning an intn */
int32 status_32, /* returned status for functions returning an int32 */
n_records, /* to retrieve the number of records in the vdata */
interlace_mode,/* to retrieve the interlace mode of the vdata */
vdata_size, /* to retrieve the size of all specified fields */
file_id, vdata_ref, vdata_id;
char fieldname_list[FIELD_SIZE], /* buffer to retrieve the vdata data */
vdata_name[VSNAMELENMAX]; /* buffer to retrieve the vdata name */
/********************** 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);
/*
* Set vdata_ref to -1 to start the search from the beginning of file.
*/
vdata_ref = -1;
/*
* Use VSgetid to obtain each vdata by its reference number then attach
* to the vdata and get its information. The loop terminates when
* the last vdata is reached.
*/
while ((vdata_ref = VSgetid (file_id, vdata_ref)) != FAIL)
{
/*
* Attach to the current vdata for reading.
*/
vdata_id = VSattach (file_id, vdata_ref, "r");
/*
* Test whether the current vdata is not a storage of an attribute, then
* obtain and display its information.
*/
if( VSisattr (vdata_id) != TRUE )
{
status_n = VSinquire (vdata_id, &n_records, &interlace_mode,
fieldname_list, &vdata_size, vdata_name);
printf ("Vdata %s: - contains %d records\n\tInterlace mode: %s \
\n\tFields: %s - %d bytes\n\t\n", vdata_name, n_records,
interlace_mode == FULL_INTERLACE ? "FULL" : "NONE",
fieldname_list, vdata_size );
}
/*
* Detach from the current vdata.
*/
status_32 = VSdetach (vdata_id);
} /* while */
/*
* Terminate access to the VS interface and close the HDF file.
*/
status_n = Vend (file_id);
status_32 = Hclose (file_id);
}
get_vdata_info.f
program vdata_info
implicit none
C
C Parameter declaration
C
character*18 FILE_NAME
integer DFACC_READ, FULL_INTERLACE
integer FIELD_SIZE
C
parameter (FILE_NAME = `General_Vdatas.hdf',
+ DFACC_READ = 1,
+ FULL_INTERLACE = 0,
+ FIELD_SIZE = 80)
C
C Function declaration
C
integer hopen, hclose
integer vfstart, vsfatch, vsfgid, vsfinq,
+ vsfisat, vsfdtch, vfend
C
C**** Variable declaration *******************************************
C
integer status
integer file_id, vdata_id, vdata_ref
integer n_records, interlace_mode, vdata_size
character*64 vdata_name
character*80 fieldname_list
C
C**** End of variable declaration ************************************
C
C
C Open the HDF file for reading.
C
file_id = hopen(FILE_NAME, DFACC_READ, 0)
C
C Initialize the VS interface.
C
status = vfstart(file_id)
C
C Set the reference number to -1 to start the search from the beginning
C of the file.
C
vdata_ref = -1
10 continue
C
C Use vsfgid to obtain each vdata by its reference number then
C attach to the vdata and get information. The loop terminates
C when the last vdata is reached.
C
vdata_ref = vsfgid(file_id, vdata_ref)
if (vdata_ref .eq. -1) goto 100
C
C Attach to the current vdata for reading.
C
vdata_id = vsfatch(file_id, vdata_ref, `r')
C
C Test whether the current vdata is not a storage for an attribute,
C then obtain and display its information.
if (vsfisat(vdata_id) .ne. 1) then
status = vsfinq(vdata_id, n_records, interlace_mode,
+ fieldname_list, vdata_size, vdata_name)
write(*,*) `Vdata: `, vdata_name
write(*,*) `contains `, n_records, ` records'
if (interlace_mode .eq. 0) then
write(*,*) `Interlace mode: FULL'
else
write(*,*) `Interlace mode: NONE'
endif
write(*,*) `Fields: `, fieldname_list(1:30)
write(*,*) `Vdata record size in bytes :', vdata_size
write(*,*)
endif
C
C Detach from the current vdata.
C
status = vsfdtch(vdata_id)
goto 10
100 continue
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
[Top] [Prev] [Next]
hdfhelp@ncsa.uiuc.edu
HDF User's Guide - 05/19/99, NCSA HDF
Development Group.