[cig-commits] [commit] master: Added class for set of events (aa91080)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Oct 8 17:06:19 PDT 2014
Repository : https://github.com/geodynamics/vc
On branch : master
Link : https://github.com/geodynamics/vc/compare/23464fca3efa2b6ad7ee0ce8f60c225b18b49741...e4325192ad1118379f46ba66899cb98143d09e04
>---------------------------------------------------------------
commit aa91080e3404d0fca322a93d5a81fd3bc7ac75d2
Author: Eric Heien <emheien at ucdavis.edu>
Date: Thu Sep 25 17:39:48 2014 -0700
Added class for set of events
>---------------------------------------------------------------
aa91080e3404d0fca322a93d5a81fd3bc7ac75d2
quakelib/src/QuakeLibIO.cpp | 30 ++++++++++++++++++++++++++++++
quakelib/src/QuakeLibIO.h | 41 ++++++++++++++++++++++++-----------------
2 files changed, 54 insertions(+), 17 deletions(-)
diff --git a/quakelib/src/QuakeLibIO.cpp b/quakelib/src/QuakeLibIO.cpp
index 6e34fc5..6ba1ca2 100644
--- a/quakelib/src/QuakeLibIO.cpp
+++ b/quakelib/src/QuakeLibIO.cpp
@@ -2748,6 +2748,36 @@ void quakelib::ModelEvent::append_event_hdf5(const hid_t &data_file) const {
delete field_sizes;
}
+int quakelib::ModelEventSet::read_file_ascii(const std::string &event_file_name, const std::string &sweep_file_name) {
+ std::ifstream event_file, sweep_file;
+ ModelSweeps file_sweeps;
+
+ // Try to open the event file
+ event_file.open(event_file_name.c_str());
+ if (!event_file.is_open()) return -1;
+
+ // Try to open the sweeps file
+ sweep_file.open(sweep_file_name.c_str());
+ if (!sweep_file.is_open()) return -1;
+
+ // Keep going until we hit the end of either file
+ while (!event_file.eof() && !sweep_file.eof()) {
+ ModelEvent new_event;
+ ModelSweeps new_sweeps;
+ new_event.read_ascii(event_file);
+ unsigned int num_rec_sweeps = new_event.getNumRecordedSweeps();
+ new_sweeps.read_ascii(sweep_file, num_rec_sweeps);
+ new_event.setSweeps(new_sweeps);
+ _events.push_back(new_event);
+ }
+
+ // Close the files
+ event_file.close();
+ sweep_file.close();
+
+ return 0;
+}
+
namespace quakelib {
std::ostream &operator<<(std::ostream &os, const ModelSweeps &ms) {
os << "SWEEPS(" << ms._sweeps.size() << ")";
diff --git a/quakelib/src/QuakeLibIO.h b/quakelib/src/QuakeLibIO.h
index c94e9cd..e8a8f68 100644
--- a/quakelib/src/QuakeLibIO.h
+++ b/quakelib/src/QuakeLibIO.h
@@ -782,6 +782,9 @@ namespace quakelib {
_data._start_sweep_rec = start_sweep;
_data._end_sweep_rec = end_sweep;
}
+ unsigned int getNumRecordedSweeps(void) const {
+ return _data._end_sweep_rec - _data._start_sweep_rec;
+ };
double getShearStressInit(void) {
return _data._shear_stress_init;
};
@@ -906,24 +909,10 @@ namespace quakelib {
_total_slip.clear();
}
- /*iterator begin(void) {
- return _total_slip.begin();
- };
- iterator end(void) {
- return _total_slip.end();
- };
-
- EventSweeps::iterator sweepBegin(void) {
- return _event_sweeps.begin();
- };
- EventSweeps::iterator sweepEnd(void) {
- return _event_sweeps.end();
- };*/
-
#ifdef HDF5_FOUND
- static std::string hdf5_table_name(void) {
- return "events";
- };
+ static std::string hdf5_table_name(void) {
+ return "events";
+ };
#endif
static void get_field_descs(std::vector<FieldDesc> &descs);
static void write_ascii_header(std::ostream &out_stream);
@@ -938,6 +927,24 @@ namespace quakelib {
friend std::ostream &operator<<(std::ostream &os, const ModelEvent &me);
};
+
+ class ModelEventSet {
+ private:
+ std::vector<ModelEvent> _events;
+
+ public:
+ typedef std::vector<ModelEvent>::iterator iterator;
+ typedef std::vector<ModelEvent>::const_iterator const_iterator;
+
+ iterator begin(void) {
+ return _events.begin();
+ };
+ iterator end(void) {
+ return _events.end();
+ };
+
+ int read_file_ascii(const std::string &event_file_name, const std::string &sweep_file_name);
+ };
}
#endif
More information about the CIG-COMMITS
mailing list