Пример #1
0
*/	static REBFLG Get_Struct_Var(REBSTU *stu, REBVAL *word, REBVAL *val)
/*
***********************************************************************/
{
	struct Struct_Field *field = NULL;
	REBCNT i = 0;
	field = (struct Struct_Field *)SERIES_DATA(stu->fields);
	for (i = 0; i < SERIES_TAIL(stu->fields); i ++, field ++) {
		if (VAL_WORD_CANON(word) == VAL_SYM_CANON(BLK_SKIP(PG_Word_Table.series, field->sym))) {
			if (field->array) {
				REBSER *ser = Make_Array(field->dimension);
				REBCNT n = 0;
				for (n = 0; n < field->dimension; n ++) {
					REBVAL elem;
					get_scalar(stu, field, n, &elem);
					Append_Value(ser, &elem);
				}
				Val_Init_Block(val, ser);
			} else {
				get_scalar(stu, field, 0, val);
			}
			return TRUE;
		}
	}
	return FALSE;
}
Пример #2
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double nsamp_double;
	double time;
	double endtime;

	if( nrhs != 3  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_scalar( prhs[0], &time ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! get_scalar( prhs[1], &nsamp_double ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! get_scalar( prhs[2], &endtime ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	plhs[0] = CreateDouble( SAMPRATE( time, (int) nsamp_double, endtime ) );
}
Пример #3
0
ring_elem SchurRing2::mult(const ring_elem f, const ring_elem g) const
{
  ring_elem resultRE;
  const schur_poly *f1 = f.schur_poly_val;
  const schur_poly *g1 = g.schur_poly_val;
  ring_elem a;
  if (get_scalar(f1,a))
    {
      resultRE.schur_poly_val = mult_by_coefficient(a,g1);
      return resultRE;
      // In this case, do a simple multiplication
    }
  else if (get_scalar(g1,a))
    {
      resultRE.schur_poly_val = mult_by_coefficient(a,f1);
      return resultRE;
    }
  else
    {
      // use the poly heap
      schur_poly_heap H(this);
      for (schur_poly::iterator i = f1->begin(); i != f1->end(); ++i)
        for (schur_poly::iterator j = g1->begin(); j != g1->end(); ++j)
          {
            ring_elem c = coefficientRing->mult(i.getCoefficient(), j.getCoefficient());
            ring_elem r = const_cast<SchurRing2 *>(this)->mult_terms(i.getMonomial(), j.getMonomial());
            resultRE.schur_poly_val = mult_by_coefficient(c, r.schur_poly_val);
            H.add(resultRE);
          }
      return H.value();
    }
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	delta;
	double	depth;
	char 	**phases = 0;
	double	*slowness = 0;
	double	*pr;
	long	narrivals;
	Tbl	*phasetbl;
	long	i;

	if( nrhs != 2  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_scalar( prhs[0], &delta ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! get_scalar( prhs[1], &depth ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	narrivals = arr_slowness( delta, depth, &phases, &slowness );

	if( narrivals <= 0 ) 
	{
		return;
	}

	phasetbl = newtbl( narrivals );

	for( i = 0; i < narrivals; i++ ) 
	{
		pushtbl( phasetbl, phases[i] );
	}

	plhs[0] = mxCreateDoubleMatrix( narrivals, 1, mxREAL );
	pr = mxGetPr( plhs[0] );

	for( i = 0; i < narrivals; i++ ) 
	{
		pr[i] = slowness[i];
	}
	
	plhs[1] = stringtbl2cellstr( phasetbl );

	freetbl( phasetbl, 0 );
}
Пример #5
0
bool SchurRing2::lift(const Ring *Rg, const ring_elem f, ring_elem &result) const
{
  const schur_poly *f1 = f.schur_poly_val;
  if (Rg == coefficientRing || Rg == globalZZ)
    {
      if (get_scalar(f1, result))
        {
          if (Rg == globalZZ)
            return coefficientRing->lift(globalZZ, result, result);
          return true;
        }
    }
  else {
    const SchurRing2 *Sg = Rg->cast_to_SchurRing2();
    if (Sg != 0)
      {
        if (coefficientRing == Sg->getCoefficientRing())
          {
            result = Sg->truncate(f);
            return true;
          }

        return lift_coeffs(Sg, f, result);
      }
  }
  return false;
}
Пример #6
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	orbfd;
	int	version;

	if( nrhs != 1 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	if( ! get_scalar( prhs[0], &orbfd ) )
	{
		mexErrMsgTxt( "orbping: bad orb file descriptor\n" );
	}

	if( mex_orbping( (int) orbfd, &version ) ) {
		antelope_mex_clear_register( 1 );
		mexErrMsgTxt ( "orbping: failed\n" );
	}

	plhs[0] = CreateDouble( (double) version );
	if( plhs[0] == NULL )
	{
		mexErrMsgTxt( "orbping: failed to create return value" );
	}
}
Пример #7
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	orbfd;

	if( nlhs > 0 ) 
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	if( nrhs != 1 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	if( ! get_scalar( prhs[0], &orbfd ) )
	{
		mexErrMsgTxt( "orbclose: bad orb file descriptor\n" );
	}

	if( mex_orbclose( (int) orbfd ) ) {
		antelope_mex_clear_register( 1 );
		mexErrMsgTxt ( "orbclose: failed\n" );
	}
}
Пример #8
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	orbfd;
	char	*regex;
	int	nselected;

	if( nlhs > 1 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	if( nrhs != 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	if( ! get_scalar( prhs[0], &orbfd ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		mexErrMsgTxt( "orbreject: bad orb file descriptor\n" );
	}
	if( ! mtlb_get_string( prhs[1], &regex ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
	}

	nselected = mex_orbreject( (int) orbfd, regex );

	plhs[0] = CreateDouble( (double) nselected );
	if( plhs[0] == NULL )
	{
		mexErrMsgTxt( "orbreject: failed to create return value" );
	}
}
Пример #9
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    Dbptr	db;
    Tbl	*groupfields = 0;
    char	errmsg[STRSZ];
    int	rhs_index;
    long	type = 1;
    double 	type_fp = 1;

    if( nrhs < 2 || nrhs > 3  )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! get_dbptr( prhs[0], &db ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! get_stringtbl( prhs[1], &groupfields ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }

    if( nrhs == 3 ) {

        if( ! get_scalar( prhs[2], &type_fp ) ) {

            antelope_mexUsageMsgTxt ( USAGE );
            return;

        } else {

            type = (long) type_fp;
        }
    }

    db = dbgroup( db, groupfields, NULL, type );
    antelope_mex_clear_register( 1 );

    freetbl( groupfields, 0 );

    if( db.table == dbINVALID )
    {
        mexErrMsgTxt( "dbgroup: group failed" );
    }

    plhs[0] = CreateDbptrStructFromDbptr( db );

    if( plhs[0] == NULL )
    {
        sprintf( errmsg, "dbgroup: failed to create database-pointer " );
        strcat( errmsg, "structure for result" );
        mexErrMsgTxt( errmsg );
    }
}
Пример #10
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	orbfd;
	double	time;
	int	nselected;
	int	pktid;

	if( nlhs > 1 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	if( nrhs != 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	if( ! get_scalar( prhs[0], &orbfd ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		mexErrMsgTxt( "orbafter: bad orb file descriptor\n" );
	}
	if( ! get_scalar( prhs[1], &time ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
	}

	pktid = mex_orbafter( (int) orbfd, time );
	antelope_mex_clear_register ( 1 );

	plhs[0] = CreateDouble( (double) pktid );
	if( plhs[0] == NULL )
	{
		mexErrMsgTxt( "orbafter: failed to create return value" );
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double time0;
	double samprate;
	double time1;
	int sampnum_indexed_by_0;
	int sampnum_indexed_by_1;

	if( nrhs != 3  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_scalar( prhs[0], &time0 ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! get_scalar( prhs[1], &samprate ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! get_scalar( prhs[2], &time1 ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	sampnum_indexed_by_0 = TIME2SAMP( time0, samprate, time1 );

	/* WAKE UP */
	sampnum_indexed_by_1 = sampnum_indexed_by_0 + 1;

	plhs[0] = CreateDouble( (double) sampnum_indexed_by_1 );
}
Пример #12
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	tr;
	double	tolerance;

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

	trsplice( tr, tolerance, 0, 0 ); 
	antelope_mex_clear_register( 1 );
}
Пример #13
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	n;
	char	*log;

	if( nlhs > 1 ) 
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	if( nrhs != 1 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! get_scalar( prhs[0], &n ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	log = elog_string( (int) n );

	if( log == (char *) NULL ) {

		mexErrMsgTxt( "elog_string: Null string from elog_string(3)" );
	}

	plhs[0] = mxCreateString( log );

	if( plhs[0] == NULL ) {

		mexErrMsgTxt( "elog_string: Failed to create return value" );
	}
}
Пример #14
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	Dbptr	tr;
	int	type;
	char	*table = NULL;
	char	*time_str = NULL, *endtime_str = NULL;
	double	scalar;
	double	*doublep;
	float	*floatp;
	int	*intp;
	char	*s;
	char	errmsg[STRSZ];
	int	rc;

	if( nrhs < 3 || nrhs > 5 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_dbptr( prhs[0], &db ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( nrhs == 4 )
	{
		if( ! mtlb_get_string( prhs[3], &table ) )
		{
			if( ! get_dbptr( prhs[3], &tr ) )
			{
				antelope_mexUsageMsgTxt ( USAGE );
				return;
			}
		}
	}
	else if( nrhs == 5 )
	{
		if( ! get_dbptr( prhs[3], &tr ) )
		{
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		}

		if( ! mtlb_get_string( prhs[4], &table ) )
		{
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
	}

	if( ! mtlb_get_string( prhs[1], &time_str ) )
	{
		if( ! get_scalar( prhs[1], &scalar ) )
		{
			if( table ) mxFree( table );
                	antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
		else
		{
			s = epoch2str( scalar, "%E\0" );
			antelope_mex_clear_register( 1 );
			
			time_str = mxCalloc( STRSZ, sizeof( char ) );
			strcpy( time_str, s );
			free( s );
		}
	}

	if( ! mtlb_get_string( prhs[2], &endtime_str ) )
	{
		if( ! get_scalar( prhs[2], &scalar ) )
		{
			if( table ) mxFree( table );
                	antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
		else
		{
			s = epoch2str( scalar, "%E\0" );
			antelope_mex_clear_register( 1 );
			
			endtime_str = mxCalloc( STRSZ, sizeof( char ) );
			strcpy( endtime_str, s );
			free( s );
		}
	}

	if( nrhs <= 3 || ( nrhs == 4 && table != NULL ) ) 
	{
		tr.database = dbINVALID;
	}

	rc = trload_css( db, time_str, endtime_str, &tr, table, 0 );
	antelope_mex_clear_register( 1 );

	if( table ) mxFree( table );
	mxFree( time_str );
	mxFree( endtime_str );

	if( rc < 0 )
	{
		mexPrintf( "trload_css: No matching data were found\n" );
	}
	else if( rc > 0 )
	{
		mexErrMsgTxt( "trload_css failed\n" );
	}
	else  /* Success */
	{
		plhs[0] = CreateDbptrStructFromDbptr( tr );

		if( plhs[0] == NULL )
		{
			sprintf( errmsg, "trload_css: failed to create " );
			strcat( errmsg, "database-pointer structure " );
			strcat( errmsg, "for result" );
			mexErrMsgTxt( errmsg );
		}
	}
}
Пример #15
0
*/	REBSER *Struct_To_Block(const REBSTU *stu)
/*
**		Used by MOLD to create a block.
**
***********************************************************************/
{
	REBSER *ser = Make_Array(10);
	struct Struct_Field *field = (struct Struct_Field*) SERIES_DATA(stu->fields);
	REBCNT i;

	// We are building a recursive structure.  So if we did not hand each
	// sub-series over to the GC then a single Free_Series() would not know
	// how to free them all.  There would have to be a specialized walk to
	// free the resulting structure.  Hence, don't invoke the GC until the
	// root series being returned is done being used or is safe from GC!
	MANAGE_SERIES(ser);

	for(i = 0; i < SERIES_TAIL(stu->fields); i ++, field ++) {
		REBVAL *val = NULL;
		REBVAL *type_blk = NULL;

		/* required field name */
		val = Alloc_Tail_Array(ser);
		Val_Init_Word_Unbound(val, REB_SET_WORD, field->sym);

		/* required type */
		type_blk = Alloc_Tail_Array(ser);
		Val_Init_Block(type_blk, Make_Array(1));

		val = Alloc_Tail_Array(VAL_SERIES(type_blk));
		if (field->type == STRUCT_TYPE_STRUCT) {
			REBVAL *nested = NULL;
			DS_PUSH_NONE;
			nested = DS_TOP;

			Val_Init_Word_Unbound(val, REB_WORD, SYM_STRUCT_TYPE);
			get_scalar(stu, field, 0, nested);
			val = Alloc_Tail_Array(VAL_SERIES(type_blk));
			Val_Init_Block(val, Struct_To_Block(&VAL_STRUCT(nested)));

			DS_DROP;
		} else
			Val_Init_Word_Unbound(val, REB_WORD, type_to_sym[field->type]);

		/* optional dimension */
		if (field->dimension > 1) {
			REBSER *dim = Make_Array(1);
			REBVAL *dv = NULL;
			val = Alloc_Tail_Array(VAL_SERIES(type_blk));
			Val_Init_Block(val, dim);

			dv = Alloc_Tail_Array(dim);
			SET_INTEGER(dv, field->dimension);
		}

		/* optional initialization */
		if (field->dimension > 1) {
			REBSER *dim = Make_Array(1);
			REBCNT n = 0;
			val = Alloc_Tail_Array(ser);
			Val_Init_Block(val, dim);
			for (n = 0; n < field->dimension; n ++) {
				REBVAL *dv = Alloc_Tail_Array(dim);
				get_scalar(stu, field, n, dv);
			}
		} else {
			val = Alloc_Tail_Array(ser);
			get_scalar(stu, field, 0, val);
		}
	}
	return ser;
}
Пример #16
0
int pfput_mxArray( Pf *pf, char *name, const mxArray *array )
{
	Pf	*sub_pf;
	double	number;
	char	*string;
	mxArray *in[2], *out[1];
	char	warning[STRSZ];
	char	*fieldname;
	mxArray	*mxfield;
	mxArray	*mxcell;
	int	M,N;
	int	rc;
	int	i;

	if( mxIsClass( array, "dbpf" ) )
	{
		if( ! get_pf( array, &sub_pf ) )
		{
			return PFINVALID;
		}

		if( sub_pf->type == PFFILE) 
		{
			/* Don't embed a PFFILE in something else */
			sub_pf->type = PFARR;
		}

    		switch (pf->type) {
        	case PFFILE:
        	case PFARR:
            		setarr ( pf->value.arr, name, sub_pf ) ;
            		break ;

        	case PFTBL:
            		settbl ( pf->value.tbl, (int) name, sub_pf ) ;
            		break ;
	
        	default :
			return PFINVALID;
        	}
		antelope_mex_clear_register( 1 );
	}
	else if( mxIsDouble( array ) )
	{
		if( ! get_scalar( array, &number ) )
		{
			return PFINVALID;
		}
	
		in[0] = (mxArray *) array; /* Input scalar */
		mexCallMATLAB( 1, out, 1, in, "floor" );
		in[1] = out[0];  /* floor( Input scalar ) */
		mexCallMATLAB( 1, out, 2, in, "eq" );
		mxDestroyArray( in[1] );
	
		if( mxIsLogicalScalarTrue( out[0] ) ) 
		{
			pfput_int( pf, name, (int) number );
		} 
		else 
		{
			pfput_double( pf, name, number );
		}
		antelope_mex_clear_register( 1 );

		mxDestroyArray( out[0] );
	}
	else if( mxIsChar( array ) )
	{
		if( ! mtlb_get_string( array, &string ) )
		{
			sprintf( warning, 
			  "failed to extract string for parameter %s\n",
			  name );
			mexWarnMsgTxt( warning );
			return PFINVALID;
		}

		pfput_string( pf, name, string );

		antelope_mex_clear_register( 1 );

		mxFree( string );
	}
	else if( mxIsStruct( array ) )
	{
		if( mxGetNumberOfDimensions( array ) > 2 ) 
		{
			sprintf( warning,
			  "structure has too many dimensions for parameter %s\n",
			  name );
			mexWarnMsgTxt( warning );
			return PFINVALID;
		}
		else if( mxGetM( array ) != 1 || mxGetN( array ) != 1 )
		{
			sprintf( warning,
			  "structure has too many elements for parameter %s\n",
			  name );
			mexWarnMsgTxt( warning );
			return PFINVALID;
		}
		N = mxGetNumberOfFields( array );

		sub_pf = pfnew( PFARR );

		for( i = 0; i < N; i++ ) 
		{
			fieldname = (char *) mxGetFieldNameByNumber( array, i );
			mxfield = mxGetFieldByNumber( array, 0, i );
			rc = pfput_mxArray( sub_pf, fieldname, mxfield );

			if( rc == PFINVALID )
			{
				pffree( sub_pf );
				return PFINVALID;
			}
		}

    		switch (pf->type) {
        	case PFFILE:
        	case PFARR:
            		setarr ( pf->value.arr, name, sub_pf ) ;
            		break ;

        	case PFTBL:
            		settbl ( pf->value.tbl, (int) name, sub_pf ) ;
            		break ;
	
        	default :
            		pffree( sub_pf );
			return PFINVALID;
        	}
		antelope_mex_clear_register( 1 );
	}
	else if( mxIsCell( array ) )
	{
                if( mxGetNumberOfDimensions( array ) > 2 )
                {
                        sprintf( warning,
                          "cell array has too many dimensions for parameter %s\n",
                          name );
                        mexWarnMsgTxt( warning );
                        return PFINVALID;
                }
                M = mxGetM( array );
                N = mxGetN( array );

		sub_pf = pfnew( PFTBL );
		for( i = 0; i < M * N; i++ ) 
		{
			mxcell = mxGetCell( array, i );
			rc = pfput_mxArray( sub_pf, (char *) i, mxcell );

			if( rc == PFINVALID )
			{
				pffree( sub_pf );
				return PFINVALID;
			}
		} 
    		switch (pf->type) {
        	case PFFILE:
        	case PFARR:
            		setarr ( pf->value.arr, name, sub_pf ) ;
            		break ;

        	case PFTBL:
            		settbl ( pf->value.tbl, (int) name, sub_pf ) ;
            		break ;
	
        	default :
            		pffree( sub_pf );
			return PFINVALID;
        	}
		antelope_mex_clear_register( 1 );
	}
	else 
	{
		return PFINVALID;
	}
	
	return 0;
}
Пример #17
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	double	orbfd;
	char	*orbstring_code;
	char	*nodelay_string;
	int	nodelay = 0;
	char	errmsg[STRSZ];
	int	pktid;
	char	srcname[STRSZ];
	char	pkttype[STRSZ];
	double	time;
	char	*packet = 0;
	int	nbytes = 0;
	int	bufsize = 0;
	int	rc;		

	if( nrhs < 1 || nrhs > 2  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_scalar( prhs[0], &orbfd ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

        if( nrhs == 2 )
	{
		if( ! mtlb_get_string( prhs[1], &nodelay_string ) || ! STREQ( nodelay_string, "nodelay" ) )
		{
                	antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
		else
		{
			mxFree( nodelay_string );
			nodelay = 1;
		}
        }

	if( nodelay )
	{
		rc = mex_orbreap_nd( (int) orbfd, &pktid, &srcname[0], &time,
			      &packet, &nbytes, &bufsize );
	} 
	else
	{
		rc = mex_orbreap( (int) orbfd, &pktid, &srcname[0], &time,
			      &packet, &nbytes, &bufsize );
	}
	antelope_mex_clear_register( 1 );

	if( rc < 0 )
	{
		return;
	}

	plhs[0] = orbpkt2mxArray( srcname, time, packet, nbytes, pkttype );
	plhs[1] = CreateDouble( time );
	plhs[2] = mxCreateString( srcname );
	plhs[3] = CreateDouble( (double) pktid );
	plhs[4] = mxCreateString( pkttype );

	free( packet );
}
Пример #18
0
static PyObject* cube_draw( PyObject* self, PyObject* args )
{
    PyObject* dict;
    double aspect, alpha;
    double x, theta;

    if ( !PyArg_ParseTuple( args, "Odd", &dict, &aspect, &alpha ) )
	return NULL;

    // "dict" is a dictionary containing the diagram's parameter values.
    // "aspect" is the aspect ratio of the viewport.
    // "alpha" is the alpha value to multiply all of your drawing
    //   colors by, if you want your diagram to respond to Slithy's
    //   normal fade_in() and fade_out() functions. 


    // if you want to use mark_projection() to save the coordinate
    // system for later use with unproject(), do that here. 


    // now we'll get started setting up our projection.  When this
    // function is called, the corners of the viewport will be at
    // (-aspect,-1) and (aspect,1).
    glMatrixMode( GL_PROJECTION );
    // we'll stretch things out so that the viewport corners are at
    // (-1,-1) and (1,1).  this corresponds to the normal OpenGL
    // default projection.  Do this if you want to use the normal
    // projection setup functions like gluPerspective() or
    // glFrustum().
    glScaled( aspect, 1.0, 1.0 );

    // if you want to use depth testing, you MUST call either
    // opengl_clear_blank() or opengl_clear_color() at this point in
    // order to initialize the depth buffer.
    //
    // opengl_clear_color() will clear the viewport to the current
    // OpenGL color; opengl_clear_blank() will have not alter the
    // color buffer.
    glColor4d( 0.2, 0.2, 0.3, alpha );
    opengl_clear_color();

    // now you can set up your normal OpenGL projection, just as with
    // any other OpenGL drawing.  note that you do NOT do a
    // glLoadIdentity first.
    //
    // you should not push or pop the projection matrix stack.  many
    // OpenGL implementations have only 2 entries on this stack, and
    // Slithy uses both of them.
    gluPerspective( 25.0, aspect, 0.1, 30.0 );

    // Slithy will initialize the model-view matrix to the identity
    // before calling your function.  you are free to push and pop
    // this matrix stack normally.
    glMatrixMode( GL_MODELVIEW );
    glTranslated( 0.0, 0.0, -12.0 );

    // note that to use depth testing, you have to explicitly turn it
    // on.  
    glEnable( GL_DEPTH_TEST );
    
    // use the get_*() functions to retrieve parameter
    // values from the dictionary.
    x = get_scalar( dict, "x" );
    theta = get_scalar( dict, "theta" );

    //
    // now we will draw a rotated cube with open faces.
    //

    glRotated( theta, 0.7, 0.4, -0.1 );
    
    glPushMatrix();
    glColor3d( 1.0, 0.0, 0.0 );
    draw_face( x );
    glColor3d( 0.0, 1.0, 1.0 );
    glRotated( 180.0, 1.0, 0.0, 0.0 );
    draw_face( x );
    glPopMatrix();
    
    glPushMatrix();
    glColor3d( 0.0, 1.0, 0.0 );
    glRotated( 90.0, 0.0, 1.0, 0.0 );
    draw_face( x );
    glColor3d( 1.0, 0.0, 1.0 );
    glRotated( 180.0, 1.0, 0.0, 0.0 );
    draw_face( x );
    glPopMatrix();
    
    glPushMatrix();
    glColor3d( 0.0, 0.0, 1.0 );
    glRotated( 90.0, 1.0, 0.0, 0.0 );
    draw_face( x );
    glColor3d( 1.0, 1.0, 0.0 );
    glRotated( 180.0, 0.0, 1.0, 0.0 );
    draw_face( x );
    glPopMatrix();

    //
    // end of the drawing code.
    //


    // the return value is discarded, but we have to return something,
    // so return the "None" object.
    // to raise an exception, use PyErr_SetString() and return NULL.
    Py_INCREF( Py_None );
    return Py_None;
}
Пример #19
0
Dbvalue *
mxArray2dbvalue( const mxArray *in, int type )
{
	Dbvalue	*value;
	char	warning[STRSZ];
	char	*s;

	value = (Dbvalue *) mxCalloc( 1, sizeof( Dbvalue ) );

	switch( type )
	{
	case dbDBPTR:
		if( ! get_dbptr( in, &value->db ) )
		{
			mxFree( value );
			value = (Dbvalue *) NULL;
		}
		break;
	case dbSTRING:
		if( ! mtlb_get_string( in, &s ) )
		{
			mxFree( value );
			value = (Dbvalue *) NULL;
		}
		else
		{
			strcpy( value->s, s );
			mxFree( s );
		}
		break;
	case dbBOOLEAN:
	case dbINTEGER:
	case dbYEARDAY:
		if( ! get_scalar( in, &value->d ) )
		{
			mxFree( value );
			value = (Dbvalue *) NULL;
		}
		else
		{
			value->i = (int) value->d;
		}
		break;
	case dbREAL:
	case dbTIME:
		if( ! get_scalar( in, &value->d ) )
		{
			mxFree( value );
			value = (Dbvalue *) NULL;
		}
		break;
	default:
		sprintf( warning, 
			"Field type %s not recognized in dbaddv",
			xlatnum( type, Dbxlat, NDbxlat ) );
		mexWarnMsgTxt( warning );
		mxFree( value );
		value = (Dbvalue *) NULL;
		break;
	}

	return value;
}
Пример #20
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	tr;
	double	phi;
	double	theta;
	char	*newchan[3];
	Tbl	*newchan_tbl;
	int	rc;
	int	i;

	if( nrhs != 4 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_dbptr( prhs[0], &tr ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( ! get_scalar( prhs[1], &phi ) )
	{
                antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! get_scalar( prhs[2], &theta ) )
	{
                antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! get_stringtbl( prhs[3], &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 = trrotate( tr, phi, theta, newchan );

	antelope_mex_clear_register( 1 );

	freetbl( newchan_tbl, 0 );

	plhs[0] = CreateDouble( (double) rc );
	if( plhs[0] == NULL )
	{
		mexErrMsgTxt( "trrotate: failed to create return value" );
	}
}