Process Column

Hello all,

Thanks for the help I got from y'all last time my code has worked perfectly.

I'm writing a simple code that will read in a number from "Numb_BBH.txt", given that number it will randomly pick said number of lines from "Realizations.txt" and have the output go into "Galaxy1.txt, Galaxy2.txt ...".

It has been working perfect, except I need it to only pick a line that has the value of the last column less than 2000.00

The second txt file is "Realizations.txt" is 32496 lines long, the following is the first line:

7.46506616E+31 6.93184332E+31 2.68544000E+10 1.14858511E-03 2.84023559E+17 2.68544205E+10

So If the last column has a value less than 2000.00 then choose the line and cout to output. Else cout a zeros.

The following is the code I have so far. I know the problem is in line 41, but I don't know how to make the if loop work.

Thanks everyone in advance :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdlib>
using namespace std;

int main(){
 ifstream file("N_testing.dat");
 //ifstream is("SpiralPeriods_TESTING.dat");
 //ifstream file("N0_populate_spiral_src.dat");
 //ifstream is("SpiralPeriods0.dat");
 ifstream is("EllipticalLISASources.dat");
 char c, d;
 char col1, col2, col3, col4, col5;
 int col6;
 //char col6;
 int x;
 string line;
 //string fileName="Galaxy";
 srand(time(0)); //seed for randomness

 //while (!is.eof()){
 int y=1;
 int num=0;
 while (file >> x) {
  stringstream ss;
  ss<<"Spiral_Galaxy_"<<y<<".txt";
  ofstream file2(ss.str().c_str());
  y++;
  for (int t = 1; t<=x; t++){
        while (c != '\n'){
                //is.seekg(rand()%32496);
                //is.seekg(rand()%100008511+1);
                is.seekg(rand()%379+1);
                c = is.get();
                //char col1, col2, col3, col4, col5;
                //int col6;
                c >> col1 >> col2 >> col3 >> col4 >> col5;
                c >> col6;
                // Here is where I'm having trouble continuing writing the line after the if loop
                int l = 2000.00;
                if (col6 >= l){

                //else{
                //cout << 0;
                }
                //if (c >> col6){
                //      col6 >= 2000;
                //}
                num++;
        }
        //getline(is,line);
        file2 << line << endl;
        //cout << line << endl; //Printing lines randomly from file.
        c = '0';
  }
  file2.close();
 }
 return 0;
}
What are you're doing on line 35?

What do you think lines 39 and 40 do? Do you get a compiler warning when you compile this?
Hi cire,

Line 35 is randomly grabbing a line from the EllipticalLISASources.dat file which has 379 lines, and throwing it to char c.

I thought that in line 39 I was separating the line into its different columns. and in line 40 it was throwing the last column into that col6 int.

I don't get any compiler errors. I only get blank lines in the output file, the Galaxy_1.txt and Galaxy_2.txt ...

Thanks you
JesusH1 wrote:
Line 35 is randomly grabbing a line from the EllipticalLISASources.dat file which has 379 lines, and throwing it to char c.

No, it's not. It's seeking to a random location within the first 380 bytes in the file. One shouldn't seekg to locations in text files that have not been returned by a call to tellg.

JesusH1 wrote:
I thought that in line 39 I was separating the line into its different columns. and in line 40 it was throwing the last column into that col6 int.
c is of type char. col1 is of type char. When you see c >> col1 it means shift the bits in c col1 bits to the right. Then you bitshift the result of that col2 bits to the right, and so on. Line 39 has no effect. Nor does line 40. They could be completely blank and they would have the same impact on your program.
OK so your saying to randomize multipels of bytes that make up a line? so if there are 6 floats then random multipels of 24? then use tellg to get that amout?
Topic archived. No new replies allowed.