Hiya. I am able ot compile my program with no errors but when I run it I get the message:(adsbygoogle = window.adsbygoogle || []).push({});

Error 112, Reference to undefined variable, array element or function result.

I cannot see where I have gone wrong and more frustratingly this code was working, running producing results on the unix system at university but when I compile it on my windows system using silverfrost plato it gives this error. This is my code: (the line is bold is what it objects to)

PROGRAM project1

! MTMW14 Project 1: A Simplified Model of Ocean Gyres and the Gulf Stream

! Date Created: 27/01/2009 Author: Freja Hunt Version 1

! Simulate wind driven circulation in a closed basin with a western boundary current using the Stommel (1948) model

! and Arakawa C grid with a mixed explicit-implicit time scheme.

!----------------------------------------

IMPLICIT NONE

! Define variables

REAL, PARAMETER:: fo=10.0**(-4), beta=10.0**(-11), g=10.0, drag=10.0**(-6), density=1000.0,&

& windo=0.2, tstep=100.0, pi=3.1415926535, L=10.0**(6)

! fo is the reference coriolis parameter, beta is the beta plane approximation that allows the coriolis parameter to vary with latitude,

! g is the accerleration due to gravity, drag is the linear drag coefficient, density is the density of sea water,

! windo is the reference wind stress, tstep is the time step (s), L is spatial extent of the basin

INTEGER, PARAMETER:: ntsteps=1, gridstep=10000, depth=1000, xlength=L/gridstep, ylength=L/gridstep

! ntsteps is the number of time steps to run for, gridstep is the distance between grid points, depth is the resting depth of the fluid

! xlenght and ylength are the number of grid points across the basin

REAL, DIMENSION(xlength,ylength):: u, unext, usqrd, v, vnext, vsqrd, surf, surfnext, surfsqrd, x, y

! u is the velocity in the x direction, v is the velocity in the y direction, surf is the surface elevation

! x is the distance east, y is the distance north

REAL:: energy, energytime(ntsteps) ! Energy is the total energy of the peturbation from the resting system

INTEGER:: i, j, n

! i is the x component, j is the y compentent, n is the time index

! Assign values to x and y arrays

x(1,:)=0

DO i=2, xlength

x(i,:)=x(i-1,:)+gridstep

END DO

y(:,1)=L

DO j=2, ylength

y(:,j)=y(:,j-1)-gridstep

END DO

! Assign initial values of zero to the surface elevation, u and v

DO j=1, ylength

DO i=1, xlength

surf(i,j)=0

u(i,j)=0

v(i,j)=0

END DO

END DO

!----------------------------------------

! Set boundary conditions

v(1:xlength,1)=0 ! Set the northward velocity at the north boundary to zero, ie the first row is zero across all columns

v(1:xlength,ylength)=0 ! Set the northwards velocity to zero at the south boundary, ie the lasow is zero across all columns

u(1,1:ylength)=0 ! Set the eastwards velocity to zero at the west boundary, ie the first column is zero at all rows

u(xlength,1:ylength)=0 ! Set the eastwards velocity to zero at the east boundary,ie the last is zero across all rows

!----------------------------------------

DO n = 1, ntsteps

DO j = 2, ylength-1

DO i = 2, xlength-1

IF (((n/2)*2)/=n) THEN ! Define the scheme for the odd times steps

surfnext(i,j)= surf(i,j) - depth*tstep*(((u(i+1,j)+u(i,j))/gridstep) + &

&((v(i,j+1)-v(i,j))/gridstep))

unext(i,j)= u(i,j) + (fo+beta*y(i,j))*tstep*v(i,j) - g*tstep* &

& ((surfnext(i,j) - surfnext(i-1,j))/gridstep) - drag*tstep*u(i,j) + &

& ((windo*(-cos((pi*y(i,j))/L))/(density*depth)))*tstep

vnext(i,j)= v(i,j) - (fo+beta*y(i,j))*tstep*unext(i,j) - &

& g*tstep*((surfnext(i,j) - surfnext(i,j-1))/gridstep) - drag*tstep*v(i,j)

ELSE ! Define the scheme for the even time steps

surfnext(i,j)= surf(i,j) - depth*tstep*(((u(i+1,j)+u(i,j))/gridstep) + &

&((v(i,j+1)-v(i,j))/gridstep))

vnext(i,j)= v(i,j) - (fo+beta*y(i,j))*tstep*u(i,j) - &

& g*tstep*((surfnext(i,j) - surfnext(i,j-1))/gridstep) - drag*tstep*v(i,j)

unext(i,j)= u(i,j) + (fo+beta*y(i,j))*tstep*vnext(i,j) - g*tstep* &

& ((surfnext(i,j) - surfnext(i-1,j))/gridstep) - drag*tstep*u(i,j) + &

& ((windo*(-cos((pi*y(i,j))/L))/(density*depth)))*tstep

END IF

! Switch arrays over for next step

surf=surfnext

u=unext

v=vnext

END DO

END DO

! Square variables to calculate the total energy at this time step

DO j=1, ylength

DO i=1, xlength

usqrd(i,j)=u(i,j)**2

vsqrd(i,j)=v(i,j)**2

surfsqrd(i,j)=surf(i,j)**2

END DO

END DO

! Calculate the total energy of the peturbation from rest

energy = 0.5*density*(depth*((sum(usqrd)) + (sum(vsqrd)))) + g*(sum(surfsqrd))

energytime(n)=energy ! Saves total energy into an array at each time step

END DO

! Write results to a file

OPEN(UNIT=55, FILE='project1_u.dat')

DO j=1, ylength

WRITE(55,*) u(:,j)

END DO

CLOSE(55)

OPEN(UNIT=56, FILE='project1_v.dat')

DO j=1, ylength

WRITE(56,*) v(:,j)

END DO

CLOSE(56)

OPEN(UNIT=57, FILE='project1_surf.dat')

DO j=1, ylength

WRITE(57,*) surf(:,j)

END DO

CLOSE(57)

OPEN(UNIT=58, FILE='project1_energy.dat')

DO n=1, ntsteps

WRITE(58,*) energytime(n)

END DO

CLOSE(58)

END PROGRAM project1

Any help REALLY apprechiated.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Error 112 /undef when running fortran code

**Physics Forums | Science Articles, Homework Help, Discussion**