Пример #1
0
Файл: clock.c Проект: 8l/inferno
void
clockinit(void)
{
	long x;

	m->delayloop = m->cpuhz/1000;	/* initial estimate */
	do {
		x = gettbl();
		delay(10);
		x = gettbl() - x;
	} while(x < 0);

	/*
	 *  fix count
	 */
	m->delayloop = ((vlong)m->delayloop*(10*(vlong)m->clockgen/1000))/(x*Timebase);
	if((int)m->delayloop <= 0)
		m->delayloop = 20000;

	x = (m->clockgen/Timebase)/HZ;
	putpit(x);
iprint("pit value=%.8lux [%lud]\n", x, x);
	puttsr(~0);
	puttcr(Pie|Are);
iprint("boot=%.8lux epctl=%.8lux pllmr0=%.8lux pllmr1=%.8lux ucr=%.8lux\n",
	getdcr(Boot), getdcr(Epctl), getdcr(Pllmr0), getdcr(Pllmr1), getdcr(Ucr));
}
Пример #2
0
static PyObject *
pf2PyObject( Pf *pf )
{
	PyObject *obj;
	Pf	*pfvalue;
	Tbl	*keys;
	char	*key;
	int	ivalue;

	switch( pf->type ) {
	case PFSTRING:
		
		obj = string2PyObject( pfexpand( pf ) );

		break;

	case PFTBL:

		obj = PyTuple_New( pfmaxtbl( pf ) );

		for( ivalue = 0; ivalue < pfmaxtbl( pf ); ivalue++ ) {

			pfvalue = (Pf *) gettbl( pf->value.tbl, ivalue );

			PyTuple_SetItem( obj, ivalue, pf2PyObject( pfvalue ) );
		}

		break;

	case PFFILE:
	case PFARR:

		keys = keysarr( pf->value.arr );

		obj = PyDict_New();

		for( ivalue = 0; ivalue < maxtbl( keys ); ivalue++ ) {

			key = gettbl( keys, ivalue );

			pfvalue = (Pf *) getarr( pf->value.arr, key );

			PyDict_SetItem( obj, Py_BuildValue( "s", key ), pf2PyObject( pfvalue ) );
		}

		break;

	case PFINVALID:
	default:

		obj = (PyObject *) NULL;

		break;
	}

	return obj;
}
Пример #3
0
int
add_latencies ( Arr * networks )
{
    char * net;
    char * sta;
    char * statime;
    Arr * stations;
    Arr * sinfo;
    Arr * network;
    Tbl * stas;
    Tbl * nets;
    Pf * oldval;
    int numstas;
    int numnets;
    int i, j;
    int min = MAXINT;
    int max = 0;

    nets = keysarr( networks );
    numnets = maxtbl( nets );
    for ( i = 0; i < numnets; i++ )
    {
        net = gettbl( nets, i );
        network = getpf( networks, net );
        stations = getpf( network, STALIST );
        stas = keysarr( stations );
        numstas = maxtbl( stas );

        for ( j = 0, min=MAXINT, max=0; j < numstas; j++ )
        {
            sta = gettbl( stas, j );
            sinfo = getpf( stations, sta );
            statime = get_station_field( sinfo, LATENCY );
            if ( statime && ( atoi( statime ) < min ) )
                min = atoi( statime );
            if ( statime && ( atoi( statime ) > max ) )
                max = atoi( statime );
        }
        freetbl( stas, 0 );
        oldval = setarr( network, MINNETLATENCY, 
                         create_pf( itoa(min), PFSTRING ) ); 
        if ( oldval ) recurse_free_pf( oldval );
        oldval = setarr( network, MAXNETLATENCY, 
                         create_pf( itoa(max), PFSTRING ) ); 
        if ( oldval ) recurse_free_pf( oldval );
    }
    freetbl( nets, 0 );

    return 1;
}
/* This function is used to exactly duplicate the arrival array of doubles from
i to o.  If *o is not a null pointer it is assumed the arr already
exists and freearr is called to clear it's contents before 
calling setarr to copy contents.*/
void dup_arrival_array(Arr *in,Arr **o)
{
	Tbl *t;
	double *value,*copy;
	char *key;
	int i;

	if((*o) == NULL)
		*o = newarr(0);
	else
	{
		freearr(*o,free);
		*o=newarr(0);
	}

	t = keysarr(in);
	for(i=0;i<maxtbl(t);++i)
	{
		key = gettbl(t,i);
		value = (double *)getarr(in,key);
		allot(double *,copy,1);
		*copy = *value;
		setarr(*o,key,copy);
	}
	freetbl(t,0);
}
void MWcheck_timing(Arr *a,Arr *arrsta,Arr *bcarr)
{
	Tbl *stakeys;
	char *name;
	int i;

	stakeys = keysarr(a);

	for(i=0;i<maxtbl(stakeys);++i)
	{
		Bad_Clock *bc;
		MWstation *sta;
		double *atime;

		name=gettbl(stakeys,i);
		bc=(Bad_Clock *)getarr(bcarr,name);
		sta=(MWstation *)getarr(arrsta,name);
		if(sta==NULL)
			elog_complain(0,"MWcheck_timing: no match in station table for arrival at station %s\n",name);
		else
		{
			if(bc==NULL)
				sta->clock_is_bad=0;
			else
			{
				atime = (double *)getarr(a,name);
				if(clock_is_bad(bc->badtimes,*atime))
					sta->clock_is_bad=1;
				else
					sta->clock_is_bad=0;
			}
		}
	}
}
/* companion to the above, but this version will copy entries in
*in to *o.  Errors are issued only if *o does not contain an entry
for the same key as *in.  If *o is null the dup function above
is called and the function returns immediately after returning
from it.  
*/
void copy_arrival_array(Arr *in,Arr **o)
{
	Tbl *t;
	double *value,*copy;
	char *key;
	int i;

	if((*o) == NULL)
	{
		*o = newarr(0);
		dup_arrival_array(in,o);
	}
	else
	{
		t = keysarr(in);
		for(i=0;i<maxtbl(t);++i)
		{
			key = gettbl(t,i);
			value = (double *)getarr(in,key);
			copy = (double *)getarr(*o,key);
			if(copy == NULL)
			{
				setarr(*o,key,value);
			}
			else
			{
				*copy = *value;
			}
		}
		freetbl(t,0);
	}
}
/* This is a companion routine to load_station_table for array beam code
tables.  At the moment it is essentially identical to the load_station_table
function, but changes may eventually occur in the beam table that will
make them diverge so I have produced to seperate functions */
Arr *load_array_table(Pf *pf)
{
	Arr *a;
	Tbl *t;
	int i;
	char *value;

	Seismic_Array *s;

        double elev_datum;
 
        a = newarr(0);
        elev_datum = pfget_double_wdef(pf,"elevation_datum",0.0);
	t = pfget_tbl(pf,"seismic_arrays");
	for(i=0;i<maxtbl(t);++i)
	{
		s = (Seismic_Array *) malloc(sizeof(Seismic_Array));
		if(s == NULL) elog_die(1,"load_array_table:  Cannot malloc Seismic_Array structure entry\n");
		value = gettbl(t,i);
		if(sscanf(value,"%s %lf %lf %lf",s->name,
			&(s->lat),&(s->lon),&(s->elev)) != 4)
			elog_complain(1,"Warning(load_array_table):  \
Read error in array tbl read from parameter file\n\
The following line of the array table was skipped\n%s\n",
				value);
		else
		{
                        s->elev -= elev_datum;
			setarr(a,s->name,s);
		}
	}
	return(a);
}
Пример #8
0
/* This function is called in ttlvz_init to parse the contents of the Pf
object containing the velocity model.  Both models are specified the same
way, so we call this same function for both model tables.  
Arguments:  
	t = Tbl set by pfget_tbl containing the velocity model table.
		It is assumed this tbl contains a set of strings that
		can be read with sscanf as velocity, depth pairs.  
	v = vector of layer velocities (space is alloced for *v and then
		values are set).  This pointer is set to alloced memory
		area here and on return it contains a vector of layer 
		velocities.  
	z = parallel vector to v for depths to layer tops.  
	n = length of z and n vectors (set by this routine)


*/
void ttlvz_parse_vmodel(Tbl *t,double **v, double **z, int *n)
{	
	int nlayers, i;

	nlayers = maxtbl(t);
	if(nlayers <= 0) 
		die(0,"ttlvz_parse_vmodel:  No velocity model parameters for calculating travel times\n");

	/* the 100 here is an arbitrary constant, and this is only a warning */
	if(nlayers > 100) 
	{
		complain(0,"Warning (ttlvz_parse_vmodel):  read data for %d layer velocity model\nConsider using a different travel time calculator for better performance\n", nlayers);
	}
	*v = (double *) calloc(nlayers, sizeof(double));
	*z = (double *) calloc(nlayers,sizeof(double));

	if( (*v == NULL) || (*z == NULL) )
		die(1,"Cannot alloc memory in ttlvz_parse_vmodel function for %d layer model\n", nlayers);

	for(i=0;i<nlayers;++i)
	{
		char *line;
		line = gettbl(t,i);
		sscanf(line,"%lf %lf",(*v)+i,(*z)+i);
	}

	*n = nlayers;
}
/* This function creates an associative array keyed by an integer
event id from a parameter file based descriptor &Tbl like this example:

pmel_calibration_events &Tbl{
	10 xyz
	11 xyzt
}
where 10 and 11 are event ids and the string defines coordinates to fix.

Author:  Gary Pavlis
*/
Arr *load_calibration_events(Pf *pf)
{
	Tbl *t;
	int evid;
	char *evidstr;
	char fix[5],*line;
	char *fptr;
	Arr *a;
	int i;

	a = newarr(0);

	t = pfget_tbl(pf,"pmel_calibration_events");
	if(t==NULL) 
	{
		elog_complain(0,
		  "pmel_calibration_events Tbl not in parameter file\nAssuming no calibration events exist\n");
	}
	else
	{
		for(i=0;i<maxtbl(t);++i)
		{
			line = (char *)gettbl(t,i);
			sscanf(line,"%d%s",&evid,fix);
			evidstr = make_evid_key(evid);
			fptr=strdup(fix);
			setarr(a,evidstr,fptr);
			free(evidstr);
		}
			
	}
	return(a);
}
Пример #10
0
/* This function establishes the list of all stations that will actually
be used for processing.  I creates an associative array of MWstation 
objects keyed by the station name.  Note it is important to realize
the structure this function creates is NOT completely filled in, but
every element is at least initialized.  (see above).  The NULL pointers
are especially dangerous if not filled in.  

The main element of the MWstation structure that this function fills in
is the weights vector.  This vector is an array of weights used for
forming the stack in a given frequency band.  That is, weight[i] is
the weight given traces for this station in wavelet band i.

arguments:
	pf = input pf object to be parsed
	nbands = number of frequency bands to use in processing = length
		of weights vector created in s->weights

The weights array is created cautiously using nbands.  The input line
is parsed and if there are insufficient weights listed in the input
a diagnostic will be issued and the undefined weights set to 1.0.
If there are more numbers listed than required the list will be silently
truncated.  

History:
Created summer 1999

Modified march 2000

Added code for stations with bad timing.  
*/
Arr *create_station_objects(Pf *pf, int nbands)
{
	int i,j,k;
	Arr *a;
	Tbl *t;
	MWstation *s;
	char *sta;
	char *line,*word;
	char *white=" \t";

	t = pfget_tbl(pf,"station_weights");
	if(t == NULL) elog_die(0,"station_weights table not in parameter file\n");

	a = newarr(0);

	for(i=0;i<maxtbl(t);i++)
	{
		line = gettbl(t,i);
		sta = strtok(line,white);

		s = (MWstation *)malloc(sizeof(MWstation));
		if(s==NULL) 
		  elog_die(0,"Cannot malloc MWstation structure for station %s\n",sta);
		initialize_MWstation(s,nbands);
		allot(double *,s->weights,nbands);
		s->sta = strdup(sta);

		for(j=0;j<nbands;j++) 
		{
			word = strtok(NULL,white);
			if(word == NULL)
			{
				elog_notify(0,"error in station_weights parameter inputfor station %s\nExpected list of %d weights, found only %d\n",
					sta,nbands, j);
				if(j==0)
				{
					elog_notify(0,"No weights defined in any band for station %s\nSetting all weights to 1.0\n",
						sta);
					for(k=0;k<nbands;++k)s->weights[k]=1.0;
				}
				else
				{
					elog_notify(0,"Setting weights for station %s above band %d to %lf\n",
						sta,j-1,s->weights[j-1]);
					for(k=j;k<nbands;++k)
						s->weights[k]=s->weights[j-1];
				}
				break;
			}
			s->weights[j] = atof(word);
		}
		/* we set the clock_is_bad variable false here and depend
		upon the genloc bad clock definitions to set a station as
		being always bad with this flag */
		s->clock_is_bad = 0;
		setarr(a,s->sta,s);
	}

	return(a);
}
Пример #11
0
int
pfpeek( Pf *pf, char *name, Pf **value )
{
	
	switch( pf->type )
	{
	case PFFILE:
	case PFARR:
		*value = (Pf *) getarr( pf->value.arr, name );
		break;
	case PFTBL:
		*value = (Pf *) gettbl( pf->value.tbl, (long) name );
		break;
#ifdef PFPROMPT
	case PFPROMPT:
#endif
	case PFSTRING:
		/* Can't have named child of a prompt or a string */
		*value = 0;
		break;
	}

	if( *value == 0 ) 
	{
		return PFINVALID;
	}
	else 
	{
		return (*value)->type;
	}
}
Пример #12
0
Tbl *
dbschema2sqlcreate( Dbptr db, long flags )
{
	Tbl	*sql;
	char	*cmd;
	Tbl	*tables;
	char	*table;
	long	itable;

	sql = newtbl( 0 );

	if( db.table >= 0 ) {
		
		cmd = generate_sqltable_create( db, flags );

		pushtbl( sql, cmd );

	} else {

		dbquery( db, dbSCHEMA_TABLES, &tables );

		for( itable = 0; itable < maxtbl( tables ); itable++ ) {

			table = gettbl( tables, itable );

			db = dblookup( db, "", table, "", "" );
			
			cmd = generate_sqltable_create( db, flags );

			pushtbl( sql, cmd );
		}
	}

	return sql;
}
Пример #13
0
Arr *build_stachan_list(Pf *pf, int *nchan,int verbose)
{
	char sta[10], chan[10];
	char *key;
	Arr *a;
	int i;
	Tbl *t;
	char *line;
	int *channel_number;  /* value stored in arr */

	if(verbose)
		elog_notify(0,"Station   Channel_code    Channel_number\n");
	a = newarr(0);
	t = pfget_tbl(pf,"channels");
	if(t==NULL) elog_die(0,"Parameter file error:  no channels table\n");
	for(i=0;i<maxtbl(t);++i)
	{
		line = gettbl(t,i);
		sscanf(line,"%s %s",sta,chan);
		key = make_key(sta,chan);
		channel_number = (int *) malloc(sizeof(int));
		if(channel_number == NULL)
			elog_die(0,"malloc error for channel_number\n");
		*channel_number = i;
		setarr(a,key,(void *)channel_number);
		if(verbose)
			elog_notify(0,"%s  %s  %d\n",sta,chan,(*channel_number)+1);
		free(key);
	}
	*nchan = maxtbl(t);
	freetbl(t,free);
	return(a);
}
Пример #14
0
int load_surface_velocity(Pf *pf, Arr *a)
{
	int nset;
	Tbl *t;
	char sta[10];
	double vp,vs;
	char *line;
	MWstation *s;
	int i;

	t = pfget_tbl(pf,"surface_velocities");
	if(t == NULL) elog_die(0,"surface_velocities table missing from parameter file\n");

	for(i=0,nset=0;i<maxtbl(t);i++)
	{
		line = gettbl(t,i);
		if((sscanf(line,"%s %lf %lf",sta,&vp,&vs)) != 3)
		{
			elog_notify(0,"Syntax error reading line from surface_velocity table\nOffending line->%s\n",
				line);
			continue;
		}
		s = (MWstation *)getarr(a,sta);
		if(s == NULL) 
		{
			elog_notify(0,"Station %s listed in surface_velocity table not found in master table\n",
				sta);
			continue;
		}
		s->vp0 = vp;
		s->vs0 = vs;
		++nset;
	}
	return(nset);
}
Пример #15
0
int anza_par( uchar_t *packet,
          double pkttime,
          char *srcname,
	  struct Packet **Pkt
	  )

{

    struct PreHdr *hdr;
    struct PktChannel *achan;
    char net[64], sta[8];
    int i, off, ch;
    short sval; 
    int val;
    long lval;

    hdr = ( struct PreHdr *) packet;
    
    (*Pkt)->pkttype = ntohl (hdr->pkttype);
    (*Pkt)->hdrtype = ntohl (hdr->hdrtype);


    parse_srcname( srcname, &net[0], &sta[0], 0, 0 );

    for( i = 0, ch = 0; i < ANZA_DAS; i++, ch++ )  {

        achan = (PktChannel *) gettbl((*Pkt)->chan, ch) ;
        if ( achan == 0 ) {
              allot ( PktChannel *, achan, 1 ) ;
              achan->data = (void *) malloc( sizeof(int)  );
        }
        strcpy( achan->chan, ANZA_DAS_NAME[i] ) ;
        strcpy( achan->net, net);
        strcpy( achan->sta, sta);
        achan->samprate = 1.0/DINTV;                                
        achan->calib = 0;                     
        achan->datatype = trINT;
        achan->nsamp = 1;                   
        achan->nbytes = sizeof(int);
        achan->time = pkttime;   

        off = hdr->hdrsiz + ANZA_DAS_OFF[i];
        if( strncmp(ANZA_DAS_NAME[i], "BUFDEL", strlen("BUFDEL")) == 0 )  
	    val = packet[off];
	else  {
	    memcpy( (char *) &sval, (char *) &packet[off], 2 );
	    val = sval ;
	   /*
	    fprintf( stderr, "%lf %s_%s %d\n", achan->time, achan->sta, achan->chan, val ); 
	    if( val < 1100  )   hexdump( stderr, packet + hdr->hdrsiz, 62 ); 
	    fflush(stderr);
	    */
	}
        memcpy(achan->data, (char *) &val, sizeof(int) );

        settbl((*Pkt)->chan, ch, achan ) ;
     } 
Пример #16
0
/* This small functions scans the gridlist tbl to get the maximum
and minimum gridid values.  These are used to subset the working view
automatically to reduce the size of the working view (found to be
excessive otherwise .

gmin and gmax are returned as the maximum and minimum grid id

Author:  Gary Pavlis
Written: July 2001
*/
void get_gridid_range(Tbl *gridlist,int *gmin,int *gmax)
{
	int gidmin,gidmax;
	int gridid;
	int i;
	
	if(maxtbl(gridlist)<=0) elog_die(0,"Empty grid id list\nProbable usage error\n");
	gidmin = (int)gettbl(gridlist,0);
	gidmax = gidmin;
	for(i=1;i<maxtbl(gridlist);++i)
	{
		gridid = (int)gettbl(gridlist,i);
		gidmin = MIN(gidmin,gridid);
		gidmax = MAX(gidmax,gridid);
	}
	*gmin = gidmin;
	*gmax = gidmax;
}
Пример #17
0
static int
dbrows2orb(Dbptr db, int orb, char *prefix)
{
	Packet         *pkt;
	char            srcname[ORBSRCNAME_SIZE];
	double          time;
	char           *packet;
	int             nbytes, packetsize = 0;
	Dbptr           tmpdb;
	long            t, nrecords, r, ntables;
	Arr            *records = NULL;
	Tbl            *tables = NULL, *static_tables;
	char           *thistablename;
	Stbl           *stbl;
	char           *s;

	dbuntangle(db, &records);
	tables = keysarr(records);
	ntables = maxtbl(tables);
	if (ntables > 0)
		pkt = newPkt();
	if (prefix)
		strncpy(pkt->parts.src_net, prefix, PKT_TYPESIZE);
	pkt->pkttype = suffix2pkttype("db");
	for (t = 0; t < ntables; t++) {
		thistablename = gettbl(tables, t);
		tmpdb = dblookup(db, 0, thistablename, 0, 0);
		stbl = (Stbl *) getarr(records, thistablename);
		nrecords = maxstbl(stbl);
		if (nrecords > 0) {
			for (r = 0; r < nrecords; r++) {
				tmpdb.record = (long) getstbl(stbl, r);
				pkt->db = tmpdb;
				if (stuffPkt(pkt, srcname, &time, &packet, &nbytes, &packetsize) < 0) {
					elog_complain(0, "stuffPkt fails for pf packet");
					return (-1);
				}
				if (orbput(orb, srcname, time, packet, nbytes) < 0) {
					elog_complain(0, "Couldn't send packet to orb\n");
					return (-1);
				}
			}
		}
	}
	freetbl(tables, 0);
	dbfree_untangle(records);
	freePkt(pkt);
	if (verbose) {
		elog_notify(0, "%s: %d patcket(s) sent with sourcename: %s\n", s = strtime(now()), nrecords, srcname);
		free(s);
	}
	return (0);




}
/* Edits the array of phase handles to keep only phases
named in the keeplist Tbl of phase names strings.  This
is complicated by the fact that keeplist is a simple
list.  The algorithm used converts the keeplist to a
temporary associative array then passes through the
array of phase handles calling the free routine on
phases not found in the keeplist.

Author:  G Pavlis
Written:  August 2001
*/
void edit_phase_handle(Arr *a,Tbl *keeplist)
{
    Tbl *akeys;
    Arr *akeeper;
    int dummy;  /* used purely as a placeholder in akeeper*/
    char *phase;
    int i,n;
    Phase_handle *ph;

    n = maxtbl(keeplist);
    if(n<=0)
        elog_die(0,"List of phases to keep is empty.\n\
Check phases_to_keep parameter setting\n");
    akeeper = newarr(0);
    for(i=0; i<maxtbl(keeplist); ++i)
    {
        phase = (char *)gettbl(keeplist,i);
        setarr(akeeper,phase,&dummy);
        ph = (Phase_handle *)getarr(a,phase);
        if(ph==NULL)elog_die(0,
                                 "Don't know how to handle required phase %s\n",
                                 phase);
    }
    akeys = keysarr(a);
    for(i=0; i<maxtbl(akeys); ++i)
    {
        phase = gettbl(akeys,i);
        if(getarr(akeeper,phase) == NULL)
        {
            ph = (Phase_handle *)getarr(a,phase);
            free_phase_handle(ph);
            delarr(a,phase);
        }
    }

    freearr(akeeper,0);
    freetbl(akeys,0);
}
Пример #19
0
char *get_refsta(Arr *s)
{
	char *ref;
	MWstation *station;
	char *key;
	Tbl *t;

	t = keysarr(s);
	key = gettbl(t,0);
	station = (MWstation *) getarr(s,key);
	ref = strdup(station->refsta);
	freetbl(t,0);
	return(ref);
}
Пример #20
0
int
decimate_trace (Trace *trace, Tbl *ncoefs, Tbl *coefs, Tbl *dec_fac, double tref)

{
    Trace *tr;
    int i, j, nstages;
    float *cfs;
    int ncfs, decfac;
    int ns, nsout, ioff;
    float *buf=NULL;

    nstages = maxtbl(ncoefs);
    for (tr=trace; tr!=NULL; tr=tr->next) {
        ns = tr->nsamps;
        buf = (float *) malloc (ns*sizeof(float));
        if (buf == NULL) {
            fprintf (stderr, "decimate_trace: Malloc error.\n");
            return (0);
        }
        for (i=0; i<nstages; i++) {
            cfs = (float *) gettbl (coefs, i);
            ncfs = *((int *) gettbl (ncoefs, i));
            decfac = *((int *) gettbl (dec_fac, i));
            ns = tr->nsamps;
            ioff = (tr->tstart-tref)/tr->dt + 0.5;
            ioff = decfac - (ioff%decfac);
            if (ioff == decfac) ioff = 0;
            convsym (tr->data, ns, cfs, ncfs, decfac, ioff, &nsout, buf);
            tr->tstart += ioff*tr->dt;
            tr->dt *= decfac;
            tr->nsamps = nsout;
            for (j=0; j<nsout; j++) tr->data[j] = buf[j];
        }
        free (buf);
    }
    return (1);
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    Dbptr	tr;
    char	*newchan[3];
    Tbl	*newchan_tbl;
    int	rc;
    int	i;

    if( nrhs != 2 )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! get_dbptr( prhs[0], &tr ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! get_stringtbl( prhs[1], &newchan_tbl ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }

    if( maxtbl( newchan_tbl ) != 3 )
    {
        freetbl( newchan_tbl, 0 );
        mexErrMsgTxt( "NEWCHANS array must have three channel names" );
    }
    else
    {
        for( i = 0; i < 3; i++ )
        {
            newchan[i] = gettbl( newchan_tbl, i );
        }
    }

    rc = rotate_to_standard( tr, newchan );

    antelope_mex_clear_register( 1 );

    freetbl( newchan_tbl, 0 );

    plhs[0] = CreateDouble( (double) rc );
    if( plhs[0] == NULL )
    {
        mexErrMsgTxt( "trrotate_to_standard: failed to create return value" );
    }
}
Пример #22
0
int watchdog_post_test (int flags)
{
	if (flags & POST_REBOOT) {
		/* Test passed */

		return 0;
	} else {
		/* 10-second delay */
		int ints = disable_interrupts ();
		ulong base = gettbl ();
		ulong clk = get_tbclk ();

		while ((gettbl () - base) / 10 < clk);

		if (ints)
			enable_interrupts ();

		/*
		 * If we have reached this point, the watchdog timer
		 * does not work
		 */
		return -1;
	}
}
Пример #23
0
/* poor man's searchtbl */
static int
findtbl(char *string, Tbl * table)
{
	int             i, found = 0;
	char           *str;

	for (i = 0; i < maxtbl(table); i++) {
		str = gettbl(table, i);
		if (strcmp(string, str) == 0) {
			found = 1;
			break;
		}
	}
	return (found);
}
Пример #24
0
Dbptr join_tables(Dbptr db, Pf *pf, Arr *tables)
{
	char *table_name;
	int *ilogic;
	Tbl *t;
	Dbptr dbj;
	long int nrec;
	int i;
	int ntables=0;

	/* This is an exact copy of above, but it is duplicated because
	this function could get stolen by another future program
	because it is pretty general */
	t = pfget_tbl(pf,"join_tables");
	if(t == NULL)
	{
		elog_die(0,"No list of tables to be joined\n");
	}
	for(i=0;i<maxtbl(t);++i)
	{
		table_name = gettbl(t,i);
		ilogic = (int *)getarr(tables,table_name);
		if(ilogic == NULL)
		{
			elog_die(0,"Table %s was not handled previously by check_tables.\nProgramming logic error\n",
				table_name);
		}
		else if(*ilogic)
		{
			if(ntables == 0)
				dbj = dblookup(db,0,table_name,0,0);
			else
				dbj=dbjoin(dbj,dblookup(db,0,table_name,0,0),
					NULL,NULL,0,NULL,0);
			++ntables;
			dbquery(dbj,dbRECORD_COUNT,&nrec);
			if(nrec == 0)
			{
				elog_complain(0,
					"join_tables error\njoined database has 0 length after joining table %s\n",
					table_name);
				dbj.record = dbINVALID;
				return(dbj);
			}
		}
	}
	return(dbj);
}
Пример #25
0
static int
get_instype (Dbptr db, char *instype, double *samprate)
{
    static Dbptr    dbsi = INVALID_DBPTR;
    static Hook    *hook = 0;
    long            nmatches;
    Tbl            *tbl;
    char            sta[MAX_STA_SIZE],
                    chan[MAX_CHAN_SIZE];
    double          time;
    char           *s;
    int             errors = 0;

    if (dbsi.database < 0) {
	Dbptr           dbsensor,
	                dbinstrument;
	dbsensor = dblookup (db, 0, "sensor", 0, 0);
	dbinstrument = dblookup (db, 0, "instrument", 0, 0);
	dbsi = dbjoin (dbsensor, dbinstrument, 0, 0, 0, 0, 0);
    }
    nmatches = dbmatches (db, dbsi, 0, 0, &hook, &tbl);
    switch (nmatches) {
      case dbINVALID:
      case 0:
	dbgetv (db, 0, "sta", sta, "chan", chan, "time", &time, NULL);
	complain (0, "no matches in sensor/instrument join for %s:%s @ %s",
		  sta, chan, s = strydtime (time));
	free (s);
	errors++;
	break;

      default:
	dbgetv (db, 0, "sta", sta, "chan", chan, "time", &time, NULL);
	complain (0, "too many matches (%ld) in sensor/instrument join for %s:%s @ %s",
		  nmatches, sta, chan, s = strydtime (time));
	free (s);
	errors++;
	/* FALLTHRU */

      case 1:
	dbsi.record = (long) gettbl (tbl, 0);
	dbgetv (dbsi, 0, "instype", instype, "samprate", samprate, NULL);
	break;
    }

    freetbl (tbl, 0);
    return errors;
}
Пример #26
0
void log_error_list(Tbl *t)
{
	int j;
	char line[512];
	int nt;
	strcpy(line,"Problem attributes: ");
	nt = maxtbl(t);
	for(j=0;j<nt;++j)
	{
		char *tval;
		tval = (char *)gettbl(t,j);
		strcat(line,tval);
		if(j<(nt-1))strcat(line,",");
	}
	elog_notify(0,line);
}
Пример #27
0
static void 
id_clients( Pf *pf )
{
	Pf	*pfclients;
	Pf	*pfclient;
	char	client_summary[STRSZ];
	char	*serveraddress;
	char	*serverport;
	Tbl	*client_keys;
	int	ikey;
	char	*client_key;
	char	clientid_key[STRSZ];
	char	*clientaddress;
	char	*what;
	char	clientid[33];

	pfeval( pf, "server{address}", &serveraddress );
	pfeval( pf, "server{port}", &serverport );

	pfget( pf, "clients", (void **) &pfclients );

	client_keys = pfkeys( pfclients );

	for( ikey = 0; ikey < maxtbl( client_keys ); ikey++ ) {

		client_key = gettbl( client_keys, ikey );

		pfget( pfclients, client_key, (void **) &pfclient );

		clientaddress = pfget_string( pfclient, "address" );
		what = pfget_string( pfclient, "what" );

		sprintf( client_summary, "%s %s %s %s", 
				serveraddress, serverport,
				clientaddress, what );

		sprintf( clientid_key, "clients{%s}{clientid}", client_key );

		mdhex( clientid, client_summary, strlen( client_summary ) );

		pfset( pf, clientid_key, clientid );
	}

	freetbl( client_keys, 0 );

	return;
}
int
antelope_mex_elog_callback( int severity, char *string, Tbl *Elog )
{
	Elog_msg *elog_msg;
	char	repeated[STRSZ];
	char	*message;
	int	nmessages;
	int	i;

	nmessages = maxtbl( Elog );

	for( i = 0; i < nmessages; i++ )
	{
		elog_msg = (Elog_msg *) gettbl( Elog, i );
		
		if( elog_msg->n > 1 )
		{
			sprintf( repeated, 
				 " (repeated %d times)", 
				 elog_msg->n );
		}
		else 
		{
			sprintf( repeated, "" );
		}

		message = (char *) mxCalloc( 
		  strlen( elog_msg->msg ) + strlen( repeated ) + 1,
		  sizeof( char ) );

		sprintf( message, "%s%s", elog_msg->msg, repeated );

		if( severity == ELOG_NOTIFY ) {

			mexPrintf( "%s", message );

		} else if( severity >= ELOG_COMPLAIN ) {

			mexWarnMsgTxt( message );
		}

		mxFree( message );
	}

	return 1;
}
Пример #29
0
void init( )

{
    Pf  		*Param;
    Tbl 		*Site;
    DAS *das;
    struct Site 	 site;
    char 	*istr;
    char         dasid[6];
    int 		pkttype;
    int 		ntrec, i, j;
    int 		nsite;
    int 		*num = 0;

    if(pfread( pfile, &Param) != 0)
        die(0, "Can't read parameter file\n");

    /* Get Input & Network tables  */

    Site = pfget_tbl(Param, "Site");
    nsite = maxtbl(Site);

    if( nsite <= 0  )
        die( 0, "init(): parameter file is not complete.\n");

    Dases = newarr( 0 );
    Dasid = newarr( 0 );

    for( i = 0; i < nsite; i++ )  {

        istr = (char *) gettbl(Site, i);
        sscanf(istr, STE_SCS,  STE_RVL(&site));
        if( !strcmp(site.up, "Y") )  {
            sprintf( dasid, "%d\0", site.sid );
            if( ( das = ( DAS *) getarr( Dases, dasid ) ) == NULL )  {
                das = new_das( site.sid, site.name );
                setarr(Dases, (char *) &dasid[0], (char *) das );
            }

            if( (num = ( int *) getarr( Dasid, site.name ) ) == NULL )  {
                allot( int *, num, 1 );
                *num = site.sid;
                setarr(Dasid, (char *) site.name, (char *) num );
            }
        }
Пример #30
0
/* This routine looks for a Tbl in the parameter space that
defines a set of auxiliary tables that are to be used.  It
cautiously checks to see if that table is defined in the
schema and is nonempty.  It sets logical variables in associative
array it returns that define if the table is "ok".  This is serious
overkill added to make the code for expandable in the future.
At the moment the only table that would be used is "shot".
It would, however, be easy to add similar auxiliary tables for
segy constructs like statics, mute definition, etc.  In that
case there probably should be a more general mechanism than this
but I'm more or less laying out a useful functionality here rather
than doing it in a completely general way.
*/
Arr *check_tables(Dbptr db, Pf *pf)
{
	char *table;
	int *ilogic;
	int i;
	Tbl *t;
	Dbptr dbtmp;
	int table_ok;
	long int nrec;
	Arr *a;

	a = newarr(0);
	t = pfget_tbl(pf,"join_tables");
	if(t == NULL)
	{
		elog_die(0,"No list of tables to be joined\n");
	}
	for(i=0;i<maxtbl(t);++i)
	{
		/* This series of conditionals is safe:  It certifies
		a table (a) is defined in this schema and (b) is
		not empty.  */
		table = (char *)gettbl(t,i);
		dbtmp = dblookup(db,0,table,0,0);
		if(dbtmp.table == dbINVALID)
			table_ok = 0;
		else
			table_ok = 1;
		if(table_ok)
		{
			dbquery(dbtmp,dbRECORD_COUNT,&nrec);
			if(nrec > 0)
				table_ok = 1;
			else
				table_ok = 0;
		}
		ilogic = (int *) malloc(sizeof(int));
		if(ilogic == NULL) elog_die(0,"malloc error\n");
		*ilogic = table_ok;
		setarr(a,table,ilogic);
	}
	return(a);
}