libsequence  1.9.5
SimParams.cc
1 /*
2 
3 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5 Remove the brackets to email me.
6 
7 This file is part of libsequence.
8 
9 libsequence is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 libsequence is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #include <Sequence/SimParams.hpp>
25 #include <iostream>
26 #include <cctype>
27 #include <sstream>
28 
29 namespace Sequence
30 {
31  SimParams::SimParams (void):_command_line(""),_howmany(0),tsam(0)
32  {}
33 
34  int SimParams::fromfile ( FILE * openfile )
35  {
36  _command_line.clear();
37  _command_line.reserve(100);
38  int ch;
39  while( (ch=std::fgetc(openfile)) != EOF )
40  {
41  if (ch == '\n')
42  break;
43  else
44  _command_line += char(ch);
45  }
46  //some versions of ms output the values with
47  //which the RNG was seeded. This deals with those cases
48  while( (ch=std::fgetc(openfile)) != EOF )
49  {
50  if ((!isdigit(ch)&&!isspace(ch))|| ch=='\n')
51  break;
52  }
53  std::istringstream in(_command_line.c_str());
54  std::string ms;//for the program name...
55  in >> ms >> tsam >> _howmany;
56  return (ch);
57  }
58 
59  std::istream & SimParams::read (std::istream & s)
63  {
64  _command_line.clear();
65  char ch;
66  //read in the command line
67  while (s.get(ch))
68  {
69  if (ch == '\n')
70  {
71  break;
72  }
73  else
74  {
75  _command_line += ch;
76  }
77  }
78 
79  //some versions of ms output the values with
80  //which the RNG was seeded. This deals with those cases
81  // std::string seedline;
82  while (1)
83  {
84  s.get (ch);
85  if ((!isdigit(int(ch))&&!isspace(int(ch)))|| ch=='\n')
86  break;
87  // else
88  // seedline += ch;
89  }
90 
91  //open a stringstream to read the sample size and # runs
92  //from the command-line args
93  std::istringstream in(_command_line.c_str());
94  std::string ms;//for the program name...
95  in >> ms >> tsam >> _howmany;
96  return s;
97  }
98 
99  std::ostream & operator<< (std::ostream & stream, class SimParams & object)
105  {
106  stream << object._command_line;
107  return (stream);
108  }
109 
110  std::istream& operator>>(std::istream& s, SimParams& c)
116  {
117  return c.read (s);
118  }
119 }
Sequence::SimParams reads in the parameters of Dick Hudon&#39;s coalescent simulation program...
std::istream & read(std::istream &s)
Definition: SimParams.cc:59
Parameters for Hudson&#39;s simulation program.
Definition: SimParams.hpp:48
The namespace in which this library resides.
std::ostream & operator<<(std::ostream &s, const AlignStream< T > &c)
std::istream & operator>>(std::istream &s, AlignStream< T > &c)