int unstuff_BBAHdr( uchar_t *packet, Packet **Pkt, void *par ) { int i, ch=0; struct DataPar *dhdr; BBAHdr bbahdr; PktChannel *achan; float calib; float samprate; short chlen, nsamp, nchan, doff; short hdrsize, pktsize; ushort_t hdrtype, pkttype; short datatype; char *name, chnames[64]; uchar_t *hdr, hdrbuf[512]; dhdr = ( struct DataPar *) par; memcpy( &hdrbuf[0], packet, 512); hdr = &hdrbuf[0]; memcpy( &hdrsize, hdr, sizeof(short )); hdr += sizeof(short ); hdrsize = ntohs( hdrsize ); bbahdr.prehdr.hdrsiz = hdrsize; memcpy( &pktsize, hdr, sizeof( short )); hdr += sizeof( short ); pktsize = ntohs( pktsize ); bbahdr.prehdr.pktsiz = pktsize; memcpy( &hdrtype, hdr, sizeof(short)); hdr += sizeof(short); hdrtype = (ushort_t) ntohs( hdrtype ); bbahdr.prehdr.hdrtype = hdrtype; memcpy( &pkttype, hdr, sizeof(short)); hdr += sizeof(short); pkttype = (ushort_t)ntohs( pkttype ); bbahdr.prehdr.pkttype = pkttype; memcpy( &calib, hdr, sizeof(float)); hdr += sizeof(float); ntohfp( &calib, &calib ); bbahdr.calib = calib; memcpy( &samprate, hdr, sizeof(float)); hdr += sizeof(float); ntohfp( &samprate, &samprate ); bbahdr.samprate = samprate; memcpy( &datatype, hdr, sizeof(short)); hdr += sizeof(short); datatype = ntohs( datatype ); bbahdr.datatype = datatype; memcpy( &nsamp, hdr, sizeof(short)); hdr += sizeof(short); nsamp = ntohs( nsamp ); bbahdr.nsamp = nsamp; memcpy( &nchan, hdr, sizeof(short)); hdr += sizeof(short); nchan = ntohs( nchan ); bbahdr.nchan = nchan; memcpy( &doff, hdr, sizeof(short)); hdr += sizeof(short); doff = ntohs( doff ); bbahdr.doff = doff; memcpy( &chlen, hdr, sizeof(short)); hdr += sizeof(short); chlen = ntohs( chlen ); bbahdr.chanlen = chlen; memcpy( (char *) &bbahdr.channels[0], hdr, chlen ); bbahdr.channels[chlen] = '\0'; strcpy( chnames,&bbahdr.channels ); dhdr->pktsize = (int) bbahdr.prehdr.pktsiz; dhdr->datatype = (int) bbahdr.datatype; dhdr->doff = (int) bbahdr.doff; dhdr->nsamp = (int) bbahdr.nsamp; if( *Pkt == 0 ) *Pkt = newpkt(); (*Pkt)->pkttype = (int) bbahdr.prehdr.pkttype; (*Pkt)->hdrtype = (int) bbahdr.prehdr.hdrtype; (*Pkt)->nchannels = (int) bbahdr.nchan; name = strtok( bbahdr.channels, "_" ) ; while ( name != 0 ) { if( ch > nchan ) { complain( 0,"There are more chan names ( %s ) than channels (%d)\n", chnames, nchan ); return 0; } achan = (PktChannel *) gettbl((*Pkt)->chan, ch) ; if ( achan == 0 ) { allot ( PktChannel *, achan, 1 ) ; achan->data = NULL; strcpy (achan->segtype, "V"); } strcpy( achan->chan, name ) ; achan->samprate = (double) bbahdr.samprate; achan->calib = (double) bbahdr.calib; achan->nsamp = (int) bbahdr.nsamp; settbl((*Pkt)->chan, ch, (char *) achan ) ; name = strtok(0, "_" ) ; ch++ ; }
int unstuff_liss( double time, char *srcname, uchar_t *packet, Packet **Pkt, void *par ) { LissHdr *hdr; struct Data_only *tmp; PktChannel *achan; int *adata; int udata[4096]; int chnum, doff, nbytes; char data[4096], *cptr; char net[12], sta[12], chan[12]; uchar_t dformat; LissPkt *seed_hdr; int tmpoff, blktype, gotone; struct blkhdr *newblk; hdr = ( LissHdr *) packet; doff = hdr->prehdr.hdrsiz+hdr->doff; seed_hdr = ( LissPkt *) (packet + hdr->prehdr.hdrsiz); tmpoff = hdr->prehdr.hdrsiz + seed_hdr->First_Blockette; gotone = 0; while ( tmpoff > 0 && tmpoff < 4095 ) { newblk = (struct blkhdr *) (packet + tmpoff); blktype = newblk->blktype; if( blktype == 1000 ) { tmp = (struct Data_only *) (packet + tmpoff); gotone = 1; break; } tmpoff = hdr->prehdr.hdrsiz + newblk->blkxref; } if( !gotone ) return 2; dformat = tmp->Encoding; cptr = &data[0]; memcpy ( cptr, packet + doff, hdr->prehdr.pktsiz - hdr->doff ); if( (nbytes = liss_ucompress( &udata[0], hdr->prehdr.pktsiz, hdr->doff, cptr, hdr->nsamp, dformat) )<= 0 ) { elog_complain( 0, "Can't uncompress LISS data.\n"); hexdump( stderr, packet, 16+hdr->doff+16 ); fflush(stderr); return 0; } /* Get net and sta names from srcname */ net[0] = '\0'; sta[0] = '\0'; chan[0] = '\0'; parse_srcname( srcname, &net[0], &sta[0], &chan[0], 0 ); if( *Pkt == 0 ) *Pkt = newpkt(); (*Pkt)->pkttype = (int) hdr->prehdr.pkttype; (*Pkt)->hdrtype = (int) hdr->prehdr.hdrtype; (*Pkt)->nchannels = 1; chnum = 0; achan = (PktChannel *) gettbl((*Pkt)->chan, chnum) ; if ( achan == 0 ) { allot ( PktChannel *, achan, 1 ) ; achan->data = 0; strcpy (achan->segtype, "V"); }