// Copyright Bruce Allen 2017
// Compile with gcc -o antenna antenna.c -lm

// REMAINING THINGS TO CHECK:

// (a) sign conventions for h, which arm is positive CONFIRMED.  VIRGO
//  AND LIGO DEFINE THE POSITIVE ARM AS "X" where X defined by right
//  hand rule with two arms and Z away from center of earth.

// (b) direction and origin conventions for the polarization axis The
// convention for LAL is that psi is the angle that the source plane
// is rotated CCW as viewed from the Earth.  The convention in my
// calculation is the opposite.  So in my code I have changed the sign
// inside get_antenna() so that the arguments now correspond to LAL
// ones.  Thus in this code, the conventions correspond to LAL.

// IOTA is zero when orbital angular momentum points to earth
// PSI is orbital plane rotation CCW as viewed from Earth

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "antenna_lib.h"

// This function requires two floating point arguments on the command
// line, iota and psi, angles in degrees.
int main(int argc, char *argv[]) {
   // to loop over detectors
   int i;

   // to pass data in and out
   struct InputStruct myinput;
   struct OutputStruct myoutput;

   // check syntax crudely, issue usage message
   if (argc != 3) {
      fprintf(stderr,
	      "Wrong argument count! Correct usage:\n"
	      "%s float_iota_in_degrees float_psi_in_degrees\n",
	      argv[0]);
      exit(1);
   }
   myinput.iota = atof(argv[1]);
   myinput.psi = atof(argv[2]);

   // pass inclination angle, polarization axis, orientation offsets
   for (i=0;i<3;i++) myinput.orientation[i]=0.0;
   
   printf("Iota = %f degrees\nPsi = %f degrees\n", myinput.iota, myinput.psi);

   // now compute responses
   get_antenna(&myoutput, &myinput);

   for (i=0; i<5; i++) print_detector(i);
   print_source();

   // degree character in UTF-8 character set (most likely terminal type!)
   int deg1=0xC2, deg2=0xB0;
   
   // Now display waveforms
   for (i=0; i<5; i++)
      printf("For detector %s the waveform is %.3f w^2 sin(2w[t%+.1f ms]%+.1f%c%c)\n",
	     myoutput.name[i], myoutput.amp[i], myoutput.dt[i], myoutput.phase[i], deg1, deg2);

   // prints angles between line in between detector i arms and direction to source
   // for (i=0; i<5; i++) print_angles(i);

   return 0;
}