Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Urgent: problem with data selection

Hi,

I do have a problem to write a Fortran program to select data from a huge data set as follows:

1.500D+00 1.000D+06 3.000D+06 5.000D+06 7.000D+06 9.000D+06 1.100D+07 1.300D+07
1.500D+07 1.700D+07 1.900D+07 2.100D+07 2.300D+07 2.500D+07 2.700D+07 2.900D+07
3.100D+07 3.300D+07 3.500D+07 3.700D+07 3.900D+07 4.100D+07 4.300D+07 4.500D+07
4.700D+07 4.900D+07 5.100D+07 5.300D+07 5.500D+07 5.700D+07 5.900D+07 6.100D+07
1.750D+08 1.770D+08 1.790D+08 1.810D+08

2.000D+00 1.000D+06 3.000D+06 5.000D+06 7.000D+06 9.000D+06 1.100D+07 1.300D+07
1.500D+07 1.700D+07 1.900D+07 2.100D+07 2.300D+07 2.500D+07 2.700D+07 2.900D+07
3.100D+07 3.300D+07 3.500D+07 3.700D+07 3.900D+07 4.100D+07 4.300D+07 4.500D+07
4.700D+07 4.900D+07 5.100D+07 5.300D+07 5.500D+07 5.700D+07 5.900D+07 6.100D+07
1.750D+08 1.770D+08 1.790D+08 1.810D+08

2.500D+00 1.000D+06 3.000D+06 5.000D+06 7.000D+06 9.000D+06 1.100D+07 1.300D+07
1.500D+07 1.700D+07 1.900D+07 2.100D+07 2.300D+07 2.500D+07 2.700D+07 2.900D+07
3.100D+07 3.300D+07 3.500D+07 3.700D+07 3.900D+07 4.100D+07 4.300D+07 4.500D+07
4.700D+07 4.900D+07 5.100D+07 5.300D+07 5.500D+07 5.700D+07 5.900D+07 6.100D+07
1.750D+08 1.770D+08 1.790D+08 1.810D+08
.....
....
....

The data consists of blocks (without spaces), the number of blocks is not known, each block contains 36 numbers, my problem is to select certain numbers from each block say B1(1)B1(20),B1(33) and put all data from all blocks under each other as:
B1(1) B1(20) B1(33)
B2(1) B2(20) B2(33)
B3(1) B3(20) B3(33)
..................

Can anybody help please,

Thanks in advance

Comments

  • quikcarlquikcarl Posts: 59Member
    Maybe this will help. Don't be afraid of READ
    and FORMAT statements. You don't write about how
    each block is laid out or my browser just makes
    it look different.
    [code]C
    INTEGER*4 I,J,X
    C
    DOUBLE B(36,100)
    C
    C ASSIGN THE UNIT NUMBER OF THE FILE. THERE SHOULD BE SOME KIND OF
    C END OF FILE(EOF) THAT YOU CAN TEST FOR
    C
    X = 10
    C
    C
    DO 10 J = 1 TO 100
    READ(UNIT=X,FMT=9000) (B(I,J),I=1,36,1)
    9000 FORMAT(36D10.3)
    C I MAY NOT HAVE THE FORMAT EXACTLY RIGHT
    10 CONTINUE
    C
    C THE OTHER DISPLAY PART I'LL LEAVE TO YOU
    C[/code]

  • anton2010anton2010 Posts: 6Member
    Hi,
    Thanks very much for the quick reply, I have adopted the program and it seems to work with small problem: The number of blocks is set to a large number (e.g., 1000) and thus if the number of blocks less than 1000, the output contains zeros for the rest (which is not required).
    Is there any way to detect the number of blocks and also write it out.

    How can I eliminate the zeros?

    Here is the program and a sample output.

    program recon
    INTEGER*4 I,J,X
    DOUBLE B(92,1000)

    C
    OPEN(UNIT=10, FILE='fourier.dat',STATUS='OLD')
    OPEN(UNIT=15, FILE='fourier.out',STATUS='replace')
    C
    DO 10 J = 1, 1000
    READ(10,9000,end=15) (B(I,J),I=1,92,1)
    9000 FORMAT(1p,8d10.3)

    10 CONTINUE
    C
    15 CONTINUE

    DO 20 J = 1, 1000
    write(15,9005) (B(I,J),I=1,92,30)
    9005 FORMAT(1p,4d10.3)
    20 CONTINUE
    end


    ----------------------

    Output

    8.640D+00 5.900D+07 1.190D+08 1.790D+08
    8.760D+00 5.900D+07 1.190D+08 1.790D+08
    8.880D+00 0.000D+00 0.000D+00 0.000D+00
    0.000D+00 0.000D+00 0.000D+00 0.000D+00
    0.000D+00 0.000D+00 0.000D+00 0.000D+00
    0.000D+00 0.000D+00 0.000D+00 0.000D+00
    0.000D+00 0.000D+00 0.000D+00 0.000D+00
    0.000D+00 0.000D+00 0.000D+00 0.000D+00
    0.000D+00 0.000D+00 0.000D+00 0.000D+00

    --------------

    Many thanks in advance,

  • anton2010anton2010 Posts: 6Member
    This post has been deleted.
  • quikcarlquikcarl Posts: 59Member
    Okay, the [b]END[/b] part in the [b]READ[/b] statement should work
    and stop the loop from going on. When that happens, take the
    value of [italic]J[/italic] and [italic]subtract 1[/italic] to have tthe number of blocks read in. Then have the 2nd loop go from [italic]1[/italic] to [italic]J-1[/italic] using another index.
  • anton2010anton2010 Posts: 6Member
    : Okay, the [b]END[/b] part in the [b]READ[/b] statement should work
    : and stop the loop from going on. When that happens, take the
    : value of [italic]J[/italic] and [italic]subtract 1[/italic] to have
    : tthe number of blocks read in. Then have the 2nd loop go from
    : [italic]1[/italic] to [italic]J-1[/italic] using another index.
    :
    Thanks a lot for your help... It works now
Sign In or Register to comment.