int liss2orbpkt ( char *seed, int size, char *database, int remap, char *srcname, double *time, char **packet, int *nbytes, int *bufsize ) { int zero = 0, two=2 ; int needed ; char *cp ; double samprate ; double calib, calper ; float fcalib, fcalper; char segtype[4] ; char sta[16], chan[16] ; static int *data, datasz=0 ; int nsamp ; Steim *conf ; Srcname parts ; int retcode = 0 ; if ( strncmp(seed, "000000 ", 64 ) == 0 ) { return -5 ; /* some kind of empty packet to keep connection open? */ } retcode = UNSEED ( seed, size, &conf, time, &samprate, &nsamp, &data, &datasz ) ; switch ( retcode ) { case 0: needed = 2*size ; SIZE_BUFFER ( char *, *packet, *bufsize, needed ) ; cp = *packet ; strcpy ( parts.src_net, conf->sdh.net ) ; strcpy ( parts.src_sta, conf->sdh.sta ) ; strcpy ( parts.src_chan, conf->sdh.chan ) ; strcpy ( parts.src_loc, conf->sdh.loc ) ; strcpy ( parts.src_suffix, "LISS" ) ; *parts.src_subcode = 0 ; N2H4 (cp, &zero, 1); cp += 4 ; N2H4 (cp, &two, 1); cp += 4 ; HI2NS (cp, &nsamp, 1); cp += 2 * 1; cp += 2; HD2NF (cp, &samprate, 1); cp += 4 ; if (database) { if (map_seed_netsta ( conf->sdh.net, conf->sdh.sta, sta ) < 0) { retcode = -1; break; } if (map_seed_chanloc ( sta, conf->sdh.chan, conf->sdh.loc, chan ) < 0) { retcode = -1; break; } } if ( remap ) { strcpy ( parts.src_sta, sta ) ; strcpy ( parts.src_chan, chan ) ; strcpy ( parts.src_loc, "" ) ; } join_srcname ( &parts, srcname) ; if (database) dbget_calib ( sta, chan, *time, database, &calib, &calper, segtype ); else { calib = 0.0; calper = -1.0; strcpy (segtype, "V"); } fcalib = calib ; N2H4 (cp, &fcalib, 1); cp += 4 * 1; fcalper = calper ; N2H4 (cp, &fcalper, 1); cp += 4 * 1; memcpy (cp, segtype, 1); cp += 1 * 1; memcpy (cp, seed, size) ; cp += size ; *nbytes = cp-*packet ; freesteim(conf) ; break ; case -2: /* got garbage */ if ( conf->sdh.samprate_factor != 0 || conf->sdh.samprate_multiplier != 0) { complain ( 0, "Can't decode this packet:" ) ; hexdump ( stderr, seed, size ) ; } break; default: case -1: complain ( 0, "failed to decode packet." ) ; hexdump ( stderr, seed, size ) ; break; case -3: /* unsupported formats */ case -4: /* log data */ break ; } return retcode ; }
long readPolygon(Dbptr db, Point **Poly) { char fname[PATH_MAX]; char ftype[6]; long npoints; long foff; int pcode; FILE *df; Data dp; /* union of pointers, a pointer */ long i; /*dbquery(db,dbRECORD_COUNT,&nrec); if (nrec != 1) { elog_log(0,"readPolygon: more than one row given..."); return -1; } */ if (dbextfile(db,0,fname) <1) { elog_log(0,"readPolygon: problem finding data in %s (are dir and dfile set properly?)",fname); return -1; } if (is_file(fname) !=1) { elog_log(0,"readPolygon: file %s not found!",fname); return -1; } dbgetv(db,0,"ftype",&ftype,"npoints",&npoints,"foff",&foff,NULL ); if ((pcode = polycode(ftype)) == -1) { elog_log(0,"readPolygon: unknown storage format %s",ftype); return -1; } *Poly = malloc((npoints+2) * sizeof(Point)); dp.c=malloc(8 * 2 * (npoints +2 )); df=fopen(fname,"r"); fseek(df,foff,0); switch (pcode) { case polyGSHHS: break; case polyINT: /* fread( rawdata,1,2 * sizeof(int) * npoints,df); N2H4(rawdata,dp.i,2 * npoints); */ fread(dp.i, sizeof(int), npoints*2, df); N2H4((char *) dp.i, (char *) dp.i, 2*npoints); for (i=0; i< npoints; i++) { (*Poly)[i].lon= dp.i[i*2] / 1.0e6; (*Poly)[i].lat= dp.i[i*2+1] / 1.0e6; } break; case polyINTELINT: fread( dp.i, sizeof(int), 2*npoints, df); #ifdef WORDS_BIGENDIAN swap4(dp.i,dp.i,2 * npoints); #endif for (i=0; i< npoints; i++) { (*Poly)[i].lon= dp.i[i*2] / 1.0e6; (*Poly)[i].lat= dp.i[i*2+1] / 1.0e6; } break; case polyFLOAT: fread( dp.f, sizeof(float), 2*npoints, df); N2H4((char *)dp.f,(char *)dp.f,2 * npoints); for (i=0; i <npoints; i++) { (*Poly)[i].lon= dp.f[i*2]; (*Poly)[i].lat= dp.f[i*2+1]; } break; case polyINTELFLOAT: fread( dp.f, sizeof(float), 2*npoints, df); #ifdef WORDS_BIGENDIAN swap4((char *)dp.f,(char *)dp.f,2 * npoints); #endif for (i=0; i <npoints; i++) { (*Poly)[i].lon= dp.f[i*2]; (*Poly)[i].lat= dp.f[i*2+1]; } break; default: elog_log(0,"readPolygon: no code for storage format %s",ftype); free(dp.c); fclose(df); return -1; } free(dp.c); fclose(df); return npoints; }