コード例 #1
0
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 );
}
コード例 #2
0
ファイル: MaskDetectorsIf.cpp プロジェクト: mkoennecke/mantid
/**
 * 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;
}