ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/globalhs/apps/jretile_fewtomany.c
Revision: 1.8
Committed: Fri Mar 31 20:02:28 2017 UTC (6 years, 5 months ago) by tplarson
Content type: text/plain
Branch: MAIN
CVS Tags: globalhs_version_23, globalhs_version_22, globalhs_version_21, globalhs_version_20, Ver_LATEST, globalhs_version_24, Ver_9-41, Ver_9-5, globalhs_version_19, Ver_9-1, Ver_9-2, globalhs_version_17, globalhs_version_18, Ver_9-4, Ver_9-3, HEAD
Changes since 1.7: +6 -6 lines
Log Message:
get rid of compiler warnings

File Contents

# Content
1 char *cvsinfo_jretile_fewtomany = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile_fewtomany.c,v 1.7 2017/03/31 19:43:36 tplarson Exp $";
2
3 int jretile_fewtomany(void)
4 {
5 int newstat = 0;
6 int status = DRMS_SUCCESS;
7
8 char *inrecquery = NULL;
9 char *outseries = NULL;
10 char *segnamein = NULL;
11 char *segnameout = NULL;
12 DRMS_RecordSet_t *inrecset = NULL;
13 DRMS_RecordSet_t *outrecset = NULL;
14 int irecin, irecout, nrecsin=0, nrecsout=0, nlchunks;
15 DRMS_Record_t *inrec = NULL;
16 DRMS_Record_t *outrec = NULL;
17 DRMS_Segment_t *segin = NULL;
18 DRMS_Segment_t *segout = NULL;
19 DRMS_Array_t *inarr = NULL;
20 DRMS_Array_t *outarr = NULL;
21 DRMS_RecLifetime_t lifetime;
22 DRMS_Type_t usetype = DRMS_TYPE_FLOAT;
23 int length[2], startind[2], endind[2];
24 float *inptr, *outptr;
25 long long histrecnum=-1;
26 int quality;
27 int mapmmax=-1;
28 int sinbdivs=-1;
29 double cadence=0;
30 int i;
31
32 TIME tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */
33 char tstartstr[100];
34
35 double tstart, tepoch, tstep, tround, tstop, tstartin, tstopin, tstepin, tstartuse, tstopuse, nseconds, chunksecs;
36 char *ttotal, *tchunk;
37 int ndt;
38 int lmin, lmax, lminin, lmaxin, lminuse, lmaxuse, lchunk, lchunksize, lchunkfirst, lchunklast;
39 int ntimechunks, nmodes, npts, imode, itime;
40 int out_time_offset, out_modes_offset, out_offset, in_time_offset, in_modes_offset, in_offset, out_index, in_index;
41 int iset, lminout, lmaxout;
42 double tstartout, tstopout;
43 float *arrptr;
44 int nrecords, nsegments, nskip;
45
46 int errbufstat=setvbuf(stderr, NULL, _IONBF, BUFSIZ);
47 int outbufstat=setvbuf(stdout, NULL, _IONBF, BUFSIZ);
48
49 double wt0, wt1, wt2, wt3, wt;
50 double ut0, ut1, ut2, ut3, ut;
51 double st0, st1, st2, st3, st;
52 double ct0, ct1, ct2, ct3, ct;
53
54 wt0=getwalltime();
55 ct0=getcputime(&ut0, &st0);
56
57 inrecquery = (char *)cmdparams_save_str(&cmdparams, "in", &newstat);
58 outseries = (char *)cmdparams_save_str(&cmdparams, "out", &newstat);
59 segnamein = (char *)cmdparams_save_str(&cmdparams, "segin", &newstat);
60 segnameout = (char *)cmdparams_save_str(&cmdparams, "segout", &newstat);
61 int seginflag = strcmp(kNOTSPECIFIED, segnamein);
62 int segoutflag = strcmp(kNOTSPECIFIED, segnameout);
63 int verbflag = cmdparams_save_int(&cmdparams, "VERB", &newstat);
64 int permflag = cmdparams_save_int(&cmdparams, "PERM", &newstat);
65 if (permflag)
66 lifetime = DRMS_PERMANENT;
67 else
68 lifetime = DRMS_TRANSIENT;
69 unsigned short calverkey = (unsigned short)cmdparams_save_int(&cmdparams, "CALVERKEY", &newstat);
70
71 char *histlinkname = (char *)cmdparams_save_str(&cmdparams, "histlink", &newstat);
72
73 tstart=cmdparams_save_time(&cmdparams, "TSTART", &newstat);
74 ttotal=(char *)cmdparams_save_str(&cmdparams, "TTOTAL", &newstat);
75 status=drms_names_parseduration(&ttotal, &nseconds, 1);
76 if (status != DRMS_SUCCESS)
77 {
78 // newstat = newstat | CPSAVE_UNKNOWN_ERROR;
79 fprintf(stderr, "ERROR: problem parsing TTOTAL, = %s\n", ttotal);
80 return 1;
81 }
82 tchunk=(char *)cmdparams_save_str(&cmdparams, "TCHUNK", &newstat);
83 if (strcmp(kNOTSPECIFIED, tchunk))
84 {
85 status=drms_names_parseduration(&tchunk, &chunksecs, 1);
86 if (status != DRMS_SUCCESS)
87 newstat = newstat | CPSAVE_UNKNOWN_ERROR;
88 }
89 else
90 chunksecs=0;
91
92 lmin=cmdparams_save_int(&cmdparams, "LMIN", &newstat);
93 lmax=cmdparams_save_int(&cmdparams, "LMAX", &newstat);
94 lchunksize=cmdparams_save_int(&cmdparams, "LCHUNK", &newstat);
95 if (lchunksize == 0)
96 lchunksize=lmax+1;
97
98 if (newstat)
99 {
100 fprintf(stderr, "ERROR: problem with input arguments, status = %d, diagnosis follows\n", newstat);
101 cpsave_decode_error(newstat);
102 return 1;
103 }
104 else if (savestrlen != strlen(savestr))
105 {
106 fprintf(stderr, "ERROR: problem with savestr, savestrlen = %d, strlen(savestr) = %d\n", savestrlen, (int)strlen(savestr));
107 return 1;
108 }
109
110 DRMS_Record_t *tempoutrec = drms_create_record(drms_env,
111 outseries,
112 DRMS_TRANSIENT,
113 &status);
114
115 if (status != DRMS_SUCCESS)
116 {
117 fprintf(stderr,"ERROR: couldn't open a record in output dataseries %s, status = %d\n", outseries, status);
118 return 1;
119 }
120
121 // set up ancillary dataseries for processing metadata
122 // char *cvsinfo = strdup("$Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/jretile_fewtomany.c,v 1.7 2017/03/31 19:43:36 tplarson Exp $");
123 DRMS_Link_t *histlink = hcon_lookup_lower(&tempoutrec->links, histlinkname);
124 if (histlink != NULL)
125 {
126 histrecnum=set_history(histlink);
127 if (histrecnum < 0)
128 {
129 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
130 return 1;
131 }
132 }
133 else
134 {
135 fprintf(stderr,"WARNING: could not find history link in output dataseries\n");
136 }
137
138 // these must be present in the output dataseries and variable, not links or constants
139 // now done in DoIt() that calls this function
140 /*
141 char *outchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "NDT"};
142 int itest;
143 for (itest=0; itest < ARRLENGTH(outchecklist); itest++)
144 {
145 DRMS_Keyword_t *outkeytest = hcon_lookup_lower(&tempoutrec->keywords, outchecklist[itest]);
146 if (outkeytest == NULL || outkeytest->info->islink || outkeytest->info->recscope == 1)
147 {
148 fprintf(stderr, "ERROR: output keyword %s is either missing, constant, or a link\n", outchecklist[itest]);
149 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
150 return 1;
151 }
152 }
153 */
154
155 tepoch=drms_getkey_time(tempoutrec, "T_START_epoch", &status);
156 tstep=drms_getkey_float(tempoutrec, "T_START_step", &status);
157 tround=drms_getkey_float(tempoutrec, "T_START_round", &status);
158 cadence=drms_getkey_float(tempoutrec, "T_STEP", &status);
159 if (fmod(tstart-tepoch,tstep) > tround/2)
160 {
161 fprintf(stderr, "ERROR: output dataseries seems incompatible with input parameters (tstep must divide tstart-tepoch): tstart = %f, tepoch = %f, tstep = %f\n", tstart, tepoch, tstep);
162 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
163 return 1;
164 }
165 if (chunksecs == 0.0)
166 chunksecs = tstep;
167 else if (fmod(chunksecs,tstep))
168 {
169 fprintf(stderr, "ERROR: output dataseries seems incompatible with input parameters (tstep must divide chunksecs): chunksecs = %f, tstep = %f\n", chunksecs, tstep);
170 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
171 return 1;
172 }
173 if (fmod(nseconds,chunksecs) != 0.0)
174 {
175 fprintf(stderr, "ERROR: input parameters seem incompatible (chunksecs must divide nseconds): nseconds = %f, chunksecs = %f\n", nseconds, chunksecs);
176 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
177 return 1;
178 }
179 ntimechunks=nseconds/chunksecs;
180 ndt=chunksecs/cadence;
181 if (verbflag)
182 {
183 printf("%d timechunks, %.1f seconds per chunk\n", ntimechunks, chunksecs);
184 }
185
186 int mapmmaxout=-1;
187 int sinbdivsout=-1;
188 DRMS_Keyword_t *outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "MAPMMAX");
189 if (outkeytest != NULL && outkeytest->info->recscope == 1)
190 mapmmaxout=drms_getkey_int(tempoutrec, "MAPMMAX", &status);
191 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "SINBDIVS");
192 if (outkeytest != NULL && outkeytest->info->recscope == 1)
193 sinbdivsout=drms_getkey_int(tempoutrec, "SINBDIVS", &status);
194
195 float apinnerout=0.0;
196 float apwidthout=0.0;
197 float apinner=0.0;
198 float apwidth=0.0;
199 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "APINNER");
200 if (outkeytest != NULL && outkeytest->info->recscope == 1)
201 apinnerout=drms_getkey_float(tempoutrec, "APINNER", &status);
202 outkeytest = hcon_lookup_lower(&tempoutrec->keywords, "APWIDTH");
203 if (outkeytest != NULL && outkeytest->info->recscope == 1)
204 apwidthout=drms_getkey_float(tempoutrec, "APWIDTH", &status);
205
206 drms_close_record(tempoutrec, DRMS_FREE_RECORD);
207
208
209 char *inchecklist[] = {"T_START", "QUALITY", "LMIN", "LMAX", "T_STEP"};
210 DRMS_Keyword_t *inkeytest;
211 int itest;
212 inrecset = drms_open_records(drms_env, inrecquery, &status);
213 // inrecset = drms_open_recordset(drms_env, inrecquery, &status);
214
215 if (status != DRMS_SUCCESS || inrecset == NULL)
216 {
217 fprintf(stderr, "ERROR: problem opening input recordset: status = %d\n", status);
218 return 1;
219 }
220 nrecsin = inrecset->n;
221
222 if (verbflag)
223 printf("input recordset opened, nrecs = %d\n", nrecsin);
224
225 int noinput=0;
226 if (nrecsin == 0)
227 {
228 printf("WARNING: input recordset contains no records\n");
229 noinput=1;
230 goto skip1;
231 // return 1;
232 }
233
234 inrec = inrecset->records[0];
235 // inrec = drms_recordset_fetchnext(drms_env, inrecset, &fetchstat);
236
237 for (itest=0; itest < ARRLENGTH(inchecklist); itest++)
238 {
239 inkeytest = hcon_lookup_lower(&inrec->keywords, inchecklist[itest]);
240 if (inkeytest == NULL)
241 {
242 fprintf(stderr, "ERROR: required input keyword %s is missing\n", inchecklist[itest]);
243 drms_close_records(inrecset, DRMS_FREE_RECORD);
244 return 1;
245 }
246 }
247
248 if (cadence != drms_getkey_float(inrec, "T_STEP", &status))
249 {
250 fprintf(stderr, "ERROR: input T_STEP does not equal output T_STEP\n");
251 drms_close_records(inrecset, DRMS_FREE_RECORD);
252 return 1;
253 }
254
255 inkeytest = hcon_lookup_lower(&inrec->keywords, "MAPMMAX");
256 if (inkeytest != NULL)
257 mapmmax=drms_getkey_int(inrec, "MAPMMAX", &status);
258 if (mapmmaxout != -1 && mapmmaxout != mapmmax)
259 {
260 fprintf(stderr, "ERROR: input MAPMMAX does not equal output MAPMMAX, in=%d, out=%d\n", mapmmax, mapmmaxout);
261 drms_close_records(inrecset, DRMS_FREE_RECORD);
262 return 1;
263 }
264
265 inkeytest = hcon_lookup_lower(&inrec->keywords, "SINBDIVS");
266 if (inkeytest != NULL)
267 sinbdivs=drms_getkey_int(inrec, "SINBDIVS", &status);
268 if (sinbdivsout != -1 && sinbdivsout != sinbdivs)
269 {
270 fprintf(stderr, "ERROR: input SINBDIVS does not equal output SINBDIVS, in=%d, out=%d\n", sinbdivs, sinbdivsout);
271 drms_close_records(inrecset, DRMS_FREE_RECORD);
272 return 1;
273 }
274
275 inkeytest = hcon_lookup_lower(&inrec->keywords, "APINNER");
276 if (inkeytest != NULL)
277 apinner=drms_getkey_float(inrec, "APINNER", &status);
278 if (apinnerout != 0.0 && (int)(10000*apinnerout) != (int)(10000*apinner))
279 {
280 fprintf(stderr, "ERROR: input APINNER does not equal output APINNER, in=%f, out=%f\n", apinner, apinnerout);
281 drms_close_records(inrecset, DRMS_FREE_RECORD);
282 return 1;
283 }
284
285 inkeytest = hcon_lookup_lower(&inrec->keywords, "APWIDTH");
286 if (inkeytest != NULL)
287 apwidth=drms_getkey_float(inrec, "APWIDTH", &status);
288 if (apinnerout != 0.0 && (int)(10000*apwidthout) != (int)(10000*apwidth))
289 {
290 fprintf(stderr, "ERROR: input APWIDTH does not equal output APWIDTH, in=%f, out=%f\n", apwidth, apwidth);
291 drms_close_records(inrecset, DRMS_FREE_RECORD);
292 return 1;
293 }
294
295
296 status=drms_stage_records(inrecset, 1, 0);
297 if (status != DRMS_SUCCESS)
298 {
299 fprintf(stderr, "ERROR: drms_stage_records returned status = %d\n", status);
300 return 1;
301 }
302
303 skip1:
304
305 nrecords=0;
306 nsegments=0;
307 nskip=0;
308
309 lchunkfirst = lmin/lchunksize;
310 lchunklast = lmax/lchunksize;
311
312 nlchunks = (lchunklast - lchunkfirst) + 1;
313 nrecsout = nlchunks*ntimechunks;
314 outrecset = drms_create_records(drms_env, nrecsout, outseries, lifetime, &status);
315 if (status != DRMS_SUCCESS || outrecset == NULL)
316 {
317 fprintf(stderr,"ERROR: unable to create records record in output dataseries %s, status = %d\n", outseries, status);
318 drms_close_records(inrecset, DRMS_FREE_RECORD);
319 return 1;
320 }
321
322 unsigned long long calversout, calvers;
323 int calversunset=1;
324 int mixflag=0;
325 unsigned int nybblearrout[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
326 int fixflagarr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
327 for (i=0;i<16;i++)
328 {
329 if (getbits(calverkey,i,1))
330 fixflagarr[i]=1;
331 }
332
333 // int firsttimethrough=1;
334 irecout=0;
335 for (iset=0; iset < ntimechunks; iset++)
336 {
337 tstartout=tstart + iset * chunksecs;
338 tstopout=tstartout+chunksecs;
339 sprint_time(tstartstr, tstartout, "TAI", 0);
340
341 if (verbflag)
342 {
343 wt1=getwalltime();
344 ct1=getcputime(&ut1, &st1);
345 printf("processing timechunk %d, tstart = %s\n", iset, tstartstr);
346 }
347
348 for (lchunk = lchunkfirst; lchunk <= lchunklast; lchunk++)
349 {
350 lminout = lchunk * lchunksize;
351 lmaxout = lminout + lchunksize - 1;
352 lminout = MAXIMUM(lminout,lmin);
353 lmaxout = MINIMUM(lmaxout,lmax);
354
355 /*
356 outrec = drms_create_record(drms_env, outseries, lifetime, &status);
357 if (status != DRMS_SUCCESS || outrec == NULL)
358 {
359 fprintf(stderr,"ERROR: unable to open record in output dataseries, status = %d, histrecnum = %lld\n", status, histrecnum);
360 drms_close_records(inrecset, DRMS_FREE_RECORD);
361 return 0;
362 }
363 */
364
365 outrec = outrecset->records[irecout++];
366 if (histlink != NULL)
367 drms_setlink_static(outrec, histlinkname, histrecnum);
368
369 if (verbflag > 1)
370 {
371 wt2=getwalltime();
372 ct2=getcputime(&ut2, &st2);
373 printf(" processing lchunk %d, min = %d, max = %d\n", lchunk-lchunkfirst, lminout, lmaxout);
374 }
375
376 if (noinput)
377 {
378 goto skip2;
379 }
380
381 if (segoutflag)
382 segout = drms_segment_lookup(outrec, segnameout);
383 else
384 segout = drms_segment_lookupnum(outrec, 0);
385
386 length[0]=2*ndt;
387 length[1]=lmaxout*(lmaxout+1)/2+lmaxout - lminout*(lminout+1)/2 + 1;
388 arrptr=(float *)(calloc(length[0]*length[1],sizeof(float)));
389 outarr = drms_array_create(usetype, 2, length, arrptr, &status);
390 if (status != DRMS_SUCCESS || outarr == NULL || segout == NULL)
391 {
392 fprintf(stderr,"ERROR: problem creating output array or segment: length = [%d, %d], status = %d, histrecnum = %lld", length[0], length[1], status, histrecnum);
393 drms_close_records(inrecset, DRMS_FREE_RECORD);
394 drms_close_records(outrecset, DRMS_FREE_RECORD);
395 return 0;
396 }
397 outptr = (float *)(outarr->data);
398
399 nskip=0;
400 mixflag=0;
401 calversunset=1;
402 for (irecin=0; irecin < nrecsin; irecin++)
403 {
404 inrec = inrecset->records[irecin]; //drms_recordset_fetchnext(drms_env, inrecset, &fetchstat);
405 quality=drms_getkey_int(inrec, "QUALITY", &status);
406 if (status != DRMS_SUCCESS || (quality & QUAL_NODATA)) //may want stricter test on quality here
407 {
408 if (verbflag>2) printf("SKIP: input data not used due to quality, irecin = %d, status = %d, quality = %08x\n", irecin, status, quality);
409 nskip++;
410 continue;
411 }
412
413 tstartin=drms_getkey_time(inrec, "T_START", &status);
414 tstopin=drms_getkey_time(inrec, "T_STOP", &status);
415 lminin=drms_getkey_int(inrec, "LMIN", &status);
416 lmaxin=drms_getkey_int(inrec, "LMAX", &status);
417 tstepin=tstopin-tstartin;
418
419 if (tstartin >= tstopout || tstopin <= tstartout || lminin > lmaxout || lmaxin < lminout)
420 {
421 nskip++;
422 continue;
423 }
424
425 if (calversunset)
426 {
427 calversout=drms_getkey_longlong(inrec, "CALVER64", &status);
428 if (status != DRMS_SUCCESS)
429 calversout = 0;
430 calversunset=0;
431 for (i=0;i<16;i++)
432 nybblearrout[i]=getbits(calversout,4*i+3,4);
433 }
434
435 calvers=drms_getkey_longlong(inrec, "CALVER64", &status);
436 if (status != DRMS_SUCCESS)
437 calvers = 0;
438
439 for (i=0;i<16;i++)
440 {
441 int nybble=getbits(calvers,4*i+3,4);
442 if (fixflagarr[i])
443 {
444 if (nybble != nybblearrout[i])
445 {
446 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);
447 return 0;
448 }
449 }
450 else
451 {
452 if (nybble < nybblearrout[i])
453 nybblearrout[i]=nybble;
454 }
455 }
456
457 if (!mixflag && (quality & QUAL_MIXEDCALVER || calvers != calversout))
458 mixflag=1;
459
460 tstartuse=MAXIMUM(tstartout, tstartin);
461 tstopuse= MINIMUM(tstopout, tstopin);
462 lminuse=MAXIMUM(lminout, lminin);
463 lmaxuse=MINIMUM(lmaxout, lmaxin);
464 nmodes=MODES(lmaxuse+1)-MODES(lminuse);
465 npts=(tstopuse - tstartuse)/cadence;
466
467 out_time_offset = (tstartuse - tstartout)/cadence;
468 out_modes_offset = MODES(lminuse) - MODES(lminout);
469 out_offset = 2 * (out_modes_offset * ndt + out_time_offset);
470 in_time_offset = (tstartuse - tstartin)/cadence;
471 in_modes_offset = MODES(lminuse) - MODES(lminin);
472 in_offset = 0; // 2 * (in_modes_offset * tstepin / cadence + in_time_offset);
473 startind[0]=2*in_time_offset;
474 startind[1]=in_modes_offset;
475 endind[0]=2*(in_time_offset + npts) - 1;
476 endind[1]=in_modes_offset + nmodes - 1;
477
478 if (seginflag)
479 segin = drms_segment_lookup(inrec, segnamein);
480 else
481 segin = drms_segment_lookupnum(inrec, 0);
482 if (segin != NULL)
483 // inarr = drms_segment_read(segin, usetype, &status);
484 inarr = drms_segment_readslice(segin, usetype, startind, endind, &status);
485 if (status != DRMS_SUCCESS || inarr == NULL || segin == NULL)
486 {
487 fprintf(stderr, "ERROR: problem reading input segment: tstart = %f, lmin = %d, lmax = %d, irecin = %d, status = %d, histrecnum = %lld\n", tstartin, lminin, lmaxin, irecin, status, histrecnum);
488 drms_close_records(inrecset, DRMS_FREE_RECORD);
489 drms_close_records(outrecset, DRMS_FREE_RECORD);
490 return 0;
491 }
492 else
493 {
494 inptr=(float *)(inarr->data);
495 }
496
497 for (imode=0; imode<nmodes; imode++)
498 {
499 for (itime=0; itime<npts; itime++)
500 {
501 in_index=in_offset + 2*itime;
502 out_index=out_offset + 2*itime;
503 outptr[out_index] = inptr[in_index];
504 outptr[out_index+1] = inptr[in_index+1];
505 }
506 out_offset+=2*ndt;
507 in_offset+=2*npts; // 2*tstepin/cadence;
508 }
509
510 drms_free_array(inarr);
511 }
512 // firsttimethrough=0;
513
514 if (nskip == nrecsin)
515 {
516 fprintf(stderr, "WARNING: no inputs for this output, no segment written\n");
517 }
518 else
519 {
520 outarr->bzero=segout->bzero;
521 outarr->bscale=segout->bscale;
522 status=drms_segment_write(segout, outarr, 0);
523 nsegments++;
524 if (status != DRMS_SUCCESS)
525 {
526 fprintf(stderr, "ERROR: problem writing output segment: status = %d, T_START = %s, LMIN = %d, LMAX = %d, histrecnum = %lld\n", status, tstartstr, lminout, lmaxout, histrecnum);
527 drms_close_records(inrecset, DRMS_FREE_RECORD);
528 drms_close_records(outrecset, DRMS_FREE_RECORD);
529 return 0;
530 }
531 }
532 drms_free_array(outarr);
533
534 drms_copykeys(outrec, inrec, 0, kDRMS_KeyClass_Explicit);
535 // copykeys takes care of MAPMMAX, SINBDIVS, etc. that should be constant across the input
536 skip2:
537
538 drms_setkey_int(outrec, "LMIN", lminout);
539 drms_setkey_int(outrec, "LMAX", lmaxout);
540 drms_setkey_time(outrec, "T_START", tstartout);
541 drms_setkey_time(outrec, "T_STOP", tstopout);
542 drms_setkey_time(outrec, "T_OBS", tstartout+chunksecs/2);
543 drms_setkey_int(outrec, "NDT", ndt);
544
545 for (i=0;i<16;i++)
546 calversout=setbits(calversout,4*i+3,4,nybblearrout[i]);
547 drms_setkey_longlong(outrec, "CALVER64", calversout);
548
549 if (noinput || nskip == nrecsin)
550 drms_setkey_int(outrec, "QUALITY", QUAL_NODATA);
551 else if (mixflag)
552 drms_setkey_int(outrec, "QUALITY", QUAL_MIXEDCALVER);
553 else
554 drms_setkey_int(outrec, "QUALITY", 0);
555
556 tnow = (double)time(NULL);
557 tnow += UNIX_epoch;
558 drms_setkey_time(outrec, "DATE", tnow);
559
560 // drms_close_record(outrec, DRMS_INSERT_RECORD);
561 nrecords++;
562
563 if (verbflag > 1)
564 {
565 wt=getwalltime();
566 ct=getcputime(&ut, &st);
567 fprintf(stdout, " lchunk %d done: %.2f ms wall time, %.2f ms cpu time\n", lchunk-lchunkfirst,
568 wt-wt2,
569 ct-ct2);
570 }
571
572 }
573
574 if (verbflag)
575 {
576 wt=getwalltime();
577 ct=getcputime(&ut, &st);
578 fprintf(stdout, "timechunk %d done: %.2f ms wall time, %.2f ms cpu time\n", iset,
579 wt-wt1,
580 ct-ct1);
581
582 }
583
584 }
585
586 drms_close_records(inrecset, DRMS_FREE_RECORD);
587 drms_close_records(outrecset, DRMS_INSERT_RECORD);
588
589 wt=getwalltime();
590 ct=getcputime(&ut, &st);
591 if (verbflag)
592 {
593 printf("number of records created = %d\n", nrecords);
594 printf("number of segments created = %d\n", nsegments);
595 fprintf(stdout, "total time spent: %.2f ms wall time, %.2f ms cpu time\n",
596 wt-wt0, ct-ct0);
597 }
598
599 printf("module %s successful completion\n", cmdparams.argv[0]);
600
601 return 0;
602
603 }