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