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