Overview
Comment:Updated to read recent struct.txt records which contain 6 fields.
Prepended std:: to iostream classes to satisfy g++.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 105ebebabdc1e2acc9497f9f852c22f12bc4c594e36f5c08ef2e19ee64e3f35d
User & Date: geraint@users.sourceforge.net on 2004-08-09 17:44:16
Other Links: branch diff | manifest | tags
Context
2004-08-09
17:45:56
cmath is preferred to math.h check-in: b22e319862 user: geraint@users.sourceforge.net tags: origin/master, trunk
17:44:16
Updated to read recent struct.txt records which contain 6 fields.
Prepended std:: to iostream classes to satisfy g++.
check-in: 105ebebabd user: geraint@users.sourceforge.net tags: origin/master, trunk
17:42:23
Updated to reflect new CR format: component type is passed as the first argument. check-in: 0aa1668692 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/lib/rep/cxxsim.cc from [5e41fc125d] to [e39d33615e].

13
14
15
16
17
18
19

20
21
22
23
24
25
26
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27







+







 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <string>

namespace cxxsim {

  class cr {
127
128
129
130
131
132
133

134
135
136
137
138
139
140
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142







+








    struct record {
      std::string	vec;	// vector: u, x, y, yz
      unsigned int	num;	// position of element in vector
      std::string	cmp;	// component
      std::string	fnm;	// full name
      unsigned int	rpt;	// number of repetitions
      std::string	cty;	// causality
    };

    typedef struct record record_t;
    std::list<record_t>			Lu;
    std::list<record_t>			Lx;
    std::list<record_t>			Ly;
    std::list<record_t>			Lyz;
187
188
189
190
191
192
193
194
195


196
197
198
199
200
201
202

203
204
205
206

207
208
209
210
211
212
213
189
190
191
192
193
194
195


196
197
198
199
200
201
202
203

204
205
206
207

208
209
210
211
212
213
214
215







-
-
+
+






-
+



-
+







    
    char				c;
    std::string				s;
    std::string				t;

    unsigned int			i;

    //    file.unsetf(ios::skipws);
    file.setf(ios::skipws);
    //    file.unsetf(std::ios::skipws);
    file.setf(std::ios::skipws);

    // read lines from file (no max length, unlike std::getline)
    while (file >> c){
      s = "";
      while (c != ';' && file){
	if (c == '%'){
	  file.unsetf(ios::skipws);
	  file.unsetf(std::ios::skipws);
	  while ((c != '\n') && file){
	    file >> c;			     // eat comment
	  }
	  file.setf(ios::skipws);
	  file.setf(std::ios::skipws);
	} else {
	  if ((c != ' ') && (c != '\t')){    // strip whitespace
	    s += c;
	  }
	  file >> c;
	}
      }
400
401
402
403
404
405
406
407

408
409
410
411
412

413
414
415
416
417
418
419
402
403
404
405
406
407
408

409
410
411
412
413

414
415
416
417
418
419
420
421







-
+




-
+







  };

  void
  parameter::read (std::ifstream &file){
    record_t r;
    while (file >> r.variable >> r.component){
      if (r.variable.find("#") == 0){
	file.unsetf(ios::skipws);
	file.unsetf(std::ios::skipws);
	char c = '\0';
	while (c != '\n'){
	  file >> c;
	}
	file.setf(ios::skipws);
	file.setf(std::ios::skipws);
      } else {
	L.push_back(r);
      }
    }
  }

  void
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483







-
+







  void
  structure::read (std::ifstream &file){
    std::list<record_t> *p;
    record_t r;
    if (! file){
      std::cerr << "warning: no structure data found (empty file)" << std::endl;
    }
    while (file >> r.vec >> r.num >> r.cmp >> r.fnm >> r.rpt){
    while (file >> r.vec >> r.num >> r.cmp >> r.fnm >> r.rpt >> r.cty){
      if (r.vec == "input"){
	p = &(this->Lu);
      } else if (r.vec == "state"){
	p = &(this->Lx);
      } else if (r.vec == "output"){
	p = &(this->Ly);
      } else {
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649
650

651
652
653
654

655
656
657
658
659
660
661
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651

652
653
654
655

656
657
658
659
660
661
662
663







-
+








-
+



-
+







	      << "  for (mttt = 0.0; mttt <= 10.0; mttt += mttdt){"		<< std::endl
	      << std::endl
	      << "    // get inputs and rates"					<< std::endl
	      << "    " << system_name << "_input(mttt,mttu,mttx,mtty);"	<< std::endl
	      << "    " << system_name << "_ode(mttt,mttu,mttx,mttdx,mtty);"	<< std::endl
	      << std::endl
	      << "    // integrate states (euler)"				<< std::endl
	      << "    for (i = 1; i < mttNx; i++){"				<< std::endl
	      << "    for (i = 1; i <= mttNx; i++){"				<< std::endl
	      << "      mttx[i] += mttdx[i] * mttdt;"				<< std::endl
	      << "    }"							<< std::endl
	      << std::endl
	      << "    // overwrite switch states"				<< std::endl
	      << "    " << system_name << "_logic(mttt,mttu,mttx,mttdx,mtty);"	<< std::endl
	      << std::endl
	      << "    // write: time outputs time states"			<< std::endl
	      << "    std::cout << mttt << '\\t';"				<< std::endl
	      << "    for (i = 1; i < mttNy; i++){"				<< std::endl
	      << "    for (i = 1; i <= mttNy; i++){"				<< std::endl
	      << "      std::cout << mtty[i] << ' ';"				<< std::endl 
	      << "    }"							<< std::endl
	      << "    std::cout << '\\t' << mttt;"				<< std::endl
	      << "    for (i = 1; i < mttNx; i++){"				<< std::endl
	      << "    for (i = 1; i <= mttNx; i++){"				<< std::endl
	      << "      std::cout << ' ' << mttx[i];"				<< std::endl 
	      << "    }"							<< std::endl
	      << "    std::cout << std::endl;"					<< std::endl
	      << "  }"								<< std::endl
	      << "  return 0;"							<< std::endl
	      << "}"								<< std::endl;


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]