TclRecorderCommands.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.39 $
00022 // $Date: 2006/08/17 22:25:43 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/recorder/TclRecorderCommands.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 
00027 // Created: 04/98
00028 // Revision: AA
00029 //
00030 // Description: This file contains the function that is invoked
00031 // by the interpreter when the comand 'record' is invoked by the 
00032 // user.
00033 //
00034 // What: "@(#) commands.C, revA"
00035 
00036 
00037 #include <tcl.h>
00038 #include <tk.h>
00039 
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043 #include <Domain.h>
00044 #include <EquiSolnAlgo.h>
00045 
00046 // recorders
00047 #include <NodeRecorder.h>
00048 #include <EnvelopeNodeRecorder.h>
00049 #include <EnvelopeElementRecorder.h>
00050 #include <PatternRecorder.h>
00051 #include <DriftRecorder.h>
00052 #include <EnvelopeDriftRecorder.h>
00053 #include <ElementRecorder.h>
00054 
00055 
00056 #include <NodeIter.h>
00057 #include <ElementIter.h>
00058 #include <Node.h>
00059 #include <Element.h>
00060 #include <DamageModel.h>
00061 #include <DamageRecorder.h>
00062 #include <MeshRegion.h>
00063 //#include <GSA_Recorder.h>
00064 #include <TclModelBuilder.h>
00065 
00066 #include <StandardStream.h>
00067 #include <DataFileStream.h>
00068 #include <XmlFileStream.h>
00069 #include <DatabaseStream.h>
00070 
00071 extern TclModelBuilder *theDamageTclModelBuilder;
00072 
00073 enum outputMode  {STANDARD_STREAM, DATA_STREAM, XML_STREAM, DATABASE_STREAM};
00074 
00075 
00076 #include <EquiSolnAlgo.h>
00077 
00078 #ifdef _NOGRAPHICS
00079 
00080 #else
00081 #include <TclFeViewer.h>
00082 #include <FilePlotter.h>
00083 #include <AlgorithmIncrements.h>
00084 #endif
00085 
00086 
00087 #include <SimulationInformation.h>
00088 extern SimulationInformation simulationInfo;
00089 
00090 
00091 static EquiSolnAlgo *theAlgorithm =0;
00092 extern FE_Datastore *theDatabase;
00093 extern FEM_ObjectBroker theBroker;
00094 
00095 int
00096 TclCreateRecorder(ClientData clientData, Tcl_Interp *interp, int argc,
00097                   TCL_Char **argv, Domain &theDomain, Recorder **theRecorder)
00098 {
00099     // make sure at least one other argument to contain integrator
00100     if (argc < 2) {
00101         opserr << "WARNING need to specify a Recorder type\n";
00102         return TCL_ERROR;
00103     }
00104 
00105     //
00106     // check argv[1] for type of Recorder, parse in rest of arguments
00107     // needed for the type of Recorder, create the object and add to Domain
00108     //
00109     (*theRecorder) = 0;
00110     (*theRecorder) = 0;
00111     FE_Datastore *theRecorderDatabase = 0;
00112     OPS_Stream *theOutputStream = 0;
00113 
00114     TCL_Char *fileName = 0;
00115     TCL_Char *tableName = 0;
00116 
00117     // an Element Recorder or ElementEnvelope Recorder
00118     if ((strcmp(argv[1],"Element") == 0) || (strcmp(argv[1],"EnvelopeElement") == 0)
00119         || (strcmp(argv[1],"ElementEnvelope") == 0)) {
00120 
00121 
00122       int numEle = 0;
00123       int endEleIDs = 2;
00124       double dT = 0.0;
00125       bool echoTime = false;
00126       int loc = endEleIDs;
00127       int flags = 0;
00128       int eleData = 0;
00129       outputMode eMode = STANDARD_STREAM; 
00130       ID eleIDs(0,32);
00131 
00132       while (flags == 0 && loc < argc) {
00133         
00134         if ((strcmp(argv[loc],"-ele") == 0) ||
00135             (strcmp(argv[loc],"-eles") == 0) ||
00136             (strcmp(argv[loc],"-element") == 0)) {
00137           
00138           // ensure no segmentation fault if user messes up
00139           if (argc < loc+2) {
00140             opserr << "WARNING recorder Element .. -ele tag1? .. - no ele tags specified\n";
00141             return TCL_ERROR;
00142           }
00143           
00144           //
00145           // read in a list of ele until end of command or other flag
00146           //
00147           loc++;
00148           int eleTag;
00149           while (loc < argc && Tcl_GetInt(interp, argv[loc], &eleTag) == TCL_OK) {
00150             eleIDs[numEle++] = eleTag;
00151             loc++;
00152           }
00153           Tcl_ResetResult(interp);
00154           
00155           if (loc == argc) {
00156             opserr << "ERROR: No response type specified for element recorder. " << endln;
00157             return TCL_ERROR;
00158           }
00159           
00160           if (strcmp(argv[loc],"all") == 0) {
00161             ElementIter &theEleIter = theDomain.getElements();
00162             Element *theEle;
00163             while ((theEle = theEleIter()) != 0)
00164               eleIDs[numEle++] = theEle->getTag();
00165             loc++;
00166           }
00167           
00168         } else if (strcmp(argv[loc],"-eleRange") == 0) {
00169           
00170           // ensure no segmentation fault if user messes up
00171           if (argc < loc+3) {
00172             opserr << "WARNING recorder Element .. -eleRange start? end?  .. - no ele tags specified\n";
00173             return TCL_ERROR;
00174           }
00175           
00176           //
00177           // read in start and end tags of two elements & add set [start,end]
00178           //
00179           
00180           int start, end;
00181           if (Tcl_GetInt(interp, argv[loc+1], &start) != TCL_OK) {
00182             opserr << "WARNING recorder Element -eleRange start? end? - invalid start " << argv[loc+1] << endln;
00183             return TCL_ERROR;
00184           }      
00185           if (Tcl_GetInt(interp, argv[loc+2], &end) != TCL_OK) {
00186             opserr << "WARNING recorder Element -eleRange start? end? - invalid end " << argv[loc+2] << endln;
00187             return TCL_ERROR;
00188           }      
00189           if (start > end) {
00190             int swap = end;
00191             end = start;
00192             start = swap;
00193           }
00194           
00195           for (int i=start; i<=end; i++)
00196             eleIDs[numEle++] = i;           
00197           
00198           loc += 3;
00199         } 
00200         
00201         else if (strcmp(argv[loc],"-region") == 0) {
00202           // allow user to specif elements via a region
00203           
00204           if (argc < loc+2) {
00205             opserr << "WARNING recorder Element .. -region tag?  .. - no region specified\n";
00206             return TCL_ERROR;
00207           }
00208           int tag;
00209           if (Tcl_GetInt(interp, argv[loc+1], &tag) != TCL_OK) {
00210             opserr << "WARNING recorder Element -region tag? - invalid tag " << argv[loc+1] << endln;
00211             return TCL_ERROR;
00212           }      
00213           MeshRegion *theRegion = theDomain.getRegion(tag);
00214           if (theRegion == 0) {
00215             opserr << "WARNING recorder Element -region " << tag << " - region does not exist" << endln;
00216             return TCL_OK;
00217           }      
00218           const ID &eleRegion = theRegion->getElements();
00219           for (int i=0; i<eleRegion.Size(); i++)
00220             eleIDs[numEle++] = eleRegion(i);
00221           
00222           loc += 2;
00223         } 
00224         
00225         else if ((strcmp(argv[loc],"-time") == 0) || (strcmp(argv[loc],"-load") == 0)) { 
00226           // allow user to specify const load
00227           echoTime = true;
00228           loc++;
00229         } 
00230         
00231         else if (strcmp(argv[loc],"-dT") == 0) {
00232           // allow user to specify time step size for recording
00233           loc++;
00234           if (Tcl_GetDouble(interp, argv[loc], &dT) != TCL_OK)  
00235             return TCL_ERROR;   
00236           loc++;
00237         } 
00238         
00239         else if (strcmp(argv[loc],"-file") == 0) {
00240           fileName = argv[loc+1];
00241           eMode = DATA_STREAM;
00242           simulationInfo.addWriteFile(fileName);
00243           loc += 2;
00244           if (strcmp(argv[loc],"-xml") == 0) {
00245             eMode = XML_STREAM;
00246             loc+=1;
00247           } else if (strcmp(argv[loc],"-headings") == 0) {
00248             eMode = DATA_STREAM;
00249             loc +=1;
00250           }
00251         }
00252         
00253         else if (strcmp(argv[loc],"-database") == 0) {
00254           theRecorderDatabase = theDatabase;
00255           if (theRecorderDatabase != 0) {
00256             tableName = argv[loc+1];
00257             eMode = DATABASE_STREAM;
00258           } else {
00259             opserr << "WARNING recorder Node .. -database &lt;fileName&gt; - NO CURRENT DATABASE, results to File instead\n";
00260             fileName = argv[loc+1];
00261           }
00262           
00263           loc += 2;
00264         }
00265         
00266         else if ((strcmp(argv[loc],"-nees") == 0) || (strcmp(argv[loc],"-xml") == 0)) {
00267           // allow user to specify load pattern other than current
00268           fileName = argv[loc+1];
00269           simulationInfo.addWriteFile(fileName);
00270           eMode = XML_STREAM;
00271           loc += 2;
00272         }           
00273         
00274         else {
00275           // first unknown string then is assumed to start 
00276           // element response request starts
00277           eleData = loc;
00278           flags = 1;
00279         }
00280       }
00281       
00282       // if user has specified no element tags lets assume he wants them all
00283       if (numEle == 0) {
00284         ElementIter &theEleIter = theDomain.getElements();
00285         Element *theEle;
00286         while ((theEle = theEleIter()) != 0)
00287           eleIDs[numEle++] = theEle->getTag();
00288       }
00289       
00290       if (eleData >= argc) {
00291         opserr << "ERROR: No response type specified for element recorder. " << endln;
00292         return TCL_ERROR;
00293       }
00294       
00295       const char **data = new const char *[argc-eleData];
00296       
00297       int i,j;
00298       for (i=eleData, j=0; i<argc; i++, j++)
00299         data[j] = argv[i];
00300       
00301       
00302       // construct the DataHandler
00303       if (eMode == DATA_STREAM && fileName != 0) {
00304         theOutputStream = new DataFileStream(fileName);
00305       } else if (eMode == XML_STREAM && fileName != 0) {
00306         theOutputStream = new XmlFileStream(fileName);
00307       } else if (eMode == DATABASE_STREAM && tableName != 0) {
00308         theOutputStream = new DatabaseStream(theDatabase, tableName);
00309       } else
00310         theOutputStream = new StandardStream();
00311       
00312       
00313       if (strcmp(argv[1],"Element") == 0) 
00314         (*theRecorder) = new ElementRecorder(eleIDs, 
00315                                              data, 
00316                                              argc-eleData, 
00317                                              echoTime, 
00318                                              theDomain, 
00319                                              *theOutputStream,
00320                                              dT);
00321       else
00322         (*theRecorder) = new EnvelopeElementRecorder(eleIDs, 
00323                                                      data, 
00324                                                      argc-eleData, 
00325                                                      theDomain, 
00326                                                      *theOutputStream,
00327                                                      dT, echoTime);
00328       
00329       delete [] data;
00330     }
00331     
00332 
00335 
00336     else if ( (strcmp(argv[1],"Damage") == 0) || (strcmp(argv[1],"ElementDamage") == 0) ||
00337                 (strcmp(argv[1],"damage") == 0) || (strcmp(argv[1],"elementDamage") == 0) ) {
00338                 
00339 
00340       if (argc < 7) {
00341         opserr << "WARNING recorder ElementDamage eleID? <-time> "
00342                << "<-file fileName?> <-section secID1? secID2? ...> <-dof dofID?> <-damage dmgID?>";
00343         return TCL_ERROR;
00344       }    
00345       
00346       double dT = 0.0;
00347       bool echoTime = false;
00348       int loc = 2;
00349       int eleID;
00350       
00351       if ( Tcl_GetInt(interp, argv[loc], &eleID) != TCL_OK) {
00352         opserr << "WARNING recorder ElementDamage: No element tag specified ";
00353         return TCL_ERROR;
00354       }
00355       loc++;
00356       
00357       if ( (strcmp(argv[loc],"-time") == 0) || (strcmp(argv[loc],"-load") == 0) ) { 
00358         // allow user to specify const load
00359         echoTime = true;
00360         loc++;
00361       }         
00362       else if ( strcmp(argv[loc],"-dT" ) == 0 ) {
00363         // allow user to specify time step size for recording
00364         loc++;
00365         if (Tcl_GetDouble(interp, argv[loc], &dT) != TCL_OK)    
00366           return TCL_ERROR;     
00367         loc++;
00368       } 
00369       
00370       
00371       if (strcmp(argv[loc],"-file") == 0) {
00372         // allow user to specify load pattern other than current
00373         loc++;
00374         fileName = argv[loc];
00375         loc++;
00376       }
00377       
00378       if ( strcmp(argv[loc],"-section")!=0 && strcmp(argv[loc],"section")!=0 ) {
00379         opserr << "WARNING recorder ElementDamage: Section keyword not specified ";
00380         return TCL_ERROR;
00381       }
00382       loc++;
00383       
00384       int secID;                
00385       int endSecIDs = loc;
00386       int numSec = 0;
00387       while ( Tcl_GetInt(interp, argv[endSecIDs], &secID ) == TCL_OK) {
00388         endSecIDs++;
00389       }
00390       
00391       numSec = endSecIDs - loc ;
00392       // create an ID to hold section/material tags
00393       ID secIDs(numSec);
00394       
00395       // read in the sec tags to the ID
00396       for (int i=loc; i<endSecIDs; i++) {
00397         if (Tcl_GetInt(interp, argv[i], &secID) != TCL_OK)      
00398           return TCL_ERROR;     
00399         secIDs[loc-i] = secID;    
00400       }
00401       
00402       loc = endSecIDs;
00403       
00404       int dofID = 0;
00405       if ( strcmp(argv[loc],"-dof")==0 || strcmp(argv[loc],"dof")==0 ||
00406            strcmp(argv[loc],"-DOF")==0 || strcmp(argv[loc],"DOF")==0 ) {
00407         loc++;
00408         if (Tcl_GetInt(interp, argv[loc], &dofID) != TCL_OK) {
00409           opserr << "WARNING recorder ElementDamage: No dof tag specified ";
00410           return TCL_ERROR;
00411         }
00412         loc++;
00413       }
00414       
00415       if ( strcmp(argv[loc],"-damage")!=0 && strcmp(argv[loc],"damage")!=0 ) {
00416         opserr << "WARNING recorder ElementDamage: No damege tag specified ";
00417         return TCL_ERROR;
00418       }
00419       loc++;
00420       
00421       int dmgID;
00422       if (Tcl_GetInt(interp, argv[loc], &dmgID) != TCL_OK) {
00423         opserr << "WARNING recorder ElementDamage: No damege tag specified ";
00424         return TCL_ERROR;
00425       }
00426       
00427       DamageModel *dmgPTR;
00428       dmgPTR = theDamageTclModelBuilder->getDamageModel(dmgID);
00429       
00430       if ( dmgPTR == NULL )
00431         {
00432           opserr << "WARNING recorder ElementDamage: specified damage model not found\n";
00433           return TCL_ERROR;
00434         }
00435       
00436       
00437       //        const char **data = new const char *[argc-eleData];
00438 
00439       OPS_Stream *theOutput = new DataFileStream(fileName);
00440       
00441       // now construct the recorder
00442       (*theRecorder) = new DamageRecorder( eleID , secIDs, dofID , dmgPTR , theDomain,echoTime,dT ,*theOutput);
00443       
00444     }
00446     
00447     
00448     // create a recorder to write nodal displacement quantities to a file
00449     else if ((strcmp(argv[1],"Node") == 0) || (strcmp(argv[1],"EnvelopeNode") == 0) 
00450              || (strcmp(argv[1],"NodeEnvelope") == 0)) {        
00451       
00452       if (argc < 7) {
00453         opserr << "WARNING recorder Node ";
00454         opserr << "-node <list nodes> -dof <doflist> -file <fileName> -dT <dT> reponse";
00455             return TCL_ERROR;
00456       }    
00457       
00458       // AddingSensitivity:BEGIN ///////////////////////////////////
00459       int sensitivity = 0;
00460       // AddingSensitivity:END /////////////////////////////////////
00461 
00462       TCL_Char *responseID = 0;
00463 
00464       outputMode eMode = STANDARD_STREAM;
00465 
00466       int pos = 2;
00467 
00468       bool echoTimeFlag = false;
00469       int flags = 0;
00470       double dT = 0.0;
00471       int numNodes = 0;
00472 
00473       // create ID's to contain the node tags & the dofs
00474       ID theNodes(0,16);
00475       ID theDofs(0, 6);
00476 
00477       while (flags == 0 && pos < argc) {
00478 
00479         if (strcmp(argv[pos],"-time") == 0) {
00480           echoTimeFlag = true;
00481           pos++;
00482         }
00483         
00484         else if (strcmp(argv[pos],"-load") == 0) {
00485           echoTimeFlag = true;      
00486           pos++;
00487         }
00488 
00489         else if (strcmp(argv[pos],"-file") == 0) {
00490           fileName = argv[pos+1];
00491           simulationInfo.addWriteFile(fileName);
00492           eMode = DATA_STREAM;
00493           pos += 2;
00494         }
00495 
00496         else if (strcmp(argv[pos],"-database") == 0) {
00497           eMode = DATABASE_STREAM;
00498           theRecorderDatabase = theDatabase;
00499           if (theRecorderDatabase != 0)
00500             tableName = argv[pos+1];
00501           else {
00502             opserr << "WARNING recorder Node .. -database &lt;fileName&gt; - NO CURRENT DATABASE, results to File instead\n";
00503             fileName = argv[pos+1];
00504           }
00505 
00506           pos += 2;
00507         }
00508         else if ((strcmp(argv[pos],"-nees") == 0) || (strcmp(argv[pos],"-xml") == 0)) {
00509           // allow user to specify load pattern other than current
00510           fileName = argv[pos+1];
00511           simulationInfo.addWriteFile(fileName);
00512           eMode = XML_STREAM;
00513           pos += 2;
00514         }           
00515 
00516         else if (strcmp(argv[pos],"-dT") == 0) {
00517           pos ++;
00518           if (Tcl_GetDouble(interp, argv[pos], &dT) != TCL_OK)  
00519             return TCL_ERROR;             
00520           pos++;
00521         }
00522 
00523         else if ((strcmp(argv[pos],"-node") == 0) || 
00524                  (strcmp(argv[pos],"-nodes") == 0)) {
00525           pos++;
00526           
00527           // read in the node tags or 'all' can be used
00528           if (strcmp(argv[pos],"all") == 0) {
00529             numNodes = theDomain.getNumNodes();
00530             
00531             NodeIter &theNodeIter = theDomain.getNodes();
00532             Node *theNode;
00533             int loc=0;
00534             while ((theNode= theNodeIter()) != 0) {
00535               int tag = theNode->getTag();
00536               theNodes[loc++] = tag;
00537             }
00538             pos++;
00539           } else {
00540             int node;
00541             for (int j=pos; j< argc; j++) 
00542               if (Tcl_GetInt(interp, argv[pos], &node) != TCL_OK) {
00543                 j = argc;
00544                 Tcl_ResetResult(interp);
00545               } else {
00546                 theNodes[numNodes] = node;
00547                 numNodes++;
00548                 pos++;
00549               }
00550           }
00551         } 
00552 
00553         else if (strcmp(argv[pos],"-nodeRange") == 0) {
00554             
00555           // ensure no segmentation fault if user messes up
00556           if (argc < pos+3) {
00557             opserr << "WARNING recorder Node .. -nodeRange start? end?  .. - no ele tags specified\n";
00558             return TCL_ERROR;
00559           }
00560           
00561           //
00562           // read in start and end tags of two elements & add set [start,end]
00563           //
00564             
00565           int start, end;
00566           if (Tcl_GetInt(interp, argv[pos+1], &start) != TCL_OK) {
00567             opserr << "WARNING recorder Node -nodeRange start? end? - invalid start " << argv[pos+1] << endln;
00568             return TCL_ERROR;
00569           }      
00570           if (Tcl_GetInt(interp, argv[pos+2], &end) != TCL_OK) {
00571             opserr << "WARNING recorder Node -nodeRange start? end? - invalid end " << argv[pos+2] << endln;
00572             return TCL_ERROR;
00573           }      
00574           if (start > end) {
00575             int swap = end;
00576             end = start;
00577             start = swap;
00578           }
00579           
00580           for (int i=start; i<=end; i++)
00581             theNodes[numNodes++] = i;       
00582           pos += 3;
00583         }
00584 
00585         else if (strcmp(argv[pos],"-region") == 0) {
00586           // allow user to specif elements via a region
00587           
00588           if (argc < pos+2) {
00589             opserr << "WARNING recorder Node .. -region tag?  .. - no region specified\n";
00590             return TCL_ERROR;
00591           }
00592           int tag;
00593           if (Tcl_GetInt(interp, argv[pos+1], &tag) != TCL_OK) {
00594             opserr << "WARNING recorder Node -region tag? - invalid tag " << argv[pos+1] << endln;
00595             return TCL_ERROR;
00596           }      
00597           MeshRegion *theRegion = theDomain.getRegion(tag);
00598           if (theRegion == 0) {
00599             opserr << "WARNING recorder Node -region " << tag << " - region does not exist" << endln;
00600             return TCL_OK;
00601           }      
00602           const ID &nodeRegion = theRegion->getNodes();
00603           for (int i=0; i<nodeRegion.Size(); i++)
00604             theNodes[numNodes++] = nodeRegion(i);
00605           
00606           pos += 2;
00607         } 
00608         
00609         else if (strcmp(argv[pos],"-dof") == 0) {
00610           pos++;
00611           int numDOF = 0;
00612           int dof;
00613           for (int j=pos; j< argc; j++) 
00614             if (Tcl_GetInt(interp, argv[pos], &dof) != TCL_OK) {
00615               j = argc;
00616               Tcl_ResetResult(interp);
00617             } else {
00618               theDofs[numDOF] = dof-1;  // -1 for c indexing of the dof's
00619               numDOF++;
00620               pos++;
00621             }
00622         }
00623 // AddingSensitivity:BEGIN //////////////////////////////////////
00624         else if (strcmp(argv[pos],"-sensitivity") == 0) {
00625                 pos++;
00626                 if (Tcl_GetInt(interp, argv[pos], &sensitivity) != TCL_OK) {
00627                         opserr << "ERROR: Invalid gradient number to node recorder." << endln;
00628                         return TCL_ERROR;
00629                 }
00630                 pos++;
00631         }
00632 // AddingSensitivity:END ////////////////////////////////////////
00633         else     
00634           flags = 1;
00635         }
00636       
00637       if (pos >= argc) {
00638         opserr << "WARNING: No response type specified for node recorder, will assume you meant -disp\n" << endln;
00639       }
00640       
00641       if (responseID == 0 && pos < argc) {
00642         responseID  = argv[pos];
00643       }
00644 
00645       if (numNodes == 0) {
00646         NodeIter &theNodeIter = theDomain.getNodes();
00647         Node *theNode;
00648         while ((theNode= theNodeIter()) != 0) {
00649           int tag = theNode->getTag();
00650           theNodes[numNodes++] = tag;
00651         }
00652       }
00653 
00654       // construct the DataHandler
00655       if (eMode == DATA_STREAM && fileName != 0) {
00656         theOutputStream = new DataFileStream(fileName);
00657       } else if (eMode == XML_STREAM && fileName != 0) {
00658         theOutputStream = new XmlFileStream(fileName);
00659       } else if (eMode == DATABASE_STREAM && tableName != 0) {
00660         theOutputStream = new DatabaseStream(theDatabase, tableName);
00661       } else {
00662         theOutputStream = new StandardStream();
00663       }
00664       
00665       if (strcmp(argv[1],"Node") == 0) {
00666         (*theRecorder) = new NodeRecorder(theDofs, 
00667                                           theNodes, 
00668                                           sensitivity,
00669                                           responseID, 
00670                                           theDomain, 
00671                                           *theOutputStream, 
00672                                           dT, 
00673                                           echoTimeFlag);
00674       } else
00675           
00676         (*theRecorder) = new EnvelopeNodeRecorder(theDofs, 
00677                                                   theNodes, 
00678                                                   responseID, 
00679                                                   theDomain,
00680                                                   *theOutputStream,
00681                                                   dT, echoTimeFlag);
00682     }
00683 
00684     else if (strcmp(argv[1],"Pattern") == 0) {
00685       if (argc < 4) {
00686         opserr << "WARNING recorder Pattern filename? <startFlag> patternTag?";
00687         return TCL_ERROR;
00688       }
00689       
00690       int flag = 0;
00691       if (strcmp(argv[3],"-time") == 0)
00692         flag = 1;
00693       if (strcmp(argv[3],"-load") == 0)
00694         flag = 2;
00695       
00696       int pos = 3;
00697       if (flag != 0) pos = 4;
00698       
00699       int patternTag;
00700       
00701       if (Tcl_GetInt(interp, argv[pos++], &patternTag) != TCL_OK)
00702         return TCL_ERROR;
00703       
00704       (*theRecorder) = new PatternRecorder(patternTag, theDomain, argv[2], 0.0, flag);
00705     }
00706     
00707     // Create a recorder to write nodal drifts to a file
00708     else if ((strcmp(argv[1],"Drift") == 0) || (strcmp(argv[1],"EnvelopeDrift") == 0)) {
00709 
00710       outputMode eMode = STANDARD_STREAM;       // enum found in DataOutputFileHandler.h
00711       
00712       bool echoTimeFlag = false;
00713       ID iNodes(0,16);
00714       ID jNodes(0,16);
00715       int dof = 1;
00716       int perpDirn = 2;
00717       int pos = 2;
00718       while (pos < argc) {
00719 
00720         
00721         if (strcmp(argv[pos],"-file") == 0) {
00722           fileName = argv[pos+1];
00723           eMode = DATA_STREAM;
00724           simulationInfo.addWriteFile(fileName);
00725           pos += 2;
00726           if (strcmp(argv[pos],"-xml") == 0) {
00727             eMode = XML_STREAM;
00728             pos+=1;
00729           } else if (strcmp(argv[pos],"-headings") == 0) {
00730             eMode = DATA_STREAM;
00731             pos +=1;
00732           }
00733         }
00734         
00735         else if (strcmp(argv[pos],"-database") == 0) {
00736           theRecorderDatabase = theDatabase;
00737           if (theRecorderDatabase != 0) {
00738             tableName = argv[pos+1];
00739             eMode = DATABASE_STREAM;
00740           } else {
00741             opserr << "WARNING recorder Node .. -database &lt;fileName&gt; - NO CURRENT DATABASE, results to File instead\n";
00742             fileName = argv[pos+1];
00743           }
00744           
00745           pos += 2;
00746         }
00747         
00748         else if ((strcmp(argv[pos],"-nees") == 0) || (strcmp(argv[pos],"-xml") == 0)) {
00749           // allow user to specify load pattern other than current
00750           fileName = argv[pos+1];
00751           simulationInfo.addWriteFile(fileName);
00752           eMode = XML_STREAM;
00753           pos += 2;
00754         }           
00755         
00756         else if ((strcmp(argv[pos],"-iNode") == 0) || 
00757                  (strcmp(argv[pos],"-iNodes") == 0)) {
00758           pos++;
00759           
00760           int node;
00761           int numNodes = 0;
00762           for (int j=pos; j< argc; j++) 
00763             if (Tcl_GetInt(interp, argv[pos], &node) != TCL_OK) {
00764               j = argc;
00765               Tcl_ResetResult(interp);
00766             } else {
00767               iNodes[numNodes] = node;
00768               numNodes++;
00769               pos++;
00770             }
00771         }
00772         
00773         else if ((strcmp(argv[pos],"-jNode") == 0) || 
00774                  (strcmp(argv[pos],"-jNodes") == 0)) {
00775           pos++;
00776           int node;
00777           int numNodes = 0;
00778           for (int j=pos; j< argc; j++) 
00779             if (Tcl_GetInt(interp, argv[pos], &node) != TCL_OK) {
00780               j = argc;
00781               Tcl_ResetResult(interp);
00782             } else {
00783               jNodes[numNodes] = node;
00784               numNodes++;
00785               pos++;
00786             }
00787         }
00788         
00789         else if (strcmp(argv[pos],"-dof") == 0) {
00790           if (Tcl_GetInt(interp, argv[pos+1], &dof) != TCL_OK) {
00791             pos = argc;
00792           } 
00793           pos+=2;
00794         }
00795         
00796         else if (strcmp(argv[pos],"-perpDirn") == 0) {
00797           if (Tcl_GetInt(interp, argv[pos+1], &perpDirn) != TCL_OK) {
00798             pos = argc;
00799           } 
00800           pos+=2;
00801         } 
00802         
00803         else if (strcmp(argv[pos],"-time") == 0) {
00804           echoTimeFlag = true;
00805           pos+=1;
00806           
00807         } else 
00808           pos++;
00809       }
00810       
00811       if (iNodes.Size() != jNodes.Size()) {
00812         opserr << "WARNING recorder Drift - the number of iNodes and jNodes must be the same " << iNodes << " " << jNodes << endln;
00813         return TCL_ERROR;
00814       }
00815       
00816       // construct the DataHandler
00817       if (eMode == DATA_STREAM && fileName != 0) {
00818         theOutputStream = new DataFileStream(fileName);
00819       } else if (eMode == XML_STREAM && fileName != 0) {
00820         theOutputStream = new XmlFileStream(fileName);
00821       } else if (eMode == DATABASE_STREAM && tableName != 0) {
00822         theOutputStream = new DatabaseStream(theDatabase, tableName);
00823       } else
00824         theOutputStream = new StandardStream();
00825       
00826       // Subtract one from dof and perpDirn for C indexing
00827       if (strcmp(argv[1],"Drift") == 0) 
00828         (*theRecorder) = new DriftRecorder(iNodes, jNodes, dof-1, perpDirn-1,
00829                                            theDomain, *theOutputStream, echoTimeFlag);
00830       else
00831         (*theRecorder) = new EnvelopeDriftRecorder(iNodes, jNodes, dof-1, perpDirn-1,
00832                                                    theDomain, *theOutputStream, echoTimeFlag);
00833       
00834     }
00835     
00836     // a recorder for the graphical display of the domain
00837     else if (strcmp(argv[1],"display") == 0) {
00838 
00839         int xLoc, yLoc, width, height;
00840 
00841         if (argc < 7) {
00842             opserr << "WARNING recorder display title xLoc yLoc pixelsX pixelsY <-file fileName?>";
00843             return TCL_ERROR;
00844         }    
00845         if (Tcl_GetInt(interp, argv[3], &xLoc) != TCL_OK)       
00846             return TCL_ERROR;   
00847         if (Tcl_GetInt(interp, argv[4], &yLoc) != TCL_OK)       
00848             return TCL_ERROR;         
00849         if (Tcl_GetInt(interp, argv[5], &width) != TCL_OK)      
00850             return TCL_ERROR;   
00851         if (Tcl_GetInt(interp, argv[6], &height) != TCL_OK)     
00852             return TCL_ERROR;
00853         
00854         // check if we are to wipe image on each redraw
00855         int wipeFlag = 0;
00856         if (argc == 8) 
00857           if (strcmp(argv[7],"-wipe") == 0) 
00858             wipeFlag = 1;
00859 
00860 
00861 #ifdef _NOGRAPHICS
00862       return TCL_OK;
00863 #else
00864         if (argc == 7 || argc == 8)
00865           (*theRecorder) = new TclFeViewer(argv[2], xLoc, yLoc, width, height, theDomain, wipeFlag, interp);
00866         else if (argc == 9)
00867           (*theRecorder) = new TclFeViewer(argv[2], xLoc, yLoc, width, height, argv[8], theDomain, interp);
00868 #endif
00869     }
00870 
00871     else if (strcmp(argv[1],"plot") == 0) {
00872 
00873         int xLoc, yLoc, width, height;
00874         if (argc < 9) {
00875             opserr << "WARNING recorder display fileName? windowTitle? xLoc yLoc pixelsX pixelsY -columns colX1 colY1 -columns colX2 ...";
00876             return TCL_ERROR;
00877         }    
00878         if (Tcl_GetInt(interp, argv[4], &xLoc) != TCL_OK)       
00879             return TCL_ERROR;   
00880         if (Tcl_GetInt(interp, argv[5], &yLoc) != TCL_OK)       
00881             return TCL_ERROR;         
00882         if (Tcl_GetInt(interp, argv[6], &width) != TCL_OK)      
00883             return TCL_ERROR;   
00884         if (Tcl_GetInt(interp, argv[7], &height) != TCL_OK)     
00885             return TCL_ERROR;         
00886 
00887         int loc = 8;
00888 
00889         double dT = 0.0;
00890         loc = 0;
00891         ID cols(0,16);
00892         int numCols = 0;
00893         while (loc < argc) {
00894           if ((strcmp(argv[loc],"-columns") == 0) ||
00895               (strcmp(argv[loc],"-cols") == 0) ||
00896               (strcmp(argv[loc],"-col") == 0)) {
00897             if (argc < loc+2)
00898               return TCL_ERROR;
00899 
00900             int colX, colY;
00901             if (Tcl_GetInt(interp, argv[loc+1], &colX) != TCL_OK)       
00902               return TCL_ERROR; 
00903 
00904             if (Tcl_GetInt(interp, argv[loc+2], &colY) != TCL_OK)       
00905               return TCL_ERROR; 
00906 
00907             cols[numCols++] = colX;
00908             cols[numCols++] = colY;
00909             loc += 3;
00910           } 
00911           else if (strcmp(argv[loc],"-dT") == 0) {
00912 
00913             if (Tcl_GetDouble(interp, argv[loc+1], &dT) != TCL_OK)      
00914               return TCL_ERROR; 
00915             loc += 2;       
00916           }
00917           else
00918             loc++;
00919         }
00920 
00921 #ifdef _NOGRAPHICS
00922         return TCL_OK;
00923 #else
00924         FilePlotter *thePlotter = new FilePlotter(argv[2], argv[3], xLoc, yLoc, width, height, dT);
00925         (*theRecorder) = thePlotter;    
00926         thePlotter->setCol(cols);
00927 #endif
00928     }
00929 
00930     else if (strcmp(argv[1],"plotDifferent") == 0) {
00931 
00932         int xLoc, yLoc, width, height;
00933         if (argc < 10) {
00934             opserr << "WARNING recorder display fileName? windowTitle? xLoc yLoc pixelsX pixelsY -columns colX1 colY1 -columns colX2 ...";
00935             return TCL_ERROR;
00936         }    
00937         if (Tcl_GetInt(interp, argv[5], &xLoc) != TCL_OK)       
00938             return TCL_ERROR;   
00939         if (Tcl_GetInt(interp, argv[6], &yLoc) != TCL_OK)       
00940             return TCL_ERROR;         
00941         if (Tcl_GetInt(interp, argv[7], &width) != TCL_OK)      
00942             return TCL_ERROR;   
00943         if (Tcl_GetInt(interp, argv[8], &height) != TCL_OK)     
00944             return TCL_ERROR;         
00945 
00946         int loc = 9;
00947 
00948         double dT = 0.0;
00949         loc = 0;
00950         ID cols(0,16);
00951         int numCols = 0;
00952         while (loc < argc) {
00953           if ((strcmp(argv[loc],"-columns") == 0) ||
00954               (strcmp(argv[loc],"-cols") == 0) ||
00955               (strcmp(argv[loc],"-col") == 0)) {
00956             if (argc < loc+2)
00957               return TCL_ERROR;
00958 
00959             int colX, colY;
00960             if (Tcl_GetInt(interp, argv[loc+1], &colX) != TCL_OK)       
00961               return TCL_ERROR; 
00962 
00963             if (Tcl_GetInt(interp, argv[loc+2], &colY) != TCL_OK)       
00964               return TCL_ERROR; 
00965 
00966             cols[numCols++] = colX;
00967             cols[numCols++] = colY;
00968             loc += 3;
00969           } 
00970           else if (strcmp(argv[loc],"-dT") == 0) {
00971 
00972             if (Tcl_GetDouble(interp, argv[loc+1], &dT) != TCL_OK)      
00973               return TCL_ERROR; 
00974             loc += 2;       
00975           }
00976           else
00977             loc++;
00978         }
00979 
00980 #ifdef _NOGRAPHICS
00981         return TCL_OK;
00982 #else
00983         FilePlotter *thePlotter = new FilePlotter(argv[2], argv[3], argv[4], xLoc, yLoc, width, height, dT);
00984         (*theRecorder) = thePlotter;    
00985         thePlotter->setCol(cols);
00986 #endif
00987     }
00988 
00989 
00990     else if (strcmp(argv[1],"increments") == 0) {
00991 
00992         int xLoc, yLoc, width, height;
00993         
00994         if (theAlgorithm == 0) {
00995             opserr << "WARNING recorder increments - only allowed as algorithmRecorder";
00996             return TCL_ERROR;
00997         }
00998         if (argc < 7) {
00999             opserr << "WARNING recorder display windowTitle? xLoc yLoc pixelsX pixelsY ";
01000             return TCL_ERROR;
01001         }    
01002         if (Tcl_GetInt(interp, argv[3], &xLoc) != TCL_OK)       
01003             return TCL_ERROR;   
01004         if (Tcl_GetInt(interp, argv[4], &yLoc) != TCL_OK)       
01005             return TCL_ERROR;         
01006         if (Tcl_GetInt(interp, argv[5], &width) != TCL_OK)      
01007             return TCL_ERROR;   
01008         if (Tcl_GetInt(interp, argv[6], &height) != TCL_OK)     
01009             return TCL_ERROR;         
01010 
01011         TCL_Char *fileName = 0;
01012         bool displayRecord = false;
01013         int loc = 7;
01014         while (loc < argc) {
01015           if ((strcmp(argv[loc],"-file") == 0) ||
01016               (strcmp(argv[loc],"-file") == 0)) {
01017             
01018               if (argc < loc+1)
01019                 return TCL_ERROR;
01020               loc++;
01021               fileName = argv[loc];
01022               loc++;
01023           } else if (strcmp(argv[loc],"-display") == 0) {
01024             displayRecord = true;
01025             loc++;                                 
01026           } 
01027           else
01028             loc++;
01029         }
01030 
01031 #ifdef _NOGRAPHICS
01032         return TCL_OK;
01033 #else
01034         AlgorithmIncrements *thePlotter =  new AlgorithmIncrements(theAlgorithm, 
01035                                                                    argv[2], xLoc, yLoc, width, height, 
01036                                                                    displayRecord, fileName);
01037         (*theRecorder) = thePlotter;
01038 #endif
01039     }
01040 
01041     /* *****************************************
01042     else if (strcmp(argv[1],"GSA") == 0) {
01043         if (argc < 3) {
01044           opserr << argc;
01045           opserr << "WARNING recorder GSA -file fileName? -dT deltaT? - not enough arguments\n";
01046           return TCL_ERROR;
01047         }    
01048         TCL_Char *fileName = 0;
01049         TCL_Char *title1 =0;
01050         TCL_Char *title2 =0;
01051         TCL_Char *title3 =0;
01052         TCL_Char *jobno =0;
01053         TCL_Char *initials =0;
01054         TCL_Char *spec =0;
01055         TCL_Char *currency =0;
01056         TCL_Char *length =0;
01057         TCL_Char *force =0;
01058         TCL_Char *temp =0;
01059         double dT = 0.0;
01060         int loc = 2;
01061 
01062         while (loc < argc) {
01063           if ((strcmp(argv[loc],"-file") == 0) ||
01064               (strcmp(argv[loc],"-file") == 0)) {
01065             fileName = argv[loc+1];
01066             loc += 2;
01067           } else if ((strcmp(argv[loc],"-title1") == 0) ||
01068               (strcmp(argv[loc],"-Title1e") == 0)) {
01069             title1 = argv[loc+1];
01070             loc += 2;
01071           } else if ((strcmp(argv[loc],"-title2") == 0) ||
01072               (strcmp(argv[loc],"-Title2e") == 0)) {
01073             title2 = argv[loc+1];
01074             loc += 2;
01075           } else if ((strcmp(argv[loc],"-title3") == 0) ||
01076               (strcmp(argv[loc],"-Title3e") == 0)) {
01077             title3 = argv[loc+1];
01078             loc += 2;
01079           } else if ((strcmp(argv[loc],"-jobno") == 0) ||
01080               (strcmp(argv[loc],"-JobNo") == 0)) {
01081             jobno = argv[loc+1];
01082             loc += 2;
01083           } else if ((strcmp(argv[loc],"-initials") == 0) ||
01084               (strcmp(argv[loc],"-Initials") == 0)) {
01085             initials = argv[loc+1];
01086             loc += 2;
01087           } else if ((strcmp(argv[loc],"-spec") == 0) ||
01088               (strcmp(argv[loc],"-Spec") == 0)) {
01089             spec = argv[loc+1];
01090             loc += 2;
01091           } else if ((strcmp(argv[loc],"-currency") == 0) ||
01092               (strcmp(argv[loc],"-Currency") == 0)) {
01093             currency = argv[loc+1];
01094             loc += 2;
01095           } else if ((strcmp(argv[loc],"-length") == 0) ||
01096               (strcmp(argv[loc],"-Length") == 0)) {
01097             length = argv[loc+1];
01098             loc += 2;
01099           } else if ((strcmp(argv[loc],"-force") == 0) ||
01100               (strcmp(argv[loc],"-Force") == 0)) {
01101             force = argv[loc+1];
01102             loc += 2;
01103           } else if ((strcmp(argv[loc],"-temp") == 0) ||
01104               (strcmp(argv[loc],"-Temp") == 0)) {
01105             temp = argv[loc+1];
01106             loc += 2;
01107           }
01108           else if (strcmp(argv[loc],"-dT") == 0) {
01109             if (Tcl_GetDouble(interp, argv[loc+1], &dT) != TCL_OK)      
01110               return TCL_ERROR;       
01111             loc += 2;
01112           }
01113           else
01114             loc++;
01115         }
01116 
01117         GSA_Recorder *theR = new GSA_Recorder(theDomain, fileName, title1, title2, title3,
01118                                               jobno, initials, spec, currency, length, force,
01119                                               temp, dT);
01120         (*theRecorder) = theR;
01121     }
01122     ************************************************* */
01123     
01124     // no recorder type specified yet exists
01125     else {
01126       opserr << "WARNING No recorder type exists ";
01127       opserr << "for recorder of type:" << argv[1];
01128       
01129       return TCL_ERROR;
01130     }    
01131     
01132     // check we instantiated a recorder .. if not ran out of memory
01133     if ((*theRecorder) == 0) {
01134         opserr << "WARNING ran out of memory - recorder " << argv[1]<< endln;
01135         return TCL_ERROR;
01136     } 
01137 
01138     // operation successfull
01139     return TCL_OK;
01140 }
01141 
01142 
01143 int 
01144 TclAddRecorder(ClientData clientData, Tcl_Interp *interp, int argc, 
01145                TCL_Char **argv, Domain &theDomain)
01146 {
01147         Recorder *theRecorder;
01148         TclCreateRecorder(clientData, interp, argc, argv, theDomain, &theRecorder);
01149         
01150         if ((theRecorder == 0) || (theDomain.addRecorder(*theRecorder)) < 0) {
01151                 opserr << "WARNING could not add to domain - recorder " << argv[1]<< endln;
01152                 if (theRecorder == 0) 
01153                         opserr << "could not create recorder\n";
01154                 else
01155                         delete theRecorder;
01156                 return TCL_ERROR;
01157         } 
01158         return TCL_OK;
01159         
01160 }
01161 
01162 
01163 int 
01164 TclAddAlgorithmRecorder(ClientData clientData, Tcl_Interp *interp, int argc, 
01165                         TCL_Char **argv, Domain &theDomain, EquiSolnAlgo *theAlgo)
01166 {
01167         Recorder *theRecorder = 0;
01168         theAlgorithm = theAlgo;
01169         if (TclCreateRecorder(clientData, interp, argc, argv, theDomain,
01170                         &theRecorder) == TCL_ERROR) {
01171                 return TCL_ERROR;
01172         } else {
01173                 // add the recorder to the domain, 
01174                 // NOTE: will not be called with theALgo == 0
01175                 // see ~/g3/SRC/tcl/commands.C file
01176                 if (theRecorder == 0 || theAlgo->addRecorder(*theRecorder) < 0) {
01177                         opserr << "WARNING could not add to algorithm - recorder " << argv[1]<< endln;
01178                         delete theRecorder;
01179                         return TCL_ERROR;
01180                 } 
01181                 return TCL_OK;
01182         }
01183 }
01184 

Generated on Mon Oct 23 15:05:25 2006 for OpenSees by doxygen 1.5.0