// 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
// (b) direction and origin conventions for the polarization axis
// (c) double check the hand calculations

#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);
   }

   // pass inclination angle, polarization axis, orientation offsets
   myinput.iota = atof(argv[1]);
   myinput.psi = atof(argv[2]);
   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);

   // degree character in UTF-8 character set (most likely terminal type!)
   int deg1=0xC2, deg2=0xB0;
   
   // Now display waveforms
   for (i=0; i<3; 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);

   return 0;
}