00001 #include <string.h>
00002 #include "jsoc_main.h"
00003 #include "drms.h"
00004 #include "drms_names.h"
00005
00006 #define NOT_SPECIFIED "***Not Specified***"
00007 #define DIE(msg) {fprintf(stderr,"$$$$ %s: %s\n", module_name, msg); return 1;}
00008
00009 #define NBINS 1048576
00010 static int hist[NBINS];
00011
00012 typedef enum { WL94A, WL131A, WL171A, WL193A, WL211A, WL304A, WL335A,
00013 WL1600A, WL1700A, WL4500A } wl_type;
00014 int image_magrotate(void *, int, int, int, float, float, float, float,
00015 void **, int *, int *, int, int);
00016
00017 int image_cutout(void *, int, int, int, float, float, float, float,
00018 void **, int, int, float, float, int, int);
00019
00020 int cutout_corners(int win, int hin, int wout, int hout, float rotang,
00021 float mag, float dx, float dy, float xco, float yco,
00022 float *cx, float *cy);
00023
00024 int set_statistics(DRMS_Segment_t *seg, DRMS_Array_t *arr, int mode);
00025
00026 ModuleArgs_t module_args[] =
00027 {
00028 {ARG_STRING, "dsinp", NOT_SPECIFIED, "Input series query"},
00029 {ARG_STRING, "dsout", NOT_SPECIFIED, "Output series"},
00030 {ARG_STRING, "mpt", NOT_SPECIFIED, "Master Pointing Table series"},
00031 {ARG_STRING, "despike", "1", "remove cosmic ray hits"},
00032 {ARG_STRING, "rescale", "1", "rescale to fixed plate scale"},
00033 {ARG_STRING, "regrid", "1", "regrid type 0: nearest neighbor, 1: bicubic"},
00034 {ARG_STRING, "scale_to", "0.6", "rescale to fixed plate scale"},
00035 {ARG_STRING, "xc", "0.0", "cutout x center WRT Sun Center in pixels"},
00036 {ARG_STRING, "yc", "0.0", "cutout y center WRT Sun Center in pixels"},
00037 {ARG_STRING, "wide", "4096", "cutout width in pixels"},
00038 {ARG_STRING, "high", "4096", "cutout height in pixels"},
00039 {ARG_STRING, "do_stretchmarks", "0", "fill in empty pixels created"},
00040 {ARG_STRING, "with_keys", "0", "write segment with all FITS keywords"},
00041 {ARG_STRING, "requestid", NOT_SPECIFIED, "Export request id if this program was invoked by the export system."},
00042 {ARG_FLAG, "c", "0", "crop input data at the limb, only for HMI"},
00043 {ARG_FLAG, "h", "0", "Print usage message and quit"},
00044 {ARG_FLAG, "v", "0", "verbose flag"},
00045 {ARG_END}
00046 };
00047
00048 char *module_name = "aia_lev1p5";
00049 int despike = 1, rescale = 1, regridtype = 1, verbose = 0, do_stretchmarks = 0;
00050 int withkeys = 0;
00051 float scale_to = 0.6, scale_by;
00052
00053 int nice_intro(int help)
00054 {
00055 int usage = cmdparams_get_int(&cmdparams, "h", NULL) != 0;
00056 verbose = cmdparams_get_int(&cmdparams, "v", NULL) != 0;
00057 if (usage || help) {
00058 printf("aia_lev1p5 {-h} {-v} dsinp=series_record_spec dsout=output_series\n"
00059 " -c: crop input data at the limb, only for HMI\n"
00060 " -h: print this message\n"
00061 " -v: verbose\n"
00062 "despike=0, do not despike, default=1, despike\n"
00063 "rescale=0, do not rescale to fixed plate scale, default=1\n"
00064 "regrid=0, nearest neighbor, default=1, bicubic\n"
00065 "scale_to=0.6, rescale to fixed plate scale, default=0.6\n"
00066 "xc=0.0, cutout x center WRT Sun Center in pixels, default=0.0\n"
00067 "yc=0.0, cutout y center WRT Sun Center in pixels, default=0.0\n"
00068 "wide=4096, cutout width in pixels, default=4096\n"
00069 "high=4096, cutout height in pixels, default=4096\n"
00070 "do_stretchmarks=1, fill in empty pixels created, default=0\n"
00071 "with_keys=1, write segment with all FITS keywords, default=0\n"
00072 "mpt=<master pointing table series>, default=NULL (use WCS keywords)\n"
00073 "dsinp=<recordset query> as <series>{[record specifier]} - required\n"
00074 "dsout=<series> - required\n");
00075 return(1);
00076 }
00077 return(0);
00078 }
00079
00080 void sprint_time_ISO (char *tstring, TIME t)
00081 {
00082 sprint_at(tstring,t);
00083 tstring[4] = tstring[7] = '-';
00084 tstring[10] = 'T';
00085 tstring[19] = '\0';
00086 }
00087
00088 int ndx2wl(int ndx)
00089 {
00090 static int wl[] = { 94, 131, 171, 193, 211, 304, 335, 1600, 1700, 4500 };
00091 if (-1 < ndx && ndx < 10) return wl[ndx];
00092 return -1;
00093 }
00094
00095 int wl2ndx(int wl)
00096 {
00097 switch (wl) {
00098 case 94: return WL94A;
00099 case 131: return WL131A;
00100 case 171: return WL171A;
00101 case 193: return WL193A;
00102 case 211: return WL211A;
00103 case 304: return WL304A;
00104 case 335: return WL335A;
00105 case 1600: return WL1600A;
00106 case 1700: return WL1700A;
00107 case 4500: return WL4500A;
00108 default: return -1;
00109 }
00110 }
00111
00112 int DoIt ()
00113 {
00114 int irec, iseg, nrecs, nsegs, status, is_aia=0, wide = 4096, high = 4096;
00115 char *dsinp, *seriesout, now_str[100];
00116 float crpix1, crpix2, cdelt1, cdelt2, crota2;
00117 float mag = 1.0, dx, dy, xc, yc;
00118 DRMS_Record_t *inprec, *outrec, *mptrec=NULL;
00119 DRMS_RecordSet_t *inprs, *mptrs=NULL;
00120 DRMS_Array_t *inparr=NULL, *outarr=NULL;
00121 DRMS_Segment_t *inpseg, *outseg;
00122 const char *reqid = NULL;
00123 const char *mpt = NULL;
00124 char mpr_str[256];
00125 char *allvers = NULL;
00126 char **sets = NULL;
00127 DRMS_RecordSetType_t *settypes = NULL;
00128 char **snames = NULL;
00129 char **filts = NULL;
00130 int nsets = 0;
00131 DRMS_RecQueryInfo_t rsinfo;
00132 TIME tstart, tstop;
00133 char mptqs[256];
00134 const char *x0names[] = { "A_094_X0", "A_131_X0", "A_171_X0", "A_193_X0",
00135 "A_211_X0", "A_304_X0", "A_335_X0", "A_1600_X0", "A1700_X0", "A_4500_X0"
00136 };
00137 const char *y0names[] = { "A_094_Y0", "A_131_Y0", "A_171_Y0", "A_193_Y0",
00138 "A_211_Y0", "A_304_Y0", "A_335_Y0", "A_1600_Y0", "A1700_Y0", "A_4500_Y0"
00139 };
00140 if (nice_intro(0)) return(0);
00141 dsinp = strdup(cmdparams_get_str(&cmdparams, "dsinp", NULL));
00142 seriesout = strdup(cmdparams_get_str(&cmdparams, "dsout", NULL));
00143 int crop = cmdparams_get_int(&cmdparams, "c", NULL) != 0;
00144 mpt = strdup(cmdparams_get_str(&cmdparams, "mpt", NULL));
00145 if (strcmp(dsinp, NOT_SPECIFIED)==0) DIE("dsinp argument is required");
00146 if (strcmp(seriesout, NOT_SPECIFIED)==0) DIE("dsout argument is required");
00147 if (strcmp(mpt, NOT_SPECIFIED)==0) mpt = NULL;
00148 despike = cmdparams_get_int(&cmdparams, "despike", NULL);
00149 rescale = cmdparams_get_int(&cmdparams, "rescale", NULL);
00150 scale_to = cmdparams_get_float(&cmdparams, "scale_to", NULL);
00151 regridtype = cmdparams_get_int(&cmdparams, "regrid", NULL);
00152 xc = cmdparams_get_float(&cmdparams, "xc", NULL);
00153 yc = cmdparams_get_float(&cmdparams, "yc", NULL);
00154 wide = cmdparams_get_int(&cmdparams, "wide", NULL);
00155 high = cmdparams_get_int(&cmdparams, "high", NULL);
00156 do_stretchmarks = cmdparams_get_int(&cmdparams, "do_stretchmarks", NULL);
00157 withkeys = cmdparams_get_int(&cmdparams, "with_keys", NULL);
00158 reqid = cmdparams_get_str(&cmdparams, "requestid", NULL);
00159
00160 if (strcmp(reqid, NOT_SPECIFIED) == 0)
00161 {
00162 reqid = NULL;
00163 }
00164
00165
00166 if (strchr(seriesout, '[') || strchr(seriesout, ','))
00167 {
00168 DIE("Invalid output record-set specification.");
00169 }
00170
00171 if (strstr(dsinp, "aia")) is_aia = 1;
00172 if (!is_aia && mpt) DIE("Master Pointing Table param only applicable to AIA data.");
00173 inprs = drms_open_records(drms_env, dsinp, &status);
00174 if (status) DIE("cant open recordset query");
00175 drms_stage_records(inprs, 1, 0);
00176 nrecs = inprs->n;
00177 printf("%d records\n", nrecs);
00178 for (irec=0; irec<nrecs; irec++) {
00179 int save_rec = 1, qualmask;
00180 qualmask = (is_aia ? 0x800100f0 : 0x80000000);
00181 inprec = inprs->records[irec];
00182 outrec = drms_create_record(drms_env, seriesout, DRMS_PERMANENT, &status);
00183 if (status) DIE("cant create recordset");
00184 status = drms_copykeys(outrec, inprec, 0, kDRMS_KeyClass_Explicit);
00185 if (status)
00186 DIE("Error in drms_copykeys()");
00187 {
00188 int fsn, quallev0, trec_off=0;
00189 double tr_step;
00190 double gaex_obs, gaey_obs, gaez_obs, haex_obs, haey_obs, haez_obs;
00191 long long tr_index;
00192 TIME t_rec, t_obs, tr_epoch;
00193
00194 sprint_time_ISO(now_str, CURRENT_SYSTEM_TIME);
00195 drms_setkey_string(outrec, "DATE", now_str);
00196 t_obs = drms_getkey_time(inprec, "T_OBS", &status);
00197 if (status) DIE("T_OBS not found!");
00198 if (is_aia) {
00199 if ( 0 == drms_setkey_time(outrec, "T_REC", t_obs)) {
00200 tr_index = drms_getkey_longlong(outrec, "T_REC_index", &status);
00201 if (status) DIE("T_REC_index not found!");
00202 tr_step = drms_getkey_double(outrec, "T_REC_step", &status);
00203 if (status) DIE("T_REC_step not found!");
00204 tr_epoch = drms_getkey_time(outrec, "T_REC_epoch", &status);
00205 if (status) DIE("T_REC_epoch not found!");
00206 t_rec = tr_epoch + tr_index*tr_step;
00207 drms_setkey_time(outrec, "T_REC", t_rec);
00208 }
00209 gaex_obs = drms_getkey_double(inprec, "GAEX_OBS", &status);
00210 if (status) {
00211 gaex_obs = drms_getkey_double(inprec, "GCIEC_X", &status);
00212 if(!status) drms_setkey_double(outrec, "GAEX_OBS", gaex_obs);
00213 }
00214 gaey_obs = drms_getkey_double(inprec, "GAEY_OBS", &status);
00215 if (status) {
00216 gaey_obs = drms_getkey_double(inprec, "GCIEC_Y", &status);
00217 if(!status) drms_setkey_double(outrec, "GAEY_OBS", gaey_obs);
00218 }
00219 gaez_obs = drms_getkey_double(inprec, "GAEZ_OBS", &status);
00220 if (status) {
00221 gaez_obs = drms_getkey_double(inprec, "GCIEC_Z", &status);
00222 if(!status) drms_setkey_double(outrec, "GAEZ_OBS", gaez_obs);
00223 }
00224 haex_obs = drms_getkey_double(inprec, "HAEX_OBS", &status);
00225 if (status) {
00226 haex_obs = drms_getkey_double(inprec, "HCIEC_X", &status);
00227 if(!status) drms_setkey_double(outrec, "HAEX_OBS", haex_obs);
00228 }
00229 haey_obs = drms_getkey_double(inprec, "HAEY_OBS", &status);
00230 if (status) {
00231 haey_obs = drms_getkey_double(inprec, "HCIEC_Y", &status);
00232 if(!status) drms_setkey_double(outrec, "HAEY_OBS", haey_obs);
00233 }
00234 haez_obs = drms_getkey_double(inprec, "HAEZ_OBS", &status);
00235 if (status) {
00236 haez_obs = drms_getkey_double(inprec, "HCIEC_Z", &status);
00237 if(!status) drms_setkey_double(outrec, "HAEZ_OBS", haez_obs);
00238 }
00239 }
00240
00241
00242 if (reqid && drms_keyword_lookup(outrec, "RequestID", 0))
00243 {
00244 if (DRMS_SUCCESS != drms_setkey_string(outrec, "RequestID", reqid))
00245 {
00246 DIE("Unable to set RequestID in output record.");
00247 }
00248 }
00249
00250 if (t_obs < 0) save_rec = 0;
00251 if (mpt) {
00252 int wi, wl;
00253 if (mptrs == NULL) {
00254 snprintf(mptqs, 256, "%s[?%f BETWEEN T_START and T_STOP?]",
00255 mpt, t_obs);
00256 mptrs = drms_open_records(drms_env, mptqs, &status);
00257 if (status) DIE("Can't open MPT recordset");
00258 if(mptrs->n) mptrec = mptrs->records[0];
00259 else DIE("No MPT record found for T_OBS");
00260 tstart = drms_getkey_time(mptrec, "T_START", &status);
00261 tstop = drms_getkey_time(mptrec, "T_STOP", &status);
00262 } else if (tstart > t_obs || t_obs > tstop) {
00263 drms_close_records(mptrs, DRMS_FREE_RECORD);
00264 snprintf(mptqs, 256, "%s[?%f BETWEEN T_START and T_STOP?]",
00265 mpt, t_obs);
00266 mptrs = drms_open_records(drms_env, mptqs, &status);
00267 if (status) DIE("Can't open MPT recordset");
00268 if(mptrs->n) mptrec = mptrs->records[0];
00269 else DIE("No MPT record found for T_OBS");
00270 tstart = drms_getkey_time(mptrec, "T_START", &status);
00271 tstop = drms_getkey_time(mptrec, "T_STOP", &status);
00272 }
00273 wl = drms_getkey_int(inprec, "WAVELNTH", &status);
00274 wi = wl2ndx(wl);
00275 crpix1 = drms_getkey_float(mptrec, x0names[wi], &status);
00276 crpix2 = drms_getkey_float(mptrec, y0names[wi], &status);
00277 sprintf(mpr_str, "%s[:#%lld]", mpt, mptrec->recnum);
00278 drms_setkey_string(outrec, "MPO_REC", mpr_str);
00279 } else {
00280 crpix1 = drms_getkey_float(inprec, "CRPIX1", &status);
00281 if (status) DIE("CRPIX1 not found!");
00282 crpix2 = drms_getkey_float(inprec, "CRPIX2", &status);
00283 if (status) DIE("CRPIX2 not found!");
00284 }
00285 cdelt1 = drms_getkey_float(inprec, "CDELT1", &status);
00286 if (status) DIE("CDELT1 not found!");
00287 cdelt2 = drms_getkey_float(inprec, "CDELT2", &status);
00288 if (status) DIE("CDELT2 not found!");
00289 if (rescale) {
00290 mag = fabs(cdelt1 / scale_to);
00291 cdelt1 /= mag;
00292 cdelt2 /= mag;
00293 drms_setkey_float(outrec, "CDELT1", cdelt1);
00294 drms_setkey_float(outrec, "CDELT2", cdelt2);
00295 }
00296 crota2 = drms_getkey_float(inprec, "CROTA2", &status);
00297 if (status) DIE("CROTA2 not found!");
00298 if (is_aia) {
00299 quallev0 = drms_getkey_int(inprec, "QUALLEV0", &status);
00300 if (status) DIE("QUALLEV0 not found!");
00301 if (quallev0 & qualmask) save_rec = 0;
00302 }
00303 }
00304 nsegs = hcon_size(&inprec->segments);
00305 for (iseg=0; iseg<1; iseg++) {
00306
00307 #ifdef JPS_STATS
00308 void *output_array = NULL;
00309 #else
00310 float *output_array = NULL;
00311 int seg0_nx, seg0_ny;
00312 #endif
00313 int i, ix, iy, n, m, dtyp, nx, ny, npix;
00314 axislen_t beg[2], end[2], out_axis[2];
00315 char *filename = NULL, *inpsegname = NULL;
00316 float *fval, tmpval, z = 16383.5, cx[4], cy[4];
00317 double s, s2, s3, s4, ss, datamin, datamax, datamedn, datamean;
00318 double data_rms, dataskew, datakurt, dtmp;
00319 inpseg = drms_segment_lookupnum(inprec, iseg);
00320 inpsegname = inpseg->info->name;
00321 filename = inpseg->filename;
00322 #ifdef JPS_STATS
00323 if (0 == iseg) {
00324 n = nx = inpseg->axis[0]; m = ny = inpseg->axis[1];
00325 #else
00326 if (0 == iseg) {
00327 seg0_nx = inpseg->axis[0];
00328 seg0_ny = inpseg->axis[1];
00329 }
00330 n = nx = inpseg->axis[0];
00331 m = ny = inpseg->axis[1];
00332 if (nx == seg0_nx && ny == seg0_ny) {
00333 #endif
00334 dx = (n + 1.0)*0.5 - crpix1; dy = (m + 1.0)*0.5 - crpix2;
00335 cutout_corners(n, m, wide, high, crota2, mag, dx, dy, xc, yc, cx, cy);
00336 beg[0] = end[0] = cx[0]; beg[1] = end[1] = cy[0];
00337 for (i=1; i<4; i++) {
00338 if (cx[i] < beg[0]) beg[0] = cx[i];
00339 if (cy[i] < beg[1]) beg[1] = cy[i];
00340 if (cx[i] > end[0]) end[0] = cx[i];
00341 if (cy[i] > end[1]) end[1] = cy[i];
00342 } beg[0] -= 2; beg[1] -= 2; end[0] += 2; end[1] += 2;
00343 if (beg[0] < 0) beg[0] = 0;
00344 if (beg[0] > (nx-1)) beg[0] = nx - 1;
00345 if (beg[1] < 0) beg[1] = 0;
00346 if (beg[1] > (ny-1)) beg[1] = ny - 1;
00347 if (end[0] > (nx-1)) end[0] = nx - 1;
00348 if (end[0] < 0) end[0] = 0;
00349 if (end[1] > (ny-1)) end[1] = ny - 1;
00350 if (end[1] < 0) end[1] = 0;
00351 crpix1 -= beg[0]; crpix2 -= beg[1];
00352 outseg = drms_segment_lookupnum(outrec, iseg);
00353 if (!outseg) DIE("Cant get output segment");
00354 inparr = drms_segment_readslice(inpseg, DRMS_TYPE_FLOAT,
00355 beg, end, &status);
00356 if (status) DIE("drms_segment_read failed!");
00357 dtyp = 3;
00358 n = inparr->axis[0]; m = inparr->axis[1];
00359
00360 dx = (n + 1.0)*0.5 - crpix1; dy = (m + 1.0)*0.5 - crpix2;
00361
00362 if (is_aia)
00363 {
00364 fval = inparr->data;
00365 for (ix = 0; ix<n; ix++) {
00366 fval[ix] = 0.0;
00367 fval[(m - 1)*n + ix] = 0.0;
00368 }
00369 for (iy = 0; iy<m; iy++) {
00370 fval[iy*n] = 0.0;
00371 fval[iy*n + n - 1] = 0.0;
00372 }
00373 }
00374 if (crop && !is_aia)
00375 {
00376 double crop_limit2 = 0.999;
00377 double rsun_obs = drms_getkey_double(inprec, "RSUN_OBS)", &status);
00378 if (status) DIE("RSUN_OBS key value is required!");
00379 double rsun2 = rsun_obs/cdelt1*rsun_obs/cdelt1;
00380 for (iy = 0; iy<n; iy++)
00381 for (ix = 0; ix<n; ix++)
00382 {
00383 float *Ip = (float *)inparr->data + iy*nx + ix;
00384 if (drms_ismissing_float(*Ip))
00385 continue;
00386 double y = iy - crpix2 + 1;
00387 double x = ix - crpix1 + 1;
00388 double dist2 = y*y + x*x;
00389 if (dist2/rsun2 > crop_limit2)
00390 *Ip = DRMS_MISSING_FLOAT;
00391 }
00392 }
00393
00394 status = image_cutout( inparr->data, n, m, dtyp, crota2,
00395 mag, dx, dy, &(void *)output_array, wide, high, xc, yc,
00396 regridtype, do_stretchmarks);
00397 if (status) DIE("image_magrotate failed!");
00398 out_axis[0] = wide; out_axis[1] = high;
00399 #ifdef JPS_STATS
00400 if (verbose) printf("using JPS_STATS section of code XXXXXX\n");
00401 if (is_aia) {
00402 outarr = drms_array_create(DRMS_TYPE_INT, 2, out_axis,
00403 NULL, &status);
00404 } else {
00405 outarr = drms_array_create(DRMS_TYPE_FLOAT, 2, out_axis,
00406 NULL, &status);
00407 }
00408
00409 if (status) DIE("drms_array_create failed!");
00410 s = s2 = s3 = s4 = 0.0; datamin = 9.9e9; datamax = -9.9e9, npix = 0;
00411 for (i=0; i<wide*high; i++) {
00412 if (is_aia) {
00413 if (*((float *)(output_array)+i)<0) *((float *)(output_array)+i)=0;
00414 if (*((float *)(output_array)+i)>z) *((float *)(output_array)+i)=z;
00415 *((int *)(outarr->data)+i) = *((float *)(output_array)+i);
00416 } else {
00417 *((float *)(outarr->data)+i) = *((float *)(output_array)+i);
00418 }
00419 tmpval = *((float *)(output_array)+i);
00420 if (finite(tmpval)) {
00421 npix++;
00422 if (tmpval < datamin) datamin = tmpval;
00423 if (tmpval > datamax) datamax = tmpval;
00424 s += tmpval;
00425 s2 += tmpval*tmpval;
00426 s3 += tmpval*tmpval*tmpval;
00427
00428 s4 += tmpval*tmpval*tmpval*tmpval;
00429 }
00430 }
00431 drms_setkey_int(outrec, "DATAMIN", (int) datamin);
00432 drms_setkey_int(outrec, "DATAMAX", (int) datamax);
00433 s /= npix;
00434 drms_setkey_float(outrec, "DATAMEAN", s);
00435 drms_setkey_float(outrec, "DATAMEDN", DRMS_MISSING_FLOAT);
00436 ss = s*s;
00437 s2 /= npix;
00438 s3 /= npix;
00439 s4 /= npix;
00440 if (npix > 1) {
00441 dtmp = npix * (s2-ss) / (npix-1);
00442 data_rms = sqrt(dtmp);
00443 drms_setkey_float(outrec, "DATARMS", (float) data_rms);
00444 if (dtmp > 0.0) {
00445 dataskew = (s3 - s * (3*s2 - 2*ss)) / (dtmp*data_rms);
00446 drms_setkey_float(outrec, "DATASKEW", (float) dataskew);
00447 datakurt = (s4 - 4*s*s3 + 3*ss*(2*s2-ss)) / (dtmp*dtmp) - 3;
00448 drms_setkey_float(outrec, "DATAKURT", (float) datakurt);
00449 }
00450 }
00451 #else
00452 outarr = drms_array_create(DRMS_TYPE_FLOAT, 2, out_axis, NULL, &status);
00453 if (status) DIE("drms_array_create failed!");
00454 for (i=0; i<wide*high; i++) {
00455 if (is_aia) {
00456 if (*(output_array+i)<0) *(output_array+i)=0;
00457 if (*(output_array+i)>z) *(output_array+i)=z;
00458 }
00459 *((float *)(outarr->data)+i) = *(output_array+i);
00460 }
00461 if (verbose) printf("calling setstats XXXXX\n");
00462 set_statistics(outseg, outarr, 1);
00463 #endif
00464 drms_setkey_float(outrec, "CROTA2", 0.0);
00465 drms_setkey_float(outrec, "CRPIX1", (wide + 1.0)*0.5 - xc);
00466 drms_setkey_float(outrec, "CRPIX2", (high + 1.0)*0.5 - yc);
00467 drms_setkey_float(outrec, "X0", 0.0);
00468 drms_setkey_float(outrec, "Y0", 0.0);
00469
00470 outarr->bzero = inparr->bzero;
00471 outarr->bscale = inparr->bscale;
00472 if (withkeys) {
00473 drms_segment_writewithkeys(outseg, outarr, 0);
00474 } else {
00475 drms_segment_write(outseg, outarr, 0);
00476 }
00477 if (inparr) drms_free_array(inparr);
00478 if (output_array) free(output_array);
00479 if (outarr) drms_free_array(outarr);
00480 }
00481 else printf("XXXXX skip segment %d since dims (%d,%d) do not match first segment of record.\n",iseg,ny,nx);
00482 }
00483 if (save_rec) drms_close_record(outrec, DRMS_INSERT_RECORD);
00484 else drms_close_record(outrec, DRMS_FREE_RECORD);
00485 }
00486
00487 return 0;
00488 }