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
00032
00033
00034
00035
00036
00037
00038
00039 #include <string.h>
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042
00043 #include <iostream>
00044 #include <iomanip>
00045 using std::ios;
00046 using std::setiosflags;
00047
00048 #include <FEM_ObjectBroker.h>
00049 #include <Domain.h>
00050 #include <ID.h>
00051 #include <Vector.h>
00052 #include <Matrix.h>
00053 #include <NEESData.h>
00054
00055 NEESData::NEESData(const char *dataBaseName,
00056 Domain &theDomain,
00057 FEM_ObjectBroker &theObjBroker)
00058 :FE_Datastore(theDomain, theObjBroker), tables(0), numTables(0)
00059 {
00060 dataBase = new char [strlen(dataBaseName)+1];
00061 strcpy(dataBase, dataBaseName);
00062 }
00063
00064 NEESData::~NEESData()
00065 {
00066
00067 for (int i=0; i<numTables; i++) {
00068 NEES_table* nextTable = tables->next;
00069 int numColumns = tables->numColumns;
00070 char **columns = tables->columns;
00071 for (int j=0; j<numColumns; j++)
00072 delete [] columns[j];
00073 delete [] columns;
00074 delete tables;
00075 tables = nextTable;
00076 }
00077 }
00078
00079 int
00080 NEESData::getDbTag(void)
00081 {
00082 opserr << "NEESData::getDbTag(void) - should not be called\n";
00083 return -1;
00084 }
00085
00086 int
00087 NEESData::commitState(int commitTag)
00088 {
00089 opserr << "NEESData::commitState(int commitTag) - should not be called\n";
00090 return -1;
00091 }
00092
00093 int
00094 NEESData::sendMsg(int dataTag, int commitTag,
00095 const Message &,
00096 ChannelAddress *theAddress)
00097 {
00098 opserr << "NEESData::sendMsg(int dataTag, int commitTag, - should not be called\n";
00099 return -1;
00100 }
00101
00102 int
00103 NEESData::recvMsg(int dataTag, int commitTag,
00104 Message &,
00105 ChannelAddress *theAddress)
00106 {
00107 opserr << "NEESData::recvMsg(int dataTag, int commitTag, - should not be called\n";
00108 return -1;
00109 }
00110
00111
00112 int
00113 NEESData::sendMatrix(int dataTag, int commitTag,
00114 const Matrix &theMatrix,
00115 ChannelAddress *theAddress)
00116 {
00117 opserr << "NEESData::sendMatrix(int dataTag, int commitTag, - should not be called\n";
00118 return -1;
00119 }
00120
00121
00122
00123
00124 int
00125 NEESData::recvMatrix(int dataTag, int commitTag,
00126 Matrix &theMatrix,
00127 ChannelAddress *theAddress)
00128 {
00129 return -1;
00130 }
00131
00132
00133
00134 int
00135 NEESData::sendVector(int dataTag, int commitTag,
00136 const Vector &theVector,
00137 ChannelAddress *theAddress)
00138 {
00139 opserr << "NEESData::sendVector(int dataTag, int commitTag, - should not be called\n";
00140 return -1;
00141 }
00142
00143 int
00144 NEESData::recvVector(int dataTag, int commitTag,
00145 Vector &theVector,
00146 ChannelAddress *theAddress)
00147 {
00148 opserr << "NEESData::recvVector(int dataTag, int commitTag, - should not be called\n";
00149 return -1;
00150 }
00151
00152
00153
00154 int
00155 NEESData::sendID(int dataTag, int commitTag,
00156 const ID &theID,
00157 ChannelAddress *theAddress)
00158 {
00159 opserr << "NEESData::sendID(int dataTag, int commitTag, - should not be called\n";
00160 return -1;
00161 }
00162
00163 int
00164 NEESData::recvID(int dataTag, int commitTag,
00165 ID &theID,
00166 ChannelAddress *theAddress)
00167 {
00168 opserr << "NEESData::recvID(int dataTag, int commitTag, - should not be called\n";
00169 return -1;
00170 }
00171
00172
00173 #include <fstream>
00174 using std::ofstream;
00175 using std::cerr;
00176
00177
00178 int
00179 NEESData::createTable(const char *tableName, int numColumns, char *columns[])
00180 {
00181
00182 int res = 0;
00183 int tableNameLength = strlen(tableName);
00184 char *copyTableName = new char[tableNameLength + 5];
00185 char *fileName = new char[tableNameLength + 5];
00186
00187 bool hasOutExtension = false;
00188
00189 if (fileName == 0 || copyTableName == 0) {
00190 opserr << "NEESData::insertData - out of memory creating copy of string " << fileName << endln;
00191 return -1;
00192 }
00193
00194 strcpy(copyTableName, tableName);
00195 if (tableNameLength > 4 && strcmp(".out", &tableName[tableNameLength-4]) == 0) {
00196 copyTableName[tableNameLength-4] = '\0';
00197 hasOutExtension = true;
00198 }
00199
00200
00201 NEES_table *t = tables;
00202 for (int i=0; i<numTables; i++) {
00203 if (strcmp(t->name, tableName) == 0) {
00204 opserr << "WARNING: NEESData::createTable - table already exists: " << copyTableName << endln;
00205 return -1;
00206 }
00207 t = t->next;
00208 }
00209
00210 strcpy(fileName, copyTableName);
00211 strcat(fileName,".out");
00212
00213 if (numColumns <= 0) {
00214 opserr << "WARNING: NEESData::createTable - number of data columns < 0 for table name: " << copyTableName << endln;
00215 delete [] fileName;
00216 delete [] copyTableName;
00217 return -1;
00218 }
00219
00220
00221
00222
00223
00224 strcpy(fileName, copyTableName);
00225 strcat(fileName,".out");
00226
00227 ofstream dataFile;
00228 dataFile.open(fileName, ios::out | ios::trunc);
00229
00230 if (!dataFile.is_open()) {
00231 opserr << "NEESData::createTable - failed to open file: " << fileName << endln;
00232 delete [] fileName;
00233 delete [] copyTableName;
00234 return -1;
00235 }
00236
00237
00238
00239
00240
00241 strcpy(fileName, copyTableName);
00242 strcat(fileName,".xml");
00243
00244 ofstream xmlFile;
00245 xmlFile.open(fileName, ios::out | ios::trunc);
00246
00247 if (xmlFile.is_open()) {
00248
00249 xmlFile << "<?xml version=\"1.0\"?>\n";
00250 xmlFile << "<NumericalFileDataDescription>\n";
00251 xmlFile << "\t<DataFile>\n";
00252 xmlFile << "\t\t<DataFileName> " << copyTableName << ".out </DataFileName>\n";
00253 xmlFile << "\t\t<NumberDataColumns> " << numColumns << "</NumberDataColumns>\n";
00254 xmlFile << "\t</DataFile>\n";
00255 for (int i=0; i<numColumns; i++) {
00256 xmlFile << "\t<DataColumnDescription>\n";
00257 xmlFile << "\t\t<ColumnLocation> " << i+1 << "</ColumnLocation>\n";
00258 xmlFile << "\t\t<Description> " << columns[i] << "</Description>\n";
00259 xmlFile << "\t</DataColumnDescription>\n";
00260 }
00261 xmlFile << "</NumericalFileDataDescription>\n";
00262 xmlFile.close();
00263
00264 } else {
00265 opserr << "NEESData::createData - failed to open file: " << copyTableName << endln;
00266 delete [] fileName;
00267 delete [] copyTableName;
00268 res = -1;
00269 }
00270
00271
00272 delete [] copyTableName;
00273
00274
00275
00276 NEES_table *nextTable = new NEES_table;
00277 if (nextTable == 0) {
00278 opserr << "NEESData::createData - out of memory creating Table structure for table: " << copyTableName << endln;
00279 res = -1;
00280 }
00281 strcpy(fileName, tableName);
00282
00283 nextTable->name = fileName;
00284 nextTable->numColumns = numColumns;
00285 nextTable->columns = new char *[numColumns];
00286 for (int ii=0; ii<numColumns; ii++)
00287 nextTable->columns[ii] = 0;
00288 nextTable->hasOutExtension = hasOutExtension;
00289
00290 if (nextTable->columns == 0) {
00291 opserr << "NEESData::createData - out of memory creating Table structure for table: " << copyTableName << endln;
00292 delete nextTable;
00293 res = -1;
00294 }
00295
00296 for (int k=0; k<numColumns; k++) {
00297
00298 nextTable->columns[k] = new char [strlen(columns[k])+1];
00299
00300 if (nextTable->columns[k] == 0) {
00301 opserr << "NEESData::createData - out of memory creating Table structure for table: " << copyTableName << endln;
00302 for (int l=0; l<k-1; l++)
00303 delete nextTable->columns[k];
00304 delete nextTable;
00305 res = -1;
00306 }
00307
00308 strcpy(nextTable->columns[k], columns[k]);
00309 }
00310
00311 nextTable->next = tables;
00312 tables = nextTable;
00313 numTables++;
00314
00315 return 0;
00316 }
00317
00318 int
00319 NEESData::insertData(const char *tableName, char *columns[],
00320 int commitTag, const Vector &data)
00321 {
00322
00323 NEES_table *t = tables;
00324 for (int i=0; i<numTables; i++) {
00325 if (strcmp(t->name, tableName) == 0)
00326 i = numTables;
00327 else
00328 t = t->next;
00329 }
00330
00331 if ( t == 0) {
00332 opserr << "NEESData::insertData - table: " << tableName << " has not been created\n";
00333 return -1;
00334 }
00335
00336 if (t->numColumns != data.Size()) {
00337 opserr << "NEESData::insertData - incorrect number of columns for table: " << tableName << "\n";
00338 return -2;
00339 }
00340
00341 char *fileName = t->name;
00342 if (t->hasOutExtension == false)
00343 strcat(fileName,".out");
00344
00345 ofstream table;
00346 table.open(fileName, ios::app);
00347
00348 table << setiosflags(ios::scientific);
00349 table << std::setprecision(16);
00350
00351 if (table.is_open()) {
00352
00353 for (int i=0; i<data.Size(); i++) {
00354 table << data(i) << "\t";
00355 }
00356
00357 table << "\n";
00358 table.close();
00359
00360 } else {
00361 opserr << "NEESData::insertData - failed to open file: " << fileName << endln;
00362 return -1;
00363 }
00364
00365 strcpy(fileName, tableName);
00366 return 0;
00367 }
00368
00369
00370 int
00371 NEESData::getData(const char *tableName, char *columns[], int commitTag, Vector &data)
00372 {
00373 return 0;
00374 }
00375