LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2014, 03:22 AM   #1
tom0395
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled
Unable to solve fortran95 compilation error "Unexpected array reference at (1)"


Hi guys,

I am currently using fortran95 compiler to run this code(see attached), however I am unable to solve the errors that were presented (unexpected array reference), I thought it would be because i declared my arrays wrongly somewhere, but even after a few tweaks the problem still presented itself. I would really appreciate any helpful comments, and do let me know if any more info is needed.

Warmest Regards,
Tom


Code:
 Program ProgramVII
      implicit none
      
      integer, parameter ::  ni=51, nj=51
      double precision, parameter :: pi = 3.1415926535897932D+0
      integer PL, irun, irunmax,ii,js,je,j
      double precision m(ni),p(ni),mp(ni),pp(ni)
      double precision mx(nj),px(nj),mpx(nj),ppx(nj)
      double precision T,Mo,Po,Pe,z,R,Area,wavespeed,D,f,alpha,delx,delt,delm,k,i,time,tp,tm,Ho,vf
      double precision A(3),B(3),tc
      
      common/group1/Mo,Po,Area,wavespeed,D,f,Pe
      common/group2/delx
      common/group3/delt
      common/group4/A,B
      
      write(*,*)'give time tc(seconds):'
      read (*,*) tc
      
      irun=1
      I=2
      PL=200
      irunmax=2000
      js=2
      je=ni-1
      
      T=273.15
      z=0.897403
      R=494.94
      k=1.27
      alpha=1.0
      
      Mo=80
      Pe=200000
      Po=400000
      mx=-Mo
      m=Mo
      
      D=0.6
      Area= pi*D**2/4
      wavespeed= sqrt(z*R*T)
      f=0.015

      delx=PL/(ni-1)
      delt=delx*alpha/wavespeed
      time=irun*delt
      
      A(1)=alpha*wavespeed/Area !coefficient
      A(2)=0.25*f*wavespeed**2*delx/D/Area/Area !coefficient
      A(3)=wavespeed*(1/alpha-alpha)/2.0/Area !coefficient
      
      B(1) = 1/wavespeed/delt
      B(2) = 1/Area/delt
      B(3) = f/2/D/Area/Area
      
      call steadystate(p)
      call steadystatex(px)
      
      pp = Po
      mp = Mo

      ppx=px(51)
      mpx=-Mo
      
      Ho=p(51)-px(51)
      
      call valveI(irun,m,p,mp,pp,tc,Ho)
      call valveII(irun,mx,px,ppx,tc,Ho)
      
      do irun =1, irunmax
      call pipeI(js,je,mx,px,mpx,ppx)
      call valveII(irun,mx,px,mpx,ppx,tc,Ho)
      call reservoirI(mx,px,mpx,ppx)
      
      do j=1,ni
      if(irun>irunmax-10)then
      write(*,*)irun,j,mpx(j),ppx(j)
      end if
      
      mx(j)=mpx(j)
      px(j) = ppx(j)
      end do
      
      open(unit=4,file = 'Plot53.txt')
      write(4,*)(irun-1)*delt,px(50)
      end do
      stop
      
      end program
      
      subroutine steadystate(p)
      implicit none
      integer,parameter :: ni=51
      integer i
      double precision p(ni)
      double precision Mo,Po,Area,wavespeed,D,f,delx
      common/group1/Mo,Po,Area,wavespeed,D,f
      common/group2/delx

      do i=1,ni
      p(i)= sqrt(Po**2-f*wavespeed**2*Mo*Mo*delx*(i-1)/D/Area/Area)
      open(unit=3,file='Initial Pressure.txt')
      write(3,*)i-1,p(i)
      end do
      return
      end
      subroutine steadystatex(px)
      implicit none
      integer,parameter :: nj=51
      integer i
      double precision px(nj)
      double precision Mo,Pe,Area,wavespeed,D,f,delx
      common/group1/Mo,Pe,Area,wavespeed,D,f
      common/group2/delx
      Pe=200000
      do i=1,nj
      px(i)=sqrt(Pe**2+f*wavespeed**2*Mo*Mo*delx*(i)/D/Area/Area)
      open(unit=3,file='Initial Pressure.txt')
      write(3,*)i-1,px(i)
      end do
      return
      end
      subroutine pipeI(js,je,m,p,mp,pp)
      implicit none
      integer,parameter :: ni=51
      double precision m(ni),p(ni),mp(ni),pp(ni)
      integer i,js,je
      double precision c1,c2,r1,f1,f2,f1p,f1m,f2p,f2m,DP,DM
      double precision r2
      double precision A(3)
      common/group4/A

      do 1000 i=js,je
      DP=1
      DM=1

      do while(abs(DP)>0.001.OR.abs(DM)>0.001)
      c1=A(1)*(mp(i)-m(i-1))
      c2=A(3)*0
      r1=A(2)*abs(mp(i)+m(i-1))
      r2=c1*(pp(i)+p(i-1))+pp(i)**2-p(i-1)**2+r1*(mp(i)+m(i-1))
      f1= r2+ c2*(mp(i)-m(i)+mp(i-1)-m(i-1))*(pp(i)+p(i-1))
      f1p=c1+2*pp(i)+c2*(mp(i)-m(i)+mp(i-1)-m(i-1))
      f1m=A(1)*(pp(i)+p(i-1))+2*r1+c2*(pp(i)+p(i-1))

      c1=A(1)*(mp(i)-mp(i+1))
      c2=A(3)*0
      r1=A(2)*abs(mp(i)+m(i+1))
      r2=c1*(pp(i)+p(i+1))-pp(i)**2+p(i+1)**2+r1*(mp(i)+m(i+1))
      f2= r2+c2*(mp(i)-m(i)+mp(i+1)-m(i+1))*(pp(i)+p(i+1))
      f2p= c1-2*pp(i)+c2*(mp(i)-m(i)+mp(i+1)-m(i+1))
      f2m= A(1)*(pp(i)+p(i+1))+2*r1+c2*(pp(i)+p(i+1))

      DP=(f1/f1m-f2/f2m)/(f2p/f2m-f1p/f1m)
      DM=-(f1+f1p*DP)/f1m

      pp(i)=pp(i)+DP
      p(i)=pp(i)
      mp(i)=mp(i)+DM
      m(i)=mp(i)
      end do
1000  continue
      return
      end
      subroutine valveI(irun,m,p,mp,pp,tc,Ho)
      Implicit None
      integer,parameter :: ni=51
      Double Precision, Parameter :: Pi=3.1415926535897932D+0
      Double Precision m(ni),p(ni),mp(ni),pp(ni)
      double precision c1,c2,r1,f1,f2,f1p,DP,r2
      Double Precision time,delm,Mo,delt,u,v,w,vf,tc,x,y,z,Ho
      Double Precision A(3),B(3)
      integer irun

      common/group1/Mo
      common/group3/delt
      common/group4/A,B

      delm=10.0
      time=delt*irun
      DP=1
      Mo=80

      if(time<tc)then
      vf=1-time/tc !valve function
      x=Ho*B(1)/vf/vf/Mo/Mo
      y=B(2)
      z=B(3)*m(ni-1)*abs(m(ni-1))-B(2)*m(ni-1)-B(1)*p(ni)
      mp(ni)=(sqrt(y*y-4*x*z)-y)/2/x !positive mass flowrate
      else
      mp(ni)=0
      end if

      do while(abs(DP)>0.001)
      !following is the Newton-Raphspn iterative method
      c1=A(1)*(mp(ni)-m(ni-1))
      c2=A(3)*0
      r1=A(2)*abs(mp(ni)+m(ni-1))
      r2=c1*(pp(ni)+p(ni-1))+pp(ni)**2-p(ni-1)**2+r1*(mp(ni)+m(ni-1))
      f1= r2+ c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))*(pp(ni)+p(ni-1))
      f1p=c1+2*pp(ni)+c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))

      DP= -f1/f1p
      pp(ni)=pp(ni)+DP
      m(ni)=mp(ni)
      p(ni)=pp(ni)
      end do
      return
      end
      subroutine valveII(irun,m,p,mp,pp,tc,Ho)
      implicit none
      integer, parameter :: ni=51
      Double Precision, Parameter :: Pi=3.1415926535897932D+0
      double precision m(ni),p(ni),mp(ni),pp(ni),DP,c1,c2,r1,f1,f1p,time,delm,delt,a,b,c,vf,tc,Ho,x,y,z,mx
      double precision A(3),B(3)
      integer irun
      
      common/group1/Mo
      common/group3/delt
      common/group4/A,B
      
      delm=10.0
      time=delt*irun
      DP=1
      mx=-80
      
      if(time<tc)then
      vf=1-time/tc
      x=-Ho*B(1)/vf/vf/mx/mx
      y=B(2)
      z=B(3)*m(ni-1)*abs(m(ni-1))-B(2)*m(ni-1)+B(1)*p(ni-1)
      mp(ni)= (sqrt(y*y-4*x*z)-y)/2/x
      else
      mp(ni)=0
      end if
      
      do while(abs(DP)>0.001)
      !following is the Newton-Raphspn iterative method
      c1=A(1)*(mp(ni)-m(ni-1))
      c2=A(3)*0
      r1=A(2)*abs(mp(ni)+m(ni-1))
      r2=c1*(pp(ni)+p(ni-1))+pp(ni)**2-p(ni-1)**2+r1*(mp(ni)+m(ni-1))
      f1= r2+ c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))*(pp(ni)+p(ni-1))
      f1p=c1+2*pp(ni)+c2*(mp(ni)-m(ni)+mp(ni-1)-m(ni-1))

      DP= -f1/f1p
      pp(ni)=pp(ni)+DP
      m(ni)=mp(ni)
      p(ni)=pp(ni)
      end do
      return
      end
      

      
      subroutine reservoirI(m,p,mp,pp)
      implicit none
      integer,parameter:: ni=51
      double Precision m(ni),p(ni),mp(ni),pp(ni)
      double precision A(3),DM,c1,c2,r1,f2,f2p,f2m,r2
      common/group4/A
      pp(1)=p(1)
      DM=1
      do while(abs(DM)>0.001)
      !following is the Newton-Raphspn iterative method
      c1=A(1)*(mp(1)-m(2))
      c2=A(3)*0
      r1=A(2)*abs(mp(1)+m(2))
      r2=c1*(pp(1)+p(2))-pp(1)**2+p(2)**2+r1*(mp(1)+m(2))
      f2= r2+c2*(mp(1)-m(1)+mp(2)-m(2))*(pp(1)+p(2))
      f2m= A(1)*(pp(1)+p(2))+2*r1+c2*(pp(1)+p(2))

      DM= -f2/f2m
      mp(1)=mp(1)+DM
      end do
      return
      end

Last edited by tom0395; 12-10-2014 at 08:09 AM. Reason: code tag addition
 
Old 12-10-2014, 05:13 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,062

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
Please edit your post and add [code] and [/code] tags.
(Details: What information to include in a post and how to use code tags)
 
Old 12-10-2014, 09:43 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137Reputation: 2137
You need to give a lot more information than that. Is this a compile error or a run-time error? Is there an associated line number or variable name? Have you tried adding the -g and/or -fbounds-check flags during compilation (or whatever the equivalent flag name is for your specific compiler)?
 
Old 12-10-2014, 09:58 AM   #4
tom0395
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for your reply. This is a compile error, and there are many variables in the error statement, but I believe the problem is with just array A(3) and B(3). The lines are all in valveII subroutine , and an error log is attached as well. Also, I haven't tried adding yet, because I have no idea how . The compiler i am using is from the website force.lepsch.com.
Attached Thumbnails
Click image for larger version

Name:	Trial7Error.jpg
Views:	24
Size:	54.5 KB
ID:	17076  
 
Old 12-10-2014, 11:02 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,062

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
Basically, your code (or: the code you're trying to compile) has bugs, fix them. Here's a patch that solves the first few errors (too long lines, double-defined variables):
Code:
--- ProgramVII.bak	2014-12-10 17:34:59.000000000 +0100
+++ ProgramVII.for	2014-12-10 17:57:43.000000000 +0100
@@ -1,4 +1,4 @@
-Program ProgramVII
+      Program ProgramVII
       implicit none
       
       integer, parameter ::  ni=51, nj=51
@@ -6,7 +6,8 @@
       integer PL, irun, irunmax,ii,js,je,j
       double precision m(ni),p(ni),mp(ni),pp(ni)
       double precision mx(nj),px(nj),mpx(nj),ppx(nj)
-      double precision T,Mo,Po,Pe,z,R,Area,wavespeed,D,f,alpha,delx,delt,delm,k,i,time,tp,tm,Ho,vf
+      double precision T,Mo,Po,Pe,z,R,Area,wavespeed,D,f,
+     $                 alpha,delx,delt,delm,k,i,time,tp,tm,Ho,vf
       double precision A(3),B(3),tc
       
       common/group1/Mo,Po,Area,wavespeed,D,f,Pe
@@ -211,7 +212,8 @@
       implicit none
       integer, parameter :: ni=51
       Double Precision, Parameter :: Pi=3.1415926535897932D+0
-      double precision m(ni),p(ni),mp(ni),pp(ni),DP,c1,c2,r1,f1,f1p,time,delm,delt,a,b,c,vf,tc,Ho,x,y,z,mx
+      double precision m(ni),p(ni),mp(ni),pp(ni),DP,c1,c2,r1,f1,f1p,
+     $                 time,delm,delt,c,vf,tc,Ho,x,y,z,mx,Mo
       double precision A(3),B(3)
       integer irun
 
Old 12-10-2014, 12:15 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,495

Rep: Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615Reputation: 2615
tom0395

??????


if i can read the tiny tiny jpg image

C:\Users\Cheek\Desktop\Trial 7\trial7.f95

there are blank spaces in that Microsoft Windows folder address

" Trial 7\ "

Are you using MS windows ?
 
Old 12-10-2014, 01:20 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,062

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
(@John_VV: Never mind Windows, gfortran on linux gives errors (and warnings) too.)
 
Old 12-12-2014, 03:06 AM   #8
tom0395
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi NevemTeme, thanks for the reply. I'm relatively new to programming; how do I apply that patch? The problem still stands when I have edited the excessively long lines, so I just could not figure out what is the issue with double definition of variables(Is it related to the common block?) , and other variants of this program worked out pretty fine.

Hi JohnVV, yes I'm using Windows. I'm not sure why is that for you, but when it was pretty fine when I opened it up.
 
Old 12-12-2014, 04:11 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,062

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
Easy: Just read the error-messages, and fix the errors one-by-one (always start with the first error-message; when you are out of errors, fix the warnings too):

too long lines -> use continuation lines
undefined variable -> do define it
double-defined variable (eg a vs A(3)) -> keep one of the two definitions

Last edited by NevemTeve; 12-12-2014 at 04:12 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script returning with error "syntax error: unexpected end of file" n_raghuvanshi Linux - Software 4 08-25-2013 08:49 AM
Kernel compilation fails, "undefined reference to sctp"? bob800 Linux - Kernel 1 06-18-2013 03:42 AM
sudo to solve this error "tar: Error exit delayed from previous errors" ? xombboxer Linux - Newbie 7 03-13-2012 02:26 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
does the G95 or Gfortran support the concept of "module" in fortran95 ztdep Programming 1 09-08-2005 02:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration