00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <jsoc_main.h>
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <math.h>
00030 #include <sys/time.h>
00031 #include <sys/resource.h>
00032 #include "copy_me_keys.c"
00033
00034 #define PI (M_PI)
00035 #define DTOR (PI / 180.)
00036 #define Rad2arcsec (3600. * 180. / PI)
00037
00038
00039 #define ARRLENGTH(ARR) (sizeof(ARR) / sizeof(ARR[0]))
00040 #define DIE(msg) {fflush(stdout); fprintf(stderr, "%s, status=%d\n", msg, status); return(status);}
00041 #define SHOW(msg) {printf("%s", msg); fflush(stdout);}
00042
00043 #include "timing.c"
00044
00045
00046
00047
00048 #define PIX_X(wx,wy) ((((wx-crvalx)*cosa + (wy-crvaly)*sina)/cdelt)+crpix1)
00049 #define PIX_Y(wx,wy) ((((wy-crvaly)*cosa - (wx-crvalx)*sina)/cdelt)+crpix2)
00050 #define WX(pix_x,pix_y) (((pix_x-crpix1)*cosa - (pix_y-crpix2)*sina)*cdelt+crvalx)
00051 #define WY(pix_x,pix_y) (((pix_y-crpix2)*cosa + (pix_x-crpix1)*sina)*cdelt+crvaly)
00052
00053 char *module_name = "disambig";
00054
00055 ModuleArgs_t module_args[] =
00056 {
00057 {ARG_STRING, "in", NULL, "Input data series."},
00058 {ARG_STRING, "out", NULL, "Output data series."},
00059 {ARG_STRING, "mask", " ", "Bitmap series name, as AR mask, for full disk"},
00060 {ARG_INT, "VERB", "1", "Level of verbosity: 0=errors/warnings; 1=minimal messages; 2=all messages"},
00061 {ARG_INT, "AMBGMTRY", "1", "1 for planar; 2 for spherical."},
00062 {ARG_INT, "AMBWEAK", "1", "0 for random; 1 for potential field; 2 for most radial."},
00063 {ARG_INT, "AMBNEROD", "1", "Number of pixels by which to erode map of above threshold pixels."},
00064 {ARG_INT, "AMBNGROW", "5", "Number of pixels by which to grow eroded map."},
00065 {ARG_INT, "AMBNPAD", "200", "Pixel number to pad with zeros for potential field."},
00066 {ARG_INT, "AMBNAP", "10", "Pixel number to apodize for potential field."},
00067 {ARG_INT, "AMBNTX", "20", "Tile number in x (lon) direction for pf on a sphere."},
00068 {ARG_INT, "AMBNTY", "20", "Tile number in y (lat) direction for pf on a sphere."},
00069 {ARG_FLOAT, "AMBBTHR0", "1.0e2", "Threshold field strength."},
00070 {ARG_FLOAT, "AMBBTHR1", "1.5e2", "Threshold field strength."},
00071 {ARG_INT, "AMBSEED", "1", "Input random number seed (seed>0)."},
00072 {ARG_INT, "AMBNEQ", "10", "Num of reconfigurations attempted at each temperature setting."},
00073 {ARG_FLOAT, "AMBLMBDA", "1.", "Weighting factor between div. and vert. current density."},
00074 {ARG_FLOAT, "AMBTFCT0", "2.", "Input factor to scale initial temperature (tfac0>0)."},
00075 {ARG_FLOAT, "AMBTFCTR", "0.990", "Input factor to reduce temperature (0<tfactr<1)."},
00076 {ARG_END}
00077 };
00078
00079
00080 extern void ambig_(int *geometry,
00081 int *weak,
00082 int *nx, int *ny,
00083 int *npad,
00084 float *xcen, float *ycen,
00085 int *verb,
00086 float *lambda,
00087 int *neq, float *tfactr, float *tfac0,
00088 int *seed,
00089 int *ntx, int *nty,
00090 float *Bx, float *By, float *Bz, float *dBt, float *probBa,
00091 int *bitmap,
00092 float *radius,
00093 int *nap, float *bthresh0, float *bthresh1);
00094
00095
00096
00097 int DoIt(void)
00098 {
00099 int status = DRMS_SUCCESS;
00100 char *inQuery, *outQuery;
00101 DRMS_RecordSet_t *inRS, *outRS;
00102 int irec, nrecs;
00103 DRMS_Record_t *inRec, *outRec;
00104
00105 int nseg = 10;
00106 char *segName[10] = {"field", "inclination", "azimuth", "alpha_mag",
00107 "field_err", "inclination_err", "alpha_err",
00108 "field_inclination_err", "field_alpha_err", "inclination_alpha_err"};
00109
00110 DRMS_Segment_t *inSeg[nseg], *outSeg_flag, *outSeg_prob;
00111 DRMS_Array_t *inArray[nseg], *outArray_flag, *outArray_prob;
00112 float *inData[nseg];
00113
00114
00115 DRMS_Link_t *magLink;
00116
00117
00118
00119
00120 char *maskSeries, *maskQuery = NULL, *trec_str = NULL;
00121 DRMS_RecordSet_t *maskRS;
00122 DRMS_Record_t *maskRec;
00123 DRMS_Segment_t *maskSeg;
00124 DRMS_Array_t *maskArray;
00125 char *mask;
00126 int mask_id,harpnum;
00127
00128 int geometry, weak;
00129 int npad, nap, ntx, nty, seed, neq;
00130 float bthresh0, bthresh1, lambda, tfac0, tfactr;
00131 int verbflag;
00132 int outDims[2];
00133
00134 int i, j, l, m;
00135 int nx, ny, nxny, nxnye, nxnyg, nerode, ngrow;
00136
00137 TIME t_rec;
00138
00139 float radius, xcen, ycen;
00140 float crpix1, crpix2, cdelt1, cdelt2;
00141 float im_scale, rsun_ref, dsun_obs;
00142 float crvalx, crvaly, cdelt, crota2, sina, cosa;
00143
00144 float center_x, center_y;
00145 int hw_x, hw_y;
00146 int ll[2], ur[2];
00147
00148 float *Bx, *By, *Bz, *dBt;
00149 float *probBa;
00150
00151
00152
00153
00154 float Bazm, Bmag, Bfil, Binc;
00155 float BmagBfil, SinBinc, BmagBfilSinBinc, CosBinc;
00156 float varBfil, varBinc, varBmag, varBfilBmag, varBfilBinc, varBmagBinc;
00157 float xx, yy, r2, rad2;
00158 int *bitmap = NULL;
00159 int *erodemap, *growmap;
00160 char *ambig_flag;
00161
00162
00163 double wt0, wt1, wt;
00164 double ut0, ut1, ut;
00165 double st0, st1, st;
00166 double ct0, ct1, ct;
00167 wt0 = getwalltime();
00168 ct0 = getcputime(&ut0, &st0);
00169
00170
00171
00172
00173
00174 inQuery = (char *)params_get_str(&cmdparams, "in");
00175 outQuery = (char *)params_get_str(&cmdparams, "out");
00176 maskSeries = (char *)params_get_str(&cmdparams, "mask");
00177 verbflag = params_get_int(&cmdparams, "VERB");
00178 geometry = params_get_int(&cmdparams, "AMBGMTRY");
00179 weak = params_get_int(&cmdparams, "AMBWEAK");
00180 nerode = params_get_int(&cmdparams, "AMBNEROD");
00181 ngrow = params_get_int(&cmdparams, "AMBNGROW");
00182 npad = params_get_int(&cmdparams, "AMBNPAD");
00183 nap = params_get_int(&cmdparams, "AMBNAP");
00184 ntx = params_get_int(&cmdparams, "AMBNTX");
00185 nty = params_get_int(&cmdparams, "AMBNTY");
00186 seed = params_get_int(&cmdparams, "AMBSEED");
00187 neq = params_get_int(&cmdparams, "AMBNEQ");
00188 bthresh0 = params_get_float(&cmdparams, "AMBBTHR0");
00189 bthresh1 = params_get_float(&cmdparams, "AMBBTHR1");
00190 lambda = params_get_float(&cmdparams, "AMBLMBDA");
00191 tfac0 = params_get_float(&cmdparams, "AMBTFCT0");
00192 tfactr = params_get_float(&cmdparams, "AMBTFCTR");
00193
00194
00195 if (nap > npad) {nap = npad; SHOW("nap set to npad\n");}
00196 if (seed <= 0) {seed = 1; SHOW("seed set to 1\n");}
00197 if (lambda < 0) {lambda = 1.0; SHOW("lambda set to 1.0\n");}
00198 if (tfac0 < 0) {tfac0 = 2.; SHOW("tfac0 set to 2.0\n");}
00199 if (neq <= 0) {neq = 20; SHOW("neq set to 20\n");}
00200 if ((tfactr < 0) || (tfactr > 1)) {tfactr = 0.995; SHOW("tfactr set to 0.995\n");}
00201 if (geometry < 1 || geometry > 2) {DIE("Unknown geometry flag");}
00202 if (weak < 0 || weak > 2) {DIE("Unknown weak flag");}
00203 if (nerode <= 0) {nerode = 1; SHOW("nerode set to 1\n");}
00204 if (ngrow <= 0) {ngrow = 5; SHOW("ngrow set to 5\n");}
00205
00206
00207
00208 inRS = drms_open_records(drms_env, inQuery, &status);
00209 if (status || inRS->n == 0) DIE("No input data found");
00210 nrecs = inRS->n;
00211
00212
00213 outRS = drms_create_records(drms_env, nrecs, outQuery, DRMS_PERMANENT, &status);
00214 if (status) DIE("Output recordset not created");
00215
00216
00217 for (irec = 0; irec < nrecs; irec++) {
00218
00219
00220 if (verbflag) {
00221 wt1 = getwalltime();
00222 ct1 = getcputime(&ut1, &st1);
00223 printf("processing record %d...\n", irec);
00224 }
00225
00226
00227 inRec = inRS->records[irec];
00228
00229
00230
00231 t_rec = drms_getkey_time(inRec, "T_REC", &status);
00232
00233 crota2 = drms_getkey_float(inRec, "CROTA2", &status);
00234 sina = sin(crota2 * DTOR);
00235 cosa = cos(crota2 * DTOR);
00236 cdelt = drms_getkey_float(inRec, "CDELT1", &status);
00237
00238 rsun_ref = drms_getkey_double(inRec, "RSUN_REF", &status);
00239 if (status) rsun_ref = 6.96e8;
00240 dsun_obs = drms_getkey_double(inRec, "DSUN_OBS", &status);
00241 radius = asin(rsun_ref / dsun_obs) * Rad2arcsec / cdelt;
00242
00243 harpnum = drms_getkey_int(inRec, "HARPNUM", &status);
00244 if (status)
00245 printf("status false\n");
00246 else
00247 printf("HARP number found:%d",harpnum);
00248
00249 if (geometry == 1) {
00250 crvalx = drms_getkey_float(inRec, "IMCRVAL1", &status);
00251 crvaly = drms_getkey_float(inRec, "IMCRVAL2", &status);
00252 crpix1 = drms_getkey_float(inRec, "IMCRPIX1", &status);
00253 crpix2 = drms_getkey_float(inRec, "IMCRPIX2", &status);
00254
00255 center_x = drms_getkey_float(inRec, "CRPIX1", &status) - 1;
00256 center_y = drms_getkey_float(inRec, "CRPIX2", &status) - 1;
00257
00258 maskSeg = drms_segment_lookup(inRec, "bitmap");
00259 mask_id = drms_getkey_int(inRec, "MASK", &status);
00260 maskArray = drms_segment_read(maskSeg, DRMS_TYPE_CHAR, &status);
00261 if (status) DIE("Error reading mask");
00262 nx = maskArray->axis[0]; ny = maskArray->axis[1];
00263 printf("nx=%d, ny=%d\n", nx, ny); fflush(stdout);
00264 DIE("Mask dimensions checked");
00265
00266
00267
00268
00269
00270 xcen = center_x - (PIX_X(0.0,0.0) - 1.);
00271 ycen = center_y - (PIX_Y(0.0,0.0) - 1.);
00272 printf("xcen=%f, ycen=%f\n", xcen, ycen); fflush(stdout);
00273
00274
00275 ll[0] = (int)center_x - hw_x; ll[1] = (int)center_y - hw_y;
00276 ur[0] = (int)center_x + hw_x; ur[1] = (int)center_y + hw_y;
00277 } else {
00278 crvalx = drms_getkey_float(inRec, "CRVAL1", &status);
00279 crvaly = drms_getkey_float(inRec, "CRVAL2", &status);
00280 crpix1 = drms_getkey_float(inRec, "CRPIX1", &status);
00281 crpix2 = drms_getkey_float(inRec, "CRPIX2", &status);
00282
00283 xcen = PIX_X(0.0,0.0);
00284 ycen = PIX_Y(0.0,0.0);
00285 }
00286
00287
00288 for (i = 0; i < nseg; i++) {
00289 inSeg[i] = drms_segment_lookup(inRec, segName[i]);
00290
00291 if (geometry == 1) {
00292 inArray[i] = drms_segment_readslice(inSeg[i], DRMS_TYPE_FLOAT, ll, ur, &status);
00293 } else {
00294 inArray[i] = drms_segment_read(inSeg[i], DRMS_TYPE_FLOAT, &status);
00295 }
00296
00297 if (status) {
00298 for (j = 0; j <= i; j++)
00299 drms_free_array(inArray[i]);
00300 DIE("Segment reading error \n");
00301 }
00302 inData[i] = (float *)inArray[i]->data;
00303 }
00304
00305
00306 nx = inArray[0]->axis[0]; ny = inArray[0]->axis[1];
00307 if (geometry == 1) {
00308 if (nx != 2 * hw_x + 1 || ny != 2 * hw_y + 1) DIE("wrong cut out dimension");
00309 }
00310 nxny = nx * ny;
00311 printf("nx=%d, ny=%d\n", nx, ny);
00312
00313
00314 if (geometry == 1) {
00315 maskSeg = drms_segment_lookup(inRec, "bitmap");
00316 mask_id = drms_getkey_int(inRec, "MASK", &status);
00317 } else {
00318
00319
00320 maskQuery = (char *)malloc(100 * sizeof(char));
00321 trec_str = (char *)malloc(30 * sizeof(char));
00322 sprint_time(trec_str, t_rec, "TAI", 0);
00323 sprintf(maskQuery, "%s[%s]", maskSeries, trec_str);
00324
00325 maskRS = drms_open_records(drms_env, maskQuery, &status);
00326 if (status || maskRS->n != 1) {
00327 maskSeg = NULL;
00328 printf("no mask used\n");
00329 } else {
00330 maskRec = maskRS->records[0];
00331 maskSeg = drms_segment_lookup(maskRec, "bitmap");
00332 mask_id = 1;
00333 printf("%s, %s\n", trec_str, maskSeries);
00334 printf("#%d: t_inrec = %lf; t_mask = %lf\n",
00335 irec, t_rec, drms_getkey_time(maskRec, "T_REC", &status));
00336 }
00337 }
00338
00339
00340
00341 Bx = (float *) malloc(nxny * sizeof(float));
00342 By = (float *) malloc(nxny * sizeof(float));
00343 Bz = (float *) malloc(nxny * sizeof(float));
00344 dBt = (float *) malloc(nxny * sizeof(float));
00345
00346
00347
00348
00349
00350 for (i = 0; i < nxny; i++) {
00351
00352
00353 Bmag = inData[0][i];
00354 Binc = inData[1][i];
00355 Bazm = inData[2][i];
00356 Bfil = inData[3][i];
00357
00358
00359 varBmag = inData[4][i];
00360 varBinc = inData[5][i];
00361
00362
00363 varBfil = 0.;
00364
00365
00366 varBmagBinc = inData[7][i];
00367 varBfilBmag = inData[8][i];
00368 varBfilBinc = inData[9][i];
00369
00370
00371
00372 if (isnan(Bmag) || isnan(Binc) || isnan(Bazm) || isnan(Bfil)) {
00373
00374 dBt[i] = 1.E9;
00375 Bx[i] = 0.; By[i] = 0.; Bz[i] = 0.;
00376
00377 } else {
00378
00379 Binc *= DTOR, Bazm *= DTOR;
00380
00381 BmagBfil = Bmag * Bfil;
00382 CosBinc = cos(Binc); SinBinc=sin(Binc);
00383 BmagBfilSinBinc = BmagBfil * SinBinc;
00384
00385
00386
00387
00388 Bx[i] =-BmagBfilSinBinc * sin(Bazm);
00389 By[i] = BmagBfilSinBinc * cos(Bazm);
00390 Bz[i] = BmagBfil * cos(Binc);
00391
00392
00393 dBt[i] = (BmagBfil==0) ? 1.E9 :
00394 (BmagBfil *
00395 sqrt (SinBinc * SinBinc * (varBfil / (Bfil * Bfil) + varBmag / (Bmag * Bmag)
00396 + 2.*varBfilBmag/BmagBfil)
00397 + varBinc * CosBinc * CosBinc
00398 + (varBfilBinc / Bfil + varBmagBinc / Bmag) * SinBinc * CosBinc));
00399
00400 }
00401 }
00402 printf("Arrays read. \n");
00403
00404
00405 for (i = 0; i < nseg; i++) {
00406 drms_free_array(inArray[i]);
00407 }
00408
00409 if (geometry == 1 && maskSeg == NULL) DIE("Error for patch mask");
00410 if (maskSeg != NULL) {
00411
00412
00413
00414
00415
00416
00417 bitmap = (int *)calloc(nxny, sizeof(int));
00418 for (i = 0; i < nxny; i++) {
00419
00420
00421 bitmap[i] = 1;
00422 }
00423 drms_free_array(maskArray);
00424 } else {
00425
00426 bitmap = (int *)calloc(nxny, sizeof(int));
00427 rad2 = radius * radius;
00428 for (i = 0; i < nxny; i++) {
00429 j = i / nx;
00430 xx = i - j * nx - xcen + 1;
00431 yy = j - ycen + 1;
00432 r2 = xx * xx + yy * yy;
00433 if (r2 < rad2) {
00434 bitmap[i] = (sqrt(Bx[i] * Bx[i] + By[i] * By[i]) > bthresh1 + (bthresh0 - bthresh1) * sqrt(1. - r2 / rad2)) ? 1 : 0;
00435
00436
00437 } else {
00438 bitmap[i] = 0;
00439 }
00440 }
00441
00442 nxnye = (nx + 2 * nerode) * (ny + 2 * nerode);
00443 erodemap = (int *)calloc(nxnye, sizeof(int));
00444 for (i = 0; i < nxnye; i++) {
00445 erodemap[i] = 1;
00446 }
00447 for (i = 0; i < nxny; i++) {
00448 if (bitmap[i] == 0) {
00449 j = i + nerode * (nx + 1 + 2 * (i / nx + nerode));
00450
00451 erodemap[j - 2 * nerode - nx - 1] = 0;
00452 erodemap[j - 2 * nerode - nx] = 0;
00453 erodemap[j - 2 * nerode - nx + 1] = 0;
00454 erodemap[j - 1] = 0;
00455 erodemap[j] = 0;
00456 erodemap[j + 1] = 0;
00457 erodemap[j + 2 * nerode + nx - 1] = 0;
00458 erodemap[j + 2 * nerode + nx] = 0;
00459 erodemap[j + 2 * nerode + nx + 1] = 0;
00460 }
00461 }
00462
00463 nxnyg = (nx + 2 * ngrow) * (ny + 2 * ngrow);
00464 growmap = (int *)calloc(nxnyg, sizeof(int));
00465 for (i = 0; i < nxnyg; i++) {
00466 growmap[i] = 0;
00467 }
00468 for (i = 0; i < nxnye; i++) {
00469 if (erodemap[i] == 1) {
00470 j = i + ngrow * 2 * (i / (nx + 2 * nerode));
00471 for (l = 0; l <= 2 * ngrow; l++) {
00472 for (m = 0; m <= 2 * ngrow; m++) {
00473 growmap[j + l + m * (nx + 2 * (nerode + ngrow))] = 1;
00474 }
00475 }
00476 }
00477 }
00478
00479 for (i = 0; i < nxny; i++) {
00480 bitmap[i] = growmap[i + (nerode + ngrow) * (nx + 1 + 2 * (i / nx + nerode + ngrow))];
00481 }
00482 }
00483
00484
00485 outDims[0] = nx; outDims[1] = ny;
00486 probBa = (float *) malloc(nxny * sizeof(float));
00487 ambig_flag = (char *) calloc(nxny, sizeof(char));
00488
00489
00490 ambig_(&geometry,
00491 &weak,
00492 &nx, &ny,
00493 &npad,
00494 &xcen, &ycen,
00495 &verbflag,
00496 &lambda,
00497 &neq, &tfactr, &tfac0,
00498 &seed,
00499 &ntx, &nty,
00500 Bx, By, Bz, probBa,
00501 dBt, bitmap,
00502 &radius,
00503 &nap, &bthresh0, &bthresh1);
00504
00505 for (i = 0; i < nxny; i++) {
00506 ambig_flag[i] = (Bx[i] > 0.) ? 1 : 0;
00507 }
00508
00509
00510 int nancount = 0, outsz = outDims[0] * outDims[1];
00511 for (i = 0; i < outsz; i++) {
00512 if (isnan(probBa[i])) nancount++;
00513 }
00514
00515
00516 outArray_flag = drms_array_create(DRMS_TYPE_CHAR, 2, outDims, ambig_flag, &status);
00517 if (status) DIE("Error creating flag array");
00518 outArray_prob = drms_array_create(DRMS_TYPE_FLOAT, 2, outDims, probBa, &status);
00519 if (status) DIE("Error creating prob array");
00520
00521
00522 outRec = outRS->records[irec];
00523 outSeg_flag = drms_segment_lookup(outRec, "ambig_flag");
00524 outSeg_prob = drms_segment_lookup(outRec, "confidence");
00525 for (i = 0; i < 2; i++) {
00526 outSeg_flag->axis[i] = outArray_flag->axis[i];
00527 outSeg_prob->axis[i] = outArray_prob->axis[i];
00528 }
00529 outArray_flag->parent_segment = outSeg_flag;
00530 outArray_prob->parent_segment = outSeg_prob;
00531
00532
00533 status = drms_segment_write(outSeg_flag, outArray_flag, 0);
00534 if (status) DIE("Problem writing flag file");
00535 drms_free_array(outArray_flag);
00536 status = drms_segment_write(outSeg_prob, outArray_prob, 0);
00537 if (status) DIE("Problem writing prob file");
00538 drms_free_array(outArray_prob);
00539
00540
00541
00542 drms_copykey(outRec, inRec, "T_REC");
00543 if (geometry == 1) {
00544 drms_copykey(outRec, inRec, "PNUM");
00545 }
00546
00547 drms_setkey_string(outRec, "BLD_VERS", jsoc_version);
00548 drms_setkey_time(outRec, "DATE", CURRENT_SYSTEM_TIME);
00549
00550 copy_me_keys(inRec, outRec);
00551 copy_geo_keys(inRec, outRec);
00552 if (geometry == 1) copy_patch_keys(inRec, outRec);
00553
00554 drms_setkey_int(outRec, "AMBGMTRY", geometry);
00555 drms_setkey_int(outRec, "AMBWEAK", weak);
00556 drms_setkey_int(outRec, "AMBNEROD", nerode);
00557 drms_setkey_int(outRec, "AMBNGROW", ngrow);
00558 drms_setkey_int(outRec, "AMBNPAD", npad);
00559 drms_setkey_int(outRec, "AMBNAP", nap);
00560 drms_setkey_int(outRec, "AMBNTX", ntx);
00561 drms_setkey_int(outRec, "AMBNTY", nty);
00562 drms_setkey_int(outRec, "AMBSEED", seed);
00563 drms_setkey_int(outRec, "AMBNEQ", neq);
00564 drms_setkey_float(outRec, "AMBBTHR0", bthresh0);
00565 drms_setkey_float(outRec, "AMBBTHR1", bthresh1);
00566 drms_setkey_float(outRec, "AMBLMBDA", lambda);
00567 drms_setkey_float(outRec, "AMBTFCT0", tfac0);
00568 drms_setkey_float(outRec, "AMBTFCTR", tfactr);
00569
00570 drms_setkey_int(outRec, "TOTVALS", outsz);
00571 drms_setkey_int(outRec, "DATAVALS", outsz - nancount);
00572 drms_setkey_int(outRec, "MISSVALS", nancount);
00573
00574
00575 if (geometry == 1) {
00576 magLink = hcon_lookup_lower(&outRec->links, "PATCH");
00577 if (magLink) {
00578 drms_setlink_static(outRec, "PATCH", inRec->recnum);
00579 }
00580 } else {
00581 magLink = hcon_lookup_lower(&outRec->links, "MDATA");
00582 if (magLink) {
00583 drms_setlink_static(outRec, "MDATA", inRec->recnum);
00584 }
00585 }
00586
00587
00588 if (verbflag) {
00589 wt = getwalltime();
00590 ct = getcputime(&ut, &st);
00591 printf("record %d done, %.2f ms wall time, %.2f ms cpu time\n",
00592 irec, wt - wt1, ct - ct1);
00593 }
00594
00595
00596 free(Bx); free(By); free(Bz); free(dBt);
00597 if (bitmap != NULL) { free(bitmap); bitmap = NULL; }
00598 if (maskQuery != NULL) { free(maskQuery); maskQuery = NULL; }
00599 if (trec_str != NULL) { free(trec_str); trec_str = NULL; }
00600
00601 }
00602
00603 drms_close_records(inRS, DRMS_FREE_RECORD);
00604 drms_close_records(outRS, DRMS_INSERT_RECORD);
00605
00606 if (verbflag) {
00607 wt = getwalltime();
00608 ct = getcputime(&ut, &st);
00609 printf("total time spent: %.2f ms wall time, %.2f ms cpu time\n",
00610 wt - wt0, ct - ct0);
00611 }
00612
00613
00614
00615 return(DRMS_SUCCESS);
00616 }