00001
00002
00003
00004 #include <math.h>
00005 #include <sys/time.h>
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <time.h>
00009 #include "jsoc_main.h"
00010 #include "imagefromchebyshev.c"
00011
00012
00013
00014
00015
00016 #define kMaskInquery "hmi.lookup_ChebyCoef_BNoise"
00017
00018 int noisemaskimag4twindow(xDim, yDim, xcen, ycen, rsun, vrcenter, maskid, image, maskQuery)
00019 double *image;
00020 int xDim, yDim, maskid;
00021 float xcen, ycen, rsun;
00022 float vrcenter;
00023 char *maskQuery;
00024 {
00025 CmdParams_t *params = &cmdparams;
00026 int valid, status = 0;
00027 DRMS_Segment_t *inSeg, *inSegfinal, *outSeg;
00028 DRMS_RecordSet_t *inRS, *inRSfinal, *outRS;
00029 DRMS_Record_t *inRec, *inRecfinal, *outRec;
00030 DRMS_Array_t *inArray, *outArray;
00031 char *inQuery=kMaskInquery, *outQuery;
00032 char *inRecQuery, *outRecQuery;
00033 char *inQueryfinal, *vr_start_str, *vr_stop_str, *maskid_str;
00034 char ttemp[64];
00035 int vr_start, vr_stop, order, vr_coef;
00036 float weight;
00037 double *coef, *mask, xc_shift, yc_shift;
00038 int i, j, t, s, nrecs, ii, jj, k;
00039 int sunSize = (int)(2 * (rsun+1));
00040
00041 vr_start = (int)(vrcenter - 50.0);
00042 vr_stop = (int)(vrcenter + 50.0);
00043 inQueryfinal = (char *)malloc(100 * sizeof(char));
00044 vr_start_str = (char *)malloc(100 * sizeof(char));
00045 vr_stop_str = (char *)malloc(100 * sizeof(char));
00046 maskid_str = (char *)malloc(100 * sizeof(char));
00047 mask = (double *)malloc(sunSize * sunSize * sizeof(double));
00048
00049 sprintf(vr_start_str, "%d", vr_start);
00050 sprintf(vr_stop_str, "%d", vr_stop);
00051 sprintf(maskid_str, "%d", maskid);
00052 sprintf(inQueryfinal, "%s[%s-%s][%s]", inQuery, vr_start_str, vr_stop_str, maskid_str);
00053 sprintf(maskQuery, "%s", inQueryfinal);
00054 printf("%s\n", inQueryfinal);
00055
00056 inRSfinal = drms_open_records(drms_env, inQueryfinal, &status);
00057 if (status || inRSfinal->n == 0) {printf("No input data found\n"); return (status ? status : -1);};
00058 nrecs = inRSfinal->n;
00059
00060 inRecfinal = inRSfinal->records[0];
00061 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00062 inArray = drms_segment_read(inSeg, DRMS_TYPE_DOUBLE, &status);
00063 order = inArray->axis[0];
00064 coef = (double *)malloc(order * order * sizeof(double));
00065
00066 for (i = 0; i < order; i++)
00067 for (j = 0; j < order; j++) {
00068 coef[i * order + j] = 0;
00069 }
00070
00071 if (nrecs == 1)
00072 {
00073 inRecfinal = inRSfinal->records[0];
00074 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00075 inArray = drms_segment_read(inSeg, DRMS_TYPE_DOUBLE, &status);
00076 if (status)
00077 {
00078 printf(" No data file found, status=%d\n", status);
00079 drms_free_array(inArray); return (status ? status : -1);
00080 }
00081 double *inData = (double *)inArray->data;
00082
00083 for (jj = 0; jj < order; jj++)
00084 {
00085 for (ii = 0; ii < order; ii++)
00086 {
00087 coef[jj * order + ii] = inData[jj * order + ii];
00088 }
00089 }
00090 }
00091
00092 if (nrecs >= 2)
00093 {
00094 for (i = 0; i < 2; i++)
00095 {
00096 inRecfinal = inRSfinal->records[i];
00097 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00098 inArray = drms_segment_read(inSeg, DRMS_TYPE_DOUBLE, &status);
00099 if (status)
00100 {
00101 printf(" No data file found, status=%d\n", status);
00102 drms_free_array(inArray);
00103 continue;
00104 }
00105 vr_coef = drms_getkey_int(inRecfinal, "VRCENT", &status);
00106 weight = 1.0 - fabs((float)(vr_coef) - vrcenter)/50.0;
00107 double *inData = (double *)inArray->data;
00108 for (jj = 0; jj < order; jj++)
00109 {
00110 for (ii = 0; ii < order; ii++)
00111 {
00112 coef[jj * order + ii] += weight * inData[jj * order + ii];
00113 }
00114 }
00115 }
00116 }
00117
00118 xc_shift = (double)xcen - (int)xcen;
00119 yc_shift = (double)ycen - (int)ycen;
00120
00121 imagefromchebyshev(mask, sunSize, sunSize, order, coef, xc_shift, yc_shift);
00122 printf("xc-shift = %f, yc-shift = %f\n", xc_shift, yc_shift);
00123
00124
00125
00126 double yDist, xDist, yDist2, xDist2, xDist2PlusyDist2, dToDiskCenter;
00127 int jy = 0, yOff, iData, yOffmask, iMask, xdelta, ydelta;
00128 for (jy = 0; jy < yDim; jy++)
00129 {
00130 int ix = 0;
00131 yDist = (double)jy - ycen;
00132 yDist2 = yDist * yDist;
00133 yOff = jy * xDim;
00134 ydelta = 0;
00135 if (jy >= ycen-rsun & jy <= ycen+rsun) ydelta = jy - (ycen-rsun);
00136 yOffmask = ydelta * sunSize;
00137 for (ix = 0; ix < xDim; ix++)
00138 {
00139 iData = yOff + ix;
00140 iMask = 0;
00141 if (ix >= xcen-rsun & ix <= xcen+rsun) iMask = yOffmask + ix - (xcen-rsun);
00142 xDist = (double)ix - xcen;
00143 xDist2 = xDist * xDist;
00144 xDist2PlusyDist2 = xDist2 + yDist2;
00145 dToDiskCenter = sqrt(xDist2PlusyDist2);
00146 if (dToDiskCenter >= rsun || iMask >= sunSize * sunSize)
00147 {
00148 image[iData] = DRMS_MISSING_DOUBLE;
00149 continue;
00150 }
00151 image[iData] = mask[iMask];
00152 }
00153 }
00154
00155 free(inQueryfinal); free(vr_start_str); free(vr_stop_str);
00156 free(coef); free(mask);
00157 drms_free_array(inArray);
00158 drms_close_records(inRSfinal, DRMS_FREE_RECORD);
00159 return 0;
00160 }
00161
00162