Fortran Programming trouble with fortran optimization code

AI Thread Summary
The discussion revolves around issues with adapting Fortran code for optimizing values across two planes, specifically regarding the reading of values into the array `dcp(i,kl)`. The user encounters a problem with the read command not functioning as expected, suspecting an issue with the declaration of the `dcp` array. Suggestions include modifying the declaration to use fixed parameters for `kl` and `i`, which clarifies the dimensions of the `dcp` array. The proposed solution aims to ensure that the array is correctly defined for the intended optimization runs. The thread concludes with a request for feedback on the suggested changes.
granbycools
Messages
4
Reaction score
0
Hi everyone,

I have some trouble adapting an existing fortran code for my application.

In the following Module I am optimizing a value for two planes ( i = iplan one&two).
In order to do that, I need to assign ten certain values from an external inp. file for each plane.

I have two loops, the first one selecting iplan one, respectively two.
In this loop is the second one, which is supposed to read in value one (dcp(i,kl)) to ten.
One value for each run in the secon loop. That means each plane is assign with ten optimization runs, and each run with a certain value.

My problem is, that: read (iread,*) dcp(i,kl) doesn´t work. The read command is linked to
the correct variable in the external inp. file, but I think that there is something wrong with the declaration
of dcp(i,kl)?

Is there anyone who can help me with that problem?
Code:
! note: module inout for iread
    use inout
    integer :: kl, i, iplan, nscwmi=100, determdcp
    real :: xnscwmi, dcp(2,10), fractionvor
    dimension dcp(i,kl)

!for iplan=1 & iplan=2; nscwmi from differnet module 
    [B]i = 1,iplan[/B]
        xnscwmi = nscwmi
! determdcp from external inp with determdcp=1
        read(iread,*) determdcp
        if (determsp .eq. 1) go to 501
    continue

    501
    do 502 kl=1, 10
       READ (iread,*)[B]dcp(i,kl)[/B]

        fractionvor = xnswmi
        xnscwmi = fractionvor/10

        ai   = xnscwmi*d(i,kl)+0.75
        imax = int(ai)
        ..
        ...
        b0(i) = 0.
        a0(i) = imax
        a1 (i)    = a1(i)+ a0(i)
Thanks!
 
Technology news on Phys.org
The declaration here seems strange.

Code:
! note: module inout for iread
    use inout
    integer :: kl, i, iplan, nscwmi=100, determdcp
    real :: xnscwmi, dcp(2,10), fractionvor
    dimension dcp(i,kl)

Try instead

Code:
! note: module inout for iread
    use inout
    integer :: iplan, determdcp
    integer, parameter :: kl = 10
    integer, parameter :: i = 2
    integer, parameter :: nscwmi = 100

    real :: xnscwmi, fractionvor
    real, dimension(i,kl) :: dcp

Let me know how that works out.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top