| 185 | |
| 186 | |
| 187 | int |
| 188 | NEESData::createTable(const char *tableName, int numColumns, char *columns[]) |
| 189 | { |
| 190 | // create a copy of the data file name |
| 191 | int res = 0; |
| 192 | int tableNameLength = strlen(tableName); |
| 193 | char *copyTableName = new char[tableNameLength + 5]; |
| 194 | char *fileName = new char[tableNameLength + 5]; |
| 195 | |
| 196 | bool hasOutExtension = false; |
| 197 | |
| 198 | if (fileName == 0 || copyTableName == 0) { |
| 199 | opserr << "NEESData::insertData - out of memory creating copy of string " << fileName << endln; |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | strcpy(copyTableName, tableName); |
| 204 | if (tableNameLength > 4 && strcmp(".out", &tableName[tableNameLength-4]) == 0) { |
| 205 | copyTableName[tableNameLength-4] = '\0'; |
| 206 | hasOutExtension = true; |
| 207 | } |
| 208 | |
| 209 | // first ensure createTable has not already been called with this table name |
| 210 | NEES_table *t = tables; |
| 211 | for (int i=0; i<numTables; i++) { |
| 212 | if (strcmp(t->name, tableName) == 0) { |
| 213 | opserr << "WARNING: NEESData::createTable - table already exists: " << copyTableName << endln; |
| 214 | return -1; |
| 215 | } |
| 216 | t = t->next; |
| 217 | } |
| 218 | |
| 219 | strcpy(fileName, copyTableName); |
| 220 | strcat(fileName,".out"); |
| 221 | |
| 222 | if (numColumns <= 0) { |
| 223 | opserr << "WARNING: NEESData::createTable - number of data columns < 0 for table name: " << copyTableName << endln; |
| 224 | delete [] fileName; |
| 225 | delete [] copyTableName; |
| 226 | return -1; |
| 227 | } |
| 228 | |
| 229 | // |
| 230 | // test opening the data file |
| 231 | // |
| 232 | |
| 233 | strcpy(fileName, copyTableName); |
| 234 | strcat(fileName,".out"); |
| 235 | |
| 236 | ofstream dataFile; |
| 237 | dataFile.open(fileName, ios::out | ios::trunc); |
| 238 | |
| 239 | if (!dataFile.is_open()) { |
| 240 | opserr << "NEESData::createTable - failed to open file: " << fileName << endln; |
| 241 | delete [] fileName; |
| 242 | delete [] copyTableName; |
| 243 | return -1; |
| 244 | } |