Programming trouble with fortran optimization code

Click For Summary
SUMMARY

The forum discussion centers on optimizing Fortran code for handling multiple planes with specific input values. The user encounters issues with the read command for the array dcp(i,kl), which is incorrectly declared. The suggested solution involves redefining the array dimensions using parameters for kl and i, ensuring proper allocation and readability of the input values. This adjustment resolves the declaration problem and enhances code functionality.

PREREQUISITES
  • Understanding of Fortran programming language syntax
  • Familiarity with array declarations and dimensions in Fortran
  • Knowledge of reading external input files in Fortran
  • Basic concepts of optimization in programming
NEXT STEPS
  • Review Fortran array handling and memory allocation techniques
  • Learn about Fortran input/output operations and file handling
  • Explore optimization techniques specific to Fortran programming
  • Investigate debugging methods for Fortran code to identify variable declaration issues
USEFUL FOR

Fortran developers, programmers optimizing numerical simulations, and anyone troubleshooting input/output operations in Fortran code.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
25K
  • · Replies 54 ·
2
Replies
54
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 25 ·
Replies
25
Views
10K
  • · Replies 2 ·
Replies
2
Views
6K