61 #define NUM_OF_BCHANNEL_FOR_POLY 10
105 int a, l, j, k, n, foundone=0;
188 st_report(
"computeEachBaseLine(): Average values for Baseline Region: %d, %f", l,
bl_averages[l]);
207 float a, b, siga1, sigb1, chi2_1, q1;
211 bzero((
char *)&x,
sizeof(x));
212 bzero((
char *)&sig,
sizeof(sig));
213 bzero((
char *)&lsqArray,
sizeof(lsqArray));
246 st_fail(
"No baseline regions defined");
266 sptip_lsqfit(x, lsqArray, 0, k, sig, 0, &b, &a, &sigb1, &siga1, &chi2_1, &q1);
272 image->binfo.rms = r;
276 image->binfo.a = 0.0;
277 image->binfo.b = 0.0;
278 image->binfo.rms = 100.0;
281 env->
rms = image->binfo.rms;
294 int i, ret,
first = 1;
303 if(image->binfo.doBaseLine)
307 st_report(
"Removing Baselines from %s", image->name);
313 st_report(
"Slope %f, Intercept %f", image->binfo.a, image->binfo.b);
316 f = &image->yplot1[0];
317 for(i=0;i<image->head.noint;i++,f++)
324 *f = *f - ((float)i * image->binfo.a + image->binfo.b);
348 if(chan >=
env->
baselines[i][0] && chan <= env->baselines[i][1])
385 int i, n, c1 = 0, c2 = 0;
386 int base, noint, old_bmark;
407 st_report(
"Setting NBase to %.3f %.3f", arg1, arg2);
416 st_report(
"X increasing, args decreaing");
441 st_report(
"X increasing, args increasing");
479 st_fail(
"Error in Translating Channels: %d %d", c1, c2);
490 st_report(
"X decreasing, args decreaing");
515 st_report(
"X decreasing, args increasing");
552 st_fail(
"Error in Translating Channels: %d %d", c1, c2);
566 bzero((
char *)&vals[0],
sizeof(vals));
570 sprintf(hint,
"Click Left Mouse Button on %s Edge of Segment %d", !(i%2) ?
"Left" :
"Right", j+1);
618 bcopy((
char *)&
env->
baselines[0][0], (
char *)&bl[0][0],
sizeof(bl));
620 bzero((
char *)&avgs[0],
sizeof(avgs));
626 if(bl[i][0] > bl[i][1])
628 st_report(
"Flipping baseline order for Segment %d", i+1);
636 avgs[i] = (bl[i][0] + bl[i][1]) / 2;
685 int i, j, n,
new, ret, base, k=0;
713 sprintf(hint,
"Click Left Mouse Button on %s Edge of Segment %d", !(i%2) ?
"Left" :
"Right",
new+1);
753 sprintf(hint,
"Click Left Mouse Button Somewhere in Segment to Remove");
767 if(now >=
env->
baselines[i][0] && now <= env->baselines[i][1])
785 int i, n, base, j=0, k=0, ret, old_bmark;
791 st_report(
"Clearing out baselines segments");
823 sprintf(hint,
"Enter Number of Baseline Regions [ Up to %d]: ",
MAX_BASELINES);
851 st_print(
"Clearing out defined baseline regions\n");
863 sprintf(hint,
"Click Left Mouse Button on %s Edge of Segment %d", !(i%2) ?
"Left" :
"Right", j+1);
925 st_fail(
"Can't set baseline channel of < 0");
955 if(image->binfo.baselines[i][0] == 0 && image->binfo.baselines[i][1] == 0)
980 f = &image->
bplot[indx];
981 for(i=indx;i>=n;i--,f--)
1007 f = &image->bplot[indx];
1008 for(i=indx;i<n;i++,f++)
1025 int b, n, b1, b2, n1, n2, i, j, k;
1026 int lgIndx, nxIndx, idiff, noint;
1027 int lastbl = 0,
recording=0, start, end;
1028 char nstr[80], bname[256];
1029 float lg, ng, diff, unit;
1030 float lastGoodVal, firstGoodVal;
1037 bzero((
char *)xd,
sizeof(xd));
1038 bzero((
char *)yd,
sizeof(yd));
1039 bzero((
char *)coeff,
sizeof(coeff));
1040 bzero((
char *)image->
bplot,
sizeof(image->
bplot));
1044 st_fail(
"No baseline regions defined");
1050 st_fail(
"Error: nbshape must be greater than 1");
1085 st_report(
"Performing Linear Smoothing between Baseline Regions");
1087 for(i=0;i<noint;i++)
1091 if(image->
bplot[i] == 0.0)
1094 image->
bplot[i] = ng;
1100 if(image->
bplot[i] == 0.0)
1103 image->
bplot[i] = lg;
1107 if(image->
bplot[i] == 0.0)
1113 idiff = lgIndx - nxIndx;
1117 unit = diff / (float)idiff;
1122 st_report(
"Last good = %4d, %f", lgIndx, lg);
1123 st_report(
"Next good = %4d, %f", nxIndx, ng);
1128 image->
bplot[i] = lg + unit * (double)(i-lgIndx);
1144 case 1: strcpy(nstr,
"st");
break;
1145 case 2: strcpy(nstr,
"nd");
break;
1146 case 3: strcpy(nstr,
"rd");
break;
1153 st_report(
"Performing %d%s Order Polynomial Smoothing between Baseline Regions",
env->
nfit, nstr);
1168 sprintf(bname,
"bline-poly-%02d.dat", i);
1170 if((fp = fopen(bname,
"w")) == NULL)
1172 st_fail(
"Unable to open %s", bname);
1177 bzero((
char *)xd,
sizeof(xd));
1178 bzero((
char *)yd,
sizeof(yd));
1179 bzero((
char *)coeff,
sizeof(coeff));
1183 st_report(
"Interp between region %2d & %2d; %4d[%4d] to %4d[%4d]", i, i+1, b1, n1, b2, n2);
1194 for(k=start;k<end;k++)
1196 xd[j] = image->
x1data[k];
1197 yd[j] = image->
bplot[k];
1204 for(k=start;k<end;k++)
1206 xd[j] = image->
x1data[k];
1207 yd[j] = image->
bplot[k];
1217 for(k=start;k<end;k++)
1219 xd[j] = image->
x1data[k];
1220 yd[j] = image->
bplot[k];
1227 for(k=start;k<end;k++)
1229 xd[j] = image->
x1data[k];
1230 yd[j] = image->
bplot[k];
1240 for(k=start;k<end;k++)
1242 xd[j] = image->
x1data[k];
1243 yd[j] = image->
bplot[k];
1250 for(k=start;k<end;k++)
1252 xd[j] = image->
x1data[k];
1253 yd[j] = image->
bplot[k];
1259 for(k=b1;k<(b1+n1);k++)
1261 xd[j] = image->
x1data[k];
1262 yd[j] = image->
bplot[k];
1266 for(k=b2;k<(b2+n2);k++)
1268 xd[j] = image->
x1data[k];
1269 yd[j] = image->
bplot[k];
1276 st_fail(
"Not enought Baseline channels set for this region");
1286 st_report(
"%02d: Filling in channels %d to %d", i, b1+n1, b2);
1289 for(k=(b1+n1-1);k<(b2+1);k++)
1296 for(k=b1;k<(b2+n2);k++)
1305 if(i == 0 && b1 > 0)
1309 st_report(
"Poly-Filling in leading channels %d to %d", 0, b1);
1313 for(k=b1;k<b1+n1;k++)
1315 xd[j] = image->
x1data[k];
1316 yd[j] = image->
bplot[k];
1331 st_report(
"Linear-Filling in leading channels %d to %d", 0, b1);
1333 firstGoodVal = image->
bplot[b1];
1338 image->
bplot[k] = firstGoodVal;
1345 st_report(
"%02d: Filled in %d leading channels", i, j);
1351 if((i+1) == lastbl && (b2+n2) < noint)
1353 lastGoodVal = image->
bplot[b2+n2-1];
1357 st_report(
"Poly-Filling in trailing channels %d to %d", b2+n2, noint);
1361 for(k=b2;k<b2+n2;k++)
1363 xd[j] = image->
x1data[k];
1364 yd[j] = image->
bplot[k];
1371 for(k=b2+n2;k<noint;k++)
1379 st_report(
"Filled in %d trailing channels", j);
1384 st_report(
"Linear-Filling in trailing channels %d to %d", b2+n2, noint);
1387 for(k=b2+n2;k<noint;k++)
1389 image->
bplot[k] = lastGoodVal;
1396 st_report(
"Filled in %d trailing channels", j);
1407 st_report(
"Skipping short baseline region %d: n1 = %d, n2 = %d", i, n1, n2);
1421 st_report(
"Saving baseline model in H8");
1422 bcopy((
char *)image, (
char *)b8image,
sizeof(
struct LP_IMAGE_INFO));
1424 strcpy(b8image->
name,
"H8");
1435 st_report(
"Saving smoothed baseline model in H9");
1436 bcopy((
char *)image, (
char *)b9image,
sizeof(
struct LP_IMAGE_INFO));
1438 strcpy(b9image->
name,
"H9");
1448 int i, j, k, n, foundone = 0;
1459 bzero((
char *)xd,
sizeof(xd));
1460 bzero((
char *)yd,
sizeof(yd));
1461 bzero((
char *)coeff,
sizeof(coeff));
1473 st_report(
"do_contGraceFit(): IF: %d contains %d records", j, n);
1478 for(i=0;i<n;i++,p++)
1495 st_report(
"do_contGraceFit(): Average for IF: (%d):, %f", j, avg);
1498 for(i=0;i<n;i++,f++)
1516 st_fail(
"do_contGraceFit(): No data to fit");
1533 st_report(
"do_contGraceFit(): IF: %d contains %d records", j, n);
1537 for(i=0;i<n;i++,p++)
1544 default: xd[i] = (double)i;
break;
1573 st_print(
"a%d = %.4e ", k, coeff[k]);
1584 for(i=0;i<n;i++,f++,p++)
1627 st_fail(
"do_contGraceFit(): No data to fit");
1654 bzero((
char *)xd,
sizeof(xd));
1655 bzero((
char *)yd,
sizeof(yd));
1656 bzero((
char *)coeff,
sizeof(coeff));
1689 st_fail(
"No baseline regions set");
1706 xd[j] = image->
x1data[i];
1707 yd[j] = image->
yplot1[i];
1714 st_fail(
"Not enought Baseline channels set");
1742 st_report(
"Removing Computed Baseline from: %s", image->
name);
1769 int i, ret, seg=0, now, then,
min = 999999, mindx = -1;
1773 sprintf(hint,
"Click Left Mouse Button on Edge of Segment to move");
1783 sprintf(hint,
"Click Left Mouse Button in New Location");
1823 if(seg >= 0 && seg < MAX_BASELINES)
1825 if(mindx == 0 || mindx == 1)
1828 st_report(
"Moving Segment %d edge from channel %d to %d", seg+1, now, then);
1846 st_fail(
"Seg: %d or index: %d; out of range", seg, mindx);
1881 int seg, start, end;
1898 st_report(
"Setting Seg %2d: %4d %4d", seg, start, end);
1905 st_fail(
"Baseline Segment %d, out of range", seg);
1926 st_fail(
"Usage: writebase filename");
1937 fprintf(fp,
"nbaseset /c\n");
1983 st_fail(
"No baseline regions defined");
struct LP_IMAGE_INFO * h0
struct PARSE_STACK * args
struct ACCUM_RESULTS_SEND accum_results_send
int computeEachBaseLine(struct LP_IMAGE_INFO *image)
struct BASELINE_INFO binfo
int line_doBaseLine(struct LP_IMAGE_INFO *image)
int baselinesDefined(struct LP_IMAGE_INFO *image)
#define VERBOSE_BASELINES
int printH_FlagHelp(char *cmd)
#define ACCUM_PLOT_Y_TSYS
void boxcar(float *input, float *output, int len, int order)
int computeBaseLine(struct LP_IMAGE_INFO *image)
struct PARSE_FLAGS pflags[MAX_PARSE_FLAGS]
#define LINEAR_BASELINE_SMOOTHING
struct ACCUM_RESULTS ar[MAX_IFS]
#define ACCUM_PLOT_Y_SMROR
int computeRms(float *y, int n, float *rms)
#define NUM_OF_BCHANNEL_FOR_POLY
int findNextGood(struct LP_IMAGE_INFO *image, int indx, int *ngn, float *ng)
int copyEnv2Image(struct LP_IMAGE_INFO *image)
int fitcurve(double *x, double *y, int n, int ideg, double *coeff)
int sptip_lsqfit(float x[], float y[], int bdata, int edata, float sig[], int mwt, float *a, float *b, float *siga, float *sigb, float *chi2, float *q)
double leasev(double *c, int degree, double x)
int addOneOrMoreSegment()
struct ACCUM_SCAN_RESULT results[MAX_ACCUM_SCANS]
double bl_averages[MAX_BASELINES]
#define ACCUM_PLOT_X_SCAN
int isInBaseLineRegion(int chan)
#define ACCUM_PLOT_Y_TASTAR
int parseMouseValues(double x1, double x2, double y1, double y2)
#define POLY_BASELINE_SMOOTHING
int baselines[MAX_BASELINES][2]
float fitcurve[MAX_IFS][MAX_ACCUM_SCANS]
#define ACCUM_PLOT_Y_NORMAL
int baselines[MAX_BASELINES][2]
double coeff[MAX_IFS][MAX_NFIT]
int removeFittedData(struct LP_IMAGE_INFO *image)
int findLastGood(struct LP_IMAGE_INFO *image, int indx, int *lgn, float *lg)
#define ACCUM_PLOT_Y_JANSKY