Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

cmd_imd.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2008 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_imd.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.21 $      $Date: 2008/03/27 19:36:50 $
00015  *
00016  ***************************************************************************/
00017 
00018 #ifdef VMDIMD
00019 #include "CmdIMD.h"
00020 #endif
00021 
00022 #include "IMDMgr.h"
00023 #include "CommandQueue.h"
00024 #include "VMDApp.h"
00025 #include "MoleculeList.h"
00026 #include "utilities.h"
00027 #include "config.h"    // for CMDLEN
00028 #include <stdlib.h>
00029 #include <tcl.h>
00030 
00031 int text_cmd_imd(ClientData cd, Tcl_Interp *interp, int argc,
00032                      const char *argv[]) {
00033 
00034 #ifdef VMDIMD
00035   VMDApp *app = (VMDApp *)cd;
00036   CommandQueue *cmdQueue = app->commandQueue; 
00037 
00038   if (argc == 1) {
00039     Tcl_AppendResult(interp, 
00040     "Need parameters for 'imd' command.  Possibilities include: \n",
00041     "pause [on|off|toggle]\n", 
00042     "detach\n" ,
00043     "kill\n" ,
00044     "connect <hostname> <port>\n" ,
00045     "transfer <rate>\n" ,
00046     "keep <rate>\n" ,
00047     NULL);
00048     return TCL_ERROR;
00049   }
00050   
00051   else if (!strupncmp(argv[1], "pause", CMDLEN)) {   
00052     if ((argc == 3) && (!strupncmp(argv[2], "toggle", CMDLEN))) { //"imd pause"
00053       app->imdMgr->togglepause();
00054       cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::PAUSE_TOGGLE));
00055     }
00056     else if ((argc == 3) && (!strupncmp(argv[2], "on", CMDLEN))) {   //"imd pause on"
00057       app->imdMgr->pause();
00058       cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::PAUSE_ON));  
00059     }   
00060     else if ((argc == 3) && (!strupncmp(argv[2], "off", CMDLEN))) {   //"imd pause off"
00061       app->imdMgr->unpause();
00062       cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::PAUSE_OFF));  
00063     }  
00064     else {
00065       Tcl_AppendResult(interp, "Wrong arguments: imd pause <on|off|toggle>", NULL); 
00066       return TCL_ERROR;
00067     }
00068     
00069     if (!app->imdMgr->connected()) { 
00070       Tcl_AppendResult(interp, "No IMD connection available.", NULL);
00071       return TCL_ERROR;
00072     }
00073   }
00074   else if ((argc == 4) && (!strupncmp(argv[1], "connect", CMDLEN)) ) {
00075     int port = atoi(argv[3]);
00076     Molecule *mol = app->moleculeList->top();
00077     if (!mol) {
00078       Tcl_AppendResult(interp,      
00079         "Can't connect, no molecule loaded", NULL); 
00080       return TCL_ERROR;
00081     }
00082     if (app->imdMgr->connected()) {
00083       char buf[500];
00084       sprintf(buf, "Can't connect; already connected to simulation running on"
00085                    "host %s over port %d", app->imdMgr->gethost(), 
00086                    app->imdMgr->getport());
00087       Tcl_SetResult(interp, buf, TCL_VOLATILE);
00088       return TCL_ERROR;
00089     }
00090     if (!app->imd_connect(mol->id(), argv[2], port)) {
00091       Tcl_AppendResult(interp, "Unable to connect to host ", argv[2], 
00092         " on port ", argv[3], NULL);
00093       return TCL_ERROR;
00094     }
00095   }
00096   else if (argc == 2) {
00097     if (!app->imdMgr->connected()) {
00098       Tcl_AppendResult(interp, "No IMD connection available.", NULL);
00099       return TCL_ERROR;
00100     }
00101     else if (!strupncmp(argv[1], "detach", CMDLEN)) {
00102       app->imdMgr->detach();
00103       cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::DETACH));
00104     } else if (!strupncmp(argv[1], "kill", CMDLEN)) {
00105       app->imdMgr->kill();
00106       cmdQueue->runcommand(new CmdIMDSim(CmdIMDSim::KILL));
00107     } else {
00108       Tcl_AppendResult(interp, 
00109         "Usage: imd [pause | detach | kill]", NULL); 
00110       return TCL_ERROR; 
00111     }
00112   }
00113   else if ((argc == 3) && (!strupncmp(argv[1], "transfer", CMDLEN)) ) {
00114     int rate = atoi(argv[2]);
00115     app->imdMgr->set_trans_rate(rate);
00116     cmdQueue->runcommand(new CmdIMDRate(CmdIMDRate::TRANSFER, rate));
00117   }
00118   else if ((argc == 3) && (!strupncmp(argv[1], "keep", CMDLEN)) ) {
00119     int rate = atoi(argv[2]);
00120     app->imdMgr->set_keep_rate(rate);
00121     cmdQueue->runcommand(new CmdIMDRate(CmdIMDRate::KEEP, rate));
00122   }
00123   else
00124     return TCL_ERROR;
00125   // No error
00126   return TCL_OK;
00127 
00128 #else
00129   Tcl_AppendResult(interp,
00130     "IMD functionality not present.  Recompile with IMD enabled.", NULL);
00131   return TCL_ERROR;
00132 #endif
00133 }
00134 
00135 
00136 
00137 

Generated on Sat Jul 5 01:29:21 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002