Commit 86247cbb authored by John Douglas Veitch's avatar John Douglas Veitch 💬
Browse files

Creating VOTables from LALInferenceVariables enabled.

Original: 74482f40c2c6b96bc912f3eebe506606f3262763
parent 2729bd53
......@@ -79,7 +79,7 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *var
void **valuearrays=NULL;
UINT4 Nfields=0,i,j;
const char *fn = __func__;
char *tablename=NULL;
char tablename[512]="\0";
int err;
......@@ -103,14 +103,24 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *var
case LALINFERENCE_PARAM_OUTPUT:
{
tmpNode=LALInferenceVariableItem2VOTFieldNode(varitem);
field_ptr=xmlAddNextSibling(field_ptr,tmpNode);
if(field_ptr) field_ptr=xmlAddNextSibling(field_ptr,tmpNode);
else {field_ptr=tmpNode; fieldNodeList=field_ptr;}
if(!field_ptr) {
XLALPrintError ("%s: xmlAddNextSibling() failed to add next field node.\n", fn );
XLAL_ERROR_NULL(fn, XLAL_EFAILED);
}
Nfields++;
break;
}
case LALINFERENCE_PARAM_FIXED:
{
tmpNode=LALInferenceVariableItem2VOTParamNode(varitem);
param_ptr=xmlAddNextSibling(param_ptr,tmpNode);
if(param_ptr) param_ptr=xmlAddNextSibling(param_ptr,tmpNode);
else {param_ptr=tmpNode; paramNodeList=param_ptr;}
if(!param_ptr) {
XLALPrintError ("%s: xmlAddNextSibling() failed to add next param node.\n", fn );
XLAL_ERROR_NULL(fn, XLAL_EFAILED);
}
break;
}
default:
......@@ -120,32 +130,38 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *var
}
varitem=varitem->next;
}
printf("Finished walking through param list\n");
valuearrays=calloc(Nfields,sizeof(void *));
VOTABLE_DATATYPE *dataTypes=calloc(Nfields,sizeof(VOTABLE_DATATYPE));
/* Build array of DATA */
for(field_ptr=fieldNodeList,j=0;field_ptr!=NULL;field_ptr=field_ptr->next,j++)
{
const xmlChar *name=field_ptr->name;
char parname[VARNAME_MAX];
sprintf(parname,"%s",name);
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);
}
}
/* Build array of DATA for fields */
for(j=0,varitem=varsArray[0].head; varitem; varitem=varitem->next)
{
switch(varitem->vary){
case LALINFERENCE_PARAM_LINEAR:
case LALINFERENCE_PARAM_CIRCULAR:
case LALINFERENCE_PARAM_OUTPUT:
{
UINT4 typesize = LALInferenceTypeSize[LALInferenceGetVariableType(&varsArray[0],varitem->name)];
valuearrays[j]=calloc(N,typesize);
dataTypes[j]=LALInferenceVariableType2VOT(varitem->type);
for(i=0;i<N;i++)
memcpy((char *)valuearrays[j]+i*typesize,LALInferenceGetVariable(&varsArray[i],varitem->name),typesize);
j++;
}
default:
continue;
}
}
UINT4 row,col;
printf("creating TABLEDATA node\n");
/* create TABLEDATA node */
if ( ( xmlTABLEDATAnode = xmlNewNode ( NULL, CAST_CONST_XMLCHAR("TABLEDATA") ))== NULL ) {
XLALPrintError ("%s: xmlNewNode() failed to create 'TABLEDATA' node.\n", fn );
err = XLAL_ENOMEM;
goto failed;
}
printf("TABLEDATA = %lx\n",(unsigned long int)xmlTABLEDATAnode);
/* ---------- loop over data-arrays and generate each table-row */
for ( row = 0; row < N; row ++ )
{
......@@ -179,6 +195,7 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *var
}
const char* tmptxt;
printf("Creating node for datatype %i, value %lf\n",dataTypes[col],((double *)valuearrays[col])[0]);
if ( (tmptxt = XLALVOTprintfFromArray ( dataTypes[col], NULL, valuearrays[col], row )) == NULL ){
XLALPrintError ("%s: XLALVOTprintfFromArray() failed for row = %d, col = %d. errno = %d.\n", fn, row, col, xlalErrno );
err = XLAL_EFUNC;
......@@ -201,15 +218,19 @@ xmlNodePtr XLALInferenceVariablesArray2VOTTable(const LALInferenceVariables *var
} /* for row < numRows */
printf("Done creating TABLEDATA tree\n");
/* Create a TABLE from the FIELDs and TABLEDATA nodes */
sprintf(tablename,"LALInferenceXMLTable");
printf("Creating table node\n");
printf("fieldNodeList = %lx\n",(long unsigned int)fieldNodeList);
printf("xmlTABLEDATAnode = %lx\n",(long unsigned int)xmlTABLEDATAnode);
VOTtableNode= XLALCreateVOTTableNode (tablename, fieldNodeList, xmlTABLEDATAnode );
printf("VOTTableNode = %lx\n",(long unsigned int)VOTtableNode);
/* Attach PARAMs to TABLE node */
if(!xmlAddChildList(VOTtableNode,paramNodeList)){
XLALPrintError("%s: xmlAddChildList failed\n",fn);
if(!(xmlAddChildList(VOTtableNode,paramNodeList))){
XLALPrintError("%s: xmlAddChild failed\n",fn);
err=XLAL_EFAILED;
goto failed;
}
......
......@@ -3,7 +3,6 @@
#include <lal/LALXML.h>
#include <lal/LALXMLVOTableCommon.h>
#include <lal/LALXMLVOTableSerializers.h>
#include <string.h>
#include <libxml/parser.h>
......@@ -20,15 +19,20 @@ int testLALInferenceVariables(void){
xmlDocPtr xmlDocument = NULL;
var.dimension=0;
var.head=NULL;
REAL8 r8test=42.0;
xmlNodePtr xmlFragment;
REAL8 r8test=42.8,r8test2=101.0;
INT4 i4test=12;
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);
LALInferenceAddVariable(&var, "field test 2",(void *)&r8test2,LALINFERENCE_REAL8_t,LALINFERENCE_PARAM_CIRCULAR);
LALInferenceAddVariable(&var, "int test",(void *)&i4test,LALINFERENCE_INT4_t,LALINFERENCE_PARAM_FIXED);
LALInferenceAddVariable(&var, "int field test",(void *)&i4test,LALINFERENCE_INT4_t,LALINFERENCE_PARAM_OUTPUT);
printf("Initial LALInferenceVariables:\n");
LALInferencePrintVariables(&var);
printf( "--> Serializing into XML string ... ");
......@@ -57,12 +61,21 @@ int testLALInferenceVariables(void){
XLALFree ( xmlString );
/* Convert array of variables into table */
printf( "--> Serializing array of variables into XML Table ... ");
vars=calloc(3,sizeof(LALInferenceVariables));
for(int i=0;i<3;i++)
int i;
for(i=0;i<3;i++)
{
printf("Copying %i\n",i);
LALInferenceCopyVariables(&var,&(vars[i]));
}
printf("Creating XML Table...\n");
xmlTable=XLALInferenceVariablesArray2VOTTable(vars, 3);
if( (xmlString = XLALCreateVOTStringFromTree ( xmlTable )) == NULL ) {
printf("Created XML Table, tree = %lx ...\n",(long unsigned int)xmlTable);
xmlString = XLALCreateVOTStringFromTree ( xmlTable );
printf("Created XML String %s\n",xmlString);
if(xmlString == NULL ) {
XLALPrintError ("%s: XLALCreateVOTStringFromTree() failed.\n", __func__);
return 1;
}
......@@ -90,5 +103,6 @@ int testLALInferenceVariables(void){
int main(void)
{
lalDebugLevel=5;
return(testLALInferenceVariables());
}
\ No newline at end of file
}
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