00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
00062 strcpy(fileName, theFileName);
00063
00064
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
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
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
00119 theFile.close();
00120
00121
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
00132 for (int i=0; i<(commitTag-1); i++)
00133
00134 if (flag == 1 || flag == 2) {
00135 inputFile >> data;
00136 inputFile >> data;
00137 }
00138
00139
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
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
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 }