Пример #1
0
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;
}
Пример #2
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 );
}
Пример #3
0
void newFileHeader(K2EvtFile **inhdr, Pf *pf,char *sta ) {
	int numchan=12;
	K2EvtFile *hdr;
	hdr=*inhdr;
	memcpy(hdr->id,"KMI",3);			/* = 'KMI' to denote a Kinemetrics file 
					   (NOTE: Added extra charafcter to hold NULL) */
	hdr->instrumentCode='9';	/* = '9' for K2 */
	hdr->headerVersion =100;	/* header version * 100 */
	hdr->headerBytes=2040;	/* size of header */
	hdr->ro_misc.a2dBits=24;		/* A/D bits per sample */
	hdr->ro_misc.sampleBytes=3;	/* bytes per sample (= 3) */
	hdr->ro_misc.restartSource=0;	/* = 0 - unknown
						   = 1 - power switch
						   = 2 - user command
						   = 3 - software watchdog
						   = 4 - DSP failure
						   = 5 - battery failure
						   = 7 - memory error */
		//hdr->ro_misc. bytePad[3];		/* for expansion */
	hdr->ro_misc.installedChan;	/* number of data streams */
	hdr->ro_misc.maxChannels;	/* physical number of channels */
	hdr->ro_misc.sysBlkVersion;	/* sys block version * 100 */
	hdr->ro_misc.bootBlkVersion;	/* boot block version * 100 */
	hdr->ro_misc.appBlkVersion;	/* application block version * 100 */
	hdr->ro_misc.dspBlkVersion;	/* DSP version * 100 */
	hdr->ro_misc.batteryVoltage;	/* voltage * 10 - negative value indicates charging */
	hdr->ro_misc.crc=0xffff;		/* 16-bit CRC of entire file with this word
			   set to 0xffff
			   NOTE: Not used at present */
	hdr->ro_misc.flags=0;		/* bit 0 = 1 if DSP system error */
	hdr->ro_misc.temperature=240;		/* degrees C X 10 */
	//hdr->ro_misc.wordpad[3];		/* for expansion */
	//hdr->ro_misc.dwordpad[4];		/* for expansion */
	hdr->ro_timing.clockSource;	/* 0 = RTC from cold start
				   1 = keyboard
				   2 = Sync with external reference pulse
						   3 = internal GPS */
	//hdr->ro_timing.gpsStatus;	
		 				/* Bit 0 set = currently checking for presence
									   of GPS board
						   Bit 1 set = GPS board present
						   Bit 2 set = error communication with GPS
						   Bit 3 set = failed to lock within allotted
									   time (gpsMaxTurnOnTime)
						   Bit 4 set = not locked
						   Bit 5 set = GPS power is on */
	//hdr->ro_timing.gpsSOH;		/* same as Acutime SOH code */
	//hdr->ro_timing.bytepad[5];	/* for expansion */
	//hdr->ro_timing.gpsLockFailCount;
					/* no. of time GPS failed to lock within
						gpsMaxTurnOnTime */
	//hdr->ro_timing.gpsUpdateRTCCount;/* no. of time GPS actually updated the RTC */
	//hdr->ro_timing.acqDelay;		
					/* time in msec between actual A/D conversion
						and DSP output */
	//hdr->ro_timing.gpsLatitude;		/* latitude x 100 , degrees North */
	//hdr->ro_timing.gpsLongitude;		/* longitude x 100 , degrees East */
	//hdr->ro_timing.gpsAltitude;		/* altitude in meters */
	// hdr->ro_timing.dacCount;	/* dac counts */
	//hdr->ro_timing.wordpad;		/* for expansion */
	//hdr->ro_timing.gpsLastDrift[2];	
					/* in msec (e.g. 5 = RTC was 5 msec faster
						than GPS */
	//hdr->ro_timing.gpsLastTurnOnTime[2];/* time when GPS was last turned on */
	//hdr->ro_timing.gpsLastUpdateTime[2];/* time of last RTC update */
	//hdr->ro_timing.gpsLastLockTime[2];/* time of last GPS lock */
	//hdr->ro_timing.dwordpad[4];		/* for expansion */
	for (int channo=0;channo<numchan;channo++) {
		hdr->ro_channel[channo].maxPeak=0;
		hdr->ro_channel[channo].maxPeakOffset=0;
		hdr->ro_channel[channo].minPeak=0;
		hdr->ro_channel[channo].minPeakOffset=0;
		hdr->ro_channel[channo].mean=0;
		hdr->ro_channel[channo].aqOffset=0;
	} 
	hdr->ro_stream.startTime=0.0;		/* first sample time, includes PEM */
	hdr->ro_stream.triggerTime=0.0;
	hdr->ro_stream.duration=0;		/* in no. of frames NOTE: frames may have different sizes */
	hdr->ro_stream.errors=0;
	hdr->ro_stream.flags;		
				/* Bit 0 set = funtional test
				   Bit 1 set = sensor response test (SRT)
				   Bit 2 set = recorded data = trigger data */
	hdr->ro_stream.startTimeMsec=0;
	hdr->ro_stream.triggerTimeMsec=0;
	hdr->ro_stream.nscans=0;		/* no. of scans in the event */
	hdr->ro_stream.triggerBitMap=0;	/* indicates first channel to trigger */
	hdr->ro_stream.pad=0;		/* for expansion */
	hdr->rw_misc.serialNumber=123;
	//attention, fix later
	hdr->rw_misc.nchannels=3;	/* no. of channels used */
	memcpy(hdr->rw_misc.stnID,sta,K2EVT_STN_ID_LENGTH);
	//hdr->rw_misc.comment[K2EVT_COMMENT_LENGTH+1];
	hdr->rw_misc.elevation=0;		/* meters above sea level */
	hdr->rw_misc.latitude=0;			/* degrees north */
	hdr->rw_misc.longitude=0;		/* degrees east */
	//hdr->rw_misc.userCodes= {'\0','\0','\0','\0'};		/* 60 bytes to here */
	hdr->rw_misc.cutlerCode=0;	
				/* 0 = Cutler off
				   1 = 4800 baud
				   2 = 9600 baud
				   3 = 19200 baud
				   4 = 38400 baud
				   5 = 57600 baud */
	hdr->rw_misc.minBatteryVoltage=115;/* minimum alarm battery voltage x 10 */
	hdr->rw_misc.cutler_decimation=0;/* Cutler grabber decimation factor
				   0 = 1:1 (raw)
				   1 = 1:2
				   2 = 1:4
				   3 = 1:5
				   4 = 1:10
				   5 = 1:20 */
	hdr->rw_misc.cutler_irig_type=1;	/* 0 = B
				   1 = E (default)
				   2 = H */
	hdr->rw_misc.cutler_bitmap=0;	/* Digital field station bitmap (channels to output) */
	hdr->rw_misc.channel_bitmap=0;	/* channels selected for acq storage */
	hdr->rw_misc.cutler_protocol=0;	/* 0 = CRLF - USGS 1 = KMI/Agbabian */
	//hdr->rw_misc.siteID[17+1];
	copystrip(hdr->rw_misc.siteID,sta,17);
	hdr->rw_misc.externalTrigger=0;	/* 0 = off, 1 = on */
	hdr->rw_misc.networkFlag;	/* Bit 0 set = master Bit 0 unset = slave */
	hdr->rw_timing.gpsTurnOnInterval;/* minutes between GPS update checking */
	hdr->rw_timing.gpsMaxTurnOnTime;	/* max time in minutes GPS tries to
				   lock before giving up */
	hdr->rw_timing.bytepad[6];
	hdr->rw_timing.localOffset;		/* hours ahead of UTC */
	hdr->rw_timing.wordpad[3];
	for (int channo=0;channo< K2EVT_MAX_MW_CHANNELS;channo++) {
		hdr->rw_channel[channo].id[K2EVT_CHANNEL_ID_LENGTH+1];
		hdr->rw_channel[channo]. bytepad;			/* for expansion */
		hdr->rw_channel[channo]. sensorSerialNumberExt;/* high word of serial no. */
		hdr->rw_channel[channo].north;		/* displacement */
		hdr->rw_channel[channo].east;			/* displacement */
		hdr->rw_channel[channo].up;			/* displacement */
		hdr->rw_channel[channo].altitude;		/* displacement */
		hdr->rw_channel[channo].azimuth;		/* displacement */
		hdr->rw_channel[channo].sensorType=32; /*EpiSensor*/
		hdr->rw_channel[channo].sensorSerialNumber;/* low word of serial no. */
		hdr->rw_channel[channo].gain=1;		/* only 1 defined as gain */
		hdr->rw_channel[channo].triggerType=0;	
				/* 0 = threshold (default)
				   1 = STA/LTA */
		hdr->rw_channel[channo].iirTriggerFilter;	
				/* 0 = A
				   1 = B (default 0.1Hz to 12.5Hz @ 200sps)
						   2 = C */
		 hdr->rw_channel[channo].StaSeconds;	/* STA seconds x 10 (default = 1.0 seconds)  */
		 hdr->rw_channel[channo].LtaSeconds;	/* LTA seconds  (default = 60 seconds) */
		 hdr->rw_channel[channo].StaLtaRatio;	/* STA/LTA trigger ratio * 10 (default = 4) */
		 hdr->rw_channel[channo].StaLtaPercent;	
						/* STA/LTA detrigger percent of trigger ratio
						   0 = 10%
						   1 = 15%
						   2 = 20%
						   3 = 40% (default)
						   4 = 60%
						   5 = 100% */
		hdr->rw_channel[channo].bytepada;
		hdr->rw_channel[channo].fullscale=20;		/* volts */
		hdr->rw_channel[channo].sensitivity=20;		/* in volts per unit (e.g., g's) */
		hdr->rw_channel[channo].damping;			/* fraction of critical */
		hdr->rw_channel[channo].naturalFrequency;		/* hz */
		hdr->rw_channel[channo].triggerThreshold;		/* fraction of fullscale */
		hdr->rw_channel[channo].detriggerThreshold;	/* fraction of fullscale */
		hdr->rw_channel[channo].alarmTriggerThreshold;	/* fraction of fullscale */
		hdr->rw_channel[channo].bytepad2[16];
	} 
	hdr->rw_stream.filterFlag=0;	/* Bit 0 set = filtered data
			   Bit 1 set = auto FT after event
			   Bit 2 set = compressed */
	hdr->rw_stream.primaryStorage=0;	/* = 0 - drive A:, etc. */
	hdr->rw_stream.secondaryStorage=0;	/* = 1 - drive B:, etc. */
	//hdr->rw_stream.bytepad[3];	/* for expansion */
	hdr->rw_stream.CheckinTime=-1;	/* minutes since midnight, -1 = no checkin */
	hdr->rw_stream.eventNumber;	/* NOT USED */
	hdr->rw_stream.sps;		/* sampling rate */
	hdr->rw_stream.apw;		/* array propagation windoe in seconds */
	hdr->rw_stream.preEvent;	/* in seconds */
	hdr->rw_stream.postEvent;	/* in seconds */
	hdr->rw_stream.minRunTime;	/* in seconds */
	hdr->rw_stream.VotesToTrigger;
	hdr->rw_stream.VotesToDetrigger;
	hdr->rw_stream.bytepada;
	hdr->rw_stream.FilterType;	/* 0 = regular, 1 = causal */
	hdr->rw_stream.DataFmt;		/* for streaming data - 0 = uncompressed, 1 = compressed */
	hdr->rw_stream.Reserved;
	hdr->rw_stream.Timeout;		/* for streaming data - com mode */
	hdr->rw_stream.TxBlkSize;
	hdr->rw_stream.BufferSize;
	hdr->rw_stream.SampleRate;	/* for streaming data - must be 0 or 100 */
	hdr->rw_stream.TxChanMap;		/* for streaming data - channel bitmap */
	//hdr->rw_stream.dwordpad[2];		/* for expansion */
	for (int voter=0;voter< K2EVT_STREAM_MW_MAX_VOTERS;voter++) {
		hdr->rw_stream.voterInfo[voter].type;		/* voter typr code */
		hdr->rw_stream.voterInfo[voter].number;		/* channel number, stream number, etc. */
		hdr->rw_stream.voterInfo[voter].weight;		/* voting weight, range is -100 to 100 */
	} 
	hdr->rw_modem.initCmd[K2EVT_MODEM_INITCMD_LENGTH+1];/* initialization string */
	hdr->rw_modem.dialingPrefix[K2EVT_MODEM_DIALPREFIX_LENGTH+1];/* dialing prefix */
	hdr->rw_modem.dialingSuffix[K2EVT_MODEM_DIALSUFFIX_LENGTH+1];/* dialing suffix */
	hdr->rw_modem.hangupCmd[K2EVT_MODEM_HANGUPCMD_LENGTH+1];
	hdr->rw_modem.autoAnswerOnCmd[K2EVT_MODEM_AUTOANSWERON_LENGTH+1];
	hdr->rw_modem.autoAnswerOffCmd[K2EVT_MODEM_AUTOANSWEROFF_LENGTH+1];
	hdr->rw_modem.phoneNumber[K2EVT_MODEM_PHONES][K2EVT_MODEM_PHONENUMBER_LENGTH+1];
	hdr->rw_modem.waitForConnection;	/* seconds */
	hdr->rw_modem.pauseBetweenCalls;	/* seconds */
	hdr->rw_modem.maxDialAttempts;
	hdr->rw_modem.cellShare;	/* 0 = 1 Hz output 1 = cell phone */
	hdr->rw_modem.cellOnTime;			/* minutes */
	hdr->rw_modem.cellWarmupTime;		/* seconds */
	hdr->rw_modem.cellStartTime[5];		/* minutes since midnight */
	hdr->rw_modem.bytepad[4];
	hdr->rw_modem.flags;			
					/* Bit 0 set = enable auto call out
					   Bit 1 set = call out on batteru < 12 V
					   Bit 2 set = call out on battery charge failed
					   Bit 3 set = call out on extreme temperature
					   Bit 4 set = call out on event
					   Bit 5 set = call out on GPS lock failure */
	hdr->rw_modem.calloutMsg[46+1];
}