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

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

00351 {
00352   int rc = -1;
00353 #if !defined(NOCOMPRESSED)
00354   rc = pclose(fout);
00355 #endif
00356   if (rc == -1) // stream not associated with a popen()
00357     {
00358     rc = fclose(fout);
00359     }
00360   return rc;
00361 } /* Fclose() */

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

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

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

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

Definition at line 150 of file common.C.

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

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

00151 {
00152   if (NAMD_file_exists(filename)) {
00153     if ( ! extension ) extension = ".BAK";
00154     char *backup = new char[strlen(filename)+strlen(extension)+1];
00155     strcpy(backup, filename);
00156     strcat(backup, extension);
00157 #if defined(WIN32) && !defined(__CYGWIN__)
00158     if ( remove(backup) ) if ( errno != ENOENT ) {
00159       char *sys_err_msg = strerror(errno);
00160       if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00161       iout << iERROR << "Error on removing file "
00162         << backup << ": " << sys_err_msg << "\n" << endi;
00163       fflush(stdout);
00164     }
00165 #endif
00166     while ( rename(filename,backup) )
00167     {
00168       if ( errno == EINTR ) continue;
00169       char *sys_err_msg = strerror(errno);
00170       if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00171       iout << iERROR << "Error on renaming file " << filename
00172         << " to " << backup << ": " << sys_err_msg << "\n" << endi;
00173       fflush(stdout);
00174       if ( errno == EXDEV ) continue;
00175       break;
00176       // char errmsg[256];
00177       // sprintf(errmsg, "Error on renaming file %s to %s",filename,backup);
00178       // NAMD_err(errmsg);
00179     }
00180     delete [] backup;
00181   }
00182 }

void NAMD_bug ( const char *  err_msg  ) 

Definition at line 117 of file common.C.

Referenced by Sequencer::algorithm(), Controller::algorithm(), 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_pme_charges(), cuda_check_pme_forces(), cuda_check_remote_progress(), cudaNAMD_bug(), CudaPmeRealSpaceCompute::CudaPmeRealSpaceCompute(), MigrateAtomsCombinedMsg::distribute(), ComputeGridForce::doForce(), HomePatch::doGroupSizeCheck(), CudaComputeNonbonded::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(), 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(), 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(), OptPmeMgr::recvUngrid(), 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(), CollectionMgr::CollectVectorInstance::reset(), CollectionMaster::CollectVectorInstance::reset(), WorkDistrib::saveComputeMap(), ComputeGlobal::saveTotalForces(), Sequencer::scalePositionsVelocities(), ComputeNonbondedUtil::select(), SELF(), 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(), ComputeMgr::updateComputes(), Node::updateGridScale(), WorkDistrib::WorkDistrib(), AtomMapper::~AtomMapper(), and Rebalancer::~Rebalancer().

00119 {
00120    if ( ! err_msg ) err_msg = "(unknown error)";
00121    const char *bug_msg = 
00122      "FATAL ERROR: See http://www.ks.uiuc.edu/Research/namd/bugreport.html";
00123    char *new_err_msg = new char[strlen(err_msg) + 40 + strlen(bug_msg)];
00124    sprintf(new_err_msg,"FATAL ERROR: %s\n%s\n",err_msg,bug_msg);
00125    CkPrintf(new_err_msg);
00126    fflush(stdout);
00127    if ( CmiNumPartitions() > 1 ) {
00128      sprintf(new_err_msg,"REPLICA %d FATAL ERROR: %s\n%s\n", CmiMyPartition(), err_msg,bug_msg);
00129    }
00130    CmiAbort(new_err_msg);
00131    delete [] new_err_msg;
00132 }

void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 230 of file common.C.

00230                                            {
00231 #ifdef WIN32
00232   while ( _close(fd) ) {
00233 #else
00234   while ( close(fd) ) {
00235 #endif
00236     if ( errno != EINTR ) {
00237       char errmsg[1024];
00238       sprintf(errmsg, "Error on closing file %s", fname);
00239       NAMD_err(errmsg);
00240     }
00241   }
00242 }

void NAMD_die ( const char *  err_msg  ) 

Definition at line 81 of file common.C.

Referenced by Controller::adaptTempInit(), ConfigList::add_element(), ComputeMsmMgr::addPotential(), after_backend_init(), ALCHPAIR(), 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(), ReductionMgr::buildSpanTree(), CudaTileListKernel::buildTileLists(), 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(), ComputeMgr::createComputes(), cuda_check_local_progress(), cuda_check_pme_charges(), cuda_check_pme_forces(), cuda_check_progress(), cuda_check_remote_progress(), 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(), ARestraint::EarlyExit(), GlobalMasterMisc::easy_calc(), msm::Grid< Vtype >::elem(), msm::GridFixed< T, N >::elem(), msm::Array< msm::PatchDiagram >::elem(), ScriptTcl::eval(), colvarproxy_namd::fatal_error(), OptPmeXPencil::fft_init(), OptPmeYPencil::fft_init(), OptPmeZPencil::fft_init(), 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(), OptPmeMgr::initialize(), 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(), PatchMap::sizeGrid(), ComputeMsmMgr::splitting(), ComputeMsmMgr::stencil_1d(), NamdCentLB::Strategy(), StringList::StringList(), ScriptTcl::tclmain(), TholeElem::TholeElem(), Node::updateGridScale(), ReductionMgr::willRequire(), and ReductionMgr::willSubmit().

00083 {
00084    if ( ! err_msg ) err_msg = "(unknown error)";
00085    char *new_err_msg = new char[strlen(err_msg) + 40];
00086    sprintf(new_err_msg,"FATAL ERROR: %s\n",err_msg);
00087    CkPrintf(new_err_msg);
00088    fflush(stdout);
00089    if ( CmiNumPartitions() > 1 ) {
00090      sprintf(new_err_msg,"REPLICA %d FATAL ERROR: %s\n", CmiMyPartition(), err_msg);
00091    }
00092    CmiAbort(new_err_msg);
00093    delete [] new_err_msg;
00094 }

void NAMD_err ( const char *  err_msg  ) 

Definition at line 98 of file common.C.

Referenced by after_backend_init(), 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().

00100 {
00101    if ( ! err_msg ) err_msg = "(unknown error)";
00102    char *sys_err_msg = strerror(errno);
00103    if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00104    char *new_err_msg = new char[strlen(err_msg) + 40 + strlen(sys_err_msg)];
00105    sprintf(new_err_msg,"FATAL ERROR: %s: %s\n",err_msg, sys_err_msg);
00106    CkPrintf(new_err_msg);
00107    fflush(stdout);
00108    if ( CmiNumPartitions() > 1 ) {
00109      sprintf(new_err_msg,"REPLICA %d FATAL ERROR: %s: %s\n", CmiMyPartition(), err_msg, sys_err_msg);
00110    }
00111    CmiAbort(new_err_msg);
00112    delete [] new_err_msg;
00113 }

int NAMD_file_exists ( const char *  filename  ) 

Definition at line 134 of file common.C.

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

Referenced by NAMD_backup_file().

00134                                            {
00135   int rval;
00136   do {
00137     rval = access(filename, F_OK);
00138   } while ( rval != 0 && errno == EINTR );
00139   if ( rval != 0 && errno != ENOENT ) {
00140     char *sys_err_msg = strerror(errno);
00141     if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
00142     iout << iERROR << "Error on checking file "
00143       << filename << ": " << sys_err_msg << "\n" << endi;
00144     fflush(stdout);
00145   }
00146   return ! rval;
00147 }

int NAMD_open_text ( const char *  fname,
int  append 
)

Definition at line 185 of file common.C.

References NAMD_err().

Referenced by ofstream_namd::open().

00185                                                   {
00186   int fd;
00187 
00188   //  open the file and die if the open fails
00189 #ifdef WIN32
00190   while ( (fd = _open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT|O_TEXT,_S_IREAD|_S_IWRITE)) < 0) {
00191 #else
00192 #ifdef NAMD_NO_O_EXCL
00193   while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_TRUNC)|O_CREAT,
00194 #else
00195   while ( (fd = open(fname, O_WRONLY|(append?O_APPEND:O_EXCL)|O_CREAT,
00196 #endif
00197                            S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
00198 #endif
00199     if ( errno != EINTR ) {
00200       char errmsg[1024];
00201       sprintf(errmsg, "Unable to open text file %s", fname);
00202       NAMD_err(errmsg);
00203     }
00204   }
00205 
00206   return fd;
00207 }

void NAMD_quit ( const char *  err_msg  ) 

Definition at line 64 of file common.C.

Referenced by Node::earlyExit(), and GlobalMasterIMD::get_vmd_forces().

00066 {
00067    if ( ! err_msg ) err_msg = "(unknown error)";
00068    char *new_err_msg = new char[strlen(err_msg) + 40];
00069    sprintf(new_err_msg,"EXITING: %s\n",err_msg);
00070    CkPrintf(new_err_msg);
00071    fflush(stdout);
00072    if ( CmiNumPartitions() > 1 ) {
00073      sprintf(new_err_msg,"REPLICA %d EXITING: %s\n", CmiMyPartition(), err_msg);
00074    }
00075    CmiAbort(new_err_msg);
00076    delete [] new_err_msg;
00077 }

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

00210                                                                           {
00211   while ( count ) {
00212 #if defined(WIN32) && !defined(__CYGWIN__)
00213     long retval = _write(fd,buf,count);
00214 #else
00215     ssize_t retval = write(fd,buf,count);
00216 #endif
00217     if ( retval < 0 && errno == EINTR ) retval = 0;
00218     if ( retval < 0 ) {
00219       char errmsg[1024];
00220       sprintf(errmsg, "Error on writing to file %s", fname);
00221       NAMD_err(errmsg);
00222     }
00223     if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
00224     buf += retval;
00225     count -= retval;
00226   }
00227 }


Generated on Tue Sep 26 01:17:15 2017 for NAMD by  doxygen 1.4.7