00001
00007
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <time.h>
00011 #include "jsoc_main.h"
00012 #include <mkl_blas.h>
00013 #include <mkl_service.h>
00014 #include <mkl_lapack.h>
00015 #include <mkl_vml_functions.h>
00016 #include <omp.h>
00017 #include "fresize.h"
00018 #include "fstats.h"
00019
00020 char *module_name = "dailysynframe";
00021
00022 #define DIE(msg) {fflush(stdout); fprintf(stderr, "%s, status = %d \n", msg, status); return(status);}
00023 #define PARAMETER_ERROR(PNAME)
00024 #define PI 4.0 * atan(1.0)
00025 #define QUAL_CHECK (0xfffefb00)
00026
00027 void frebinbox(float *image_in, float *image_out, int nx, int ny, int nbinx, int nbiny);
00028
00029 ModuleArgs_t module_args[] =
00030 {
00031 {ARG_STRING, "in", "NOTSPECIFIED", "in"},
00032 {ARG_STRING, "out", "NOTSPECIFIED", "out"},
00033 {ARG_STRING, "synoptic", "NOTSPECIFIED", "synoptic"},
00034 {ARG_STRING, "smallsyn", "NOTSPECIFIED", ""},
00035 {ARG_STRING, "drmethod", "NOCORRDIFFROT", "drmethod"},
00036 {ARG_INT, "magresoln", "NOTSPECIFIED", "magresoln"},
00037 {ARG_INT, "synresoln", "NOTSPECIFIED", "synresoln"},
00038 {ARG_INT, "xx1", "-1", "xx1"},
00039 {ARG_INT, "yy1", "-1", "yy1"},
00040 {ARG_END}
00041 };
00042
00043 float zgrid(int jph, int ith, int cmp, int rup, int dbl,
00044 float phd[], float thd[], float lad[], float cth[],
00045 float sth[], float csc[], float scs[]);
00046
00047 int DoIt(void)
00048 {
00049 DRMS_RecordSet_t *inRS, *inRSfinal;
00050 DRMS_Record_t *inRec, *inRecfinal, *outRec = NULL, *smallRD;
00051 DRMS_Segment_t *inSeg, *inSegfinal, *outSeg, *smalloutSeg;
00052 DRMS_Array_t *inArray, *inArrayfinal;
00053 TIME t_rec, t_rec0;
00054 TIME halfw = 7200.0;
00055 char *t_window = "240m";
00056 char *inQueryfinal, *trec_str = NULL, *smallRecQuery;
00057 float crlt, crln;
00058
00059 double clog0;
00060 float aa, bb, cc, dd, ee;
00061 int status = DRMS_SUCCESS, nrecs, irec, quality;
00062 int i, j, crn;
00063 int xdim_syn, ydim_syn, xmg, ymg;
00064 char sdatestime[100], sdatetmp[100], timetmp[100];
00065 memset(sdatetmp, 0, sizeof(sdatetmp));
00066 memset(timetmp, 0, sizeof(timetmp));
00067 memset(sdatestime, 0, sizeof(sdatestime));
00068
00069 char *sdate, *stime, *inQuery, *outQuery, *synQuery;
00070 char *drmethod;
00071 int magresoln = params_get_int(&cmdparams, "magresoln");
00072 int synresoln = params_get_int(&cmdparams, "synresoln");
00073 int xx1 = params_get_int(&cmdparams, "xx1");
00074 int yy1 = params_get_int(&cmdparams, "yy1");
00075 int nbin = 5;
00076
00077 inQuery = (char *)params_get_str(&cmdparams, "in");
00078 outQuery = (char *)params_get_str(&cmdparams, "out");
00079 synQuery = (char *)params_get_str(&cmdparams, "synoptic");
00080 smallRecQuery = (char *)cmdparams_get_str(&cmdparams, "smallsyn", &status);
00081 drmethod = (char *)params_get_str(&cmdparams, "drmethod");
00082
00083 char historyofthemodule[2048];
00084 sprintf(historyofthemodule,"o2helio.c bug corrected -- July 2013");
00085
00086 aa = 13.1988; bb = 0.0; cc = 0.0;
00087 if (strcmp(drmethod, "Meunier") == 0)
00088 {
00089 aa = 13.562; bb = -2.04; cc = -1.4875;
00090 }
00091
00092 if (strcmp(drmethod, "Phil") == 0)
00093 {
00094 aa = 2.917; bb = -0.40; cc = -0.40;
00095 dd = 0.202006;
00096 aa = aa/dd; bb = bb/dd; cc=cc/dd;
00097 ee = 0.930505;
00098 aa = aa*ee; bb = bb*ee; cc = cc*ee;
00099 }
00100
00101 if (strcmp(drmethod, "Pevtsov") == 0)
00102 {
00103 aa = 13.51; bb = -1.72; cc = -2.31;
00104 }
00105
00106 if (strcmp(drmethod, "Snodgrass") == 0)
00107 {
00108 aa = 2.897; bb = -0.339; cc = -0.485;
00109 dd = 0.202006;
00110 aa = aa/dd; bb=bb/dd; cc=cc/dd;
00111 ee = 0.930505;
00112 aa = aa*ee; bb = bb*ee; cc = cc*ee;
00113 }
00114
00115 outRec = drms_create_record(drms_env, outQuery, DRMS_PERMANENT, &status);
00116 if (status) DIE("Output recordset not created");
00117 smallRD = drms_create_record(drms_env, smallRecQuery, DRMS_PERMANENT, &status);
00118 if (status) DIE("Output record not created");
00119
00120 inRS = drms_open_records(drms_env, inQuery, &status);
00121 if (status || inRS->n == 0)
00122 DIE("No input data found -- no remapped files");
00123 inRec = inRS->records[0];
00124 t_rec = drms_getkey_time(inRec, "T_REC", &status);
00125 t_rec0 = t_rec - halfw;
00126
00127 inQueryfinal = (char *)malloc(100 * sizeof(char));
00128 trec_str = (char *)malloc(30 * sizeof(char));
00129 sprint_time(trec_str, t_rec0, "TAI", 0);
00130 sprintf(inQueryfinal, "%s[%s/%s]", inRec->seriesinfo->seriesname, trec_str, t_window);
00131 printf("%s\n", inQueryfinal);
00132 drms_close_records(inRS, DRMS_FREE_RECORD);
00133 free(trec_str);
00134
00135 inRSfinal = drms_open_records(drms_env, inQueryfinal, &status);
00136 if (status || inRSfinal->n == 0) DIE("No input data found -- files contain no data");
00137 nrecs = inRSfinal->n;
00138
00139
00140
00141 int count = 0;
00142 int *recp;
00143 int nref, rec_cen;
00144 recp = (int *)malloc(nrecs * sizeof(int));
00145 for (i = 0; i < nrecs; i++)
00146 {
00147 inRecfinal = inRSfinal->records[i];
00148 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00149 inArray = drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
00150 if (status)
00151 {
00152 printf(" No data file found, status=%d\n", status);
00153 drms_free_array(inArray);
00154 continue;
00155 }
00156
00157 quality = drms_getkey_int(inRecfinal, "QUALITY", &status);
00158 if (quality & QUAL_CHECK)
00159 {
00160 printf("SKIP: error getting keyword %s: iRec = %d, quality = %x\n",
00161 "QUALITY", i, quality);
00162 continue;
00163 }
00164
00165 recp[count] = i;
00166 count += 1;
00167 drms_free_array(inArray);
00168 }
00169
00170 if (count==0) DIE("No input remapped data found");
00171 rec_cen = (int)(count/2);
00172 nref = recp[rec_cen];
00173 printf("middle data id=%d\n", nref);
00174 inRecfinal = inRSfinal->records[nref];
00175 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00176 inArray = drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
00177 int naxis = inArray->naxis;
00178 xmg = inArray->axis[0]; ymg = inArray->axis[1];
00179 t_rec = drms_getkey_time(inRecfinal, "T_REC", &status);
00180 t_rec0 = drms_getkey_time(inRecfinal, "T_OBS", &status);
00181 crn = drms_getkey_int(inRecfinal, "CAR_ROT", &status);
00182 crlt = drms_getkey_float(inRecfinal, "CRLT_OBS", &status);
00183 crln = drms_getkey_float(inRecfinal, "CRLN_OBS", &status);
00184 clog0 = drms_getkey_double(inRecfinal, "CRVAL1", &status);
00185
00186
00187 drms_copykey(outRec, inRecfinal, "DATASIGN");
00188 drms_copykey(outRec, inRecfinal, "DSUN_OBS");
00189 drms_copykey(outRec, inRecfinal, "OBS_VR");
00190 drms_copykey(outRec, inRecfinal, "OBS_VW");
00191 drms_copykey(outRec, inRecfinal, "OBS_VN");
00192 drms_copykey(outRec, inRecfinal, "QUALITY");
00193 drms_copykey(outRec, inRecfinal, "MAPMMAX");
00194 drms_copykey(outRec, inRecfinal, "MAPLGMAX");
00195 drms_copykey(outRec, inRecfinal, "MAPLGMIN");
00196 drms_copykey(outRec, inRecfinal, "SINBDIVS");
00197 drms_copykey(outRec, inRecfinal, "MAPBMAX");
00198 drms_copykey(outRec, inRecfinal, "MAPRMAX");
00199 drms_copykey(outRec, inRecfinal, "LGSHIFT");
00200 drms_copykey(outRec, inRecfinal, "INTERPO");
00201 drms_copykey(outRec, inRecfinal, "MCORLEV");
00202 drms_copykey(outRec, inRecfinal, "MOFFSET");
00203 drms_copykey(outRec, inRecfinal, "CARSTRCH");
00204 drms_copykey(outRec, inRecfinal, "DIFROT_A");
00205 drms_copykey(outRec, inRecfinal, "DIFROT_B");
00206 drms_copykey(outRec, inRecfinal, "DIFROT_C");
00207 drms_copykey(outRec, inRecfinal, "INSTRUME");
00208 drms_copykey(outRec, inRecfinal, "BLD_VERS");
00209 drms_copykey(outRec, inRecfinal, "CALVER64");
00210
00211
00212 int itmp;
00213 float ftmp;
00214 double dtmp;
00215
00216 drms_copykey(smallRD, inRecfinal, "DATASIGN");
00217 drms_copykey(smallRD, inRecfinal, "DSUN_OBS");
00218 drms_copykey(smallRD, inRecfinal, "OBS_VR");
00219 drms_copykey(smallRD, inRecfinal, "OBS_VW");
00220 drms_copykey(smallRD, inRecfinal, "OBS_VN");
00221 drms_copykey(smallRD, inRecfinal, "QUALITY");
00222 drms_copykey(smallRD, inRecfinal, "MAPMMAX");
00223 drms_copykey(smallRD, inRecfinal, "MAPLGMAX");
00224 drms_copykey(smallRD, inRecfinal, "MAPLGMIN");
00225 drms_copykey(smallRD, inRecfinal, "SINBDIVS");
00226 drms_copykey(smallRD, inRecfinal, "MAPBMAX");
00227 drms_copykey(smallRD, inRecfinal, "MAPRMAX");
00228 drms_copykey(smallRD, inRecfinal, "LGSHIFT");
00229 drms_copykey(smallRD, inRecfinal, "INTERPO");
00230 drms_copykey(smallRD, inRecfinal, "MCORLEV");
00231 drms_copykey(smallRD, inRecfinal, "MOFFSET");
00232 drms_copykey(smallRD, inRecfinal, "CARSTRCH");
00233 drms_copykey(smallRD, inRecfinal, "DIFROT_A");
00234 drms_copykey(smallRD, inRecfinal, "DIFROT_B");
00235 drms_copykey(smallRD, inRecfinal, "DIFROT_C");
00236 drms_copykey(smallRD, inRecfinal, "INSTRUME");
00237 drms_copykey(smallRD, inRecfinal, "BLD_VERS");
00238 drms_copykey(smallRD, inRecfinal, "CALVER64");
00239 drms_free_array(inArray);
00240
00241
00242
00243 float *aveData;
00244
00245 xdim_syn = 3600; ydim_syn = 1440;
00246 int inDims[2] = {xmg, ymg};
00247 int dxsz = 2 * inDims[0];
00248 int ith = inDims[1];
00249 int ppd = xdim_syn/360;
00250 int xbeg = 30;
00251 if (xx1 == -1) xx1 = 60;
00252 if (yy1 == -1) yy1 = 0;
00253 int hwd = xx1;
00254 int ii, jj;
00255 int smallDims[2], xout, yout;
00256 TIME tobs_total = 0.0, tobs_ave;
00257 xx1 *= ppd;
00258 xbeg *= ppd;
00259 aveData = (float *)malloc(xmg * ymg * sizeof(float));
00260 xout = xdim_syn/nbin; yout = ydim_syn/(nbin-1);
00261 smallDims[0] = xout; smallDims[1] = yout;
00262
00263 for (i = 0; i < count; i++)
00264 {
00265 inRecfinal = inRSfinal->records[recp[i]];
00266 inSeg = drms_segment_lookupnum(inRecfinal, 0);
00267 inArray = drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
00268 float *inData = (float *)inArray->data;
00269 int crnn = drms_getkey_int(inRecfinal, "CAR_ROT", &status);
00270 float clogn = drms_getkey_float(inRecfinal, "CRVAL1", &status);
00271 int xshift = (int)(ppd * ((clogn - clog0) - 360.0 * (crnn - crn)));
00272 TIME Tobs = drms_getkey_time(inRecfinal, "T_OBS", &status);
00273 tobs_total += Tobs;
00274
00275
00276 for (jj = 0; jj < ymg; jj++)
00277 {
00278 for (ii = xbeg; ii < xmg - xbeg; ii++)
00279 {
00280 aveData[jj * xmg + ii] += inData[jj * xmg + ii - xshift];
00281 }
00282 }
00283 drms_free_array(inArray);
00284 }
00285
00286 tobs_ave = tobs_total/count;
00287 for (jj = 0; jj < ymg; jj++)
00288 for (ii = 0; ii < xmg; ii++)
00289 aveData[jj * xmg + ii] /= count;
00290
00291 drms_close_records(inRSfinal, DRMS_FREE_RECORD);
00292 float thd[ith], csc[ith], phd[dxsz];
00293 float lad[ith], sth[ith], cth[ith], scs[dxsz];
00294 double dtor = PI/180.;
00295 float constrate = 13.1988;
00296 float ratelow, sinlat;
00297 DRMS_RecordSet_t *synRS = NULL;
00298 DRMS_Record_t *synRec;
00299 DRMS_Segment_t *synSeg;
00300 DRMS_Array_t *synArray, *supsynArray, *outArray, *smalloutArray;
00301 float *synData, *supsynData, *outData, *smalloutData;
00302 int i1, j1;
00303 int synleftst = ppd * hwd, supleftst = ppd * clog0;
00304
00305 zgrid(dxsz, ith, 0, 0, 0, phd, thd, lad, cth, sth, csc, scs);
00306
00307 snprintf(timetmp, sizeof(timetmp), "%s[%d/3]", synQuery, crn-2);
00308 synQuery = timetmp;
00309 printf("inputname= %s\n", synQuery);
00310 synRS = drms_open_records(drms_env, synQuery, &status);
00311 if (status || synRS->n == 0) DIE("No input data found -- no synoptic charts");
00312
00313 int nds = synRS->n;
00314 int supxDim = nds * xdim_syn;
00315 int supsynDim[2] = {supxDim, ydim_syn};
00316 int synDim[2] = {xdim_syn, ydim_syn};
00317 supsynArray = drms_array_create(DRMS_TYPE_FLOAT, 2, supsynDim, NULL, &status);
00318 supsynData = supsynArray->data;
00319
00320 outArray = drms_array_create(DRMS_TYPE_FLOAT, 2, synDim, NULL, &status);
00321 outData = outArray->data;
00322 smalloutArray = drms_array_create(DRMS_TYPE_FLOAT, 2, smallDims, NULL, &status);
00323 smalloutData = smalloutArray->data;
00324
00325 for (i = 0; i < nds; i++)
00326 {
00327 synRec = synRS->records[i];
00328 synSeg = drms_segment_lookupnum(synRec, 0);
00329 synArray = drms_segment_read(synSeg, DRMS_TYPE_FLOAT, &status);
00330 synData = synArray->data;
00331 int ii = (nds - 1 - i) * xdim_syn;
00332 for (j1 = 0; j1 < ydim_syn; j1++)
00333 for (i1 = 0; i1 < xdim_syn; i1++)
00334 {
00335 supsynData[supxDim * j1 + ii + i1] = synData[xdim_syn * j1 + i1];
00336 }
00337 }
00338
00339
00340
00341
00342 for (j = 0; j < ydim_syn/2; j++)
00343 {
00344 sinlat = sin(lad[j]*dtor);
00345 ratelow = aa + bb * sinlat * sinlat + cc * pow(sinlat, 4);
00346
00347 for (i = synleftst; i < xdim_syn; i++)
00348 {
00349 float lon = (i - synleftst) * constrate/ratelow;
00350 float delta_x = lon - (int)lon;
00351 int lonpixel = (int)(supleftst + lon);
00352 float x1 = supsynData[j * supxDim + lonpixel];
00353 float x2 = supsynData[j * supxDim + lonpixel + 1];
00354 outData[j*xdim_syn + i] = (1.0 - delta_x) * x1 + delta_x * x2;
00355 jj = ydim_syn - 1 - j;
00356 x1 = supsynData[jj * supxDim + lonpixel];
00357 x2 = supsynData[jj * supxDim + lonpixel + 1];
00358 outData[jj*xdim_syn + i] = (1.0 - delta_x) * x1 + delta_x * x2;
00359 }
00360 }
00361
00362 int magleft = ppd * (90 - hwd);
00363 for (j = 0; j < ydim_syn; j++)
00364 for (i = 0; i < 2*synleftst; i++)
00365 {
00366 outData[j * xdim_syn + i] = aveData[j * inDims[0] + (int)magleft + i];
00367 }
00368
00369 double statMin, statMax, statMedn, statMean, statSig, statSkew, statKurt;
00370 int statNgood;
00371 if (fstats(xdim_syn*ydim_syn, outData, &statMin, &statMax, &statMedn, &statMean, &statSig,
00372 &statSkew, &statKurt, &statNgood)) printf("\n Statistics computation failed\n");
00373
00374 frebinbox(outData, smalloutData, xdim_syn, ydim_syn, nbin, nbin-1);
00375 double smallstatMin, smallstatMax, smallstatMedn, smallstatMean, smallstatSig, smallstatSkew, smallstatKurt;
00376 int smallstatNgood;
00377 if (fstats(xout*yout, smalloutData, &smallstatMin, &smallstatMax, &smallstatMedn, &smallstatMean, &smallstatSig,
00378 &smallstatSkew, &smallstatKurt, &smallstatNgood)) printf("\n Statistics computation failed\n");
00379
00380
00381
00382
00383
00384 drms_setkey_time(outRec, "T_REC", t_rec);
00385 trec_str = (char *)malloc(30 * sizeof(char));
00386 sprint_time(trec_str, tobs_ave, "TAI", 0);
00387 drms_setkey_time(outRec, "T_OBS", tobs_ave);
00388 drms_setkey_int(outRec, "CAR_ROT", crn);
00389 drms_setkey_float(outRec, "CRLT_OBS", crlt);
00390 drms_setkey_float(outRec, "CRLN_OBS", crln);
00391 drms_setkey_float(outRec, "CADENCE", 24.0 * 60.0 * 60.0);
00392 drms_setkey_float(outRec, "CROTA2", 0.0);
00393 drms_setkey_string(outRec, "WCSNAME", "Carrington Heliographic");
00394 drms_setkey_string(outRec, "HISTORY", historyofthemodule);
00395
00396 double loncen = xdim_syn/2 + 0.0;
00397 drms_setkey_double(outRec, "CRPIX1", loncen);
00398
00399 double latcen = ydim_syn/2 + 0.0;
00400 drms_setkey_double(outRec, "CRPIX2", latcen);
00401
00402 double lonstep = -360.0/xdim_syn;
00403 drms_setkey_double(outRec, "CDELT1", lonstep);
00404 double latstep = 2.0/ydim_syn;
00405 drms_setkey_double(outRec, "CDELT2", latstep);
00406 double lonfirst = 360.0 * (crn - 1) - clog0 + hwd;
00407
00408 drms_setkey_double(outRec, "LON_FRST", lonfirst);
00409 double lonlast = 360.0 * crn - clog0 + hwd - 360.0/xdim_syn;
00410
00411 drms_setkey_double(outRec, "LON_LAST", lonlast);
00412 double loncenter = lonfirst + 180.0 - 0.5 * 360.0/xdim_syn;
00413 drms_setkey_double(outRec, "CRVAL1", loncenter);
00414 drms_setkey_double(outRec, "CARRTIME", loncenter);
00415 drms_setkey_double(outRec, "LON_STEP", lonstep);
00416
00417
00418 float hwnwidth = drms_getkey_float(synRec, "HWNWIDTH", &status);
00419 drms_setkey_float(outRec, "HWNWIDTH", hwnwidth);
00420 float eqpoints = drms_getkey_float(synRec, "EQPOINTS", &status);
00421 drms_setkey_float(outRec, "EQPOINTS", eqpoints);
00422 float syndro_a = drms_getkey_float(synRec, "DIFROT_A", &status);
00423 drms_setkey_float(outRec, "OSYNDR_A", syndro_a);
00424 float syndro_b = drms_getkey_float(synRec, "DIFROT_B", &status);
00425 drms_setkey_float(outRec, "OSYNDR_B", syndro_b);
00426 float syndro_c = drms_getkey_float(synRec, "DIFROT_C", &status);
00427 drms_setkey_float(outRec, "OSYNDR_C", syndro_c);
00428
00429 i = xdim_syn*ydim_syn;
00430 drms_setkey_int(outRec, "TOTVALS", i);
00431 drms_setkey_int(outRec, "DATAVALS", statNgood);
00432 i = xdim_syn*ydim_syn-statNgood;
00433 drms_setkey_int(outRec, "MISSVALS", i);
00434 drms_setkey_double(outRec, "DATAMIN", statMin);
00435 drms_setkey_double(outRec, "DATAMAX", statMax);
00436 drms_setkey_double(outRec, "DATAMEDN", statMedn);
00437 drms_setkey_double(outRec, "DATAMEAN", statMean);
00438 drms_setkey_double(outRec, "DATARMS", statSig);
00439 drms_setkey_double(outRec, "DATASKEW", statSkew);
00440 drms_setkey_double(outRec, "DATAKURT", statKurt);
00441
00442 drms_setkey_string(outRec, "FRTIMWDN", t_window);
00443 drms_setkey_string(outRec, "SYNDRORA", drmethod);
00444 drms_setkey_int(outRec, "FRAVEPNT", count);
00445 drms_setkey_float(outRec, "FRWINDOW", 2.0 * hwd);
00446 drms_setkey_float(outRec, "SYNDRO_A", aa);
00447 drms_setkey_float(outRec, "SYNDRO_B", bb);
00448 drms_setkey_float(outRec, "SYNDRO_C", cc);
00449
00450 drms_keyword_setdate(outRec);
00451
00452 printf(" WRITING OUTPUT\n");
00453
00454 outSeg = drms_segment_lookupnum(outRec, 0);
00455 outArray->parent_segment = outSeg;
00456 status = drms_segment_write(outSeg, outArray, 0);
00457 if (status) DIE("problem writing file");
00458
00459
00460 drms_setkey_time(smallRD, "T_REC", t_rec);
00461 drms_setkey_time(smallRD, "T_OBS", tobs_ave);
00462 drms_setkey_int(smallRD, "CAR_ROT", crn);
00463 drms_setkey_float(smallRD, "CRLT_OBS", crlt);
00464 drms_setkey_float(smallRD, "CRLN_OBS", crln);
00465 drms_setkey_float(smallRD, "CADENCE", 24.0 * 60.0 * 60.0);
00466 drms_setkey_float(smallRD, "CROTA2", 0.0);
00467 drms_setkey_string(smallRD, "WCSNAME", "Carrington Heliographic");
00468 drms_setkey_string(smallRD, "HISTORY", historyofthemodule);
00469
00470 loncen = xout/2 + 0.0;
00471 drms_setkey_double(smallRD, "CRPIX1", loncen);
00472 latcen = yout/2 + 0.0;
00473 drms_setkey_double(smallRD, "CRPIX2", latcen);
00474 lonstep = -360.0/xout;
00475 drms_setkey_double(smallRD, "CDELT1", lonstep);
00476 latstep = 2.0/yout;
00477 drms_setkey_double(smallRD, "CDELT2", latstep);
00478 lonfirst = 360.0 * (crn - 1) - clog0 + hwd;
00479 drms_setkey_double(smallRD, "LON_FRST", lonfirst);
00480 lonlast = 360.0 * crn - clog0 + hwd - 360.0/xout;
00481 drms_setkey_double(smallRD, "LON_LAST", lonlast);
00482 loncenter = lonfirst + 180.0 - 0.5 * 360.0/xout;
00483 drms_setkey_double(smallRD, "CRVAL1", loncenter);
00484 drms_setkey_double(smallRD, "CARRTIME", loncenter);
00485 drms_setkey_double(smallRD, "LON_STEP", lonstep);
00486
00487 hwnwidth = drms_getkey_float(synRec, "HWNWIDTH", &status);
00488 drms_setkey_float(smallRD, "HWNWIDTH", hwnwidth);
00489 eqpoints = drms_getkey_float(synRec, "EQPOINTS", &status);
00490 drms_setkey_float(smallRD, "EQPOINTS", eqpoints);
00491 syndro_a = drms_getkey_float(synRec, "DIFROT_A", &status);
00492 drms_setkey_float(smallRD, "OSYNDR_A", syndro_a);
00493 syndro_b = drms_getkey_float(synRec, "DIFROT_B", &status);
00494 drms_setkey_float(smallRD, "OSYNDR_B", syndro_b);
00495 syndro_c = drms_getkey_float(synRec, "DIFROT_C", &status);
00496 drms_setkey_float(smallRD, "OSYNDR_C", syndro_c);
00497
00498 i = xout*yout;
00499 drms_setkey_int(smallRD, "TOTVALS", i);
00500 drms_setkey_int(smallRD, "DATAVALS", smallstatNgood);
00501 i = xout*yout-smallstatNgood;
00502 drms_setkey_int(smallRD, "MISSVALS", i);
00503 drms_setkey_double(smallRD, "DATAMIN", smallstatMin);
00504 drms_setkey_double(smallRD, "DATAMAX", smallstatMax);
00505 drms_setkey_double(smallRD, "DATAMEDN", smallstatMedn);
00506 drms_setkey_double(smallRD, "DATAMEAN", smallstatMean);
00507 drms_setkey_double(smallRD, "DATARMS", smallstatSig);
00508 drms_setkey_double(smallRD, "DATASKEW", smallstatSkew);
00509 drms_setkey_double(smallRD, "DATAKURT", smallstatKurt);
00510
00511 drms_setkey_string(smallRD, "FRTIMWDN", t_window);
00512 drms_setkey_string(smallRD, "SYNDRORA", drmethod);
00513 drms_setkey_int(smallRD, "FRAVEPNT", count);
00514 drms_setkey_float(smallRD, "FRWINDOW", 2.0 * hwd);
00515 drms_setkey_float(smallRD, "SYNDRO_A", aa);
00516 drms_setkey_float(smallRD, "SYNDRO_B", bb);
00517 drms_setkey_float(smallRD, "SYNDRO_C", cc);
00518
00519 drms_keyword_setdate(smallRD);
00520
00521 printf(" WRITING OUTPUT--small-size version\n");
00522
00523 smalloutSeg = drms_segment_lookupnum(smallRD, 0);
00524 smalloutArray->parent_segment = smalloutSeg;
00525 status = drms_segment_write(smalloutSeg, smalloutArray, 0);
00526 if (status) DIE("problem writing file");
00527
00528 free(trec_str); free(recp); free(aveData);
00529 drms_free_array(smalloutArray);
00530 drms_free_array(outArray);
00531 drms_free_array(supsynArray);
00532 drms_free_array(synArray);
00533
00534 drms_close_record(smallRD, DRMS_INSERT_RECORD);
00535 drms_close_record(outRec, DRMS_INSERT_RECORD);
00536 drms_close_records(synRS, DRMS_FREE_RECORD);
00537
00538 return 0;
00539 }
00540
00541
00542
00543
00544
00545 float zgrid(int jph, int ith, int cmp, int rup, int dbl,
00546 float phd[], float thd[], float lad[], float cth[],
00547 float sth[], float csc[], float scs[])
00548 {
00549
00550 double dtor = PI/180.;
00551 int i, j;
00552
00553 float dcth = 2.0/ith;
00554 float dph = 360./jph;
00555 float cpc[jph], thr, dphr;
00556 float lthd[ith], lphd[jph], lscs[jph];
00557 float llad[ith], lsth[ith], lcth[ith];
00558
00559 #if 0
00560 if (dbl == 1)
00561 {
00562 double thd[ith], phd[jph], csc[ith], cpc[jph];
00563 double dph = 360./jph;
00564 double dcth = 2.0/ith;
00565 double lad[ith], sth[ith], cth[ith], thr;
00566 double lthd[ith], lphd[jph], lscs[jph];
00567 double llad[ith], lsth[ith], lcth[ith];
00568 double dphr;
00569 float scs[jph];
00570 }
00571 #endif
00572
00573 for (i =0; i < ith; i++)
00574 {
00575 cth[i] = (i + 0.5) * dcth - 1.0;
00576 thr = acos(cth[i]);
00577 sth[i] = sin(thr);
00578 thd[i] = thr/dtor;
00579 lad[i] = 90-thd[i];
00580 }
00581
00582 for (j = 0; j < jph; j++)
00583 phd[j] = (j + 0.5) * dph;
00584
00585 if (cmp == 1)
00586 {
00587 for (i = 0; i < ith; i++)
00588 csc[i] = 1/sth[i];
00589 for (j = 0; j < jph; j++)
00590 {
00591 dphr = (phd[j] - cmp) * dtor;
00592 cpc[j] = cos(dphr);
00593 scs[j] = 1/cpc[j];
00594 }
00595 }
00596
00597 if (rup == 1)
00598 {
00599 for (i = 0; i < ith; i++)
00600 {
00601 thd[i] = lthd[ith - i];
00602 lad[i] = llad[ith - 1];
00603 cth[i] = lcth[ith - i];
00604 sth[i] = lsth[ith - 1];
00605 }
00606 for (j = 0; j < jph; j++)
00607 {
00608 phd[j] = lphd[jph-j];
00609 scs[j] = lscs[jph-j];
00610 }
00611 }
00612 return 0;
00613 }
00614
00615
00616
00617 void frebin(float *image_in, float *image_out, int nx, int ny, int nbin)
00618 {
00619 struct fresize_struct fresizes;
00620 int nxout, nyout;
00621 int nlead = nx;
00622
00623 nxout = nx / nbin; nyout = ny / nbin;
00624 init_fresize_gaussian(&fresizes, (nbin / 2) * 2, (nbin / 2) * 2, nbin);
00625 fresize(&fresizes, image_in, image_out, nx, ny, nlead, nxout, nyout, nxout, (nbin / 2) * 2, (nbin / 2) * 2, DRMS_MISSING_FLOAT);
00626 free_fresize(&fresizes);
00627
00628 }
00629
00630 void frebinbox(float *image_in, float *image_out, int nx, int ny, int nbinx, int nbiny)
00631 {
00632 int nxout, nyout;
00633 int ii, jj, i, j;
00634 nxout = nx / nbinx; nyout = ny / nbiny;
00635 for (j = 0; j < nyout; j++) {
00636 int yOff, jy;
00637 jy = j * nbiny;
00638 for (i = 0; i < nxout; i++) {
00639 int ix;
00640 ix = i * nbinx;
00641 float aveval = 0.0;
00642 int number = 0;
00643 for (jj = 0; jj < nbiny; jj++) {
00644 yOff = (jy + jj) * nx;
00645 for (ii = 0; ii < nbinx; ii++) {
00646 int iData = yOff + ix + ii;
00647 if (!(isnan(image_in[iData]))) {
00648 aveval += image_in[iData];
00649 number += 1;
00650 }
00651 }
00652 }
00653 image_out[j*nxout+i] = aveval/number;
00654 }
00655 }
00656 }
00657
00658