PatternRecorder.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.5 $
00022 // $Date: 2004/11/24 22:45:28 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/recorder/PatternRecorder.cpp,v $
00024 
00025 // Written: MHS 
00026 // Created: 2002
00027 //
00028 // Description: This file contains the class definition for PatternRecorder.
00029 // A PatternRecorder is used to record the load values from a pattern.
00030 
00031 #include <PatternRecorder.h>
00032 #include <Domain.h>
00033 #include <LoadPattern.h>
00034 #include <Vector.h>
00035 #include <ID.h>
00036 #include <Matrix.h>
00037 #include <FE_Datastore.h>
00038 
00039 #include <fstream>
00040 using std::ifstream;
00041 
00042 #include <iomanip>
00043 using std::ios;
00044 
00045 PatternRecorder::PatternRecorder(int pattern,
00046                                  Domain &theDom,
00047                                  const char *theFileName,
00048                                  double dT,
00049                                  int startFlag)
00050   :Recorder(RECORDER_TAGS_PatternRecorder),
00051    thePattern(pattern), theDomain(&theDom),
00052    flag(startFlag), deltaT(dT), nextTimeStampToRecord(0.0)
00053 {
00054   // create char array to store file name
00055   int fileNameLength = strlen(theFileName) + 1;
00056   fileName = new char[fileNameLength];
00057   if (fileName == 0) {
00058     opserr << "PatternRecorder::PatternRecorder - out of memory creating string" << endln;
00059   }
00060   
00061   // copy the strings
00062   strcpy(fileName, theFileName);    
00063   
00064   // open the file
00065   theFile.open(fileName, ios::out);
00066   if (theFile.bad()) {
00067     opserr << "WARNING - PatternRecorder::PatternRecorder()";
00068     opserr << " - could not open file " << fileName << endln;
00069   }
00070   //theFile << setiosflags(ios::scientific) << setprecision(15);
00071 }
00072 
00073 PatternRecorder::~PatternRecorder()
00074 {
00075   if (!theFile)
00076     theFile.close();
00077   
00078   if (fileName != 0)
00079     delete [] fileName;
00080 }
00081 
00082 int 
00083 PatternRecorder::record(int commitTag, double timeStamp)
00084 {
00085   double value = 0.0;
00086   
00087   if (deltaT == 0.0 || timeStamp >= nextTimeStampToRecord) {
00088     
00089     if (deltaT != 0.0)
00090       nextTimeStampToRecord = timeStamp + deltaT;
00091     
00092     LoadPattern *pattern = theDomain->getLoadPattern(thePattern);
00093     if (pattern != 0) {
00094       value = pattern->getLoadFactor();
00095     }
00096   }
00097   
00098   // write them to the file
00099   if (flag == 1)
00100     theFile << timeStamp << " ";
00101   else if (flag == 2)
00102     theFile << timeStamp << " ";
00103   
00104   theFile << value << " ";
00105   
00106   theFile << endln;
00107   theFile.flush();
00108   
00109   return 0;
00110 }
00111 
00112 int 
00113 PatternRecorder::playback(int commitTag)
00114 {
00115   if (theFile.bad())
00116     return 0;
00117   
00118   // close o/p file to ensure all buffered data gets written to file
00119   theFile.close(); 
00120   
00121   // open a stream for reading from the file
00122   ifstream inputFile;
00123   inputFile.open(fileName, ios::in);
00124   if (inputFile.bad()) {
00125     opserr << "WARNING - PatternRecorder::playback() - could not open file ";
00126     opserr << fileName << endln;
00127     return -1;
00128   }   
00129   
00130   double data;
00131   // read file up until line we want
00132   for (int i=0; i<(commitTag-1); i++)
00133     // now read in a line
00134     if (flag == 1 || flag == 2) {
00135       inputFile >> data;
00136       inputFile >> data;
00137     }
00138   
00139   // now read in our line and print out
00140   if (flag == 1 || flag == 2) {
00141     inputFile >> data;
00142     opserr << data << " ";
00143     inputFile >> data;
00144     opserr << data << " ";
00145     opserr << endln;
00146   }
00147   inputFile.close();
00148   
00149   // open file again for writing
00150   theFile.open(fileName, ios::app);
00151   if (theFile.bad()) {
00152     opserr << "WARNING - PatternRecorder::playback() - could not open file ";
00153     opserr << fileName << endln;
00154     return -1;
00155   }    
00156   
00157   // does nothing
00158   return 0;
00159 }
00160 
00161 int
00162 PatternRecorder::restart(void)
00163 {
00164   theFile.close();
00165   theFile.open(fileName, ios::out);
00166   if (theFile.bad()) {
00167     opserr << "WARNING - PatternRecorder::restart() - could not open file ";
00168     opserr << fileName << endln;
00169   }
00170   return 0;
00171 }

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