void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	char	*a;
	char	*b;
	char	*res;
	char	*hold;
	char	*another;
	int	nleft;

	if( nrhs < 2  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! mtlb_get_string( prhs[0], &a ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! mtlb_get_string( prhs[1], &b ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	res = concatpaths( a, b, NULL );

	nleft = nrhs - 2;

	while( nleft > 0 ) {

		nleft--;

		hold = res;

        	if( ! mtlb_get_string( prhs[nrhs-1-nleft], &another ) )
        	{
               		antelope_mexUsageMsgTxt ( USAGE );
			return;
        	}

		res = concatpaths( hold, another, NULL );

		free( hold );
	}

	plhs[0] = mxCreateString( res );

	if( res != (char *) NULL ) {

		free( res );
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	char	*message;

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

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

	elog_debug( 0, message );

	mxFree( message );
}
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" );
	}
}
Example #4
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    char	*envname = NULL;
    char	*dirname = NULL;
    char	*filename = NULL;
    char	*suffix = NULL;
    char	*fname = NULL;

    if( nrhs != 4  )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! mtlb_get_string( prhs[0], &envname ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! mtlb_get_string( prhs[1], &dirname ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! mtlb_get_string( prhs[2], &filename ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }
    else if( ! mtlb_get_string( prhs[3], &suffix ) )
    {
        antelope_mexUsageMsgTxt ( USAGE );
        return;
    }

    fname = datapath( envname, dirname, filename, suffix );

    plhs[0] = mxCreateString( fname );

    if( fname != (char *) NULL ) {

        free( fname );
    }
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	char	*tablename = 0;
	char	filename[FILENAME_MAX];
	char	status[STRSZ];
	int	rc;

	if( nrhs != 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_dbptr( prhs[0], &db ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( ! mtlb_get_string( prhs[1], &tablename ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	rc = dbextfile( db, tablename, filename );
	antelope_mex_clear_register( 1 );
	switch( rc ) {
	case 2:
		sprintf( status, "file exists, is compressed, and is readable" );
		break;
	case 1:
		sprintf( status, "file exists and is readable" );
		break;
	case 0:
		sprintf( status, "file does not exist, but directory is writeable" );
		break;
	case -1:
		sprintf( status, "file does not exist; directory is not writeable" );
		break;
	default:
		sprintf( status, "file status unknown" );
		break;
	}

	mxFree( tablename );

	plhs[0] = mxCreateString( filename );
	plhs[1] = mxCreateString( status );
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Pf 	*pf;
	char	*name;
	char	*mystring;
	mxArray	*input[1];

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

	if( nrhs != 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_pf( prhs[0], &pf ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( ! mtlb_get_string( prhs[1], &name ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	pfconfig( "ask", (void *) matlabPfprompt );

	mystring = pfget_string( pf, name );	
	antelope_mex_clear_register( 1 );

	mxFree( name );

	if( mystring == NULL )
	{
		mexErrMsgTxt( "pfget_num: Couldn't get specified value" );
	}
	else
	{
		input[0] = mxCreateString( mystring );
		mexCallMATLAB( 1, plhs, 1, input, "str2double" );
		mxDestroyArray( input[0] );
	}
}
Example #7
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	char	*record;
	int	use_dbscratch = 0;
	int	rc;

	if( nrhs != 2  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! get_dbptr( prhs[0], &db ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! mtlb_get_string( prhs[1], &record ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	if( STREQ( record, "dbSCRATCH" ) )
	{
		mxFree( record );
		record = 0;
	}

	rc = dbadd( db, record );
	antelope_mex_clear_register( 1 );

	if( record ) mxFree( record );

	if( rc < 0 )
	{
		mexErrMsgTxt( "dbadd: failed to add record" );
	}
	else
	{
		plhs[0] = CreateDouble( (double) rc );
		if( plhs[0] == NULL )
		{
			mexErrMsgTxt( "dbadd: failed to create return value" );
		}
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	int	type;
	char	*string;
	int	printflag;
	double	*doublep;
	int	*intp;
	int	i;
	char	**messages;
	int	*count;
	int	NMAX;
	int	next, wrapflag;
	char	s[STRSZ];

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

	if( nrhs == 1 )
	{
		if( ! mtlb_get_string( prhs[0], &string ) )
		{
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		} 
		else if( ! STREQ( string, "print" ) )
		{
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		} 
		else
		{
			mxFree( string );
			printflag = 1;
		}

	}
	else
	{
		printflag = 0;
	}

	antelope_mex_clear_register ( printflag );
}
Example #9
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	tr;
	char	*tr_path = 0;
	char 	*schema_name = 0;
	char	errmsg[STRSZ];

	if( nrhs > 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( nrhs >= 1 && ! get_trimmed_string( prhs[0], &tr_path ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( nrhs == 2 && ! mtlb_get_string( prhs[1], &schema_name ) )
        {
		mxFree( tr_path );
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	tr = trnew( tr_path, schema_name ); 
	antelope_mex_clear_register( 1 );

	if( tr_path ) mxFree( tr_path );
	if( schema_name ) mxFree( schema_name );

	if( tr.database == dbINVALID ) 
	{
		mexErrMsgTxt( "trnew: failed to create new trace database" );
	}

	plhs[0] = CreateDbptrStructFromDbptr( tr );

	if( plhs[0] == NULL )
	{
		sprintf( errmsg, "trnew: failed to create database-pointer " );
		strcat( errmsg, "structure for result" );
		mexErrMsgTxt( errmsg );
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	int	rc;
	int	argc = 1;
	char	**argv;

	allot( char **, argv, 1 );

	if( nrhs == 0 ) 
	{
		argv[0] = strdup( "Matlab" );
	} 
	else if( nrhs == 1 ) 
	{

		if( ! mtlb_get_string( prhs[0], &argv[0] ) ) 
		{
			free( argv );
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
	}
	else
	{
		free( argv );
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	rc = elog_init( argc, argv );

	elog_set( ELOG_CALLBACK, 0, antelope_mex_elog_callback );

	strcpy( Program_Name, argv[0] );

	plhs[0] = CreateDouble( (double) rc );

	if( plhs[0] == NULL )
	{
		mexErrMsgTxt( "elog_init: failed to create return value" );
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	char	*rel;
	char	abs[FILENAME_MAX] = "";

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

	abspath( rel, abs );

	plhs[0] = mxCreateString( abs );
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	char	*table;
	char	errmsg[STRSZ];

	if( nrhs != 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! get_dbptr( prhs[0], &db ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! mtlb_get_string( prhs[1], &table ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	db = dbseparate( db, table );
	antelope_mex_clear_register( 1 );
	if( db.table == dbINVALID ) 
	{
		mexErrMsgTxt( "dbseparate: returned invalid database pointer" );
	}

	mxFree( table );

	plhs[0] = CreateDbptrStructFromDbptr( db );

	if( plhs[0] == NULL )
	{
		sprintf( errmsg, "dbseparate: failed to create " );
		strcat( errmsg, "database-pointer structure for result" );
		mexErrMsgTxt( errmsg );
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	char	*formatstring;
	char	*timestring;
	mxArray	*timestr;
	double	*epoch;
	int	M, N;
	int	nsubs = 2;
	int	subs[2];
	int	cell_index;
	int	i, j;

	if( nrhs != 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( mxGetClassID( prhs[0] ) != mxDOUBLE_CLASS )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! mtlb_get_string( prhs[1], &formatstring ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	epoch = mxGetPr( prhs[0] );

	M = mxGetM( prhs[0] );
	N = mxGetN( prhs[0] );

	if( M == 1 && N == 1 ) 
	{
		timestring = epoch2str( *epoch, formatstring );
		antelope_mex_clear_register( 1 );
		plhs[0] = mxCreateString( timestring );
		free( timestring );
	}
	else 
	{

		plhs[0] = mxCreateCellMatrix( M, N );

		for( i = 0; i < M; i++ ) 
		{
	   	   for( j = 0; j < N; j++ ) 
	   	   {

			timestring = epoch2str( *(epoch + i*N + j),
						 formatstring );
			antelope_mex_clear_register( 1 );
			timestr = mxCreateString( timestring );
			free( timestring );

			subs[0] = i; 
			subs[1] = j;

			cell_index = mxCalcSingleSubscript( plhs[0],
							    nsubs, subs );

			mxSetCell( plhs[0], cell_index, timestr );
	   	   }
		}
	}

	mxFree( formatstring );
}
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 );
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	mxArray	*array_ptr;
	char	errmsg[STRSZ];
	char	*dbstring_code;
	int	dbcode;
	int	retcode;
	char	*string;
	Tbl	*tbl;
	long	n;
	int	i;

	if( nrhs != 2  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_dbptr( prhs[0], &db ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! mtlb_get_string( prhs[1], &dbstring_code ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }

	dbcode = xlatname( dbstring_code, Dbxlat, NDbxlat );

	switch( dbcode )
	{
	case dbSCHEMA_DEFAULT:
	case dbDATABASE_FILENAME:
	case dbIDSERVER:
	case dbLOCKS:
        case dbSCHEMA_DESCRIPTION:
        case dbTIMEDATE_NAME:
        case dbDATABASE_DESCRIPTION:
        case dbTABLE_DESCRIPTION:
        case dbFIELD_DESCRIPTION:
        case dbSCHEMA_DETAIL:
        case dbDATABASE_DETAIL:
        case dbTABLE_DETAIL:
        case dbFIELD_DETAIL:
        case dbSCHEMA_NAME:
        case dbDATABASE_NAME:
        case dbTABLE_NAME:
        case dbFIELD_NAME:
        case dbTABLE_FILENAME:
        case dbTABLE_DIRNAME:
        case dbFIELD_RANGE:
        case dbFIELD_FORMAT:
        case dbDBPATH:
        case dbFORMAT:
        case dbFIELD_UNITS:
        case dbFIELD_BASE_TABLE:
        case dbUNIQUE_ID_NAME:
		if( ( retcode = dbquery(db, dbcode, &string) ) >= 0 )
		{
			plhs[0] = mxCreateString( string );
		}
		antelope_mex_clear_register( 1 );
		break;

        case dbDATABASE_COUNT:
        case dbTABLE_COUNT:
        case dbFIELD_COUNT:
        case dbRECORD_COUNT:
        case dbTABLE_SIZE:
        case dbFIELD_SIZE:
        case dbFIELD_INDEX:
        case dbVIEW_TABLE_COUNT:
        case dbRECORD_SIZE:
        case dbTABLE_IS_WRITEABLE:
        case dbTABLE_IS_VIEW:
	case dbDATABASE_IS_WRITABLE:
	case dbTABLE_PRESENT:
	case dbTABLE_IS_TRANSIENT:
		if( ( retcode = dbquery(db, dbcode, &n) ) >= 0 )
		{
			antelope_mex_clear_register( 1 );
			plhs[0] = CreateDouble( (double) n );
			if( plhs[0] == NULL )
			{
				mxFree( dbstring_code );
				mexErrMsgTxt( 
				   "dbquery: failed to create return value" );
			}
		}
		else
		{
			antelope_mex_clear_register( 1 );
		}
                break;  

        case dbFIELD_TYPE:
		if( ( retcode = dbquery(db, dbcode, &n) ) >= 0 )
		{
			antelope_mex_clear_register( 1 );
			plhs[0] = mxCreateString( xlatnum( n, Dbxlat, NDbxlat ) );
		}
		else
		{
			antelope_mex_clear_register( 1 );
		}
                break;  
 
        case dbLINK_FIELDS:
        case dbSCHEMA_FIELDS:
	case dbSCHEMA_TABLES:
        case dbFIELD_TABLES:
        case dbVIEW_TABLES:
        case dbTABLE_FIELDS:
        case dbPRIMARY_KEY:
        case dbALTERNATE_KEY:
        case dbFOREIGN_KEYS:
		if( ( retcode = dbquery(db, dbcode, &tbl) ) >= 0 )
		{
			antelope_mex_clear_register( 1 );
			plhs[0] = stringtbl2cellstr( tbl );
		}
		else
		{
			antelope_mex_clear_register( 1 );
		}
                break;  
 
        default:
		sprintf( errmsg, "dbquery: bad code '%s'", dbstring_code );
		mxFree( dbstring_code );
		mexErrMsgTxt( errmsg );
		break ;
	}

	mxFree( dbstring_code );
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	tr;
	Dbptr	db;
	char	*datatype;
	char	*wfname;
	int	rc;
	int	flags = 0;
	char 	*flag_string;

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

	if( nrhs == 5 )
	{
		if( ! mtlb_get_string( prhs[4], &flag_string ) ) 
		{
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		}

		if( STREQ( flag_string, "overwrite" ) )
		{
			flags |= trOVERWRITE;
		}
		else if( STREQ( flag_string, "append" ) )
		{
			flags |= trAPPEND;
		}
		else
		{
			antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
	}

	rc = trsave_wf( tr, db, datatype, wfname, flags );
	antelope_mex_clear_register( 1 );

	mxFree( datatype );
	mxFree( wfname );

	if( rc & TR_CLIPPED || rc & TR_TRUNCATED )
	{
		mexWarnMsgTxt( 
			"trsave_wf: clipping occurred during conversion\n" );
	}
	if( rc < 0 ) mexErrMsgTxt( "trsave_wf failed\n" );
}
Example #17
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	char	*result = NULL;
	char	*dbscratch_string;
	int	use_dbscratch = 0;
	long	n;
	int	rc;
	double	*doublep;
	int	*intp;

	if( nrhs < 1 || nrhs > 2 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_dbptr( prhs[0], &db ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( nrhs == 2 ) 
        {
		if( ! mtlb_get_string( prhs[1], &dbscratch_string ) )
		{
                	antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
		else if( ! STREQ( dbscratch_string, "dbSCRATCH" ) )
		{
			mxFree( dbscratch_string );
                	antelope_mexUsageMsgTxt ( USAGE );
			return;
		}
		else
		{
			mxFree( dbscratch_string );
			use_dbscratch = 1;
		}
        }

	if( use_dbscratch )
	{
		if( dbget( db, NULL ) < 0 )
		{
			antelope_mex_clear_register( 1 );
			mexErrMsgTxt( "dbget into scratch record failed" );
		}
	}
	else
	{
		rc = dbquery(db, dbSIZE, &n);
		antelope_mex_clear_register( 1 );
		if( rc == dbINVALID )
		{
			mexErrMsgTxt( "dbget: dbquery failed" );
		}

		result = (char *) mxCalloc( n+3, sizeof( char ) );

		if( dbget( db, result ) < 0 )
		{

			antelope_mex_clear_register( 1 );

			mxFree( result );
			mexErrMsgTxt( "dbget failed\n" );

		}
		else
		{
			if ( db.field != dbALL )
			{
				copystrip( result, result, n );
			}
			plhs[0] = mxCreateString( result );
			mxFree( result );
		}
	}

	antelope_mex_clear_register( 1 );
}
Example #18
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;
}
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 );
		}
	}
}
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	char	*database;
	char	*table;
	char	*field;
	char	*record;
	char	errmsg[STRSZ];

	if( nrhs != 5  )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! get_dbptr( prhs[0], &db ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! mtlb_get_string( prhs[1], &database ) )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! mtlb_get_string( prhs[2], &table ) )
	{
		mxFree( database );
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! mtlb_get_string( prhs[3], &field ) )
	{
		mxFree( database );
		mxFree( table );
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
	else if( ! mtlb_get_string( prhs[4], &record ) )
	{
		mxFree( database );
		mxFree( table );
		mxFree( field );
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}

	if( ! STREQ( record, "" ) &&
	    ! STREQ( record, "dbSCRATCH" ) &&
	    ! STREQ( record, "dbNULL" ) && 
	    ! STREQ( record, "dbALL" ) )
	{
		/* We're trying to match a record... */

		if( STREQ( field, "dbALL" ) ||
		    ( STREQ( field, "" ) && db.field < 0 ) )
		{
			/* But we don't know which field to look at */

			mxFree( database );
			mxFree( table );
			mxFree( field );
			mxFree( record );
			mexErrMsgTxt(
			  "dblookup: Specify field before matching records" );
		}

	}

	db = dblookup( db, database, table, field, record );
	antelope_mex_clear_register( 1 );

	mxFree( database );
	mxFree( table );
	mxFree( field );
	mxFree( record );

	plhs[0] = CreateDbptrStructFromDbptr( db );

	if( plhs[0] == NULL )
	{
		sprintf( errmsg, "dblookup: failed to create " );
		strcat( errmsg, "database-pointer structure for result" );
		mexErrMsgTxt( errmsg );
	}
}
Example #21
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;
}
Example #22
0
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	Dbptr	db;
	int	single_row;
	long	nrows;
	int	code = 0;
	int	rc = 0;
	char	*expression;
	char	*codestr;
	Expression *expr;
	Dbvalue	exresult;
	double	*pr;

	if( nrhs != 2 && nrhs != 3 )
	{
		antelope_mexUsageMsgTxt ( USAGE );
		return;
	}
        else if( ! get_dbptr( prhs[0], &db ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( ! mtlb_get_string( prhs[1], &expression ) )
        {
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
        else if( nrhs == 3 && ! mtlb_get_string( prhs[2], &codestr ) )
        {
		mxFree( expression );
                antelope_mexUsageMsgTxt ( USAGE );
		return;
        }
	else if( nrhs == 3 )
	{
		code = xlatname( codestr, Dbxlat, NDbxlat );
		mxFree( codestr );
	}

	if( dbex_compile( db, expression, &expr, code ) < 0 )
	{
		antelope_mex_clear_register( 1 );
		mxFree( expression );
		mexErrMsgTxt( "dbeval: expression failed to compile\n" );
	}
	else
	{
		antelope_mex_clear_register( 1 );
		mxFree( expression );
	}

	rc = dbquery( db, dbRECORD_COUNT, &nrows );
	antelope_mex_clear_register( 1 );
	if( rc == dbINVALID ) 
	{
		mexErrMsgTxt( "dbgetv: query for number of records failed" );
	}

	if( db.record == dbALL ) {
		if( nrows == 1 ) {
			single_row = 1;
			db.record = 0;
		} else {
			single_row = 0;
		}
	} else {
		single_row = 1;
	}

	if( single_row ) 
	{
		rc = dbex_eval ( db, expr, 1, &exresult ) ;
		antelope_mex_clear_register( 1 );

		if( rc >= 0 )
		{
		   switch( expr->type )
		   {
			case dbBOOLEAN:
			case dbINTEGER:
			case dbYEARDAY:
				plhs[0] = CreateDouble( (double)  exresult.i );
				if( plhs[0] == NULL )
				{
					dbex_free( expr );
					mexErrMsgTxt( 
				   	"dbeval: failed to create return value" );
				}
				break;
			case dbREAL:
			case dbTIME:
				plhs[0] = CreateDouble( exresult.d );
				if( plhs[0] == NULL )
				{
					dbex_free( expr );
					mexErrMsgTxt( 
				   	"dbeval: failed to create return value" );
				}
				break;
			case dbSTRING:
				plhs[0] = mxCreateString( exresult.t );
				free( exresult.t );
				break;
			default:
				dbex_free( expr );
				mexErrMsgTxt( "Unknown type in dbeval\n" );
				break;
		   }
		   dbex_free( expr );
		}
		else
		{
			dbex_free( expr );
			mexErrMsgTxt( "dbeval: eval failed\n" );
		}
	} else {

		db.record = 0;

		rc = dbex_eval ( db, expr, 1, &exresult ) ;
		antelope_mex_clear_register( 1 );

		if( rc >= 0 )
		{
		   switch( expr->type )
		   {
			case dbBOOLEAN:
			case dbINTEGER:
			case dbYEARDAY:
				plhs[0] = mxCreateDoubleMatrix( nrows, 1, mxREAL );
				if( plhs[0] == NULL )
				{
					dbex_free( expr );
					mexErrMsgTxt( 
				   	"dbeval: failed to create return value" );
				}

				pr = mxGetPr( plhs[0] );
				pr[db.record] = (double) exresult.i;

				for( db.record = 1; db.record < nrows; db.record++ )
				{
					if( dbex_eval ( db, expr, 1, &exresult ) < 0 ) 
					{
						antelope_mex_clear_register( 1 );
						dbex_free( expr );
						mxDestroyArray( plhs[0] );
						mexErrMsgTxt( "dbeval: eval failed\n" );
					} else {
						pr[db.record] = (double) exresult.i;
					}
				}

				break;
			case dbREAL:
			case dbTIME:
				plhs[0] = mxCreateDoubleMatrix( nrows, 1, mxREAL );
				if( plhs[0] == NULL )
				{
					dbex_free( expr );
					mexErrMsgTxt( 
				   	"dbeval: failed to create return value" );
				}

				pr = mxGetPr( plhs[0] );
				pr[db.record] = exresult.d;

				for( db.record = 1; db.record < nrows; db.record++ )
				{
					if( dbex_eval ( db, expr, 1, &exresult ) < 0 ) 
					{
						antelope_mex_clear_register( 1 );
						dbex_free( expr );
						mxDestroyArray( plhs[0] );
						mexErrMsgTxt( "dbeval: eval failed\n" );
					} else {
						pr[db.record] = (double) exresult.d;
					}
				}

				break;
			case dbSTRING:
				plhs[0] = mxCreateCellMatrix( nrows, 1 );
				if( plhs[0] == NULL )
				{
					dbex_free( expr );
					mexErrMsgTxt( 
				   	"dbeval: failed to create return value" );
				}

				mxSetCell( plhs[0], db.record, mxCreateString( exresult.t ) );
				free( exresult.t );

				for( db.record = 1; db.record < nrows; db.record++ )
				{
					if( dbex_eval ( db, expr, 1, &exresult ) < 0 ) 
					{
						antelope_mex_clear_register( 1 );
						dbex_free( expr );
						mxDestroyArray( plhs[0] );
						mexErrMsgTxt( "dbeval: eval failed\n" );
					} else {
						mxSetCell( plhs[0], db.record, mxCreateString( exresult.t ) );
						free( exresult.t );
					}
				}

				break;
			default:
				dbex_free( expr );
				mexErrMsgTxt( "Unknown type in dbeval\n" );
				break;
		   }
		   dbex_free( expr );
		}
		else
		{
			dbex_free( expr );
			mexErrMsgTxt( "dbeval: eval failed\n" );
		}
	}
}