1 /*
2  * Copyright (c) 2014-2021, The OSKAR Developers.
3  * See the LICENSE file at the top-level directory of this distribution.
4  */
5 
6 #include "telescope/station/oskar_station.h"
7 #include "telescope/station/private_station.h"
8 
9 #include "utility/oskar_getline.h"
10 #include "utility/oskar_string_to_array.h"
11 #include "math/oskar_cmath.h"
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
oskar_station_save_permitted_beams(const oskar_Station * station,const char * filename,int * status)20 void oskar_station_save_permitted_beams(const oskar_Station* station,
21         const char* filename, int* status)
22 {
23     FILE* file = 0;
24     const double *az = 0, *el = 0;
25     int i = 0;
26     if (*status || !station) return;
27     file = fopen(filename, "w");
28     if (!file)
29     {
30         *status = OSKAR_ERR_FILE_IO;
31         return;
32     }
33     az = oskar_mem_double_const(
34             oskar_station_permitted_beam_az_rad_const(station), status);
35     el = oskar_mem_double_const(
36             oskar_station_permitted_beam_el_rad_const(station), status);
37     const int num_beams = oskar_station_num_permitted_beams(station);
38     for (i = 0; i < num_beams; ++i)
39     {
40         fprintf(file, "%.6f %.6f\n", az[i] * 180.0 / M_PI,
41                 el[i] * 180.0 / M_PI);
42     }
43     fclose(file);
44 }
45 
46 #ifdef __cplusplus
47 }
48 #endif
49