int QIO_decode_usqcd_lattice_info(QIO_USQCDLatticeInfo *record_info, QIO_String *record_string) { // taken from QIO_decode_record_info char *parse_pt = QIO_string_ptr(record_string); char *tmp_pt; char tag[QIO_MAXTAG]; char tags_string[QIO_MAXVALUESTRING]; char value_string[QIO_MAXVALUESTRING]; int errors = 0; QIO_USQCDLatticeInfoWrapper wrapper = QIO_USQCD_LATTICE_INFO_WRAPPER; QIO_USQCDLatticeInfo templ = QIO_USQCD_LATTICE_INFO_TEMPLATE; char *left_angle; /* Initialize record info structure from a template */ memcpy(record_info, &templ, sizeof(QIO_USQCDLatticeInfo)); /* Start parsing record_string */ /* Check leading tag, which is probably the info phrase "<?xml ...?>" */ /* We ignore it if it is there */ tmp_pt = QIO_next_tag(parse_pt, tag, &left_angle); if(strcmp(tag,QIO_QUESTXML)==0){ /* Found ?xml, so resume parsing after the closing ">", ignoring the field. Otherwise, leave the parse_pt at its initial value */ parse_pt = tmp_pt; } /* Open top-level tag (wrapper) and extract string containing tags */ parse_pt = QIO_get_tag_value(parse_pt, tag, tags_string); QIO_decode_as_string (tag, tags_string, &wrapper.usqcdlatticeinfo_tags); /* If outer wrapper has bad tag, exit with error status */ if(QIO_check_string_occur(&wrapper.usqcdlatticeinfo_tags)) return QIO_BAD_XML; /* Otherwise start parsing the string of tags */ parse_pt = QIO_get_usqcd_lattice_info_tag_string(&wrapper); /* Scan string until null character is reached */ while(*parse_pt){ parse_pt = QIO_get_tag_value(parse_pt, tag, value_string); QIO_decode_as_string(tag,value_string,&record_info->version); QIO_decode_as_string(tag,value_string,&record_info->plaq); QIO_decode_as_string(tag,value_string,&record_info->linktr); QIO_decode_as_string(tag,value_string,&record_info->info); } /* Check for completeness */ errors += QIO_check_string_occur(&record_info->version); errors += QIO_check_string_occur(&record_info->plaq); errors += QIO_check_string_occur(&record_info->linktr); errors += QIO_check_string_occur(&record_info->info); return errors; }
int QIO_decode_checksum_info(QIO_ChecksumInfo *checksum, QIO_String *file_string){ char *parse_pt = QIO_string_ptr(file_string); char *tmp_pt; char tag[QIO_MAXTAG]; char tags_string[QIO_MAXVALUESTRING]; char value_string[QIO_MAXVALUESTRING]; int errors = 0; QIO_ChecksumInfoWrapper wrapper = QIO_CHECKSUM_INFO_WRAPPER; QIO_ChecksumInfo templ = QIO_CHECKSUM_INFO_TEMPLATE; char *left_angle; /* Initialize from template */ memcpy(checksum, &templ, sizeof(QIO_ChecksumInfo)); /* Start parsing checksum_string */ /* Check leading tag, which is probably the info phrase "<?xml ...?>" */ /* We ignore it if it is there */ tmp_pt = QIO_next_tag(parse_pt, tag, &left_angle); if(strcmp(tag,QIO_QUESTXML)==0){ /* Found ?xml, so resume parsing after the closing ">", ignoring the field. Otherwise, leave the parse_pt at its initial value. */ parse_pt = tmp_pt; } /* Open top-level tag (wrapper) and extract string containing tags */ parse_pt = QIO_get_tag_value(parse_pt, tag, tags_string); QIO_decode_as_string (tag, tags_string, &wrapper.checksuminfo_tags); /* If outer wrapper has bad tag exit with error status */ if(QIO_check_string_occur(&wrapper.checksuminfo_tags))return QIO_BAD_XML; /* Otherwise start parsing the enclosed string of tags */ parse_pt = QIO_get_checksum_info_tag_string(&wrapper); /* Scan string until null character is reached */ while(*parse_pt){ parse_pt = QIO_get_tag_value(parse_pt, tag, value_string); QIO_decode_as_string (tag,value_string,&checksum->version); QIO_decode_as_hex32 (tag,value_string,&checksum->suma); QIO_decode_as_hex32 (tag,value_string,&checksum->sumb); } /* Check for completeness */ errors += QIO_check_string_occur (&checksum->version); errors += QIO_check_hex32_occur (&checksum->suma); errors += QIO_check_hex32_occur (&checksum->sumb); return errors; }
int QIO_decode_file_info(QIO_FileInfo *file_info, QIO_String *file_string){ char *parse_pt = QIO_string_ptr(file_string); char *tmp_pt; char tag[QIO_MAXTAG]; char tags_string[QIO_MAXVALUESTRING]; char value_string[QIO_MAXVALUESTRING]; int errors = 0; QIO_FileInfoWrapper wrapper = QIO_FILE_INFO_WRAPPER; QIO_FileInfo templ = QIO_FILE_INFO_TEMPLATE; char *left_angle; /* Compatibility */ QIO_FileInfo_v1p0 file_info_v1p0 = QIO_FILE_INFO_TEMPLATE_v1p0; /* Initialize file info structure from a template */ memcpy(file_info, &templ, sizeof(QIO_FileInfo)); /* Start parsing file_string */ /* Check leading tag, which is probably the info phrase "<?xml ...?>" */ /* We ignore it if it is there */ tmp_pt = QIO_next_tag(parse_pt, tag, &left_angle); if(strcmp(tag,QIO_QUESTXML)==0){ /* Found ?xml, so resume parsing after the closing ">", ignoring the field. Otherwise, leave the parse_pt at its initial value. */ parse_pt = tmp_pt; } /* Open top-level tag (wrapper) and extract string containing tags */ parse_pt = QIO_get_tag_value(parse_pt, tag, tags_string); QIO_decode_as_string (tag, tags_string, &wrapper.fileinfo_tags); /* If outer wrapper has bad tag, exit with error status */ if(QIO_check_string_occur(&wrapper.fileinfo_tags))return QIO_BAD_XML; /* Otherwise start parsing the enclosed string of tags */ parse_pt = QIO_get_file_info_tag_string(&wrapper); /* Scan string until null character is reached */ while(*parse_pt){ parse_pt = QIO_get_tag_value(parse_pt, tag, value_string); QIO_decode_as_string (tag,value_string,&file_info->version); QIO_decode_as_int (tag,value_string,&file_info->spacetime); QIO_decode_as_intlist(tag,value_string,&file_info->dims); QIO_decode_as_int (tag,value_string,&file_info->volfmt); /* compatibility */ QIO_decode_as_int (tag,value_string,&file_info_v1p0.multifile); } /* Check for completeness */ errors += QIO_check_string_occur (&file_info->version); errors += QIO_check_int_occur (&file_info->spacetime); errors += QIO_check_intarray_occur(&file_info->dims); errors += QIO_check_int_occur (&file_info->volfmt); /* Did we get all the spacetime dimensions */ if(file_info->spacetime.value != file_info->dims.n){ printf("QIO_decode_file_info: mismatch in spacetime dimensions\n"); errors++; } /* Backward compatibility */ /* Convert version 1.0 file_info structure to version 1.1 */ if(strcmp("1.0",QIO_get_file_version(file_info)) == 0){ /* Version 1.0 had a multifile parameter where the volfmt paramter now appears. The multifile parameter gave the file count. A 1 implied singlefile and greater than 1 implied multifile. There was no partfile format in 1.0. In version 1.1 the multifile flag was changed to specify the volume format: SINGLEFILE, MULTIFILE, PARTFILE */ if(QIO_get_multifile(&file_info_v1p0) == 1) QIO_insert_volfmt(file_info,QIO_SINGLEFILE); else QIO_insert_volfmt(file_info,QIO_MULTIFILE); } return errors; }
int QIO_decode_record_info(QIO_RecordInfo *record_info, QIO_String *record_string){ char *parse_pt = QIO_string_ptr(record_string); char *tmp_pt; char tag[QIO_MAXTAG]; char tags_string[QIO_MAXVALUESTRING]; char value_string[QIO_MAXVALUESTRING]; int errors = 0; QIO_RecordInfoWrapper wrapper = QIO_RECORD_INFO_WRAPPER; QIO_RecordInfo templ = QIO_RECORD_INFO_TEMPLATE; char *left_angle; /* Compatibility */ QIO_RecordInfo_v1p0 record_info_v1p0 = QIO_RECORD_INFO_TEMPLATE_v1p0; /* Initialize record info structure from a template */ memcpy(record_info, &templ, sizeof(QIO_RecordInfo)); /* Start parsing record_string */ /* Check leading tag, which is probably the info phrase "<?xml ...?>" */ /* We ignore it if it is there */ tmp_pt = QIO_next_tag(parse_pt, tag, &left_angle); if(strcmp(tag,QIO_QUESTXML)==0){ /* Found ?xml, so resume parsing after the closing ">", ignoring the field. Otherwise, leave the parse_pt at its initial value */ parse_pt = tmp_pt; } /* Open top-level tag (wrapper) and extract string containing tags */ parse_pt = QIO_get_tag_value(parse_pt, tag, tags_string); QIO_decode_as_string (tag, tags_string, &wrapper.recordinfo_tags); /* If outer wrapper has bad tag, exit with error status */ if(QIO_check_string_occur(&wrapper.recordinfo_tags)) return QIO_BAD_XML; /* Otherwise start parsing the string of tags */ parse_pt = QIO_get_record_info_tag_string(&wrapper); /* Scan string until null character is reached */ while(*parse_pt){ parse_pt = QIO_get_tag_value(parse_pt, tag, value_string); QIO_decode_as_string (tag,value_string,&record_info->version); QIO_decode_as_string (tag,value_string,&record_info->date); QIO_decode_as_int (tag,value_string,&record_info->recordtype); QIO_decode_as_int (tag,value_string,&record_info->spacetime); QIO_decode_as_intlist(tag,value_string,&record_info->hyperlower); QIO_decode_as_intlist(tag,value_string,&record_info->hyperupper); QIO_decode_as_string (tag,value_string,&record_info->datatype); QIO_decode_as_string (tag,value_string,&record_info->precision); QIO_decode_as_int (tag,value_string,&record_info->colors); QIO_decode_as_int (tag,value_string,&record_info->spins); QIO_decode_as_int (tag,value_string,&record_info->typesize); QIO_decode_as_int (tag,value_string,&record_info->datacount); /* compatibility */ QIO_decode_as_int (tag,value_string,&record_info_v1p0.globaldata); } /* Backward compatibility */ /* Convert version 1.0 record_info structure to version 1.1 */ if(strcmp("1.0",QIO_get_record_info_version(record_info)) == 0){ /* Version 1.1 added a new record type: hypercube subset and requires a list of lower and upper coordinate bounds to specify the hypercube. These parameters are ignored with the QIO_GLOBAL and QIO_FIELD record types, the only ones used in version 1, so we don't need to set default values. */ /* An earlier defective version (also labeled 1.0) was missing the "globaldata" parameter altogether. */ /* If the old globaldata tag is missing, insert a default value */ if(QIO_check_int_occur(&record_info_v1p0.globaldata) != 0){ record_info_v1p0.globaldata.occur = 1; /* Default is "field" record type */ record_info_v1p0.globaldata.value = QIO_FIELD; } /* Also the "globaldata" member was renamed "recordtype". So just copy the old parameter value. */ record_info->recordtype.occur = 1; record_info->recordtype.value = QIO_get_globaldata(&record_info_v1p0); } /* Check for completeness */ errors += QIO_check_string_occur(&record_info->version); errors += QIO_check_int_occur (&record_info->recordtype); errors += QIO_check_string_occur(&record_info->datatype); errors += QIO_check_string_occur(&record_info->precision); errors += QIO_check_int_occur (&record_info->typesize); errors += QIO_check_int_occur (&record_info->datacount); /* Requirements for hypercube record type */ if(QIO_get_recordtype(record_info) == QIO_HYPER){ errors += QIO_check_int_occur (&record_info->spacetime); errors += QIO_check_intarray_occur (&record_info->hyperlower); errors += QIO_check_intarray_occur (&record_info->hyperupper); } return errors; }