#include <complex.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "mwa_hyperbeam.h"
void handle_hyperbeam_error(char file[], int line_num, const char function_name[]) {
int err_length = hb_last_error_length();
char *err = malloc(err_length * sizeof(char));
int err_status = hb_last_error_message(err, err_length);
if (err_status == -1) {
printf("Something really bad happened!\n");
exit(EXIT_FAILURE);
}
printf("File %s:%d: hyperbeam error in %s: %s\n", file, line_num, function_name, err);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
if (argc == 1) {
fprintf(stderr, "Expected one argument - the path to the HDF5 file.\n");
exit(EXIT_FAILURE);
}
FEEBeam *beam;
if (new_fee_beam(argv[1], &beam))
handle_hyperbeam_error(__FILE__, __LINE__, "new_fee_beam");
double az = 45.0 * M_PI / 180.0;
double za = 80.0 * M_PI / 180.0;
unsigned delays[16] = {3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3, 2, 1, 0};
double amps[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1};
int freq_hz = 51200000;
int norm_to_zenith = 1;
double latitude_rad = -0.4660608448386394;
int iau_order = 1;
complex double jones[4];
if (fee_calc_jones(beam, az, za, freq_hz, delays, amps, 16, norm_to_zenith, &latitude_rad, iau_order,
(double *)&jones))
handle_hyperbeam_error(__FILE__, __LINE__, "fee_calc_jones");
printf("The returned Jones matrix:\n");
printf("[[%+.8f%+.8fi,", creal(jones[0]), cimag(jones[0]));
printf(" %+.8f%+.8fi]\n", creal(jones[1]), cimag(jones[1]));
printf(" [%+.8f%+.8fi,", creal(jones[2]), cimag(jones[2]));
printf(" %+.8f%+.8fi]]\n", creal(jones[3]), cimag(jones[3]));
double amps_2[32] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
complex double *jones_2 = malloc(4 * sizeof(complex double));
if (fee_calc_jones(beam, az, za, freq_hz, delays, amps_2, 32, norm_to_zenith, &latitude_rad, iau_order,
(double *)jones_2))
handle_hyperbeam_error(__FILE__, __LINE__, "fee_calc_jones");
printf("The returned Jones matrix with altered Y amps:\n");
printf("[[%+.8f%+.8fi,", creal(jones_2[0]), cimag(jones_2[0]));
printf(" %+.8f%+.8fi]\n", creal(jones_2[1]), cimag(jones_2[1]));
printf(" [%+.8f%+.8fi,", creal(jones_2[2]), cimag(jones_2[2]));
printf(" %+.8f%+.8fi]]\n", creal(jones_2[3]), cimag(jones_2[3]));
free(jones_2);
free_fee_beam(beam);
return EXIT_SUCCESS;
}