00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <time.h>
00010 #include <math.h>
00011 #include <sys/time.h>
00012 #include <sys/resource.h>
00013 #include <mkl_lapack.h>
00014 #include "jsoc_main.h"
00015 #include "fstats.h"
00016 #include "drms_dsdsapi.h"
00017 #include "projection.h"
00018
00019 #define ARRLENGTH(ARR) (sizeof(ARR)/sizeof(ARR[0]))
00020 #define QUAL_NODATA (0x80000000)
00021
00022 #define PI (M_PI)
00023 #define RADSINDEG (PI/180)
00024 #define ARCSECSINRAD (3600*180/PI)
00025 #define DAYSINYEAR (365.2425)
00026 #define SECSINDAY (86400)
00027 #define TAU_A (499.004783806) // light travel time in seconds, = 1 AU/c
00028
00029 #define TCARR (25.38) // days
00030 #define RTRUE (6.96000000e8) // meters
00031 #define AU (149597870691) // meters/au
00032
00033 #define MAXLEN (256)
00034 #define NO_DATASET (-1)
00035 #define NO_IMAGE (-1)
00036 #define kMAX_SKIPERRMSG 1024
00037 #define kMAXROWS 65536
00038
00039 #define kNOTSPECIFIED "not specified"
00040
00041
00042 double dsecnd();
00043
00044 typedef enum
00045 {
00046 V2HStatus_Success,
00047 V2HStatus_MissingParameter,
00048 V2HStatus_IllegalTimeFormat,
00049 V2HStatus_TimeConvFailed,
00050 V2HStatus_Unimplemented,
00051 V2HStatus_IllegalOrientation
00052 } V2HStatus_t;
00053
00054 char *module_name = "undistortmdi";
00055 char *cvsinfo_undistortmdi = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/undistortmdi.c,v 1.4 2013/05/03 21:05:08 tplarson Exp $";
00056
00057 ModuleArgs_t module_args[] =
00058 {
00059 {ARG_STRING, "in", "", "input data records"},
00060 {ARG_STRING, "out", "", "output data series"},
00061 {ARG_STRING, "segin", kNOTSPECIFIED, "name of input segment if not using segment 0"},
00062 {ARG_STRING, "segout", kNOTSPECIFIED, "name of output segment if not using segment 0"},
00063 {ARG_STRING, "histlink", "HISTORY", "name of link to ancillary dataseries for processing metadata"},
00064 {ARG_STRING, "srclink", "SRCDATA", "name of link to source data"},
00065 {ARG_INT, "PERM", "1", "set to 0 for transient records, nonzero for permanent records"},
00066 {ARG_INT, "VERB", "1", "option for level of verbosity: 0=only error and warning messages; >0=print messages outside of loop; >1=print messages inside loop; >2=debugging output", ""},
00067 {ARG_INT, "OUTCOLS", "4096", "number of output columns"},
00068 {ARG_INT, "OUTROWS", "4096", "number of output rows"},
00069 {ARG_FLOAT, "MAPRMAX", "1.1", "maximum image radius", ""},
00070 {ARG_INT, "RMAXFLAG", "1", "set to nonzero to set output to DRMS_MISSING outside MAPRMAX, otherwise uses 0.0 outside MAPRMAX"},
00071 {ARG_INT, "INTERPO", "1", "option for interpolation: 0=bilinear; 1=cubic convolution", ""},
00072 {ARG_FLOAT, "OUTSCALE", "1.0", "bscale to use for output", ""},
00073 {ARG_FLOAT, "OUTBIAS", "0.0", "bzero to use for output", ""},
00074 {ARG_INT, "DISTORT", "0", "option for distortion correction: 0=none; 1=full disk(fd) data; 2=vector-weighted(vw) data", ""},
00075 {ARG_FLOAT, "CUBIC", "7.06E-9", "cubic distortion in fd units", ""},
00076 {ARG_FLOAT, "TILTALPHA","2.59", "tilt of CCD, degrees", ""},
00077 {ARG_FLOAT, "TILTBETA", "56.0", "direction of CCD tilt, degrees", ""},
00078 {ARG_FLOAT, "TILTFEFF", "12972.629", "effective focal length", ""},
00079 {ARG_INT, "DATASIGN", "0", "value to multiply data; set to 0 to take DATASIGN from keyword, or 1.0 if not found", ""},
00080 {ARG_INT, "MAXMISSVALS", "0", "if >0, this becomes threshold on MISSVALS from keyword", ""},
00081 {ARG_FLOAT, "SOLAR_P", "999.0", "P-angle; if unset, taken from keywords", ""},
00082 {ARG_FLOAT, "PSIGN", "1.0", "sign of SOLAR_P", ""},
00083 {ARG_FLOAT, "PERR", "0.0", "fixed P-angle error, likely -0.22", ""},
00084 {ARG_FLOAT, "IERR", "0.0", "error in Carrington inclination, likely -0.10", ""},
00085 {ARG_TIME, "REF_TB0", "2001.06.06_06:57:22_TAI", "reference time for computing correction to P and B angles, roughly when B0=0", ""},
00086 {ARG_END}
00087 };
00088
00089 #include "imageinterp.c"
00090 #include "saveparm.c"
00091 #include "timing.c"
00092 #include "set_history.c"
00093
00094 static inline void ParameterDef(int status,
00095 char *pname,
00096 double defaultp,
00097 double *p,
00098 int iRec,
00099 int verbflag)
00100 {
00101
00102 if (status != 0)
00103 {
00104 *p = defaultp;
00105 if (verbflag)
00106 fprintf(stderr, "WARNING: default value %g used for %s, iRec = %d, status = %d\n", defaultp, pname, iRec, status);
00107 }
00108 }
00109
00110
00111 #define PARAMETER_ERROR(PNAME) \
00112 if (status != DRMS_SUCCESS) \
00113 { \
00114 CreateBlankRecord(inrec, outrec, quality); \
00115 fprintf(stderr, \
00116 "SKIP: error getting keyword %s: iRec = %d, status = %d, T_REC = %s, recnum = %lld\n", \
00117 PNAME, \
00118 iRec, \
00119 status, \
00120 trecstr, \
00121 inrec->recnum); \
00122 if (inarr) drms_free_array(inarr); \
00123 if (outarr) drms_free_array(outarr); \
00124 if (orientation) free(orientation); \
00125 continue; \
00126 }
00127
00128
00129
00130 static void CreateBlankRecord(DRMS_Record_t *inrec, DRMS_Record_t *outrec, int quality)
00131 {
00132
00133
00134 quality = quality | QUAL_NODATA;
00135 drms_copykey(outrec, inrec, "T_REC");
00136 drms_setkey_int(outrec, "QUALITY", quality);
00137 drms_close_record(outrec, DRMS_INSERT_RECORD);
00138 }
00139
00140
00141 int DoIt(void)
00142 {
00143
00144 int newstat = 0;
00145 int status = DRMS_SUCCESS;
00146 V2HStatus_t vstat = V2HStatus_Success;
00147
00148 const char *orientationdef = "SESW ";
00149 char *orientation = NULL;
00150 int paramsign;
00151 int longitude_shift, velocity_correction, interpolation, apodization;
00152 int mag_correction;
00153 int mag_offset;
00154 int row;
00155 int mapped_lmax, sinb_divisions, mapcols, maprows, nmax, nmin;
00156 int length[2];
00157 int carrStretch = 0;
00158 float diffrotA = 0.0;
00159 float diffrotB = 0.0;
00160 float diffrotC = 0.0;
00161 double tobs, tmearth, tref, trefb0;
00162 double smajor, sminor, sangle;
00163 double xscale, yscale, imagescale;
00164 int xpixels, ypixels, pixels;
00165 double obs_vr, obs_vw, obs_vn;
00166 double b0, bmax, bmin, sinBdelta;
00167 double longmax, longmin, longmax_adjusted, longmin_adjusted, longinterval;
00168 double p0, p, rmax;
00169 double ierr, perr, psign;
00170 double x0, y0;
00171 double obsdist, longshift, obsl0, refl0, mapl0, longrate, rtrue, rsun, S;
00172 double rsunDef;
00173 int obsCR;
00174 int apel;
00175 double apinner, apwidth, apx, apy;
00176 double scale, bias;
00177 double colsperdeg;
00178
00179 int quality, NaN_beyond_rmax, nRecs;
00180 double satrot, instrot;
00181 double dsignout, vsign;
00182 int distsave;
00183 double cubsave, tiltasave, tiltbsave, tiltfsave;
00184 TIME trec, tnow, UNIX_epoch = -220924792.000;
00185 char trecstr[100];
00186
00187 LIBPROJECTION_Dist_t distP;
00188 DRMS_Segment_t *segin = NULL;
00189 DRMS_Segment_t *segout = NULL;
00190 DRMS_Array_t *inarr = NULL;
00191 DRMS_Array_t *outarr = NULL;
00192 DRMS_Record_t *inrec = NULL;
00193 DRMS_Record_t *outrec = NULL;
00194 DRMS_Type_t usetype = DRMS_TYPE_FLOAT;
00195 DRMS_RecLifetime_t lifetime;
00196
00197 long long histrecnum=-1;
00198
00199 int errbufstat=setvbuf(stderr, NULL, _IONBF, BUFSIZ);
00200 int outbufstat=setvbuf(stdout, NULL, _IONBF, BUFSIZ);
00201
00202 struct timeval tv0, tv1, tv;
00203 double ct0, ct1, ct;
00204 double wt0, wt1, wt;
00205 double ut0, ut1, ut;
00206 double st0, st1, st;
00207 double tt0, tt1, tt;
00208
00209 wt0=getwalltime();
00210 getcputime(&ut0, &st0);
00211
00212 gettimeofday(&tv0, NULL);
00213 ct0=dsecnd();
00214 tt0=1000*((double)clock())/CLOCKS_PER_SEC;
00215
00216 char *inRecQuery = (char *)cmdparams_save_str(&cmdparams, "in", &newstat);
00217 char *outSeries = (char *)cmdparams_save_str(&cmdparams, "out", &newstat);
00218
00219 int verbflag = cmdparams_save_int(&cmdparams, "VERB", &newstat);
00220 int maxmissvals = cmdparams_save_int(&cmdparams, "MAXMISSVALS", &newstat);
00221 int permflag = cmdparams_save_int(&cmdparams, "PERM", &newstat);
00222 if (permflag)
00223 lifetime = DRMS_PERMANENT;
00224 else
00225 lifetime = DRMS_TRANSIENT;
00226
00227
00228 interpolation = cmdparams_save_int(&cmdparams, "INTERPO", &newstat);
00229 paramsign = cmdparams_save_int(&cmdparams, "DATASIGN", &newstat);
00230
00231 distsave = cmdparams_save_int(&cmdparams, "DISTORT", &newstat);
00232 cubsave = cmdparams_save_double(&cmdparams, "CUBIC", &newstat);
00233 tiltasave = cmdparams_save_double(&cmdparams, "TILTALPHA", &newstat);
00234 tiltbsave = cmdparams_save_double(&cmdparams, "TILTBETA", &newstat);
00235 tiltfsave = cmdparams_save_double(&cmdparams, "TILTFEFF", &newstat);
00236
00237 scale = cmdparams_save_double(&cmdparams, "OUTSCALE", &newstat);
00238 bias = cmdparams_save_double(&cmdparams, "OUTBIAS", &newstat);
00239 p0 = cmdparams_save_double(&cmdparams, "SOLAR_P", &newstat);
00240 psign = cmdparams_save_double(&cmdparams, "PSIGN", &newstat);
00241 perr = cmdparams_save_double(&cmdparams, "PERR", &newstat);
00242 ierr = cmdparams_save_double(&cmdparams, "IERR", &newstat);
00243 trefb0 = cmdparams_save_time(&cmdparams, "REF_TB0", &newstat);
00244 rmax = cmdparams_save_double(&cmdparams, "MAPRMAX", &newstat);
00245 NaN_beyond_rmax = cmdparams_save_int(&cmdparams, "RMAXFLAG", &newstat);
00246
00247 SetDistort(distsave, cubsave, tiltasave, tiltbsave, tiltfsave, &distP);
00248
00249 mapcols = cmdparams_save_int(&cmdparams, "OUTCOLS", &newstat);
00250 maprows = cmdparams_save_int(&cmdparams, "OUTROWS", &newstat);
00251
00252 length[0] = mapcols;
00253 length[1] = maprows;
00254
00255 char *segnamein = (char *)cmdparams_save_str(&cmdparams, "segin", &newstat);
00256 char *segnameout = (char *)cmdparams_save_str(&cmdparams, "segout", &newstat);
00257 int seginflag = strcmp(kNOTSPECIFIED, segnamein);
00258 int segoutflag = strcmp(kNOTSPECIFIED, segnameout);
00259
00260 char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat);
00261 char *srclinkname = (char *)cmdparams_save_str(&cmdparams, "srclink", &newstat);
00262
00263 if (newstat)
00264 {
00265 fprintf(stderr, "ERROR: problem with input arguments, status = %d, diagnosis follows\n", newstat);
00266 cpsave_decode_error(newstat);
00267 return 1;
00268 }
00269 else if (savestrlen != strlen(savestr))
00270 {
00271 fprintf(stderr, "ERROR: problem with savestr, savestrlen = %d, strlen(savestr) = %d\n", savestrlen, (int)strlen(savestr));
00272 return 1;
00273 }
00274
00275
00276 DRMS_Record_t *tempoutrec = drms_create_record(drms_env,
00277 outSeries,
00278 DRMS_TRANSIENT,
00279 &status);
00280
00281 if (status != DRMS_SUCCESS)
00282 {
00283 fprintf(stderr,"ERROR: couldn't open a record in output dataseries %s, status = %d\n", outSeries, status);
00284 return 1;
00285 }
00286
00287 DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname);
00288 DRMS_Link_t *srclink = hcon_lookup_lower(&tempoutrec->links, srclinkname);
00289
00290 if (histlink != NULL)
00291 {
00292 histrecnum=set_history(histlink);
00293 if (histrecnum < 0)
00294 {
00295 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00296 return 1;
00297 }
00298 }
00299 else
00300 {
00301 fprintf(stderr,"WARNING: could not find history link in output dataseries\n");
00302 }
00303
00304 int itest;
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
00322
00323
00324 DRMS_RecordSet_t *inRecSet = drms_open_records(drms_env, inRecQuery, &status);
00325 if (status != DRMS_SUCCESS || inRecSet == NULL)
00326 {
00327 fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);
00328 return 1;
00329 }
00330
00331 nRecs = inRecSet->n;
00332 if (nRecs == 0)
00333 {
00334 printf("WARNING: input recordset contains no records\nmodule %s successful completion\n", cmdparams.argv[0]);
00335 return 1;
00336 }
00337
00338 if (verbflag)
00339 printf("input recordset opened, nRecs = %d\n",nRecs);
00340
00341
00342
00343 char *inchecklist[] = {"T_REC", "QUALITY", "T_OBS", "CRLT_OBS", "CRLN_OBS",
00344 "CDELT1", "CDELT2"};
00345
00346 DRMS_Record_t *tempinrec = inRecSet->records[0];
00347 for (itest=0; itest < ARRLENGTH(inchecklist); itest++)
00348 {
00349 DRMS_Keyword_t *inkeytest = hcon_lookup_lower(&tempinrec->keywords, inchecklist[itest]);
00350 if (!inkeytest)
00351 {
00352 fprintf(stderr, "ERROR: required input keyword %s is missing\n", inchecklist[itest]);
00353 return 1;
00354 }
00355 }
00356
00357
00358 int iRec;
00359 int error=0;
00360 int nsuccess=0;
00361 for (iRec = 0; iRec < nRecs; iRec++)
00362 {
00363 if (verbflag > 1)
00364 {
00365 wt1=getwalltime();
00366 getcputime(&ut1, &st1);
00367 gettimeofday(&tv1, NULL);
00368 ct1=dsecnd();
00369 tt1=1000*((double)clock())/CLOCKS_PER_SEC;
00370 printf("processing record %d\n", iRec);
00371 }
00372 inrec = inRecSet->records[iRec];
00373
00374
00375 outrec = drms_create_record(drms_env,
00376 outSeries,
00377 lifetime,
00378 &status);
00379
00380 if (status != DRMS_SUCCESS || outrec==NULL)
00381 {
00382 fprintf(stderr,"ERROR: unable to open record in output dataseries, status = %d\n", status);
00383 error=2;
00384 break;
00385 }
00386
00387 if (histlink)
00388 drms_setlink_static(outrec, histlinkname, histrecnum);
00389
00390 if (srclink)
00391 drms_setlink_static(outrec, srclinkname, inrec->recnum);
00392
00393
00394 if (segoutflag)
00395 segout = drms_segment_lookup(outrec, segnameout);
00396 else
00397 segout = drms_segment_lookupnum(outrec, 0);
00398
00399
00400 outarr = drms_array_create(usetype, 2, length, NULL, &status);
00401
00402 if (!segout || !outarr || status != DRMS_SUCCESS)
00403 {
00404 fprintf(stderr, "ERROR: problem with output segment or array: iRec = %d, status = %d\n", iRec, status);
00405 if (outarr)
00406 drms_free_array(outarr);
00407 error=1;
00408 break;
00409 }
00410
00411 trec = drms_getkey_time(inrec, "T_REC", &status);
00412 if (status != DRMS_SUCCESS)
00413 {
00414 fprintf(stderr,
00415 "SKIP: error getting prime keyword %s: iRec = %d, status = %d, recnum = %lld\n",
00416 "T_REC",
00417 iRec,
00418 status,
00419 inrec->recnum);
00420 drms_free_array(outarr);
00421 continue;
00422 }
00423 sprint_time(trecstr, trec, "TAI", 0);
00424
00425 quality = drms_getkey_int(inrec, "QUALITY", &status);
00426 PARAMETER_ERROR("QUALITY")
00427
00428
00429
00430 if (quality & QUAL_NODATA)
00431 {
00432 CreateBlankRecord(inrec, outrec, quality);
00433 fprintf(stderr,"SKIP: record rejected based on quality = %d: iRec = %d, T_REC = %s, recnum = %lld\n", quality, iRec, trecstr, inrec->recnum);
00434 drms_free_array(outarr);
00435 continue;
00436 }
00437
00438 if (seginflag)
00439 segin = drms_segment_lookup(inrec, segnamein);
00440 else
00441 segin = drms_segment_lookupnum(inrec, 0);
00442
00443 if (segin)
00444 inarr = drms_segment_read(segin, usetype, &status);
00445
00446 if (!segin || !inarr || status != DRMS_SUCCESS)
00447 {
00448
00449 fprintf(stderr, "ERROR: problem with input segment or array: iRec = %d, status = %d, T_REC = %s, recnum = %lld \n", iRec, status, trecstr, inrec->recnum);
00450 drms_free_array(outarr);
00451 if (inarr)
00452 drms_free_array(inarr);
00453 error=1;
00454 break;
00455 }
00456
00457 if (maxmissvals > 0)
00458 {
00459 int missvals = drms_getkey_int(inrec, "MISSVALS", &status);
00460 if (status == DRMS_ERROR_UNKNOWNKEYWORD)
00461 {
00462 fprintf(stderr, "ERROR: required keyword %s missing, iRec = %d, T_REC = %s, recnum = %lld\n", "MISSVALS", iRec, trecstr, inrec->recnum);
00463 drms_free_array(inarr);
00464 drms_free_array(outarr);
00465 free(orientation);
00466 error=1;
00467 break;
00468 }
00469 PARAMETER_ERROR("MISSVALS")
00470 if (missvals > maxmissvals)
00471 {
00472 CreateBlankRecord(inrec, outrec, quality);
00473 fprintf(stderr, "SKIP: %d pixels MISSING, max allowed is %d: iRec = %d, status = %d, T_REC = %s, recnum = %lld\n", missvals, maxmissvals, iRec, status, trecstr, inrec->recnum);
00474 drms_free_array(inarr);
00475 drms_free_array(outarr);
00476 free(orientation);
00477 continue;
00478 }
00479 }
00480
00481 tobs = drms_getkey_time(inrec, "T_OBS", &status);
00482 PARAMETER_ERROR("T_OBS")
00483
00484
00485 b0 = drms_getkey_double(inrec, "CRLT_OBS", &status);
00486 PARAMETER_ERROR("CRLT_OBS")
00487
00488
00489 obsl0 = drms_getkey_double(inrec, "CRLN_OBS", &status);
00490 PARAMETER_ERROR("CRLN_OBS")
00491
00492 if (p0 == 999.0)
00493 {
00494
00495
00496
00497
00498
00499
00500
00501
00502 double crota = drms_getkey_double(inrec, "CROTA2", &status);
00503 PARAMETER_ERROR("CROTA2")
00504 p=-crota;
00505 }
00506 else
00507 {
00508 p = p0;
00509 }
00510
00511
00512
00513
00514 p = psign * p ;
00515
00516
00517
00518
00519
00520
00521
00522 b0 = b0 + ierr * sin((tobs - trefb0) / 31557600. * 2 * PI);
00523
00524
00525
00526
00527 p = p + perr - ierr * cos((tobs - trefb0) / 31557600. * 2 * PI);
00528
00529 if (paramsign != 0)
00530 {
00531 vsign = paramsign;
00532 }
00533 else
00534 {
00535 vsign = drms_getkey_double(inrec, "DATASIGN", &status);
00536 ParameterDef(status, "DATASIGN", 1.0, &vsign, iRec, 1);
00537 }
00538
00539 xscale = drms_getkey_double(inrec, "CDELT1", &status);
00540 PARAMETER_ERROR("CDELT1")
00541 yscale = drms_getkey_double(inrec, "CDELT2", &status);
00542 PARAMETER_ERROR("CDELT2")
00543
00544 if (xscale != yscale)
00545 {
00546 fprintf(stderr, "ERROR: %s != %s not supported, iRec = %d, T_REC = %s, recnum = %lld \n", "CDELT1", "CDELT2", iRec, trecstr, inrec->recnum);
00547 drms_free_array(inarr);
00548 error++;
00549 continue;
00550 }
00551 imagescale=xscale;
00552
00553
00554 obsdist = drms_getkey_double(inrec, "DSUN_OBS", &status);
00555 obsdist /= AU;
00556 ParameterDef(status, "DSUN_OBS", 1.0, &obsdist, iRec, 1);
00557 S = rtrue / obsdist;
00558
00559
00560 rsun = drms_getkey_double(inrec, "R_SUN", &status);
00561 if (status != DRMS_SUCCESS)
00562 {
00563 rsun = drms_getkey_double(inrec, "RSUN_OBS", &status);
00564 if (status != DRMS_SUCCESS)
00565 rsun = ARCSECSINRAD * S / sqrt(1.0 - S * S) / imagescale;
00566 else
00567 rsun /= imagescale;
00568 }
00569
00570 xpixels = inarr->axis[0];
00571 ypixels = inarr->axis[1];
00572
00573
00574 x0 = drms_getkey_double(inrec, "CRPIX1", &status);
00575 ParameterDef(status, "CRPIX1", xpixels / 2, &x0, iRec, 1);
00576 x0 -= 1.0;
00577
00578
00579 y0 = drms_getkey_double(inrec, "CRPIX2", &status);
00580 ParameterDef(status, "CRPIX2", ypixels / 2, &y0, iRec, 1);
00581 y0 -= 1.0;
00582
00583 if (status = imageinterp((float *)inarr->data,
00584 (float *)outarr->data,
00585 xpixels,
00586 ypixels,
00587 x0,
00588 y0,
00589 p * RADSINDEG,
00590 rsun,
00591 rmax,
00592 NaN_beyond_rmax,
00593 interpolation,
00594 mapcols,
00595 maprows,
00596 vsign,
00597 &distP))
00598 {
00599 CreateBlankRecord(inrec, outrec, quality);
00600 fprintf(stderr, "failure in imageinterp: iRec = %d, status = %d, T_REC = %s, recnum = %lld\n", iRec, status, trecstr, inrec->recnum);
00601 drms_free_array(inarr);
00602 drms_free_array(outarr);
00603 free(orientation);
00604 continue;
00605 }
00606
00607 drms_setkey_int(outrec, "TOTVALS", maprows*mapcols);
00608 set_statistics(segout, outarr, 1);
00609
00610
00611 outarr->bzero=bias;
00612 outarr->bscale=scale;
00613 segout->axis[0]=outarr->axis[0];
00614 segout->axis[1]=outarr->axis[1];
00615 drms_segment_write(segout, outarr, 0);
00616
00617
00618 drms_copykey(outrec, inrec, "T_REC");
00619 drms_setkey_int(outrec, "QUALITY", quality);
00620
00621 double xratio = (double)mapcols/xpixels;
00622 double yratio = (double)maprows/ypixels;
00623
00624 drms_setkey_float(outrec, "CRPIX1", (drms_getkey_float(inrec, "CRPIX1", &status)-0.5)*xratio+0.5);
00625 drms_setkey_float(outrec, "CRPIX2", (drms_getkey_float(inrec, "CRPIX2", &status)-0.5)*yratio+0.5);
00626 drms_setkey_float(outrec, "CDELT1", drms_getkey_float(inrec, "CDELT1", &status)/xratio);
00627 drms_setkey_float(outrec, "CDELT2", drms_getkey_float(inrec, "CDELT2", &status)/yratio);
00628 drms_setkey_float(outrec, "CROTA2", 0.0);
00629 drms_setkey_float(outrec, "X0", (x0 + 0.5)*xratio - 0.5);
00630 drms_setkey_float(outrec, "Y0", (y0 + 0.5)*yratio - 0.5);
00631 drms_setkey_float(outrec, "IM_SCALE", imagescale/xratio);
00632 drms_setkey_float(outrec, "R_SUN", rsun*xratio);
00633 drms_setkey_float(outrec, "RSUN_OBS", drms_getkey_float(inrec, "RSUN_OBS", &status)*xratio);
00634
00635 drms_copykey(outrec, inrec, "CRVAL1");
00636 drms_copykey(outrec, inrec, "CRVAL2");
00637 drms_copykey(outrec, inrec, "T_OBS");
00638 drms_copykey(outrec, inrec, "CADENCE");
00639 drms_copykey(outrec, inrec, "EXPTIME");
00640 drms_copykey(outrec, inrec, "CRLT_OBS");
00641 drms_copykey(outrec, inrec, "CRLN_OBS");
00642 drms_copykey(outrec, inrec, "CAR_ROT");
00643 drms_copykey(outrec, inrec, "DSUN_OBS");
00644 drms_copykey(outrec, inrec, "R_SUN_REF");
00645 drms_copykey(outrec, inrec, "OBS_VR");
00646 drms_copykey(outrec, inrec, "OBS_VW");
00647 drms_copykey(outrec, inrec, "OBS_VN");
00648
00649 dsignout=vsign*drms_getkey_double(inrec, "DATASIGN", &status);
00650 if (status != DRMS_SUCCESS) dsignout=vsign;
00651 dsignout/=fabs(dsignout);
00652 drms_setkey_int(outrec, "DATASIGN", (int)dsignout);
00653
00654 tnow = (double)time(NULL);
00655 tnow += UNIX_epoch;
00656 drms_setkey_time(outrec, "DATE", tnow);
00657
00658 drms_close_record(outrec, DRMS_INSERT_RECORD);
00659
00660 if (verbflag > 1)
00661 {
00662 wt=getwalltime();
00663 getcputime(&ut, &st);
00664 gettimeofday(&tv, NULL);
00665 ct=dsecnd();
00666 tt=1000*((double)clock())/CLOCKS_PER_SEC;
00667 fprintf(stdout,
00668 "record %d done, %f ms wall time, %f ms cpu time\n",
00669 iRec,
00670 (float)((tv.tv_sec * 1000000.0 + tv.tv_usec -
00671 (tv1.tv_sec * 1000000.0 + tv1.tv_usec)) / 1000.0),
00672 (ct-ct1)*1000);
00673 printf("test: %f ms wall time, %f ms cpu time\n", wt-wt1, (ut+st)-(ut1+st1));
00674 printf("clock: %f ms\n",tt-tt1);
00675 }
00676
00677 drms_free_array(inarr);
00678 drms_free_array(outarr);
00679 free(orientation);
00680 nsuccess++;
00681
00682 }
00683
00684 if (inRecSet)
00685 drms_close_records(inRecSet, DRMS_FREE_RECORD);
00686
00687 if (error == 1)
00688 drms_close_record(outrec, DRMS_FREE_RECORD);
00689
00690 wt=getwalltime();
00691 getcputime(&ut, &st);
00692
00693 gettimeofday(&tv, NULL);
00694 ct=dsecnd();
00695 tt=1000*((double)clock())/CLOCKS_PER_SEC;
00696 if (verbflag)
00697 {
00698 printf("number of records processed = %d\n", nsuccess);
00699 fprintf(stdout, "total time spent: %f ms wall time, %f ms cpu time\n",
00700 (float)((tv.tv_sec * 1000000.0 + tv.tv_usec - (tv0.tv_sec * 1000000.0 + tv0.tv_usec)) / 1000.0),
00701 (ct-ct0)*1000);
00702 printf("test: %f ms wall time, %f ms cpu time\n", wt-wt0, (ut+st)-(ut0+st0));
00703 printf("clock: %f ms\n",tt-tt0);
00704 if (!error)
00705 printf("module %s successful completion\n", cmdparams.argv[0]);
00706 }
00707
00708 return 0;
00709
00710 }