replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Array definition and write problem
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Array definition and write problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Thu Oct 06, 2011 3:43 pm    Post subject: Array definition and write problem Reply with quote

I am having a problem I define a 8x11 arrays FX(j,nrpm) etc I assign values in a double loop. But when I try to write the same array out to file, slightly further down the code, using another double loop reversing the order, using j and n as the loop variables it complains that they are undefined variables etc?? I am of course now using 11x8 in the reversal.

here is a subset of the code in question its part of a bigger subroutine loop where NRPM is incremented - note I am reversing the order its written out
ie I want J tabled with NRPM (N) incremented, then stepping J+1 increment then NRPM incremented again.

DO J=1,8
DO M=2,512
IF(ABS(THETA(2,M)-(RPM*J/120)).LT.0.01)THEN
FX(J,NRPM)=ABS(GENG(31,M))
FY(J,NRPM)=ABS(GENG(32,M))
FZ(J,NRPM)=ABS(GENG(33,M))
MX(J,NRPM)=ABS(GENG(34,M))
MY(J,NRPM)=ABS(GENG(35,M))
MZ(J,NRPM)=ABS(GENG(36,M))
ENDIF
ENDDO
ENDDO
IF(NRPM.EQ.11)THEN
DO J=1,8

DO N=1,NRPM
ESP=RPMIN+(N-1)*RPMI
EO=J*0.5
WRITE(*,*)ESP,EO,ESP*j/120,FX(J,N),FY(J,N),FZ(J,N),MX(J,N),MY(J,N),MZ(J,N)
ENDDO
ENDDO
ENDIF

Basically it does not recognise the FX(J,N) etc variables? error 112 reference to undefined variable etc...


Last edited by colt1954 on Thu Oct 06, 2011 11:35 pm; edited 5 times in total
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Thu Oct 06, 2011 4:08 pm    Post subject: Reply with quote

Where you assign values to FX as in FX(J,NRPM)=ABS(GENG(31,M)) the second index is fixed at NRPM so for the loop M=2,512 you are just continuously overwriting the same cell.

Whilst when you try to write out the array contents you are attempting to do this with the second index varying from 1 to NRPM. Cells with indeces 1 to NRPM-1 have not been populated, hence the error message.
_________________
John Horspool
Roshaz Software Ltd.
Gloucestershire
Back to top
View user's profile Send private message Visit poster's website
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Thu Oct 06, 2011 4:27 pm    Post subject: Re: Reply with quote

JohnHorspool wrote:
Where you assign values to FX as in FX(J,NRPM)=ABS(GENG(31,M)) the second index is fixed at NRPM so for the loop M=2,512 you are just continuously overwriting the same cell.

Whilst when you try to write out the array contents you are attempting to do this with the second index varying from 1 to NRPM. Cells with indeces 1 to NRPM-1 have not been populated, hence the error message.


Thanks I'll consider more what you write, but the NRPM is incremented outside of this section in a subroutine as as I think I tried to explain?

Further example here is an output at the foot of the define array variable:

FX(J,NRPM)=ABS(GENG(31,M))
FY(J,NRPM)=ABS(GENG(32,M))
FZ(J,NRPM)=ABS(GENG(33,M))
MX(J,NRPM)=ABS(GENG(34,M))
MY(J,NRPM)=ABS(GENG(35,M))
MZ(J,NRPM)=ABS(GENG(36,M))
PRINT *,j,nrpm, fz(j,nrpm)

The output is correct it assigns the right values it increments NRPM etc its just that I cannot reproduce them further down which is weird
Back to top
View user's profile Send private message
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Thu Oct 06, 2011 4:45 pm    Post subject: Update Reply with quote

if i try to print out two Fz array values beyond the initial do loops its again says its undefined, so its losing its values not sure why?

FX(J,NRPM)=ABS(GENG(31,M))
FY(J,NRPM)=ABS(GENG(32,M))
FZ(J,NRPM)=ABS(GENG(33,M))
MX(J,NRPM)=ABS(GENG(34,M))
MY(J,NRPM)=ABS(GENG(35,M))
MZ(J,NRPM)=ABS(GENG(36,M))
! PRINT *,j,nrpm, fz(j,nrpm) - assigns ok here !!
ENDIF
ENDDO
ENDDO
print *,fz(1,1),fz(1,2) - undefined here !!!
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 07, 2011 12:00 pm    Post subject: Re: Array definition and write problem Reply with quote

Your code is very difficult to understand.

Can you provide details of what you are trying to do (rather than code that doesn't work)?

Sometimes, the only way to make progress is to throw away what you have and start again.


Whatever the value of NRPM is (but actually it must be 11 to get the printout), you are only setting up one column of the arrays FX, FY etc.

You therefore get an error when you try to access the other columns since
they are undefined.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Fri Oct 07, 2011 12:40 pm    Post subject: Reply with quote

There is nothing in this block of code that increments the value of NRPM !

Code:
DO J=1,8
DO M=2,512
IF(ABS(THETA(2,M)-(RPM*J/120)).LT.0.01)THEN
FX(J,NRPM)=ABS(GENG(31,M))
FY(J,NRPM)=ABS(GENG(32,M))
FZ(J,NRPM)=ABS(GENG(33,M))
MX(J,NRPM)=ABS(GENG(34,M))
MY(J,NRPM)=ABS(GENG(35,M))
MZ(J,NRPM)=ABS(GENG(36,M))
ENDIF
ENDDO
ENDDO

_________________
John Horspool
Roshaz Software Ltd.
Gloucestershire
Back to top
View user's profile Send private message Visit poster's website
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Fri Oct 07, 2011 2:17 pm    Post subject: Re: Reply with quote

JohnHorspool wrote:
There is nothing in this block of code that increments the value of NRPM !

Code:
DO J=1,8
DO M=2,512
IF(ABS(THETA(2,M)-(RPM*J/120)).LT.0.01)THEN
FX(J,NRPM)=ABS(GENG(31,M))
FY(J,NRPM)=ABS(GENG(32,M))
FZ(J,NRPM)=ABS(GENG(33,M))
MX(J,NRPM)=ABS(GENG(34,M))
MY(J,NRPM)=ABS(GENG(35,M))
MZ(J,NRPM)=ABS(GENG(36,M))
ENDIF
ENDDO
ENDDO



Correct, it is beyond this LOOP its a subroutine etc a return then increments NRPM....believe me it does there is no problem there it goes from 1 to 11 correctly.

Its so weird I can get the arrays to keep the j values but it only seems to store the last NRPM value 11...why, when I seeded 8x11 at the start surely array values for both subscripts J,N should stay? I realise it starts to write out at when NRPM=11 but I am re-setting from N=1,NRPM etc to pick up all the array values...

Further I have created a simpler programme swopping the array order and it works..see here:

program Test
REAL,dimension (15,15)::FX,FY,FZ
NRPM=0
100 NRPM=NRPM+1
DO J=1,3
FX(J,NRPM)=0.2*NRPM+J
FY(J,NRPM)=0.5*NRPM+J
FZ(J,NRPM)=0.7*NRPM+J
PRINT *,J*0.5,NRPM*1000,FX(J,NRPM),FY(J,NRPM),FZ(J,NRPM)
ENDDO
print *
IF(NRPM.EQ.4)THEN
DO J=1,3
DO N=1,4
WRITE(*,*)J*0.5,N*1000,FX(J,N),FY(J,N),FZ(J,N)
ENDDO
ENDDO
STOP
ENDIF
GOTO 100
END
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 07, 2011 2:41 pm    Post subject: Reply with quote

If the code you have provided in your first post is in a subroutine then the values you set up for a given value of NRPM will be lost when the subroutine exits (depending on whether you used the SAVE attribute or SAVE statement or not), so when the next call is made with NRPM incremented an "undefined" error will occur.

Can we see all the code or enough to work out what you have done?

We need to see where and how each variable is declared, and what the scope of each variable is.

Its almost certainly an error in the code, rather than a FTN95 error.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 07, 2011 2:51 pm    Post subject: Reply with quote

In the last program you posted you have a STOP between the last END DO and the END IF.

But you don't have this in the first code!!

Perhaps you have started again!
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Fri Oct 07, 2011 3:46 pm    Post subject: Re: Reply with quote

davidb wrote:
If the code you have provided in your first post is in a subroutine then the values you set up for a given value of NRPM will be lost when the subroutine exits (depending on whether you used the SAVE attribute or SAVE statement or not), so when the next call is made with NRPM incremented an "undefined" error will occur.

Can we see all the code or enough to work out what you have done?

We need to see where and how each variable is declared, and what the scope of each variable is.

Its almost certainly an error in the code, rather than a FTN95 error.


I think you may be right because the only array value combinations that 'stay unaltered' are for J,11 ie valid for all J values but it only recognises the last NRPM increment which is 11 and its NRPM that gets incremented in the sub routine...I could cut and paste the code buts its massive can you suggest a save command I need to do etc
Back to top
View user's profile Send private message
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Fri Oct 07, 2011 3:49 pm    Post subject: Re: Reply with quote

davidb wrote:
In the last program you posted you have a STOP between the last END DO and the END IF.

But you don't have this in the first code!!

Perhaps you have started again!


Point taken but its not this that was simply a convenience for that program, but maybe this simple program without a subroutine is evidence again that is the SR thats re-setting things!!!
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 07, 2011 3:57 pm    Post subject: Reply with quote

Don't post it if its very big.

Try

real, save :: FX(10,11), FY(10,11), ...

etc but use the dimensions you have now.

or you can add the line

save FX, FY, ...
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 07, 2011 4:07 pm    Post subject: Reply with quote

I modified your program so it has a subroutine. Does your real program look like this.

Code:

SUBROUTINE XXX(NRPM)
INTEGER NRPM
REAL,dimension (15,15), SAVE ::FX,FY,FZ
DO J=1,3
FX(J,NRPM)=0.2*NRPM+J
FY(J,NRPM)=0.5*NRPM+J
FZ(J,NRPM)=0.7*NRPM+J
PRINT *,J*0.5,NRPM*1000,FX(J,NRPM),FY(J,NRPM),FZ(J,NRPM)
ENDDO
print *
IF(NRPM.EQ.4)THEN
DO J=1,3
DO N=1,4
WRITE(*,*)J*0.5,N*1000,FX(J,N),FY(J,N),FZ(J,N)
ENDDO
ENDDO
! Note RETURN IN HERE
RETURN
ENDIF
END SUBROUTINE XXX

program Test
NRPM=0
100 NRPM=NRPM+1
   CALL XXX(NRPM)
IF (NRPM < 4) GOTO 100
END

_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
colt1954



Joined: 21 Dec 2010
Posts: 81

PostPosted: Fri Oct 07, 2011 4:24 pm    Post subject: Hi Again Reply with quote

Hi David if you were near by I'd hug you!!!

I have spent hours on this....yes your right I have got round it using common block etc, ok old fashioned I know but much of my programme is based on them. Have not looked at this programme for ages so a little rusty I guess....

Thanks again David have a nice weekend.

ps have just seen your save command might give that a whirl too it looks simpler than common block approach etc
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 07, 2011 4:28 pm    Post subject: Reply with quote

Good to know you have a way forward Smile
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group