00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004
00005
00006 int errorprop (float *bTotal, float *bAzim, float *bInc, float *ebT, float *ebA, float *ebI,
00007 float *ebTbA, float *ebTbI, float *ebIbA,
00008 double lon, double lat, double lonc, double latc, double pAng, int nx, int ny, double x, double y,
00009 double *BtVariance, double *BpVariance, double *BrVariance) {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 static double raddeg = M_PI / 180.;
00037 double b, inc, azim;
00038 double a11, a12, a13, a21, a22, a23, a31, a32, a33;
00039 double dBrdBtotal, dBrdInc, dBrdAzim;
00040 double dBtdBtotal, dBtdInc, dBtdAzim;
00041 double dBpdBtotal, dBpdInc, dBpdAzim;
00042 double errBT, errINC, errAZ;
00043 double errBTINC, errBTAZ, errINCAZ;
00044 double BrSigma2, BtSigma2, BpSigma2;
00045 int ix, iy;
00046
00047 if (x < 1. || x >= (float)(nx-2) || y < 1. || y >= (float)(ny-2))
00048 return (1);
00049
00050 a11 = - sin(latc) * sin(pAng) * sin(lon - lonc) + cos(pAng) * cos(lon - lonc);
00051 a12 = sin(latc) * cos(pAng) * sin(lon - lonc) + sin(pAng) * cos(lon - lonc);
00052 a13 = -cos(latc) * sin(lon - lonc);
00053 a21 = -sin(lat) * (sin(latc) * sin(pAng) * cos(lon - lonc) + cos(pAng) * sin(lon - lonc))
00054 - cos(lat) * cos(latc) * sin(pAng);
00055 a22 = sin(lat) * (sin(latc) * cos(pAng) * cos(lon - lonc) - sin(pAng) * sin(lon - lonc))
00056 + cos(lat) * cos(latc) * cos(pAng);
00057 a23 = -cos(latc) * sin(lat) * cos(lon - lonc) + sin(latc) * cos(lat);
00058 a31 = cos(lat) * (sin(latc) * sin(pAng) * cos(lon - lonc) + cos(pAng) * sin(lon - lonc))
00059 - sin(lat) * cos(latc) * sin(pAng);
00060 a32 = -cos(lat) * (sin(latc) * cos(pAng) * cos(lon - lonc) - sin(pAng) * sin(lon - lonc))
00061 + sin(lat) * cos(latc) * cos(pAng);
00062 a33 = cos(lat) * cos(latc) * cos(lon - lonc) + sin(lat) * sin(latc);
00063
00064 ix = (int)x;
00065 iy = (int)y;
00066
00067 int iAll = iy * nx + ix;
00068
00069 if (isnan(bTotal[iAll])) return(1);
00070 b = bTotal[iAll];
00071 if (isnan(bInc[iAll])) return(1);
00072 inc = raddeg * bInc[iAll];
00073 if (isnan(bAzim[iAll])) return(1);
00074 azim = raddeg * bAzim[iAll];
00075 if (isnan(ebT[iAll])) return(1);
00076 errBT = ebT[iAll];
00077 if (isnan(ebI[iAll])) return(1);
00078 errINC = ebI[iAll];
00079 if (isnan(ebA[iAll])) return(1);
00080 errAZ = ebA[iAll];
00081 if (isnan(ebTbI[iAll])) return(1);
00082 errBTINC = ebTbI[iAll];
00083 if (isnan(ebTbA[iAll])) return(1);
00084 errBTAZ = ebTbA[iAll];
00085 if (isnan(ebIbA[iAll])) return(1);
00086 errINCAZ = ebIbA[iAll];
00087
00088
00089 dBpdBtotal = (- a11 * sin(inc) * sin(azim) + a12 * sin(inc) * cos(azim) + a13 * cos(inc));
00090 dBpdInc = b * (- a11 * cos(inc) * sin(azim) + a12 * cos(inc) * cos(azim) - a13 * sin(inc));
00091 dBpdAzim = b * (- a11 * sin(inc) * cos(azim) - a12 * sin(inc) * sin(azim));
00092
00093 dBtdBtotal = (- a21 * sin(inc) * sin(azim) + a22 * sin(inc) * cos(azim) + a23 * cos(inc));
00094 dBtdInc = b * (- a21 * cos(inc) * sin(azim) + a22 * cos(inc) * cos(azim) - a23 * sin(inc));
00095 dBtdAzim = b * (- a21 * sin(inc) * cos(azim) - a22 * sin(inc) * sin(azim));
00096
00097 dBrdBtotal = (- a31 * sin(inc) * sin(azim) + a32 * sin(inc) * cos(azim) + a33 * cos(inc));
00098 dBrdInc = b * (- a31 * cos(inc) * sin(azim) + a32 * cos(inc) * cos(azim) - a33 * sin(inc));
00099 dBrdAzim = b * (- a31 * sin(inc) * cos(azim) - a32 * sin(inc) * sin(azim));
00100
00101 BrSigma2 = 0.0;
00102 BtSigma2 = 0.0;
00103 BpSigma2 = 0.0;
00104
00105 BtSigma2 = BtSigma2 + dBtdBtotal * dBtdBtotal * errBT +
00106 dBtdInc * dBtdInc * errINC +
00107 dBtdAzim * dBtdAzim * errAZ +
00108 2.0 * dBtdBtotal * dBtdInc * errBTINC +
00109 2.0 * dBtdBtotal * dBtdAzim * errBTAZ +
00110 2.0 * dBtdInc * dBtdAzim * errINCAZ;
00111 BpSigma2 = BpSigma2 + dBpdBtotal * dBpdBtotal * errBT +
00112 dBpdInc * dBpdInc * errINC +
00113 dBpdAzim * dBpdAzim * errAZ +
00114 2.0 * dBpdBtotal * dBpdInc * errBTINC +
00115 2.0 * dBpdBtotal * dBpdAzim * errBTAZ +
00116 2.0 * dBpdInc * dBpdAzim * errINCAZ;
00117 BrSigma2 = BrSigma2 + dBrdBtotal * dBrdBtotal * errBT +
00118 dBrdInc * dBrdInc * errINC +
00119 dBrdAzim * dBrdAzim * errAZ +
00120 2.0 * dBrdBtotal * dBrdInc * errBTINC +
00121 2.0 * dBrdBtotal * dBrdAzim * errBTAZ +
00122 2.0 * dBrdInc * dBrdAzim * errINCAZ;
00123
00124 *BrVariance = BrSigma2;
00125 *BtVariance = BtSigma2;
00126 *BpVariance = BpSigma2;
00127
00128 return 0;
00129 }
00130
00131
00132