Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

mainfunc.C

Go to the documentation of this file.
00001 
00007 #include "memusage.h"
00008 #include "converse.h"
00009 #include "common.h"
00010 #include "BackEnd.h"
00011 #include "InfoStream.h"
00012 #include "Broadcasts.h"
00013 
00014 #include "NamdState.h"
00015 #include "Node.h"
00016 #if defined(WIN32) && !defined(__CYGWIN__)
00017 #include <direct.h>
00018 #define CHDIR _chdir
00019 #define GETCWD _getcwd
00020 #define PATHSEP '\\'
00021 #define PATHSEPSTR "\\"
00022 #else
00023 #include <unistd.h>
00024 #define CHDIR chdir
00025 #define GETCWD getcwd
00026 #define PATHSEP '/'
00027 #define PATHSEPSTR "/"
00028 #endif
00029 #include <sys/stat.h>
00030 #include "ConfigList.h"
00031 #include "ScriptTcl.h"
00032 
00033 
00034 void after_backend_init(int argc, char **argv);
00035 
00036 int main(int argc, char **argv) {
00037   BackEnd::init(argc,argv);
00038   after_backend_init(argc, argv);
00039   return 0;
00040 }
00041 
00042 void after_backend_init(int argc, char **argv){
00043   ScriptTcl *script = new ScriptTcl;
00044   Node::Object()->setScript(script);
00045 
00046   for(argc = 0; argv[argc]; ++argc);
00047   if ( argc < 2 ) {
00048     NAMD_die("No simulation config file specified on command line.");
00049   }
00050 #ifdef NAMD_TCL
00051   if (argc>2)
00052     iout << iINFO << "Found " << (argc-1) << " config files.\n" << endi;
00053   for(int i = 1; i < argc; ++i) {
00054   char *confFile = argv[i];
00055 #else
00056   char *confFile = argv[argc-1];
00057 #endif
00058   char *oldcwd = GETCWD(0,0);
00059   char *currentdir=confFile;
00060   char *tmp;
00061   for(tmp=confFile;*tmp;++tmp); // find final null
00062   for( ; tmp != confFile && *tmp != PATHSEP; --tmp); // find last '/'
00063 #if defined(WIN32) && !defined(__CYGWIN__)
00064   if (tmp == confFile) {
00065     // in case this is under cygwin, search for '/' as well
00066     for(tmp=confFile;*tmp;++tmp); // find final null
00067     for( ; tmp != confFile && *tmp != '/'; --tmp); // find last '/'
00068   }
00069 #endif
00070   if ( tmp != confFile )
00071   {
00072     *tmp = 0; confFile = tmp + 1;
00073     if ( CHDIR(currentdir) ) NAMD_die("chdir() failed!");
00074     iout << iINFO << "Changed directory to " << currentdir << "\n" << endi;
00075   }
00076   else if ( *tmp == PATHSEP ) // config file in / is odd, but it might happen
00077     if ( CHDIR(PATHSEPSTR) ) NAMD_die("chdir() failed!");
00078   currentdir = NULL;
00079 
00080   iout << iINFO << "Configuration file is " << confFile << "\n" << endi;
00081 
00082   struct stat statBuf;
00083   if (stat(confFile, &statBuf)) {
00084     NAMD_die("Simulation config file is not accessible.");
00085   }
00086 
00087 #ifdef NAMD_TCL
00088   if ( i == argc - 1 ) script->run(confFile);
00089   else script->load(confFile);
00090 #else
00091   script->run(confFile);
00092 #endif
00093 
00094   CHDIR(oldcwd);
00095 //  free(oldcwd);
00096 
00097 #ifdef NAMD_TCL
00098 }
00099 #endif
00100 
00101   BackEnd::exit();
00102 }
00103 

Generated on Mon Nov 23 04:59:21 2009 for NAMD by  doxygen 1.3.9.1