Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
dbase.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 #include "extern.h"
60 
61 #include <mysql/mysql.h>
62 
63 
65  int SCANID;
66  double Scanno;
67  char Fname[120];
68  char Obs[8];
69  char Opr[8];
70  double UTdate;
71  char Tele[8];
72  double UT;
73  double LST;
74  char Source[24];
75  char Epoch[8];
76  double RA;
77  double Declin;
78  double Vel;
79  double Az;
80  double El;
81  double AzOff;
82  double ElOff;
83  char Front[8];
84  char Line[16];
85  double Rest;
86  double Sky;
87  char Back[8];
88  double Noint;
89  double Freqres;
90  double FirstIF;
91  double Sb;
92  double T_Sys;
93  double Tamb;
94  double Pres;
95  double Hum;
96  double mmh20;
97  double PBeam;
98  double NutRate;
99  char ObsMode[8];
100  double IntTime;
101 };
102 
104 
105 
107 
108 char dbase_tok[120][120];
109 
113 int dbase_get_tok(edit)
114 char *edit;
115 {
116  int c = 0;
117  char *token;
118 
119  bzero((char *)&dbase_tok, sizeof(dbase_tok));
120 
121  token = strtok(edit, ",");
122  while(token != (char *)NULL)
123  {
124  sprintf(dbase_tok[c++], "%s", token);
125  token = strtok((char *)NULL, ",");
126  }
127 
128  return(c);
129 }
130 
131 
132 /*
133 
134 36 items;
135 
136 0000094492 177.01 /home/archive/2017-2018/12m/data/lmz/sdd.lmz_043 sys sck \
137 2004.1009 NRAO 12M 12.12277222 5.91141887 IRC+10216 1950.0 146.31166667 13.51111111 \
138 -26 95.24140111 33.6776447 0 0 3mmhi 12CO 115271.204 115287.7146841 \
139 FB_2_01 256 1 1500 2 3337 15.86 611.05 27.35 48.24 120.00002 0 LINEBSP 120
140 
141  */
142 int printRow(buf)
143 char *buf;
144 {
145  int n;
146 
147  if(buf)
148  {
149  n = dbase_get_tok(buf);
150  if(n == 36)
151  {
152  mysql_response.SCANID = atoi(dbase_tok[ 0]);
153  mysql_response.Scanno = atof(dbase_tok[ 1]);
154  strcpy(mysql_response.Fname, dbase_tok[ 2]);
155  strcpy(mysql_response.Obs, dbase_tok[ 3]);
156  strcpy(mysql_response.Opr, dbase_tok[ 4]);
157  mysql_response.UTdate = atof(dbase_tok[ 5]);
158  strcpy(mysql_response.Tele, dbase_tok[ 6]);
159  mysql_response.UT = atof(dbase_tok[ 7]);
160  mysql_response.LST = atof(dbase_tok[ 8]);
161  strcpy(mysql_response.Source, dbase_tok[ 9]);
162  strcpy(mysql_response.Epoch, dbase_tok[10]);
163  mysql_response.RA = atof(dbase_tok[11]);
164  mysql_response.Declin = atof(dbase_tok[12]);
165  mysql_response.Vel = atof(dbase_tok[13]);
166  mysql_response.Az = atof(dbase_tok[14]);
167  mysql_response.El = atof(dbase_tok[15]);
168  mysql_response.AzOff = atof(dbase_tok[16]);
169  mysql_response.ElOff = atof(dbase_tok[17]);
170  strcpy(mysql_response.Front, dbase_tok[18]);
171  strcpy(mysql_response.Line, dbase_tok[19]);
172  mysql_response.Rest = atof(dbase_tok[20]);
173  mysql_response.Sky = atof(dbase_tok[21]);
174  strcpy(mysql_response.Back, dbase_tok[22]);
175  mysql_response.Noint = atof(dbase_tok[23]);
176  mysql_response.Freqres = atof(dbase_tok[24]);
177  mysql_response.FirstIF = atof(dbase_tok[25]);
178  mysql_response.Sb = atof(dbase_tok[26]);
179  mysql_response.T_Sys = atof(dbase_tok[27]);
180  mysql_response.Tamb = atof(dbase_tok[28]);
181  mysql_response.Pres = atof(dbase_tok[29]);
182  mysql_response.Hum = atof(dbase_tok[30]);
183  mysql_response.mmh20 = atof(dbase_tok[31]);
184  mysql_response.PBeam = atof(dbase_tok[32]);
185  mysql_response.NutRate = atof(dbase_tok[33]);
186  strcpy(mysql_response.ObsMode, dbase_tok[34]);
187  mysql_response.IntTime = atof(dbase_tok[35]);
188 
189  if(first)
190  {
191  printf("\n Scan Source Filename Date Freq Mode\n\n");
192  first = 0;
193  }
194 
195  printf("%8.2f %16.16s %64s %9.4f %10.3f %8.8s\n",
202  dbindx++;
203  }
204  else
205  {
206  printf("N = %d\n", n);
207  }
208  }
209  else
210  {
211  }
212 
213  return(0);
214 }
215 
216 
217 int doDbase()
218 {
219  int i, num_fields;
220  MYSQL *conn;
221  MYSQL_RES *result;
222  MYSQL_ROW row;
223  char qstr[1024], rstr[4096], tbuf[256], gstr[64];
224 
225  st_report("Entering Dbase Sub-System");
226 
227  if(isSet(PF_R_FLAG))
228  {
229  st_report("Dbase Query Command");
230 
231  first = 1;
232  dbindx = 0;
233 
234  conn = mysql_init(NULL);
235 
236  if(conn == NULL)
237  {
238  printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
239  return(1);
240  }
241 
242  if(mysql_real_connect(conn, "hamms", "tfolkers", "2bad4you", "ARO_Data_Archive", 0, NULL, 0) == NULL)
243  {
244  printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
245  return(1);
246  }
247 
248  if(isSet(PF_G_FLAG))
249  {
250  if(isSet(PF_O_FLAG))
251  {
252  strcpy(gstr, "GROUP by Source");
253  }
254  else
255  if(isSet(PF_T_FLAG))
256  {
257  strcpy(gstr, "GROUP by Rest");
258  }
259  else
260  {
261  strcpy(gstr, "GROUP by Fname");
262  }
263  }
264  else
265  {
266  strcpy(gstr, " ");
267  }
268 
269  if(isSet(PF_M_FLAG)) /* Match Mode */
270  {
271  if(strlen(args->secondArg))
272  {
273  sprintf(qstr, "SELECT * FROM ARO_Data_Archive.Scan_Records WHERE ObsMode LIKE '%%%s%%' %s", args->secondArg, gstr);
274  }
275  else
276  {
277  printH_FlagHelp("dbase");
278 
279  mysql_close(conn); /* Always close the connection */
280 
281  return(1);
282  }
283  }
284  else
285  if(isSet(PF_S_FLAG) && notSet(PF_F_FLAG)) /* Match Source */
286  {
287  sprintf(qstr,
288  "SELECT * FROM ARO_Data_Archive.Scan_Records WHERE Source LIKE '%%%s%%' %s",
289  env->source, gstr);
290  }
291  else
292  if(notSet(PF_S_FLAG) && isSet(PF_F_FLAG)) /* Match Freq */
293  {
294  sprintf(qstr,
295  "SELECT * FROM ARO_Data_Archive.Scan_Records WHERE Rest > '%.3f' AND Rest < '%.3f' %s",
296  (env->freq-env->dfreq) * 1e3, (env->freq+env->dfreq) * 1e3, gstr);
297  }
298  else
299  if(isSet(PF_S_FLAG) && isSet(PF_F_FLAG)) /* Match Both */
300  {
301  sprintf(qstr,
302  "SELECT * FROM ARO_Data_Archive.Scan_Records WHERE Source LIKE '%%%s%%' AND Rest > '%.3f' AND Rest < '%.3f' %s",
303  env->source, (env->freq-env->dfreq) * 1e3, (env->freq+env->dfreq) * 1e3, gstr);
304  }
305  else
306  {
307  printH_FlagHelp("dbase");
308 
309  mysql_close(conn); /* Always close the connection */
310 
311  return(1);
312  }
313 
314  printf("Qstr = %s\n", qstr);
315 
316  if(mysql_query(conn, qstr))
317  {
318  printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
319  mysql_close(conn); /* Always close the connection */
320 
321  return(1);
322  }
323 
324  result = mysql_store_result(conn);
325 
326  if(result->row_count > 256)
327  {
328  if(!getYesNoQuit("MySql Returned %d Rows; Continue: y/N ?", result->row_count))
329  {
330  st_report("Cancelling Request; You might try the /g, grouping-flag, next time");
331 
332  mysql_free_result(result);
333 
334  mysql_close(conn); /* Always close the connection */
335 
336  return(0);
337  }
338  }
339 
340  num_fields = mysql_num_fields(result);
341  row = mysql_fetch_row(result);
342 
343  if(row)
344  {
345  while(row)
346  {
347  rstr[0] = '\0';
348 
349  for(i=0;i<num_fields;i++)
350  {
351  sprintf(tbuf, "%s ,", row[i]);
352  strcat(rstr, tbuf);
353  }
354 
355  printRow(rstr);
356 
357  row = mysql_fetch_row(result);
358  }
359  }
360  else
361  {
362  st_report("No Records Found");
363  }
364 
365  mysql_free_result(result);
366 
367  mysql_close(conn); /* Always close the connection */
368 
369  if(dbindx)
370  {
371  st_report("Found %d records", dbindx);
372  }
373  }
374 
375  if(isSet(PF_I_FLAG))
376  {
377  st_report("Dbase Ingest Command Not Implemented Yet");
378  }
379 
380  return(0);
381 }
char Front[8]
Definition: dbase.c:83
double Tamb
Definition: dbase.c:93
double dfreq
Definition: env.h:183
double T_Sys
Definition: dbase.c:92
double mmh20
Definition: dbase.c:96
int first
Definition: dbase.c:106
struct PARSE_STACK * args
Definition: parse.h:196
double Freqres
Definition: dbase.c:89
char Tele[8]
Definition: dbase.c:71
int printH_FlagHelp(char *cmd)
Definition: help.c:430
double PBeam
Definition: dbase.c:97
char Back[8]
Definition: dbase.c:87
double ElOff
Definition: dbase.c:82
char Epoch[8]
Definition: dbase.c:75
char Opr[8]
Definition: dbase.c:69
double El
Definition: dbase.c:80
int dbindx
Definition: dbase.c:106
int printRow(char *buf)
Definition: dbase.c:142
char dbase_tok[120][120]
Definition: dbase.c:108
double NutRate
Definition: dbase.c:98
double LST
Definition: dbase.c:73
double UTdate
Definition: dbase.c:70
int notSet(int flag)
Definition: parse.c:669
int getYesNoQuit()
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int dbase_get_tok(char *edit)
Definition: dbase.c:113
char source[64]
Definition: env.h:11
int isSet(int flag)
Definition: parse.c:646
double Noint
Definition: dbase.c:88
struct MYSQL_RESPONSE mysql_response
Definition: dbase.c:103
double FirstIF
Definition: dbase.c:90
double Scanno
Definition: dbase.c:66
double Hum
Definition: dbase.c:95
char Source[24]
Definition: dbase.c:74
double Vel
Definition: dbase.c:78
double Pres
Definition: dbase.c:94
double Sky
Definition: dbase.c:86
double Sb
Definition: dbase.c:91
int SCANID
Definition: dbase.c:65
double Declin
Definition: dbase.c:77
void st_report()
double Az
Definition: dbase.c:79
double AzOff
Definition: dbase.c:81
double freq
Definition: env.h:197
char ObsMode[8]
Definition: dbase.c:99
char * secondArg
Definition: parse.h:181
double IntTime
Definition: dbase.c:100
char Line[16]
Definition: dbase.c:84
int doDbase()
Definition: dbase.c:217
double UT
Definition: dbase.c:72
double Rest
Definition: dbase.c:85
double RA
Definition: dbase.c:76
char Fname[120]
Definition: dbase.c:67
char Obs[8]
Definition: dbase.c:68