mainfunc.C File Reference

#include "memusage.h"
#include "converse.h"
#include "common.h"
#include "BackEnd.h"
#include "InfoStream.h"
#include "Broadcasts.h"
#include "NamdState.h"
#include "Node.h"
#include <unistd.h>
#include <sys/stat.h>
#include "ConfigList.h"
#include "ScriptTcl.h"

Go to the source code of this file.

Defines

#define CHDIR   chdir
#define GETCWD   getcwd
#define PATHSEP   '/'
#define PATHSEPSTR   "/"
#define CWDSIZE   1024

Functions

void after_backend_init (int argc, char **argv)
int main (int argc, char **argv)

Define Documentation

#define CHDIR   chdir

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

Definition at line 24 of file mainfunc.C.

Referenced by after_backend_init().

#define CWDSIZE   1024

Referenced by after_backend_init().

#define GETCWD   getcwd

Definition at line 25 of file mainfunc.C.

Referenced by after_backend_init().

#define PATHSEP   '/'

Definition at line 26 of file mainfunc.C.

Referenced by after_backend_init().

#define PATHSEPSTR   "/"

Definition at line 27 of file mainfunc.C.

Referenced by after_backend_init().


Function Documentation

void after_backend_init ( int  argc,
char **  argv 
)

Definition at line 54 of file mainfunc.C.

References CHDIR, CWDSIZE, endi(), ScriptTcl::eval(), BackEnd::exit(), GETCWD, iINFO(), iout, j, ScriptTcl::load(), NAMD_die(), NAMD_err(), Node::Object(), PATHSEP, PATHSEPSTR, ScriptTcl::run(), Node::setScript(), and ScriptTcl::tclmain().

Referenced by main(), and slave_init().

00054                                               {
00055 #define CWDSIZE 1024
00056   char origcwd_buf[CWDSIZE];
00057   char currentdir_buf[CWDSIZE];
00058 
00059   ScriptTcl *script = new ScriptTcl;
00060   Node::Object()->setScript(script);
00061 
00062   for(argc = 0; argv[argc]; ++argc);
00063   if ( argc < 2 ) {
00064 #if defined(WIN32) && !defined(__CYGWIN__)
00065     CkPrintf("\nFATAL ERROR: No simulation config file specified on command line.\n");
00066     CkPrintf("\nNOTE: NAMD has no graphical interface and must be run from a command line.\n");
00067     int nsleep = 10;
00068     CkPrintf("\nSleeping %d seconds before exiting...\n", nsleep);
00069     fflush(stdout);
00070     sleep(nsleep);
00071     CkPrintf("\n");
00072 #endif
00073     NAMD_die("No simulation config file specified on command line.");
00074   }
00075   char *origcwd = GETCWD(origcwd_buf,CWDSIZE);
00076   if ( ! origcwd ) NAMD_err("getcwd");
00077 #ifdef NAMD_TCL
00078   for(int i = 1; i < argc; ++i) {
00079   if ( strstr(argv[i],"--") == argv[i] ) {
00080     char buf[1024];
00081     if ( i + 1 == argc ) {
00082       sprintf(buf, "missing argument for command line option %s", argv[i]);
00083       NAMD_die(buf);
00084     }
00085     if ( ! strcmp(argv[i],"--tclmain") ) {
00086       // pass all remaining arguments to script
00087       iout << iINFO << "Command-line argument is";
00088       for ( int j=i; j<argc; ++j ) { iout << " " << argv[j]; }
00089       iout << "\n" << endi;
00090       script->tclmain(argc-i-1,argv+i+1);
00091       BackEnd::exit();
00092       return;
00093     }
00094     sprintf(buf, "%s %s", argv[i]+2, argv[i+1]);
00095     iout << iINFO << "Command-line argument is --" << buf << "\n" << endi;
00096     script->eval(buf);
00097     ++i;
00098     continue;
00099   }
00100   char *confFile = argv[i];
00101 #else
00102   char *confFile = argv[argc-1];
00103 #endif
00104   iout << iINFO << "Configuration file is " << confFile << "\n" << endi;
00105 
00106   char *currentdir=confFile;
00107   char *tmp;
00108   char tmpcurdir[3];
00109   for(tmp=confFile;*tmp;++tmp); // find final null
00110   for( ; tmp != confFile && *tmp != PATHSEP; --tmp); // find last '/'
00111 #if defined(WIN32) && !defined(__CYGWIN__)
00112   if (tmp == confFile) {
00113     // in case this is under cygwin, search for '/' as well
00114     for(tmp=confFile;*tmp;++tmp); // find final null
00115     for( ; tmp != confFile && *tmp != '/'; --tmp); // find last '/'
00116   }
00117 #endif
00118   if ( CHDIR(origcwd) ) NAMD_err(origcwd);
00119   if ( tmp != confFile )
00120   {
00121     *tmp = 0; confFile = tmp + 1;
00122     if ( CHDIR(currentdir) ) NAMD_err(currentdir);
00123     struct stat statBuf;
00124     if (stat(confFile, &statBuf)) {
00125       char buf[1024];
00126       sprintf(buf,"Unable to access config file %s%c%s",currentdir,PATHSEP,confFile);
00127       NAMD_die(buf);
00128     }
00129     iout << iINFO << "Changed directory to " << currentdir << "\n" << endi;
00130     currentdir = GETCWD(currentdir_buf,CWDSIZE);
00131     if ( ! currentdir ) NAMD_err("getcwd after chdir");
00132   }
00133   else{
00134       if ( *tmp == PATHSEP ){ // config file in / is odd, but it might happen
00135           if ( CHDIR(PATHSEPSTR) ) NAMD_err(PATHSEPSTR);
00136           struct stat statBuf;
00137           if (stat(confFile, &statBuf)) {
00138             char buf[1024];
00139             sprintf(buf,"Unable to access config file %s",confFile);
00140             NAMD_die(buf);
00141           }
00142       }else{ // just a config file name, so the path is the current working path
00143           struct stat statBuf;
00144           if (stat(confFile, &statBuf)) {
00145             char buf[1024];
00146             if ( confFile[0] == '-' || confFile[0] == '+' ) {
00147               sprintf(buf,"Unknown command-line option %s",confFile);
00148             } else {
00149               sprintf(buf,"Unable to access config file %s",confFile);
00150             }
00151             NAMD_die(buf);
00152           }
00153           tmpcurdir[0] = '.';
00154           tmpcurdir[1] = PATHSEP;
00155           tmpcurdir[2] = 0;
00156           currentdir = tmpcurdir;
00157           iout << iINFO << "Working in the current directory " << origcwd << "\n" << endi;
00158       }
00159   }
00160 
00161 #ifdef MEM_OPT_VERSION
00162     int dirlen = strlen(currentdir);
00163     gWorkDir = new char[dirlen+1];
00164     gWorkDir[dirlen]=0;
00165     memcpy(gWorkDir, currentdir, dirlen);
00166 #endif
00167 
00168   currentdir = NULL;
00169 
00170 #ifdef NAMD_TCL
00171   script->load(confFile);
00172 #else
00173   script->run(confFile);
00174 #endif
00175 
00176 #ifdef NAMD_TCL
00177 }
00178   script->run();
00179 #endif
00180 
00181   BackEnd::exit();
00182 }

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file mainfunc.C.

References after_backend_init(), BackEnd::init(), and ScriptTcl::tclsh().

00042                                 {
00043 #ifdef NAMD_TCL
00044   if ( argc > 2 && ! strcmp(argv[1],"+tclsh") ) {
00045     // pass all remaining arguments to script
00046     return ScriptTcl::tclsh(argc-2,argv+2);
00047   }
00048 #endif
00049   BackEnd::init(argc,argv);
00050   after_backend_init(argc, argv);
00051   return 0;
00052 }


Generated on 5 Jun 2020 for NAMD by  doxygen 1.6.1