Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

READING DATA IN BEATS

Status
Not open for further replies.

lehloks

Programmer
Jul 12, 2013
40
ZA
Hi forum users

I have this piece of code which reads data from a large file. Now I want your help,I would like to read the data in beats say read the fist 5 steps,then the next 5 steps but the data must be on the same file and in sequence. Before I read the first 5 step I must add a label indicating step1, then read the 5 beats of data then add data label step2 then read data, and so on.

I should look something like this
Step1
data
Step2
data
Step3
data
...
Step..n
data..n

The current code reads the data at once!



Code:
program read_data
implicit none
integer stepno, arrsize
real steptime, datum, datum_1,datum_2,datum_3,datum_4,datum_5,datum_6, &
     datum_7,datum_8
real, allocatable :: array(:)
real, allocatable :: charge(:)
integer, parameter:: iunit=20

open(iunit,file='STATIS',status='old')
read(iunit,*)
read(iunit,*)
do
   read(iunit,*,end=10) &
   stepno,steptime,arrsize
   allocate(array(arrsize))
   read(iunit,*, end=10) array
   datum = array(33)
   datum_1 =array(34)
   datum_2 =array(35)
   datum_3 =array(36)
   datum_4 =array(37)
   datum_5 =array(38)
   datum_6 =array(39)
   datum_7 =array(40)
   datum_8 =array(41)
   write(*,*) steptime,datum,datum_1,datum_2,datum_3,datum_4,datum_5,datum_6, &
   datum_7,datum_8

   deallocate(array)
end do
10 continue
close(iunit)
end program read_data


[Data]
MgSiO3 Perovskite using Alison Wall model
ENERGY UNITS=electron Volts
10 1.000000E-02 48
-4.342202E+04 2.745104E+03 -4.403020E+04 8.879340E+03 -5.290954E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.341588E+04
0.000000E+00 1.197946E+03 -5.170810E+04 5.290605E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.688629E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 5.751242E-01 0.000000E+00 0.000000E+00 0.000000E+00
2.929603E+00 3.688254E+00 -1.829384E+00 3.688254E+00 1.754018E+00
8.892383E-01 -1.829384E+00 8.892383E-01 -2.958248E+00 2.565536E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.565536E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.565536E+01
20 2.000000E-02 48
-4.342063E+04 2.662520E+03 -4.401051E+04 8.932975E+03 -5.294349E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.337687E+04
0.000000E+00 1.048502E+03 -5.189159E+04 5.294009E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.689234E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 4.096082E+00 0.000000E+00 0.000000E+00 0.000000E+00
3.605396E+00 3.817738E+00 -1.588635E+00 3.817738E+00 7.371576E+00
-6.543485E-01 -1.588635E+00 -6.543485E-01 1.311275E+00 2.565842E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.565842E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.565842E+01
30 3.000000E-02 48
-4.340100E+04 2.750015E+03 -4.401028E+04 8.931365E+03 -5.294164E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.334942E+04
0.000000E+00 1.063785E+03 -5.187443E+04 5.293822E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.690591E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 4.825026E+00 0.000000E+00 0.000000E+00 0.000000E+00
1.388851E+00 6.071435E+00 6.222573E-01 6.071435E+00 7.364409E+00
-1.988894E+00 6.222573E-01 -1.988894E+00 5.721819E+00 2.566529E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.566529E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.566529E+01
40 4.000000E-02 48
-4.340071E+04 2.726387E+03 -4.400475E+04 8.893358E+03 -5.289811E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.338372E+04
0.000000E+00 1.157086E+03 -5.173744E+04 5.289453E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.691463E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 1.588967E+00 0.000000E+00 0.000000E+00 0.000000E+00
-2.691109E+00 7.424682E+00 4.256815E+00 7.424682E+00 5.195487E+00
-3.658003E+00 4.256815E+00 -3.658003E+00 2.262524E+00 2.566970E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.566970E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.566970E+01
50 5.000000E-02 48
-4.339559E+04 2.803722E+03 -4.401676E+04 8.856416E+03 -5.287318E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.340127E+04
0.000000E+00 1.259382E+03 -5.161026E+04 5.286964E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.691643E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 -5.307975E-01 0.000000E+00 0.000000E+00 0.000000E+00
-4.339224E+00 3.178968E+00 1.650271E-01 3.178968E+00 1.982409E+00
-3.321507E-01 1.650271E-01 -3.321507E-01 7.644225E-01 2.567061E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.567061E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.567061E+01
60 6.000000E-02 48
-4.340740E+04 2.641404E+03 -4.399261E+04 8.871264E+03 -5.286388E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.343189E+04
0.000000E+00 1.243870E+03 -5.161652E+04 5.286038E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.691200E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 -2.289050E+00 0.000000E+00 0.000000E+00 0.000000E+00
-8.008839E+00 1.749894E+00 9.809765E-01 1.749894E+00 1.376657E+00
-3.355454E+00 9.809765E-01 -3.355454E+00 -2.349680E-01 2.566837E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.566837E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.566837E+01
70 7.000000E-02 48
-4.338339E+04 2.772948E+03 -4.399775E+04 8.878612E+03 -5.287636E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.337333E+04
0.000000E+00 1.198542E+03 -5.167445E+04 5.287299E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.691060E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 9.402781E-01 0.000000E+00 0.000000E+00 0.000000E+00
-3.648047E+00 3.260050E-01 3.159112E+00 3.260050E-01 3.135602E+00
1.086856E+00 3.159112E+00 1.086856E+00 3.333279E+00 2.566766E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.566766E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.566766E+01
80 8.000000E-02 48
-4.338830E+04 2.730652E+03 -4.399329E+04 8.935455E+03 -5.292874E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.334711E+04
0.000000E+00 1.086382E+03 -5.183880E+04 5.292518E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.691691E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 3.850525E+00 0.000000E+00 0.000000E+00 0.000000E+00
2.888392E+00 4.780251E+00 -1.044040E+00 4.780251E+00 4.001642E+00
2.181758E+00 -1.044040E+00 2.181758E+00 4.661541E+00 2.567086E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.567086E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.567086E+01
90 9.000000E-02 48
-4.338385E+04 2.786654E+03 -4.400124E+04 8.913111E+03 -5.291435E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.334849E+04
0.000000E+00 1.128712E+03 -5.178208E+04 5.291079E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.692666E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 3.302934E+00 0.000000E+00 0.000000E+00 0.000000E+00
6.592381E+00 8.515005E+00 -4.749211E-01 8.515005E+00 -1.289925E+00
2.917594E+00 -4.749211E-01 2.917594E+00 4.606346E+00 2.567579E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.567579E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.567579E+01
100 1.000000E-01 48
-4.339182E+04 2.735197E+03 -4.399781E+04 8.938879E+03 -5.293669E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.335158E+04
0.000000E+00 1.091287E+03 -5.184184E+04 5.293312E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.693403E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 3.756643E+00 0.000000E+00 0.000000E+00 0.000000E+00
9.510231E+00 7.369906E+00 -5.079313E-02 7.369906E+00 -2.826299E+00
1.206644E-02 -5.079313E-02 1.206644E-02 4.585997E+00 2.567951E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.567951E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.567951E+01
110 1.100000E-01 48
-4.338833E+04 2.770362E+03 -4.400211E+04 8.934787E+03 -5.293690E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.334443E+04
0.000000E+00 1.095865E+03 -5.183735E+04 5.293321E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.694582E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 4.096304E+00 0.000000E+00 0.000000E+00 0.000000E+00
5.675703E+00 4.261052E+00 -1.856161E+00 4.261052E+00 1.117220E+00
-5.114345E-01 -1.856161E+00 -5.114345E-01 5.495990E+00 2.568547E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.568547E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.568547E+01
120 1.200000E-01 48
-4.339271E+04 2.753539E+03 -4.400276E+04 8.869902E+03 -5.287266E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.339465E+04
0.000000E+00 1.225934E+03 -5.164312E+04 5.286906E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.694984E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 -1.811241E-01 0.000000E+00 0.000000E+00 0.000000E+00
-4.790543E+00 -1.927001E+00 -2.845512E+00 -1.927001E+00 2.023010E+00
-8.144502E-02 -2.845512E+00 -8.144502E-02 2.224161E+00 2.568750E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.568750E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.568750E+01
130 1.300000E-01 48
-4.339347E+04 2.752278E+03 -4.400325E+04 8.941813E+03 -5.294506E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.334389E+04
0.000000E+00 1.070812E+03 -5.187048E+04 5.294130E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.695386E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 4.624118E+00 0.000000E+00 0.000000E+00 0.000000E+00
-3.211007E+00 -3.316756E+00 -1.974711E+00 -3.316756E+00 8.701281E+00
2.452575E+00 -1.974711E+00 2.452575E+00 8.382080E+00 2.568953E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.568953E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.568953E+01
140 1.400000E-01 48
-4.339367E+04 2.761503E+03 -4.400549E+04 8.908368E+03 -5.291385E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.337046E+04
0.000000E+00 1.154019E+03 -5.175581E+04 5.290983E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.696560E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 2.162902E+00 0.000000E+00 0.000000E+00 0.000000E+00
-5.754450E+00 2.772456E+00 -2.350762E+00 2.772456E+00 7.207171E+00
-3.098741E-01 -2.350762E+00 -3.098741E-01 5.035983E+00 2.569546E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.569546E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.569546E+01
150 1.500000E-01 48
-4.339645E+04 2.803014E+03 -4.401746E+04 8.812663E+03 -5.283012E+04
0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -4.344678E+04
0.000000E+00 1.393028E+03 -5.143326E+04 5.282629E+04 0.000000E+00
0.000000E+00 0.000000E+00 0.000000E+00 1.696187E+04 0.000000E+00
0.000000E+00 0.000000E+00 9.000000E+01 9.000000E+01 9.000000E+01
0.000000E+00 -4.692047E+00 0.000000E+00 0.000000E+00 0.000000E+00
-8.032210E+00 1.587956E+00 -2.106394E+00 1.587956E+00 7.552222E-02
-4.371547E+00 -2.106394E+00 -4.371547E+00 -6.119453E+00 2.569358E+01
0.000000E+00 0.000000E+00 0.000000E+00 2.569358E+01 0.000000E+00
0.000000E+00 0.000000E+00 2.569358E+01
160 1.600000E-01 48


[/]
 
... I would like to read the data in beats say read the fist 5 steps...
what you mean with a beat and what with a step?

Before I read the first 5 step I must add a label indicating step1, then read the 5 beats of data then add data label step2 then read data, and so on.
Don't understand. Where you want to add a label?
 
Hi Mikrom
I want to add the label before I read the data such as

Label 1
data
Label 2
data
Label 3
data
...

...
Label..n
data ..n

Best regards
Lehloks
 
But where you want to add the labels? To the file with the data?
 
Hi Mikrom

I want to add the label at the top left conner of the data as shown below:

[]
STEP1
10000.100 0.62234730 -3.6641850 2.4883280 -3.6641850 1.8993200 0.29834500 2.4883280 0.29834500 3.0102229
10000.200 -1.7910060 0.15255409 1.6537470 0.15255409 -3.6363189 2.7032411 1.6537470 2.7032411 4.9755712
10000.300 -0.31293780 -3.6637239 1.6561610 -3.6637239 -4.1280112 -2.0438321 1.6561610 -2.0438321 3.2798519
10000.400 -6.4509192 -3.7080820 -2.6110699 -3.7080820 -5.6932492 0.44605070 -2.6110699 0.44605070 1.6073290
10000.500 3.1462791 -0.56442529 0.52846128 -0.56442529 -4.6423979 1.2161140 0.52846128 1.2161140 4.0431032
10000.600 4.8732929 2.1838751 6.15512393E-03 2.1838751 5.3250189 -4.93021086E-02 6.15512393E-03 -4.93021086E-02 1.0123240
10000.700 -1.3533940 2.3333621 4.4080052 2.3333621 -4.2695279 -0.75997698 4.4080052 -0.75997698 -4.3540859
10000.800 -4.8135672 -2.6035140 -0.21469951 -2.6035140 3.1690519 -3.6204469 -0.21469951 -3.6204469 -7.2280278
10000.900 -3.8826640 1.0258610 6.7142401 1.0258610 -4.1984720 1.2173650 6.7142401 1.2173650 -1.3499670
10001.000 8.2251139 -1.2880760 -4.1206179 -1.2880760 8.2421551 1.4846520 -4.1206179 1.4846520 -1.3953760
10001.100 -0.42780939 0.13022810 -1.92078501E-02 0.13022810 4.5270901 -1.2878300 -1.92078501E-02 -1.2878300 0.85644352

Step2
10000.100 0.62234730 -3.6641850 2.4883280 -3.6641850 1.8993200 0.29834500 2.4883280 0.29834500 3.0102229
10000.200 -1.7910060 0.15255409 1.6537470 0.15255409 -3.6363189 2.7032411 1.6537470 2.7032411 4.9755712
10000.300 -0.31293780 -3.6637239 1.6561610 -3.6637239 -4.1280112 -2.0438321 1.6561610 -2.0438321 3.2798519
10000.400 -6.4509192 -3.7080820 -2.6110699 -3.7080820 -5.6932492 0.44605070 -2.6110699 0.44605070 1.6073290
10000.500 3.1462791 -0.56442529 0.52846128 -0.56442529 -4.6423979 1.2161140 0.52846128 1.2161140 4.0431032
10000.600 4.8732929 2.1838751 6.15512393E-03 2.1838751 5.3250189 -4.93021086E-02 6.15512393E-03 -4.93021086E-02 1.0123240
10000.700 -1.3533940 2.3333621 4.4080052 2.3333621 -4.2695279 -0.75997698 4.4080052 -0.75997698 -4.3540859
10000.800 -4.8135672 -2.6035140 -0.21469951 -2.6035140 3.1690519 -3.6204469 -0.21469951 -3.6204469 -7.2280278
10000.900 -3.8826640 1.0258610 6.7142401 1.0258610 -4.1984720 1.2173650 6.7142401 1.2173650 -1.3499670
10001.000 8.2251139 -1.2880760 -4.1206179 -1.2880760 8.2421551 1.4846520 -4.1206179 1.4846520 -1.3953760
10001.100 -0.42780939 0.13022810 -1.92078501E-02 0.13022810 4.5270901 -1.2878300 -1.92078501E-02 -1.2878300 0.85644352

[/]
 
The recent data is the one I get when I run the code i.e the output from the code above. Then I broke the data into pieces to demonstrate what I want my data to be.
 
What about mifiying the loop like this
Code:
[highlight]i=0
k=0[/highlight]
do
   ...
   [highlight]
   i = i + 1
   if (i==1 .or. modulo(i, 12) == 0) then
     k = k + 1
     write(*,*)
     write(*,100) k
     100 format ('STEP',i0)
   end if[/highlight]
   write(*,*) steptime,datum,datum_1,datum_2,datum_3,datum_4,datum_5,datum_6, &  
emd do
 
Hi Macrom

I have been trying to follow your suggestion but Im getting lost: The loop should be changed as I have done below?
Code:
program read_data
implicit none
integer stepno, arrsize
real steptime, datum, datum_1,datum_2,datum_3,datum_4,datum_5,datum_6, &
     datum_7,datum_8,i,k
real, allocatable :: array(:)
real, allocatable :: charge(:)
integer, parameter:: iunit=20

open(iunit,file='STATIS',status='old')
read(iunit,*)
read(iunit,*)


i=0
k=0
do
   read(iunit,*,end=10) &
   stepno,steptime,arrsize
   allocate(array(arrsize))
   read(iunit,*, end=10) array
   datum = array(33)
   datum_1 =array(34)
   datum_2 =array(35)
   datum_3 =array(36)
   datum_4 =array(37)
   datum_5 =array(38)
   datum_6 =array(39)
   datum_7 =array(40)
   datum_8 =array(41)

i = i + 1
   if (i==1 .or. modulo(i, 12) == 0) then
     k = k + 1
     write(*,*)
     write(*,100) k
     100 format ('STEP',i0)
   end if
 write(*,*) steptime,datum,datum_1,datum_2,datum_3,datum_4,datum_5,datum_6, &
end do


   deallocate(array)
end do
10 continue
close(iunit)
end program read_data


[/]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top