00001
00002
00003
00004 #include <math.h>
00005 #include <sys/time.h>
00006
00007
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <time.h>
00011 #include "jsoc_main.h"
00012 #include "imagefromchebyshev.c"
00013
00014
00015 #define kRecSetIn "in"
00016 #define kSeriesOut "out"
00017 #define kSegIn "segin"
00018 #define kSegOut "segout"
00019 #define kNOTSPECIFIED "not specified"
00020
00021 int noisemask(tobs, xDim, yDim, xcen, ycen, rsun, vrcenter, image, maskQuery)
00022 double *image;
00023 int xDim, yDim;
00024 float xcen, ycen, rsun;
00025 float vrcenter;
00026 TIME tobs;
00027 char *maskQuery;
00028 {
00029 CmdParams_t *params = &cmdparams;
00030 int valid, status = 0;
00031 DRMS_Segment_t *inSeg, *inSegfinal, *outSeg;
00032 DRMS_RecordSet_t *inRS, *inRSfinal, *outRS;
00033 DRMS_Record_t *inRec, *inRecfinal, *outRec;
00034 DRMS_Array_t *inArray, *outArray;
00035
00036 char *inQuery="hmi.lookup_ChebyCoef_BNoise", *outQuery;
00037 char *inRecQuery, *outRecQuery;
00038 char *inQueryfinal, *vr_start_str, *vr_stop_str;
00039 char ttemp[64];
00040 TIME ChangeTime1, ChangeTime2, ChangeTime3;
00041 int MaskIndex = 0;
00042 int vr_start, vr_stop, order = 15;
00043 float vr_coef, weight;
00044 double *coef, *mask, xc_shift, yc_shift;
00045 int i, j, t, s, nrecs, ii, jj, k;
00046 int sunSize = (int)(2 * (rsun+1));
00047 int ncoef;
00048
00049 strcpy(ttemp, "2010.12.13_19:47:00_TAI");
00050 ChangeTime1 = sscan_time(ttemp);
00051
00052 strcpy(ttemp, "2011.07.13_18:35:00_TAI");
00053 ChangeTime2 = sscan_time(ttemp);
00054
00055 strcpy(ttemp, "2012.01.18_18:15:00_TAI");
00056 ChangeTime3 = sscan_time(ttemp);
00057
00058 if (tobs<ChangeTime1) MaskIndex = 0;
00059 if (tobs>ChangeTime1 && tobs<ChangeTime2) MaskIndex = 1;
00060 if (tobs>ChangeTime2 && tobs<ChangeTime3) MaskIndex = 2;
00061 if (tobs>ChangeTime3) MaskIndex = 3;
00062
00063 vr_start = (int)(vrcenter - 50.0);
00064 vr_stop = (int)(vrcenter + 50.0);
00065 inQueryfinal = (char *)malloc(100 * sizeof(char));
00066 vr_start_str = (char *)malloc(100 * sizeof(char));
00067 vr_stop_str = (char *)malloc(100 * sizeof(char));
00068 mask = (double *)malloc(sunSize * sunSize * sizeof(double));
00069
00070 coef = (double *)malloc(order * order * sizeof(double));
00071 for (i = 0; i < order; i++)
00072 for (j = 0; j < order; j++) {
00073 coef[i * order + j] = 0;
00074 }
00075
00076 inRS = drms_open_records(drms_env, inQuery, &status);
00077 if (status || inRS->n == 0) {printf("No input data found\n"); return (status ? status : -1);};
00078 inRec = inRS->records[0];
00079
00080 sprintf(vr_start_str, "%d", vr_start);
00081 sprintf(vr_stop_str, "%d", vr_stop);
00082 sprintf(inQueryfinal, "%s[%s-%s][%d]", inRec->seriesinfo->seriesname, vr_start_str, vr_stop_str, MaskIndex);
00083 sprintf(maskQuery, "%s", inQueryfinal);
00084 printf("%s\n", inQueryfinal);
00085 drms_close_records(inRS, DRMS_FREE_RECORD);
00086
00087 inRSfinal = drms_open_records(drms_env, inQueryfinal, &status);
00088 if (status || inRSfinal->n == 0) {printf("No input data found\n"); return (status ? status : -1);};
00089 nrecs = inRSfinal->n;
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 if (nrecs == 1)
00104 {
00105 inRecfinal = inRSfinal->records[0];
00106 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00107 inArray = drms_segment_read(inSeg, DRMS_TYPE_DOUBLE, &status);
00108 if (status)
00109 {
00110 drms_free_array(inArray);
00111 printf("No data array found\n"); return (status ? status : -1);
00112 }
00113 double *inData = (double *)inArray->data;
00114
00115 for (jj = 0; jj < order; jj++)
00116 {
00117 for (ii = 0; ii < order; ii++)
00118 {
00119 coef[jj * order + ii] = inData[jj * order + ii];
00120 }
00121 }
00122 }
00123
00124 if (nrecs >= 2)
00125 {
00126 ncoef = 0;
00127 for (i = 0; i < 2; i++)
00128 {
00129 inRecfinal = inRSfinal->records[i];
00130 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00131 inArray = drms_segment_read(inSeg, DRMS_TYPE_DOUBLE, &status);
00132 if (status)
00133 {
00134 printf(" No input data array found, status=%d\n", status);
00135 drms_free_array(inArray);
00136 ncoef += 1;
00137 continue;
00138 }
00139 vr_coef = drms_getkey_float(inRecfinal, "VRCENT", &status);
00140 weight = 1.0 - fabs(vr_coef - vrcenter)/50.0;
00141 double *inData = (double *)inArray->data;
00142 for (jj = 0; jj < order; jj++)
00143 {
00144 for (ii = 0; ii < order; ii++)
00145 {
00146 coef[jj * order + ii] += weight * inData[jj * order + ii];
00147 }
00148 }
00149 }
00150 if (ncoef == 1)
00151 {
00152 for (jj = 0; jj < order; jj++)
00153 {
00154 for (ii = 0; ii < order; ii++)
00155 {
00156 coef[jj * order + ii] /= weight;
00157 }
00158 }
00159 }
00160
00161 if (ncoef == 2) {printf("No input data array found\n"); return (-1);}
00162 }
00163
00164 xc_shift = (double)xcen - (int)xcen;
00165 yc_shift = (double)ycen - (int)ycen;
00166 imagefromchebyshev(mask, sunSize, sunSize, order, coef, xc_shift, yc_shift);
00167
00168
00169
00170 double yDist, xDist, yDist2, xDist2, xDist2PlusyDist2, dToDiskCenter;
00171 int jy, yOff, iData, yOffmask, iMask, xdelta, ydelta;
00172 for (jy = 0; jy < yDim; jy++)
00173 {
00174 int ix = 0;
00175 yDist = (double)jy - ycen;
00176 yDist2 = yDist * yDist;
00177 yOff = jy * xDim;
00178 ydelta = 0;
00179 if (jy >= ycen-rsun & jy <= ycen+rsun) ydelta = jy - (ycen-rsun);
00180 yOffmask = ydelta * sunSize;
00181 for (ix = 0; ix < xDim; ix++)
00182 {
00183 iData = yOff + ix;
00184 iMask = 0;
00185 if (ix >= xcen-rsun & ix <= xcen+rsun) iMask = yOffmask + ix - (xcen-rsun);
00186 xDist = (double)ix - xcen;
00187 xDist2 = xDist * xDist;
00188 xDist2PlusyDist2 = xDist2 + yDist2;
00189 dToDiskCenter = sqrt(xDist2PlusyDist2);
00190 if (dToDiskCenter >= rsun || iMask >= sunSize * sunSize)
00191 {
00192 image[iData] = DRMS_MISSING_DOUBLE;
00193 continue;
00194 }
00195 image[iData] = mask[iMask];
00196 }
00197 }
00198
00199
00200
00201 free(inQueryfinal); free(vr_start_str); free(vr_stop_str); free(mask);
00202
00203 return 0;
00204 }
00205
00206