DataOutputDatabaseHandler.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.2 $
00022 // $Date: 2004/11/24 22:40:16 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/handler/DataOutputDatabaseHandler.cpp,v $
00024                                                                         
00025 // Written: fmk 
00026 // Date: 10/04
00027 //
00028 // Description: This file contains the class implementation for
00029 // DataOutputDatabaseHandler. 
00030 //
00031 // What: "@(#) DataOutputDatabaseHandler.C, revA"
00032 
00033 #include "DataOutputDatabaseHandler.h"
00034 #include <FE_Datastore.h>
00035 #include <Vector.h>
00036 
00037 DataOutputDatabaseHandler::DataOutputDatabaseHandler(FE_Datastore *database, const char *tName)
00038   :DataOutputHandler(DATAHANDLER_TAGS_DataOutputDatabaseHandler),
00039    theDatabase(database), tableName(0), numColumns(0), columns(0), commitTag(0)
00040 {
00041   //
00042   // create memory to store the dataDescription and make a copy of it
00043   //
00044 
00045   if (tName != 0) {
00046     tableName = new char [strlen(tName)+1];
00047     strcpy(tableName, tName);
00048     if (tableName == 0) {
00049       opserr << "DataOutputDatabaseHandler::DataOutputDatabaseHandler - out of memory creating copy of tableName: " << tName << endln;
00050     }
00051   }
00052 }
00053 
00054 DataOutputDatabaseHandler::~DataOutputDatabaseHandler()
00055 {
00056   if (tableName != 0)
00057     delete [] tableName;
00058 
00059   if (columns != 0) {
00060     for (int j=0; j<numColumns; j++)
00061       delete [] columns[j];
00062     delete [] columns;
00063   }
00064 }
00065 
00066 int 
00067 DataOutputDatabaseHandler::open(char **dataDescription, int numData)
00068 {
00069   //
00070   // check the args are valid & that database has been set
00071   //
00072 
00073   if (theDatabase == 0) {
00074     opserr << "DataOutputStreamHandler::open() - database has not been set\n";
00075     return -1;
00076   } 
00077 
00078   if (tableName == 0) {
00079     opserr << "DataOutputDatabaseHandler::open() - no tableName passed or failed to get memory\n";
00080     return -1;
00081   }
00082 
00083   if (dataDescription == 0) {
00084     opserr << "DataOutputDatabaseHandler::open() - no column description data passed\n";
00085     return -1;
00086   }
00087 
00088   if (numData < 0) {
00089     opserr << "DataOutputDatabaseHandler::open() - numColumns (" << numData << ") < 0\n";
00090     return -1;
00091   } else
00092     numColumns = numData;
00093 
00094   //
00095   // remove old if open has already been called
00096   //
00097 
00098   if (columns != 0) {
00099     for (int j=0; j<numColumns; j++)
00100       delete [] columns[j];
00101     delete [] columns;
00102     columns = 0;
00103   }
00104 
00105   //
00106   // create memory to store the dataDescription and make a copy of it
00107   //
00108 
00109   columns = new char *[numColumns];
00110   if (columns == 0) {
00111     opserr << "DataOutputDatabaseHandler::open() - out of memory creating array for columns of size (" << numData << ") < 0\n";
00112     numColumns = 0;
00113     return -1;
00114   } 
00115 
00116   // make copy
00117   for (int i=0; i<numColumns; i++) {
00118     columns[i] = new char[strlen(dataDescription[i])+1];
00119     if (columns[i] == 0) {
00120       opserr << "DataOutputDatabaseHandler::open() - out of memory creating copy of string " << dataDescription[i] << endln;
00121       for (int j=0; j<i; j++)
00122         delete [] columns[j];
00123       delete [] columns;
00124       numColumns = 0;
00125       return -1;
00126     }
00127     strcpy(columns[i], dataDescription[i]);
00128   }
00129 
00130   // ask database to create a table
00131   return theDatabase->createTable(tableName, numColumns, columns);
00132 }
00133 
00134 int 
00135 DataOutputDatabaseHandler::write(Vector &data) 
00136 {
00137   int result = 0;
00138 
00139   if (data.Size() == numColumns)
00140     if (theDatabase != 0)
00141       result = theDatabase->insertData(tableName, columns, commitTag, data);
00142       else {
00143       opserr << "DataOutputStreamHandler::write() - database has not been set\n";
00144       return -1;
00145     } 
00146   else {
00147     opserr << "DataOutputStreamHandler::write() - Vector not of correct size or open() has not been called\n" << numColumns << " " << data.Size() << endln;
00148     return -1;
00149   }
00150 
00151   commitTag++;
00152 
00153   return result;
00154 }
00155 
00156 int 
00157 DataOutputDatabaseHandler::setDatabase(FE_Datastore &database, const char *tName)
00158 {
00159   if (tName == 0 || strlen(tName) == 0) {
00160     opserr << "DataOutputDatabaseHandler::DataOutputDatabaseHandler - no tableName passed\n";
00161     return -1;
00162   }
00163 
00164   if (tableName != 0)
00165     delete [] tableName;
00166   
00167   tableName = new char [strlen(tName)+1];
00168   strcpy(tableName, tName);
00169   if (tableName == 0) {
00170     opserr << "DataOutputDatabaseHandler::DataOutputDatabaseHandler - out of memory creating copy of tableName: " << tName << endln;
00171     return -1;
00172   }
00173 
00174   theDatabase = &database;
00175   return 0;
00176 }
00177 
00178 
00179 int 
00180 DataOutputDatabaseHandler::sendSelf(int commitTag, Channel &theChannel)
00181 {
00182   opserr << "DataOutputDatabaseHandler::sendSelf() - not yet implemented\n";
00183   return -1;
00184 }
00185 int 
00186 DataOutputDatabaseHandler::recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker)
00187 {
00188   opserr << "DataOutputDatabaseHandler::sendSelf() - not yet implemented\n";
00189   return -1;
00190 }

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