NAMD
Functions
common.C File Reference
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <ctype.h>
#include "common.h"
#include "InfoStream.h"
#include "charm++.h"

Go to the source code of this file.

Functions

char * NAMD_stringdup (const char *s)
 
void NAMD_quit (const char *err_msg)
 
void NAMD_die (const char *err_msg)
 
void NAMD_err (const char *err_msg)
 
void NAMD_bug (const char *err_msg)
 
int NAMD_file_exists (const char *filename)
 
void NAMD_backup_file (const char *filename, const char *extension)
 
int NAMD_open_text (const char *fname, int append)
 
void NAMD_write (int fd, const char *buf, size_t count, const char *fname)
 
void NAMD_close (int fd, const char *fname)
 
FILE * Fopen (const char *filename, const char *mode)
 
int Fclose (FILE *fout)
 

Function Documentation

int Fclose ( FILE *  fout)

Definition at line 359 of file common.C.

Referenced by ConfigList::ConfigList(), parm::genclose(), PDB::PDB(), read_binary_file(), and Parameters::read_parameter_file().

360 {
361  int rc = -1;
362 #if !defined(NOCOMPRESSED)
363  rc = pclose(fout);
364 #endif
365  if (rc == -1) // stream not associated with a popen()
366  {
367  rc = fclose(fout);
368  }
369  return rc;
370 } /* Fclose() */
FILE* Fopen ( const char *  filename,
const char *  mode 
)

Definition at line 265 of file common.C.

References endi(), and iout.

Referenced by ConfigList::ConfigList(), parm::genopen(), GridforceFullMainGrid::initialize(), PDB::PDB(), read_binary_file(), and Parameters::read_parameter_file().

266 {
267  struct stat buf;
268  // check if basic filename exists (and not a directory)
269 
270 #if defined(NOCOMPRESSED)
271  if (!stat(filename,&buf))
272  {
273  FILE *rval;
274  while ( ! (rval = fopen(filename,mode)) ) {
275  if ( errno != EINTR ) break;
276  }
277  return(rval);
278  }
279 #else
280  if (!stat(filename,&buf))
281  {
282  if (!S_ISDIR(buf.st_mode)) {
283  FILE *rval;
284  while ( ! (rval = fopen(filename,mode)) ) {
285  if ( errno != EINTR ) break;
286  }
287  return(rval);
288  }
289  }
290  // check for a compressed file
291  char *realfilename;
292  char *command;
293  FILE *fout;
294  command = (char *)malloc(strlen(filename)+25);
295  // check for .Z (unix compress)
296  sprintf(command,"zcat %s.Z",filename);
297  realfilename = command+5;
298  iout << "Command = " << command << "\n" << endi;
299  iout << "Filename.Z = " << realfilename << "\n" << endi;
300  if (!stat(realfilename,&buf))
301  {
302  if (!S_ISDIR(buf.st_mode))
303  {
304  fout = popen(command,mode);
305  // on HP-UX, the first character(s) out of pipe may be
306  // garbage! (Argh!)
307  int C;
308  do
309  {
310  C = fgetc(fout);
311  // iout << "C is " << C << "\n" << endi;
312  if (isalnum(C) || isspace(C))
313  {
314  ungetc(C,fout);
315  C = -1; // outta loop
316  }
317  } while(C != -1);
318  free(command);
319  return(fout);
320  }
321  }
322  // check for .gz (gzip)
323  sprintf(command,"gzip -d -c %s.gz",filename);
324  realfilename = command+11;
325  iout << "Command = " << command << "\n" << endi;
326  iout << "Filename.gz = " << realfilename << "\n" << endi;
327  if (!stat(realfilename,&buf))
328  {
329  if (!S_ISDIR(buf.st_mode))
330  {
331  fout = popen(command,mode);
332  // on HP-UX, the first character(s) out of pipe may be
333  // garbage! (Argh!)
334  int C;
335  do
336  {
337  C = fgetc(fout);
338  // iout << "C is " << C << "\n" << endi;
339  if (isalnum(C) || isspace(C))
340  {
341  ungetc(C,fout);
342  C = -1; // outta loop
343  }
344  } while(C != -1);
345  free(command);
346  return(fout);
347  }
348  }
349  free(command);
350 #endif /* !defined(NOCOMPRESSED) */
351 
352  return(NULL);
353 } /* Fopen() */
#define iout
Definition: InfoStream.h:87
infostream & endi(infostream &s)
Definition: InfoStream.C:38
void NAMD_backup_file ( const char *  filename,
const char *  extension 
)

Definition at line 159 of file common.C.

References endi(), iERROR(), iout, and NAMD_file_exists().

Referenced by Controller::adaptTempInit(), colvarproxy_namd::backup_file(), ofstream_namd::open(), open_dcd_write(), Controller::outputExtendedSystem(), Controller::outputFepEnergy(), Controller::outputTiEnergy(), CollectionMaster::receiveDataStream(), and Controller::write_accelMDG_rest_file().

160 {
161  if (NAMD_file_exists(filename)) {
162  if ( ! extension ) extension = ".BAK";
163  char *backup = new char[strlen(filename)+strlen(extension)+1];
164  strcpy(backup, filename);
165  strcat(backup, extension);
166 #if defined(WIN32) && !defined(__CYGWIN__)
167  if ( remove(backup) ) if ( errno != ENOENT ) {
168  char *sys_err_msg = strerror(errno);
169  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
170  iout << iERROR << "Error on removing file "
171  << backup << ": " << sys_err_msg << "\n" << endi;
172  fflush(stdout);
173  }
174 #endif
175  while ( rename(filename,backup) )
176  {
177  if ( errno == EINTR ) continue;
178  const char *sys_err_msg = strerror(errno);
179  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
180  iout << iERROR << "Error on renaming file " << filename
181  << " to " << backup << ": " << sys_err_msg << "\n" << endi;
182  fflush(stdout);
183  if ( errno == EXDEV ) continue;
184  break;
185  // char errmsg[256];
186  // sprintf(errmsg, "Error on renaming file %s to %s",filename,backup);
187  // NAMD_err(errmsg);
188  }
189  delete [] backup;
190  }
191 }
int NAMD_file_exists(const char *filename)
Definition: common.C:143
#define iout
Definition: InfoStream.h:87
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:109
infostream & endi(infostream &s)
Definition: InfoStream.C:38
void NAMD_bug ( const char *  err_msg)

Definition at line 123 of file common.C.

Referenced by Sequencer::algorithm(), Controller::algorithm(), CollectProxyVectorInstance::append(), CudaComputeNonbonded::assignPatches(), CudaComputeNonbonded::assignPatchesOnPe(), PmePencilXYZ::backwardDone(), LdbCoordinator::barrier(), ComputeNonbondedCUDA::build_exclusions(), ComputeNonbondedCUDA::build_lj_table(), HomePatch::buildSpanningTree(), ReductionMgr::buildSpanTree(), ComputeNonbondedUtil::calc_error(), Controller::calcPressure(), ComputePmeMgr::chargeGridReady(), checkSum(), ofstream_namd::close(), Box< Patch, CompAtom >::close(), Controller::compareChecksums(), ComputeCUDAMgr::ComputeCUDAMgr(), ComputeNonbondedCUDA::ComputeNonbondedCUDA(), ComputePmeCUDAMgr::ComputePmeCUDAMgr(), ComputeTclBC::ComputeTclBC(), CudaPmeTranspose::copyDataDeviceToDevice(), CudaPmeTranspose::copyDataDeviceToHost(), CudaPmeTranspose::copyDataHostToDevice(), WorkDistrib::createAtomLists(), ComputeCUDAMgr::createCudaComputeNonbonded(), ComputePmeCUDAMgr::createDevicesAndAtomFiler(), CsmAckHandler(), CsmHandler(), cuda_check_local_progress(), cuda_check_remote_progress(), cudaNAMD_bug(), CudaPmeRealSpaceCompute::CudaPmeRealSpaceCompute(), MigrateAtomsCombinedMsg::distribute(), ComputeGridForce::doForce(), HomePatch::doGroupSizeCheck(), ComputePme::doWork(), ComputeNonbondedCUDA::doWork(), CudaComputeNonbonded::doWork(), WorkDistrib::enqueueAngles(), WorkDistrib::enqueueAniso(), WorkDistrib::enqueueBonds(), WorkDistrib::enqueueCrossterms(), WorkDistrib::enqueueDihedrals(), WorkDistrib::enqueueExcls(), WorkDistrib::enqueueGromacsPair(), WorkDistrib::enqueueImpropers(), WorkDistrib::enqueueLCPO(), WorkDistrib::enqueuePme(), WorkDistrib::enqueueSelfA1(), WorkDistrib::enqueueSelfA2(), WorkDistrib::enqueueSelfA3(), WorkDistrib::enqueueSelfB1(), WorkDistrib::enqueueSelfB2(), WorkDistrib::enqueueSelfB3(), WorkDistrib::enqueueThole(), WorkDistrib::enqueueWork(), WorkDistrib::enqueueWorkA1(), WorkDistrib::enqueueWorkA2(), WorkDistrib::enqueueWorkA3(), WorkDistrib::enqueueWorkB1(), WorkDistrib::enqueueWorkB2(), WorkDistrib::enqueueWorkB3(), WorkDistrib::enqueueWorkC(), ScriptTcl::eval(), ComputeMap::extendPtrs(), findRecipEvirPe(), CudaComputeNonbonded::finishReductions(), ofstream_namd::flush(), PmeAtomStorage::getAtomIndex(), getBlockDim(), CudaPmeTranspose::getBuffer(), ComputeCUDAMgr::getComputeCUDAMgr(), ComputeCUDAMgr::getCudaComputeNonbonded(), ComputePmeCUDAMgr::getDevice(), ComputePmeCUDAMgr::getDevicePencilY(), ComputePmeCUDAMgr::getDevicePencilZ(), ParseOptions::getfromptr(), ComputePmeCUDAMgr::getHomePencil(), Communicate::getMessage(), ComputePmeCUDAMgr::getNode(), getPencilDim(), GridforceFullBaseGrid::grid_index(), FFTCompute::init(), ComputePmeCUDA::initialize(), ComputePatch::initialize(), ComputeHomePatch::initialize(), ComputePme::initialize(), LdbCoordinator::initialize(), ParallelIOMgr::initialize(), ComputePmeMgr::initialize(), ComputePmeMgr::initialize_computes(), IRSet::insert(), ParseOptions::issetfromptr(), ParseOptions::istruefromptr(), CudaComputeNonbonded::launchWork(), LdbCoordinator::LdbCoordinator(), ScriptTcl::load(), NamdState::loadStructure(), PatchMap::makePatches(), WorkDistrib::messageEnqueueWork(), CudaComputeNonbonded::messageEnqueueWork(), WorkDistrib::messageFinishCUDA(), WorkDistrib::messageFinishMIC(), HomePatch::minimize_rattle2(), Sequencer::multigratorPressure(), NAMD_write(), Node::Node(), PmeZPencil::node_process_untrans(), PmeYPencil::node_process_untrans(), ofstream_namd::open(), Box< Patch, CompAtom >::open(), CudaComputeNonbonded::openBoxesOnPe(), PatchMap::pack(), PatchMgr::PatchMgr(), CudaComputeNonbonded::patchReady(), PmePencilX::PmePencilX(), PmePencilXY::PmePencilXY(), PmePencilXYZ::PmePencilXYZ(), PmePencilY::PmePencilY(), PmePencilZ::PmePencilZ(), PmeTranspose::PmeTranspose(), ComputePmeMgr::pollChargeGridReady(), ComputePmeMgr::pollForcesReady(), PmePencilXYZMap::populateInitial(), PmePencilXMap::populateInitial(), PmePencilXYMap::populateInitial(), PmePencilMap::populateInitial(), Controller::printEnergies(), Rebalancer::printLoads(), PmePencilXMap::procNum(), PmePencilXYMap::procNum(), ProxyMgr::ProxyMgr(), HomePatch::rattle2(), Sequencer::reassignVelocities(), ProxyPatch::receiveAll(), ProxyPatch::receiveData(), ParallelIOMgr::receiveForces(), ParallelIOMgr::receivePositions(), ParallelIOMgr::receiveVelocities(), recursive_bisect_with_curve(), recvAck(), ComputePmeMgr::recvAck(), ComputePmeCUDADevice::recvAtoms(), ComputePmeCUDADevice::recvAtomsFromNeighbor(), recvBcast(), BroadcastMgr::recvBroadcast(), PatchMgr::recvCheckpointAck(), HomePatch::recvCheckpointLoad(), PatchMgr::recvCheckpointReq(), WorkDistrib::recvComputeMapChanges(), GlobalMasterServer::recvData(), recvData(), ComputePmeCUDAMgr::recvDevices(), recvEvalCommand(), recvEvalResult(), PatchMgr::recvExchangeReq(), ComputePmeCUDADevice::recvForcesFromNeighbor(), ComputePmeMgr::recvGrid(), ComputeQMMgr::recvPartQM(), ComputePmeMgr::recvRecipEvir(), Output::recvReplicaDcdData(), ComputeGlobal::recvResults(), ProxyMgr::recvResults(), ComputePmeMgr::recvUngrid(), NodePmeMgr::recvUngrid(), ReductionSet::ReductionSet(), register_cuda_compute_pair(), register_cuda_compute_self(), AtomMapper::registerIDsCompAtomExt(), AtomMapper::registerIDsFullAtom(), registerUserEventsForAllComputeObjs(), Node::reloadGridforceGrid(), ReductionMgr::remoteSubmit(), IRSet::remove(), replica_bcast(), replica_min_double(), CollectProxyVectorInstance::reset(), CollectionMgr::CollectVectorInstance::reset(), CollectionMaster::CollectVectorInstance::reset(), ComputeGlobal::saveTotalForces(), Sequencer::scalePositionsVelocities(), ComputeNonbondedUtil::select(), PmeZPencil::send_ungrid(), PatchMgr::sendAtoms(), NodePmeMgr::sendDataHelper(), ComputePmeMgr::sendDataPart(), Communicate::sendMessage(), PatchMgr::sendMovePatches(), PatchMgr::sendOneHomePatch(), NodePmeMgr::sendPencilsHelper(), ComputePmeMgr::sendPencilsPart(), CudaPmeTranspose::setDataPtrsYZX(), CudaPmeTranspose::setDataPtrsZXY(), ComputePmeCUDADevice::setPencilProxy(), ComputePmeCUDAMgr::setupPencils(), SimpleBroadcastObject< Tensor >::SimpleBroadcastObject(), Box< Patch, CompAtom >::skip(), CudaComputeNonbonded::skipPatchesOnPe(), CudaPmeKSpaceCompute::solve(), Node::startup(), ComputeMap::storeCompute(), ComputePmeCUDA::storePmeForceMsg(), PmePencilXYZ::submitReductions(), PmePencilZ::submitReductions(), ComputePmeMgr::submitReductions(), Sync::Sync(), TopoManagerWrapper::TopoManagerWrapper(), CudaPmeTranspose::transposeXYZtoYZX(), CudaPmeTranspose::transposeXYZtoZXY(), IRSet::unchecked_insert(), ComputePme::ungridForces(), ComputeMap::unpack(), GridforceGrid::unpack_grid(), unregister_cuda_compute(), CudaComputeNonbonded::unregisterBoxesOnPe(), AtomMapper::unregisterIDsCompAtomExt(), AtomMapper::unregisterIDsFullAtom(), ComputeCUDAMgr::update(), ComputeMgr::updateComputes(), Node::updateGridScale(), WorkDistrib::WorkDistrib(), AtomMapper::~AtomMapper(), and Rebalancer::~Rebalancer().

124 {
125  if ( ! err_msg ) err_msg = "(unknown error)";
126  const char *bug_msg =
127  "FATAL ERROR: See http://www.ks.uiuc.edu/Research/namd/bugreport.html";
128  CkPrintf("FATAL ERROR: %s\n%s\n",err_msg, bug_msg);
129  fflush(stdout);
130  char repstr[24] = "";
131  if (CmiNumPartitions() > 1) {
132  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
133  }
134  CkError("%sFATAL ERROR: %s\n%s\n", repstr, err_msg, bug_msg);
135 #if CHARM_VERSION < 61000
136  CkExit();
137 #else
138  CkExit(2);
139 #endif
140 }
void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 239 of file common.C.

239  {
240 #ifdef WIN32
241  while ( _close(fd) ) {
242 #else
243  while ( close(fd) ) {
244 #endif
245  if ( errno != EINTR ) {
246  char errmsg[1024];
247  sprintf(errmsg, "Error on closing file %s", fname);
248  NAMD_err(errmsg);
249  }
250  }
251 }
void NAMD_err(const char *err_msg)
Definition: common.C:102
void NAMD_die ( const char *  err_msg)

Definition at line 83 of file common.C.

Referenced by Controller::adaptTempInit(), ConfigList::add_element(), ComputeMsmMgr::addPotential(), after_backend_init(), Controller::algorithm(), AnisoElem::AnisoElem(), msm::PatchData::anterpolation(), msm::PatchData::anterpolationC1Hermite(), Parameters::assign_angle_index(), Parameters::assign_bond_index(), Parameters::assign_crossterm_index(), Parameters::assign_dihedral_index(), Parameters::assign_improper_index(), Parameters::assign_vdw_index(), WorkDistrib::assignNodeToPatch(), ComputeNonbondedCUDA::build_exclusions(), Molecule::build_go_arrays(), Molecule::build_go_params(), Molecule::build_go_sigmas(), Molecule::build_go_sigmas2(), Molecule::build_gridforce_params(), buildBondData(), HomePatch::buildRattleList(), ReductionMgr::buildSpanTree(), CudaTileListKernel::buildTileLists(), ParallelIOMgr::calcAtomsInEachPatch(), ComputeQMMgr::calcMOPAC(), ComputeQMMgr::calcORCA(), GlobalMasterTest::calculate(), GlobalMasterTcl::calculate(), GlobalMaster::calculate(), ComputeQMMgr::calcUSR(), GlobalMaster::check(), ComputeMsmMgr::compute(), PmeRealSpace::compute_forces(), AngleElem::computeForce(), ComputeMgr::ComputeMgr(), ComputeNonbondedCUDA::ComputeNonbondedCUDA(), ComputeTclBC::ComputeTclBC(), ConfigList::ConfigList(), NamdState::configListInit(), ConfigList::ConfigListNode::ConfigListNode(), Sequencer::correctMomentum(), Controller::correctMomentum(), WorkDistrib::createAtomLists(), cuda_errcheck(), cuda_getargs(), cuda_init_bspline_coeffs(), CudaComputeNonbonded::CudaComputeNonbonded(), cudaDie(), ComputeMsmMgr::d_stencil_1d(), Molecule::delete_qm_bonded(), ComputeGridForce::doForce(), ComputeNonbondedSelf::doForce(), HomePatch::doMarginCheck(), Parameters::done_reading_files(), ComputeFullDirect::doWork(), ComputeTclBC::doWork(), ARestraint::EarlyExit(), Node::earlyExit(), GlobalMasterMisc::easy_calc(), msm::Array< msm::PatchDiagram >::elem(), msm::GridFixed< T, N >::elem(), msm::Grid< Vtype >::elem(), colvarproxy_namd::error(), ScriptTcl::eval(), PmeZPencil::fft_init(), PmeYPencil::fft_init(), PmeXPencil::fft_init(), PmeRealSpace::fill_charges(), parm::get(), Molecule::get_atom_from_index_in_residue(), Molecule::get_atom_from_name(), Molecule::get_atomtype(), Parameters::get_dihedral_params(), Molecule::get_fep_bonded_type(), Parameters::get_improper_params(), Molecule::get_residue_size(), Parameters::get_vdw_params(), AngleElem::getMoleculePointers(), ImproperElem::getMoleculePointers(), CrosstermElem::getMoleculePointers(), DihedralElem::getMoleculePointers(), TholeElem::getMoleculePointers(), AnisoElem::getMoleculePointers(), BondElem::getMoleculePointers(), ExclElem::getMoleculePointers(), GromacsPairElem::getMoleculePointers(), CudaComputeNonbondedKernel::getPatchReadyQueue(), TholeElem::getTupleInfo(), AnisoElem::getTupleInfo(), GlobalMasterIMD::GlobalMasterIMD(), GlobalMasterSymmetry::GlobalMasterSymmetry(), GromacsTopFile::GromacsTopFile(), BackEnd::init(), DeviceCUDA::initialize(), LdbCoordinator::initialize(), GridforceFullMainGrid::initialize(), GridforceFullSubGrid::initialize(), GridforceLiteGrid::initialize(), ComputePmeMgr::initialize(), ComputeMsmMgr::initialize(), SimParameters::initialize_config_data(), msm::PatchData::interpolation(), msm::PatchData::interpolationC1Hermite(), ScriptTcl::load(), NamdState::loadStructure(), ludcmp(), main::main(), Node::mallocTest(), WorkDistrib::mapComputes(), HomePatch::minimize_rattle2(), Molecule::Molecule(), HomePatch::mollyAverage(), HomePatch::mollyMollify(), NAMD_new_handler(), NAMD_read_int(), NAMD_read_line(), NAMD_seek(), NAMD_write(), ComputeMsmMgr::ndsplitting(), CudaComputeNonbondedKernel::nonbondedForce(), Vector::operator[](), Node::outputPatchComputeMaps(), MGridforceParamsList::pack_data(), WorkDistrib::patchMapInit(), PDB::PDB(), PDBUnknown::PDBUnknown(), parm::preadln(), Molecule::prepare_qm(), ProblemParsing(), MsmBlockProxyMsg::put(), MsmC1HermiteBlockProxyMsg::put(), HomePatch::rattle1old(), HomePatch::rattle2(), Molecule::read_alch_unpert_angles(), Molecule::read_alch_unpert_bonds(), Molecule::read_alch_unpert_dihedrals(), read_binary_file(), Parameters::read_charmm_parameter_file(), Parameters::read_ener_table(), Parameters::read_energy_type(), Parameters::read_energy_type_bothcubspline(), Parameters::read_energy_type_cubspline(), Molecule::read_go_file(), Parameters::read_parameter_file(), Parameters::read_parm(), SimParameters::readExtendedSystem(), GridforceFullBaseGrid::readSubgridHierarchy(), RecBisection::RecBisection(), Molecule::receive_GoMolecule(), Parameters::receive_Parameters(), CollectionMaster::receiveDataStream(), ParallelIOMgr::recvAtomsCntPerPatch(), Controller::recvCheckpointReq(), HomePatch::recvCheckpointReq(), ComputeMgr::recvComputeDPMEData(), ComputeMgr::recvComputeDPMEResults(), ComputeMgr::recvComputeEwaldData(), ComputeMgr::recvComputeEwaldResults(), ComputeMgr::recvComputeGlobalData(), ComputeMgr::recvComputeGlobalResults(), ComputeExtMgr::recvCoord(), ComputeMsmSerialMgr::recvCoord(), ComputeFmmSerialMgr::recvCoord(), ComputeQMMgr::recvPartQM(), ComputeQMMgr::recvPntChrg(), Output::recvReplicaDcdData(), Node::reloadCharges(), Node::reloadGridforceGrid(), ReductionMgr::remoteRegister(), ReductionMgr::remoteUnregister(), ReductionSet::removeData(), Sequencer::rescaleaccelMD(), Controller::rescaleaccelMD(), CudaTileListKernel::reSortTileLists(), ScriptTcl::run(), ComputeMsm::saveResults(), SimParameters::scriptSet(), ComputeNonbondedUtil::select(), Molecule::send_GoMolecule(), Parameters::send_Parameters(), ComputeMgr::sendComputeDPMEData(), ComputeMgr::sendComputeEwaldData(), StringList::set(), msm::Array< T >::setmax(), CudaTileListKernel::setTileListVirialEnergyGBISLength(), CudaTileListKernel::setTileListVirialEnergyLength(), ComputeMsmMgr::setup_hgrid_1d(), ComputeMsmMgr::setup_periodic_blocksize(), SimParameters::setupIDWS(), PatchMap::sizeGrid(), ComputeMsmMgr::splitting(), ComputeMsmMgr::stencil_1d(), NamdCentLB::Strategy(), StringList::StringList(), ScriptTcl::tclmain(), TestArray_write(), TholeElem::TholeElem(), Node::updateGridScale(), ReductionMgr::willRequire(), and ReductionMgr::willSubmit().

84 {
85  if ( ! err_msg ) err_msg = "(unknown error)";
86  CkPrintf("FATAL ERROR: %s\n", err_msg);
87  fflush(stdout);
88  char repstr[24] = "";
89  if (CmiNumPartitions() > 1) {
90  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
91  }
92  CkError("%sFATAL ERROR: %s\n", repstr, err_msg);
93 #if CHARM_VERSION < 61000
94  CkExit();
95 #else
96  CkExit(1);
97 #endif
98 }
void NAMD_err ( const char *  err_msg)

Definition at line 102 of file common.C.

Referenced by after_backend_init(), ComputeQMMgr::calcMOPAC(), ComputeQMMgr::calcORCA(), ComputeQMMgr::calcUSR(), close_dcd_write(), colvarproxy_namd::error(), NAMD_close(), NAMD_open(), NAMD_open_text(), NAMD_seek(), NAMD_write(), Controller::outputExtendedSystem(), PDB::PDB(), ComputeQMMgr::recvPartQM(), Output::recvReplicaDcdData(), and PDB::write().

103 {
104  if ( ! err_msg ) err_msg = "(unknown error)";
105  const char *sys_err_msg = strerror(errno);
106  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
107  CkPrintf("FATAL ERROR: %s: %s\n", err_msg, sys_err_msg);
108  fflush(stdout);
109  char repstr[24] = "";
110  if (CmiNumPartitions() > 1) {
111  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
112  }
113  CkError("%sFATAL ERROR: %s: %s\n", repstr, err_msg, sys_err_msg);
114 #if CHARM_VERSION < 61000
115  CkExit();
116 #else
117  CkExit(1);
118 #endif
119 }
int NAMD_file_exists ( const char *  filename)

Definition at line 143 of file common.C.

References endi(), iERROR(), and iout.

Referenced by NAMD_backup_file().

143  {
144  int rval;
145  do {
146  rval = access(filename, F_OK);
147  } while ( rval != 0 && errno == EINTR );
148  if ( rval != 0 && errno != ENOENT ) {
149  const char *sys_err_msg = strerror(errno);
150  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
151  iout << iERROR << "Error on checking file "
152  << filename << ": " << sys_err_msg << "\n" << endi;
153  fflush(stdout);
154  }
155  return ! rval;
156 }
#define iout
Definition: InfoStream.h:87
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:109
infostream & endi(infostream &s)
Definition: InfoStream.C:38
int NAMD_open_text ( const char *  fname,
int  append 
)

Definition at line 194 of file common.C.

References NAMD_err().

Referenced by ofstream_namd::open().

194  {
195  int fd;
196 
197  // open the file and die if the open fails
198 #ifdef WIN32
199  while ( (fd = _open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT|O_TEXT,_S_IREAD|_S_IWRITE)) < 0) {
200 #else
201 #ifdef NAMD_NO_O_EXCL
202  while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_TRUNC)|O_CREAT,
203 #else
204  while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT,
205 #endif
206  S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
207 #endif
208  if ( errno != EINTR ) {
209  char errmsg[1024];
210  sprintf(errmsg, "Unable to open text file %s", fname);
211  NAMD_err(errmsg);
212  }
213  }
214 
215  return fd;
216 }
void NAMD_err(const char *err_msg)
Definition: common.C:102
void NAMD_quit ( const char *  err_msg)

Definition at line 64 of file common.C.

Referenced by GlobalMasterIMD::get_vmd_forces().

65 {
66  if ( ! err_msg ) err_msg = "(unknown error)";
67  CkPrintf("EXITING: %s\n", err_msg);
68  fflush(stdout);
69  char repstr[24] = "";
70  if (CmiNumPartitions() > 1) {
71  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
72  }
73  CkError("%sEXITING: %s\n", repstr, err_msg);
74 #if CHARM_VERSION < 61000
75  CkExit();
76 #else
77  CkExit(0);
78 #endif
79 }
char* NAMD_stringdup ( const char *  s)

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 50 of file common.C.

50  {
51  char *rs;
52 
53  if(!s)
54  return NULL;
55 
56  rs = new char[strlen(s) + 1];
57  strcpy(rs,s);
58 
59  return rs;
60 }
void NAMD_write ( int  fd,
const char *  buf,
size_t  count,
const char *  fname 
)

Definition at line 219 of file common.C.

219  {
220  while ( count ) {
221 #if defined(WIN32) && !defined(__CYGWIN__)
222  long retval = _write(fd,buf,count);
223 #else
224  ssize_t retval = write(fd,buf,count);
225 #endif
226  if ( retval < 0 && errno == EINTR ) retval = 0;
227  if ( retval < 0 ) {
228  char errmsg[1024];
229  sprintf(errmsg, "Error on writing to file %s", fname);
230  NAMD_err(errmsg);
231  }
232  if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
233  buf += retval;
234  count -= retval;
235  }
236 }
void NAMD_err(const char *err_msg)
Definition: common.C:102
void NAMD_bug(const char *err_msg)
Definition: common.C:123