#ifndef _EVENTVARVECT_H_ #define _EVENTVARVECT_H_ // // $Id$ //----------------------------------------------------------------------- // // (c) Copyright 2006 by GATS, Inc., // 11864 Canon Blvd, Suite 101, Newport News VA 23606 // // All Rights Reserved. No part of this software or publication may be // reproduced, stored in a retrieval system, or transmitted, in any form // or by any means, electronic, mechanical, photocopying, recording, or // otherwise without the prior written permission of GATS, Inc. // //----------------------------------------------------------------------- // // Module: EventVarVect.h // // Author: John Burton // // Date: Mon May 1 14:35:09 2006 // //----------------------------------------------------------------------- // // Modification History: // // $Log$ // //----------------------------------------------------------------------- // //----------------------------------------------------------------------- // Include Files: //----------------------------------------------------------------------- // #include "EventVar.h" #include "GracePlot.h" // //----------------------------------------------------------------------- // Class EventVarVect: //----------------------------------------------------------------------- // //! //! EventVarVect is derived from the STL vector and provides a vector of EventVars. //! This provides the ability to have multiple 1-D eventVars associated with the same name //! template class EventVarVect: public std::vector *>{ private: std::string Name; //!< Name of the Variable - will be used by Event object std::string Description; //!< Long description of Variable - will be used for plotting void PlotVars(gracesc::Xmgrace &graph); //!< Plots the data of the EventVar objects contained in the EventVarVect. void PlotVars(gracesc::Xmgrace &graph, EventVar<_Tp>& xvar); //!< Plots the data of the EventVar objects contained in the EventVarVect. public: EventVarVect() : std::vector *>(){}; //!< default constructor - Constructs an empty EventVar object EventVarVect(const EventVarVect &vec); EventVarVect(const std::string name); //!< Construct an empty EventVarVect object and initializes the property Name //!< @param name - a string containing the name of the EventVarVect object EventVarVect(const std::string name, const std::string desc); //!< Construct an empty EventVarVect object and initializes the property Name //!< @param name - a string containing the name of the data in EventVarVect //!< @param desc - long (multi-word) description of the data in EventVarVect virtual ~EventVarVect(); //!< Destructor - delete the EventVarVect object void clear(); //!< clear the EventVarVect object void addEventVar(EventVar<_Tp>& EV); //!< Creates a copy of the EventVar EV on the heap and adds the pointer //!< to the copy to the EventVarVect object void addEventVar(const EventVar<_Tp>& EV); //!< Creates a copy of the EventVar EV on the heap and adds the pointer //!< to the copy to the EventVarVect object void addEventVar(EventVar<_Tp>* EV); //!< Adds the pointer to the EventVar EV to the EventVarVect object void insertEventVar(EventVar<_Tp>* EV); void setName(const std::string name) {Name = name;} //!< Initializes the EventVarVect Name property //!< @param name - a string containing the name of the data in EventVarVect void setDescription(const std::string desc) {Description = desc;} //!< Initializes the EventVarVect Description property //!< @param desc - long (multi-word) description of the data in EventVarVect /// Assignment operator that assigns the values in a valarray to /// the data elements of EventVar EventVarVect<_Tp>& operator = (const EventVarVect<_Tp>& a); /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (unsigned int i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (int i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (unsigned int i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (int i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (unsigned long i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (long i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (unsigned long i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (long i) {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (unsigned int i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (int i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (unsigned int i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (int i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (unsigned long i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator [] (long i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (unsigned long i) const {return *this->at(i);} /// Index operator that returns the EventVar located at index i /// @param i - index into the EventVarVect vector EventVar<_Tp>& operator () (long i) const {return *this->at(i);} std::string getName() {return Name;} //!< Returns the value of the EventVarVect Name property std::string getDescription() {return Description;} //!< Returns the value of the EventVarVect Description property void PrintEventVarVect(); //!< Prints the properties of the EventVarVect object. First it prints the \c Name //!< and \c Description properties and then iterates through the EventVarVect //!< doing a \c PrintVarProperties() for each EventVar EventVarVect<_Tp> VInterpol(EventVar<_Tp>& xin, EventVar<_Tp>& xout); //!< Interpolates each of the EventVar objects contained in this //!< EventVarVect based on \c xin and \c xout //!< @param xin - input x variable for which the contained EventVar objects //!< represent the y variables //!< @param xout - output x grid that the contained EventVar objects are //!< to be interpolated to void Plot(); //!< Plots the data of the EventVar objects contained in the EventVarVect. void Plot(std::string Title, std::string SubTitle); //!< Plots the data of the EventVar objects contained in the EventVarVect. void Plot(std::string Title, std::string SubTitle, EventVar<_Tp>& xvar); //!< Plots the data of the EventVar objects contained in the EventVarVect. EventVarVect<_Tp> Transpose(); }; // //----------------------------------------------------------------------- // Method Definitions: //----------------------------------------------------------------------- // template inline EventVarVect<_Tp>::EventVarVect(const EventVarVect<_Tp> &vec) : std::vector *>() { int i; Name = vec.Name; Description = vec.Description; for(i=0;iaddEventVar(vec.at(i)); } template inline EventVarVect<_Tp>::EventVarVect(const std::string name) : std::vector *>() { Name = name; } template inline EventVarVect<_Tp>::EventVarVect(const std::string name, const std::string desc) : std::vector *>() { Name = name; Description = desc; } template inline void EventVarVect<_Tp>::clear() { unsigned int i; EventVar<_Tp> *ev; Name = ""; Description = ""; for(i=0;isize();i++) { ev = this->at(i); delete ev; // ev->EventVar<_Tp>::~EventVar(); this->at(i) = NULL; } std::vector *>::clear(); } template inline EventVarVect<_Tp>::~EventVarVect() { unsigned int i; EventVar<_Tp> *ev; for(i=0;isize();i++) { ev = this->at(i); // ev->EventVar<_Tp>::~EventVar(); delete ev; this->at(i) = NULL; } std::vector *>::clear(); } template inline void EventVarVect<_Tp>::addEventVar(EventVar<_Tp>& EV) { std::string name; EventVar<_Tp> *tmp; tmp = new EventVar<_Tp>(EV); name = EV.getName(); this->push_back(tmp); } template inline void EventVarVect<_Tp>::addEventVar(const EventVar<_Tp>& EV) { std::string name; EventVar<_Tp> *tmp; tmp = new EventVar<_Tp>(EV); name = EV.getName(); this->push_back(tmp); } template inline void EventVarVect<_Tp>::addEventVar(EventVar<_Tp>* EV) { std::string name; EventVar<_Tp> *tmp; tmp = new EventVar<_Tp>(*EV); name = EV->getName(); this->push_back(tmp); } template inline void EventVarVect<_Tp>::insertEventVar(EventVar<_Tp>* EV) { std::string name; this->push_back(EV); } template inline void EventVarVect<_Tp>::PrintEventVarVect(void) { int i; EventVar<_Tp> *ev; std::cerr << "EventVarVect::PrintEventVarVect()\n"; std::cerr << "EventVarVect Name = " << Name << "\n"; std::cerr << "EventVarVect Description = " << Description << "\n"; std::cerr << "EventVar Properties:\n"; for(i=0;isize();i++) { ev = this->at(i); ev->PrintVar(); std::cerr << "---------------------------------------------------------------\n"; } } template inline EventVarVect<_Tp> EventVarVect<_Tp>::VInterpol(EventVar<_Tp>& xin, EventVar<_Tp>& xout) { int i,j, len,nl; EventVar<_Tp> *ev,tmp; EventVarVect<_Tp> yout; yout.Name = this->Name; yout.Description = this->Description; nl = ev->size(); len = this->size(); for(i=0;iat(i); tmp = ev->VInterpol(xin,xout); yout.addEventVar(tmp); // delete ev; } return yout; } template inline void EventVarVect<_Tp>::PlotVars(gracesc::Xmgrace &graph) { int i,j, len,nl; EventVar<_Tp> *ev; ev = this->at(0); nl = ev->size(); len = this->size(); // gracesc::Xmgrace graph(1); for(i=0;iat(i); nl = (nl < ev->size()) ? nl : ev->size(); } for(j=0;jat(i); graph[0] << (*ev)[j]; } graph[0] << gracesc::endl; } graph[0].draw(); graph[0].Set_legend_location("1.0","0.8"); for(i=0;iat(i); graph[0].SetLegend(i,ev->getName()); } graph[0].autoscale(); graph[0].timestamp(); graph.redraw(); } template inline void EventVarVect<_Tp>::PlotVars(gracesc::Xmgrace &graph, EventVar<_Tp>& xvar) { int i,j, len,nl; EventVar<_Tp> *ev; nl = xvar.size(); len = this->size(); // gracesc::Xmgrace graph(1); for(i=0;iat(i); nl = (nl < ev->size()) ? nl : ev->size(); } for(j=0;jat(i); graph[0] << (*ev)[j]; } graph[0] << gracesc::endl; } graph[0].draw(); graph[0].Set_legend_location("1.0","0.8"); for(i=0;iat(i); graph[0].SetLegend(i,ev->getName()); } graph[0].autoscale(); graph[0].timestamp(); graph.redraw(); } template inline void EventVarVect<_Tp>::Plot(void) { gracesc::Xmgrace graph(1); std::string xlabel = "Index"; std::string ylabel = Description; PlotVars(graph); // graph[0].Display_titles(Title,SubTitle,xlabel,ylabel); graph.redraw(); } template inline void EventVarVect<_Tp>::Plot(std::string Title, std::string SubTitle) { gracesc::Xmgrace graph(1); std::string xlabel = "Index"; std::string ylabel = Description; PlotVars(graph); graph[0].Display_titles(Title,SubTitle,xlabel,ylabel); graph.redraw(); } template inline void EventVarVect<_Tp>::Plot(std::string Title, std::string SubTitle, EventVar<_Tp>& xvar) { gracesc::Xmgrace graph(1); std::string xlabel = xvar.getDescription() + " (" + xvar.getUnits() + ")"; std::string ylabel = Description; PlotVars(graph,xvar); // graph[0].Scale_xAxis(0,xvar.getAxisRange()[0],xvar.getAxisRange()[1]); graph[0].autoscale(); graph[0].Display_titles(Title,SubTitle,xlabel,ylabel); graph.redraw(); } template inline EventVarVect<_Tp>& EventVarVect<_Tp>::operator = (const EventVarVect<_Tp>& a) { int i; // EventVarVect<_Tp> b(a); this->clear(); Name = a.Name; Description = a.Description; // std::vector >::operator=(a); for(i=0;iaddEventVar(a.at(i)); return *this; } template inline EventVarVect<_Tp> EventVarVect<_Tp>::Transpose(void) { EventVarVect<_Tp> evv; int n1 = this->size(); int n2 = (*this)[0].size(); EventVar<_Tp> ev(n1); for(int i=0; i