Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
getMoonAge.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 /* Returns the time since the last new moon */
59 /* */
60 /* The file NEWMOONS contains new-moon times from */
61 /* page A1 of the Almanac. When updating the file, */
62 /* be sure to retain at least the entry for the most */
63 /* recent, previous new moon. */
64 /* */
65 
66 #include "extern.h"
67 
68 #define NEWMOONS "newmoons"
69 
70 double getMoonAge(int yr, int mon, int day, int hr, int min)
71 {
72  int count;
73  int nm_yr, nm_mon, nm_day, nm_hr, nm_min;
74  int last_nm_yr, last_nm_mon, last_nm_day, last_nm_hr, last_nm_min;
75  double mjd, nm_mjd, last_nm_mjd;
76  char nmfile[256];
77 
78  FILE *fp;
79 
80  sprintf(nmfile, "%s/share/%s", pkg_home, NEWMOONS);
81 
82  if((fp = fopen(nmfile, "r")) == NULL)
83  {
84  st_fail("getMoonAge(): Can't open %s", nmfile);
85 
86  return(0);
87  }
88 
89  count = 0;
90  nm_mjd = 0.0;
91  mjd = getmjd(yr, mon, day, hr, min);
92 
93  while(fscanf(fp, "%d %d %d %d %d", &nm_yr, &nm_mon, &nm_day, &nm_hr, &nm_min) != EOF)
94  {
95  if((nm_mjd = getmjd(nm_yr, nm_mon, nm_day, nm_hr, nm_min)) > mjd)
96  {
97  break;
98  }
99  else
100  {
101  last_nm_yr = nm_yr;
102  last_nm_mon = nm_mon;
103  last_nm_day = nm_day;
104  last_nm_hr = nm_hr;
105  last_nm_min = nm_min;
106  last_nm_mjd = nm_mjd;
107  count++;
108  }
109  }
110 
111  fclose(fp);
112 
113  if(count == 0)
114  {
115  st_fail("getMoonAge(): no prior new moons listed in %s", nmfile);
116  return(0);
117  }
118 
119  last_nm_mjd = getmjd(last_nm_yr, last_nm_mon, last_nm_day, last_nm_hr, last_nm_min);
120 
121  if (nm_mjd == last_nm_mjd)
122  {
123  st_fail("getMoonAge(): %s is out of date", nmfile);
124  }
125 
126  return(mjd - last_nm_mjd);
127 }
char pkg_home[256]
Definition: makemem.c:97
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
FILE * fp
Definition: linuxpops.c:70
#define min(a, b)
Definition: cactus.h:114
int mon
Definition: convol.c:102
void st_fail()
#define NEWMOONS
Definition: getMoonAge.c:68