Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
shift.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 /* Perform the actual shift. 'ashift' contains the number
62  of channels to shift +/-; left or right. ashift must be
63  and interger number of channels */
64 
65 int shift()
66 {
67  int i, n, nn;
68  float thold[MAX_CHANS], *f1, *f2;
69 
70  if(env->ashift == 0 || env->ashift < -300 || env->ashift > 300)
71  {
72  st_fail("shift(): ASHIFT %d out of range -300 to 300; but not 0", env->ashift);
73  return(1);
74  }
75 
76  st_report("Shifting data %d channels", env->ashift);
77 
78  n = h0->head.noint;
79 
80  bzero((char *)&thold[0], sizeof(thold));
81 
82  if(env->ashift < 0)
83  {
84  f1 = &thold[0];
85  f2 = &h0->yplot1[abs(env->ashift)];
86 
87  nn = n - abs(env->ashift);
88 
89  st_report("Moving a total of %d channels left", nn);
90 
91  for(i=0;i<nn;i++, f1++, f2++)
92  {
93  *f1 = *f2;
94  }
95 
96  bzero((char *)h0->yplot1, sizeof(h0->yplot1));
97  bcopy((char *)&thold[0], (char *)h0->yplot1, sizeof(h0->yplot1));
98 
99  h0->head.restfreq -= (double)env->ashift*h0->head.freqres;
100  h0->head.obsfreq -= (double)env->ashift*h0->head.freqres;
101 
102  setColor(RED);
103 
104  if(isSet(PF_D_FLAG))
105  {
106  st_report("Dropping %d Channels From End", abs(env->ashift));
107  env->edrop = abs(env->ashift);
108  }
109  else
110  {
111  st_report("Recommend 'edrop=%d'", abs(env->ashift));
112  }
113 
114  setColor(BLACK);
115  }
116  else
117  {
118  f1 = &thold[env->ashift];
119  f2 = &h0->yplot1[0];
120 
121  nn = n - env->ashift;
122 
123  st_report("Moving a total of %d channels Right", nn);
124 
125  for(i=0;i<nn;i++, f1++, f2++)
126  {
127  *f1 = *f2;
128  }
129 
130  bzero((char *)h0->yplot1, sizeof(h0->yplot1));
131  bcopy((char *)&thold[0], (char *)h0->yplot1, sizeof(h0->yplot1));
132 
133  h0->head.restfreq -= (double)env->ashift*h0->head.freqres;
134  h0->head.obsfreq -= (double)env->ashift*h0->head.freqres;
135 
136  setColor(RED);
137 
138  if(isSet(PF_D_FLAG))
139  {
140  st_report("Dropping %d Channels From Start", abs(env->ashift));
141  env->bdrop = abs(env->ashift);
142  }
143  else
144  {
145  st_report("Recommend 'bdrop=%d'", env->ashift);
146  }
147 
148  setColor(BLACK);
149  }
150 
151  if(notSet(PF_D_FLAG))
152  {
153  st_report("NOTE: Be sure to '[e|b]drop' the 'shifted' %d chans", env->ashift);
154  }
155 
156  h0->shifted = env->ashift;
157 
158  return(0);
159 }
160 
161 
162 int doShift()
163 {
164  return(shift());
165 }
166 
167 
169 {
170  int f, idiff, ret=0;
171  double f1, f2, fdiff;
172  struct LP_IMAGE_INFO *first, *second;
173 
174  if(strlen(args->secondArg))
175  {
176  f = parseHarg(args->secondArg);
177 
178  if((f >= 0 && f < MAX_IMAGES))
179  {
180  first = findImage(f);
181  second = h0;
182 
183  if(first == second)
184  {
185  st_fail("autoShift(): First and Second Holders must be different");
186  return(1);
187  }
188 
189  f1 = first->head.restfreq;
190  f2 = second->head.restfreq;
191 
192  st_report("%s Freq: = %f, %s Freq: = %f", first->name, f1, second->name, f2);
193 
194  fdiff = f2 - f1; /* Diff between current and designated freq */
195  st_report("diff = %.2f MHz", fdiff);
196 
197  idiff = (int)round(fdiff / first->head.freqres);
198 
199  if(isSet(PF_O_FLAG)) /* We are shifting the image's into alignment */
200  {
201  idiff *= -2;
202 
203  st_report("Setting Opposite ashift to %d", idiff);
204  }
205  else
206  {
207  st_report("Setting ashift to %d", idiff);
208  }
209 
210  env->ashift = idiff;
211 
212  if(env->ashift)
213  {
214  ret = doShift();
215  }
216  }
217  }
218 
219  return(ret);
220 }
float yplot1[MAX_CHANS]
Definition: image.h:110
struct LP_IMAGE_INFO * h0
Definition: image.c:74
int compAutoShift(void)
Definition: shift.c:168
int doShift(void)
Definition: shift.c:162
int first
Definition: dbase.c:106
struct PARSE_STACK * args
Definition: parse.h:196
int edrop
Definition: env.h:52
double noint
Definition: header.h:211
int ashift
Definition: env.h:23
#define MAX_CHANS
Definition: defines.h:38
#define RED
Definition: colors.h:5
char name[32]
Definition: image.h:73
int shift(void)
Definition: shift.c:65
int notSet(int flag)
Definition: parse.c:669
struct ENVIRONMENT * env
Definition: linuxpops.c:71
int isSet(int flag)
Definition: parse.c:646
struct HEADER head
Definition: image.h:104
double obsfreq
Definition: header.h:197
void st_fail()
int setColor(int c)
Definition: parse.c:2644
int parseHarg(char *arg)
Definition: image.c:256
void st_report()
int shifted
Definition: image.h:94
int bdrop
Definition: env.h:31
#define MAX_IMAGES
Definition: defines.h:34
#define BLACK
Definition: colors.h:4
char * secondArg
Definition: parse.h:181
double restfreq
Definition: header.h:198
double freqres
Definition: header.h:199
struct LP_IMAGE_INFO * findImage(int i)
Definition: image.c:233