bool dFileRename(const char *oldName, const char *newName)
{
   AssertFatal( oldName != NULL && newName != NULL, "dFileRename - NULL file name" );

   TempAlloc< TCHAR > oldf( dStrlen( oldName ) + 1 );
   TempAlloc< TCHAR > newf( dStrlen( newName ) + 1 );

#ifdef UNICODE
   convertUTF8toUTF16( oldName, oldf, oldf.size );
   convertUTF8toUTF16( newName, newf, newf.size );
#else
   dStrcpy(oldf, oldName);
   dStrcpy(newf, newName);
#endif
   backslash(oldf);
   backslash(newf);

   return MoveFile( oldf, newf );
}
/**
 * Create a new cal file based on the old file
 * @param oldfile :: The old cal file path
 * @param newfile :: The new cal file path
 */
void MaskDetectorsIf::createNewCalFile(const std::string &oldfile,
                                       const std::string &newfile) {
  std::ifstream oldf(oldfile.c_str());
  if (!oldf.is_open()) {
    g_log.error() << "Unable to open grouping file " << oldfile << std::endl;
    throw Exception::FileError("Error reading .cal file", oldfile);
  }
  std::ofstream newf(newfile.c_str());
  if (!newf.is_open()) {
    g_log.error() << "Unable to open grouping file " << newfile << std::endl;
    throw Exception::FileError("Error reading .cal file", newfile);
  }
  std::string str;
  while (getline(oldf, str)) {
    // Comment or empty lines get copied into the new cal file
    if (str.empty() || str[0] == '#') {
      newf << str << std::endl;
      continue;
    }
    std::istringstream istr(str);
    int n, udet, sel, group;
    double offset;
    istr >> n >> udet >> offset >> sel >> group;
    udet2valuem::iterator it = umap.find(udet);
    bool selection;

    if (it == umap.end())
      selection = (sel == 0) ? false : true;
    else
      selection = (*it).second;

    newf << std::fixed << std::setw(9) << n << std::fixed << std::setw(15)
         << udet << std::fixed << std::setprecision(7) << std::setw(15)
         << offset << std::fixed << std::setw(8) << selection << std::fixed
         << std::setw(8) << group << std::endl;
  }
  oldf.close();
  newf.close();
  return;
}
Exemple #3
0
/* mexFunction is the gateway routine for the MEX-file. */ 
void
mexFunction( int nlhs, mxArray *plhs[],
             int nrhs, const mxArray *prhs[] )
{
  int i, r, c, Xrows, Xcols, Lrows, Lcols;
  float **mfv, **X, **L, *inData, *inLib, *outData, *outMd;
  (void) nlhs;     /* unused parameters */
  (void) plhs;
  const mwSize *dims;
  mwSize number_of_dimensions;
  mxClassID  category;

/* Check to see if we are on a platform that does not support the compatibility layer. */
#if defined(_LP64) || defined (_WIN64)
#ifdef MX_COMPAT_32
  for (i=0; i<nrhs; i++)  {
      if (mxIsSparse(prhs[i])) {
          mexErrMsgIdAndTxt("MATLAB:explore:NoSparseCompat",
                    "MEX-files compiled on a 64-bit platform that use sparse array functions need to be compiled using -largeArrayDims.");
      }
  }
#endif
#endif

  /* check inputs */
  if (nrhs != 2) 
  {
    fprintf(stderr,"I need 2 inputs\n");
    return;
  }
  if (mxGetNumberOfDimensions(prhs[0]) != 2)
  {
    mexPrintf("usage: mf(X,L), where each row of X is a spectrum\n");
    return;
  }
  if (mxGetNumberOfDimensions(prhs[1]) != 2)
  {
    mexPrintf("usage: mf(X,L), where each row of L is a spectrum\n");
    return;
  }
  category = mxGetClassID(prhs[0]);
  if (category != mxSINGLE_CLASS)
  {
    mexPrintf("The data matrix must have type 'single'\n");
    return;
  }
  category = mxGetClassID(prhs[1]);
  if (category != mxSINGLE_CLASS)
  {
    mexPrintf("The library matrix must have type 'single'\n");
    return;
  }
  
  /* Get input dimensions */
  dims = mxGetDimensions(prhs[0]);
  Xrows = dims[0];
  Xcols = dims[1];
  dims = mxGetDimensions(prhs[1]);
  Lrows = dims[0];
  Lcols = dims[1];
        
  if (Lcols != Xcols)
  {
    mexPrintf("Dimension mismatch between library and data\n");
    return;
  }
  
  inData = (float *) mxGetData(prhs[0]);
  inLib = (float *)  mxGetData(prhs[1]);

  /* build data arrays. do MF detection, clean up */
  newf(&X, Xrows, Xcols);
  newf(&L, Lrows, Lcols);
  initf(&mfv, Xrows, Lrows, 0);
  
  /* Copy matlab input arrays into X and L */
  for (r=0; r<Xrows; r++)
  {
    for (c=0; c<Xcols; c++)
    {
      X[r][c] = inData[c*Xrows+r];
    }
  }
  for (r=0; r<Lrows; r++)
  {
    for (c=0; c<Lcols; c++)
    {
      L[r][c] = inLib[c*Lrows+r];
    }
  }
  
  /* create space for output */
  outData = (float *) mxCalloc(Xrows*Lrows, sizeof(float));
  outMd = (float *) mxCalloc(Xrows, sizeof(float));
  
  /* call the library function for matched filter detection */
  mf(X, Xrows, Xcols, L, Lrows, NEVALS, DIAG, mfv, outMd);
  
  /* copy into the output array */
  for (r=0; r<Xrows; r++)
  {
    for (c=0; c<Lrows; c++)
    {
      outData[c*Xrows+r] = mfv[r][c];
    }
  }
  
  /* clean up */
  clearf(X, Xrows, Xcols);
  clearf(L, Lrows, Lcols);
  clearf(mfv, Xrows, Lrows);

  /* create output structure */
  plhs[0] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS, mxREAL);
  mxSetData(plhs[0], outData);
  mxSetM(plhs[0], Xrows);
  mxSetN(plhs[0], Lrows);
  
  if (nlhs > 1) 
  {
    plhs[1] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS, mxREAL);
    mxSetData(plhs[1], outMd);
    mxSetM(plhs[1], Xrows);
    mxSetN(plhs[1], 1);
  }
  else
  {
    mxFree(outMd);
  }
}
Exemple #4
0
//The writer simply goes gathers all objects from the scene.
//We will check if the object has a transform, if so, we will check
//if it's either a nurbsSphere, nurbsCone or nurbsCylinder.  If so,
//we will write it out.
MStatus LepTranslator::writer ( const MFileObject& file,
                                const MString& options,
                                MPxFileTranslator::FileAccessMode mode)
{
    MStatus status;
	bool showPositions = false;
    unsigned int  i;
    const MString fname = file.fullName();

    ofstream newf(fname.asChar(), ios::out);
    if (!newf) {
        // open failed
        cerr << fname << ": could not be opened for reading\n";
        return MS::kFailure;
    }
    newf.setf(ios::unitbuf);

    if (options.length() > 0) {
        // Start parsing.
        MStringArray optionList;
        MStringArray theOption;
        options.split(';', optionList);    // break out all the options.
        
        for( i = 0; i < optionList.length(); ++i ){
            theOption.clear();
            optionList[i].split( '=', theOption );
            if( theOption[0] == MString("showPositions") &&
                                                    theOption.length() > 1 ) {
                if( theOption[1].asInt() > 0 ){
                    showPositions = true;
                }else{
                    showPositions = false;
                }
            }
        }
    }

    // output our magic number
    newf << "<LEP>\n";

    MItDag dagIterator( MItDag::kBreadthFirst, MFn::kInvalid, &status);

    if ( !status) {
        status.perror ("Failure in DAG iterator setup");
        return MS::kFailure;
    }

    MSelectionList selection;
    MGlobal::getActiveSelectionList (selection);
    MItSelectionList selIterator (selection, MFn::kDagNode);

    bool done = false;
    while (true) 
    {
        MObject currentNode;
        switch (mode)
        {
            case MPxFileTranslator::kSaveAccessMode:
            case MPxFileTranslator::kExportAccessMode:
                if (dagIterator.isDone ())
                    done = true;
                else {
                    currentNode = dagIterator.item ();
                    dagIterator.next ();
                }
                break;
            case MPxFileTranslator::kExportActiveAccessMode:
                if (selIterator.isDone ())
                    done = true;
                else {
                    selIterator.getDependNode (currentNode);
                    selIterator.next ();
                }
                break;
            default:
                cerr << "Unrecognized write mode: " << mode << endl;
                break;
        }
        if (done)
            break;

        //We only care about nodes that are transforms
        MFnTransform dagNode(currentNode, &status);
        if ( status == MS::kSuccess ) 
        {
            MString nodeNameNoNamespace=MNamespace::stripNamespaceFromName(dagNode.name());
            for (i = 0; i < numPrimitives; ++i) {                
                if(nodeNameNoNamespace.indexW(primitiveStrings[i]) >= 0){
                    // This is a node we support
                    newf << primitiveCommands[i] << " -n " << nodeNameNoNamespace << endl;
                    if (showPositions) {
                        MVector pos;
                        pos = dagNode.getTranslation(MSpace::kObject);
                        newf << "move " << pos.x << " " << pos.y << " " << pos.z << endl;
                    }
                }
            }
        }//if (status == MS::kSuccess)
    }//while loop

    newf.close();
    return MS::kSuccess;
}