/* **********************************************************************
 * *                                                                    *
 * *       Routine to Test Polar Calculations                           *
 * *                                                                    *
 * **********************************************************************
 * File: /libs/user/test_sphere.c
 *
 *                        COPYRIGHT (c) 2006  BY
 *              VAISALA INC, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include "sigtypes.h"
#include "user_lib.h"

/* ==========================================================================
 */

int main( int iargc, char **sargv )
{
  struct latlon8 Earth1, Earth2;
  struct D2Polar8 Polar;
  char sString1[20], sString2[20];
  /* ------------------------------------------------------------
   */
  if( !setlocale(LC_ALL, "") )
    {
      printf("Setlocale failed, using C locale.\n") ;
    }

  memset( &Earth1, 0, sizeof(Earth1) );
  memset( &Earth2, 0, sizeof(Earth2) );

  /* Source point */
  Earth1.fLon  = (FPI/180.0) * -157.0;
  Earth1.fLon += (FPI/180.0) * (-57.307/60.0);

  Earth1.fLat  = (FPI/180.0) * 21.0;
  Earth1.fLat += (FPI/180.0) * (21.346/60.0);

  /* Target point ARSR-4 */
  /*
  Earth2.fLon  = (FPI/180.0) * -158.0;
  Earth2.fLon += (FPI/180.0) * (-8.0/60.0);
  Earth2.fLon += (FPI/180.0) * (-32.0/3600.0);

  Earth2.fLat  = (FPI/180.0) * 21.0;
  Earth2.fLat += (FPI/180.0) * (30.0/60.0);
  Earth2.fLat += (FPI/180.0) * (27.0/3600.0);
  */

  /* Target point ASR-9 */
  Earth2.fLon  = (FPI/180.0) * -157.0;
  Earth2.fLon += (FPI/180.0) * (-55.0/60.0);
  Earth2.fLon += (FPI/180.0) * (-41.0/3600.0);

  Earth2.fLat  = (FPI/180.0) * 21.0;
  Earth2.fLat += (FPI/180.0) * (19.0/60.0);
  Earth2.fLat += (FPI/180.0) * (3.0/3600.0);


  PolarFromEarth( &Earth1, &Earth2, &Polar );

  /* Print out the results */
  fprintf( stdout, "Start location: %s %s\n", 
	   sLatFromRadian( Earth1.fLat, sString1, 20 ),
	   sLonFromRadian( Earth1.fLon, sString2, 20 ) );
  fprintf( stdout, "  End location: %s %s\n", 
	   sLatFromRadian( Earth2.fLat, sString1, 20 ),
	   sLonFromRadian( Earth2.fLon, sString2, 20 ) );
  fprintf( stdout, "       Bearing: %3.1f degrees, Range: %3.1f km\n",
	   (180.0/FPI)*Polar.fAz, Polar.fRange );

  return(0) ;
}
