00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdlib.h>
00031 #include <math.h>
00032 #include "projection.h"
00033
00034 #define VERSION_NUM (0.9)
00035
00036 #define PI (M_PI)
00037
00038 char *cvsinfo_apodize = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/libs/projection/apodize.c,v 1.1 2013/04/28 07:46:05 tplarson Exp $";
00039
00040
00041
00042 int apodize(float *data,
00043 double b0,
00044 int cols, int rows,
00045 double Lmin,
00046 double Ldelta,
00047 double sinBdelta,
00048 int apodlevel,
00049
00050
00051
00052 double apinner,
00053 double apwidth,
00054 int apel,
00055
00056 double apx,
00057
00058 double apy)
00059
00060 {
00061 int row, col, i;
00062 double weight;
00063 float *dp;
00064 double sinBbase;
00065 double sinB0, cosB0;
00066 double sinB, cosB;
00067 double L;
00068 double apouter,apinx,apoutx,ss,cc,sc,cs;
00069 double x, y, r, cosrho, apod, apx2, apy2;
00070 double *savecosL, *savesinL;
00071
00072 if (apodlevel == 0) return kLIBPROJECTION_Success;
00073
00074 if (apodlevel > 2) return kLIBPROJECTION_InconsistentConstraints;
00075
00076 if (apodlevel == 2) b0=0.0;
00077
00078 apouter=apinner+apwidth;
00079
00080 sinBbase=0.5-rows/2;
00081 sinB0=sin(b0);
00082 cosB0=cos(b0);
00083 apinx=sqrt(1.-apinner*apinner);
00084 apoutx=sqrt(1.-apouter*apouter);
00085 apx2=1.0/apx/apx;
00086 apy2=1.0/apy/apy;
00087
00088
00089 savecosL=(double *)(malloc(cols*sizeof(double)));
00090 savesinL=(double *)(malloc(cols*sizeof(double)));
00091 for (col=0; col<cols; col++) {
00092 L=Ldelta*col+Lmin;
00093 savecosL[col]=cos(L);
00094 savesinL[col]=sin(L);
00095 }
00096
00097 for (row = 0; row < rows; row++) {
00098 sinB=sinBdelta*(sinBbase + row);
00099 cosB=sqrt(1.0-sinB*sinB);
00100 ss=sinB0*sinB;
00101 cc=cosB0*cosB;
00102 sc=sinB0*cosB;
00103 cs=cosB0*sinB;
00104 dp=data+row*cols;
00105 if (apel == 0) {
00106 for (col=0; col<cols; col++) {
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 cosrho=ss+cc*savecosL[col];
00122 if (cosrho > apinx) {}
00123 else if (cosrho > apoutx) {
00124 dp[col]*=(0.5+0.5*cos(PI*(sqrt(1.0-cosrho*cosrho)-apinner)/apwidth));
00125 }
00126 else
00127 dp[col]=0.0;
00128 }
00129 }
00130 else {
00131
00132 for (col=0; col<cols; col++) {
00133 x=cosB*savesinL[col];
00134 y=cs-sc*savecosL[col];
00135 r=sqrt(apx2*x*x+apy2*y*y);
00136 if (r < apinner) {}
00137 else if (r < apouter)
00138 dp[col]*=0.5+0.5*cos(PI*(r-apinner)/apwidth);
00139 else
00140 dp[col]=0.0;
00141 }
00142 }
00143 }
00144
00145 free(savesinL);
00146 free(savecosL);
00147
00148 return kLIBPROJECTION_Success;
00149 }