Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rap.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 #ifdef TOMMIE
62 
63 /* From UNipops Cookbook */
64 Processing Frequency-Switched Data
65 
66 If you wish to combine the left half of a frequency-switched scan in Array (0)
67 with the right half, then use the verb RAP. On completion, RAP places the result
68 in Array (0), and sets the adverb OSHIFT equal to the number of channels between
69 Signal and Reference frequencies. (At present, RAP only works correctly if the
70 frequency shift is an integral number of channels.)
71 
72 Be careful when using RAP, as its operation is rather different for Green Bank and
73 Tucson data.
74 
75 Green Bank Data : RAP will compute the number of channels to
76 
77  "shift and combine" from the frequencies stored
78  in the scan header. Thus to perform the
79  combination, just type,
80 
81  >RAP
82 
83 Tucson Data : Here, one must set the two adverbs,
84 
85  FS (Frequency offset in MHz for the Signal data) and
86  FR (Frequency offset in MHz for the Reference data)
87  before invoking RAP. As of Fall 1993, these two values
88  are available from the header. There are three
89  frequency offsets stored in the header:
90  FOFFSIG, FOFFREF1, and FOFFREF2. Usually you will
91  want to set FS to the value of the FOFFSIG header
92  word and FR to the value of the FOFFREF1 header
93  word.
94 
95  > FS = H0(FOFFSIG)
96  > FR = H0(FOFFREF1)
97  > RAP
98 
99 NOTE : Following the application of RAP, the user must decide which half of the
100 spectrum is the signal half, and drop the other half via the adverbs BDROP and
101 EDROP before displaying the data. If OSHIFT is > 0, then you should set BDROP
102 to at least the value of OSHIFT. If OSHIFT is < 0, then you should set EDROP to
103 at least the absolute value of OSHIFT.
104 
105 The adverb DEFMODE indicates how RAP treats undefined data values. An undefined
106 data value is one equal to IEEE Inf (Infinity).
107 
108 If DEFMODE is FALSE, RAP will place an undefined data value at any location where
109 either the signal or reference values are undefined (i.e. if channel 100 is
110 undefined, as above, then the channel in the result that depends on channel 100
111 will also be undefined if DEFMODE is FALSE).
112 
113 If DEFMODE is TRUE, RAP will place an undefined data value at any location where
114 both the signal and reference values are undefined. However, if only one value is
115 undefined, then the result will be as if the undefined value were zero (i.e. if
116 channel 100 is the only undefined value, then that value will be treated as if
117 it were 0).
118 
119 Most users will leave DEFMODE set to its default value of FALSE.
120 
121 
122 C-----------------------------------------------------------------------
123 C RAP
124 C----------------------------------------------------------------------
125  170 CONTINUE
126  if(dtwh(c1tel,iptwh).eq.value12m) then
127  goto 1709
128  else if(dtwh(c1tel,iptwh).eq.value140 .or.
129  1 dtwh(c1tel,iptwh).eq.value300) then
130  goto 1719
131  else
132  call oerror(n283, m2, 'RAP')
133  endif
134 c Tucson Version
135 c input adverbs : fr = signal frequency (MHz)
136 c fs = referenc freq (MHz)
137 1709 continue
138  OSHFT=(FR-FS)/DTWH(C12FR,IPTWH)
139 c oshift number of channels
140  if(oshft.eq.0.0) call oerror(n291, m2, 'RAP')
141  IF (OSHFT.le.0.0) then
142 c
143  IDF=nint(ABS(OSHFT))
144  ISTART=DTWH(C12SPN,IPTWH) + IDATOFF
145  ISTOP=DTWH(C12SPN,IPTWH) + DTWH(C12NI,IPTWH)
146  . + IDATOFF -IDF - 1
147  DO 172 JJ = ISTART,ISTOP
148  if(okreal4(TWH(JJ,IPTWH)) .and.
149  . okreal4(TWH(JJ+IDF,IPTWH))) then
150  TWH(JJ,IPTWH)=(TWH(JJ,IPTWH)-TWH(JJ+IDF,IPTWH))/2.0
151  else if (defmode .ge. 0.5 .and. okreal4(TWH(JJ+IDF,IPTWH))) then
152  twh(jj,iptwh)=-TWH(JJ+IDF,IPTWH)
153  else if (defmode .lt. 0.5) then
154  twh(jj,iptwh)=rinfinity()
155  endif
156  172 CONTINUE
157  DTWH(C12NI,IPTWH)=DTWH(C12NI,IPTWH)-IDF
158  else
159 c
160  IDF=nint(OSHFT+0.5)
161  ISTART=DTWH(C12SPN,IPTWH)+IDATOFF+IDF
162  ISTOP=DTWH(C12SPN,IPTWH)+DTWH(C12NI,IPTWH)+
163  . IDATOFF - 1
164  DO 177 JJ=ISTOP,ISTART,-1
165  if(okreal4(TWH(JJ,IPTWH)) .and.
166  . okreal4(TWH(JJ-IDF,IPTWH))) then
167  TWH(JJ,IPTWH)=(TWH(JJ,IPTWH)-TWH(JJ-IDF,IPTWH))/2.0
168  else if (defmode .ge. 0.5 .and. okreal4(TWH(JJ-IDF,IPTWH))) then
169  twh(jj,iptwh)=-TWH(JJ-IDF,IPTWH)
170  else if (defmode .lt. 0.5) then
171  twh(jj,iptwh)=rinfinity()
172  endif
173  177 CONTINUE
174  DTWH(C12SPN,IPTWH)=DTWH(C12SPN,IPTWH)+IDF
175  DTWH(C12NI,IPTWH)=DTWH(C12NI,IPTWH)-IDF
176  endif
177 c
178  DF=-(FS)/DTWH(C12FR,IPTWH)
179  IDF=nint(DF)
180 c set ref point
181  DTWH(C12RP,IPTWH) = DTWH(C12RP,IPTWH) + FLOAT(IDF)
182  GO TO 99
183 
184 #endif
185 
186 
188 {
189  int i, idf, istart, istop;
190  double oshift, fs, fr, df;
191 
192  if(isSet(PF_A_FLAG)) /* Get offsets from header */
193  {
194  fs = h0->head.foffsig;
195  fr = h0->head.foffref1;
196  }
197  else /* User sets them himself */
198  {
199  fs = env->fs;
200  fr = env->fr;
201  }
202 
203  if(fs == 0.0 && fr == 0.0)
204  {
206 
207  return(1);
208  }
209 
210  oshift = (fr-fs) / h0->head.freqres;
211 
212  if(oshift == 0.0)
213  {
214  st_report("Diff between FS & FR = 0.0");
215 
216  return(1);
217  }
218 
219  if(oshift < 0.0)
220  {
221  idf = (int)fabs(round(oshift));
222  istart = 0;
223  istop = (int)(h0->head.noint - (double)idf);
224 
225  for(i=istart;i<istop;i++)
226  {
227  /* Check for NAN here */
228  h0->yplot1[i] = (h0->yplot1[i] - h0->yplot1[i+idf]) / 2.0;
229  }
230 
231  h0->head.noint -= (double)idf;
232  }
233  else
234  {
235  idf = (int)round(oshift + 0.5);
236  istart = idf;
237  istop = (int)(h0->head.noint - 1.0);
238 
239  for(i=istop;i>istart;i--)
240  {
241  /* Check for NAN here */
242  h0->yplot1[i] = (h0->yplot1[i] - h0->yplot1[i+idf]) / 2.0;
243  }
244 
245  h0->head.spn += (double)idf;
246  h0->head.noint -= (double)idf;
247  }
248 
249  df = fs / h0->head.noint;
250  idf = (int)round(df);
251 
252  h0->head.refpt += (double)idf;
253 
254  return(0);
255 }
256 
float yplot1[MAX_CHANS]
Definition: image.h:110
struct LP_IMAGE_INFO * h0
Definition: image.c:74
#define FALSE
Definition: xgraphic.c:40
int do_FreqSwitch(void)
Definition: rap.c:187
#define C
Definition: beam.c:64
struct PARSE_STACK * args
Definition: parse.h:196
#define FLOAT
Definition: defines.h:55
double noint
Definition: header.h:211
Definition: parse.h:8
struct LP_IMAGE_INFO H0
Definition: image.c:63
int scan
int printH_FlagHelp(char *cmd)
Definition: help.c:430
int shift(void)
Definition: shift.c:65
double fr
Definition: env.h:293
double foffref1
Definition: header.h:150
double foffsig
Definition: header.h:149
double spn
Definition: header.h:212
struct ENVIRONMENT * env
Definition: linuxpops.c:71
#define FS
Definition: observing_par.h:29
int isSet(int flag)
Definition: parse.c:646
struct HEADER head
Definition: image.h:104
struct XBE_POS m2[]
Definition: obsmodes.c:77
double fs
Definition: env.h:292
double refpt
Definition: header.h:207
void st_report()
int set
Definition: parse.h:88
#define TRUE
Definition: xgraphic.c:39
char * firstArg
Definition: parse.h:180
double freqres
Definition: header.h:199