Commit 2729bd53 authored by John Douglas Veitch's avatar John Douglas Veitch 💬
Browse files

Add array to table into test program

Original: 2b52bd2ae5cbb5fc9adb32d7d8bd3152256cd48b
parent ce35ea15
......@@ -67,7 +67,7 @@
xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables **varsArray, UINT4 N)
xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *varsArray, UINT4 N)
{
xmlNodePtr fieldNodeList=NULL;
xmlNodePtr paramNodeList=NULL;
......@@ -92,7 +92,7 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables **va
field_ptr=fieldNodeList;
param_ptr=paramNodeList;
varitem=varsArray[0]->head;
varitem=varsArray[0].head;
/* Build a list of PARAM and FIELD elements */
while(varitem)
......@@ -129,12 +129,12 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables **va
const xmlChar *name=field_ptr->name;
char parname[VARNAME_MAX];
sprintf(parname,"%s",name);
UINT4 typesize=LALInferenceTypeSize[LALInferenceGetVariableType(varsArray[0],parname)];
UINT4 typesize=LALInferenceTypeSize[LALInferenceGetVariableType(&varsArray[0],parname)];
valuearrays[j]=calloc(N,typesize);
dataTypes[j]=field_ptr->type;
for(i=0;i<N;i++)
{
memcpy((char *)valuearrays[j]+i*typesize,LALInferenceGetVariable(varsArray[i],parname),typesize);
memcpy((char *)valuearrays[j]+i*typesize,LALInferenceGetVariable(&varsArray[i],parname),typesize);
}
}
UINT4 row,col;
......
......@@ -43,7 +43,7 @@ extern "C" {
#include <lal/LALInference.h>
xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables **varsArray, UINT4 N);
xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *varsArray, UINT4 N);
xmlNodePtr XLALInferenceVariables2VOTNode(const LALInferenceVariables *const vars, const char *name);
......
......@@ -15,15 +15,19 @@ int testLALInferenceVariables(void);
int testLALInferenceVariables(void){
LALInferenceVariables var;
LALInferenceVariables *vars;
char *xmlString = NULL;
xmlDocPtr xmlDocument = NULL;
var.dimension=0;
var.head=NULL;
REAL8 r8test=42.0;
xmlNodePtr xmlFragment;
xmlNodePtr xmlTable;
LALInferenceAddVariable(&var, "real8 test", (void *)&r8test,
LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_LINEAR);
LALInferenceAddVariable(&var, "param test", (void *)&r8test,
LALINFERENCE_REAL8_t, LALINFERENCE_PARAM_FIXED);
printf("Initial LALInferenceVariables:\n");
LALInferencePrintVariables(&var);
......@@ -48,10 +52,38 @@ int testLALInferenceVariables(void){
}
printf ("ok.\n");
xmlFreeDoc(xmlDocument);
xmlFreeNode ( xmlFragment );
XLALFree ( xmlString );
/* Convert array of variables into table */
vars=calloc(3,sizeof(LALInferenceVariables));
for(int i=0;i<3;i++)
LALInferenceCopyVariables(&var,&(vars[i]));
xmlTable=XLALInferenceVariablesArray2VOTTable(vars, 3);
if( (xmlString = XLALCreateVOTStringFromTree ( xmlTable )) == NULL ) {
XLALPrintError ("%s: XLALCreateVOTStringFromTree() failed.\n", __func__);
return 1;
}
printf ("ok.\n");
/* display serialized structure */
printf( "----------------------------------------------------------------------\n");
printf( "%s", xmlString );
printf( "----------------------------------------------------------------------\n");
/* ---------- parse XML string back and validate ---------- */
/* convert VOTable string back into VOTable document */
printf ("--> Parsing XML string into xmlDoc ... ");
if ( (xmlDocument = XLALXMLString2Doc ( xmlString )) == NULL ) {
XLALPrintError( "%s: XLALXMLString2Doc() failed.\n", __func__);
return 1;
}
printf ("ok.\n");
xmlFreeDoc(xmlDocument);
xmlFreeNode ( xmlTable );
XLALFree ( xmlString );
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment