Astro::Catalog::Query::Sesame - Object name resolution via SIMBAD


Astro-Catalog documentation Contained in the Astro-Catalog distribution.

Index


Code Index:

NAME

Top

Astro::Catalog::Query::Sesame - Object name resolution via SIMBAD

SYNOPSIS

Top

  my $sesame = new Astro::Catalog::Query::Sesame( Target => "EX Hya" );
  my $catalog = $sesame->querydb();

DESCRIPTION

Top

Simple wrapper object for the CDS SIMBAD Name Resolver serbice (Sesame), see http://cdsweb.u-strasbg.fr/cdsws.gml for details of the service.

REVISION

Top

$Id: Sesame.pm,v 1.9 2005/07/25 07:45:49 aa Exp $

METHODS

Top

Constructor

Create a new instance from a hash of options

  $query = new Astro::Catalog::Query::WebService( Object => $target );

returns a reference to an query object. =cut

Returns an Astro::Catalog object resulting from the specific query.

   $catalog = $query->querydb();


Astro-Catalog documentation Contained in the Astro-Catalog distribution.
package Astro::Catalog::Query::Sesame;

# L O A D   M O D U L E S --------------------------------------------------

use strict;
use warnings;
use base qw/ Astro::Catalog::Transport::WebService /;
use vars qw/ $VERSION /;

use Carp;
use POSIX qw(ceil);

# generic catalog objects
use Astro::Coords;
use Astro::Catalog;
use Astro::Catalog::Star;

'$Revision: 1.9 $ ' =~ /.*:\s(.*)\s\$/ && ($VERSION = $1);

# base class 

sub querydb {
  my $self = shift;
  
  # clean out buffer
  $self->_set_raw("");
  
  my $endpoint = $self->endpoint();
  my %options = $self->_translate_options();
  
  # return unless we haev a target, set it otherwise
  return undef unless $self->query_options("object");

  # make sesame query
  #print "Endpoint: $endpoint\n";
  my $service = SOAP::Lite->service( $self->endpoint() );   
  
  my $ident = $self->query_options("object");
  $ident =~ s/\+/ /g;
  
  my $buffer; 
  eval { $buffer = $service->sesame( $ident, "u" ); };
  if ( $@ ) {
     my $status = $service->transport()->status();
     croak("Error ($status): $@");
     return;
  }
 
  # parse results & return
  $self->_set_raw( $buffer );
  my $catalog = $self->_parse_query();
  return $catalog; 
}

sub _default_endpoint {
  return "http://cdsws.u-strasbg.fr/axis/services/Sesame?wsdl";
}

sub _default_urn {
  return undef;
}

sub _is_service {
  return 1;
}  

sub _get_allowed_options {
  my $self = shift;
  return (
	  object => 'object'
	 );
}

# base class

sub _set_default_options {
  return (
	  object => undef,
	 );
}


sub _get_supported_init {
  return (qw/ Target URN Endpoint Proxy /);
}

sub _parse_query {
  my $self = shift;

  # create an Astro::Catalog object to hold the search results
  my $catalog = new Astro::Catalog();

  # create a temporary object to hold stars
  my $star = new Astro::Catalog::Star();

  # get a local copy of the current BUFFER
  my @result = $self->_dump_raw();
  chomp @result;
  
  use Data::Dumper; print Dumper( @result );
  
  # Grab Coordinates
  # ----------------
  #use Data::Dumper;
  #print Dumper( @result );
  
  # grab line from return result
  my $coord_line = undef;
  foreach my $i ( 0 ... $#result ) {
     if ( $result[$i] =~ /^%J / ) {
       $coord_line = $i;
       last;
     }  
  }
  
  croak "Can not understand response, no co-ordinate line found "
      unless defined $coord_line;
  my $line = $result[$coord_line];
  
  # split it on \s+
  my @coords = split( /\s+/,$line);

  # GRAB DEC
  # --------

  # grab Dec
  my $dec = $coords[2];  
  #print "dec $dec\n";
  
  my $decdot = index $dec, ".";
  my $deg = substr $dec, 0, $decdot;
  #print "deg $deg\n";
  
  my $min = substr $dec, $decdot+1, length($dec);
  $min = "0." . $min;
  $min = $min * 60.0;  

  my $secdot = index $min, ".";
  my $sec = substr $min, $secdot+1, length($min);
  $min = substr $min, 0, $secdot;
  $sec = "0." . $sec;
  $sec = POSIX::ceil($sec * 60.0);  
  
  if ( $sec == 60 ) {
     $sec = 0;
     $min = $min+1;
  }   
  #print "min $min\n";
  #print "sec $sec\n";
  
  my $objdec = "$deg $min $sec";  
  
  # GRAB RA
  # -------
  
  # grab RA
  my $ra = $coords[1];
  $ra = $ra/15.0;
  #print "ra $ra\n";
  
  my $radot = index $ra, ".";
  my $hours = substr $ra, 0, $radot;
  #print "hours $hours\n";
  
  $min = substr $ra, $radot+1, length($ra);
  $min = "0." . $min;
  $min = $min * 60.0;  

  $secdot = index $min, ".";
  $sec = substr $min, $secdot+1, length($min);
  $min = substr $min, 0, $secdot;
  $sec = "0." . $sec;
  $sec = POSIX::ceil($sec * 60.0);  
  
  if ( $sec == 60 ) {
     $sec = 0;
     $min = $min+1;
  }   
  #print "min $min\n";
  #print "sec $sec\n";
  
  my $objra = "$hours $min $sec";  


  $star->coords( new Astro::Coords(ra => $objra,
                                   dec => $objdec,
                                   units => 'sex',
                                   type => 'J2000',
                                   name => $self->query_options("object"),
                                   ) );


  # Push the star into the catalog
  $catalog->pushstar( $star );
  
  # return
  return $catalog;

}

# L A S T  O R D E R S ------------------------------------------------------

1;