NAMD
Macros | Typedefs | Functions
common.h File Reference
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include "converse.h"

Go to the source code of this file.

Macros

#define NAMD_FILENAME_BUFFER_SIZE   4096
 
#define COULOMB   332.0636
 
#define BOLTZMANN   0.001987191
 
#define TIMEFACTOR   48.88821
 
#define PRESSUREFACTOR   6.95E4
 
#define PDBVELFACTOR   20.45482706
 
#define PDBVELINVFACTOR   (1.0/PDBVELFACTOR)
 
#define PNPERKCALMOL   69.479
 
#define namdnearbyint(x)   floor((x)+0.5)
 
#define PI   3.141592653589793
 
#define TWOPI   2.0 * PI
 
#define ONE   1.000000000000000
 
#define ZERO   0.000000000000000
 
#define SMALLRAD   0.0005
 
#define SMALLRAD2   SMALLRAD*SMALLRAD
 
#define FALSE   0
 
#define TRUE   1
 
#define NO   0
 
#define YES   1
 
#define STRINGNULL   '\0'
 
#define MAX_NEIGHBORS   27
 
#define SIMPARAMSTAG   100
 
#define STATICPARAMSTAG   101
 
#define MOLECULETAG   102
 
#define FULLTAG   104
 
#define FULLFORCETAG   105
 
#define DPMTATAG   106
 
#define GRIDFORCEGRIDTAG   107
 
#define COMPUTEMAPTAG   108
 
#define CYCLE_BARRIER   0
 
#define PME_BARRIER   0
 
#define STEP_BARRIER   0
 
#define USE_BARRIER   (CYCLE_BARRIER || PME_BARRIER || STEP_BARRIER)
 
#define NAMD_SeparateWaters   0
 
#define NAMD_ComputeNonbonded_SortAtoms   1
 
#define NAMD_ComputeNonbonded_SortAtoms_LessBranches   1
 
#define WAT_TIP3   0
 
#define WAT_TIP4   1
 
#define WAT_SWM4   2 /* Drude model (5 charge sites) */
 

Typedefs

typedef long long int64
 
typedef float Real
 
typedef double BigReal
 
typedef int Bool
 

Functions

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

Macro Definition Documentation

#define BOLTZMANN   0.001987191
#define COMPUTEMAPTAG   108

Definition at line 159 of file common.h.

Referenced by WorkDistrib::recvComputeMapChanges(), and WorkDistrib::sendComputeMap().

#define COULOMB   332.0636
#define CYCLE_BARRIER   0

Definition at line 161 of file common.h.

#define DPMTATAG   106

Definition at line 157 of file common.h.

#define FALSE   0
#define FULLFORCETAG   105

Definition at line 156 of file common.h.

Referenced by ComputeFullDirect::doWork().

#define FULLTAG   104

Definition at line 155 of file common.h.

Referenced by ComputeFullDirect::doWork().

#define GRIDFORCEGRIDTAG   107

Definition at line 158 of file common.h.

Referenced by Node::reloadGridforceGrid().

#define MAX_NEIGHBORS   27

Definition at line 131 of file common.h.

#define MOLECULETAG   102

Definition at line 154 of file common.h.

Referenced by Node::resendMolecule().

#define NAMD_ComputeNonbonded_SortAtoms   1

Definition at line 186 of file common.h.

#define NAMD_ComputeNonbonded_SortAtoms_LessBranches   1

Definition at line 187 of file common.h.

#define NAMD_FILENAME_BUFFER_SIZE   4096
#define NAMD_SeparateWaters   0

Definition at line 173 of file common.h.

#define namdnearbyint (   x)    floor((x)+0.5)
#define NO   0

Definition at line 123 of file common.h.

#define ONE   1.000000000000000

Definition at line 91 of file common.h.

#define PDBVELFACTOR   20.45482706

Definition at line 50 of file common.h.

Referenced by ParallelIOMgr::bcastMolInfo(), and Sequencer::maximumMove().

#define PDBVELINVFACTOR   (1.0/PDBVELFACTOR)

Definition at line 51 of file common.h.

#define PI   3.141592653589793
#define PME_BARRIER   0

Definition at line 162 of file common.h.

#define PNPERKCALMOL   69.479

Definition at line 52 of file common.h.

#define PRESSUREFACTOR   6.95E4
#define SIMPARAMSTAG   100

Definition at line 152 of file common.h.

#define SMALLRAD   0.0005

Definition at line 99 of file common.h.

#define SMALLRAD2   SMALLRAD*SMALLRAD

Definition at line 103 of file common.h.

#define STATICPARAMSTAG   101

Definition at line 153 of file common.h.

Referenced by Node::resendMolecule().

#define STEP_BARRIER   0

Definition at line 163 of file common.h.

#define STRINGNULL   '\0'
#define TIMEFACTOR   48.88821
#define TRUE   1
#define TWOPI   2.0 * PI
#define USE_BARRIER   (CYCLE_BARRIER || PME_BARRIER || STEP_BARRIER)

Definition at line 165 of file common.h.

#define WAT_SWM4   2 /* Drude model (5 charge sites) */
#define WAT_TIP3   0

Definition at line 190 of file common.h.

Referenced by HomePatch::rattle1().

#define WAT_TIP4   1
#define YES   1

Definition at line 124 of file common.h.

#define ZERO   0.000000000000000

Definition at line 95 of file common.h.

Referenced by ComputeNonbondedUtil::calcGBIS().

Typedef Documentation

typedef double BigReal

Definition at line 114 of file common.h.

typedef int Bool

Definition at line 133 of file common.h.

typedef long long int64

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

Definition at line 34 of file common.h.

typedef float Real

Definition at line 109 of file common.h.

Function Documentation

int Fclose ( FILE *  fout)

Definition at line 367 of file common.C.

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

368 {
369  int rc = -1;
370 #if !defined(NOCOMPRESSED)
371  rc = pclose(fout);
372 #endif
373  if (rc == -1) // stream not associated with a popen()
374  {
375  rc = fclose(fout);
376  }
377  return rc;
378 } /* Fclose() */
FILE* Fopen ( const char *  filename,
const char *  mode 
)

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

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

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

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

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

130 {
131  if ( ! err_msg ) err_msg = "(unknown error)";
132  const char *bug_msg =
133  "FATAL ERROR: See http://www.ks.uiuc.edu/Research/namd/bugreport.html";
134  CkPrintf("FATAL ERROR: %s\n%s\n",err_msg, bug_msg);
135  fflush(stdout);
136  char repstr[24] = "";
137  if (CmiNumPartitions() > 1) {
138  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
139  // CkAbort ensures that all replicas die
140  CkAbort("%sFATAL ERROR: %s\n%s\n", repstr, err_msg, bug_msg);
141  }
142  CkError("%sFATAL ERROR: %s\n%s\n", repstr, err_msg, bug_msg);
143 #if CHARM_VERSION < 61000
144  CkExit();
145 #else
146  CkExit(2);
147 #endif
148 }
void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 247 of file common.C.

References NAMD_err().

247  {
248 #ifdef WIN32
249  while ( _close(fd) ) {
250 #else
251  while ( close(fd) ) {
252 #endif
253  if ( errno != EINTR ) {
254  char errmsg[1024];
255  sprintf(errmsg, "Error on closing file %s", fname);
256  NAMD_err(errmsg);
257  }
258  }
259 }
void NAMD_err(const char *err_msg)
Definition: common.C:106
void NAMD_die ( const char *  )

Definition at line 85 of file common.C.

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

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

107 {
108  if ( ! err_msg ) err_msg = "(unknown error)";
109  const char *sys_err_msg = strerror(errno);
110  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
111  CkPrintf("FATAL ERROR: %s: %s\n", err_msg, sys_err_msg);
112  fflush(stdout);
113  char repstr[24] = "";
114  if (CmiNumPartitions() > 1) {
115  sprintf(repstr,"REPLICA %d ", CmiMyPartition());
116  // CkAbort ensures that all replicas die
117  CkAbort("%sFATAL ERROR: %s: %s\n", repstr, err_msg, sys_err_msg);
118  }
119  CkError("%sFATAL ERROR: %s: %s\n", repstr, err_msg, sys_err_msg);
120 #if CHARM_VERSION < 61000
121  CkExit();
122 #else
123  CkExit(1);
124 #endif
125 }
int NAMD_file_exists ( const char *  filename)

Definition at line 151 of file common.C.

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

Referenced by NAMD_backup_file().

151  {
152  int rval;
153  do {
154  rval = access(filename, F_OK);
155  } while ( rval != 0 && errno == EINTR );
156  if ( rval != 0 && errno != ENOENT ) {
157  const char *sys_err_msg = strerror(errno);
158  if ( ! sys_err_msg ) sys_err_msg = "(unknown error)";
159  iout << iERROR << "Error on checking file "
160  << filename << ": " << sys_err_msg << "\n" << endi;
161  fflush(stdout);
162  }
163  return ! rval;
164 }
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
#define iout
Definition: InfoStream.h:51
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
int NAMD_open_text ( const char *  fname,
int  append = 0 
)

Definition at line 202 of file common.C.

References NAMD_err().

Referenced by ofstream_namd::open().

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

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  // CkAbort ensures that all replicas die
73  CkAbort("%sEXITING: %s\n", repstr, err_msg);
74  }
75  CkError("%sEXITING: %s\n", repstr, err_msg);
76 #if CHARM_VERSION < 61000
77  CkExit();
78 #else
79  CkExit(0);
80 #endif
81 }
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 = "in NAMD_write()" 
)

Definition at line 227 of file common.C.

References endi(), iout, iWARN(), NAMD_bug(), and NAMD_err().

227  {
228  while ( count ) {
229 #if defined(WIN32) && !defined(__CYGWIN__)
230  long retval = _write(fd,buf,count);
231 #else
232  ssize_t retval = write(fd,buf,count);
233 #endif
234  if ( retval < 0 && errno == EINTR ) retval = 0;
235  if ( retval < 0 ) {
236  char errmsg[1024];
237  sprintf(errmsg, "Error on writing to file %s", fname);
238  NAMD_err(errmsg);
239  }
240  if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write()");
241  buf += retval;
242  count -= retval;
243  }
244 }
void NAMD_err(const char *err_msg)
Definition: common.C:106
void NAMD_bug(const char *err_msg)
Definition: common.C:129