Esempio n. 1
0
main(int argc, char **argv)
{
struct seed_fsdh dest;
char src[48];

    if (fread(src, 1, 48, stdin) != 48) {
        perror("fread");
        exit(1);
    }

    if (seed_fsdh(&dest, src) != 0) {
        fprintf(stderr, "seed_fsdh failed\n");
        exit(1);
    }

    printf("seqno  = %ld\n", dest.seqno);
    printf("staid  = %s\n",  dest.staid);
    printf("locid  = %s\n",  dest.locid);
    printf("chnid  = %s\n",  dest.chnid);
    printf("netid  = %s\n",  dest.netid);
    printf("start  = %s\n",  util_dttostr(dest.start, 0));
    printf("nsamp  = %hd\n", dest.nsamp);
    printf("srfact = %hd\n", dest.srfact);
    printf("srmult = %hd\n", dest.srmult);
    printf("active = %d\n",  (int) dest.active);
    printf("ioclck = %d\n",  (int) dest.ioclck);
    printf("qual   = %d\n",  (int) dest.qual);
    printf("more   = %d\n",  (int) dest.more);
    printf("tcorr  = %ld\n", dest.tcorr);
    printf("bod    = %hd\n", dest.bod);
    printf("first  = %hd\n", dest.first);
    printf("order  = %s\n",  dest.order == LTL_ENDIAN_ORDER ? "little endian" : "big endian");
    printf("swap   = %d\n",  dest.swap);
    exit(0);
}
Esempio n. 2
0
static void DumpPkt(Packet *pkt)
{
char buf[256];

    printf("Pkt:     %s_%s_%s_%s   %s\n", 
        pkt->parts.src_sta, 
        pkt->parts.src_chan, 
        pkt->parts.src_net, 
        pkt->parts.src_loc,
        util_dttostr(pkt->time, 0, buf)
    );
}
Esempio n. 3
0
static void dump_inf_chn(int level, struct edes_inf_chn *chn)
{
    if ((int) chn->beg == (int) XFER_YNGEST) {
        sprintf(buf, "beg=XFER_YNGEST, ");
    } else if ((int) chn->beg == (int) XFER_OLDEST) {
        sprintf(buf, "beg=XFER_OLDEST, ");
    } else {
        sprintf(buf, "beg=%s, ", util_dttostr(chn->beg, 0));
    }
    if ((int) chn->end == (int) XFER_YNGEST) {
        sprintf(buf+strlen(buf), "end=XFER_YNGEST, ");
    } else if ((int) chn->end == (int) XFER_OLDEST) {
        sprintf(buf+strlen(buf), "end=XFER_OLDEST, ");
    } else {
        sprintf(buf+strlen(buf), "end=%s, ", util_dttostr(chn->end, 0));
    }
    sprintf(buf+strlen(buf), "begndx=%ld ", chn->begndx);
    sprintf(buf+strlen(buf), "endndx=%ld ", chn->endndx);
    sprintf(buf+strlen(buf), "nxtndx=%ld ", chn->nxtndx);
    sprintf(buf+strlen(buf), "count=%ld ",  chn->count);
    sprintf(buf+strlen(buf), "status=%d ",  chn->status);
    util_log(level, buf);
}
CHAR *util_lttostr(INT32 ltime, UINT16 code, CHAR *buf)
{
CHAR *string;

    string = util_dttostr((double) ltime, code, buf);
    if (code >= 4 && code <= 7) return string;

    if (code != 3) {
        string[strlen(string)-strlen(".msc")] = 0;
    } else {
        string[strlen(string)-strlen("msc")] = 0;
    }

    return string;
}
Esempio n. 5
0
static void DumpPktChan(PktChannel *pktchan)
{
char buf[256];
    printf("PktChan: %s_%s_%s_%s_%s %s %.3f %4d  %10d %10d\n", 
        pktchan->sta,
        pktchan->chan,
        pktchan->net,
        pktchan->loc,
        pktchan->segtype,
        util_dttostr(pktchan->time, 0, buf),
        pktchan->samprate,
        pktchan->nsamp,
        pktchan->data[0],
        pktchan->data[pktchan->nsamp-1]
    );
}
void CPreview::mouseMoveEvent ( QMouseEvent * e ) 
	{
	if(!bContinue) return;

	int x=e->x();
	int y=MaxY-e->y();


	if(x>=x1 && x<=x2)
		{
		double ttt=(x-x1)*(pDisplay->tB2-pDisplay->tB1)/(x2-x1)+pDisplay->tB1;
		char cBuff[64];	
		strcpy(cBuff, util_dttostr(ttt, 1));
		MainFrame *pParent=(MainFrame *)parentWidget();
		QCustomEvent *event = new QCustomEvent(MainFrame::SETTEXT);
		event->setData(new QString(cBuff));
		QApplication::postEvent(pParent, event);
		}

	}
struct nrts_header *nrts_ida10decode(char *buffer, int len, int *action)
{
struct nrts_chn *chn;
REAL64 errsec, errsmp;
int i, status, sign;
UINT64 err;
IDA10_TSHDR dhead, *prev, *crnt;
static char tqual[2] = {'?', 'M'};
static short tcode[2] = {5, 1};
static char *fid = "nrts_ida10decode";

    if (ida10Type((UINT8 *)buffer) != IDA10_TYPE_TS) return NULL;

/* Decode the record header */

    memset(&dhead, 0, sizeof(IDA10_TSHDR));
    crnt = &dhead;
    if (ida10UnpackTSHdr((UINT8 *)buffer, crnt) == 0) {
        util_log(2, "corrupt data record dropped");
        return (struct nrts_header *) NULL;
    }

/* Determine if desired stream. */

    for (hd.chnndx = -1, i = 0; hd.chnndx < 0 && i < sys->sta[0].nchn; i++) {
        if (strcasecmp(sys->sta[0].chn[i].name, crnt->cname) == 0) hd.chnndx = i;
    }
    if (hd.chnndx == -1) {
        util_log(2, "unconfigured channel %s, packet dropped", crnt->cname);
        return (struct nrts_header *) NULL;
    }

    chn = sys->sta[0].chn + hd.chnndx;

/* Sanity checks on header contents */

    sprintf(msgbuf, "corrupt data record dropped: ");

    if (crnt->unused > 0) {
        util_log(1, "short %s packet dropped (%d unused bytes)", chn->name, crnt->unused);
        return (struct nrts_header *) NULL;
    } else if (crnt->unused < 0) {
        sprintf(msgbuf+strlen(msgbuf), "%s claims %d extra bytes?", chn->name, crnt->unused);
        util_log(1, msgbuf);
        return (struct nrts_header *) NULL;
    }

    if (UnreliableTimeTag(&crnt->cmn.ttag.beg.status) || UnreliableTimeTag(&crnt->cmn.ttag.end.status)) {
        sprintf(msgbuf+strlen(msgbuf), "%s unreliable time stamp", chn->name);
        util_log(1, msgbuf);
        return (struct nrts_header *) NULL;
    }

/*  Look for and reject records with duplicate or overlapping headers or times */

    prev = &prev_dhead[hd.chnndx];

    if (write_enabled && !first[hd.chnndx]) {
        if (memcmp(prev, crnt, sizeof(IDA10_TSHDR)) == 0) {
            util_log(1, "duplicate %s data header, packet dropped", chn->name);
            return (struct nrts_header *) NULL;
        }
        if (
            memcmp(&prev->cmn.ttag.beg, &crnt->cmn.ttag.beg, sizeof(IDA10_TTAG)) == 0 &&
            memcmp(&prev->cmn.ttag.end, &crnt->cmn.ttag.end, sizeof(IDA10_TTAG)) == 0
        ) {
            util_log(1, "duplicate %s start and end times, packet dropped",
                chn->name
            );
            return (struct nrts_header *) NULL;
        }
        if (crnt->tofs <= prev->tols) {
            sprintf(msgbuf, "%s <= ", util_dttostr(crnt->tofs, 0));
            sprintf(msgbuf+strlen(msgbuf), "%s", util_dttostr(prev->tols, 0));
            util_log(1, "dropped overlapping %s packet (%s)", chn->name, msgbuf);
            return (struct nrts_header *) NULL;
        }
    }

/*  Fill in the output header for this packet */

    sprintf(hd.wfdisc.chan, "%s", chn->name);
    hd.wrdsiz         = 4;
    hd.wfdisc.nsamp   = crnt->nsamp;
    hd.wfdisc.time    = crnt->tofs;
    hd.wfdisc.endtime = crnt->tols;
    hd.wfdisc.smprate = (float) crnt->srate;
    hd.order = BIG_ENDIAN_ORDER;

    hd.beg.code = (char) tcode[crnt->cmn.ttag.beg.status.locked ? 1 : 0];
    hd.beg.qual = tqual[crnt->cmn.ttag.beg.status.locked ? 1 : 0];

    hd.end.code = (char) tcode[crnt->cmn.ttag.end.status.locked ? 1 : 0];
    hd.end.qual = tqual[crnt->cmn.ttag.end.status.locked ? 1 : 0];

/* If filling disk loop, save the sample interval */

    if (write_enabled && first[hd.chnndx]) chn->sint = (float) crnt->sint;

/*  Look for time tears  */

    if (!first[hd.chnndx]) {

        status = ida10TtagIncrErr(prev, crnt, &sign, &err);
        if (status != 0) {
            util_log(1,"%s: ida10TtagIncrErr: error %d", fid, status);
            return (struct nrts_header *) NULL;
        } else {
            errsec = (REAL64) err / (REAL64) NANOSEC_PER_SEC;
            errsmp = errsec / (REAL64) crnt->sint;
        }
        if ((unsigned long) errsmp > errtol) {
            if (write_enabled) {
                util_log(1, "%c%.5f sec %s time tear (%.2lf samp)",
                    sign > 0 ? '+' : '-',errsec, chn->name,  errsmp
                );
            }
            if (sign < 0) errsec *= -1.0;
            hd.tear = errsec;
            *action = NRTS_CREATE;

        } else {

    /* No time tear detected */

            hd.tear = 0.0;
            *action = NRTS_EXTEND;
        }
    } else {
        hd.tear = 0.0;
        *action = NRTS_TESTWD;
    }

/*  Save the decoded header for later comparisons  */

    *prev = *crnt;
    first[hd.chnndx] = FALSE;

    return &hd;
}
struct nrts_header *nrts_asldecode(char *buffer, int len, int *action)
{
int i, j, status;
long error;
struct nrts_chn *chn;
struct channel_info *channel;
struct seed_minipacket dhead, *prev, *crnt;
static struct seed_minipacket prev_dhead[NRTS_MAXCHN];
static char *fid = "nrts_asldecode";

/* Decode the record header */

    if (buffer[6] != 'D') {
        util_log(2, "unexpected non-data record dropped");
        return (struct nrts_header *) NULL;
    }

/* Must be a data record at this point */

    crnt = &dhead;

/* Decode and determine if desired stream. */

    sprintf(msgbuf, "corrupt data record dropped: ");

    if ((status = seed_minihdr(crnt, buffer)) < 0) {
        sprintf(msgbuf+strlen(msgbuf), "seed_minihdr status %d",
            status
        );
        util_log(1, msgbuf);
        return (struct nrts_header *) NULL;

    }
#ifdef DEBUG
    util_log(1, "%s/%s/%s %s %.3lf %4ld",
        crnt->sname, crnt->cname, crnt->nname,
        util_dttostr(crnt->beg, 0), crnt->sint, crnt->nsamp
    );
#endif


/* Find its position in the local lookup table */

    for (j = -1, i = 0; j == -1 && i < sys->sta[0].nchn; i++) {
        if (strcasecmp(crnt->cname, channel_table[i].name) == 0) j = i;
    }

    if (j == -1) {
        util_log(2, "unexpected %s record dropped", crnt->cname);
        return (struct nrts_header *) NULL;
    }

    channel = channel_table + j;

/*  Fill in the output header for this packet */

    sprintf(hd.wfdisc.chan, "%s", crnt->cname);
    switch (crnt->b1000.format) {
      case SEED_INT_32:
        hd.order  = LTL_ENDIAN_ORDER;
        hd.wrdsiz = 4;
        sprintf(hd.wfdisc.datatype, "s4");
        break;
      case SEED_INT_16:
        hd.order  = LTL_ENDIAN_ORDER;
        hd.wrdsiz = 2;
        sprintf(hd.wfdisc.datatype, "s2");
        break;
      default:
        hd.order  = 0;
        hd.wrdsiz = 0;
        hd.wfdisc.datatype[0] = 0;
        break;
    }
    hd.wfdisc.nsamp   = crnt->nsamp;
    hd.wfdisc.time    = crnt->beg;
    hd.wfdisc.endtime = crnt->beg + ((crnt->nsamp - 1) * crnt->sint);
    hd.wfdisc.smprate = (float) (1.0 / crnt->sint);
    hd.wfdisc.calib   = channel->calib;
    hd.wfdisc.calper  = channel->calper;
    strlcpy(hd.wfdisc.instype, channel->instype, NRTS_INAMLEN+1);
    hd.hang  = channel->hang;
    hd.vang  = channel->vang;

    hd.beg.code = hd.end.code = ' ';
    hd.beg.qual = hd.end.qual = 0;

/*  If no further action is specified, then we are done */

    if (*action == NRTS_DECODE) {
        return &hd;
    }

/*  Locate this channel in the NRTS system  */

    if ((hd.chnndx = channel->index) < 0) {
        util_log(2, "unexpected %s record dropped", crnt->cname);
        return (struct nrts_header *) NULL;
    }

    chn = sys->sta[0].chn + hd.chnndx;
#ifdef DEBUG
    util_log(1, "%d: %d %d %s %15.4f %15.4f %8.3f %8.3f %s",
        j, channel->index, hd.chnndx, chn->name, channel->calib,
        channel->calper, channel->vang, channel->hang, channel->instype
    );
#endif

/*  Look for and reject records with duplicate headers or times */

    prev = prev_dhead + hd.chnndx;

    if (write_enabled  && channel->count > 0) {
        if (memcmp(prev, crnt, sizeof(IDA_DHDR)) == 0) {
            util_log(1, "duplicate %s data header, packet dropped", chn->name);
            return (struct nrts_header *) NULL;
        }
    }

/* If filling disk loop, save the sample interval */

    if (write_enabled && channel->count == 0) chn->sint = (float) crnt->sint;

/*  Count time tears  */

    if (channel->count > 0) {
        if ((status = seed_timetear(prev, crnt, &error)) != 0) {
            util_log(1,"%s: seed_timetear failed with status %d: ignored",
                        fid, status
            );
        } else if (error > 1) {
            util_log(1, "%d sample %s time tear", error, chn->name);
        } else if (error < -1) {
            util_log(1, "%d sample %s time tear, packet dropped",
                error, chn->name
            );
            return (struct nrts_header *) NULL;
        }
    }

/*  Save the decoded header for later comparisons  */

    *prev = *crnt;
    ++channel->count;

/*  For ASL we don't attempt wfdisc maintenance */

    *action = NRTS_NOP;

    return &hd;
}
Esempio n. 9
0
long search(struct old_xfer_req *req, struct nrts_chn *chn, double target, long ldef, long rdef, char *buffer)
{
struct span *span, dl;
long oldest, yngest;
static char *fid = "search";

    oldest = chn->hdr.oldest;
    yngest = chn->hdr.yngest;
    util_log(3, "`%s' search for time %s", chn->name, util_dttostr(target, 0));
    util_log(3, "`%s' oldest = %ld, youngest = %ld", chn->name, oldest, yngest);

/* First, insure the desired time falls inside the disk buffer */

    span = get_span(req, oldest, chn, buffer);
    dl.beg = span->beg;

    span = get_span(req, yngest, chn, buffer);
    dl.end = span->end;
    sprintf(buffer, "`%s' spans %s ", chn->name, util_dttostr(dl.beg, 0));
    util_log(3, "%s to %s", buffer, util_dttostr(dl.end, 0));

    if (target < dl.beg) {
        util_log(3, "`%s' target too old, return %d", chn->name, ldef);
        return ldef;
    }

    if (target > dl.end) {
        util_log(3, "`%s' target too young, return %d", chn->name, rdef);
        return rdef;
    }

/* It must be available, so search for it */
/* First case, no wraparound at end of disk buffer */

    if (oldest < yngest) {
        util_log(3, "`%s' no disk loop wrap around");
        util_log(3, "`%s' search from oldest (%ld) to youngest (%ld)",
            chn->name, oldest, yngest
        );
        return do_search(req, target, chn, oldest, yngest, buffer);
    }

/* Second case, data wrap around end of disk buffer */

    span = get_span(req, (long) 0, chn, buffer);
    span->beg -= chn->sint;  /* will allow for one sample slop */
    if (target > span->beg && target <= dl.end) {
        util_log(3, "`%s' target is in later half of disk buffer", chn->name);
        util_log(3, "`%s' search from 0 to youngest (%ld)",
            chn->name, yngest
        );
        return do_search(req, target, chn, 0, yngest, buffer);
    } else {
        span = get_span(req, (long) chn->hdr.nrec - 1, chn, buffer);
        if (target > dl.beg && target <= span->end) {
            util_log(3, "`%s' search from oldest (%ld) to eof (%ld)",
                chn->name, oldest, chn->hdr.nrec - 1
            );
            return do_search(req,target,chn,oldest,chn->hdr.nrec - 1,buffer);
        } else {
            util_log(1, "HELP! I don't know what to do!");
            util_log(1, "target = %s", util_dttostr(target, 0));
            util_log(1, "dl beg = %s", util_dttostr(dl.beg, 0));
            util_log(1, "dl end = %s", util_dttostr(dl.end, 0));
            util_log(1, "end of dl file time = %s", util_dttostr(span->end, 0));
            ack(0);
            die(1);
        }
    }

    util_log(1, "%s: FATAL PROGRAM LOGIC ERROR!", fid);
    util_log(1, "%s: target = %s", fid, util_dttostr(target, 0));
    util_log(1, "%s: dl beg = %s", fid, util_dttostr(dl.beg, 0));
    util_log(1, "%s: dl end = %s", fid, util_dttostr(dl.end, 0));
}
Esempio n. 10
0
main(int argc, char **argv)
{
struct seed_fsdh fsdh;
struct seed_b1000 dest;
int nread, type, next, count;
char *ptr, *string, src[1024];

    nread = fread(src, 1, 1024, stdin);
    if (nread < 48) {
        fprintf(stderr, "nread = %d is too small!\n", nread);
        exit(1);
    }

       if (seed_fsdh(&fsdh, src) != 0) {
           fprintf(stderr, "seed_fsdh failed\n");
           exit(1);
       }

    printf("FSDH\n");
    printf("seqno  = %ld\n", fsdh.seqno);
    printf("staid  = %s\n",  fsdh.staid);
    printf("locid  = %s\n",  fsdh.locid);
    printf("chnid  = %s\n",  fsdh.chnid);
    printf("netid  = %s\n",  fsdh.netid);
    printf("start  = %s\n",  util_dttostr(fsdh.start, 0));
    printf("nsamp  = %hd\n", fsdh.nsamp);
    printf("srfact = %hd\n", fsdh.srfact);
    printf("srmult = %hd\n", fsdh.srmult);
    printf("active = %d\n",  (int) fsdh.active);
    printf("ioclck = %d\n",  (int) fsdh.ioclck);
    printf("qual   = %d\n",  (int) fsdh.qual);
    printf("more   = %d\n",  (int) fsdh.more);
    printf("tcorr  = %ld\n", fsdh.tcorr);
    printf("bod    = %hd\n", fsdh.bod);
    printf("first  = %hd\n", fsdh.first);
    printf("order  = %s\n",  fsdh.order == LTL_ENDIAN_ORDER ? "little endian" : "big endian");
    printf("swap   = %d\n",  fsdh.swap);

    printf("\n");
    next = fsdh.first;
    do {
        ptr = src + next;
        type = seed_type(ptr, &next, fsdh.swap);
        printf("B%d\n", type);
        if (type == 1000) {
            if (seed_b1000(&dest, ptr) != 0) {
                fprintf(stderr, "seed_b1000 failed\n");
            } else {
                printf("next   = %hd ", dest.next);
                if (next != dest.next) {
                    printf("ERROR: next offset confusion!\n");
                } else {
                    printf("\n");
                }
                printf("format = %d ", (int) dest.format);
                switch (dest.format) {
                  case  1: string = "16 bit integers"; break;
                  case  2: string = "24 bit integers"; break;
                  case  3: string = "32 bit integers"; break;
                  case  4: string = "IEEE float"; break;
                  case  5: string = "IEEE double"; break;
                  case 10: string = "Steim 1 compressed"; break;
                  case 11: string = "Steim 2 compressed"; break;
                  case 12: string = "GEOSCOPE 1"; break;
                  case 13: string = "GEOSCOPE 1"; break;
                  case 14: string = "GEOSCOPE 1"; break;
                  case 15: string = "USNSN compressed"; break;
                  case 16: string = "CDSN 16 bit gain ranged"; break;
                  case 17: string = "Graefenberg 16 bit gain ranged"; break;
                  case 18: string = "IPG-Strasbourg 16 bit gain ranged"; break;
                  case 30: string = "SRO format"; break;
                  case 31: string = "HGLP format"; break;
                  case 32: string = "DWWSSN gain ranged"; break;
                  case 33: string = "RSTN 16 bit gain ranged"; break;
                  default: string = "unknown";
                }
                printf("(%s)\n", string);
                printf("order  = %d ", (int) dest.order);
                printf("(%s)\n", dest.order ? "big endian" : "little endian");
                printf("length = %d ", (int) dest.length);
                printf("(%d)\n", (int) pow(2.0, (double) dest.length));
            }
        } else {
            printf("blockette ignored\n");
        }
    } while (next != 0);
    exit(0);
}