4.7.2 Reading and writing QDP fields
Reading a field
| Syntax | int QDP_read_T(QDP_Reader *in, QDP_String *record_xml, QDP_Type *field);
| | Meaning | Reads the field and its metadata from the next record in the specified file.
| | Type | S, I, R, C, V, H, D, M, P
| | Example | QDP_Real *field = QDP_create_R();
QDP_read_R(reader, record_xml, field);
|
|
The integer return value is 0 for success and 1 for failure. It is
assumed the user has created the QDP_String for the record metadata
and the field for the data in advance.
The datatype of the record must match the field type.
Reading an array of fields
| Syntax | int QDP_vread_T(QDP_Reader *in, QDP_String *record_xml, QDP_Type *field[], int n);
| | Meaning | Reads the array of fields and its metadata from the next record in the specified file.
| | Type | S, I, R, C, V, H, D, M, P
| | Example | QDP_ColorMatrix *field[4];
for(i=0; i<4; i++) field[i] = QDP_create_M();
QDP_vread_M(reader, record_xml, field, 4);
|
|
The integer return value is 0 for success and 1 for failure. It is
assumed the user has created the QDP_String for the record metadata
and the fields for the data in advance.
Reading only the record information
It may be convenient to examine the record metadata first to decide whether
to read or skip the accompanying binary data.
| Syntax | int QDP_read_record_info(QDP_Reader *in, QDP_String *record_xml);
| | Meaning | Reads the only the metadata from the next record in the specified file.
| | Example | QDP_read_record_info(reader, record_xml);
|
|
A subsequent call to QDP_read_T returns a copy of the same
metadata along with the lattice field.
Skipping to the next record
| Syntax | int QDP_next_record(QDP_Reader *in);
| | Meaning | Advances to the beginning of the next record.
| | Example | QDP_next_record(reader);
|
|
Writing a field
| Syntax | int QDP_write_T(QDP_Writer *out, QDP_String *record_xml, QDP_Type *field);
| | Meaning | Writes the field and its metadata as the next record in the specified file.
| | Type | S, I, R, C, V, H, D, M, P
| | Example | QDP_Real *field = QDP_create_R();
QDP_R_eq_zero(field, QDP_all);
QDP_write_R(writer, record_xml, field);
|
|
The integer return value is 0 for success and 1 for failure. It is
assumed the user has created the QDP_String for the record metadata
and the array for the data in advance.
Writing an array of fields
| Syntax | int QDP_write_vT(QDP_Writer *out, QDP_String *record_xml, QDP_Type *field[], int n);
| | Meaning | Writes the array of fields and its metadata as the next record in the specified file.
| | Type | S, I, R, C, V, H, D, M, P
| | Example | QDP_ColorMatrix *field[4];
for(i=0; i<4; i++) field[i] = QDP_create_M();
for(i=0; i<4; i++) QDP_M_eq_zero(field[i], QDP_all);
QDP_write_vM(writer, record_xml, field, 4);
|
|
The integer return value is 0 for success and 1 for failure. It is
assumed the user has prepared the record metadata and the array data
in advance.