当前位置: 首页>>代码示例>>C++>>正文


C++ DataStore::add_group方法代码示例

本文整理汇总了C++中DataStore::add_group方法的典型用法代码示例。如果您正苦于以下问题:C++ DataStore::add_group方法的具体用法?C++ DataStore::add_group怎么用?C++ DataStore::add_group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataStore的用法示例。


在下文中一共展示了DataStore::add_group方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mexFunction

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
  int i,j,k;
  char *filename;
  char *precision;
  DataGroup::DataType prec;
  const char *fieldname;
  const mxArray *matstruct, *matcell, *matfield;
  mwSize numfields;
  mwSize ndims;
  mwSize nelems;
  mwSize numcells;
  const mwSize *dims;
  double *dreal;
  double *dimag;
  float *sreal;
  float *simag;

  ofstream output;

  /* Protobuf object types */
  DataStore ds;
  DataGroup *dg;
  DataValue *dv;
  
  if(nlhs != 0){
    mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore","Mex function does not return any values.");
  }

  if(nrhs != 3 || !mxIsChar(prhs[0]) || !mxIsChar(prhs[1])){
    mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore","Mex function takes a file name, precision string and a single structure of named literals.");
  }

  /* Check the type/precision requested */
  precision = mxArrayToString(prhs[1]);
  if(0 == strcmp(precision, "double")){
    prec = DataGroup::DOUBLE;
  }else if(0 == strcmp(precision, "complexdouble")){
    prec = DataGroup::COMPLEXDOUBLE;
  }else if(0 == strcmp(precision, "float")){
    prec = DataGroup::SINGLE;
  }else if(0 == strcmp(precision, "complexfloat")){
    prec = DataGroup::COMPLEXSINGLE;
  }else{
    mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Invalid precision requested '%s'.\n", precision);
  }
  mxFree(precision);

  matstruct = prhs[2];
  ndims = mxGetNumberOfDimensions(matstruct);
  dims = mxGetDimensions(matstruct);

  /* Verify that the data input is a structure and does not have multiple dimensions */
  if(!mxIsStruct(matstruct) ||
     2 != ndims ||
     1 != dims[0] ||
     1 != dims[1]){
    mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore","Mex function takes file name, precision string and a single structure of named literals.");
  }

  numfields = mxGetNumberOfFields(matstruct);

  for(i=0;i<numfields;i++){
    fieldname = mxGetFieldNameByNumber(matstruct, i);

    /* Check to see if struct field is a cell array */
    matcell = mxGetFieldByNumber(matstruct, 0, i);
    if(mxIsCell(matcell)){
      ndims = mxGetNumberOfDimensions(matcell);
      dims = mxGetDimensions(matcell);
      numcells = 1;
      for(j=0;j<ndims;j++){
	numcells *= dims[j];
      }
      matfield = mxGetCell(matcell, 0);
    }
    else{
      numcells = 1;
      matfield = matcell;
    }

    /* Create a new DataGroup corresponding to the structure field */
    dg = ds.add_group();
    dg->set_name(fieldname);
    dg->set_type(prec);

    /* Add a DataValue for each cell in structure field, only one member if field is numeric */
    for(j=0;j<numcells;j++){
      /* Ensure data element is double precision numeric data if requested precision is double */
      if(!mxIsDouble(matfield) && (DataGroup::DOUBLE == prec || DataGroup::COMPLEXDOUBLE == prec)){
	mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore","Field '%s' does not contain a double precision numeric literal at position %d.  Type is '%s'.", fieldname, j, mxGetClassName(matfield));
      }
      
      /* Ensure data element is double or single precision if requested precision is single */
      if(!mxIsDouble(matfield) && !mxIsSingle(matfield) && (DataGroup::SINGLE == prec || DataGroup::COMPLEXSINGLE == prec)){
	mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Field '%s' does not contain a floating point literal at position %d.  Type is '%s'.", fieldname, j, mxGetClassName(matfield));
      }

      /* Ensure data is not complex if only reals were specified */
      if(mxIsComplex(matfield) && (DataGroup::DOUBLE == prec || DataGroup::SINGLE == prec)){
	mexErrMsgIdAndTxt("Simatra:simEngine:mexDataStore", "Field '%s' contains a complex literal at position %d but only real values were requested.", fieldname, j);
//.........这里部分代码省略.........
开发者ID:joshuaecook,项目名称:simengine,代码行数:101,代码来源:mexDataStore.cpp


注:本文中的DataStore::add_group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。