Skip to content

Commit

Permalink
gaiavo: implement VOTable 1.3 support, including BINARY2
Browse files Browse the repository at this point in the history
  • Loading branch information
pwdraper committed Aug 8, 2014
1 parent da089fe commit 75f20d9
Show file tree
Hide file tree
Showing 11 changed files with 800 additions and 29 deletions.
19 changes: 16 additions & 3 deletions applications/gaia/gaiavo/Makefile.in
Expand Up @@ -490,7 +490,7 @@ distdir:
#============================================================================

VOTable1.1.C: VOTable1.1.xsd
xsd cxx-tree --root-element VOTABLE \
xsdcxx cxx-tree --root-element VOTABLE \
--generate-serialization \
--namespace-map http://www.ivoa.net/xml/VOTable/v1.1=votable_11 \
--parser-regex '/VOTABLE/VOTABLE_read/' \
Expand All @@ -504,7 +504,7 @@ VOTable1.1.C: VOTable1.1.xsd

# Note no serialization support for this. Do not want to write these.
VOTable1.1_dns.C: VOTable1.1_dns.xsd
xsd cxx-tree --root-element VOTABLE \
xsdcxx cxx-tree --root-element VOTABLE \
--namespace-map '=votable_11_dns' \
--parser-regex '/VOTABLE/VOTABLE_read/' \
--generate-wildcard \
Expand All @@ -515,7 +515,7 @@ VOTable1.1_dns.C: VOTable1.1_dns.xsd
mv VOTable1.1_dns.hxx generic/VOTable1.1_dns.hxx

VOTable1.2.C: VOTable1.2.xsd
xsd cxx-tree --root-element VOTABLE \
xsdcxx cxx-tree --root-element VOTABLE \
--generate-serialization \
--namespace-map http://www.ivoa.net/xml/VOTable/v1.2=votable_12 \
--parser-regex '/VOTABLE/VOTABLE_read/' \
Expand All @@ -527,5 +527,18 @@ VOTable1.2.C: VOTable1.2.xsd
rm -f generic/VOTable1.2.hxx
mv VOTable1.2.hxx generic/VOTable1.2.hxx

VOTable1.3.C: VOTable1.3.xsd
xsdcxx cxx-tree --root-element VOTABLE \
--generate-serialization \
--namespace-map http://www.ivoa.net/xml/VOTable/v1.3=votable_13 \
--parser-regex '/VOTABLE/VOTABLE_read/' \
--serializer-regex '/VOTABLE/VOTABLE_write/' \
--generate-wildcard \
VOTable1.3.xsd
rm -f generic/VOTable1.3.C
mv VOTable1.3.cxx generic/VOTable1.3.C
rm -f generic/VOTable1.3.hxx
mv VOTable1.3.hxx generic/VOTable1.3.hxx

# Local dependencies.
VOTableWriteFunctions.o: ./generic/VOTableWriteFunctions.icc
8 changes: 8 additions & 0 deletions applications/gaia/gaiavo/VOTable1.3.xsd
Expand Up @@ -365,6 +365,7 @@
<xs:choice>
<xs:element name="TABLEDATA" type="TABLEDATA"/>
<xs:element name="BINARY" type="BINARY"/>
<xs:element name="BINARY2" type="BINARY2"/>
<xs:element name="FITS" type="FITS"/>
</xs:choice>
<xs:element name="INFO" type="INFO" minOccurs="0" maxOccurs="unbounded"/>
Expand Down Expand Up @@ -418,6 +419,13 @@
<xs:complexType name="BINARY">
<xs:sequence>
<xs:element name="STREAM" type="STREAM"/>
</xs:sequence>
</xs:complexType>

<!-- BINARY2 data format -->
<xs:complexType name="BINARY2">
<xs:sequence>
<xs:element name="STREAM" type="STREAM"/>
</xs:sequence>
</xs:complexType>

Expand Down
78 changes: 74 additions & 4 deletions applications/gaia/gaiavo/generic/VOTable.C
Expand Up @@ -87,6 +87,7 @@ namespace gaia {
*/
const char *VOTABLE_NS11 ="http://www.ivoa.net/xml/VOTable/v1.1";
const char *VOTABLE_NS12 ="http://www.ivoa.net/xml/VOTable/v1.2";
const char *VOTABLE_NS13 ="http://www.ivoa.net/xml/VOTable/v1.3";

/** Static member initializations. */
bool VOTable::initialized = false;
Expand All @@ -99,7 +100,8 @@ namespace gaia {
VOTable::VOTable() :
votable1_(NULL),
votable2_(NULL),
votable3_(NULL)
votable3_(NULL),
votable4_(NULL)
{
// Initialise Xerces runtime
if ( !VOTable::initialized ) {
Expand Down Expand Up @@ -179,6 +181,10 @@ namespace gaia {
delete votable3_;
votable3_ = NULL;
}
if ( votable4_ ) {
delete votable4_;
votable4_ = NULL;
}

// Open the VOTable using the correct parsing classes. Currently this
// just scans for the namespace qualifying string in the first 2048
Expand All @@ -191,23 +197,33 @@ namespace gaia {

// Now look for namespace signifier.
if ( strstr( line, VOTABLE_NS11 ) == NULL &&
strstr( line, VOTABLE_NS12 ) == NULL ) {
strstr( line, VOTABLE_NS12 ) == NULL &&
strstr( line, VOTABLE_NS13 ) == NULL ) {

// No namespace.
votable1_ = openVOTable1( in );
}
else {
// Namespace.
if ( strstr( line, VOTABLE_NS11 ) == NULL ) {
votable3_ = openVOTable3( in );
// Not 1.1
if ( strstr( line, VOTABLE_NS12 ) == NULL ) {
// 1.3
votable4_ = openVOTable4( in );
}
else {
// 1.2
votable3_ = openVOTable3( in );
}
}
else {
// 1.1
votable2_ = openVOTable2( in );
}
}

// If we have a table, that's OK.
if ( votable1_ || votable2_ || votable3_ ) {
if ( votable1_ || votable2_ || votable3_ || votable4_ ) {
return 1;
}
return 0;
Expand All @@ -234,6 +250,10 @@ namespace gaia {
delete votable3_;
votable3_ = NULL;
}
if ( votable4_ ) {
delete votable4_;
votable4_ = NULL;
}

// Create new instance.
votable2_ = new VOTABLE();
Expand Down Expand Up @@ -263,6 +283,16 @@ namespace gaia {
votable3_->version( "1.2" );
VOTABLE_write( out, *votable3_, map );
}

using namespace votable_13;
if ( votable4_ != NULL ) {
ofstream out( file, ios::out );
xml_schema::namespace_infomap map;
map[""].name = "http://www.ivoa.net/xml/VOTable/v1.3";
map[""].schema = "VOTable1.3.xsd";
votable4_->version( "1.3" );
VOTABLE_write( out, *votable4_, map );
}
}

/**
Expand All @@ -279,6 +309,9 @@ namespace gaia {
if ( votable3_ ) {
delete votable3_;
}
if ( votable4_ ) {
delete votable4_;
}
}

/**
Expand Down Expand Up @@ -417,6 +450,31 @@ namespace gaia {
return NULL;
}

/**
* Read stream for a VOTable version 1.3 using fully qualified
* namespace.
*/
votable_13::VOTABLE *VOTable::openVOTable4( istream *in )
{
using namespace votable_13;
try {
auto_ptr<VOTABLE> table =
VOTABLE_read( *in,
xml_schema::flags::dont_validate |
xml_schema::flags::dont_initialize |
xml_schema::flags::keep_dom );
return table.release();
}
catch ( const xml_schema::exception &e ) {
// Basic report to terminal.
cerr << "open_votable: ";
cerr << e << endl;
}

// Open failed.
return NULL;
}

/**
* Simple listing of VOTable contents.
*/
Expand All @@ -431,6 +489,9 @@ namespace gaia {
else if ( votable3_ ) {
votable_enum( *votable3_, str );
}
else if ( votable4_ ) {
votable_enum( *votable4_, str );
}
}

/**
Expand All @@ -447,6 +508,9 @@ namespace gaia {
else if ( votable3_ ) {
return votable_count( *votable3_ );
}
else if ( votable4_ ) {
return votable_count( *votable4_ );
}
return 0;
}

Expand All @@ -472,6 +536,9 @@ namespace gaia {
else if ( votable3_ ) {
result = votable_write( *votable3_, index, out );
}
else if ( votable4_ ) {
result = votable_write( *votable4_, index, out );
}
out.close();

return result;
Expand Down Expand Up @@ -507,6 +574,9 @@ namespace gaia {
else if ( votable3_ ) {
return votable_info_value( *votable3_, name, value, content );
}
else if ( votable4_ ) {
return votable_info_value( *votable4_, name, value, content );
}
return 0;
}
}
17 changes: 17 additions & 0 deletions applications/gaia/gaiavo/generic/VOTable.h
Expand Up @@ -51,6 +51,7 @@
#include "VOTable1.1.hxx"
#include "VOTable1.1_dns.hxx"
#include "VOTable1.2.hxx"
#include "VOTable1.3.hxx"

using namespace std;

Expand All @@ -74,6 +75,10 @@ namespace gaia
votable_12::VOTABLE *votable3_;
votable_12::VOTABLE *openVOTable3( istream *in );

// Open a VOTable 1.3.
votable_13::VOTABLE *votable4_;
votable_13::VOTABLE *openVOTable4( istream *in );

// Note for above. VOTABLE classes are not derived, so cannot
// simply use an array.

Expand Down Expand Up @@ -124,16 +129,28 @@ namespace gaia
// default namespace). These read a VOTable and write a tab
// table. Defined in VOTableWriteFunctions.C.
#define NS ::votable_11_dns
#define NSVERS 11
#include "VOTableWriteFunctions.h"
#undef NS
#undef NSVERS

#define NS ::votable_11
#define NSVERS 11
#include "VOTableWriteFunctions.h"
#undef NS
#undef NSVERS

#define NS ::votable_12
#define NSVERS 12
#include "VOTableWriteFunctions.h"
#undef NS
#undef NSVERS

#define NS ::votable_13
#define NSVERS 13
#include "VOTableWriteFunctions.h"
#undef NS
#undef NSVERS

// Similar functions for reading a tab table and writing a VOTable.
// Only support writing in the VOTable 1.1 namespace so no need for
Expand Down

0 comments on commit 75f20d9

Please sign in to comment.