Programming trouble with fortran optimization code

In summary, the conversation discusses adapting a Fortran code for a specific application. In order to optimize a value for two planes, the code needs to read in ten values from an external inp. file for each plane. However, there seems to be an issue with the declaration of the variable used for reading in the values. The expert suggests a different declaration that may solve the problem.
  • #1
granbycools
4
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][COLOR="Red"]dcp(i,kl)[/COLOR][/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
  • #2
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.
 

Related to Programming trouble with fortran optimization code

1. What is Fortran optimization code?

Fortran optimization code is a type of programming code written in the Fortran language that is specifically designed to improve the efficiency and performance of a computer program.

2. Why do I need to optimize my Fortran code?

Optimizing your Fortran code can lead to faster execution times and more efficient use of resources, resulting in improved performance of your program. This is especially important for large and complex programs.

3. What are some common programming troubles with Fortran optimization code?

Some common troubles with Fortran optimization code include incorrect use of optimization flags, errors in the code that can lead to unexpected results, and difficulties in debugging due to the complex nature of optimization techniques.

4. How can I debug my Fortran optimization code?

To debug your Fortran optimization code, you can use tools such as a debugger or a profiler to identify any errors or bottlenecks in your code. Additionally, testing and monitoring your code as you make changes can also help in identifying and fixing any issues.

5. Are there any best practices for writing Fortran optimization code?

Yes, some best practices for writing Fortran optimization code include writing clean and concise code, using optimization flags appropriately, regularly testing and monitoring your code, and consulting with experienced programmers for guidance and advice.

Similar threads

  • Programming and Computer Science
Replies
4
Views
768
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
5
Views
24K
  • Programming and Computer Science
2
Replies
54
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
25
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
  • Programming and Computer Science
Replies
2
Views
6K
Back
Top