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 363 of file common.C.

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

00364 {
00365   int rc = -1;
00366 #if !defined(NOCOMPRESSED)
00367   rc = pclose(fout);
00368 #endif
00369   if (rc == -1) // stream not associated with a popen()
00370     {
00371     rc = fclose(fout);
00372     }
00373   return rc;
00374 } /* Fclose() */

FILE* Fopen ( const char *  filename,
const char *  mode 
)

Definition at line 269 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().

00270 {
00271   struct stat buf;
00272   // check if basic filename exists (and not a directory)
00273 
00274 #if defined(NOCOMPRESSED)
00275   if (!stat(filename,&buf))
00276     {
00277       FILE *rval;
00278       while ( ! (rval = fopen(filename,mode)) ) {
00279         if ( errno != EINTR ) break;
00280       }
00281       return(rval);
00282     }
00283 #else
00284   if (!stat(filename,&buf))
00285     {
00286       if (!S_ISDIR(buf.st_mode)) {
00287         FILE *rval;
00288         while ( ! (rval = fopen(filename,mode)) ) {
00289           if ( errno != EINTR ) break;
00290         }
00291         return(rval);
00292       }
00293     }
00294   // check for a compressed file
00295   char *realfilename;
00296   char *command;
00297   FILE *fout;
00298   command = (char *)malloc(strlen(filename)+25);
00299   // check for .Z (unix compress)
00300   sprintf(command,"zcat %s.Z",filename);
00301   realfilename = command+5;
00302   iout << "Command = " << command << "\n" << endi;
00303   iout << "Filename.Z = " << realfilename << "\n" << endi;
00304   if (!stat(realfilename,&buf))
00305         {
00306         if (!S_ISDIR(buf.st_mode))
00307                 {
00308                 fout = popen(command,mode);
00309                 // on HP-UX, the first character(s) out of pipe may be
00310                 // garbage!  (Argh!)
00311                 int C;
00312                 do
00313                   {
00314                   C = fgetc(fout);
00315                   // iout << "C is " << C << "\n" << endi;
00316                   if (isalnum(C) || isspace(C))
00317                         {
00318                         ungetc(C,fout);
00319                         C = -1; // outta loop
00320                         }
00321                   } while(C != -1);
00322                 free(command);
00323                 return(fout);
00324                 }
00325         }
00326   // check for .gz (gzip)
00327   sprintf(command,"gzip -d -c %s.gz",filename);
00328   realfilename = command+11;
00329   iout << "Command = " << command << "\n" << endi;
00330   iout << "Filename.gz = " << realfilename << "\n" << endi;
00331   if (!stat(realfilename,&buf))
00332         {
00333         if (!S_ISDIR(buf.st_mode))
00334                 {
00335                 fout = popen(command,mode);
00336                 // on HP-UX, the first character(s) out of pipe may be
00337                 // garbage!  (Argh!)
00338                 int C;
00339                 do
00340                   {
00341                   C = fgetc(fout);
00342                   // iout << "C is " << C << "\n" << endi;
00343                   if (isalnum(C) || isspace(C))
00344                         {
00345                         ungetc(C,fout);
00346                         C = -1; // outta loop
00347                         }
00348                   } while(C != -1);
00349                 free(command);
00350                 return(fout);
00351                 }
00352         }
00353   free(command);
00354 #endif /* !defined(NOCOMPRESSED) */
00355 
00356   return(NULL);
00357 } /* Fopen() */

void NAMD_backup_file ( const char *  filename,
const char *  extension 
)

Definition at line 163 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().

00164 {
00165   if (NAMD_file_exists(filename)) {
00166     if ( ! extension ) extension = ".BAK";
00167     char *backup = new char[strlen(filename)+strlen(extension)+1];
00168     strcpy(backup, filename);
00169     strcat(backup, extension);
00170 #if defined(WIN32) && !defined(__CYGWIN__)
00171     if ( remove(backup) ) if ( errno != ENOENT ) {
00172       char *sys_err_msg = strerror(errno);
00173       if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00174       iout << iERROR << "Error on removing file "
00175         << backup << ": " << sys_err_msg << "\n" << endi;
00176       fflush(stdout);
00177     }
00178 #endif
00179     while ( rename(filename,backup) )
00180     {
00181       if ( errno == EINTR ) continue;
00182       const char *sys_err_msg = strerror(errno);
00183       if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00184       iout << iERROR << "Error on renaming file " << filename
00185         << " to " << backup << ": " << sys_err_msg << "\n" << endi;
00186       fflush(stdout);
00187       if ( errno == EXDEV ) continue;
00188       break;
00189       // char errmsg[256];
00190       // sprintf(errmsg, "Error on renaming file %s to %s",filename,backup);
00191       // NAMD_err(errmsg);
00192     }
00193     delete [] backup;
00194   }
00195 }

void NAMD_bug ( const char *  err_msg  ) 

Definition at line 126 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(), CudaComputeNonbonded::doWork(), ComputePme::doWork(), ComputeNonbondedCUDA::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(), ParallelIOMgr::initialize(), LdbCoordinator::initialize(), ComputePmeCUDA::initialize(), ComputePme::initialize(), ComputePmeMgr::initialize(), ComputePatch::initialize(), ComputeHomePatch::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(), PmePencilXYMap::populateInitial(), PmePencilXMap::populateInitial(), PmePencilXYZMap::populateInitial(), PmePencilMap::populateInitial(), Controller::printEnergies(), Rebalancer::printLoads(), PmePencilXYMap::procNum(), PmePencilXMap::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(), ProxyMgr::recvResults(), ComputeGlobal::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(), PmePencilZ::submitReductions(), PmePencilXYZ::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().

00127 {
00128   if ( ! err_msg ) err_msg = "(unknown error)";
00129   const char *bug_msg = 
00130     "FATAL ERROR: See http://www.ks.uiuc.edu/Research/namd/bugreport.html";
00131   CkPrintf("FATAL ERROR: %s\n%s\n",err_msg, bug_msg);
00132   fflush(stdout);
00133   char repstr[24] = "";
00134   if (CmiNumPartitions() > 1) {
00135     sprintf(repstr,"REPLICA %d ", CmiMyPartition());
00136   }
00137   char msgbuf[256];
00138   sprintf(msgbuf,"%sFATAL ERROR: %136s\n%80s\n", repstr, err_msg, bug_msg);
00139 #if CHARM_VERSION >= 61000
00140   CkAbort("%s", msgbuf);
00141 #else
00142   CkAbort(msgbuf);
00143 #endif
00144 }

void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 243 of file common.C.

00243                                            {
00244 #ifdef WIN32
00245   while ( _close(fd) ) {
00246 #else
00247   while ( close(fd) ) {
00248 #endif
00249     if ( errno != EINTR ) {
00250       char errmsg[1024];
00251       sprintf(errmsg, "Error on closing file %s", fname);
00252       NAMD_err(errmsg);
00253     }
00254   }
00255 }

void NAMD_die ( const char *  err_msg  ) 

Definition at line 84 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(), ComputeNonbondedSelf::doForce(), ComputeGridForce::doForce(), HomePatch::doMarginCheck(), Parameters::done_reading_files(), ComputeTclBC::doWork(), ComputeFullDirect::doWork(), Node::earlyExit(), ARestraint::EarlyExit(), GlobalMasterMisc::easy_calc(), msm::Grid< BlockDiagram >::elem(), msm::GridFixed< T, N >::elem(), msm::Array< BlockDiagram >::elem(), ScriptTcl::eval(), colvarproxy_namd::fatal_error(), PmeXPencil::fft_init(), PmeYPencil::fft_init(), PmeZPencil::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(), TholeElem::getMoleculePointers(), ExclElem::getMoleculePointers(), ImproperElem::getMoleculePointers(), GromacsPairElem::getMoleculePointers(), DihedralElem::getMoleculePointers(), CrosstermElem::getMoleculePointers(), BondElem::getMoleculePointers(), AnisoElem::getMoleculePointers(), AngleElem::getMoleculePointers(), CudaComputeNonbondedKernel::getPatchReadyQueue(), TholeElem::getTupleInfo(), AnisoElem::getTupleInfo(), GlobalMasterIMD::GlobalMasterIMD(), GlobalMasterSymmetry::GlobalMasterSymmetry(), GromacsTopFile::GromacsTopFile(), BackEnd::init(), LdbCoordinator::initialize(), GridforceLiteGrid::initialize(), GridforceFullSubGrid::initialize(), GridforceFullMainGrid::initialize(), DeviceCUDA::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(), GlobalMaster::processData(), MsmC1HermiteBlockProxyMsg::put(), MsmBlockProxyMsg::put(), HomePatch::rattle1old(), HomePatch::rattle2(), 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(), HomePatch::recvCheckpointReq(), Controller::recvCheckpointReq(), ComputeMgr::recvComputeDPMEData(), ComputeMgr::recvComputeDPMEResults(), ComputeMgr::recvComputeEwaldData(), ComputeMgr::recvComputeEwaldResults(), ComputeMgr::recvComputeGlobalData(), ComputeMgr::recvComputeGlobalResults(), ComputeMsmSerialMgr::recvCoord(), ComputeFmmSerialMgr::recvCoord(), ComputeExtMgr::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().

00085 {
00086   if ( ! err_msg ) err_msg = "(unknown error)";
00087   CkPrintf("FATAL ERROR: %s\n", err_msg);
00088   fflush(stdout);
00089   char repstr[24] = "";
00090   if (CmiNumPartitions() > 1) {
00091     sprintf(repstr,"REPLICA %d ", CmiMyPartition());
00092   }
00093   char msgbuf[256];
00094   sprintf(msgbuf,"%sFATAL ERROR: %216s\n", repstr, err_msg);
00095 #if CHARM_VERSION >= 61000
00096   CkAbort("%s", msgbuf);
00097 #else
00098   CkAbort(msgbuf);
00099 #endif
00100 }

void NAMD_err ( const char *  err_msg  ) 

Definition at line 104 of file common.C.

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

00105 {
00106   if ( ! err_msg ) err_msg = "(unknown error)";
00107   const char *sys_err_msg = strerror(errno);
00108   if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00109   CkPrintf("FATAL ERROR: %s: %s\n", err_msg, sys_err_msg);
00110   fflush(stdout);
00111   char repstr[24] = "";
00112   if (CmiNumPartitions() > 1) {
00113     sprintf(repstr,"REPLICA %d ", CmiMyPartition());
00114   }
00115   char msgbuf[256];
00116   sprintf(msgbuf,"%sFATAL ERROR: %136s: %80s\n", repstr, err_msg, sys_err_msg);
00117 #if CHARM_VERSION >= 61000
00118   CkAbort("%s", msgbuf);
00119 #else
00120   CkAbort(msgbuf);
00121 #endif
00122 }

int NAMD_file_exists ( const char *  filename  ) 

Definition at line 147 of file common.C.

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

Referenced by NAMD_backup_file().

00147                                            {
00148   int rval;
00149   do {
00150     rval = access(filename, F_OK);
00151   } while ( rval != 0 && errno == EINTR );
00152   if ( rval != 0 && errno != ENOENT ) {
00153     const char *sys_err_msg = strerror(errno);
00154     if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00155     iout << iERROR << "Error on checking file "
00156       << filename << ": " << sys_err_msg << "\n" << endi;
00157     fflush(stdout);
00158   }
00159   return ! rval;
00160 }

int NAMD_open_text ( const char *  fname,
int  append 
)

Definition at line 198 of file common.C.

References NAMD_err().

Referenced by ofstream_namd::open().

00198                                                   {
00199   int fd;
00200 
00201   //  open the file and die if the open fails
00202 #ifdef WIN32
00203   while ( (fd = _open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT|O_TEXT,_S_IREAD|_S_IWRITE)) < 0) {
00204 #else
00205 #ifdef NAMD_NO_O_EXCL
00206   while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_TRUNC)|O_CREAT,
00207 #else
00208   while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT,
00209 #endif
00210                            S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
00211 #endif
00212     if ( errno != EINTR ) {
00213       char errmsg[1024];
00214       sprintf(errmsg, "Unable to open text file %s", fname);
00215       NAMD_err(errmsg);
00216     }
00217   }
00218 
00219   return fd;
00220 }

void NAMD_quit ( const char *  err_msg  ) 

Definition at line 64 of file common.C.

Referenced by GlobalMasterIMD::get_vmd_forces().

00065 {
00066   if ( ! err_msg ) err_msg = "(unknown error)";
00067   CkPrintf("EXITING: %s\n", err_msg);
00068   fflush(stdout);
00069   char repstr[24] = "";
00070   if (CmiNumPartitions() > 1) {
00071     sprintf(repstr,"REPLICA %d ", CmiMyPartition());
00072   }
00073   char msgbuf[256];
00074   sprintf(msgbuf,"%sEXITING: %216s\n", repstr, err_msg);
00075 #if CHARM_VERSION >= 61000
00076   CkAbort("%s", msgbuf);
00077 #else
00078   CkAbort(msgbuf);
00079 #endif
00080 }

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.

00050                                     {
00051   char *rs;
00052 
00053   if(!s)
00054     return NULL;
00055 
00056   rs = new char[strlen(s) + 1];
00057   strcpy(rs,s);
00058 
00059   return rs;
00060 }

void NAMD_write ( int  fd,
const char *  buf,
size_t  count,
const char *  fname 
)

Definition at line 223 of file common.C.

00223                                                                           {
00224   while ( count ) {
00225 #if defined(WIN32) && !defined(__CYGWIN__)
00226     long retval = _write(fd,buf,count);
00227 #else
00228     ssize_t retval = write(fd,buf,count);
00229 #endif
00230     if ( retval < 0 && errno == EINTR ) retval = 0;
00231     if ( retval < 0 ) {
00232       char errmsg[1024];
00233       sprintf(errmsg, "Error on writing to file %s", fname);
00234       NAMD_err(errmsg);
00235     }
00236     if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
00237     buf += retval;
00238     count -= retval;
00239   }
00240 }


Generated on 19 Jan 2020 for NAMD by  doxygen 1.6.1