 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Thu Oct 06, 2011 3:43 pm Post subject: Array definition and write problem |
|
|
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 |
|
 |
JohnHorspool
Joined: 26 Sep 2005 Posts: 270 Location: Gloucestershire UK
|
Posted: Thu Oct 06, 2011 4:08 pm Post subject: |
|
|
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 |
|
 |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Thu Oct 06, 2011 4:27 pm Post subject: Re: |
|
|
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 |
|
 |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Thu Oct 06, 2011 4:45 pm Post subject: Update |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 07, 2011 12:00 pm Post subject: Re: Array definition and write problem |
|
|
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 |
|
 |
JohnHorspool
Joined: 26 Sep 2005 Posts: 270 Location: Gloucestershire UK
|
Posted: Fri Oct 07, 2011 12:40 pm Post subject: |
|
|
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 |
|
 |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Fri Oct 07, 2011 2:17 pm Post subject: Re: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 07, 2011 2:41 pm Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 07, 2011 2:51 pm Post subject: |
|
|
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 |
|
 |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Fri Oct 07, 2011 3:46 pm Post subject: Re: |
|
|
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 |
|
 |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Fri Oct 07, 2011 3:49 pm Post subject: Re: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 07, 2011 3:57 pm Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 07, 2011 4:07 pm Post subject: |
|
|
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 |
|
 |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Fri Oct 07, 2011 4:24 pm Post subject: Hi Again |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 07, 2011 4:28 pm Post subject: |
|
|
Good to know you have a way forward  _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
|
|
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
|