Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unexpected Array Reference

Status
Not open for further replies.

IamMcCoder

Programmer
Jun 11, 2010
6
US
Little help debugging please? Thanks in advance.

I receive this error message when compiling my code using FORTRAN g95:

In file short_trl.f:171

type (*,'short_trline:',nstp,x,y,z,h,hemisphere)
1
Error: Unexpected array reference at (1)



Here's my code:

SUBROUTINE short_stepcon(status)

!******************************************************************

!******************************************************************
IMPLICIT NONE

INTEGER n
PARAMETER (n=4)
REAL*8 xyz(n), xyztry(n), error(n), h, hmin, hmax, tol, sig
COMMON /fltcom/ xyz, xyztry, error, h, hmin, hmax, tol, sig

INTEGER i
REAL*8 errmax, hsm
REAL*8 safety, pgrow, pshrnk, errcon
PARAMETER (safety=0.9, pgrow=-.25, pshrnk=-.25, errcon=1.89
integer*2 status
real*8 err_limit
!******************************************************************

save

1 h = h*signh

CALL step_trace(status)

h = ABS(h)

errmax=0.
DO 11 i=1,3
errmax = errmax + error(i)*error(i)
11 CONTINUE
errmax=SQRT(errmax)/tol

err_limit = 1.0

IF((errmax.GT.err_limit).AND.(h.GT.hmin).and.
# (status .ne. -1))then
! PRINT *,'hfail: h=', h
hsm = safety*h*(errmax**pshrnk)
IF (hsm/h .LT. 0.1) hsm = 0.1*h
h = MIN(MAX(hsm, hmin), hmax)
GOTO 1
ELSE
DO 12 i=1,n
xyz(i) = xyztry(i)
12 CONTINUE


RETURN
ENDIF

END

!******************************************************************

SUBROUTINE short_trline(in_pos,out_pos,dir,final_r,status)

c******************************************************************

IMPLICIT NONE

real*8 in_pos(4)
real*8 out_pos(4)
real*8 final_r
integer*2 status
integer*2 dir

INTEGER n
PARAMETER (n=4)
REAL*8 xyz(n), xyztry(n), error(n), h, hmin, hmax, tol, sig
COMMON /fltcom/ xyz, xyztry, error, h, hmin, hmax, tol, sig

INTEGER*4 nstp
integer*4 trace_print
real*4 nmax
REAL*8 x, y, z, ls, rs, vz, hz, hs, r,vpar
REAL*8 pi(3.1415926535897932D0)
EQUIVALENCE (xyz(1),x), (xyz(2),y), (xyz(3),z), (xyz(4),vpa
PARAMETER(ls=-60.0, rs=20.0, vz=40.0)
PARAMETER(hz=(rs-ls)/2.0, hs=ABS(rs+ls)/2.0)
logical*1 done

real*8 accepted_z
parameter (accepted_z = 0.001)

real*8 R_e
parameter (R_e = 6371.2)

real*8 hemisphere

real*8 stop_r

save

status = 0

hmin = 1.e-7
hmax = 2.e-6
h = 2.e-6

tol = 0.0001

nmax = 10000.
signh = dble(dir)

stop_r = 1. + final_r/R_e

x = in_pos(1)/R_e
y = in_pos(2)/R_e
z = in_pos(3)/R_e

vpar = 5.e7

done = .false.
nstp = 1
do while(.not. done)

r = sqrt(x*x + y*y + z*z)

if(r .le. stop_r) then
done = .true.
else

IF(nstp .GT. 2) then
h=MIN(hmin,h,hmax)
endif


call short_stepcon(status)

trace_print = mod(nstp,1000)
if(trace_print .eq. 0) then
hemisphere = float(dir) * z
TYPE (*,'short_trline:',nstp,x,y,z,h,hemisphere)
endif


if(nstp .gt. nmax) then
status = 2
done = .true.
endif

nstp = nstp + 1
endif

end do

out_pos(1) = x * R_e
out_pos(2) = y * R_e
out_pos(3) = z * R_e
out_pos(4) = vpar


RETURN
END





 
Well, I'm not sure whether I can help you, but first of all: "TYPE" is a reserved command in fortran90, which I'd rather avoid programming in old fashioned F77. This may cause problems if you compile with G95 and your compiler options don't explicitly mention it's all F77.

Apart from that, you don't define "TYPE" as a routine anywhere. Seeing "mod(nstp,1000)" I suppose it's a routine to write somethng on the screen, but why don't you just use something easier like:
Code:
WRITE(*,'(A13,I5,5(E4.2))')'short_trline:',nstp,x,y,z,h,hemisphere
?
...for example
 
Thanks you.

I changed my code to:

Code:
write (*,'short_trline:',nstp,x,y,z,h,hemisphere)

Now however, I receive the error:

Code:
write (*,'short_trline:',nstp,x,y,z,h,hemisphere)
                         1
Error: Syntax error in WRITE statement at (1)

 
Hi IamMcCoder,

Shouldn't the variables to be printed be outside of the bracket? Have a look at how GerritGroot showed you.

To simplify it, you might want to get the free format write working first, so try:

Code:
write (*,*) nstp,x,y,z,h,hemisphere

If you succeed with that, add the formatting you need, so maybe something like:

Code:
write (*,100) nstp,x,y,z,h,hemisphere
100 format ('short_trline: ',I5,5(E4.2))

I could be off on the formatting thing there, just writing this from memory, as I don't need formatted outputs too often.

Hope it helps!

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Nevermind my previous post. Instead, I decided to send the data to standard output by changing my code to:

Code:
write (*,*) 'short_trline: ', nstp, x, y, z, hemisphere

But I still have the following errors:
Code:
hemisphere = float(dir) * z
                   1
Error: Type of argument 'a' in call to 'float' at (1) should be INTEGER(4), not INTEGER(2)


hemisphere = float(dir) * z
             1
Error: Function 'float' at (1) has no implicit type


 
Well, couldn't the first error be fixed with

Code:
integer*4 dir

in the declaration?

As for the error regarding "float" -- what are you trying to do with it? Convert the integer to a floating point number, I assume? The error makes it sound like "float" isn't an intrinsic function, which it may well not be -- I've not encountered it before. You've declared "hemisphere" as a real*8, which I imagine is double precision on your system, so what about?:

Code:
hemisphere = double(dir) * z

As a disclaimer, I should point out that I don't know all that much about Fortran, and have learnt exclusively in Fortran 90/95. My advice may or may not be of use. ;)

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Hi NickFort

I did as you suggested and now my code looks like:
Code:
write (*,*) 'short_line: ', nstp, x, y, z, hemisphere 
write (*,100) nstp,x,y,z,h,hemisphere
100 format ('short_trline: ',I5,5(E4.2))

I receive this error:
Code:
100 format ('short_trline: ',I5,5(E4.2))
1
Error: Unclassifiable statement at (1)

 
Don't worry about

Code:
write (*,100) nstp,x,y,z,h,hemisphere
100 format ('short_trline: ',I5,5(E4.2))

As I said, it was off the top of my head, and I don't know Fortran 77 either, both of which could be contributing to the problem.

If
Code:
write (*,*) 'short_line: ', nstp, x, y, z, hemisphere
is working for you, leave it for now would be my suggestion, until you get the more important errors ironed out.

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
This works with g95
Code:
[COLOR=#2e8b57][b]integer[/b][/color] :: dir
[COLOR=#2e8b57][b]real[/b][/color] :: hemisphere, z
dir [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]2[/color]
z [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]3[/color]
hemisphere [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]float[/color](dir) [COLOR=#804040][b]*[/b][/color] z
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'dir = '[/color], dir, [COLOR=#ff00ff]'z = '[/color], z, [COLOR=#ff00ff]'hemisphere = '[/color], hemisphere
[COLOR=#a020f0]end[/color]
Code:
$ g95 float.f95 -o float

$ float
 dir =  2 z =  3. hemisphere =  6.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top