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 #include<SimulationInformation.h>
00031 #include <OPS_Globals.h>
00032 #include <string.h>
00033 #include <time.h>
00034
00035 SimulationInformation::SimulationInformation()
00036 :filesRead(0), filesWritten(0), paramNames(0), paramValues(0),
00037 numFilesWritten(0), numFilesRead(0), numParameters(0)
00038 {
00039
00040 strcpy(startTime," ");
00041 strcpy(endTime," ");
00042
00043 }
00044
00045
00046 int
00047 SimulationInformation::start(void)
00048 {
00049
00050
00051
00052
00053 if (filesRead != 0) {
00054 for (int i=0; i<numFilesRead; i++)
00055 delete [] filesRead[i];
00056 delete [] filesRead;
00057 }
00058 filesRead = 0;
00059 numFilesRead = 0;
00060
00061 if (filesWritten != 0) {
00062 for (int i=0; i<numFilesWritten; i++)
00063 delete [] filesWritten[i];
00064 delete [] filesWritten;
00065 }
00066 filesWritten = 0;
00067 numFilesWritten = 0;
00068
00069 if (paramNames != 0) {
00070 for (int i=0; i<numParameters; i++) {
00071 delete [] paramNames[i];
00072 delete [] paramValues[i];
00073 }
00074 delete [] paramNames;
00075 delete [] paramValues;
00076 }
00077 numParameters = 0;
00078 paramNames = 0;
00079 paramValues = 0;
00080
00081
00082
00083 time_t timeT;
00084 if (time(&timeT) != 0) {
00085 #ifdef _WIN32
00086 const char *sTime = ctime(&timeT);
00087 strcpy(startTime, sTime);
00088 #else
00089 ctime_r(&timeT, &startTime[0]);
00090 #endif
00091
00092 }
00093
00094 return 0;
00095 }
00096
00097 int
00098 SimulationInformation::end(void)
00099 {
00100 time_t timeT;
00101 if (time(&timeT) != 0) {
00102 #ifdef _WIN32
00103 const char *eTime = ctime(&timeT);
00104 strcpy(endTime, eTime);
00105 #else
00106 ctime_r(&timeT, &endTime[0]);
00107 #endif
00108 }
00109
00110 return 0;
00111 }
00112
00113 SimulationInformation::~SimulationInformation()
00114 {
00115
00116 if (filesRead != 0) {
00117 for (int i=0; i<numFilesRead; i++) {
00118 delete [] filesRead[i];
00119 }
00120 delete [] filesRead;
00121 }
00122
00123 if (filesWritten != 0) {
00124 for (int i=0; i<numFilesWritten; i++)
00125 delete [] filesWritten[i];
00126 delete [] filesWritten;
00127 }
00128
00129 if (paramNames != 0) {
00130 for (int i=0; i<numParameters; i++) {
00131 delete [] paramNames[i];
00132 delete [] paramValues[i];
00133 }
00134 delete [] paramNames;
00135 delete [] paramValues;
00136 }
00137
00138 }
00139
00140
00141 int
00142 SimulationInformation::addReadFile(const char *fileName)
00143 {
00144
00145 if (fileName == 0)
00146 return -1;
00147
00148
00149 int filenameLength = strlen(fileName+1);
00150 int historyLocation = filenameLength-10;
00151 if (historyLocation > 0) {
00152 if (strcmp("history.tcl",&fileName[historyLocation]) == 0)
00153 return 0;
00154 }
00155
00156
00157 char **nextFiles = new char *[numFilesRead+1];
00158 if (nextFiles == 0)
00159 return -2;
00160
00161 for (int i=0; i<numFilesRead; i++)
00162 nextFiles[i] = filesRead[i];
00163
00164
00165 char *copyFileName = new char[strlen(fileName)+1];
00166 if (copyFileName == 0)
00167 return -3;
00168
00169 strcpy(copyFileName, fileName);
00170 nextFiles[numFilesRead] = copyFileName;
00171
00172
00173 if (filesRead != 0)
00174 delete [] filesRead;
00175 filesRead = nextFiles;
00176
00177
00178 numFilesRead++;
00179
00180 return 0;
00181 }
00182
00183 int
00184 SimulationInformation::addWriteFile(const char *fileName)
00185 {
00186
00187
00188 if (fileName == 0)
00189 return -1;
00190
00191
00192 char **nextFiles = new char *[numFilesWritten+1];
00193 if (nextFiles == 0)
00194 return -2;
00195
00196 for (int i=0; i<numFilesWritten; i++)
00197 nextFiles[i] = filesWritten[i];
00198
00199
00200 char *copyFileName = new char[strlen(fileName)+1];
00201 if (copyFileName == 0)
00202 return -3;
00203
00204 strcpy(copyFileName, fileName);
00205
00206 nextFiles[numFilesWritten] = copyFileName;
00207
00208
00209
00210 if (filesWritten != 0)
00211 delete [] filesWritten;
00212 filesWritten = nextFiles;
00213
00214
00215 numFilesWritten++;
00216
00217
00218
00219 return 0;
00220 }
00221
00222 int
00223 SimulationInformation::addParameter(const char *name, const char *value)
00224 {
00225
00226 if (name == 0 || value == 0)
00227 return -1;
00228
00229
00230 char **nextNames = new char *[numParameters+1];
00231 char **nextValues = new char *[numParameters+1];
00232 if (nextNames == 0 && nextValues == 0)
00233 return -2;
00234
00235 for (int i=0; i<numParameters; i++) {
00236 nextNames[i] = paramNames[i];
00237 nextValues[i] = paramValues[i];
00238 }
00239
00240
00241 char *copyParamName = new char[strlen(name)+1];
00242 char *copyParamValue = new char[strlen(value)+1];
00243 if (copyParamName == 0 || copyParamValue == 0) {
00244 delete [] nextNames;
00245 delete [] nextValues;
00246 return -3;
00247 }
00248
00249 strcpy(copyParamName, name);
00250 strcpy(copyParamValue, value);
00251 nextNames[numParameters] = copyParamName;
00252 nextValues[numParameters] = copyParamValue;
00253
00254
00255
00256 if (paramNames != 0)
00257 delete [] paramNames;
00258 paramNames = nextNames;
00259 if (paramValues != 0)
00260 delete [] paramValues;
00261 paramValues = nextValues;
00262
00263
00264 numParameters++;
00265
00266 return 0;
00267 }
00268
00269 void
00270 SimulationInformation::Print(OPS_Stream &s) const
00271 {
00272 char version[10];
00273 strcpy(version,OPS_VERSION);
00274
00275 s << "Program: OpenSees\n";
00276 s << "Version: " << version << endln;
00277 s << "Start Time: " << startTime;
00278 s << "End Time: " << endTime;
00279 s << "Input Files:\n";
00280 for (int i=0; i<numFilesRead; i++)
00281 s << " " << filesRead[i] << "\n";
00282 s << "\nOutput Files:\n";
00283 for (int k=0; k<numFilesWritten; k++)
00284 s << " " << filesWritten[k] << "\n";
00285 s << "\nParameters:\n";
00286 for (int j=0; j<numParameters; j++)
00287 s << " " << paramNames[j] << " " << paramValues[j] << "\n";
00288 s << endln;
00289 }
00290
00291 OPS_Stream &operator<<(OPS_Stream &s, const SimulationInformation &E)
00292 {
00293 E.Print(s);
00294 return s;
00295 }
00296
00297