Exemple #1
0
char* CRingBuffer::PutPack(const char* pData, const DWORD dwDataSize)
{
	if ( pData == NULL )
		return NULL;

	DWORD dwRemainEmptySize = 0;
	if ( m_pLeft <= m_pRight )
		dwRemainEmptySize = m_dwBufferLen - (m_pRight - m_pLeft) - 1;
	else
		dwRemainEmptySize = m_pRight - m_pLeft - 1;

	if ( dwRemainEmptySize < dwDataSize + PACK_HEADER_SIZE )
	{
		printf("The RingBuffer is overflow!\n");
		return NULL;
	}

	char *pLeft = m_pLeft, *pRight = m_pRight;

	// 写入数据长度
	pRight = PutData(pLeft, pRight, (const char*)&dwDataSize, PACK_HEADER_SIZE);

	if ( pRight == NULL ) 
		return NULL;

	// 写入原始数据
	pRight = PutData(pLeft, pRight, pData, dwDataSize);

	if (pRight == NULL)
		return NULL;

	m_pRight = pRight;

	return m_pRight;
}
Exemple #2
0
void cParser::Parse(unsigned char *data, int datasize, bool pusi)
{
  // get available data
  int length = 0;
  uint8_t* buffer = Get(length);

  // do we have a sync ?
  int framesize = 0;
  if(length > m_headersize && buffer != NULL && CheckAlignmentHeader(buffer, framesize))
  {
    if(framesize > 0 && length >= framesize)
    {
      ParsePayload(buffer, framesize);
      SendPayload(buffer, framesize);

      m_curPTS = PtsAdd(m_curPTS, m_duration);
      m_curDTS = PtsAdd(m_curDTS, m_duration);

      Del(framesize);
    }

    PutData(data, datasize, pusi);
    return;
  }

  // try to find sync
  int offset = FindAlignmentOffset(buffer, length, 0, framesize);
  if(offset != -1)
  {
    INFOLOG("sync found at offset %i (streamtype: %s / %i bytes in buffer / framesize: %i bytes)", offset, m_demuxer->TypeName(), Available(), framesize);
    Del(offset);
  }

  PutData(data, datasize, pusi);
}
Exemple #3
0
// CLIENT
bool CGuildMarkImage::SaveBlockFromCompressedData(DWORD posBlock, const BYTE * pbComp, DWORD dwCompSize)
{
	if (posBlock >= BLOCK_TOTAL_COUNT)
		return false;

	Pixel apxBuf[SGuildMarkBlock::SIZE];
	lzo_uint sizeBuf = sizeof(apxBuf);

	if (LZO_E_OK != lzo1x_decompress_safe(pbComp, dwCompSize, (BYTE *) apxBuf, &sizeBuf, CLZO::Instance().GetWorkMemory()))
	{
		sys_err("GuildMarkImage::CopyBlockFromCompressedData: cannot decompress, compressed size = %u", dwCompSize);
		return false;
	}

	if (sizeBuf != sizeof(apxBuf))
	{
		sys_err("GuildMarkImage::CopyBlockFromCompressedData: image corrupted, decompressed size = %u", sizeBuf);
		return false;
	}

	DWORD rowBlock = posBlock / BLOCK_COL_COUNT;
	DWORD colBlock = posBlock % BLOCK_COL_COUNT;

	PutData(colBlock * SGuildMarkBlock::WIDTH, rowBlock * SGuildMarkBlock::HEIGHT, SGuildMarkBlock::WIDTH, SGuildMarkBlock::HEIGHT, apxBuf);

	m_aakBlock[rowBlock][colBlock].CopyFrom(pbComp, dwCompSize, GetCRC32((const char *) apxBuf, sizeof(Pixel) * SGuildMarkBlock::SIZE));
	return true;
}
int mxW_KINSys(N_Vector y, N_Vector fy, void *user_data )
{
  kimInterfaceData kimData;
  mxArray *mx_in[3], *mx_out[3];
  int ret;
  
  /* Extract global interface data from user-data */
  kimData = (kimInterfaceData) user_data;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */
  mx_in[1] = kimData->SYSfct;                  /* matlab function handle */ 
  mx_in[2] = kimData->mtlb_data;               /* matlab user data */

  /* Call matlab wrapper */

  GetData(y, mxGetPr(mx_in[0]), N);

  mexCallMATLAB(3,mx_out,3,mx_in,"kim_sys");

  PutData(fy, mxGetPr(mx_out[0]), N);
  ret = (int)*mxGetPr(mx_out[1]);
  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], kimData);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);
}
/**
 * Maps the specified key (where the key is the name of the {@link
 * SmartDashboardNamedData}
 * to the specified value in this table.
 * The value can be retrieved by calling the get method with a key that is equal
 * to the original key.
 * @param value the value
 */
void SmartDashboard::PutData(NamedSendable *value) {
  if (value == nullptr) {
    wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
    return;
  }
  PutData(value->GetName(), value);
}
Exemple #6
0
BOOL	CommonData::CreateObjectByRawData(const char *lpbuf,S_UINT bufsize)
{
	if(lpbuf==NULL)
		return false;

	S_UINT len=0,tlen=sizeof(S_UINT);

	try{

		const char *pend=lpbuf+bufsize;
		const char *pt=lpbuf;

		memmove(&m_DataType,pt,sizeof(int));
		pt+=sizeof(int);
		if(pt>pend)
			return false;

		memmove(&m_DataLen,pt,tlen);
		pt+=tlen;
		if(pt>pend)
			return false;
		if(!PutData(pt,m_DataLen,m_DataType))
			return false;
		pt+=m_DataLen;
		if(pt>pend)
			return false;

	}catch(...)
	{
		return false;
	}


	return true;
}
int mtlb_IdaSensRes(int Nsens, realtype tres,
                    N_Vector yy, N_Vector yp, N_Vector rr,
                    N_Vector *yyS, N_Vector *ypS, N_Vector *rrS,
                    void *rdataS,
                    N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
{
    mxArray *mx_in[9], *mx_out[3];
    int is, ret;
    double *tmp_yyS, *tmp_ypS, *tmp_rrS;

    /* Inputs to the Matlab function */
    mx_in[0] = mxCreateScalarDouble(tres);          /* current t */
    mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL);    /* current yy */
    mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);    /* current yp */
    mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL);    /* current rr */
    mx_in[4] = mxCreateScalarDouble(Ns);            /* number of sensitivities */
    mx_in[5] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current yyS */
    mx_in[6] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current ypS */
    mx_in[7] = mx_SRESfct;                          /* matlab function handle */
    mx_in[8] = mx_data;                             /* matlab user data */

    /* Call matlab wrapper */
    GetData(yy, mxGetPr(mx_in[1]), N);
    GetData(yp, mxGetPr(mx_in[2]), N);
    GetData(rr, mxGetPr(mx_in[3]), N);
    tmp_yyS = mxGetPr(mx_in[5]);
    tmp_ypS = mxGetPr(mx_in[6]);
    for (is=0; is<Ns; is++) {
        GetData(yyS[is], &tmp_yyS[is*N], N);
        GetData(ypS[is], &tmp_ypS[is*N], N);
    }

    mexCallMATLAB(3,mx_out,9,mx_in,"idm_resS");

    tmp_rrS = mxGetPr(mx_out[0]);

    for(is=0; is<Ns; is++)
        PutData(rrS[is], &tmp_rrS[is*N], N);

    ret = (int)*mxGetPr(mx_out[1]);

    if (!mxIsEmpty(mx_out[2])) {
        UpdateUserData(mx_out[2]);
    }

    /* Free temporary space */

    mxDestroyArray(mx_in[0]);
    mxDestroyArray(mx_in[1]);
    mxDestroyArray(mx_in[2]);
    mxDestroyArray(mx_in[3]);
    mxDestroyArray(mx_in[4]);
    mxDestroyArray(mx_in[5]);
    mxDestroyArray(mx_in[6]);
    mxDestroyArray(mx_out[0]);
    mxDestroyArray(mx_out[1]);
    mxDestroyArray(mx_out[2]);

    return(ret);
}
int mtlb_IdaSpilsPsolB(realtype tt,
                       N_Vector yy, N_Vector yp,
                       N_Vector yyB, N_Vector ypB, N_Vector rrB,
                       N_Vector rvecB, N_Vector zvecB,
                       realtype c_jB, realtype deltaB,
                       void *prec_dataB, N_Vector tmpB)
{
    mxArray *mx_in[11], *mx_out[3];
    int ret;

    /* Inputs to the Matlab function */
    mx_in[0] = mxCreateScalarDouble(-1.0);        /* type=-1: backward ODE */
    mx_in[1] = mxCreateScalarDouble(tt);          /* current t */
    mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yy */
    mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yp */
    mx_in[4] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yyB */
    mx_in[5] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current ypB */
    mx_in[6] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current rrB */
    mx_in[7] = mxCreateDoubleMatrix(NB,1,mxREAL); /* right hand side rB */
    mx_in[8] = mxCreateScalarDouble(c_jB);        /* current c_jB */
    mx_in[9] = mx_PSOLfctB;                       /* matlab function handle */
    mx_in[10] = mx_data;                          /* matlab user data */

    /* Call matlab wrapper */
    GetData(yy, mxGetPr(mx_in[2]), N);
    GetData(yp, mxGetPr(mx_in[3]), N);
    GetData(yyB, mxGetPr(mx_in[4]), NB);
    GetData(ypB, mxGetPr(mx_in[5]), NB);
    GetData(rrB, mxGetPr(mx_in[6]), NB);
    GetData(rvecB, mxGetPr(mx_in[7]), NB);

    mexCallMATLAB(3,mx_out,11,mx_in,"idm_psol");

    PutData(zvecB, mxGetPr(mx_out[0]), NB);
    ret = (int)*mxGetPr(mx_out[1]);

    if (!mxIsEmpty(mx_out[2])) {
        UpdateUserData(mx_out[2]);
    }

    /* Free temporary space */
    mxDestroyArray(mx_in[0]);
    mxDestroyArray(mx_in[1]);
    mxDestroyArray(mx_in[2]);
    mxDestroyArray(mx_in[3]);
    mxDestroyArray(mx_in[4]);
    mxDestroyArray(mx_in[5]);
    mxDestroyArray(mx_in[6]);
    mxDestroyArray(mx_in[7]);
    mxDestroyArray(mx_in[8]);
    mxDestroyArray(mx_out[0]);
    mxDestroyArray(mx_out[1]);
    mxDestroyArray(mx_out[2]);

    return(ret);

}
/**
 * Maps the specified key (where the key is the name of the {@link SmartDashboardNamedData}
 * to the specified value in this table.
 * The value can be retrieved by calling the get method with a key that is equal to the original key.
 * @param value the value
 */
void SmartDashboard::PutData(SmartDashboardNamedData *value)
{
    if (value == NULL)
    {
        wpi_setWPIErrorWithContext(NullParameter, "value");
        return;
    }
    PutData(value->GetName().c_str(), value);
}
Exemple #10
0
/**
 * Maps the specified key (where the key is the name of the {@link SmartDashboardNamedData}
 * to the specified value in this table.
 * The value can be retrieved by calling the get method with a key that is equal to the original key.
 * @param value the value
 */
void SmartDashboard::PutData(NamedSendable *value)
{
	if (value == NULL)
	{
		//TODO wpi_setWPIErrorWithContext(NullParameter, "value");
		return;
	}
	PutData(value->GetName(), value);
}
int mxW_CVodeSensRhs(int Nsens, realtype t,
                     N_Vector y, N_Vector yd,
                     N_Vector *yS, N_Vector *ySd,
                     void *user_data,
                     N_Vector tmp1, N_Vector tmp2)
{
  cvmPbData fwdPb;
  mxArray *mx_in[7], *mx_out[3];
  int is, ret;
  double *tmp;

  /* Extract global interface data from user-data */
  fwdPb = (cvmPbData) user_data;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleScalar(t);             /* current t */
  mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL);    /* current y */
  mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);    /* current yd */
  mx_in[3] = mxCreateDoubleScalar(Ns);            /* number of sensitivities */
  mx_in[4] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current yS */
  mx_in[5] = fwdPb->SRHSfct;                      /* matlab function handle */      
  mx_in[6] = fwdPb->mtlb_data;                    /* matlab user data */
  
  /* Call matlab wrapper */
  GetData(y, mxGetPr(mx_in[1]), N);
  GetData(yd, mxGetPr(mx_in[2]), N);
  tmp = mxGetPr(mx_in[4]);
  for (is=0; is<Ns; is++)
    GetData(yS[is], &tmp[is*N], N);

  mexCallMATLAB(3,mx_out,7,mx_in,"cvm_rhsS");
  
  tmp = mxGetPr(mx_out[0]);

  for(is=0;is<Ns;is++)
    PutData(ySd[is], &tmp[is*N], N);

  ret = (int)*mxGetPr(mx_out[1]);

  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], fwdPb);
  }

  /* Free temporary space */

  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_in[3]);
  mxDestroyArray(mx_in[4]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);
}
Exemple #12
0
wxSoundStream& wxSoundFileStream::Write(const void *buffer, wxUint32 len)
{
  if (!m_prepared || m_state != wxSOUND_FILE_RECORDING) {
      m_snderror = wxSOUND_NOTSTARTED;
      m_lastcount = 0;
      return *this;
  }
  m_lastcount = PutData(buffer, len);
  return *this;
}
int mxW_CVodeQUADfctBS(realtype t, N_Vector y,  N_Vector *yS,
                       N_Vector yB, N_Vector yQBd, void *user_dataB)
{
  cvmPbData fwdPb, bckPb;
  mxArray *mx_in[8], *mx_out[3];
  int is, ret;
  double *tmp;

  /* Extract global interface data from user-data */
  bckPb = (cvmPbData) user_dataB;
  fwdPb = bckPb->fwd;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleScalar(1.0);           /* type=1: dependent on yS */
  mx_in[1] = mxCreateDoubleScalar(t);             /* current t */
  mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);    /* current y */
  mx_in[3] = mxCreateDoubleScalar(Ns);            /* number of sensitivities */
  mx_in[4] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current yS */
  mx_in[5] = mxCreateDoubleMatrix(NB,1,mxREAL);   /* current yB */
  mx_in[6] = bckPb->QUADfct;                      /* matlab function handle */ 
  mx_in[7] = bckPb->mtlb_data;                    /* matlab user data */

  /* Call matlab wrapper */

  GetData(y, mxGetPr(mx_in[2]), N);

  tmp = mxGetPr(mx_in[4]);
  for (is=0; is<Ns; is++)
    GetData(yS[is], &tmp[is*N], N);

  GetData(yB, mxGetPr(mx_in[5]), NB);

  mexCallMATLAB(3,mx_out,8,mx_in,"cvm_rhsQB");

  PutData(yQBd, mxGetPr(mx_out[0]), NqB);

  ret = (int)*mxGetPr(mx_out[1]);

  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], bckPb);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_in[3]);
  mxDestroyArray(mx_in[4]);
  mxDestroyArray(mx_in[5]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);
}
uint_8 
CmtSdCard::WriteBlock( const uint32 *src, uint32 block ) {
  block <<= mSdFactor; // sector <<= 9;
  //Отправить команду
  if( SendCommand( mMmc, MMC_CMD24, block, 0 ) ) {
    //Команда ушла, передать данные
    if( PutData( mMmc, src ) )
      return fnSdIsConnect();
    return CMTE_SD_WRITE_BLOCK_FAIL;
    }
  return CMTE_SD_WRITE_BLOCK_TIMEOUT;
  }
void PVMFBufferDataSink::HandlePortActivity(const PVMFPortActivity &aActivity)
{
    if (aActivity.iType != PVMF_PORT_ACTIVITY_INCOMING_MSG)
        return;
    PVMFSharedMediaMsgPtr aMsg;
    PVMFStatus aStatus;
    while (IncomingMsgQueueSize())
    {
        aStatus = DequeueIncomingMsg(aMsg);
        PutData(aMsg);
    }
}
Exemple #16
0
void TInstSheet::Paste(void)
{
	if (hWnd) {
		if ((resId == UNINSTALL_SHEET) == (cfg->mode == UNINSTALL_MODE))
			return;
		GetData();
		Destroy();
	}
	resId = cfg->mode == UNINSTALL_MODE ? UNINSTALL_SHEET : INSTALL_SHEET;

	Create();
	PutData();
}
int mxW_CVodeSpilsPsolB(realtype t, N_Vector y,
                         N_Vector yB, N_Vector fyB,
                         N_Vector rB, N_Vector zB,
                         realtype gammaB, realtype deltaB,
                         int lrB, void *user_dataB, N_Vector tmpB)
{
  cvmPbData fwdPb, bckPb;
  mxArray *mx_in[7], *mx_out[3];
  int ret;

  /* Extract global interface data from user-data */
  bckPb = (cvmPbData) user_dataB;
  fwdPb = bckPb->fwd;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleScalar(t);           /* current t */   
  mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current y */
  mx_in[2] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yB */
  mx_in[3] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current fyB */
  mx_in[4] = mxCreateDoubleMatrix(NB,1,mxREAL); /* right hand side rB */
  mx_in[5] = bckPb->PSOLfct;                    /* matlab function handle */
  mx_in[6] = bckPb->mtlb_data;                  /* matlab user data */
  
  /* Call matlab wrapper */
  GetData(y, mxGetPr(mx_in[1]), N);
  GetData(yB, mxGetPr(mx_in[2]), NB);
  GetData(fyB, mxGetPr(mx_in[3]), NB);
  GetData(rB, mxGetPr(mx_in[4]), NB);

  mexCallMATLAB(3,mx_out,7,mx_in,"cvm_psolB");

  PutData(zB, mxGetPr(mx_out[0]), NB);
  ret = (int)*mxGetPr(mx_out[1]);

  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], bckPb);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_in[3]);
  mxDestroyArray(mx_in[4]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);

}
void cPvrReadThread::PesToTs(uint8_t *Data, uint32_t Length)
{
  uint8_t stream_id;
  bool write_PES_hdr = true;
  uint32_t i;
  const short *pid = &kVideoPid;
  uint8_t *counter = &video_counter;
  const short PayloadSize = TS_SIZE - 4;
  uint32_t Payload_Count  = Length / PayloadSize;
  uint32_t Payload_Rest   = Length % PayloadSize;
  stream_id = Data[3];

  if (packet_counter <= 0) { // time to send PAT and PMT
     // increase continuity counter
     pat_buffer[ 3] = (pat_buffer[ 3] & 0xF0) | (((pat_buffer[ 3] & 0x0F) + 1) & 0x0F);
     pmt_buffer[ 3] = (pmt_buffer[ 3] & 0xF0) | (((pmt_buffer[ 3] & 0x0F) + 1) & 0x0F);
     PutData(pat_buffer, TS_SIZE);
     PutData(pmt_buffer, TS_SIZE);
     packet_counter = SENDPATPMT_PACKETINTERVAL;
     }

  if (pes_scr_isvalid && (stream_id != 0xBD)) { // send PCR packet but not PCR of vbi data
     TS_HEADER(kPCRPid, 0, pcr_counter, TS_ADAPTATION_FIELD);
     ts_buffer[4] = 0xB7;
     ts_buffer[5] = 0x10;
     ts_buffer[6] = (pes_scr & 0x01FE000000ull) >> 25; // 33 bits SCR base
     ts_buffer[7] = (pes_scr & 0x01FE0000) >> 17;
     ts_buffer[8] = (pes_scr & 0x01FE00) >> 9;
     ts_buffer[9] = (pes_scr & 0x01FE) >> 1;
     ts_buffer[10] = (pes_scr & 0x01) << 7;
     ts_buffer[10] |= 0x7E; // 6 bits between SCR and SCR extension
     ts_buffer[10] |= (pes_scr_ext & 0x0100) >> 8; // 9 bits SCR extension
     ts_buffer[11] = (pes_scr_ext & 0xFF);
     memset(ts_buffer + 12, 0xFF, TS_SIZE - 12);
     PutData(ts_buffer, TS_SIZE);
     pcr_counter = (pcr_counter + 1) & 15;
     pes_scr_isvalid = false;
     }
Exemple #19
0
//---------------------------------------------------------------------------
// Put formatted string with comment (see *printf)
void
NaDataStream::PutF (const char* szComment, const char* szFormat, ...)
{
    if(NULL == szFormatBuf)
        throw(na_bad_value);

    va_list argptr;

    va_start(argptr, szFormat);
    vsprintf(szFormatBuf, szFormat, argptr);
    PutData(szFormatBuf, szComment);

    va_end(argptr);
}
int mxW_KINSpilsPsol(N_Vector y, N_Vector yscale, 
                     N_Vector fy, N_Vector fscale, 
                     N_Vector v, void *user_data,
                     N_Vector vtemp)
{
  kimInterfaceData kimData;
  mxArray *mx_in[7], *mx_out[3];
  int ret;

  /* Extract global interface data from user-data */
  kimData = (kimInterfaceData) user_data;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */
  mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yscale */
  mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current fy */
  mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL); /* current fscale */
  mx_in[4] = mxCreateDoubleMatrix(N,1,mxREAL); /* right hand side */
  mx_in[5] = kimData->PSOLfct;                 /* matlab function handle */
  mx_in[6] = kimData->mtlb_data;               /* matlab user data */
  
  /* Call matlab wrapper */

  GetData(y,      mxGetPr(mx_in[0]), N);
  GetData(yscale, mxGetPr(mx_in[1]), N);
  GetData(fy,     mxGetPr(mx_in[2]), N);
  GetData(fscale, mxGetPr(mx_in[3]), N);
  GetData(v,      mxGetPr(mx_in[4]), N);

  mexCallMATLAB(3,mx_out,7,mx_in,"kim_psol");

  PutData(v, mxGetPr(mx_out[0]), N);
  ret = (int)*mxGetPr(mx_out[1]);

  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], kimData);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_in[3]);
  mxDestroyArray(mx_in[4]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);
}
int mtlb_IdaSpilsJac(realtype tt,
                     N_Vector yy, N_Vector yp, N_Vector rr,
                     N_Vector v, N_Vector Jv,
                     realtype c_j, void *jac_data,
                     N_Vector tmp1, N_Vector tmp2)
{
    mxArray *mx_in[9], *mx_out[3];
    int ret;

    /* Inputs to the Matlab function */
    mx_in[0] = mxCreateScalarDouble(1.0);         /* type=1: forward ODE */
    mx_in[1] = mxCreateScalarDouble(tt);          /* current t */
    mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yy */
    mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yp */
    mx_in[4] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current rr */
    mx_in[5] = mxCreateDoubleMatrix(N,1,mxREAL);  /* vector v */
    mx_in[6] = mxCreateScalarDouble(c_j);         /* current c_j */
    mx_in[7] = mx_JACfct;                         /* matlab function handle */
    mx_in[8] = mx_data;                           /* matlab user data */

    /* Call matlab wrapper */
    GetData(yy, mxGetPr(mx_in[2]), N);
    GetData(yp, mxGetPr(mx_in[3]), N);
    GetData(rr, mxGetPr(mx_in[4]), N);
    GetData(v, mxGetPr(mx_in[5]), N);

    mexCallMATLAB(3,mx_out,9,mx_in,"idm_jtv");

    PutData(Jv, mxGetPr(mx_out[0]), N);
    ret = (int)*mxGetPr(mx_out[1]);

    if (!mxIsEmpty(mx_out[2])) {
        UpdateUserData(mx_out[2]);
    }

    /* Free temporary space */
    mxDestroyArray(mx_in[0]);
    mxDestroyArray(mx_in[1]);
    mxDestroyArray(mx_in[2]);
    mxDestroyArray(mx_in[3]);
    mxDestroyArray(mx_in[4]);
    mxDestroyArray(mx_in[5]);
    mxDestroyArray(mx_in[6]);
    mxDestroyArray(mx_out[0]);
    mxDestroyArray(mx_out[1]);
    mxDestroyArray(mx_out[2]);

    return(ret);
}
int mtlb_IdaQuadFctB(realtype tt,
                     N_Vector yy, N_Vector yp,
                     N_Vector yyB, N_Vector ypB,
                     N_Vector ypQB, void *rdataQB)
{
    mxArray *mx_in[8], *mx_out[3];
    int ret;

    /* Inputs to the Matlab function */
    mx_in[0] = mxCreateScalarDouble(-1.0);        /* type=-1: backward ODE */
    mx_in[1] = mxCreateScalarDouble(tt);          /* current t */
    mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yy */
    mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yp */
    mx_in[4] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yyB */
    mx_in[5] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current ypB */
    mx_in[6] = mx_QUADfctB;                       /* matlab function handle */
    mx_in[7] = mx_data;                           /* matlab user data */

    /* Call matlab wrapper */
    GetData(yy, mxGetPr(mx_in[2]), N);
    GetData(yp, mxGetPr(mx_in[3]), N);
    GetData(yyB, mxGetPr(mx_in[4]), NB);
    GetData(ypB, mxGetPr(mx_in[5]), NB);

    mexCallMATLAB(3,mx_out,8,mx_in,"idm_rhsQ");

    PutData(ypQB, mxGetPr(mx_out[0]), NqB);

    ret = (int)*mxGetPr(mx_out[1]);

    if (!mxIsEmpty(mx_out[2])) {
        UpdateUserData(mx_out[2]);
    }

    /* Free temporary space */
    mxDestroyArray(mx_in[0]);
    mxDestroyArray(mx_in[1]);
    mxDestroyArray(mx_in[2]);
    mxDestroyArray(mx_in[3]);
    mxDestroyArray(mx_in[4]);
    mxDestroyArray(mx_in[5]);
    mxDestroyArray(mx_out[0]);
    mxDestroyArray(mx_out[1]);
    mxDestroyArray(mx_out[2]);

    return(ret);
}
static void KIM_Solve(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    double *y0, *ys, *fs;
    N_Vector yscale, fscale;
    int buflen, status, strategy;
    char *bufval;

    if ( kim_Kdata == NULL) return ;
    /* Exract y0 and load initial guess in y */
    y0 = mxGetPr(prhs[0]);
    PutData(y, y0, N);

    /* Extract strategy */
    buflen = mxGetM(prhs[1]) * mxGetN(prhs[1]) + 1;
    bufval = mxCalloc(buflen, sizeof(char));
    status = mxGetString(prhs[1], bufval, buflen);
    if(!strcmp(bufval,"None")) strategy = KIN_NONE;
    if(!strcmp(bufval,"LineSearch")) strategy = KIN_LINESEARCH;

    /* Extract yscale */
    ys = mxGetPr(prhs[2]);
    yscale = N_VCloneEmpty(y);
    N_VSetArrayPointer(ys, yscale);

    /* Extract fscale */
    fs = mxGetPr(prhs[3]);
    fscale = N_VCloneEmpty(y);
    N_VSetArrayPointer(fs, fscale);

    /* call KINSol() */
    status = KINSol(kin_mem, y, strategy, yscale, fscale);

    /* KINSOL return flag */
    plhs[0] = mxCreateScalarDouble((double)status);

    /* Solution vector */
    plhs[1] = mxCreateDoubleMatrix(N,1,mxREAL);
    GetData(y, mxGetPr(plhs[1]), N);

    /* Free temporary N_Vectors */
    N_VDestroy(yscale);
    N_VDestroy(fscale);

    return;
}
Exemple #24
0
/*------------------------------------------------------------------------
----------------------------- crank some data ----------------------------
------------------------------------------------------------------------*/
static int ActivateECLUT(floDefPtr flo, peDefPtr ped, peTexPtr pet)
{
  xieFloExportClientLUT *raw = (xieFloExportClientLUT *)ped->elemRaw;
  receptorPtr	rcp = pet->receptor;
  CARD32	bands = rcp->inFlo->bands;
  bandPtr	dbnd, sbnd = &rcp->band[0];
  CARD32	*start  = &(raw->start0);
  CARD32	*length = &(raw->length0);
  CARD8	 	*src, *dst;
  CARD32	b, pitch, nentry, dlen;
  Bool		swizzle;

  swizzle = (bands == 3) && (raw->bandOrder != xieValLSFirst);
  
  for(b = 0; b < bands; ++sbnd, ++b) {
    
    if (!(src = (CARD8*)GetCurrentSrc(flo,pet,sbnd))) continue; 

    dbnd = &pet->emitter[swizzle ? xieValMaxBands - b - 1 : b];
    
    nentry = length[b] ? length[b] : sbnd->format->height;
    pitch = LutPitch(sbnd->format->levels);
    dlen = nentry * pitch;
    
    if (!(dst = (CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,dlen,KEEP)))
      return FALSE;

    if (start[b])
      src += start[b] * pitch;       /* Adjust via start[b] && length[b] */

    memcpy(dst,src,dlen);

    SetBandFinal(dbnd);
    PutData(flo,pet,dbnd,dbnd->maxGlobal);
    
    FreeData(flo,pet,sbnd,sbnd->maxLocal);

    switch(raw->notify) {
    case xieValFirstData:	/* fall thru */
    case xieValNewData:		SendExportAvailableEvent(flo,ped,b,nentry,0,0);
    default:			break;
    }
  }
  return(TRUE);
}                               /* end ActivateECLUT */
int mxW_CVodeSpilsJac(N_Vector v, N_Vector Jv, realtype t,
                      N_Vector y, N_Vector fy,
                      void *user_data, N_Vector tmp)
{
  cvmPbData fwdPb;
  mxArray *mx_in[6], *mx_out[3];
  int ret;

  /* Extract global interface data from user-data */
  fwdPb = (cvmPbData) user_data;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleScalar(t);           /* current t */ 
  mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current y */
  mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current fy */
  mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL);  /* vector v */
  mx_in[4] = fwdPb->JACfct;                     /* matlab function handle */
  mx_in[5] = fwdPb->mtlb_data;                  /* matlab user data */
  
  /* Call matlab wrapper */
  GetData(y, mxGetPr(mx_in[1]), N);
  GetData(fy, mxGetPr(mx_in[2]), N);
  GetData(v, mxGetPr(mx_in[3]), N);

  mexCallMATLAB(3,mx_out,6,mx_in,"cvm_jtv");

  PutData(Jv, mxGetPr(mx_out[0]), N);
  ret = (int)*mxGetPr(mx_out[1]);

  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], fwdPb);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_in[3]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);
}
int mxW_KINSpilsJac(N_Vector v, N_Vector Jv,
                     N_Vector y, booleantype *new_y, 
                     void *user_data)
{
  kimInterfaceData kimData;
  mxArray *mx_in[5], *mx_out[4];
  int ret;

  /* Extract global interface data from user-data */
  kimData = (kimInterfaceData) user_data;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current y */
  mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL);  /* vector v */
  mx_in[2] = mxCreateLogicalScalar(*new_y);     /* */
  mx_in[3] = kimData->JACfct;                   /* matlab function handle */
  mx_in[4] = kimData->mtlb_data;                /* matlab user data */
 
  /* Call matlab wrapper */

  GetData(y, mxGetPr(mx_in[0]), N);
  GetData(v, mxGetPr(mx_in[1]), N);

  mexCallMATLAB(4,mx_out,5,mx_in,"kim_jtv");

  PutData(Jv, mxGetPr(mx_out[0]), N);
  *new_y = mxIsLogicalScalarTrue(mx_out[1]);
  ret = (int)*mxGetPr(mx_out[2]);

  if (!mxIsEmpty(mx_out[3])) {
    UpdateUserData(mx_out[3], kimData);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);
  mxDestroyArray(mx_out[3]);

  return(ret);
}
int mxW_CVodeQUADfctB(realtype t, N_Vector y, N_Vector yB, N_Vector yQBd, void *user_dataB)
{
  cvmPbData fwdPb, bckPb;
  mxArray *mx_in[6], *mx_out[3];
  int ret;

  /* Extract global interface data from user-data */
  bckPb = (cvmPbData) user_dataB;
  fwdPb = bckPb->fwd;

  /* Inputs to the Matlab function */
  mx_in[0] = mxCreateDoubleScalar(0.0);         /* type=0: not dependent on yS */
  mx_in[1] = mxCreateDoubleScalar(t);           /* current t */
  mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current y */
  mx_in[3] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yB */
  mx_in[4] = bckPb->QUADfct;                    /* matlab function handle */ 
  mx_in[5] = bckPb->mtlb_data;                  /* matlab user data */

  /* Call matlab wrapper */
  GetData(y, mxGetPr(mx_in[2]), N);
  GetData(yB, mxGetPr(mx_in[3]), NB);

  mexCallMATLAB(3,mx_out,6,mx_in,"cvm_rhsQB");

  PutData(yQBd, mxGetPr(mx_out[0]), NqB);

  ret = (int)*mxGetPr(mx_out[1]);

  if (!mxIsEmpty(mx_out[2])) {
    UpdateUserData(mx_out[2], bckPb);
  }

  /* Free temporary space */
  mxDestroyArray(mx_in[0]);
  mxDestroyArray(mx_in[1]);
  mxDestroyArray(mx_in[2]);
  mxDestroyArray(mx_in[3]);
  mxDestroyArray(mx_out[0]);
  mxDestroyArray(mx_out[1]);
  mxDestroyArray(mx_out[2]);

  return(ret);
}
Exemple #28
0
static int NetDbgPrint(char *strData)
{
	/* 把数据放入环形缓冲区 */
	int i;
	
	for (i = 0; i < strlen(strData); i++)
	{
		if (0 != PutData(strData[i]))
			break;
	}
	
	/* 如果已经有客户端连接了, 就把数据通过网络发送给客户端 */
	/* 唤醒netprint的发送线程 */
	pthread_mutex_lock(&g_tNetDbgSendMutex);
	pthread_cond_signal(&g_tNetDbgSendConVar);
	pthread_mutex_unlock(&g_tNetDbgSendMutex);

	return i;
	
}
Exemple #29
0
void wxSoundFileStream::OnSoundEvent(int evt)
{
  wxUint32 len = m_codec.GetBestSize();
  char *buffer;

  buffer = new char[len];
  wxSoundStream::OnSoundEvent(evt);

  while (!m_sndio->QueueFilled()) {
    switch(evt) {
    case wxSOUND_INPUT:
      if (len > m_bytes_left)
        len = m_bytes_left;

      len = m_codec.Read(buffer, len).GetLastAccess();
      PutData(buffer, len);
      m_bytes_left -= len;
      if (m_bytes_left == 0) {
        Stop();
        delete[] buffer;
        return;
      }
      break;
    case wxSOUND_OUTPUT:
      if (len > m_bytes_left)
        len = m_bytes_left;

      len = GetData(buffer, len);
      m_bytes_left -= len;
      if (m_bytes_left == 0) {
        Stop();
        delete[] buffer;
        return;
      }
      m_codec.Write(buffer, len);
      break;
    }
  }
  delete[] buffer;
}
int mtlb_IdaBBDgloc(long int Nlocal, realtype tt,
                    N_Vector yy, N_Vector yp, N_Vector gval,
                    void *res_data)
{
    mxArray *mx_in[6], *mx_out[3];
    int ret;

    /* Inputs to the Matlab function */
    mx_in[0] = mxCreateScalarDouble(1.0);         /* type=1: forward ODE */
    mx_in[1] = mxCreateScalarDouble(tt);          /* current t */
    mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yy */
    mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL);  /* current yp */
    mx_in[4] = mx_GLOCfct;                        /* matlab function handle */
    mx_in[5] = mx_data;                           /* matlab user data */

    /* Call matlab wrapper */
    GetData(yy, mxGetPr(mx_in[2]), N);
    GetData(yp, mxGetPr(mx_in[3]), N);

    mexCallMATLAB(3,mx_out,6,mx_in,"idm_gloc");

    PutData(gval, mxGetPr(mx_out[0]), N);
    ret = (int)*mxGetPr(mx_out[1]);

    if (!mxIsEmpty(mx_out[2])) {
        UpdateUserData(mx_out[2]);
    }

    /* Free temporary space */
    mxDestroyArray(mx_in[0]);
    mxDestroyArray(mx_in[1]);
    mxDestroyArray(mx_in[2]);
    mxDestroyArray(mx_in[3]);
    mxDestroyArray(mx_out[0]);
    mxDestroyArray(mx_out[1]);
    mxDestroyArray(mx_out[2]);

    return(ret);
}