version 1.3, 2012/09/18 16:03:27
|
version 1.9, 2017/03/31 19:43:36
|
|
|
#define MODES(L) ((((L)+1)*(L))/2) |
char *cvsinfo_jretile_manytofew = "cvsinfo: $Header$"; |
#define MINIMUM(X,Y) (((X)<(Y))?(X):(Y)) |
|
#define MAXIMUM(X,Y) (((X)>(Y))?(X):(Y)) |
|
| |
int jretile_manytofew(void) | int jretile_manytofew(void) |
{ | { |
Line 31 int jretile_manytofew(void) |
|
Line 29 int jretile_manytofew(void) |
|
int mapmmax=-1; | int mapmmax=-1; |
int sinbdivs=-1; | int sinbdivs=-1; |
double cadence=0; | double cadence=0; |
|
int i; |
| |
TIME tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */ | TIME tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */ |
char tstartstr[100], tscrstr[100]; | char tstartstr[100], tscrstr[100]; |
Line 68 int jretile_manytofew(void) |
|
Line 67 int jretile_manytofew(void) |
|
lifetime = DRMS_PERMANENT; | lifetime = DRMS_PERMANENT; |
else | else |
lifetime = DRMS_TRANSIENT; | lifetime = DRMS_TRANSIENT; |
|
unsigned short calverkey = (unsigned short)cmdparams_save_int(&cmdparams, "CALVERKEY", &newstat); |
| |
char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat); | char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat); |
| |
Line 121 int jretile_manytofew(void) |
|
Line 121 int jretile_manytofew(void) |
|
} | } |
| |
// set up ancillary dataseries for processing metadata | // set up ancillary dataseries for processing metadata |
char *cvsinfo = strdup("$Header$"); |
// char *cvsinfo = strdup("$Header$"); |
DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname); | DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname); |
if (histlink != NULL) | if (histlink != NULL) |
{ | { |
histrecnum=set_history(histlink, cvsinfo); |
histrecnum=set_history(histlink); |
if (histrecnum < 0) | if (histrecnum < 0) |
{ | { |
drms_close_record(tempoutrec, DRMS_FREE_RECORD); | drms_close_record(tempoutrec, DRMS_FREE_RECORD); |
Line 197 int jretile_manytofew(void) |
|
Line 197 int jretile_manytofew(void) |
|
if (outkeytest != NULL && outkeytest->info->recscope == 1) | if (outkeytest != NULL && outkeytest->info->recscope == 1) |
sinbdivsout=drms_getkey_int(tempoutrec, "SINBDIVS", &status); | sinbdivsout=drms_getkey_int(tempoutrec, "SINBDIVS", &status); |
| |
|
float apinnerout=0.0; |
|
float apwidthout=0.0; |
|
outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "APINNER"); |
|
if (outkeytest != NULL && outkeytest->info->recscope == 1) |
|
apinnerout=drms_getkey_float(tempoutrec, "APINNER", &status); |
|
outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "APWIDTH"); |
|
if (outkeytest != NULL && outkeytest->info->recscope == 1) |
|
apwidthout=drms_getkey_float(tempoutrec, "APWIDTH", &status); |
|
|
drms_close_record(tempoutrec, DRMS_FREE_RECORD); | drms_close_record(tempoutrec, DRMS_FREE_RECORD); |
| |
char *inchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "T_STEP"}; | char *inchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "T_STEP"}; |
Line 210 int jretile_manytofew(void) |
|
Line 219 int jretile_manytofew(void) |
|
fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status); | fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status); |
return 1; | return 1; |
} | } |
nrecsin = inrecset->n; |
// nrecsin = inrecset->n; |
|
nrecsin = drms_count_records(drms_env, inrecquery, &status); |
|
if (status != DRMS_SUCCESS) |
|
{ |
|
fprintf(stderr, "ERROR: problem counting input records: status = %d, nrecs = %d\n", status, nrecsin); |
|
return 1; |
|
} |
| |
if (verbflag) | if (verbflag) |
printf("input recordset opened, nrecs = %d\n", nrecsin); | printf("input recordset opened, nrecs = %d\n", nrecsin); |
Line 256 int jretile_manytofew(void) |
|
Line 271 int jretile_manytofew(void) |
|
} | } |
| |
inkeytest = hcon_lookup_lower(&inrec->keywords, "SINBDIVS"); | inkeytest = hcon_lookup_lower(&inrec->keywords, "SINBDIVS"); |
if (outkeytest != NULL) |
if (inkeytest != NULL) |
sinbdivs=drms_getkey_int(inrec, "SINBDIVS", &status); | sinbdivs=drms_getkey_int(inrec, "SINBDIVS", &status); |
if (sinbdivsout != -1 && sinbdivsout != sinbdivs) | if (sinbdivsout != -1 && sinbdivsout != sinbdivs) |
{ | { |
Line 265 int jretile_manytofew(void) |
|
Line 280 int jretile_manytofew(void) |
|
return 1; | return 1; |
} | } |
| |
|
float apinner=0.0; |
|
float apwidth=0.0; |
|
inkeytest = hcon_lookup_lower(&inrec->keywords, "APINNER"); |
|
if (inkeytest != NULL) |
|
apinner=drms_getkey_float(inrec, "APINNER", &status); |
|
if (apinnerout != 0.0 && (int)(10000*apinnerout) != (int)(10000*apinner)) |
|
{ |
|
fprintf(stderr, "ERROR: input APINNER does not equal output APINNER, in=%d, out=%d\n",apinner, apinnerout); |
|
drms_close_records(inrecset, DRMS_FREE_RECORD); |
|
return 1; |
|
} |
|
|
|
inkeytest = hcon_lookup_lower(&inrec->keywords, "APWIDTH"); |
|
if (inkeytest != NULL) |
|
apwidth=drms_getkey_float(inrec, "APWIDTH", &status); |
|
if (apinnerout != 0.0 && (int)(10000*apwidthout) != (int)(10000*apwidth)) |
|
{ |
|
fprintf(stderr, "ERROR: input APWIDTH does not equal output APWIDTH, in=%d, out=%d\n", apwidth, apwidth); |
|
drms_close_records(inrecset, DRMS_FREE_RECORD); |
|
return 1; |
|
} |
|
|
status=drms_stage_records(inrecset, 1, 0); | status=drms_stage_records(inrecset, 1, 0); |
if (status != DRMS_SUCCESS) | if (status != DRMS_SUCCESS) |
{ | { |
Line 287 int jretile_manytofew(void) |
|
Line 324 int jretile_manytofew(void) |
|
return 1; | return 1; |
} | } |
| |
/* |
unsigned long long calversout, calvers; |
irecout=0; |
int fixflagarr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
for (iset=0; iset < ntimechunks; iset++) |
for (i=0;i<16;i++) |
{ |
{ |
tstartout=tstart + iset * chunksecs; |
if (getbits(calverkey,i,1)) |
tstopout=tstartout+chunksecs; |
fixflagarr[i]=1; |
|
|
for (lchunk = lchunkfirst; lchunk <= lchunklast; lchunk++) |
|
{ |
|
lminout = lchunk * lchunksize; |
|
lmaxout = lminout + lchunksize - 1; |
|
lminout = MAXIMUM(lminout,lmin); |
|
lmaxout = MINIMUM(lmaxout,lmax); |
|
|
|
outrec = outrecset->records[irecout]; |
|
if (histlink) |
|
drms_setlink_static(outrec, histlinkname, histrecnum); |
|
drms_setkey_int(outrec, "LMIN", lminout); |
|
drms_setkey_int(outrec, "LMAX", lmaxout); |
|
drms_setkey_time(outrec, "T_START", tstartout); |
|
drms_setkey_time(outrec, "T_STOP", tstopout); |
|
drms_setkey_time(outrec, "T_OBS", tstartout+chunksecs/2); |
|
drms_setkey_int(outrec, "NDT", ndt); |
|
|
|
irecout++; |
|
} |
|
} | } |
*/ |
|
long long calversout, calvers; |
unsigned int *nybblearrout = (unsigned int *)malloc(16*nrecsout*sizeof(unsigned int)); |
int calversunset=1; |
int *mixflagarr = (int *)calloc(16*nrecsout,sizeof(int)); |
|
int *calverssetarr = (int *)calloc(16*nrecsout,sizeof(int)); |
|
unsigned long long *calversoutarr = (unsigned long long *)malloc(nrecsout*sizeof(unsigned long long)); |
| |
int firsttimethrough=1; | int firsttimethrough=1; |
int *nskiparr=(int *)calloc(nrecsout,sizeof(int)); | int *nskiparr=(int *)calloc(nrecsout,sizeof(int)); |
Line 330 int jretile_manytofew(void) |
|
Line 349 int jretile_manytofew(void) |
|
lmaxin=drms_getkey_int(inrec, "LMAX", &status); | lmaxin=drms_getkey_int(inrec, "LMAX", &status); |
tstepin=tstopin-tstartin; | tstepin=tstopin-tstartin; |
| |
|
if (verbflag > 1) |
|
{ |
|
sprint_time(tscrstr, tstartin, "TAI", 0); |
|
printf("processing input %d, tstart = %s, lmin = %d, lmax = %d\n", irecin, tscrstr, lminin, lmaxin); |
|
} |
|
|
quality=drms_getkey_int(inrec, "QUALITY", &status); | quality=drms_getkey_int(inrec, "QUALITY", &status); |
if (status != DRMS_SUCCESS || (quality & QUAL_NODATA)) //may want stricter test on quality here | if (status != DRMS_SUCCESS || (quality & QUAL_NODATA)) //may want stricter test on quality here |
{ | { |
if (verbflag > 2) | if (verbflag > 2) |
{ | { |
sprint_time(tscrstr, tstartin, "TAI", 0); |
// sprint_time(tscrstr, tstartin, "TAI", 0); |
fprintf(stderr, "WARNING: input data not used due to quality: T_START = %s, LMIN = %d, LMAX = %d, recnum = %lld, irec = %d, status = %d, quality = %08x\n", |
printf("SKIP: input data not used due to quality: T_START = %s, LMIN = %d, LMAX = %d, recnum = %lld, irec = %d, status = %d, quality = %08x\n", |
tscrstr, lminin, lmaxin, inrec->recnum, irecin, status, quality); | tscrstr, lminin, lmaxin, inrec->recnum, irecin, status, quality); |
} | } |
for (irecout=0; irecout < nrecsout; irecout++) | for (irecout=0; irecout < nrecsout; irecout++) |
Line 345 int jretile_manytofew(void) |
|
Line 370 int jretile_manytofew(void) |
|
// continue; | // continue; |
} | } |
| |
if (calversunset) |
|
{ |
|
calversout=drms_getkey_longlong(inrec, "CALVER64", &status); |
|
if (status != DRMS_SUCCESS) |
|
calversout = 0; |
|
calversunset=0; |
|
} |
|
|
|
calvers=drms_getkey_longlong(inrec, "CALVER64", &status); |
|
if (status != DRMS_SUCCESS) |
|
calvers = 0; |
|
|
|
if (calvers != calversout) |
|
{ |
|
fprintf(stderr, "ERROR: input data has mixed CALVER64: %lld and %lld, recnum = %lld, histrecnum = %lld\n", calversout, calvers, inrec->recnum, histrecnum); |
|
return 0; |
|
} |
|
|
|
if (seginflag) | if (seginflag) |
segin = drms_segment_lookup(inrec, segnamein); | segin = drms_segment_lookup(inrec, segnamein); |
else | else |
Line 384 int jretile_manytofew(void) |
|
Line 391 int jretile_manytofew(void) |
|
inptr=(float *)(inarr->data); | inptr=(float *)(inarr->data); |
} | } |
| |
|
|
|
calvers=drms_getkey_longlong(inrec, "CALVER64", &status); |
|
if (status != DRMS_SUCCESS) |
|
calvers = 0; |
|
|
irecout=0; | irecout=0; |
for (iset=0; iset < ntimechunks; iset++) | for (iset=0; iset < ntimechunks; iset++) |
{ | { |
Line 404 int jretile_manytofew(void) |
|
Line 416 int jretile_manytofew(void) |
|
if (histlink != NULL) | if (histlink != NULL) |
drms_setlink_static(outrec, histlinkname, histrecnum); | drms_setlink_static(outrec, histlinkname, histrecnum); |
drms_copykeys(outrec, inrec, 0, kDRMS_KeyClass_Explicit); | drms_copykeys(outrec, inrec, 0, kDRMS_KeyClass_Explicit); |
// copykeys takes care of MAPMMAX, SINBDIVS, CALVER64, etc. that should be constant across the input |
// copykeys takes care of MAPMMAX, SINBDIVS, etc. that should be constant across the input |
drms_setkey_int(outrec, "LMIN", lminout); | drms_setkey_int(outrec, "LMIN", lminout); |
drms_setkey_int(outrec, "LMAX", lmaxout); | drms_setkey_int(outrec, "LMAX", lmaxout); |
drms_setkey_time(outrec, "T_START", tstartout); | drms_setkey_time(outrec, "T_START", tstartout); |
Line 419 int jretile_manytofew(void) |
|
Line 431 int jretile_manytofew(void) |
|
continue; | continue; |
} | } |
| |
|
int index0 = 16*irecout; |
|
|
|
if (!calverssetarr[irecout]) |
|
{ |
|
calversoutarr[irecout]=calvers; |
|
calverssetarr[irecout]=1; |
|
for (i=0;i<16;i++) |
|
nybblearrout[index0 + i]=getbits(calvers,4*i+3,4); |
|
} |
|
|
|
for (i=0;i<16;i++) |
|
{ |
|
int nybble=getbits(calvers,4*i+3,4); |
|
if (fixflagarr[i]) |
|
{ |
|
if (nybble != nybblearrout[index0 + i]) |
|
{ |
|
fprintf(stderr, "ERROR: input data has mixed values for field %d of CALVER64: %d and %d, recnum = %lld, histrecnum = %lld\n", i, nybblearrout[i], nybble, inrec->recnum, histrecnum); |
|
return 0; |
|
} |
|
} |
|
else |
|
{ |
|
if (nybble < nybblearrout[index0 + i]) |
|
nybblearrout[index0 + i]=nybble; |
|
} |
|
} |
|
|
|
if (!mixflagarr[irecout] && (quality & QUAL_MIXEDCALVER || calvers != calversoutarr[irecout])) |
|
mixflagarr[irecout]=1; |
|
|
if (segoutflag) | if (segoutflag) |
segout = drms_segment_lookup(outrec, segnameout); | segout = drms_segment_lookup(outrec, segnameout); |
else | else |
Line 506 int jretile_manytofew(void) |
|
Line 549 int jretile_manytofew(void) |
|
{ | { |
drms_setkey_int(outrec, "QUALITY", QUAL_NODATA); | drms_setkey_int(outrec, "QUALITY", QUAL_NODATA); |
} | } |
|
else if (mixflagarr[irecout]) |
|
{ |
|
drms_setkey_int(outrec, "QUALITY", QUAL_MIXEDCALVER); |
|
nsegments++; |
|
} |
else | else |
{ | { |
drms_setkey_int(outrec, "QUALITY", 0); | drms_setkey_int(outrec, "QUALITY", 0); |
nsegments++; | nsegments++; |
} | } |
| |
|
for (i=0;i<16;i++) |
|
calversout=setbits(calversout,4*i+3,4,nybblearrout[16*irecout + i]); |
|
drms_setkey_longlong(outrec, "CALVER64", calversout); |
|
|
tnow = (double)time(NULL); | tnow = (double)time(NULL); |
tnow += UNIX_epoch; | tnow += UNIX_epoch; |
drms_setkey_time(outrec, "DATE", tnow); | drms_setkey_time(outrec, "DATE", tnow); |