Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
getephem.c
Go to the documentation of this file.
1 /*
2 Copyright 2021 Arizona Board of Regents on behalf of the University of Arizona.
3 
4 For commercial uses, to obtain a license to sell and or sublicense copies of
5 the Software please contact the University of Arizona at Tech Launch Arizona:
6 lewish@tla.arizona.edu.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction for non-commercial use educational and
11 research purposes, including without limitation the rights to use, copy,
12 modify, merge, publish, distribute, and to permit persons to whom the Software
13 is furnished to do so, subject to the following conditions:
14 
15 The entire above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 
26 1. Additional Required Provisions
27 
28 1.1. Arbitration. The parties agree that if a dispute arises between them
29 concerning this Agreement, the parties may be required to submit the matter to
30 arbitration pursuant to Arizona law.
31 
32 1.2. Applicable Law and Venue. This Agreement shall be interpreted pursuant
33 to the laws of the State of Arizona. Any arbitration or litigation between the
34 Parties shall be conducted in Pima County, ARIZONA, and LICENSEE hereby
35 submits to venue and jurisdiction in Pima County, ARIZONA.
36 
37 1.3. Non-Discrimination. The Parties agree to be bound by state and federal
38 laws and regulations governing equal opportunity and non-discrimination and
39 immigration.
40 
41 1.4. Appropriation of Funds. The Parties recognize that performance by
42 ARIZONA may depend upon appropriation of funds by the State Legislature of
43 ARIZONA. If the Legislature fails to appropriate the necessary funds, or if
44 ARIZONA’S appropriation is reduced during the fiscal year, ARIZONA may cancel
45 this Agreement without further duty or obligation. ARIZONA will notify
46 LICENSEE as soon as reasonably possible after it knows of the loss of funds.
47 
48 1.5. Conflict of Interest. This Agreement is subject to the provisions of
49 A.R.S. 38-511 and other conflict of interest regulations. Within three years
50 of the EFFECTIVE DATE, ARIZONA may cancel this Agreement if any person
51 significantly involved in initiating, negotiating, drafting, securing, or
52 creating this Agreement for or on behalf of ARIZONA becomes an employee or
53 consultant in any capacity of LICENSEE with respect to the subject matter of
54 this Agreement.
55 
56  */
57 
58 /* */
59 /* Program getephem.c M. Begam 27 Feb 2012 */
60 /* */
61 /* Extracts the data from the on-disk planet ephemeris */
62 /* required for analyzing beam-efficiency measurments. */
63 /* */
64 /* The ephemeris file contains data for 2010-2025 as */
65 /* generated by Y. Shirley from 'The Rings Node' of */
66 /* NASA's Planetary Data System web site at */
67 /* */
68 /* http://pds-rings.seti.org/ */
69 /* */
70 
71 #include "extern.h"
72 
73 #define FEB 1
74 #define MJD2000 51544.0
75 #define YEAR yr-2012
76 #define MON mon-1
77 
78 int yr12to25[14] = { 4382,
79  4748,
80  5113,
81  5478,
82  5843,
83  6209,
84  6574,
85  6939,
86  7304,
87  7670,
88  8035,
89  8400,
90  8765,
91  9131 };
92 
93 int mon_norm[12] = {0, 31, 59, 90, 120, 151,
94  181, 212, 243, 273, 304, 334};
95 
96 int mon_leap[12] = {0, 31, 60, 91, 121, 152,
97  182, 213, 244, 274, 305, 335};
98 
99 double getmjd(int yr, int mon, int day, int hr, int min)
100 {
101  double ut, mjd;
102 
103  ut = (double) hr + (double) min / 60.0;
104  mjd = MJD2000 + (double) yr12to25[YEAR];
105  if (yr % 4)
106  mjd += (double) mon_norm[MON];
107  else
108  mjd += (double) mon_leap[MON];
109  mjd += ((double) day + ut / 24.0);
110 
111  return(mjd);
112 }
113 
114 
116 {
117  time_t curtime;
118  struct tm *uttime;
119 
120  curtime = time(NULL);
121  uttime = gmtime(&curtime);
122 
123  tp->year = uttime->tm_year + 1900;
124  tp->mon = uttime->tm_mon + 1;
125  tp->day = uttime->tm_mday;
126  tp->hour = uttime->tm_hour;
127  tp->min = uttime->tm_min;
128 }
129 
131 int first;
132 {
133  TIME *tm = &global.time;
134  EPH *eph = &global.eph;
135 
136  int day1, day2, mon1, mon2, interp;
137  int yr, curyea, curmon, curday, curhou, curmin;
138 
139  int maxdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
140 
141  double day, frac;
142  double ven_d1, mar_d1, mar_r1, jup_d1, sat_d1, sat_i1;
143  double ven_d2, mar_d2, mar_r2, jup_d2, sat_d2, sat_i2;
144 
145  time_t curtime;
146  struct tm *uttime;
147 
148  FILE *fp;
149 
150  char ename[256];
151 
152  if(tm->UseCurrent)
153  {
154  /* get current UT date and time from the system */
155  curtime = time(NULL);
156  uttime = gmtime(&curtime);
157  curyea = uttime->tm_year + 1900;
158  curmon = uttime->tm_mon + 1;
159  curday = uttime->tm_mday;
160  curhou = uttime->tm_hour;
161  curmin = uttime->tm_min;
162 
163  tm->year = curyea;
164  tm->mon = curmon;
165  tm->day = curday;
166  tm->hour = curhou;
167  tm->min = curmin;
168  }
169  else
170  {
171  /* get UT date and time from GUI */
172  curyea = tm->year;
173  curmon = tm->mon;
174  curday = tm->day;
175  curhou = tm->hour;
176  curmin = tm->min;
177  }
178 
179  /* check for valid input */
180 
181  if(curyea < 2010 || curyea > 2025)
182  {
183  st_fail("Year: %d Outside valid range of 2010-2025", curyea);
184  return(0);
185  }
186 
187  if(curmon < 1 || curmon > 12)
188  {
189  st_fail("Invalid month: %d", curmon);
190  return(0);
191  }
192 
193  /* simplified leap-year check: valid for year range */
194 
195  if(curyea % 4 == 0)
196  {
197  maxdays[FEB]++;
198  }
199 
200  if(curday < 1 || curday > maxdays[curmon-1])
201  {
202  st_fail("Invalid day: %d", curday);
203  return(0);
204  }
205 
206  if(curhou < 0 || curhou > 23)
207  {
208  st_fail("Invalid hour: %d", curhou);
209  return(0);
210  }
211 
212  if(curmin < 0 || curmin > 59)
213  {
214  st_fail("Invalid minutes: %d", curmin);
215  return(0);
216  }
217 
218  /* open ephemeris */
219 
220  sprintf(ename, "%s/share/%s", pkg_home, EPHEM);
221 
222  if(first)
223  {
224  st_report("Using Ephem file: %s", ename);
225  }
226 
227  if((fp = fopen(ename, "r")) == NULL)
228  {
229  st_fail("Can't open ephemeris file: %s", ename);
230  return(0);
231  }
232 
233  /* read line matching input date and time plus the one after that */
234  /* (skip the sun-angle data fields in the ephemeris) */
235 
236  interp = 1;
237  while (fscanf(fp, "%d %d %d %lf %*s %lf %lf %*s %lf %*s %lf %lf %*s",
238  &yr, &mon1, &day1, &ven_d1, &mar_d1, &mar_r1, &jup_d1, &sat_d1, &sat_i1) != EOF)
239  {
240  if(yr == curyea && mon1 == curmon && day1 == curday)
241  {
242  break;
243  }
244  }
245 
246  if(fscanf(fp, "%d %d %d %lf %*s %lf %lf %*s %lf %*s %lf %lf %*s",
247  &yr, &mon2, &day2, &ven_d2, &mar_d2, &mar_r2, &jup_d2, &sat_d2, &sat_i2) == EOF)
248  {
249  st_fail("End of Ephemeris--unable to interpolate!");
250  interp = 0;
251  }
252 
253  /* interpolate the data if able to read both lines */
254 
255  if(interp)
256  {
257  frac = ((double) curhou + ((double) curmin / 60.0)) / 24.0;
258  ven_d1 += frac * (ven_d2 - ven_d1);
259  mar_d1 += frac * (mar_d2 - mar_d1);
260  mar_r1 += frac * (mar_r2 - mar_r1);
261  jup_d1 += frac * (jup_d2 - jup_d1);
262  sat_d1 += frac * (sat_d2 - sat_d1);
263  sat_i1 += frac * (sat_i2 - sat_i1);
264  day = (double) day1 + frac;
265  }
266 
267  eph->VenDiam = ven_d1;
268  eph->MarDiam = mar_d1;
269  eph->MarDist = mar_r1;
270  eph->JupDiam = jup_d1;
271  eph->SatDiam = sat_d1;
272  eph->SatIncl = sat_i1;
273  eph->MoonAge = getMoonAge(curyea, curmon, curday, curhou, curmin);
274  eph->Day = day;
275 
276  fclose(fp);
277 
278  return(0);
279 }
EPH eph
Definition: beam.h:49
Definition: beam.h:32
char pkg_home[256]
Definition: makemem.c:97
int first
Definition: dbase.c:106
int interp(double *array, int nx, int ny, double *parray, int npx, int npy)
Definition: interp.c:102
double getMoonAge(int yr, int mon, int day, int hr, int min)
Definition: getMoonAge.c:70
double getmjd(int yr, int mon, int day, int hr, int min)
Definition: getephem.c:99
int yr12to25[14]
Definition: getephem.c:78
FILE * fp
Definition: linuxpops.c:70
#define FEB
Definition: getephem.c:73
double VenDiam
Definition: beam.h:34
#define min(a, b)
Definition: cactus.h:114
int min
Definition: beam.h:28
#define MJD2000
Definition: getephem.c:74
int day
Definition: beam.h:26
double MarDist
Definition: beam.h:36
double SatIncl
Definition: beam.h:39
int mon
Definition: convol.c:102
int getephem(int first)
Definition: getephem.c:130
double MarDiam
Definition: beam.h:35
void getephem_utc(TIME *tp)
Definition: getephem.c:115
int year
Definition: beam.h:24
int mon
Definition: beam.h:25
void st_fail()
int mon_norm[12]
Definition: getephem.c:93
#define YEAR
Definition: getephem.c:75
double Day
Definition: beam.h:41
void st_report()
int UseCurrent
Definition: beam.h:29
TIME time
Definition: beam.h:48
#define EPHEM
Definition: ephem.h:2
double JupDiam
Definition: beam.h:37
int hour
Definition: beam.h:27
GLOBAL global
Definition: beam.h:52
int mon_leap[12]
Definition: getephem.c:96
double SatDiam
Definition: beam.h:38
Definition: beam.h:22
#define MON
Definition: getephem.c:76
double MoonAge
Definition: beam.h:40