mxArray * dbfield2mxArray( Dbptr db ) { mxArray *result; long type; Dbvalue value; char warning[STRSZ]; dbquery( db, dbFIELD_TYPE, &type ); antelope_mex_clear_register( 1 ); if( dbget( db, value.s ) < 0 ) { antelope_mex_clear_register( 1 ); return (mxArray *) NULL; } switch( type ) { case dbDBPTR: result = CreateDbptrStructFromDbptr( value.db ); break; case dbSTRING: copystrip( value.s, value.s, strlen( value.s ) ); result = mxCreateString( value.s ); break; case dbBOOLEAN: case dbINTEGER: case dbYEARDAY: copystrip( value.s, value.s, strlen( value.s ) ); result = CreateDouble( (double) atol( value.s ) ); break; case dbREAL: case dbTIME: copystrip( value.s, value.s, strlen( value.s ) ); result = CreateDouble( (double) atof( value.s ) ); break; default: sprintf( warning, "Can't interpret field of type %s", xlatnum( type, Dbxlat, NDbxlat ) ); mexWarnMsgTxt( warning ); result = (mxArray *) NULL; break; } return result; }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { #ifndef HAVE_CGEOM mexErrMsgTxt( "No cggrid support in your version of Antelope" ); #else CGGrid *cgg; if( nlhs > 1 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } if( nrhs != 1 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! get_cggrid( prhs[0], &cgg ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } plhs[0] = CreateDouble( (double) cgg->nx ); if( ! plhs[0] ) { mexErrMsgTxt( "Failed to create return value"); } #endif }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { int n; if( nlhs > 1 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } if( nrhs != 0 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } n = elog_mark(); plhs[0] = CreateDouble( (double) n ); if( plhs[0] == NULL ) { mexErrMsgTxt( "elog_mark: failed to create return value" ); } }
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" ); } }
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], ®ex ) ) { 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" ); } }
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 ) ); }
flatbuffers::Offset<LogData> SampleEnvironmentEventDouble::getSEEvent( flatbuffers::FlatBufferBuilder &builder) { auto nameOffset = builder.CreateString(m_name); auto valueOffset = CreateDouble(builder, m_value); auto timestamp = getTimestamp(); return CreateLogData(builder, nameOffset, Value_Double, valueOffset.Union(), timestamp); }
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" ); } }
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 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[] ) { 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 ); }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Dbptr db; Dbvalue *value; int nfields; int retcode = 0; int rc; long type; char errmsg[STRSZ]; char *field_name; int fieldname_index; int fieldval_index; int i; if( nrhs < 3 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ( nrhs - 1 ) % 2 != 0 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! get_dbptr( prhs[0], &db ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } db.record = dbNULL; rc = dbget( db, NULL ); antelope_mex_clear_register( 1 ); if( rc == dbINVALID ) { mexErrMsgTxt( "dbaddv: failed to get null record" ); } db.record = dbSCRATCH; nfields = ( nrhs - 1 ) / 2; for( i = 0; i < nfields; i++ ) { fieldname_index = i * 2 + 1; if( mxGetClassID( prhs[fieldname_index] ) != mxCHAR_CLASS ) { antelope_mexUsageMsgTxt ( USAGE ); return; } } for( i = 0; i < nfields; i++ ) { fieldname_index = i * 2 + 1; fieldval_index = fieldname_index + 1; get_malloced_string( prhs[fieldname_index], &field_name ); db = dblookup ( db, 0, 0, field_name, 0 ); antelope_mex_clear_register( 1 ); rc = dbquery ( db, dbFIELD_TYPE, &type ); antelope_mex_clear_register( 1 ); if( rc == dbINVALID ) { sprintf( errmsg, "dbaddv: dbquery failed for field %s", field_name ); mxFree( field_name ); mexErrMsgTxt( errmsg ); } value = mxArray2dbvalue( prhs[fieldval_index], type ); if( value == (Dbvalue *) NULL ) { sprintf( errmsg, "dbaddv: failed to convert field %s", field_name ); mxFree( field_name ); mexErrMsgTxt( errmsg ); } switch( type ) { case dbDBPTR: retcode |= dbputv( db, 0, field_name, value->db, NULL ); break; case dbSTRING: retcode |= dbputv( db, 0, field_name, value->s, NULL ); break; case dbBOOLEAN: case dbINTEGER: case dbYEARDAY: retcode |= dbputv( db, 0, field_name, value->i, NULL ); break; case dbREAL: case dbTIME: retcode |= dbputv( db, 0, field_name, value->d, NULL ); break; default: retcode = -1; break; } antelope_mex_clear_register( 1 ); mxFree( value ); mxFree( field_name ); } if( retcode != 0 ) { mexErrMsgTxt( "dbaddv failed\n" ); } retcode = dbaddchk ( db, 0 ) ; antelope_mex_clear_register( 1 ); if( retcode < 0 ) { mexErrMsgTxt( "dbaddv failed\n" ); } else { plhs[0] = CreateDouble( (double) retcode ); if( plhs[0] == NULL ) { mexErrMsgTxt( "dbaddv: failed to create return value" ); } } }
bool ff::Value::Convert(Type type, Value **ppValue) const { assertRetVal(ppValue, false); *ppValue = nullptr; if (type == GetType()) { *ppValue = GetAddRef(const_cast<Value *>(this)); return true; } wchar_t buf[256]; switch (GetType()) { case Type::Null: switch (type) { case Type::String: CreateString(String(L"null"), ppValue); break; } break; case Type::Bool: switch (type) { case Type::Double: CreateDouble(AsBool() ? 1.0 : 0.0, ppValue); break; case Type::Float: CreateFloat(AsBool() ? 1.0f : 0.0f, ppValue); break; case Type::Int: CreateInt(AsBool() ? 1 : 0, ppValue); break; case Type::String: CreateString(AsBool() ? String(L"true") : String(L"false"), ppValue); break; } break; case Type::Double: switch (type) { case Type::Bool: CreateBool(AsDouble() != 0, ppValue); break; case Type::Float: CreateFloat((float)AsDouble(), ppValue); break; case Type::Int: CreateInt((int)AsDouble(), ppValue); break; case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%g", AsDouble()); CreateString(String(buf), ppValue); break; } break; case Type::Float: switch (type) { case Type::Bool: CreateBool(AsFloat() != 0, ppValue); break; case Type::Double: CreateDouble((double)AsFloat(), ppValue); break; case Type::Int: CreateInt((int)AsFloat(), ppValue); break; case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%g", AsFloat()); CreateString(String(buf), ppValue); break; } break; case Type::Int: switch (type) { case Type::Bool: CreateBool(AsInt() != 0, ppValue); break; case Type::Double: CreateDouble((double)AsInt(), ppValue); break; case Type::Float: CreateFloat((float)AsInt(), ppValue); break; case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%d", AsInt()); CreateString(String(buf), ppValue); break; } break; case Type::Point: switch (type) { case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%d,%d)", AsPoint().x, AsPoint().y); CreateString(String(buf), ppValue); break; } break; case Type::PointF: switch (type) { case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%g,%g)", AsPointF().x, AsPointF().y); CreateString(String(buf), ppValue); break; } break; case Type::Rect: switch (type) { case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%d,%d,%d,%d)", AsRect().left, AsRect().top, AsRect().right, AsRect().bottom); CreateString(String(buf), ppValue); break; } break; case Type::RectF: switch (type) { case Type::String: _snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%g,%g,%g,%g)", AsRectF().left, AsRectF().top, AsRectF().right, AsRectF().bottom); CreateString(String(buf), ppValue); break; } break; case Type::String: switch (type) { case Type::Bool: if (AsString().empty() || AsString() == L"false" || AsString() == L"no" || AsString() == L"0") { CreateBool(false, ppValue); } else if (AsString() == L"true" || AsString() == L"yes" || AsString() == L"1") { CreateBool(true, ppValue); } break; case Type::Double: { const wchar_t *start = AsString().c_str(); wchar_t *end = nullptr; double val = wcstod(start, &end); if (end > start && !*end) { CreateDouble(val, ppValue); } } break; case Type::Float: { const wchar_t *start = AsString().c_str(); wchar_t *end = nullptr; double val = wcstod(start, &end); if (end > start && !*end) { CreateFloat((float)val, ppValue); } } break; case Type::Int: { const wchar_t *start = AsString().c_str(); wchar_t *end = nullptr; long val = wcstol(start, &end, 10); if (end > start && !*end) { CreateInt((int)val, ppValue); } } break; case Type::Guid: { GUID guid; if (StringToGuid(AsString(), guid)) { CreateGuid(guid, ppValue); } } break; } break; case Type::Object: switch (type) { case Type::Bool: CreateBool(AsObject() != nullptr, ppValue); break; } break; case Type::Guid: switch (type) { case Type::String: CreateString(StringFromGuid(AsGuid()), ppValue); break; } break; case Type::Data: switch (type) { case Type::SavedData: { ff::ComPtr<ff::ISavedData> savedData; if (ff::CreateLoadedDataFromMemory(AsData(), false, &savedData)) { CreateSavedData(savedData, ppValue); } } break; } break; case Type::SavedData: switch (type) { case Type::Data: { ff::ComPtr<ff::ISavedData> savedData; if (AsSavedData()->Clone(&savedData)) { ff::ComPtr<ff::IData> data = savedData->Load(); if (data) { CreateData(data, ppValue); } } } break; } break; case Type::Dict: switch (type) { case Type::Data: case Type::SavedData: case Type::SavedDict: { ff::ComPtr<ff::IData> data; ff::ComPtr<ff::ISavedData> savedData; if (ff::SaveDict(AsDict(), true, false, &data)) { if (type == Type::Data) { CreateData(data, ppValue); } else if (ff::CreateLoadedDataFromMemory(data, true, &savedData)) { if (type == Type::SavedData) { CreateSavedData(savedData, ppValue); } else { CreateSavedDict(savedData, ppValue); } } } } break; } break; case Type::SavedDict: switch (type) { case Type::Data: { ff::ComPtr<ff::ISavedData> savedData; if (AsSavedData()->Clone(&savedData)) { ff::ComPtr<ff::IData> data = savedData->Load(); if (data) { CreateData(data, ppValue); } } } break; case Type::SavedData: CreateSavedData(AsSavedData(), ppValue); break; case Type::Dict: { ff::ComPtr<ff::ISavedData> savedData; if (AsSavedData()->Clone(&savedData)) { ff::ComPtr<ff::IData> data = savedData->Load(); ff::ComPtr<ff::IDataReader> dataReader; Dict dict; if (data && ff::CreateDataReader(data, 0, &dataReader) && ff::LoadDict(dataReader, dict)) { CreateDict(std::move(dict), ppValue); } } } break; } break; case Type::Resource: AsResource()->GetValue()->Convert(type, ppValue); break; case Type::IntVector: switch (type) { case Type::Point: if (AsIntVector().Size() == 2) { PointInt point( AsIntVector().GetAt(0), AsIntVector().GetAt(1)); CreatePoint(point, ppValue); } break; case Type::Rect: if (AsIntVector().Size() == 4) { RectInt rect( AsIntVector().GetAt(0), AsIntVector().GetAt(1), AsIntVector().GetAt(2), AsIntVector().GetAt(3)); CreateRect(rect, ppValue); } break; } break; case Type::FloatVector: switch (type) { case Type::PointF: if (AsFloatVector().Size() == 2) { PointFloat point( AsFloatVector().GetAt(0), AsFloatVector().GetAt(1)); CreatePointF(point, ppValue); } break; case Type::RectF: if (AsFloatVector().Size() == 4) { RectFloat rect( AsFloatVector().GetAt(0), AsFloatVector().GetAt(1), AsFloatVector().GetAt(2), AsFloatVector().GetAt(3)); CreateRectF(rect, ppValue); } break; } break; case Type::ValueVector: switch (type) { case Type::Point: if (AsValueVector().Size() == 2) { ValuePtr newValues[2]; const Vector<ValuePtr> &values = AsValueVector(); if (values[0]->Convert(Type::Int, &newValues[0]) && values[1]->Convert(Type::Int, &newValues[1])) { CreatePoint(PointInt(newValues[0]->AsInt(), newValues[1]->AsInt()), ppValue); } } break; case Type::PointF: if (AsValueVector().Size() == 2) { ValuePtr newValues[2]; const Vector<ValuePtr> &values = AsValueVector(); if (values[0]->Convert(Type::Float, &newValues[0]) && values[1]->Convert(Type::Float, &newValues[1])) { CreatePointF(PointFloat(newValues[0]->AsFloat(), newValues[1]->AsFloat()), ppValue); } } break; case Type::Rect: if (AsValueVector().Size() == 4) { ValuePtr newValues[4]; const Vector<ValuePtr> &values = AsValueVector(); if (values[0]->Convert(Type::Int, &newValues[0]) && values[1]->Convert(Type::Int, &newValues[1]) && values[2]->Convert(Type::Int, &newValues[2]) && values[3]->Convert(Type::Int, &newValues[3])) { CreateRect(RectInt( newValues[0]->AsInt(), newValues[1]->AsInt(), newValues[2]->AsInt(), newValues[3]->AsInt()), ppValue); } } break; case Type::RectF: if (AsValueVector().Size() == 4) { ValuePtr newValues[4]; const Vector<ValuePtr> &values = AsValueVector(); if (values[0]->Convert(Type::Float, &newValues[0]) && values[1]->Convert(Type::Float, &newValues[1]) && values[2]->Convert(Type::Float, &newValues[2]) && values[3]->Convert(Type::Float, &newValues[3])) { CreateRectF(RectFloat( newValues[0]->AsFloat(), newValues[1]->AsFloat(), newValues[2]->AsFloat(), newValues[3]->AsFloat()), ppValue); } } break; case Type::StringVector: { bool valid = true; Vector<String> newValues; const Vector<ValuePtr> &values = AsValueVector(); for (ValuePtr oldValue : values) { ValuePtr newValue; valid = oldValue->Convert(Type::String, &newValue); if (valid) { newValues.Push(newValue->AsString()); } else { break; } } if (valid) { CreateStringVector(std::move(newValues), ppValue); } } break; case Type::IntVector: { bool valid = true; Vector<int> newValues; const Vector<ValuePtr> &values = AsValueVector(); for (ValuePtr oldValue : values) { ValuePtr newValue; valid = oldValue->Convert(Type::Int, &newValue); if (valid) { newValues.Push(newValue->AsInt()); } else { break; } } if (valid) { CreateIntVector(std::move(newValues), ppValue); } } break; case Type::DoubleVector: { bool valid = true; Vector<double> newValues; const Vector<ValuePtr> &values = AsValueVector(); for (ValuePtr oldValue : values) { ValuePtr newValue; valid = oldValue->Convert(Type::Double, &newValue); if (valid) { newValues.Push(newValue->AsDouble()); } else { break; } } if (valid) { CreateDoubleVector(std::move(newValues), ppValue); } } break; case Type::FloatVector: { bool valid = true; Vector<float> newValues; const Vector<ValuePtr> &values = AsValueVector(); for (ValuePtr oldValue : values) { ValuePtr newValue; valid = oldValue->Convert(Type::Float, &newValue); if (valid) { newValues.Push(newValue->AsFloat()); } else { break; } } if (valid) { CreateFloatVector(std::move(newValues), ppValue); } } break; } break; } if (*ppValue) { return true; } return false; }
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" ); } } }
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[] ) { 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 ); }