Topic: Variable

Hi Everyone,
I am writing some codes, but I have found very strange problem with that.

On the following "do loop" which is a part of my program, ncomp=10 before the execution of "do loop". While, the value changes to 1041999331 just after finishing the execution of that, which make a big problem for the rest of program. 

do k=1, ncomp
    do i=1, 16
        if(comp(k).eq.com(i))then
            mw(k)=mmw(i)
            MWg=MWg+mf(k)*mw(k)             
            Tc(k)=TTc(i)
            Pc(k)=PPc(i)
            PAF(k)=PPAF(i)
            if(comp(k).eq.'N2')yn2=mf(k)
            if(comp(k).eq.'CO2')yco=mf(k)
            if(comp(k).eq.'H2S')yh2s=mf(k)
        endif
    enddo
enddo

So, I appreciate if someone could help me to over this problem.

Regards,
Nemat

Re: Variable

As the 'ncomp' variable is not used inside the loop, it certainly comes from an array which has an "out-of-bounds" problem with its index.

It is difficult to find in C (except using 'valgrind' under linux). Fortunaltely, Fortran good compilers generally gives an option which allow to find the error. In our case (GNU gfortran), add the '-fbounds-check' to the compiler flags : it leads to a run-time error giving you the exact line of your program where the "out-of-bounds" problem occur (assuming you are using the DEBUG mode).

Regards,
Edouard

Re: Variable

Please confirm that
   mw()       
   Tc()
   Pc()
   PPAF()
..are array variables, not functions.

Please tell us which of,
   com()
   mmw()
   mf()   
   TTc()
   PPc()
   PAF()
   comp()
..are array variables, and which are functions.

Please show the type declarations for them all of the above.
For those which are functions, please show us the function coding.
---
John

Re: Variable

Thanks all you guys,

Actually I have found the problem, but in a very crazy way that you may not believe. I only changed the name of PAF(), PPAF() and ncomp to AF(), AAF() and nc , respectively. That’s it. But, I have found another crazy problem. However, regarding to your questions just let me to explain more about the variables, arrays and the program.

All  com(), comp(),  mmw(),  TTc(), PPc(), AAF(), mw(), Tc(), Pc(), mf(), AF() are arrays, this is their declaration:

character(len=15) com(16), comp(nc)
real mft, mmw(16), MWg, TTc(16), PPc(16), AAF(16)
real mw(nc), Tc(nc), Pc(nc), mf(nc), AF(nc)

The program has been designed to read some components from a data file, and then compares with the entered ones. If the components are equal the program should pick up the rest of information related to that component and write them in a new file for the rest of program.

These are the components should be compared.
comp(1)='N2'
comp(2)='CH4'
comp(3)='C2H6'
comp(4)='C3H8'
comp(5)='i-C4H10'
comp(6)='n-C4H10'
comp(7)='i-C5H12'
comp(8)='n-C5H12'
comp(9)='C6H14'
comp(10)='C7+'

And this is the ‘do loop’ for that execuation.
do k=1, nc
    do i=1, 16
        if(comp(k).eq.com(i))then
            comp(k)=com(i)
            mw(k)=mmw(i)
            MWg=MWg+mf(k)*mw(k)             !MWg: lbm/lbm.mol
            mft=mft+mf(k)
            Tc(k)=TTc(i)
            Pc(k)=PPc(i)
            AF(k)=AAF(i)
            write (50, '(A15, A, 5(f15.3,A), f15.3)') comp(k),',',mf(k),',',mw(k),',',mf(k)*mw(k),',',Tc(k),',',Pc(k),',',AF(k)
            if(comp(k).eq.'N2')yn2=mf(k)
            if(comp(k).eq.'CO2')yco=mf(k)
            if(comp(k).eq.'H2S')yh2s=mf(k)
        endif
    enddo
enddo

However, the program do not bring back the component ‘CH4’ and it also bring ‘E=H6’ instead of ‘C2H6’. But, for the rest of components, there is not any problem.

Therefore, I would appreciate if give me some suggestions regarding this problem.

Regards,
Nemat

Re: Variable

Nemat,

One thing I find curious is that after your test:

if(comp(k).eq.com(i))then

you immediately follow it with:

comp(k)=com(i)

Since you already checked if they are equal, this assignment is redundant.  Nothing else is jumping out at me at the moment.

Jeff Armstrong
Approximatrix, LLC

Re: Variable

Hi -

It would help to have more of the code. By that I mean, for example, the declaration -

real mw(nc), Tc(nc), Pc(nc), mf(nc), AF(nc)

is puzzling to me. If it occurs in the main program, then "nc" must be a parameter value, but I don't see it. Or is it dynamic ? If the declaration is in a subroutine, then it would help to see where "nc" is coming from. From what you've posted, I cannot trace the sizes of arrays, etc. to see if something is getting clobbered.

Regards