Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
box.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 /* Changes:
62  *
63  * Added nbox function: twf; March 01, 2016
64  * Added hanning function: twf; Jan 04, 2017
65  *
66  */
67 
68 int doBoxcar()
69 {
70  float tfloat[MAX_CHANS];
71  struct LP_IMAGE_INFO *image = h0;
72 
73  /* If nbox != 0 then smooth the data */
74  if(env->nbox > 0)
75  {
76  st_report("Performing boxcar(%d) on array %s", env->nbox, image->name);
77 
78  bcopy((char *)&image->yplot1[0], (char *)&tfloat[0], image->head.noint * sizeof(float));
79 
80  boxcar(&tfloat[0], &image->yplot1[0], image->head.noint, env->nbox);
81  }
82  else
83  {
84  st_fail("nbox <= 0");
85  return(1);
86  }
87 
88  return(0);
89 }
90 
91 
92 void boxcar(input, output, len, order)
93 float *input, *output;
94 int len, order;
95 {
96  int i, j, left, right;
97  float box;
98 
99  for(i=0;i<len;i++)
100  {
101  box = 0.0;
102  left = ((i-order) < 0 ? 0 : i-order);
103  right = ((i+order) >= len ? len : i+order);
104 
105  for (j=left; j<right; j++)
106  {
107  box += input[j];
108  }
109  output[i] = box / (float)(right-left);
110  }
111 
112  return;
113 }
114 
115 
117 {
118  float tfloat[MAX_CHANS];
119  struct LP_IMAGE_INFO *image = h0;
120 
121  st_report("Performing hanning on array %s", image->name);
122 
123  bcopy((char *)&image->yplot1[0], (char *)&tfloat[0], image->head.noint * sizeof(float));
124 
125  hanning(&tfloat[0], &image->yplot1[0], image->head.noint);
126 
127  st_report("Dropping 2 channels off both ends");
128 
129  env->bdrop += 2;
130  env->edrop += 2;
131 
132  return(0);
133 }
134 
135 
136 int hanning(input, output, n)
137 float *input, *output;
138 int n;
139 {
140  int i, j, ib, ie, ic, nw;
141  double sum, twt;
142  float wgt[4];
143 
144  wgt[0] = 0.25;
145  wgt[1] = 0.50;
146  wgt[2] = 0.25;
147  nw = 3;
148 
149  ib = 0;
150  ie = n - (nw-1);
151  ic = nw / 2;
152 
153  st_report("Performing Hanning from %d to %d", ib, ie);
154 
155  for(i=ib;i<ie;i++)
156  {
157  sum = 0.0;
158  twt = 0.0;
159 
160  for(j=0;j<nw;j++)
161  {
162  sum += wgt[j] * input[i+j-1];
163  twt += wgt[j];
164  }
165 
166  if(twt > 0.0)
167  {
168  output[i+ic] = sum / twt;
169  }
170  else
171  {
172  output[i+ic] = GSL_POSINF;
173  }
174  }
175 
176  return(0);
177 }
178 
float yplot1[MAX_CHANS]
Definition: image.h:110
struct LP_IMAGE_INFO * h0
Definition: image.c:74
int doBoxcar()
Definition: box.c:68
int edrop
Definition: env.h:52
double noint
Definition: header.h:211
#define MAX_CHANS
Definition: defines.h:38
char name[32]
Definition: image.h:73
void boxcar(float *input, float *output, int len, int order)
Definition: box.c:92
struct ENVIRONMENT * env
Definition: linuxpops.c:71
double sum
Definition: beam.h:5
struct HEADER head
Definition: image.h:104
void st_fail()
int hanning(float *input, float *output, int n)
Definition: box.c:136
void st_report()
int bdrop
Definition: env.h:31
int nbox
Definition: env.h:79
int doHanning()
Definition: box.c:116