Flip odd profiles

From this file I want to pullout sections of the stream reverse them
and put the list back into the stream

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
80.77929 240.4816
79.20770 239.0709
77.62594 237.6511
83.89242 234.5288
83.89242 232.7794
85.43414 230.7089
85.43414 228.9650
79.20770 228.4730
80.77929 226.3963
89.24594 222.9945
88.48840 221.4085
90.00109 219.3933
90.00109 217.6659
91.50430 215.6688
90.75387 214.0787
91.50430 212.2248
92.99810 210.2510
92.99810 208.5344
92.99810 206.8178
94.48257 204.8670
94.48257 203.1557
94.48257 201.4445
94.48257 199.7332
95.22134 197.9161
95.95782 196.1046
95.95782 194.3987
95.95782 192.6927
95.95782 190.9868
95.95782 189.2809
95.95782 187.5750
95.95782 185.8690
95.95782 184.1631
95.95782 182.4572
97.42392 180.5940
97.42392 178.8933
97.42392 177.1927
97.42392 175.4920
97.42392 173.7914
95.95782 172.2216
95.95782 170.5157
95.95782 168.8098
95.95782 167.1038
95.95782 165.3979
95.95782 163.6920
95.95782 161.9861
94.48257 160.3746
94.48257 158.6633
94.48257 156.9521
92.99810 155.3198
92.99810 153.6032



Here is my coding I am getting lost when trying to assign the section
of the stream to the list.

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

//The objective is to pull out a series of numbers from an file stream
// into a list and then reverse the numbers before putting them back into
// the stream, then jump over the next profile onto the next odd profile
// e.g jump values 6,7,8,9,10 and make the next list from element ax[11]
// and so on. Then do the same for the ay co-ordinates.

#include <iostream>
#include <fstream>
#include <list>


using namespace std;


float array[50][2];
float ax[50];
float ay[50];
int i;
int j;

float* X0 = &ax[0];                                // declare pointer
float* Y0 = &ay[0];                                // declare pointer

int main()
{
        ifstream in_file("C:\\bust\\fliptest.txt"); //get the file stream

    if(!in_file.is_open()) {
        cout<<"File not opened"<<"\n";
        return 1;
    }
    for(i=0;i<50;i++) {                           //turn the stream into an array
       for(j=0;j<2;j++) {
        in_file >> array[i][j];
       }
    }

    for(i=0; i<50; i++){                         // pull out the X co-ordinate from the
        for(j=0; j<1; j++){                      // array
            ax[i] = array[i][j];
        }
    }
    for(i=0; i<50; i++){                        // pull out the Y co-ordinate from the
       for(j=1; j<2; j++){                      // array
            ay[i] = array[i][j];
        }
    }



    std::list<float>profile_X;                // set up a list

    for(i=0; i<9; i++){                       // loop through the file

       for(i=0; i<5; i++){                    // loop through to fill the list

    profile_X.push_back(i)= X0;              // start the list from ax[0] element
                                             // and for 5 elements upto ax[4]
    }

    profile_X.reverse();                       // reverse the list

   for (std::list<float>::iterator it=profile_X.begin(); it!=profile_X.end(); ++it)

   std::cout << ' ' << *it;                    // check the list has been reveresed

         X0 = X0 + 5;                          // increament forward 5 elements to the
                                               // start of the next list
    }

         return 0 ;

}



There is beer on offer here :-).

Peter
I'd suggest that you use a vector instead of a list. But it's supposed to work with list too.

A reverse function exists (just a bit different):

http://www.cplusplus.com/reference/algorithm/reverse/?kw=reverse
Hi,

Please refer to the bolded line code

1
2
3
4
5
6
7
8
9
10
11

 std::list<float>profile_X;                // set up a list

    for(i=0; i<9; i++){                       // loop through the file

       for(i=0; i<5; i++){                    // loop through to fill the list

    profile_X.push_back(X0[i]);              // start the list from ax[0] element
                                             // and for 5 elements upto ax[4]
    }
Hi NVTKrishna

Thank you I have seen it and will try your addition.

Peter
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

    std::list<float>profile_X;                // set up a list profile_X
    std::list<float>profile_Y;                // set up a list profile_Y

       for(i=0; i<5; i++){                    // loop through to fill the list

    profile_X.push_back( X0 [i]);              // start the list from ax[0] element
                                               // and for 5 elements upto ax[4]
    }
    profile_X.reverse();                       // reverse the lis

   for (std::list<float>::iterator it=profile_X.begin(); it!=profile_X.end(); ++it)

    fout << *it<<"\n";                         // check numbers reversed

       for(i=0; i<5; i++){                    // loop through to fill the list

    profile_Y.push_back( Y0 [i]);              // start the list from ay[0] element
                                               // and for 5 elements upto ay[4]
    }

    profile_Y.reverse();                       // reverse the list

   for (std::list<float>::iterator it=profile_Y.begin(); it!=profile_Y.end(); ++it)

    fout << *it<<"\n";                         //// check numbers reversed


         return 0 ;

}



output

83.8924
83.8924
77.6259
79.2077
80.7793
232.779
234.529
237.651
239.071
240.482


I would like this though

83.8924 232.779
83.8924 234.529
77.6259 237.651
79.2077 239.071
80.7793 240.482
Topic archived. No new replies allowed.