Exemplo n.º 1
0
mxArray *sf_c2_MPC_framework_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] =
  {"checksum","inputs","parameters","outputs"};
  mxArray *mxAutoinheritanceInfo =
  mxCreateStructMatrix(1,1,4,autoinheritanceFields);
  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(4146277402U);
    pr[1] = (double)(3031080980U);
    pr[2] = (double)(1162626880U);
    pr[3] = (double)(4240345295U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,6,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }
    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }
    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }
    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }
  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,mxREAL));
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }
  return(mxAutoinheritanceInfo);
}
PsychError PSYCHHIDReceiveReports(void)
{
	long error=0;
	int deviceIndex;
	mxArray **mxErrPtr;
	const mxArray *mxOptions,*mx;

    PsychPushHelp(useString,synopsisString,seeAlsoString);
    if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};
    PsychErrorExit(PsychCapNumOutputArgs(1));
    PsychErrorExit(PsychCapNumInputArgs(2));
	PsychCopyInIntegerArg(1,TRUE,&deviceIndex);

    if(deviceIndex < 0 || deviceIndex >= MAXDEVICEINDEXS) PrintfExit("Sorry. Can't cope with deviceNumber %d (more than %d). Please tell [email protected]",deviceIndex, (int) MAXDEVICEINDEXS-1);
    
	/*
	 "\"options.print\" =1 (default 0) enables diagnostic printing of a summary of each report when our callback routine receives it. "	
	 "\"options.printCrashers\" =1 (default 0) enables diagnostic printing of the creation of the callback source and its addition to the CFRunLoop. "
	 "\"options.maxReports\" (default 10000) allocate space for at least this many reports, shared among all devices. "
	 "\"options.maxReportSize\" (default 65) allocate this many bytes per report. "
	 */
	//optionsPrintReportSummary=0;	// options.print
	//optionsPrintCrashers=0;		// options.printCrashers
	//optionsMaxReports=10000;		// options.maxReports
	//optionsMaxReportSize=65;		// options.maxReportSize
	//optionsSecs=0.010;			// options.secs
    
	mxOptions=PsychGetInArgMxPtr(2);
	if(mxOptions!=NULL){
		mx=mxGetField(mxOptions,0,"print");
		if(mx!=NULL)optionsPrintReportSummary=(psych_bool)mxGetScalar(mx);
		mx=mxGetField(mxOptions,0,"printCrashers");
		if(mx!=NULL)optionsPrintCrashers=(psych_bool)mxGetScalar(mx);
		mx=mxGetField(mxOptions,0,"secs");
		if(mx!=NULL)optionsSecs=mxGetScalar(mx);
		mx=mxGetField(mxOptions,0,"consistencyChecks");
		if(mx!=NULL)optionsConsistencyChecks=(psych_bool)mxGetScalar(mx);

        // Changing maxReports or maxReportSize triggers a reallocation of
        // buffer memory:
		mx=mxGetField(mxOptions,0,"maxReports");
		if(mx!=NULL) {
            oneShotRealloc = TRUE;
            optionsMaxReports = (int) mxGetScalar(mx);
        }

		mx=mxGetField(mxOptions,0,"maxReportSize");
		if(mx!=NULL) {
            oneShotRealloc = TRUE;
            optionsMaxReportSize = (int) mxGetScalar(mx);
        }
	}

    // Sanity check:
	if(optionsMaxReports < 1) PsychErrorExitMsg(PsychError_user, "PsychHID ReceiveReports: Sorry, requested maxReports count must be at least 1!");
	if(optionsMaxReportSize < 1) PsychErrorExitMsg(PsychError_user, "PsychHID ReceiveReports: Sorry, requested maxReportSize must be at least 1 byte!");
	if(optionsMaxReportSize > MAXREPORTSIZE) {
        printf("PsychHID ReceiveReports: Sorry, requested maximum report size %d bytes exceeds built-in maximum of %d bytes.\n", optionsMaxReportSize, (int) MAXREPORTSIZE);
        PsychErrorExitMsg(PsychError_user, "Invalid option.maxReportSize provided!");
    }
    
    // Start reception of reports: This will also allocate memory for the reports
    // on first invocation for this deviceIndex:
	error = ReceiveReports(deviceIndex);

	mxErrPtr=PsychGetOutArgMxPtr(1);
	if(mxErrPtr!=NULL){
		const char *fieldNames[]={"n", "name", "description"};
		char *name="",*description="";
		mxArray *fieldValue;

		PsychHIDErrors(NULL, error,&name,&description); // Get error name and description, if available.
		*mxErrPtr=mxCreateStructMatrix(1,1,3,fieldNames);
		fieldValue=mxCreateString(name);
		if(fieldValue==NULL)PrintfExit("PSYCHHIDReceiveReports: Couldn't allocate \"err\".");
		mxSetField(*mxErrPtr,0,"name",fieldValue);
		fieldValue=mxCreateString(description);
		if(fieldValue==NULL)PrintfExit("PSYCHHIDReceiveReports: Couldn't allocate \"err\".");
		mxSetField(*mxErrPtr,0,"description",fieldValue);
		fieldValue=mxCreateDoubleMatrix(1,1,mxREAL);
		if(fieldValue==NULL)PrintfExit("PSYCHHIDReceiveReports: Couldn't allocate \"err\".");
		*mxGetPr(fieldValue)=(double)error;
		mxSetField(*mxErrPtr,0,"n",fieldValue);
	}
    return(PsychError_none);	
}
Exemplo n.º 3
0
mxArray *sf_c2_linearproto_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("rHIjevK8p1xcPMFltA9WU");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 4
0
mxArray *sf_c4_StateObserver_2_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals", "postCodegenInfo" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1, 1, sizeof
    (autoinheritanceFields)/sizeof(autoinheritanceFields[0]),
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("2NG0oQpv2F02o0cXCR26xG");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(8);
      pr[1] = (double)(14);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(14);
      pr[1] = (double)(8);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  {
    mxArray* mxPostCodegenInfo = sf_c4_StateObserver_2_get_post_codegen_info();
    mxSetField(mxAutoinheritanceInfo,0,"postCodegenInfo",mxPostCodegenInfo);
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 5
0
mxArray *
GetMetaData (int m, int imax, mxArray* meta_cols,long vid, long id)
{
  stringstream numsql;
  stringstream strsql;
  vector < Pair * >pairs;;

  // mexPrintf (">>GetMetaData: %d %x %d/%d \n", m,meta_cols,vid,id);	

  /* Estrai le stringhe */
  numsql << "SELECT N.Name, s.value FROM meta M, metaname N, metastr s WHERE N.MID = M.MID AND M.VID =";
  numsql << vid << " AND M.ID =" << id << " AND s.XID = M.XID";
  mysqlpp::Query query = conn.query (numsql.str());

  if (mysqlpp::UseQueryResult res = query.use()) {
    while (mysqlpp::Row row = res.fetch_row()) {
      if (conn.errnum ()) {
	mexPrintf ("Error received in fetching a row: %s\n", conn.error ());
	return NULL;
      }
      char *name = (char *) malloc (strlen (row[0]) * sizeof (char) + 1);
      char *stringValue =
	(char *) malloc (strlen (row[1]) * sizeof (char) + 1);
      strcpy (name, row[0]);
      strcpy (stringValue, row[1]);
      pairs.push_back (new Pair (name, stringValue));
    }
  } else {
    mexPrintf ("Failed to get item list: %s \n", query.error ());
    return NULL;
  }


  /* Estrai i numeri */
  strsql <<
    "SELECT N.Name, s.value FROM meta M, metaname N, metanum s WHERE N.MID = M.MID AND M.VID =";
  strsql << vid << " AND M.ID =" << id << " AND s.XID = M.XID";
  mysqlpp::Query strquery = conn.query (strsql.str ());
  if (mysqlpp::UseQueryResult res = strquery.use ()) {
    while (mysqlpp::Row row = res.fetch_row ()) {
      if (conn.errnum ()) {
	mexPrintf ("Error received in fetching a row: %s\n", conn.error ());
	return NULL;
      }
      char *name = (char *) malloc (strlen (row[0]) * sizeof (char) + 1);
      strcpy (name, row[0]);
      pairs.push_back (new Pair (name, atof (row[1])));
    }
  } else {
    mexPrintf ("Failed to get item list: %s \n", strquery.error ());
    return NULL;
  }


  int i = 0;

  /* If meta_cols is Empty create meta_cols contents fields */

  if (NULL==meta_cols) 
    {
      int number_of_fields = pairs.size ();
      unsigned int i;
      char **field_names = (char **) malloc (number_of_fields * sizeof (char *));

      // creo i nomi dei campi cosi' come li ho presi dal DB

      for (i = 0; i < pairs.size (); i++) {
	field_names[i] =
	  (char *) malloc (strlen (pairs[i]->getName ()) * sizeof (char));
	strcpy (field_names[i], pairs[i]->getName ());
      }
      const mwSize ndim = 2;
      const mwSize dims[2] = { 1, 1 };
      // creo la struttura dati per matlab  
      meta_cols = mxCreateStructArray (ndim, dims, number_of_fields,
				       (const char **) field_names);
      //mexPrintf (">>making meta_cols: %x %d \n",meta_cols,imax);

      for (i = 0; i < pairs.size (); i++) {
	mxArray *cell = mxCreateCellMatrix(1,imax);
	mxSetField (meta_cols, 0, field_names[i], cell);
	//mexPrintf (">>making cell: %d %x \n",i, cell);		
      }
    }


  /* */
  for (i = 0; i < pairs.size (); i++) {
    mxArray* cell = mxGetField(meta_cols, 0, pairs[i]->getName ());
    //mexPrintf (">>getting cell: %d %x \n", i,cell);
    if (NULL==cell) {
      // mexPrintf (">>cannot get cell for name %s in series %d \n", pairs[i]->getName(),m);
      continue;
    }
    if (pairs[i]->isChar ()) {
      //mexPrintf (">>putting value: %s\n", pairs[i]->getStringValue () );
      mxSetCell (cell, m, mxCreateString (pairs[i]->getStringValue ()));
    } else {
      //mexPrintf (">>putting value: %f\n", pairs[i]->getDoubleValue () );
      mxArray *field_value;
      field_value = mxCreateDoubleMatrix (1, 1, mxREAL);
      *mxGetPr (field_value) = pairs[i]->getDoubleValue ();
      mxSetCell (cell, m, field_value);
    }
    delete pairs[i];
  }
  return meta_cols;
}
Exemplo n.º 6
0
mxArray *sf_c4_MON_sl_after_replacement3_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals", "postCodegenInfo" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1, 1, sizeof
    (autoinheritanceFields)/sizeof(autoinheritanceFields[0]),
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("is2DE0mVJR8Beyt8nge1TB");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,4,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,0,mxREAL);
      double *pr = mxGetPr(mxSize);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,0,mxREAL);
      double *pr = mxGetPr(mxSize);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,0,mxREAL);
      double *pr = mxGetPr(mxSize);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,0,mxREAL);
      double *pr = mxGetPr(mxSize);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,0,mxREAL);
      double *pr = mxGetPr(mxSize);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxData);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,0,mxREAL);
      double *pr = mxGetPr(mxSize);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(1));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  {
    mxArray* mxPostCodegenInfo =
      sf_c4_MON_sl_after_replacement3_get_post_codegen_info();
    mxSetField(mxAutoinheritanceInfo,0,"postCodegenInfo",mxPostCodegenInfo);
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 7
0
mxArray *sf_c2_chooseTapB_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(2968906768U);
    pr[1] = (double)(484985574U);
    pr[2] = (double)(162178795U);
    pr[3] = (double)(2744820555U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 8
0
mxArray* buildGroupsArrayForTrial(DataLoggerStatus *dlStatus, unsigned trialIdx, bool clearBuffers)
{
    DataLoggerStatusByTrial* trialStatus = dlStatus->byTrial + trialIdx;

    // gtrie for current trial
    GroupTrie* gtrie = dlStatus->gtrie;

    int nFieldsGroup = 7;
    const char* fieldNames[] = {"name", "type", "configHash", "version", "signalNames", "signals", "time"};
    mxArray *mxGroups, *mxSignals;

    unsigned nGroups = getGroupCount(gtrie);
    unsigned nGroupsUsed = 0;

    // create the outer groups array
    mxGroups = mxCreateStructMatrix(nGroups, 1, nFieldsGroup, fieldNames);

    if(trialStatus->utilized) {
        // ensure trial actually used
        timestamp_t trialStartTime = trialStatus->timestampStart;

        GroupTrie* groupNode = getFirstGroupNode(gtrie);
        SignalDataBuffer* psdb;
        for(unsigned iGroup = 0; iGroup < nGroups; iGroup++) {
            if(groupNode == NULL) break;
            GroupInfo* pg = (GroupInfo*)groupNode->value;
            unsigned nSamples = pg->tsBuffers[trialIdx].nSamples;

            if(pg->tsBuffers[trialIdx].nSamples > 0) {
                unsigned iGroupInArray = nGroupsUsed;

                // build an mxArray containing meta data about this group
                setGroupMetaFields((const GroupInfo*)pg, mxGroups, iGroupInArray);

                if(pg->type == GROUP_TYPE_ANALOG) {
                    // build an mxArray containing timestamps for this group
                    // false = don't use group field name prefix
                    addGroupTimestampsField(mxGroups, (const GroupInfo*)pg, trialIdx,
                        trialStartTime, false, iGroupInArray, nSamples);
                }

                // add in the signal fields
                mxSignals = mxCreateStructMatrix(1,1,0,NULL);
                if(pg->type != GROUP_TYPE_EVENT) {
					for(unsigned iSignal = 0; iSignal < pg->nSignals; iSignal++) {
						psdb = pg->signals[iSignal];
						if(psdb == NULL) continue;
						// add the signal data to mxSignals which is groups(iGroup).signals
						addSignalDataField(mxSignals, psdb, trialIdx, false, nSamples);

						// clear the timeseries buffer as these samples are no longer needed
						if(clearBuffers)
							clearSampleBuffer(psdb->buffers + trialIdx);
					}

                } else { // event group
                    // add the events directly to mxSignals, i.e. groups(iGroup.signals),
                    // without a group prefix
                    // add the meta field group.signalNames as groups(iGroup).signalNames
                    addEventGroupFields(mxSignals, mxGroups, pg, trialIdx,
                        trialStartTime, false, iGroupInArray);
                    if(clearBuffers) {
                    	for(unsigned iSignal = 0; iSignal < pg->nSignals; iSignal++) {
                    		psdb = pg->signals[iSignal];
                    		clearSampleBuffer(psdb->buffers + trialIdx);
                    	}
                    }
                }

                // add signals to groups(i).signals
                mxSetField(mxGroups, iGroupInArray, "signals", mxSignals);

                // clear the group's timestamp buffer
                if(clearBuffers)
                    clearTimestampBuffer(pg->tsBuffers + trialIdx);

                nGroupsUsed++;
            }

            // advance to the next group
            groupNode = getNextGroupNode(groupNode);
        }
    }
    // shrink the groups array in case some groups were unused
    if(nGroupsUsed < nGroups)
        mxSetM(mxGroups, nGroupsUsed);

    // mark this trial as written if we flushed the data
    if(clearBuffers) {
        controlMarkTrialWritten(dlStatus, trialIdx);
        //logInfo("marked trial %d as written\n", trialIdx);
    }

    return mxGroups;
}
Exemplo n.º 9
0
mxArray *sf_c16_Final_Project_v3b_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("Kp1xowPSfXFBuSBkQEcUWE");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,6,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }

    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(9);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(2);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
static void KIM_Stats(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    const char *fnames_solver[]= {
        "nfe",
        "nni",
        "nbcf",
        "nbops",
        "fnorm",
        "step",
        "LSInfo",
    };
    const char *fnames_dense[]= {
        "name",
        "njeD",
        "nfeD"
    };
    const char *fnames_spils[]= {
        "name",
        "nli",
        "npe",
        "nps",
        "ncfl",
    };

    long int nfe, nni, nbcf, nbops;
    double fnorm, step;

    long int njeD, nfeD;
    long int nli, npe, nps, ncfl;

    int flag;
    mxArray *mx_ls;
    int nfields;

    if (kim_Kdata == NULL) return;

    flag = KINGetNumNonlinSolvIters(kin_mem, &nni);
    flag = KINGetNumFuncEvals(kin_mem, &nfe);
    flag = KINGetNumBetaCondFails(kin_mem, &nbcf);
    flag = KINGetNumBacktrackOps(kin_mem, &nbops);

    flag = KINGetFuncNorm(kin_mem, &fnorm);
    flag = KINGetStepLength(kin_mem, &step);

    nfields = sizeof(fnames_solver)/sizeof(*fnames_solver);
    plhs[0] = mxCreateStructMatrix(1, 1, nfields, fnames_solver);

    mxSetField(plhs[0], 0, "nfe",   mxCreateScalarDouble((double)nfe));
    mxSetField(plhs[0], 0, "nni",   mxCreateScalarDouble((double)nni));
    mxSetField(plhs[0], 0, "nbcf",  mxCreateScalarDouble((double)nbcf));
    mxSetField(plhs[0], 0, "nbops", mxCreateScalarDouble((double)nbops));
    mxSetField(plhs[0], 0, "fnorm", mxCreateScalarDouble(fnorm));
    mxSetField(plhs[0], 0, "step",  mxCreateScalarDouble(step));

    /* Linear Solver Statistics */

    switch(ls) {

    case LS_DENSE:

        flag = KINDenseGetNumJacEvals(kin_mem, &njeD);
        flag = KINDenseGetNumFuncEvals(kin_mem, &nfeD);

        nfields = sizeof(fnames_dense)/sizeof(*fnames_dense);
        mx_ls = mxCreateStructMatrix(1, 1, nfields, fnames_dense);

        mxSetField(mx_ls, 0, "name", mxCreateString("Dense"));
        mxSetField(mx_ls, 0, "njeD", mxCreateScalarDouble((double)njeD));
        mxSetField(mx_ls, 0, "nfeD", mxCreateScalarDouble((double)nfeD));

        break;

    case LS_SPGMR:
    case LS_SPBCG:
    case LS_SPTFQMR:

        flag = KINSpilsGetNumLinIters(kin_mem, &nli);
        flag = KINSpilsGetNumPrecEvals(kin_mem, &npe);
        flag = KINSpilsGetNumPrecSolves(kin_mem, &nps);
        flag = KINSpilsGetNumConvFails(kin_mem, &ncfl);

        nfields = sizeof(fnames_spils)/sizeof(*fnames_spils);
        mx_ls = mxCreateStructMatrix(1, 1, nfields, fnames_spils);

        if (ls == LS_SPGMR)
            mxSetField(mx_ls, 0, "name",  mxCreateString("GMRES"));
        else if (ls == LS_SPBCG)
            mxSetField(mx_ls, 0, "name",  mxCreateString("BiCGStab"));
        else
            mxSetField(mx_ls, 0, "name",  mxCreateString("TFQMR"));

        mxSetField(mx_ls, 0, "nli",   mxCreateScalarDouble((double)nli));
        mxSetField(mx_ls, 0, "npe",   mxCreateScalarDouble((double)npe));
        mxSetField(mx_ls, 0, "nps",   mxCreateScalarDouble((double)nps));
        mxSetField(mx_ls, 0, "ncfl",  mxCreateScalarDouble((double)ncfl));

        break;

    }

    mxSetField(plhs[0], 0, "LSInfo", mx_ls);

    return;
}
Exemplo n.º 11
0
// builds a trial struct in *pMxTrial and meta data struct in *pMxMeta
// if clearBuffers is true, each timestamp buffer, signal data buffer will be cleared
// and the trial will be marked as written
void buildStructForTrial(DataLoggerStatus* dlStatus, unsigned trialIdx, bool clearBuffers,
        mxArray ** pMxTrial, mxArray **pMxMeta) {
    DataLoggerStatusByTrial *trialStatus = dlStatus->byTrial + trialIdx;

    // iterate over the group trie
    GroupTrie* gtrie = dlStatus->gtrie;

    const char* metaFields[] = {"groups", "signals"};
    mxArray* mxTrial;
    mxArray* mxMeta;
    mxArray* mxGroupMeta;
    mxArray* mxSignalMeta;

    // outer trial struct
    mxTrial = mxCreateStructMatrix(1,1,0,NULL);

    // outer meta struct
    mxMeta = mxCreateStructMatrix(1, 1, 2, metaFields);
    // meta.groups struct
    mxGroupMeta = mxCreateStructMatrix(1,1,0,NULL);
    // meta.signals struct
    mxSignalMeta = mxCreateStructMatrix(1,1,0,NULL);

    // add fields like .protocol, subject, duration, etc.
    // to trial (not the meta struct, sorry for the name collision)
    addTrialMetaFields(mxTrial, dlStatus, trialIdx);

    // all timestamps written to the struct will be relative to this start time
    timestamp_t trialStartTime = trialStatus->timestampStart;

    GroupTrie* groupNode = getFirstGroupNode(gtrie);
    SignalDataBuffer* psdb;
    unsigned iSignal = 0, iGroup = 0;
    while(groupNode != NULL) {
        GroupInfo* pg = (GroupInfo*)groupNode->value;
        unsigned nSamples = pg->tsBuffers[trialIdx].nSamples;

        // build an mxArray containing meta data about this group
        addGroupMetaField(mxGroupMeta, (const GroupInfo*)pg);

        if(pg->type == GROUP_TYPE_ANALOG) {
            // build an mxArray containing timestamps for this group
            // true is for useGroupPrefix, which we should do always for the time field or else there
            // will be name collisions
            addGroupTimestampsField(mxTrial, (const GroupInfo*)pg, trialIdx, trialStartTime, true, 0, nSamples);
        }

        if(pg->type != GROUP_TYPE_EVENT) {
			for(unsigned i = 0; i < pg->nSignals; i++) {
				psdb = pg->signals[i];
				if(psdb == NULL) continue;

				// these have been accounted for by addGroupTimestampsField above
				if(psdb->type != SIGNAL_TYPE_TIMESTAMP && psdb->type != SIGNAL_TYPE_TIMESTAMPOFFSET) {
					// add to meta.signals.(name)
					 addSignalMetaField(mxSignalMeta, (const SignalDataBuffer*) psdb);

					// build an mxArray for this signal's data
					// don't use group prefix on the signal and hope there are no collisions
					// todo CHECK FOR COLLISIONS?
					addSignalDataField(mxTrial, psdb, trialIdx, false, nSamples);
				}

				// clear the timeseries buffer as these samples are no longer needed
				if(clearBuffers)
					clearSampleBuffer(psdb->buffers + trialIdx);

				iSignal++;
			}
        } else {
        	// event group type
        	// for event groups, the individual samples will be event names
			// so we write a new field with each event in it containing the timestamps encountered
			mxArray* mxThisGroupMeta = mxGetField(mxGroupMeta, 0, pg->name);
			addEventGroupFields(mxTrial, mxThisGroupMeta, pg, trialIdx,
				trialStartTime, false, 0);

			// clear the timeseries buffer as these samples are no longer needed
			if(clearBuffers) {
				for(unsigned i = 0; i < pg->nSignals; i++) {
					psdb = pg->signals[i];
					if(psdb == NULL) continue;
					clearSampleBuffer(psdb->buffers + trialIdx);
				}
			}
        }

        // clear the group's timestamp buffer
        if(clearBuffers)
            clearTimestampBuffer(pg->tsBuffers + trialIdx);

        // advance to the next group on the trie
        groupNode = getNextGroupNode(groupNode);

        iGroup++;
    }

    // set meta.groups = mxGroupMeta
    mxSetField(mxMeta, 0, "groups", mxGroupMeta);
    mxSetField(mxMeta, 0, "signals", mxSignalMeta);

    // mark that trial as no longer being actively written
    if(clearBuffers)
        controlMarkTrialWritten(dlStatus, trialIdx);

    // assign the output argument mxArrays
    if(pMxTrial != NULL)
        *pMxTrial = mxTrial;

    if(pMxMeta != NULL)
        *pMxMeta = mxMeta;
}
Exemplo n.º 12
0
mxArray *sf_c3_controller1_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(3719275678U);
    pr[1] = (double)(4192044686U);
    pr[2] = (double)(4111541287U);
    pr[3] = (double)(4053187991U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 13
0
mxArray *sf_c7_ekffede_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(869705337U);
    pr[1] = (double)(4037793131U);
    pr[2] = (double)(919190404U);
    pr[3] = (double)(3945250788U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,5,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 14
0
mxArray *Trader::GetOrder(int ind, string OrderRef)
{
    if(ind < v_tds.size() && v_tds[ind] != NULL)
    {
        CThostFtdcOrderField order;
        if (TD_GetOrder(v_tds[ind], OrderRef.c_str(), &order))
        {
            mxArray *result;
            const char *field_names[] = {"BrokerID", "InvestorID", "InstrumentID", "OrderRef", "UserID", "Direction",
            "CombOffsetFlag", "LimitPrice", "ExchangeID", "OrderSysID",
            "OrderStatus", "FrontID", "SessionID"};
            mwSize dims[2] = {1, 1};
            result = mxCreateStructArray(2, dims, sizeof(field_names)/sizeof(*field_names), field_names);
            string tmp;
            mxSetField(result, 0, "BrokerID", mxCreateString(order.BrokerID));
            mxSetField(result, 0, "InvestorID", mxCreateString(order.InvestorID));
            mxSetField(result, 0, "InstrumentID", mxCreateString(order.InstrumentID));
            mxSetField(result, 0, "OrderRef", mxCreateString(order.OrderRef));
            mxSetField(result, 0, "UserID", mxCreateString(order.UserID));
            tmp = string("") + order.Direction;
            mxSetField(result, 0, "Direction", mxCreateString(tmp.c_str()));
            mxSetField(result, 0, "CombOffsetFlag", mxCreateString(order.CombOffsetFlag));
            mxSetField(result, 0, "LimitPrice", mxCreateDoubleScalar(order.LimitPrice));
            mxSetField(result, 0, "ExchangeID", mxCreateString(order.ExchangeID));
            mxSetField(result, 0, "OrderSysID", mxCreateString(order.OrderSysID));
            tmp = string("") + order.OrderStatus;
            mxSetField(result, 0, "OrderStatus", mxCreateString(tmp.c_str()));
            mxSetField(result, 0, "FrontID", mxCreateDoubleScalar(order.FrontID));
            mxSetField(result, 0, "SessionID", mxCreateDoubleScalar(order.SessionID));
            return result;
        }
        PrintLog(string(__FUNCTION__) +  string("账户: ") + to_string(ind) + string(" 不存在订单: ") + OrderRef, "error");
        return mxCreateDoubleScalar(0);
    }
    PrintLog(string(__FUNCTION__) + string("不存在账户: ") + to_string(ind), "error");
    return mxCreateDoubleScalar(0);
    
    
}
Exemplo n.º 15
0
mxArray *sf_c17_ManipulatorME4901_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("GkC8n8AWs2U6BZMv5p3uMB");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(6);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(6);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(6);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 16
0
mxArray *sf_c24_CusakisME4901arcs2_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("9BGwLjtuiNHcaA759BfM6F");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(4);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 17
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
				 const mxArray *prhs[])
{
    mxArray *pDataArray;
	int i, nVariables = -1;
	int nFields;
    int T;
	mwSize dims[4];
    int streamID, vlistID, nVars;
    bool useGRIB;
	char buf[MEXCDI_STR_LEN];
	
    /* ==================================================================*/
    /* Call CDI_VARLIST */
    /* ==================================================================*/
    cdi_varlist(1, plhs, nrhs, prhs);

    streamID = OpenCDIStream(prhs[0]);
    useGRIB = streamInqFiletype(streamID) == FILETYPE_GRB;
	/* Get the variable list of the dataset */
	vlistID = streamInqVlist(streamID);
	/* get number of variables */
    nVariables = mxGetNumberOfElements(plhs[0]);

    /* ==================================================================*/
    /* ALLOCATING ALL MEMORY FOR FIELD
    /* ==================================================================*/
	getTimeSize(NULL, streamID, &T ); /* Notice: T is the same for all variables */
	for (i=0; i<nVariables; i++)
	{
        DEBUG_DISPLAY("allocating %d/%d\n", i+1, nVariables);
		/* get size of data to read */
		dims[0] = (mwSize)mxGetNumberOfElements(mxGetField(plhs[0], i, FIELD_LON)); 
		dims[1] = (mwSize)mxGetNumberOfElements(mxGetField(plhs[0], i, FIELD_LAT));
		dims[2] = (mwSize)mxGetNumberOfElements(mxGetField(plhs[0], i, FIELD_LEVELS));
		dims[3] = (mwSize)mxGetNumberOfElements(mxGetField(plhs[0], i, FIELD_DATES));
        /* allocate memory for MATLAB matrix*/
		allocateField(useGRIB, vlistID, (int)mxGetScalar(mxGetField(plhs[0], i, FIELD_VARID)), streamID, T, dims, &pDataArray); 
        DEBUG_DISPLAY("setting %d/%d\n", i+1, nVariables);
        mxSetField(plhs[0], (mwIndex)i, FIELD_DATA, pDataArray); 
	}

    /* ==================================================================*/
	/* CALL CDI_READFIELD FOR EACH VARIABLE */
    /* ==================================================================*/
	for (i=0; i<nVariables; i++)
	{
		/* Prepare data for CDI_READFIELD */
		mxArray *plhsTmp[1];
		const mxArray *prhsTmp[3];

		/* Filename, nametable */
		prhsTmp[0] = prhs[0];
        if (nrhs == 2)
    		prhsTmp[1] = prhs[1]; /* if nametable */
        else
            prhsTmp[1] = NULL;

		/* Varname: plhs[0] holds thee output from cdi_readmeta */
		prhsTmp[2] = mxGetField(plhs[0], i, FIELD_VARCODE);

		/* pass previously allocated data as left-hand-side argument to cdi_readfield*/
		plhsTmp[0] = mxGetField(plhs[0], i, FIELD_DATA);

		/* Call CDI_READFIELD */
		read1var(1, plhsTmp, 3, prhsTmp);
	}

    /* remove the fields used only internally */
    mxRemoveField(plhs[0], mxGetFieldNumber(plhs[0], FIELD_VARCODE));
    mxRemoveField(plhs[0], mxGetFieldNumber(plhs[0], FIELD_VARID));
    
	streamClose(streamID);
}
Exemplo n.º 18
0
void
mexFunction (int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]) {

  /* these variables are MPI-ANT specific for reading the data */
  char filename[256];
  int chan, sample, sb, se, length, chanc, samplec;
  float period;
  int status;
  FILE *fp;
  sraw_t *buf;
  eeg_t *hdr;

  /* these variables are Matlab specific for interfacing */
  double *ptr;
  const int dims[] = {1, 1};
  mxArray *label;
  mxArray *rate;
  mxArray *npnt;
  mxArray *nchan;
  mxArray *nsample;
  mxArray *time;
  mxArray *data;
  mxArray *triggers;

  const int nfields = 8;
  const char *field_names[] = {
    "label",                     /* label			*/
    "rate",                      /* 1/(period)			*/
    "npnt",                      /* nsample of this segment	*/
    "nchan",                     /* chanc			*/
    "nsample",                   /* nsample of the whole data	*/
    "time",                      /* 				*/
    "triggers",                  /* 				*/
    "data"
  };                     /* data			*/

  trg_t              * trigger_struct;
  const int            trigger_field_count = 4;
  const char         * trigger_field_names[] = { "time", "offset", "code", "type"};
  int                  trigger_array_index;
  int                  trigger_index;
  int                  trigger_count;
  char               * trigger_label;
  unsigned long long   trigger_offset;

  if (nrhs!=3)
    mexErrMsgTxt ("Invalid number of input arguments");

  mxGetString(prhs[0], filename, 256);
  sb = (int)(mxGetScalar(prhs[1]) + 0.5) - 1;
  se = (int)(mxGetScalar(prhs[2]) + 0.5) - 1;
  length = se-sb+1;

  /* open the data file */
  if ((fp = eepio_fopen(filename, "rb"))==NULL)
    mexErrMsgTxt ("Could not open file");

  /* read header information */
  hdr = eep_init_from_file(filename, fp, &status);
  if ((hdr == NULL) || (status!=CNTERR_NONE))
    mexErrMsgTxt ("Error reading header from file");

  chanc   = eep_get_chanc(hdr);
  period  = eep_get_period(hdr);
  samplec = eep_get_samplec(hdr);

  if (sb<0)
    mexErrMsgTxt ("Begin sample should be 1 or larger");

  if (se<sb)
    mexErrMsgTxt ("End sample should be similar to, or larger than the begin sample");

  if (chanc<1)
    mexErrMsgTxt ("Invalid number of channels in the data");

  if (se>samplec)
    mexErrMsgTxt ("End sample should be less than the number of samples in the data");

  /* rate      = mxCreateDoubleMatrix(1,1,mxREAL); *mxGetPr(rate     ) = (double)1/period; */
  rate      = mxCreateDoubleMatrix(1,1,mxREAL);
  *mxGetPr(rate     ) = (double)eep_get_rate(hdr);
  npnt      = mxCreateDoubleMatrix(1,1,mxREAL);
  *mxGetPr(npnt     ) = (double)length;
  nchan     = mxCreateDoubleMatrix(1,1,mxREAL);
  *mxGetPr(nchan    ) = (double)chanc;
  nsample   = mxCreateDoubleMatrix(1,1,mxREAL);
  *mxGetPr(nsample  ) = (double)samplec;
  data      = mxCreateDoubleMatrix(chanc,length,mxREAL);
  time      = mxCreateDoubleMatrix(1,length,mxREAL);
  label     = mxCreateCellMatrix(chanc,1);

  ptr = mxGetPr(time);
  for (sample=0; sample<length; sample++)
    ptr[sample] = (double)1000*(sb+sample)*period;

  for (chan=0; chan<chanc; chan++)
    mxSetCell(label,chan,mxCreateString(eep_get_chan_label(hdr, chan)));

  /* allocate memory for the data and read it from file */
  buf = (sraw_t *)malloc(CNTBUF_SIZE(hdr, chanc));
  ptr = mxGetPr(data);
  eep_seek(hdr, DATATYPE_EEG, sb, 0);
  for (sample=0; sample<length; sample++)
    if (eep_read_sraw(hdr, DATATYPE_EEG, buf, 1) != CNTERR_NONE)
      mexErrMsgTxt ("Error reading raw data from file");
    else
      for (chan=0; chan<chanc; chan++)
        ptr[sample*chanc+chan] = eep_get_chan_scale(hdr, chan) * buf[chan];

  /* create the struct array with dimensions 1x1 */
  plhs[0] = mxCreateStructArray(2, dims, nfields, field_names);

  /* trigger stuff */
  trigger_struct = eep_get_trg(hdr);
  if(trigger_struct != NULL) {
    // pass one, count triggers
    trigger_count = 0;
    for(trigger_index=0;trigger_index<trg_get_c(trigger_struct);trigger_index++) {
      trigger_label = trg_get(trigger_struct, trigger_index, & trigger_offset);
      if( (trigger_offset >= sb) && (trigger_offset < se) ) {
        trigger_count++;
      }
    }
    // pass two, fill triggers
    triggers  = mxCreateStructMatrix(1, trigger_count, trigger_field_count, trigger_field_names);
    trigger_array_index = 0;
    for(trigger_index=0;trigger_index<trg_get_c(trigger_struct);trigger_index++) {
      trigger_label = trg_get(trigger_struct, trigger_index, & trigger_offset);
      if(trigger_offset >= sb && trigger_offset < se) {
        mxArray * time;
        mxArray * offset;
        mxArray * code;
        mxArray * type;

        time = mxCreateDoubleMatrix(1,1,mxREAL);
        *mxGetPr(time) = (double) trigger_offset * period;

        offset = mxCreateDoubleMatrix(1,1,mxREAL);
        *mxGetPr(offset) = (double) trigger_offset;

        code = mxCreateString(trigger_label);

        type = mxCreateDoubleMatrix(1,1,mxREAL);
        *mxGetPr(type) = (double) atof(trigger_label);

        /* fill the struct array with the variables */
        mxSetField(triggers, trigger_array_index, "time", time );
        mxSetField(triggers, trigger_array_index, "offset", offset );
        mxSetField(triggers, trigger_array_index, "code", code );
        mxSetField(triggers, trigger_array_index, "type", type );
        trigger_array_index++;
      }
    }
  }

  /* fill the struct array with the variables */
  mxSetField(plhs[0], 0, "rate",      rate     );
  mxSetField(plhs[0], 0, "npnt",      npnt     );
  mxSetField(plhs[0], 0, "nchan",     nchan    );
  mxSetField(plhs[0], 0, "nsample",   nsample  );
  mxSetField(plhs[0], 0, "data",      data     );
  mxSetField(plhs[0], 0, "time",      time     );
  mxSetField(plhs[0], 0, "label",     label    );
  mxSetField(plhs[0], 0, "triggers",  triggers );

  /* close the file */
  eep_free(hdr);
  eepio_fclose(fp);
  free(buf);

  return;
}
mxArray *sf_c6_DemoGazeFollowWaveIdleRand_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("q7zoKb2PYssm0FsycxJhm");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 20
0
/*
======================================================================
mexFunction

This is the Matlab interface function for the MPEG to Matlab decoder.
This routine initializes variables, creates the output matrices and
calls the MPEG encoder functions to decode the MPEG file.

======================================================================
*/
void
mexFunction(int nlhs,
	    mxArray *plhs[],
	    int nrhs,
	    const mxArray *prhs[])
{
  char filename[256];             /* input MPEG file name */
  char err_text[80];              /* string to hold error message */
  static VidStream *theStream;    /* pointer to Video Stream struct. */
  int h,i,j,k;                    /* loop counters */
  double *cm;                     /* pointer to colormap matrix values */
  double *movie;                  /* pointer to movie matrix values */
  double *red;                    /* pointer to R,G,B matrix values */
  double *green;
  double *blue;
  int movie_rows;                 /* number of rows in movie matrix */
  int num_pix_doubles;            /* number of doubles used by each frame */
  int n_colors;                   /* number of colors in colormap */
  unsigned char r,g,b;            /* hold RGB values converted from YUV */
  unsigned char *m_ptr;           /* pointer to bytes in movie matrix */
  double *r_ptr;                  /* pointers to doubles in R,G,B matrices */
  double *g_ptr;
  double *b_ptr;
  unsigned int lum, crom;         /* indices into luminance and crominance */
  int vid_status;                 /* holds return from main decoder call */
  int last_frame;                 /* holds last frame requested by user */
  int n_req_frames;               /* number of requested frames */
  double *req_frames;             /* points to array of frame numbers */
  int frames_stored;              /* counts # of frames stored in matrix */
  int no_colormap;                /* whether or not to return colormap */
  int rgb_format;                 /* RGB if true, otherwise colormapped */
  int NewOutput = 0;              /* 0: Pre-5.3 movie format, 1: 5.3+ movie format */
  int NewTrueColorOutput = 0;     /* 0: Indexed movie, 1: TrueColor movie */
  unsigned int temp_int;          /* used as temp storage for flipping bytes*/
  mxArray *fid[2], *filestr[2];    /* matrices used in searching Matlab path */


  /* check arguments */
  no_colormap = 1;
  rgb_format = 0;
  if (nlhs == 2)
    no_colormap = 0;
  else if (nlhs == 3)
    rgb_format = 1;

  else if (nlhs > 3)
    mexErrMsgTxt("Too many output arguments.");
  else if (nlhs < 1)
    mexErrMsgTxt("Too few output arguments.");

  if (nrhs < 1)
    mexErrMsgTxt("Too few input arguments.");
  if (nrhs > 3)
    mexErrMsgTxt("Too many input arguments.");

  if (!mxIsChar(prhs[0]))
    mexErrMsgTxt("First argument (file name) must be a string.");

  mxGetString(prhs[0], filename, 256);

  /* get list of frame numbers if passed*/
  if ((nrhs >= 2) && (!mxIsEmpty(prhs[1])))
  {
    if (mxGetN(prhs[1]) > 1)
    {
      n_req_frames = mxGetN(prhs[1]);
      if (mxGetM(prhs[1]) > 1)
        mexErrMsgTxt("Second argument must be a vector");
    }
    else
    {
      n_req_frames = mxGetM(prhs[1]);
    }
    req_frames = mxGetPr(prhs[1]);

    /* find the highest number frame requested */
    last_frame = 1;
    for (j = 0; j < n_req_frames; j++)
    {
      if ((int)req_frames[j] > last_frame)
        last_frame = (int)req_frames[j];
    }
  }
  else
  {
    last_frame = 0;
    n_req_frames = 0;
  }

  if (nrhs == 3) {
    char str[100];
    mxGetString(prhs[2], str, 100);
    if (strcmp(str, "truecolor") == 0) {
      NewTrueColorOutput = 1;
    }
    NewOutput = 1;
  }

  /* open the MPEG file */
  /* call Matlab to search the Matlab path */
  filestr[0] = mxCreateString(filename);
  mexCallMATLAB(1,fid,1,filestr,"fopen");
  if (*(mxGetPr(fid[0])) == -1)
  {
    if (strchr(filename, '.') == NULL)
    {
      strcat(filename, ".mpg");
      mxDestroyArray(filestr[0]);
      mxDestroyArray(fid[0]);
      filestr[0] = mxCreateString(filename);
      mexCallMATLAB(1,fid,1,filestr,"fopen");
      if (*mxGetPr(fid[0]) == -1)
        mexErrMsgTxt("Could not open file.");
    }
    else
      mexErrMsgTxt("Could not open file.");
  }
  mxDestroyArray(filestr[0]);
  mexCallMATLAB(1,filestr,1,fid,"fopen");
  mxGetString(filestr[0], filename, 255);
  mxDestroyArray(filestr[0]);
  mexCallMATLAB(1,filestr,1,fid,"fclose");
  mxDestroyArray(fid[0]);
  mxDestroyArray(filestr[0]);
#ifdef WIN32
  input = fopen(filename, "rb");
#else
  input = fopen(filename, "r");
#endif
  if (input == NULL) {
    mexErrMsgTxt("Could not open file.");
  }

  /* initialization */
  ditherType = ORDERED2_DITHER;
  LUM_RANGE = 8;
  CR_RANGE = CB_RANGE = 4;
  noDisplayFlag = 0;

#ifdef SH_MEM
  shmemFlag = 1;
#endif

  init_tables();

  InitColor();
  InitOrdered2Dither();

  
  EOF_flag = 0;
  curBits = 0;
  bitOffset = 0;
  bufLength = 0;
  bitBuffer = NULL;
  totNumFrames = 0;
  
  start_decode = 1;
  curVidStream = NULL;
  theStream = NewVidStream(BUF_LENGTH);
  if (theStream == NULL)
    mexErrMsgTxt("Out of memory.");

  /* parse the MPEG header */
  mpegVidRsrc(0, theStream);

  /* create the movie and colormap Matrices */
  n_colors = LUM_RANGE*CB_RANGE*CR_RANGE;

  /*realTimeStart = ReadSysClock();*/

  if (n_req_frames == 0)
  {
    /* if user did not specify frames to get, one pass is needed to determine
     * the number of frames before actually putting them into the matrix */
    vid_status = 0;
    while (vid_status != 1)
    {
      vid_status = mpegVidRsrc(0, theStream);
    }
    n_req_frames = last_frame = totNumFrames;
    req_frames = (double *)mxCalloc(n_req_frames, sizeof(double));
    for (i = 0; i < n_req_frames; i++)
      req_frames[i] = i+1;
    DestroyVidStream(theStream);
    rewind(input);
    EOF_flag = 0;
    curBits = 0;
    bitOffset = 0;
    bufLength = 0;
    bitBuffer = NULL;
    totNumFrames = 0;
    theStream = NewVidStream(BUF_LENGTH);
    mpegVidRsrc(0, theStream);
  }

  /* create the output matrices */
  if (NewOutput) 
    {
      char *fieldnames[] = {"cdata", "colormap"};
      plhs[0] = mxCreateStructMatrix(1, n_req_frames, 2, (const char **)fieldnames);
      if (NewTrueColorOutput) 
	{
	  int i;
	  int dims[3];
	  dims[0] = theStream->v_size; dims[1] = theStream->h_size; dims[2] = 3;
	  for (i = 0; i < n_req_frames; i++) 
	    {
	      mxArray *cdata = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL);
	      mxSetField(plhs[0], i, "cdata", cdata);
	    }
	}
      else
	{
	  int i;
	  int dims[2];
	  dims[0] = theStream->v_size; dims[1] = theStream->h_size;
	  for (i = 0; i < n_req_frames; i++) 
	    {
	      mxArray *cdata = mxCreateNumericArray(2, dims, mxUINT8_CLASS, mxREAL);
	      mxArray *colormap = mxCreateDoubleMatrix(n_colors, 3, mxREAL);
	      mxSetField(plhs[0], i, "cdata", cdata);
	      mxSetField(plhs[0], i, "colormap", colormap);
	      
	      {
		/* Fill in the colormap */
		double *cm = mxGetPr(colormap);
		int j;
		for (j = 0; j < n_colors; j++)
		  {
		    /* fprintf(stderr, "Color: %d\n", j); */
		    ConvertColor(lum_values[(j/(CR_RANGE*CB_RANGE))%LUM_RANGE],
				 cr_values[(j/CB_RANGE)%CR_RANGE],
				 cb_values[j%CB_RANGE], 
				 &r, &g, &b);
		    cm[j] = (double)r/255;
		    cm[n_colors + j] = (double)g/255;
		    cm[n_colors * 2 + j] = (double)b/255;
		  }
	      }
	    }
	}
    }
  else
    {
      if (rgb_format)
	{
	  plhs[0] = mxCreateDoubleMatrix(theStream->v_size, theStream->h_size*n_req_frames,
					 mxREAL);
	  if (plhs[0] == NULL)
	    mexErrMsgTxt("Out of memory.");

	  plhs[1] = mxCreateDoubleMatrix(theStream->v_size, theStream->h_size*n_req_frames,
					 mxREAL);
	  if (plhs[1] == NULL)
	    mexErrMsgTxt("Out of memory.");

	  plhs[2] = mxCreateDoubleMatrix(theStream->v_size, theStream->h_size*n_req_frames,
					 mxREAL);
	  if (plhs[2] == NULL)
	    mexErrMsgTxt("Out of memory.");

	  red = mxGetPr(plhs[0]);
	  green = mxGetPr(plhs[1]);
	  blue = mxGetPr(plhs[2]);
	  movie_rows = mxGetM(plhs[0]);
	}
      else
	{
	  num_pix_doubles = (int)((theStream->h_size*theStream->v_size + 7)/8);
  
	  if (n_req_frames > 0)
	    plhs[0] = mxCreateDoubleMatrix(388 + num_pix_doubles, n_req_frames, mxREAL);

	  if (plhs[0] == NULL)
	    mexErrMsgTxt("Out of memory.");
	  movie = mxGetPr(plhs[0]);
	  movie_rows = mxGetM(plhs[0]);
	}

      if (!no_colormap)
	{
	  plhs[1] = mxCreateDoubleMatrix(n_colors, 3, mxREAL);
	  if (plhs[1] == NULL)
	    mexErrMsgTxt("Out of memory.");
	  cm = mxGetPr(plhs[1]);
	  /* create a Matlab colormap */
	  /* fprintf(stderr, "About to create colormap\n");*/
	  for (j = 0; j < n_colors; j++)
	    {
	      /* fprintf(stderr, "Color: %d\n", j); */
	      ConvertColor(lum_values[(j/(CR_RANGE*CB_RANGE))%LUM_RANGE],
			   cr_values[(j/CB_RANGE)%CR_RANGE],
			   cb_values[j%CB_RANGE], 
			   &r, &g, &b);
	      cm[j] = (double)r/255;
	      cm[n_colors + j] = (double)g/255;
	      cm[n_colors * 2 + j] = (double)b/255;
	    }
	}
    }
  /*fprintf(stderr, "movie rows: %d\n", movie_rows);*/

  /* get requested frames and store them in output martrix (matrices).*/
  frames_stored = 0;
  for (j = 1; j <= last_frame; j++)
  {
    /*fprintf(stderr, "Generating frame #%d\n", j);*/
    while (totNumFrames < j)
    {
      vid_status = mpegVidRsrc(0, theStream);
      if (vid_status == 1)
      {
        sprintf(err_text, "Frame(s) requested beyond last frame (%d).",
                totNumFrames);
	mexErrMsgTxt(err_text);
      }
    } 

    /* store this frame wherever it has been requested */   
    for (i = 0; i < n_req_frames; i++)
    {
      if ((int)req_frames[i] == j)
      {
        frames_stored++;
        
	if (NewOutput) 
	  {
	    mxArray *cdata = mxGetField(plhs[0], i, "cdata");
	    unsigned char *pr = (unsigned char *)mxGetPr(cdata);
	    if (NewTrueColorOutput) 
	      {
		unsigned char *pg = pr + theStream->v_size * theStream->h_size;
		unsigned char *pb = pg + theStream->v_size * theStream->h_size;

		lum = 0;
		crom = 0;
		for (h = 0; h < theStream->h_size; h++) 
		  {
		    lum = h;
		    crom = h/2;
		    for (k = 0; k < theStream->v_size; k++) 
		      {
			ConvertColor(*(curVidStream->current->luminance + lum),
				     *(curVidStream->current->Cr + crom),
				     *(curVidStream->current->Cb + crom),
				     &r, &g, &b);
			*pr = (unsigned char)r;
			*pg = (unsigned char)g;
			*pb = (unsigned char)b;
			pr++; pg++; pb++;

			lum += theStream->h_size;
			if ((k % 2) == 1)
			  {
			    crom += theStream->h_size / 2;
			  }
		      }
		  }
	      }
	    else
	      {
		int index = 0;
		for (h = 0; h < theStream->h_size; h++) 
		  {
		    for (k = 0; k < theStream->v_size; k++) 
		      {
			index = k * theStream->h_size + h;
			*pr = *(curVidStream->current->display + index);
			pr++;
		      }
		  }
	      }
	  }
	else
	  {
	    if (rgb_format)
	      {
		lum = 0;
		crom = 0;
		for (h = 0; h < theStream->v_size; h++)
		  {
		    r_ptr = red + theStream->v_size*theStream->h_size * i + h;
		    g_ptr = green + theStream->v_size*theStream->h_size * i + h;
		    b_ptr = blue + theStream->v_size*theStream->h_size * i + h;
		    for (k = 0; k < theStream->h_size; k++)
		      {
			ConvertColor(*(curVidStream->current->luminance + lum),
				     *(curVidStream->current->Cr + crom),
				     *(curVidStream->current->Cb + crom),
				     &r, &g, &b);
			*r_ptr = (double)r/255;
			*g_ptr = (double)g/255;
			*b_ptr = (double)b/255;
              
			r_ptr += theStream->v_size;
			g_ptr += theStream->v_size;
			b_ptr += theStream->v_size;

			lum++;
			if (k%2 == 0)
			  crom++;
		      }
		    if (h%2 == 0)
		      crom -= theStream->h_size / 2;
		  }
	      }
	    else
	      {
		/* create Matlab movie frame header */
		m_ptr = (unsigned char *)(movie + (movie_rows * i));
		*((double *)m_ptr) = curVidStream->h_size;
		m_ptr += sizeof(double);
		*((double *)m_ptr) = curVidStream->v_size;
		m_ptr += sizeof(double);
		*((double *)m_ptr) = 0;
		m_ptr += sizeof(double);
		if (MOVIE_GetClientByteOrder() == ELITTLE_ENDIAN)
		  {
		    *((int *)m_ptr) = 0;
		    m_ptr += sizeof(int);
		    *((int *)m_ptr) = LUM_RANGE*CB_RANGE*CR_RANGE;
		    m_ptr += sizeof(int);
		  }
		else
		  {
		    *((int *)m_ptr) = LUM_RANGE*CB_RANGE*CR_RANGE;
		    m_ptr += sizeof(int);
		    *((int *)m_ptr) = 0;
		    m_ptr += sizeof(int);
		  }
		m_ptr += 256*3*sizeof(float);

          /* copy frame data into movie matrix */
		memcpy(m_ptr, curVidStream->current->display, 
		       (theStream->h_size*theStream->v_size));
		if (MOVIE_GetClientByteOrder() == ELITTLE_ENDIAN)
		  {
		    for (k = 0; k < (movie_rows - 388); k++)
		      {
			temp_int = FLIPBYTES(*((unsigned int *)m_ptr));
			*((unsigned int *)m_ptr) = 
			  FLIPBYTES(*((unsigned int *)m_ptr + 1));
			*((unsigned int *)m_ptr + 1) = temp_int;
			m_ptr += sizeof(double);
		      }
		  }
	      }
	  }
      }
    }
  }


  /* destroy the video stream */
  DestroyVidStream(theStream);
  fclose(input);
}
mxArray
  *sf_c31_adcs_v15_integral_Power_no_charge_in_detumb_get_autoinheritance_info
  (void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(1182779610U);
    pr[1] = (double)(3336495085U);
    pr[2] = (double)(332585477U);
    pr[3] = (double)(187604071U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}
mxArray *sf_c19_ArregloSeisPorSeis_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("1KPkaEZ7HoPbK8UmULOSJ");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 23
0
mxArray * createInfoStruct(VlSvmPegasos* svm)
{
  mwSize dims[] = {1 , 1} ;

  const char* names [15] = {
    "dimension", "iterations", "maxIterations",
    "epsilon", "lambda", "biasMultiplier",
    "biasLearningRate", "energyFrequency", "elapsedTime",
    "energy", "regularizerTerm", "lossPos",
    "lossNeg", "hardLossPos", "hardLossNeg"} ;

  mxArray *output, *dimension, *iterations, *maxIterations, *epsilon, *lambda ;
  mxArray *biasMultiplier, *biasLearningRate, *energyFrequency, *elapsedTime ;

  output = mxCreateStructArray(1, dims, 15, names);

  dimension = mxCreateNumericMatrix(1, 1,mxUINT32_CLASS, mxREAL) ;
  setUintValue(dimension,svm->dimension) ;

  iterations = mxCreateNumericMatrix(1, 1,mxUINT32_CLASS, mxREAL) ;
  setUintValue(iterations,svm->iterations) ;

  maxIterations = mxCreateNumericMatrix(1, 1,mxUINT32_CLASS, mxREAL) ;
  setUintValue(maxIterations,svm->maxIterations) ;

  epsilon = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
  setDoubleValue(epsilon,svm->epsilon) ;

  lambda = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
  setDoubleValue(lambda,svm->lambda) ;

  biasMultiplier = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
  setDoubleValue(biasMultiplier,svm->biasMultiplier) ;

  biasLearningRate = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
  setDoubleValue(biasLearningRate,svm->biasLearningRate) ;

  energyFrequency = mxCreateNumericMatrix(1, 1,mxUINT32_CLASS, mxREAL) ;
  setUintValue(energyFrequency,svm->energyFrequency) ;

  elapsedTime = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
  setDoubleValue(elapsedTime,svm->elapsedTime) ;


  mxSetField(output, 0, "dimension", dimension) ;
  mxSetField(output, 0, "iterations", iterations) ;
  mxSetField(output, 0, "maxIterations", maxIterations) ;
  mxSetField(output, 0, "epsilon", epsilon) ;
  mxSetField(output, 0, "lambda", lambda) ;
  mxSetField(output, 0, "biasMultiplier", biasMultiplier) ;
  mxSetField(output, 0, "biasLearningRate", biasLearningRate) ;
  mxSetField(output, 0, "energyFrequency", energyFrequency) ;
  mxSetField(output, 0, "elapsedTime", elapsedTime) ;

  if (svm->objective) {
    mxArray *energy, *regularizerTerm, *lossPos, *lossNeg, *hardLossPos, *hardLossNeg ;
    energy = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
    setDoubleValue(energy,svm->objective->energy) ;

    regularizerTerm = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
    setDoubleValue(regularizerTerm,svm->objective->regularizer) ;

    lossPos = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
    setDoubleValue(lossPos,svm->objective->lossPos) ;

    lossNeg = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
    setDoubleValue(lossNeg,svm->objective->lossNeg) ;

    hardLossPos = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
    setDoubleValue(hardLossPos,svm->objective->hardLossPos) ;

    hardLossNeg = mxCreateNumericMatrix(1, 1,mxDOUBLE_CLASS, mxREAL) ;
    setDoubleValue(hardLossNeg,svm->objective->hardLossNeg) ;

    mxSetField(output, 0, "energy", energy) ;
    mxSetField(output, 0, "regularizerTerm", regularizerTerm) ;
    mxSetField(output, 0, "lossPos", lossPos) ;
    mxSetField(output, 0, "lossNeg", lossNeg) ;
    mxSetField(output, 0, "hardLossPos", hardLossPos) ;
    mxSetField(output, 0, "hardLossNeg", hardLossNeg) ;
  }

  return output ;
}
Exemplo n.º 24
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  int i, j;
  mxArray *xm, *cell, *xm_cell;
  double *src;
  double *dest;
  double *dest_cell;
  int valid_vars;
  int steps;
  int this_var_errors;
  int warned_diags;
  int prepare_for_c = 0;
  int extra_solves;
  const char *status_names[] = {"optval", "gap", "steps", "converged"};
  mwSize dims1x1of1[1] = {1};
  mwSize dims[1];
  const char *var_names[] = {"u_0", "u_1", "u_2", "u_3", "u_4", "u_5", "u_6", "u_7", "u_8", "u_9", "u_10", "x_1", "x_2", "x_3", "x_4", "x_5", "x_6", "x_7", "x_8", "x_9", "x_10", "x_11", "u", "x"};
  const int num_var_names = 24;
  /* Avoid compiler warnings of unused variables by using a dummy assignment. */
  warned_diags = j = 0;
  extra_solves = 0;
  set_defaults();
  /* Check we got the right number of arguments. */
  if (nrhs == 0)
    mexErrMsgTxt("Not enough arguments: You need to specify at least the parameters.\n");
  if (nrhs > 1) {
    /* Assume that the second argument is the settings. */
    if (mxGetField(prhs[1], 0, "eps") != NULL)
      settings.eps = *mxGetPr(mxGetField(prhs[1], 0, "eps"));
    if (mxGetField(prhs[1], 0, "max_iters") != NULL)
      settings.max_iters = *mxGetPr(mxGetField(prhs[1], 0, "max_iters"));
    if (mxGetField(prhs[1], 0, "refine_steps") != NULL)
      settings.refine_steps = *mxGetPr(mxGetField(prhs[1], 0, "refine_steps"));
    if (mxGetField(prhs[1], 0, "verbose") != NULL)
      settings.verbose = *mxGetPr(mxGetField(prhs[1], 0, "verbose"));
    if (mxGetField(prhs[1], 0, "better_start") != NULL)
      settings.better_start = *mxGetPr(mxGetField(prhs[1], 0, "better_start"));
    if (mxGetField(prhs[1], 0, "verbose_refinement") != NULL)
      settings.verbose_refinement = *mxGetPr(mxGetField(prhs[1], 0,
            "verbose_refinement"));
    if (mxGetField(prhs[1], 0, "debug") != NULL)
      settings.debug = *mxGetPr(mxGetField(prhs[1], 0, "debug"));
    if (mxGetField(prhs[1], 0, "kkt_reg") != NULL)
      settings.kkt_reg = *mxGetPr(mxGetField(prhs[1], 0, "kkt_reg"));
    if (mxGetField(prhs[1], 0, "s_init") != NULL)
      settings.s_init = *mxGetPr(mxGetField(prhs[1], 0, "s_init"));
    if (mxGetField(prhs[1], 0, "z_init") != NULL)
      settings.z_init = *mxGetPr(mxGetField(prhs[1], 0, "z_init"));
    if (mxGetField(prhs[1], 0, "resid_tol") != NULL)
      settings.resid_tol = *mxGetPr(mxGetField(prhs[1], 0, "resid_tol"));
    if (mxGetField(prhs[1], 0, "extra_solves") != NULL)
      extra_solves = *mxGetPr(mxGetField(prhs[1], 0, "extra_solves"));
    else
      extra_solves = 0;
    if (mxGetField(prhs[1], 0, "prepare_for_c") != NULL)
      prepare_for_c = *mxGetPr(mxGetField(prhs[1], 0, "prepare_for_c"));
  }
  valid_vars = 0;
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "A");
  if (xm == NULL) {
    printf("could not find params.A.\n");
  } else {
    if (!((mxGetM(xm) == 6) && (mxGetN(xm) == 6))) {
      printf("A must be size (6,6), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter A must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter A must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter A must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.A;
      src = mxGetPr(xm);
      for (i = 0; i < 36; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "B");
  if (xm == NULL) {
    printf("could not find params.B.\n");
  } else {
    if (!((mxGetM(xm) == 6) && (mxGetN(xm) == 2))) {
      printf("B must be size (6,2), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter B must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter B must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter B must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.B;
      src = mxGetPr(xm);
      for (i = 0; i < 12; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "Q");
  if (xm == NULL) {
    printf("could not find params.Q.\n");
  } else {
    if (!((mxGetM(xm) == 6) && (mxGetN(xm) == 6))) {
      printf("Q must be size (6,6), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter Q must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter Q must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter Q must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.Q;
      src = mxGetPr(xm);
      for (i = 0; i < 36; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "R");
  if (xm == NULL) {
    printf("could not find params.R.\n");
  } else {
    if (!((mxGetM(xm) == 2) && (mxGetN(xm) == 2))) {
      printf("R must be size (2,2), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter R must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter R must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter R must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.R;
      src = mxGetPr(xm);
      for (i = 0; i < 4; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "S");
  if (xm == NULL) {
    printf("could not find params.S.\n");
  } else {
    if (!((mxGetM(xm) == 1) && (mxGetN(xm) == 1))) {
      printf("S must be size (1,1), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter S must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter S must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter S must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.S;
      src = mxGetPr(xm);
      for (i = 0; i < 1; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "u_max");
  if (xm == NULL) {
    printf("could not find params.u_max.\n");
  } else {
    if (!((mxGetM(xm) == 2) && (mxGetN(xm) == 1))) {
      printf("u_max must be size (2,1), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter u_max must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter u_max must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter u_max must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.u_max;
      src = mxGetPr(xm);
      for (i = 0; i < 2; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "u_min");
  if (xm == NULL) {
    printf("could not find params.u_min.\n");
  } else {
    if (!((mxGetM(xm) == 2) && (mxGetN(xm) == 1))) {
      printf("u_min must be size (2,1), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter u_min must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter u_min must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter u_min must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.u_min;
      src = mxGetPr(xm);
      for (i = 0; i < 2; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  this_var_errors = 0;
  xm = mxGetField(prhs[0], 0, "x_0");
  if (xm == NULL) {
    printf("could not find params.x_0.\n");
  } else {
    if (!((mxGetM(xm) == 6) && (mxGetN(xm) == 1))) {
      printf("x_0 must be size (6,1), not (%d,%d).\n", mxGetM(xm), mxGetN(xm));
      this_var_errors++;
    }
    if (mxIsComplex(xm)) {
      printf("parameter x_0 must be real.\n");
      this_var_errors++;
    }
    if (!mxIsClass(xm, "double")) {
      printf("parameter x_0 must be a full matrix of doubles.\n");
      this_var_errors++;
    }
    if (mxIsSparse(xm)) {
      printf("parameter x_0 must be a full matrix.\n");
      this_var_errors++;
    }
    if (this_var_errors == 0) {
      dest = params.x_0;
      src = mxGetPr(xm);
      for (i = 0; i < 6; i++)
        *dest++ = *src++;
      valid_vars++;
    }
  }
  if (valid_vars != 8) {
    printf("Error: %d parameters are invalid.\n", 8 - valid_vars);
    mexErrMsgTxt("invalid parameters found.");
  }
  if (prepare_for_c) {
    printf("settings.prepare_for_c == 1. thus, outputting for C.\n");
    for (i = 0; i < 6; i++)
      printf("  params.x_0[%d] = %.6g;\n", i, params.x_0[i]);
    for (i = 0; i < 36; i++)
      printf("  params.Q[%d] = %.6g;\n", i, params.Q[i]);
    for (i = 0; i < 4; i++)
      printf("  params.R[%d] = %.6g;\n", i, params.R[i]);
    for (i = 0; i < 36; i++)
      printf("  params.A[%d] = %.6g;\n", i, params.A[i]);
    for (i = 0; i < 12; i++)
      printf("  params.B[%d] = %.6g;\n", i, params.B[i]);
    for (i = 0; i < 2; i++)
      printf("  params.u_max[%d] = %.6g;\n", i, params.u_max[i]);
    for (i = 0; i < 2; i++)
      printf("  params.u_min[%d] = %.6g;\n", i, params.u_min[i]);
    for (i = 0; i < 1; i++)
      printf("  params.S[%d] = %.6g;\n", i, params.S[i]);
  }
  /* Perform the actual solve in here. */
  steps = solve();
  /* For profiling purposes, allow extra silent solves if desired. */
  settings.verbose = 0;
  for (i = 0; i < extra_solves; i++)
    solve();
  /* Update the status variables. */
  plhs[1] = mxCreateStructArray(1, dims1x1of1, 4, status_names);
  xm = mxCreateDoubleMatrix(1, 1, mxREAL);
  mxSetField(plhs[1], 0, "optval", xm);
  *mxGetPr(xm) = work.optval;
  xm = mxCreateDoubleMatrix(1, 1, mxREAL);
  mxSetField(plhs[1], 0, "gap", xm);
  *mxGetPr(xm) = work.gap;
  xm = mxCreateDoubleMatrix(1, 1, mxREAL);
  mxSetField(plhs[1], 0, "steps", xm);
  *mxGetPr(xm) = steps;
  xm = mxCreateDoubleMatrix(1, 1, mxREAL);
  mxSetField(plhs[1], 0, "converged", xm);
  *mxGetPr(xm) = work.converged;
  /* Extract variable values. */
  plhs[0] = mxCreateStructArray(1, dims1x1of1, num_var_names, var_names);
  /* Create cell arrays for indexed variables. */
  dims[0] = 10;
  cell = mxCreateCellArray(1, dims);
  mxSetField(plhs[0], 0, "u", cell);
  dims[0] = 11;
  cell = mxCreateCellArray(1, dims);
  mxSetField(plhs[0], 0, "x", cell);
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_0", xm);
  dest = mxGetPr(xm);
  src = vars.u_0;
  for (i = 0; i < 2; i++) {
    *dest++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_1", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 0, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_1;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_2", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 1, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_2;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_3", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 2, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_3;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_4", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 3, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_4;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_5", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 4, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_5;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_6", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 5, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_6;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_7", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 6, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_7;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_8", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 7, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_8;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_9", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 8, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_9;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(2, 1, mxREAL);
  mxSetField(plhs[0], 0, "u_10", xm);
  xm_cell = mxCreateDoubleMatrix(2, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "u");
  mxSetCell(cell, 9, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.u_10;
  for (i = 0; i < 2; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_1", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 0, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_1;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_2", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 1, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_2;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_3", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 2, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_3;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_4", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 3, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_4;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_5", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 4, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_5;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_6", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 5, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_6;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_7", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 6, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_7;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_8", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 7, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_8;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_9", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 8, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_9;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_10", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 9, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_10;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
  xm = mxCreateDoubleMatrix(6, 1, mxREAL);
  mxSetField(plhs[0], 0, "x_11", xm);
  xm_cell = mxCreateDoubleMatrix(6, 1, mxREAL);
  cell = mxGetField(plhs[0], 0, "x");
  mxSetCell(cell, 10, xm_cell);
  dest = mxGetPr(xm);
  dest_cell = mxGetPr(xm_cell);
  src = vars.x_11;
  for (i = 0; i < 6; i++) {
    *dest++ = *src;
    *dest_cell++ = *src++;
  }
}
mxArray *sf_c10_adcs_v15_integral_Power_nom_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(1696892486U);
    pr[1] = (double)(3281932529U);
    pr[2] = (double)(4258979837U);
    pr[3] = (double)(1164524302U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxData);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 26
0
mxArray *sf_c4_DisplayCANMsg_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals", "postCodegenInfo" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1, 1, sizeof
    (autoinheritanceFields)/sizeof(autoinheritanceFields[0]),
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("yR9xWeEO4THJ0b7ucUgS9C");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt", "isFixedPointType" };

      mxArray *mxType = mxCreateStructMatrix(1,1,sizeof(typeFields)/sizeof
        (typeFields[0]),typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(6));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxType,0,"isFixedPointType",mxCreateDoubleScalar(0));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  {
    mxArray* mxPostCodegenInfo = sf_c4_DisplayCANMsg_get_post_codegen_info();
    mxSetField(mxAutoinheritanceInfo,0,"postCodegenInfo",mxPostCodegenInfo);
  }

  return(mxAutoinheritanceInfo);
}
mxArray *sf_c17_HIL_model_error_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("VXZlspe2d7KKElQK7f33OD");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 28
0
void ttCallBlockSystem(int nOutp, double *outp, int nInp, double *inp, const char *blockName) {
  
  mxArray *simsetRHS[8];
  mxArray *simRHS[4];
  mxArray *simLHS[3];
  mxArray *options[1];
  mxArray *states;
  double *values;
  double *state_values;
  int i, j, n;

  DataNode* dn;
  Blockdata *bd;

  // Make sure that the Simulink block exists in Matlab path
  mxArray *lhs[1];
  mxArray *rhs[1];
  rhs[0] = mxCreateString(blockName);
  mexCallMATLAB(1, lhs, 1, rhs, "exist");
  int number = (int) *mxGetPr(lhs[0]);
  if (number == 0) {
    TT_MEX_ERROR("ttCallBlockSystem: Simulink block not in path!");
    for (j=0; j < nOutp; j++) {
      outp[j] = 0.0;
    }
    return;
  }

  Task* task = rtsys->running;
  dn = (DataNode*) getNode(blockName, task->blockList);

  if (dn==NULL) {
    // Not found, create options mxArray (Matlab struct) 

    bd = new Blockdata(blockName);
    
    simsetRHS[0] = mxCreateString("Solver");
    simsetRHS[1] = mxCreateString("FixedStepDiscrete");
    simsetRHS[2] = mxCreateString("FixedStep");
	simsetRHS[3] = mxCreateDoubleScalar(1.0);
    simsetRHS[4] = mxCreateString("MaxDataPoints");
	simsetRHS[5] = mxCreateDoubleScalar(2.0);
    simsetRHS[6] = mxCreateString("OutputVariables");
    simsetRHS[7] = mxCreateString("xy");
    
    mexCallMATLAB(1, options, 8, simsetRHS, "simset");
    
    bd->options = options[0];
    mexMakeArrayPersistent(bd->options);
    
    for (i=0; i<8; i++) {
      mxDestroyArray(simsetRHS[i]);
    }
    task->blockList->appendNode(new DataNode(bd, bd->blockName));
  } else {
    bd = (Blockdata*) dn->data;
  }

  // [t,x,outp] = sim(blockName,1,options,[0 inp]) 

  simRHS[0] = mxCreateString(blockName);
  simRHS[1] = mxCreateDoubleScalar(1.0);
  simRHS[2] = bd->options;
  simRHS[3] = mxCreateDoubleMatrix(1, nInp+1, mxREAL);
  values = mxGetPr(simRHS[3]);
  values[0] = 0.0;
  for (j=0; j < nInp; j++) {
    values[j+1] = inp[j];
  }

  i = mexCallMATLAB(3, simLHS, 4, simRHS, "sim");

  mxDestroyArray(simRHS[0]);
  mxDestroyArray(simRHS[1]);
  mxDestroyArray(simRHS[3]);

  if (i==0) { // Successful
    // Update options mxArray with last row of returned state matrix 
    n = mxGetN(simLHS[1]); // Number of cols of state matrix 
    
    states = mxCreateDoubleMatrix(1, n, mxREAL);

    values = mxGetPr(simLHS[1]);
    state_values = mxGetPr(states);
    
    // Transfer values 
    for (j=0; j < n; j++) {
      state_values[j] = values[2*j+1]; // second row elements
    }

    mxArray* oldstates = mxGetField(bd->options, 0, "InitialState");
    mxDestroyArray(oldstates);
    mxSetField(bd->options, 0, "InitialState", states);
    
    // Return the output of the simulation, first row of returned output matrix 
    values = mxGetPr(simLHS[2]);
    for (j=0; j < nOutp; j++) {
      outp[j] = values[2*j];          // first row elements
    }

    mxDestroyArray(simLHS[0]);
    mxDestroyArray(simLHS[1]);
    mxDestroyArray(simLHS[2]);

  } else {

    TT_MEX_ERROR("ttCallBlockSystem: Simulation failed!");
    for (j=0; j < nOutp; j++) {
      outp[j] = 0.0;
    }
  }
}
mxArray *sf_c1_motor_control_with_off_the_shelf_SVPWM_get_autoinheritance_info
  (void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("gIN6RcWrDawHbmOtO18itE");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Exemplo n.º 30
0
mxArray* ParseChildNodes(pugi::xml_node& node)
{
    mxArray *children = NULL;
    pugi::xml_attribute tempAttr = node.first_attribute();

    if (HasChildNodes(node) || tempAttr != NULL)
    {
        mxArray *attributes = ParseAttributes(node);

        std::vector<std::string> distinctNames;
        std::vector<std::string> allChildNodeNames;
        std::vector<pugi::xml_node> childNodes;
        std::size_t numChildNodes;

        childNodes = GetChildNodes(node);
        numChildNodes = childNodes.size();

        for (int i = 0; i < numChildNodes; i++)
        {
            allChildNodeNames.push_back(childNodes.at(i).name());
        }

        distinctNames = GetDistinctNodeNames(allChildNodeNames);
        
        /* Patch for bypassing the variable-length arrays problems of modern C++ compilers */
        std::vector<const char*> distinctChildNodeNames;
        std::transform(distinctNames.begin(), distinctNames.end(), std::back_inserter(distinctChildNodeNames), [](const std::string & str) {
            // initialize empty char array
            char *output = new char[str.size()+1];
            std::strcpy(output, str.c_str());
            return output;
        });        

        std::vector<std::string> processedNames;

        children = mxCreateStructMatrix(1, 1, (int)distinctNames.size(), &distinctChildNodeNames[0]);

        for (int idx = 0; idx < childNodes.size(); idx++)
        {
            pugi::xml_node theChild = childNodes.at(idx);
            std::string type = node_types[theChild.type()];
            std::string temp = theChild.name();
            std::string val = theChild.value();

            const char *namey[1] = {};
            namey[0] = temp.c_str();
            mxArray *glhf = mxGetField(children, 0, namey[0]);
            int indexOfMatchingItem = mxGetFieldNumber(children,  namey[0]);

            if (!(strcmp(type.c_str(), "pcdata") == 0) && !(strcmp(type.c_str(), "comment") == 0) && !(strcmp(type.c_str(), "cdata") == 0))
            {
                //XML allows the same elements to be defined multiple times, put each in a different cell
                if (std::find(processedNames.begin(), processedNames.end(), temp) != processedNames.end())
                {
                    if ( glhf != NULL )
                    {
                        if (!mxIsCell(glhf))
                        {
                            mxArray *temp = glhf;
                            glhf = mxCreateCellMatrix(1, 2);
                            mxSetCell(glhf, 0, temp);
                            mxSetCell(glhf, 1, ParseChildNodes(theChild));
                            mxSetCell(children, indexOfMatchingItem, glhf);
                        }
                        else
                        {
                            std::size_t numberItemsInCell = mxGetN(glhf);
                            mxArray *temp = glhf;
                            glhf = mxCreateCellMatrix(1, numberItemsInCell + 1);

                            for (int i = 0; i < numberItemsInCell; i++)
                            {
                                mxSetCell(glhf, i, mxGetCell(temp, i));
                            }

                            mxSetCell(glhf, numberItemsInCell, ParseChildNodes(theChild));
                            mxSetCell(children, indexOfMatchingItem, glhf);
                        }
                    }
                }
                //add previously unknown (new) element to the structure
                else
                {
                    mxSetCell(children, indexOfMatchingItem, ParseChildNodes(theChild));
                }

                processedNames.push_back(temp);
            }
            else
            {
                const char *typeFieldNames[1] = {"Text"};
                std::string value  = theChild.value();
                mxArray *matValue  = mxCreateString(value.c_str());

                if (strcmp(type.c_str(), "cdata") == 0)
                {
                    typeFieldNames[0] = "CDATA";
                }
                else if (strcmp(type.c_str(), "comment") == 0)
                {
                    typeFieldNames[0] = "Comment";
                }

                children = mxCreateStructMatrix(1, 1, 1, typeFieldNames);
                mxSetFieldByNumber(children, 0, 0, matValue);

                processedNames.push_back(temp);
            }
        }

        if (attributes != NULL)
        {
            const char *attrFieldName = "Attributes";
            mxAddField(children, attrFieldName);
            mxSetField(children, 0, attrFieldName, attributes);
        }

    }

    return children;
}