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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create several columns from one column? 1

Status
Not open for further replies.

cealess

Technical User
Oct 24, 2007
13
CA
The thing is that I am working with daily data which is in two columns, the first one tells me the month and the second one the value of the observation for that month.The problem is when i am trying to write the data to the same file it keeps writing down like in this.
Jan Feb
315.3280 0.0000
315.3100 0.0000
315.3050 0.0000
315.3170 0.0000
315.2800 0.0000
315.2560 0.0000
315.2950 0.0000
315.3180 0.0000
315.3350 0.0000
315.3170 0.0000
315.3070 0.0000
315.3000 0.0000
315.2840 0.0000
315.3090 0.0000
315.2900 0.0000
315.2640 0.0000
315.3030 0.0000
315.3190 0.0000
315.3360 0.0000
315.3440 0.0000
315.3170 0.0000
315.2870 0.0000
315.2830 0.0000
315.2820 0.0000
315.2540 0.0000
315.2510 0.0000
315.2620 0.0000
315.2660 0.0000
315.2630 0.0000
315.2800 0.0000
315.2800 315.2960
315.2800 315.2680
315.2800 315.2440
315.2800 315.2890
315.2800 315.3110
315.2800 315.2910
315.2800 315.2790
315.2800 315.2660
315.2800 315.2540
315.2800 315.2500
315.2800 315.2340
315.2800 315.2310
315.2800 315.2380
315.2800 315.2500
315.2800 315.2620
315.2800 315.2800
315.2800 315.2870
315.2800 315.2780
315.2800 315.2750
315.2800 315.2750
315.2800 315.2580
315.2800 315.2850
315.2800 315.2520
315.2800 315.2410
315.2800 315.2620
315.2800 315.2500
315.2800 315.2470
315.2800 315.2370

I want it to start writing in the first line for all the months. So how can i write the first data of feb in the first line?

Thanks a lot.
 
If you post some of your code, someone could tell you where you're going wrong.
 
Here there is a part of the code. I am using other variables to try to write the data into column, not sure if it is the best idea or there is other way to write the file. Thanks for the help.

Do j=1, nd

If (month(j)== 1) Then
jan=value(j)
Else If (month(j)== 2) Then
feb=value(j)

end if

End Do
Do i=1,nd
write(1,10) jan(i), feb(i)

end do
11 Format(6x,'Jan',6x,'Feb')

10 Format(1x,F10.4,1x,F10.4)
 
Try this
Code:
      Do j=1, nd
      
      If (month(j)== 1) Then
        jan[COLOR=red](j)[/color]=value(j)
        Else If (month(j)== 2) Then
        feb[COLOR=red](j)[/color]=value(j)
            
       end if
       
      End Do
      ! could also do
      ! write (1,10) (jan(i), feb(i), i = 1, nd)
      Do i=1,nd
       write(1,10) jan(i), feb(i)
     
      end do
   11 Format(8x,'Jan',7x,'Feb')
   
     10 Format(1x,F10.4,1x,F10.4)
 
Thanks, I tried that one previously and got the columns showed before. Also, I tried it again and got similar format.

Jan Feb
315.3360 0.0000
315.3300 0.0000
315.2960 0.0000
315.3100 0.0000
315.3100 0.0000
315.3220 0.0000
315.3240 0.0000
315.3320 0.0000
315.3200 0.0000
315.3110 0.0000
315.3140 0.0000
315.3280 0.0000
315.3260 0.0000
315.3650 0.0000
315.3530 0.0000
315.3410 0.0000
315.3540 0.0000
315.3530 0.0000
315.3380 0.0000
315.3280 0.0000
315.3330 0.0000
315.3400 0.0000
315.3070 0.0000
315.2870 0.0000
315.2870 0.0000
315.3050 0.0000
315.3150 0.0000
315.3260 0.0000
0.0000 315.3320
0.0000 315.3320
0.0000 315.2890
0.0000 315.3110
0.0000 315.3210
0.0000 315.3290
0.0000 315.3390
0.0000 315.3400
0.0000 315.3400
0.0000 315.3170
0.0000 315.3090
0.0000 315.3000
0.0000 315.2920
0.0000 315.3250
0.0000 315.3300
 
1) What does your input data look like
2) How are you reading it in
3) What do you want the output to look like
 
My input looks like is below and I am reading it as columns or vectors months and values.
1 315.336
1 315.33
1 315.296
1 315.31
1 315.31
1 315.322
1 315.324
1 315.332
1 315.32
1 315.311
1 315.314
1 315.328
1 315.326
1 315.365
1 315.353
1 315.341
1 315.354
1 315.353
1 315.338
1 315.328
1 315.333
1 315.34
1 315.307
1 315.287
1 315.287
1 315.305
1 315.315
1 315.326
2 315.332
2 315.332
2 315.289
2 315.311
2 315.321
2 315.329
2 315.339
2 315.34
2 315.34
2 315.317
2 315.309
2 315.3
2 315.292
2 315.325
2 315.33
3 315.269
4 315.269
5 315.269
6 315.208
7 315.258
7 315.259
7 315.259
7 315.265
7 315.256
7 315.249
7 315.25
7 315.259
7 315.286
7 315.289
7 315.279
7 315.253
7 315.254
7 315.259
7 315.242
7 315.223
7 315.229
7 315.24
7 315.238
7 315.232
7 315.239
7 315.249
7 315.237
7 315.231



Then I want my output to be like this for the first two months (jan, feb), the idea is to create on column for each month of the year. The output file should have 12 in the same format

315.336 315.332
315.33 315.332
315.296 315.289
315.31 315.311
315.31 315.321
315.322 315.329
315.324 315.339
315.332 315.34
315.32 315.34
315.311 315.317
315.314 315.309
315.328 315.3
315.326 315.292
315.365 315.325
315.353 315.33
315.341
315.354
315.353
315.338
315.328
315.333
315.34
315.307
315.287
315.287
315.305
315.315
315.326



 
You're getting your collection wrong. You need to fill the jan and feb arrays sequentially, not according to the index of month. Assume you have jan and feb big enough to accomodate all values.
Code:
! Collect the data
jancount = 0
febcount = 0
do j=1, nd
   if (month(j) .eq. 1) then
      jancount = jancount + 1
      jan(jancount) = value(j)
   else if (month(j) .eq. 2) then
      febcount = febcount + 1
      feb(febcount) = value(j)
   end if
enddo
! which month has more data
jmax = jancount
if (jmax .lt. febcount) jmax = febcount
! print the data
do j = 1, jmax
   if (j .le. jancount .and. j .le. febcount) then
      ! j less than both
      write (1, '(2F10.4)') jan(j), feb(j)
   else if (j .le. jancount) then
      ! end of feb
      write (1, '(F10.4)') jan(j)
   else
      ! end of jan
      write (1, '(10x, F10.4)') feb(j)
   end if
end do
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top