From 7e11286d25b6995c649ab22ef7a106a0671b8a79 Mon Sep 17 00:00:00 2001
From: Bruce Allen <ballen4705@googlemail.com>
Date: Wed, 13 Sep 2017 11:07:35 +0200
Subject: [PATCH] Split this into library and main with header file as
 interface

---
 src/antenna.c | 121 ++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 93 insertions(+), 28 deletions(-)

diff --git a/src/antenna.c b/src/antenna.c
index 3dd304a..f876f70 100644
--- a/src/antenna.c
+++ b/src/antenna.c
@@ -11,6 +11,36 @@
 #include <stdlib.h>
 #include <strings.h>
 
+
+// Structure for passing information about the GW source and detectors
+struct InputStruct {
+   // orbital orientation in degrees, 0 to 180. Zero degrees has
+   // orbital angular momentum pointing to the earth
+   double iota;
+   // orientation of long axis of ellipse, 0 to 360, in degrees CCW
+   // from North
+   double psi;
+   // orientation of detector arms away from actual, 0 to 360, in
+   // degrees CCW when viewed from directly overhead
+   // Ordering is LLO, LHO, VIRGO
+   double orientation[3];
+};
+
+// Structure for returning information about the response.  The array
+// elements are in the order LLO, LHO, VIRGO
+struct OutputStruct {
+   // amplitude of sin function, dimensionless
+   double amp[3];
+   // phase of sin function, in degrees from 0 to 360
+   double phase[3];
+   // time delays, in milliseconds
+   double dt[3];
+};
+
+// Global variables for passing information. Ugly style but doesn't
+// matter for this!
+struct InputStruct inputdata;
+
 // For converting degrees to radians
 const double deg_to_rad = M_PI/180.0;
 
@@ -184,21 +214,21 @@ void populate_detectors(){
    strcpy(detectors[0].name, " LLO ");
    detectors[0].location[0] = 30.56*deg_to_rad;
    detectors[0].location[1] = -90.77*deg_to_rad;
-   detectors[0].orientation = 198.0*deg_to_rad;
+   detectors[0].orientation = (198.0+inputdata.orientation[0])*deg_to_rad;
 
    // LHO
    // Sanity checked using Google Earth!
    strcpy(detectors[1].name, " LHO ");
    detectors[1].location[0] = 46.45*deg_to_rad;
    detectors[1].location[1] = -119.41*deg_to_rad;
-   detectors[1].orientation = 126.8*deg_to_rad;
+   detectors[1].orientation = (126.8+inputdata.orientation[1])*deg_to_rad;
    
    // VIRGO
    // Sanity checked using Google Earth!
    strcpy(detectors[2].name, "VIRGO");
    detectors[2].location[0] = 43.63*deg_to_rad;
    detectors[2].location[1] = 10.5*deg_to_rad;
-   detectors[2].orientation = 71.5*deg_to_rad;
+   detectors[2].orientation = (71.5+inputdata.orientation[2])*deg_to_rad;
 
    int i;
 
@@ -282,34 +312,23 @@ void get_UV_combinations(int det, double *alpha, double *beta, double *rdotn) {
    *rdotn = dot;
 }
 
-// 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
+// library function that can be called either from the GUI code or
+// from a stand-alone terminal program.  This function does not modify
+// the input struct, but does populate/modify the output strut!
+void get_antenna(struct OutputStruct *out, struct InputStruct *in) {
    int i;
-
-   // 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);
-   }
-   
-   // setup and test
-   // print_galaxy_coordinates();
+   // set up the source and detectors
+   inputdata=*in;
    populate_source();
-   // print_source();
-   
    populate_detectors();
-   // for (i=0; i<3; i++) print_detector(i);
 
-   // get inclination angle, polarization axis
-   double iota = atof(argv[1]);
-   double psi = atof(argv[2]);
-   printf("Iota = %f degrees\nPsi = %f degrees\n", iota, psi);
+
+   double iota = inputdata.iota;
+   double psi = inputdata.psi;
+#ifdef DEBUG
+   fprintf(stderror, "Iota = %f degrees\nPsi = %f degrees\n", iota, psi);
+#endif
    iota *= deg_to_rad;
    psi *= deg_to_rad;
 
@@ -347,11 +366,57 @@ int main(int argc, char *argv[]) {
       
       double amp = sqrt(X*X + Y*Y);
       double ang = 180.0*atan2(Y, X)/M_PI;
-      
+
+      // pass outputs
+      out->amp[i]= amp;
+      out->phase[i] = ang;
+      out->dt[i] = dt;
+
+#ifdef DEBUG
       // degree character in UTF-8 character set (most likely terminal type!)
       int deg1=0xC2, deg2=0xB0;
+      fprintf(stderr, "For detector %s the waveform is %.3f w^2 sin(2w[t%+.1f ms]%+.1f%c%c)\n", detectors[i].name, amp, dt, ang, deg1, deg2);
+#endif
+   }
+   return;
+}
+
+
+// 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;
 
-      printf("For detector %s the waveform is %.3f w^2 sin(2w[t%+.1f ms]%+.1f%c%c)\n", detectors[i].name, amp, dt, ang, deg1, deg2);
+   // 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", detectors[i].name, myoutput.amp[i], myoutput.dt[i], myoutput.phase[i], deg1, deg2);
+
    return 0;
 }
-- 
GitLab