void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Dbptr db; int single_row; int nrows; int nfields; char *field_name; int arg_index; int rc; int i; if( nrhs < 2 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! get_dbptr( prhs[0], &db ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } nfields = nrhs - 1; for( i=0; i< nfields; i++ ) { arg_index = i + 1; if( mxGetClassID( prhs[arg_index] ) != mxCHAR_CLASS ) { antelope_mexUsageMsgTxt ( USAGE ); return; } } rc = dbquery( db, dbRECORD_COUNT, &nrows ); antelope_mex_clear_register( 1 ); if( rc == dbINVALID ) { mexErrMsgTxt( "dbgetv: query for number of records failed" ); } if( nrows <= 0 ) { mexErrMsgTxt( "dbgetv: no rows in database view" ); } if( db.record == dbALL ) { if( nrows == 1 ) { single_row = 1; db.record = 0; } else { single_row = 0; } } else { single_row = 1; } for( i = 0; i < nfields; i++ ) { arg_index = i + 1; get_malloced_string( prhs[arg_index], &field_name ); db = dblookup ( db, 0, 0, field_name, 0 ); antelope_mex_clear_register( 1 ); if( db.field < 0 ) { cleanup_and_bail( plhs, field_name, i ); } if( single_row ) { plhs[i] = dbfield2mxArray( db ); } else { plhs[i] = dbcolumn2mxArray( db ); } if( plhs[i] == (mxArray *) NULL ) { cleanup_and_bail( plhs, field_name, i ); } mxFree( field_name ); } }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Dbptr db; Dbvalue *value; char errmsg[STRSZ]; char *field_name; int nfields; int retcode = 0; int rc; long type; 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; } 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, "dbputv: dbquery failed for field %s", field_name ); mxFree( field_name ); mexErrMsgTxt( errmsg ); } value = mxArray2dbvalue( prhs[fieldval_index], type ); if( value == (Dbvalue *) NULL ) { sprintf( errmsg, "dbputv: 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 dbYEARDAY: case dbINTEGER: 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( "dbputv failed" ); } }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Dbptr db; Point *polygon; char *pname; char *ptype; char *auth; char *dir; char *dfile; char *s_pcode; int pcode; double *lat; double *lon; long nsamp; mwSize nlat,nlon; const mwSize *dimensions; int i; int retcode; char *dbfile_name; char *dbschema_name; char errmsg[STRSZ]; if ( nrhs != 9 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( ! get_dbptr( prhs[0], &db ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsDouble( prhs[1] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsDouble( prhs[2] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[3] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[4] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[5] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[6] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[7] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[8] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } dimensions= (mwSize*) mxGetDimensions( prhs[1] ); if (dimensions[1] != 1 && dimensions[0] != 1) { mexErrMsgTxt("writepolygondata: LAT must have dimensions Nx1 or 1xN\n"); } if (dimensions[1] == 1) { nlat= dimensions[0]; } else { nlat= dimensions[1]; } dimensions= (mwSize *)mxGetDimensions( prhs[2] ); if (dimensions[1] != 1 && dimensions[0] != 1) { mexErrMsgTxt("writepolygondata: LON must have dimensions Nx1 or 1xN\n"); } if (dimensions[1] == 1) { nlon= dimensions[0]; } else { nlon= dimensions[1]; } if (nlat != nlon) { mexErrMsgTxt("writepolygondata: LAT and LON must be of same size\n"); } if( ( retcode = dbquery(db, dbDATABASE_FILENAME, &dbfile_name) ) < 0 ) { mexErrMsgTxt("writepolygondata: problem getting descriptor filename\n"); } if ( is_file(dbfile_name)==1 ) { if( ( retcode = dbquery(db, dbSCHEMA_NAME, &dbschema_name) ) < 0 ) { mexErrMsgTxt("writepolygondata: problem getting schema name\n"); } else { if (strmatches(dbschema_name,"polygon1.2.*", 0) != 1) { sprintf(errmsg, "writepolygondata: wrong schema '%s' for output database '%s'\n",dbschema_name,dbfile_name); mexErrMsgTxt(errmsg); } } } else { sprintf(errmsg, "writepolygondata: please create database schema '%s' with schema polygon1.2\n",dbfile_name); mexErrMsgTxt(errmsg); //there might be a fix, but for the moment this simply does NOT work if (dbcreate(dbfile_name,"polygon1.2",0, 0, 0) != 0 ) { mexErrMsgTxt("writepolygondata: problem with dbcreate\n"); } } nsamp= (long) nlat; lat= mxGetPr(prhs[1]); lon= mxGetPr(prhs[2]); polygon= mxCalloc(nsamp+1,sizeof(Point)); for (i= 0; i < nsamp; i++) { polygon[i].lat=lat[i]; polygon[i].lon=lon[i]; } get_malloced_string(prhs[3],&pname); get_malloced_string(prhs[4],&ptype); get_malloced_string(prhs[5],&auth); get_malloced_string(prhs[6],&dir); get_malloced_string(prhs[7],&dfile); get_malloced_string(prhs[8],&s_pcode); pcode= polycode(s_pcode); /*maybe nsamp -1, check later...*/ writePolygonData(db,polygon,nsamp,pname,1,1,ptype,auth,dir,dfile,pcode); antelope_mex_clear_register(1); mxFree(polygon); mxFree(s_pcode); mxFree(dfile); mxFree(dir); mxFree(auth); mxFree(ptype); mxFree(pname); }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Dbptr db; Tbl *tbl; char **sortfields; char errmsg[STRSZ]; int i, arg_index, nvarargs; int flags = 0; int rc; if( nrhs < 1 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if( ! get_dbptr( prhs[0], &db ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } nvarargs = nrhs - 1; for( i = 0; i<nvarargs; i++) { arg_index = i + 1; if( mxGetClassID( prhs[arg_index] ) != mxCHAR_CLASS ) { antelope_mexUsageMsgTxt ( USAGE ); return; } } if( nvarargs > 0 ) { tbl = newtbl( nvarargs ); sortfields = (char **) mxCalloc( nvarargs, sizeof( char * ) ); for( i = 0; i < nvarargs; i++ ) { arg_index = i + 1; get_malloced_string( prhs[arg_index], &sortfields[i] ); if( STREQ( sortfields[i], "dbSORT_UNIQUE" ) ) { flags |= dbSORT_UNIQUE; } else if( STREQ( sortfields[i], "dbSORT_REVERSE" ) ) { flags |= dbSORT_REVERSE; } else { pushtbl( tbl, sortfields[i] ); } } } else { rc = dbquery ( db, dbPRIMARY_KEY, &tbl ); antelope_mex_clear_register( 1 ); if( rc == dbINVALID ) { mexErrMsgTxt( "dbsort: query for primary keys failed" ); } } db = dbsort ( db, tbl, flags, 0) ; antelope_mex_clear_register( 1 ); if( nvarargs > 0 ) { for( i = 0; i < nvarargs; i++ ) { mxFree( sortfields[i] ); } mxFree( sortfields ); freetbl( tbl, 0 ); } if( db.table == dbINVALID ) { mexErrMsgTxt( "dbsort failed" ); } plhs[0] = CreateDbptrStructFromDbptr( db ); if( plhs[0] == NULL ) { sprintf( errmsg, "dbsort: failed to create database-pointer " ); strcat( errmsg, "structure for result" ); mexErrMsgTxt( errmsg ); } }