| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2009 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
|
| 27 |
.VERSION |
| 28 |
|
| 29 |
090420 last modif |
| 30 |
===========================================================================*/ |
| 31 |
|
| 32 |
|
| 33 |
#include <stdio.h> |
| 34 |
#include <math.h> |
| 35 |
|
| 36 |
int mean_filter(ina,len,width,outa) |
| 37 |
float *ina, *outa; |
| 38 |
int len,width; |
| 39 |
|
| 40 |
{ |
| 41 |
double sum; |
| 42 |
int midpt,i,j,k,endpt; |
| 43 |
midpt = width/2; |
| 44 |
endpt = len - midpt; |
| 45 |
sum =0.0; |
| 46 |
for(i=0;i < width ; i ++) |
| 47 |
sum += ina[i]; |
| 48 |
for(i=0,k=width,j=midpt; j <endpt; j++,i++,k++) |
| 49 |
{ |
| 50 |
outa[j] = sum / width; |
| 51 |
sum += ina[k] - ina[i]; |
| 52 |
} |
| 53 |
for(i=0;i<midpt ; i++) |
| 54 |
{ |
| 55 |
outa[i] = outa[midpt]; |
| 56 |
outa[len - i - 1] = outa[len- midpt - 1]; |
| 57 |
} |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |
| 61 |
|
| 62 |
int median_filter(ina,len,width,outa) |
| 63 |
float *ina, *outa; |
| 64 |
int len,width; |
| 65 |
|
| 66 |
{ |
| 67 |
float xxx[1000]; |
| 68 |
float xmed; |
| 69 |
int midpt,i,j,k,endpt,ii; |
| 70 |
|
| 71 |
void mdian1(); |
| 72 |
|
| 73 |
|
| 74 |
midpt = width/2; |
| 75 |
endpt = len - midpt; |
| 76 |
for(i=0,k=width,j=midpt; j <endpt; j++,i++,k++) |
| 77 |
{ |
| 78 |
for(ii=0;ii<width;ii++) |
| 79 |
xxx[ii+1] = ina[i+ii]; |
| 80 |
/*mdian3(ina,i,k-1,&xmed);*/ |
| 81 |
mdian1(xxx,width,&xmed); |
| 82 |
outa[j] = xmed; |
| 83 |
} |
| 84 |
for(i=0;i<midpt ; i++) |
| 85 |
{ |
| 86 |
outa[i] = outa[midpt]; |
| 87 |
outa[len - i - 1] = outa[len- midpt - 1]; |
| 88 |
} |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
int rebin(opt,xin,xout,yin,yout,n,Z,Xmin,Xmax,Ymin,Ymax) |
| 94 |
int opt,n; |
| 95 |
float *xin,*xout,*yin,*yout,Z,*Xmin,*Xmax,*Ymin,*Ymax; |
| 96 |
|
| 97 |
{ |
| 98 |
int i,istart=0; |
| 99 |
float xstep,splint(),auxval; |
| 100 |
switch(opt) |
| 101 |
{ |
| 102 |
case 1: |
| 103 |
for(i=0;i<n;i++) |
| 104 |
xin[i] = xin[i]/(1+Z); |
| 105 |
break; |
| 106 |
case 2: |
| 107 |
for(i=0;i<n;i++) |
| 108 |
xin[i] = log(xin[i]); |
| 109 |
break; |
| 110 |
case 3: |
| 111 |
for(i=0;i<n;i++) |
| 112 |
xin[i] = 1/xin[i]; |
| 113 |
break; |
| 114 |
} |
| 115 |
if(xin[0] < xin[n-1]) |
| 116 |
{ |
| 117 |
xstep = (xin[n-1] -xin[0]) / n; |
| 118 |
xout[0] = xin[0]; |
| 119 |
} |
| 120 |
else |
| 121 |
{ |
| 122 |
xstep = (xin[0] -xin[n-1]) / n; |
| 123 |
xout[0] = xin[n-1]; |
| 124 |
for(i=0;i< n/2 ; i++) |
| 125 |
{ |
| 126 |
auxval = xin[i]; |
| 127 |
xin[i] = xin[n-i-1]; |
| 128 |
xin[n-i-1]=auxval; |
| 129 |
auxval =yin[i]; |
| 130 |
yin[i] =yin[n-i-1]; |
| 131 |
yin[n-i-1]=auxval; |
| 132 |
} |
| 133 |
} |
| 134 |
for(i=1; i< n ; i++) |
| 135 |
xout[i] = xout[i-1]+xstep; |
| 136 |
*Xmin = xout[0]; |
| 137 |
*Xmax = xout[n-1]; |
| 138 |
yout[0] = yin[0]; |
| 139 |
*Ymin = yout[0]; |
| 140 |
*Ymax = yout[0]; |
| 141 |
for(i=1; i< n-1 ; i++) |
| 142 |
{ |
| 143 |
yout[i] = splint(xout[i],xin,yin,n,&istart); |
| 144 |
if(yout[i] < *Ymin) *Ymin = yout[i]; |
| 145 |
if(yout[i] > *Ymax) *Ymax = yout[i]; |
| 146 |
} |
| 147 |
yout[n-1] = yin[n-1]; |
| 148 |
|
| 149 |
return 0; |
| 150 |
} |