#! /usr/bin/perl -w
# This program estimates the proper motion of a double star.

BEGIN { push @INC, "../../../astroDB" }

use astroUtils;
use CGI qw(:standard); # The Perl CGI processing class.
use DBI;
use strict;

my $found = 0;
my $loc;
my $q = new CGI;

open TST, ">runResults" or die "Can't open runResults.\n"; #TEST

my $err = "";

my $mva = uc(param('mva'));
chomp $mva;
unless (($mva =~ /\d+/) and ($mva < 20) and ($mva > -2)) {
  $err .= "<P><H2>Primary magnitude not understood!</H2></P>\n";
}

my $mvb = uc(param('mvb'));
chomp $mvb;
unless (($mvb =~ /\d+/) and ($mvb < 20) and ($mvb > -2)) {
  $err .= "<P><H2>Secondary magnitude not understood!</H2></P>\n";
} 

my $rho = uc(param('rho'));
chomp $rho;
unless (($rho =~ /\d+/) and ($rho < 3600) and ($rho > 0)) {
  $err .= "<P><H2>Separation not understood!</H2></P>\n";
} 

my $spec = uc(param('Spec'));
chomp $spec;
$spec = uc $spec;
my $color = uc(param('Color'));
chomp $color;

my $mp; # Mass of the primary.
my $ms; # Mass of the secondary.
my $specOK = 0;
if ((defined($spec)) and ($spec =~ /[O|B|A|F|G|K|M]/)) {
  if ($spec  =~ /[O|B|A|F]/) {
  } else {
  }
  $specOK = 1;
} elsif (!defined($color)) {
  $err .= "<P><H2>Spectrum not understood!</H2></P>\n";
}

if (($specOK == 0) and ($color =~ /^\s*([-|\d|\.]+)\s*$/)) {
  $color = $1;
  if ($color > -1) {
  } else {
  }
} elsif ($specOK == 0) {
  $err .= "<P><H2>Color not understood!</H2></P>\n";
} 

print TST $err; #TEST

if ($err) {
  $err  .= "$err<P>Hit the back button to try again.</P>";
  print $q->header,                 # create the HTTP header
         $q->start_html("Misunderstood input data"), # start the HTML
         $q->title("Misunderstood input data"),      # start the HTML
         $q->p($err),              # level 1 header
         $q->end_html;              # end the HTML
  exit;
}

close TST; #TEST
