Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm writing Fortran code to input user subroutine in Abaqus.
This example code for UEL example.
I want to make UEL subroutine for hyperelasticity parameters.
I'm first doing Fortran, so I could not solve the errors.
This is my code.
Error is Unclassifiable statement,
but I don't know Fortran method.
c
c Blankholder force contro element for deep drawing applications
c
subroutine uel(rhs, amatrx, svars, energy, ndofel, nrhs, nsvars,
1 props, nprops, coords, mcrd, nnode, u, du, v, a, jtype, time, dtime,
2 kstep, kinc, jelem, params, nload, jdltyp, adlmag, predef, npredf,
3 lfoags, mlvarx, ddlmag, mdload, pnewdt, jprops, njprop, period)
c
include 'aba_param.inc'
c
dimension rhs(mlvarx, *), amatrx(ndofel, ndofel), svars(*), props(*),
1 energy(7), coord(mcrd, nnode), u(ndofel), du(mlvarx, *), v(ndofel),
2 a(ndofel), time(2), params(*), jdltyp(mdload, *), adlmag(mdload, *),
4 ddlag(mdload, *), predef(2, npredf, nnode), lflags(4), jprops(*)
c
c Pick up the input data
c
sPunch = props(1) !Spring stiffness
fPunchTarget = props(2) ! Target punch force
fHolderInit = props(3) ! Initial blankholder force
fractHolder = props(4) ! Fractional change allowed
tolPunch = props(5) ! Tolereance on punch force
c
c Calculate the punch force
c
fPunchNew = sPunch * (u(1)-u(2))
c
c Generate force vector and
c
rhs(1,1) = -fPunchNew
rhs(2,1) = +fpunchNew
c
c Generate stiffness matris
c
amatrx(1,1) = +sPunch
amatrx(1,2) = -sPunch
amatrx(2,1) = -sPunch
c
c The holder force is only applied during steps 2 and 3
c
if(kstep.eq.2) teh
c
c Ramp the punch force to the desired starting value
c
fHolder = time(1)*fHolderInit/period
svars(2) = fHolder
rhs(3,1) = -fHolder
else if(kstep.eq.3) then
c
c Adjust the punch force to control the blankholder force
c
c Values of state variables at start of increment
c
fPunchOld = svars(1) !Punch force
fHolderOld = svars(2) !Blankholder force
fPunchMax = svar(3) !Maximum blankholder force
c
c Allowed change in blankholer force
c
dfHolderMax = fractHolder * fHolderOld
c
c Allowed tolerance in the targetforce
c
dfPunchTol = tolPunch * fPunchTarget
c
c Calculate the holder force
c
if (fPunchOld.gt.fPunchTarget+dfPunchTol) then
fHolerNew = fHolderOld - dfHolderMax !Decrease
else if(fPunchMax.lt.fPunchTarget+dfPunchTol .or.
1 fPunchOld.gt.fPunchTarget-dfPunchTol) then
fHolderNew = fHolderOld
else
fHolderNew = fHolderOld + dfHolderMax !Increase
end if
c
c Generate holer force vector
c
rhs(3,1) = -fHolderNew
c
c Update state variables
c
svars(1) = fPunchNew
svars(2) = fPHolderNew
svars(3) = max(fPunchMax, fPunchNew)
end if
c
return
end
And this is my errors.
my_subroutine.for:4:6:
subroutine uel(rhs, amatrx, svars, energy, ndofel, nrhs, nsvars,
1
Error: Bad continuation line at (1)
my_subroutine.for:4:6:
subroutine uel(rhs, amatrx, svars, energy, ndofel, nrhs, nsvars,
1
Error: Unclassifiable statement at (1)
my_subroutine.for:5:6:
1 props, nprops, coords, mcrd, nnode, u, du, v, a, jtype, time, dtime,
1
Error: Unclassifiable statement at (1)
my_subroutine.for:6:6:
2 kstep, kinc, jelem, params, nload, jdltyp, adlmag, predef, npredf,
1
Error: Unclassifiable statement at (1)
my_subroutine.for:7:6:
3 lfoags, mlvarx, ddlmag, mdload, pnewdt, jprops, njprop, period)
1
Error: Unclassifiable statement at (1)
aba_param.inc:17:57:
PARAMETER(IALLD=0,IRMMD=4,NEMPTY=0,ISPIND=2,IGRAD=0)
1
Error: Unexpected characters in PARAMETER statement at (1)
my_subroutine.for:12:6:
1 energy(7), coord(mcrd, nnode), u(ndofel), du(mlvarx, *), v(ndofel),
1
Error: Unclassifiable statement at (1)
my_subroutine.for:13:6:
2 a(ndofel), time(2), params(*), jdltyp(mdload, *), adlmag(mdload, *),
1
Error: Unclassifiable statement at (1)
my_subroutine.for:14:6:
4 ddlag(mdload, *), predef(2, npredf, nnode), lflags(4), jprops(*)
1
Error: Unclassifiable statement at (1)
my_subroutine.for:46:6:
svars(2) = fHolder
1
Error: Unclassifiable statement at (1)
my_subroutine.for:47:6:
rhs(3,1) = -fHolder
1
Error: Unclassifiable statement at (1)
my_subroutine.for:48:5:
else if(kstep.eq.3) then
1
Error: Non-numeric character in statement label at (1)
my_subroutine.for:48:5:
else if(kstep.eq.3) then
1
Error: Unclassifiable statement at (1)
my_subroutine.for:79:6:
rhs(3,1) = -fHolderNew
1
Error: Unclassifiable statement at (1)
my_subroutine.for:83:11: Error: 'svars' at (1) is not a variable
my_subroutine.for:84:11: Error: 'svars' at (1) is not a variable
my_subroutine.for:85:11: Error: 'svars' at (1) is not a variable
f951.exe: Error: Unexpected end of file in 'my_subroutine.for'
How can I solve this error and use Fortran method?
You are using so-called "fixed-form" Fortran with lines continuation signaled by a character in the 6th column, see the Fortran Wiki page about this.
From the error, you apparently miss one space on every beginning of line (the error is at character 6 of the line), provided the formatting in the question is correct.
Make sure that the "continuation character" (here, the 1, 2 and 3) are on the sixth column.
You can also decide to switch to "free form" Fortran in which continuation lines are indicated differently.
Related
I am trying to use quadpack in Microsoft Visual using Intel Fortran.
From netlib I downloaded: dqag.f, dqage.f, dqk15.f, dqk21.f, dqk31.f, dqk41.f, dqk51.f, dqk61.f, dqpsrt.f, dquad.f, fdump.f, j4save.f, s88fmt.f, testf4.f, xerabt.f, xerctl.f, xerprt.f, xerror.f, xerrwv.f, xersav.f, xgetua.f.
to try to recreate the result from makefile.2.
And I get the errors:
Severity Code Description Project File Line Suppression State
Error Compilation Aborted (code 1) C:\Users\...\test_quadpack\xerrwv.f 1
Error error #6633: The type of the actual argument differs from the type of the dummy argument. [LFIRST] C:\Users\...\test_quadpack\xerrwv.f 65
Error error #6633: The type of the actual argument differs from the type of the dummy argument. [MESSG] C:\Users\...\test_quadpack\xerrwv.f 127
Error error #6634: The shape matching rules of actual arguments and dummy arguments have been violated. [MESSG] C:\Users\C:\Users\...\test_quadpack\xerrwv.f 127
These errors I get from xerrmv.f which can be downloaded from xerrmv.f line 65, 127 and 127
subroutine xerrwv(messg,nmessg,nerr,level,ni,i1,i2,nr,r1,r2)
c
c abstract
c xerrwv processes a diagnostic message, in a manner
c determined by the value of level and the current value
c of the library error control flag, kontrl.
c (see subroutine xsetf for details.)
c in addition, up to two integer values and two real
c values may be printed along with the message.
c
c description of parameters
c --input--
c messg - the hollerith message to be processed.
c nmessg- the actual number of characters in messg.
c nerr - the error number associated with this message.
c nerr must not be zero.
c level - error category.
c =2 means this is an unconditionally fatal error.
c =1 means this is a recoverable error. (i.e., it is
c non-fatal if xsetf has been appropriately called.)
c =0 means this is a warning message only.
c =-1 means this is a warning message which is to be
c printed at most once, regardless of how many
c times this call is executed.
c ni - number of integer values to be printed. (o to 2)
c i1 - first integer value.
c i2 - second integer value.
c nr - number of real values to be printed. (0 to 2)
c r1 - first real value.
c r2 - second real value.
c
c examples
c call xerror(29hsmooth -- num (=i1) was zero.,29,1,2,
c 1 1,num,0,0,0.,0.)
c call xerrwv(54hquadxy -- requested error (r1) less than minimum
c 1 (r2).,54,77,1,0,0,0,2,errreq,errmin)
c
c written by ron jones, with slatec common math library subcommittee
c latest revision --- 19 mar 1980
c
dimension messg(nmessg),lun(5)
c get flags
lkntrl = j4save(2,0,.false.)
maxmes = j4save(4,0,.false.)
c check for valid input
if ((nmessg.gt.0).and.(nerr.ne.0).and.
1 (level.ge.(-1)).and.(level.le.2)) go to 10
if (lkntrl.gt.0) call xerprt(17hfatal error in...,17)
call xerprt(23hxerror -- invalid input,23)
if (lkntrl.gt.0) call fdump
if (lkntrl.gt.0) call xerprt(29hjob abort due to fatal error.,
1 29)
if (lkntrl.gt.0) call xersav(1h ,0,0,0,kdummy)
call xerabt(23hxerror -- invalid input,23)
return
10 continue
c record message
junk = j4save(1,nerr,.true.)
call xersav(messg,nmessg,nerr,level,kount)
c let user override
lfirst = messg(1)
lmessg = nmessg
lerr = nerr
llevel = level
call xerctl(lfirst,lmessg,lerr,llevel,lkntrl)
c reset to original values
lmessg = nmessg
lerr = nerr
llevel = level
lkntrl = max0(-2,min0(2,lkntrl))
mkntrl = iabs(lkntrl)
c decide whether to print message
if ((llevel.lt.2).and.(lkntrl.eq.0)) go to 100
if (((llevel.eq.(-1)).and.(kount.gt.min0(1,maxmes)))
1.or.((llevel.eq.0) .and.(kount.gt.maxmes))
2.or.((llevel.eq.1) .and.(kount.gt.maxmes).and.(mkntrl.eq.1))
3.or.((llevel.eq.2) .and.(kount.gt.max0(1,maxmes)))) go to 100
if (lkntrl.le.0) go to 20
call xerprt(1h ,1)
c introduction
if (llevel.eq.(-1)) call xerprt
1(57hwarning message...this message will only be printed once.,57)
if (llevel.eq.0) call xerprt(13hwarning in...,13)
if (llevel.eq.1) call xerprt
1 (23hrecoverable error in...,23)
if (llevel.eq.2) call xerprt(17hfatal error in...,17)
20 continue
c message
call xerprt(messg,lmessg)
call xgetua(lun,nunit)
do 50 kunit=1,nunit
iunit = lun(kunit)
if (iunit.eq.0) iunit = i1mach(4)
if (ni.ge.1) write (iunit,22) i1
if (ni.ge.2) write (iunit,23) i2
if (nr.ge.1) write (iunit,24) r1
if (nr.ge.2) write (iunit,25) r2
22 format (11x,21hin above message, i1=,i10)
23 format (11x,21hin above message, i2=,i10)
24 format (11x,21hin above message, r1=,e20.10)
25 format (11x,21hin above message, r2=,e20.10)
if (lkntrl.le.0) go to 40
c error number
write (iunit,30) lerr
30 format (15h error number =,i10)
40 continue
50 continue
c trace-back
if (lkntrl.gt.0) call fdump
100 continue
ifatal = 0
if ((llevel.eq.2).or.((llevel.eq.1).and.(mkntrl.eq.2)))
1ifatal = 1
c quit here if message is not fatal
if (ifatal.le.0) return
if ((lkntrl.le.0).or.(kount.gt.max0(1,maxmes))) go to 120
c print reason for abort
if (llevel.eq.1) call xerprt
1 (35hjob abort due to unrecovered error.,35)
if (llevel.eq.2) call xerprt
1 (29hjob abort due to fatal error.,29)
c print error summary
call xersav(1h ,-1,0,0,kdummy)
120 continue
c abort
if ((llevel.eq.2).and.(kount.gt.max0(1,maxmes))) lmessg = 0
call xerabt(messg,lmessg)
return
end
This is the main program:
program dquad
c driver for quadpack
implicit double precision (a-h, o-z)
external f
parameter (limit=50, lenw=4*limit)
dimension iwork(limit), work(lenw)
open (unit=8, file='outquad', iostat=ios, err=100)
c lower limit of itegration
a=-1.0d+00
c upper limit of integration
b=2.0d+00
c absolute accuracy requested
epsabs=1.0d-15
c relative accuracy requested
epsrel=1.0d-09
do 20 l=1, 3000
c key for choice of local integration rule:
c a Gauss-Kronrod pair is used with
c 7 - 15 points if key .lt. 2,
c 10 - 21 points if key = 2,
c 15 - 31 points if key = 3,
c 20 - 41 points if key = 4,
c 25 - 51 points if key = 5,
c 30 - 61 points if key .gt. 5
do 10 key=1, 6
call dqag (f, a, b, epsabs, epsrel, key, result, abserr, neval,
* ier, limit, lenw, last, iwork, work)
if (l .eq. 1) then
write (8, *) 'integral =', result
write (8, *) 'absolute error =', abserr
write (8, *) 'number of integrand evaluations=', neval
end if
10 continue
20 continue
stop
100 write (8, *) 'ios=', ios
stop
end
Also from netlib quad.f.
And this is the function that should be integrated, it's just an example, it not the function that I am gonna integrate in my research,
I just want to learn to integrate quadpack in my code.
double precision function f(x)
implicit double precision (a-h, o-z)
f = 1.0d+00 + x * x + 1.0d+00 / (1.0d+00 + 1.0d+02 * x * x)
return
end
This is from netlib [testf4.f] (http://netlib.org/alliant/quad/testf4.f).
This is xerctl.f
SUBROUTINE XERCTL(MESSG1,NMESSG,NERR,LEVEL,KONTRL)
C***BEGIN PROLOGUE XERCTL
C***DATE WRITTEN 790801 (YYMMDD)
C***REVISION DATE 820801 (YYMMDD)
C***CATEGORY NO. R3C
C***KEYWORDS ERROR,XERROR PACKAGE
C***AUTHOR JONES, R. E., (SNLA)
C***PURPOSE Allows user control over handling of individual errors.
C***DESCRIPTION
C Abstract
C Allows user control over handling of individual errors.
C Just after each message is recorded, but before it is
C processed any further (i.e., before it is printed or
C a decision to abort is made), a call is made to XERCTL.
C If the user has provided his own version of XERCTL, he
C can then override the value of KONTROL used in processing
C this message by redefining its value.
C KONTRL may be set to any value from -2 to 2.
C The meanings for KONTRL are the same as in XSETF, except
C that the value of KONTRL changes only for this message.
C If KONTRL is set to a value outside the range from -2 to 2,
C it will be moved back into that range.
C
C Description of Parameters
C
C --Input--
C MESSG1 - the first word (only) of the error message.
C NMESSG - same as in the call to XERROR or XERRWV.
C NERR - same as in the call to XERROR or XERRWV.
C LEVEL - same as in the call to XERROR or XERRWV.
C KONTRL - the current value of the control flag as set
C by a call to XSETF.
C
C --Output--
C KONTRL - the new value of KONTRL. If KONTRL is not
C defined, it will remain at its original value.
C This changed value of control affects only
C the current occurrence of the current message.
C***REFERENCES JONES R.E., KAHANER D.K., "XERROR, THE SLATEC ERROR-
C HANDLING PACKAGE", SAND82-0800, SANDIA LABORATORIES,
C 1982.
C***ROUTINES CALLED (NONE)
C***END PROLOGUE XERCTL
CHARACTER*20 MESSG1
C***FIRST EXECUTABLE STATEMENT XERCTL
RETURN
END
This is xerror.f
subroutine xerror(messg,nmessg,nerr,level)
c
c abstract
c xerror processes a diagnostic message, in a manner
c determined by the value of level and the current value
c of the library error control flag, kontrl.
c (see subroutine xsetf for details.)
c
c description of parameters
c --input--
c messg - the hollerith message to be processed, containing
c no more than 72 characters.
c nmessg- the actual number of characters in messg.
c nerr - the error number associated with this message.
c nerr must not be zero.
c level - error category.
c =2 means this is an unconditionally fatal error.
c =1 means this is a recoverable error. (i.e., it is
c non-fatal if xsetf has been appropriately called.)
c =0 means this is a warning message only.
c =-1 means this is a warning message which is to be
c printed at most once, regardless of how many
c times this call is executed.
c
c examples
c call xerror(23hsmooth -- num was zero.,23,1,2)
c call xerror(43hinteg -- less than full accuracy achieved.,
c 43,2,1)
c call xerror(65hrooter -- actual zero of f found before interval
c 1 fully collapsed.,65,3,0)
c call xerror(39hexp -- underflows being set to zero.,39,1,-1)
c
c written by ron jones, with slatec common math library subcommittee
c latest revision --- 7 feb 1979
c
dimension messg(nmessg)
call xerrwv(messg,nmessg,nerr,level,0,0,0,0,0.,0.)
return
end
I think the problem is with the messages like this from here:
if(ier.ne.0) call xerror(26habnormal return from dqag ,26,ier,lvl)
but I don't know to fix it.
Can I use in main Fortran 90, where I call the subroutine to integrate? How it is supposed to look? I'm not familiar with fortran 77.
Any suggestion for dealing with this is greatly appreciated.
Hey I am trying to get my LAPACK libraries to work and I have searched and searched but I can't seem to figure out what I am doing wrong.
I try running my code, and I get the following error
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x7FFB23D405F7
#1 0x7FFB23D40C3E
#2 0x7FFB23692EAF
#3 0x401ED1 in sgesv_
#4 0x401D0B in MAIN__ at CFDtest.f03:? Segmentation fault (core dumped)
I will paste my main code here, hopefully someone can help me with this problem.
****************************************************
PROGRAM CFD_TEST
USE MY_LIB
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION ET(0:10), VN(0:10), WT(0:10)
DIMENSION SO(0:10), FU(0:10), DMA(0:10,0:10)
DIMENSION DMA2(0:10,0:10), QN(0:10), WKSPCE(0:10)
INTEGER*8 :: pivot(10), inf
INTEGER*8 :: N
EXTERNAL SGESV
!SET THE PARAMETERS
SIGMA1 = 0.D0
SIGMA2 = 0.D0
TAU = 1.D0
EF = 1.D0
EXP = 2.71828182845904509D0
COST = EXP/(1.D0+EXP*EXP)
DO 1 N=2, 10
!COMPUATION OF THE NODES, WEIGHTS AND DERIVATIVE MATRIX
CALL ZELEGL(N,ET,VN)
CALL WELEGL(N,ET,VN,WT)
CALL DMLEGL(N,10,ET,VN,DMA)
!CONSTRUCTION OF THE MATRIX CORRESPONDING TO THE
!DIFFERENTIAL OPERATOR
DO 2 I=0, N
DO 2 J=0, N
SUM = 0.D0
DO 3 K=0, N
SUM = SUM + DMA(I,K)*DMA(K,J)
3 CONTINUE
OPER = -SUM
IF(I .EQ. J) OPER = -SUM + TAU
DMA2(I,J) = OPER
2 CONTINUE
!CHANGE OF THE ENTRIES OF THE MATRIX ACCORDING TO THE
!BOUNDARY CONDITIONS
DO 4 J=0, N
DMA2(0,J) = 0.D0
DMA2(N,J) = 0.D0
4 CONTINUE
DMA2(0,0) = 1.D0
DMA2(N,N) = 1.D0
!CONSTRUCTION OF THE RIGHT-HAND SIDE VECTOR
DO 5 I=1, N-1
FU(I) = EF
5 CONTINUE
FU(0) = SIGMA1
FU(N) = SIGMA2
!SOLUTION OF THE LINEAR SYSTEM
N1 = N + 1
CALL SGESV(N,N,DMA2,pivot,FU,N,inf)
DO 6 I = 0, N
FU(I) = SO(I)
6 CONTINUE
PRINT *, pivot
1 CONTINUE
RETURN
END PROGRAM CFD_TEST
*****************************************************
The commands I run to compile are
gfortran -c MY_LIB.f03
gfortran -c CFDtest.f03
gfortran MY_LIB.o CFDtest.o -o CFDtest -L/usr/local/lib -llapack -lblas
I ran the command
-fbacktrace -g -Wall -Wextra CFDtest
CFDtest: In function _fini':
(.fini+0x0): multiple definition of_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o:/build/buildd/glibc-2.19/csu/../sysdeps/x86_64/crti.S:80: first defined here
CFDtest: In function data_start':
(.data+0x0): multiple definition ofdata_start'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
CFDtest: In function data_start':
(.data+0x8): multiple definition of__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o:(.data+0x0): first defined here
CFDtest:(.rodata+0x0): multiple definition of _IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
CFDtest: In function_start':
(.text+0x0): multiple definition of _start'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
CFDtest: In function_init':
(.init+0x0): multiple definition of _init'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o:/build/buildd/glibc-2.19/csu/../sysdeps/x86_64/crti.S:64: first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o:(.tm_clone_table+0x0): multiple definition of__TMC_END'
CFDtest:(.data+0x10): first defined here
/usr/bin/ld: error in CFDtest(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
You haven't posted your code for MY_LIB.f03 so we cannot compile CFDtest.f03 exactly as you have supplied it.
(As an aside, the usual naming convention is that f90 in a .f90 file is not supposed to imply the language version being targeted. Rather, .f90 denotes free format while .f is used for fixed format. By extension, your .f03 files would be better (i.e., more portable if) named as .f90.)
I commented out the USE MY_LIB line and ran your code through nagfor -u -c cfd_test.f90. The output, broken down, is
Extension: cfd_test.f90, line 13: Byte count on numeric data type
detected at *#8
Extension: cfd_test.f90, line 15: Byte count on numeric data type
detected at *#8
Byte counts are not portable. The kind value for an 8-byte integer is selected_int_kind(18). (Similarly you might like to use a kind(0.0d0) kind value for your double precision data.)
Error: cfd_test.f90, line 48: Implicit type for I
detected at 2#I
Error: cfd_test.f90, line 50: Implicit type for J
detected at 2#J
Error: cfd_test.f90, line 54: Implicit type for K
detected at 3#K
Error: cfd_test.f90, line 100: Implicit type for N1
detected at N1#=
You have these implicitly typed, which implies they are 4-byte (default) integers. You should probably declare these explicitly as 8-byte integers (using the 8-byte integer kind value above) if that's what you intend.
Questionable: cfd_test.f90, line 116: Variable COST set but never referenced
Questionable: cfd_test.f90, line 116: Variable N1 set but never referenced
Warning: cfd_test.f90, line 116: Unused local variable QN
Warning: cfd_test.f90, line 116: Unused local variable WKSPCE
You need to decide what you intend to do with these, or whether they are just deletable cruft.
With the implicit integers declared explicitly, there is further output
Warning: cfd_test.f90, line 116: Variable SO referenced but never set
This looks bad.
Obsolescent: cfd_test.f90, line 66: 2 is a shared DO termination label
Your DO loops would probably be better using the modern END DO terminators (not shared!)
Error: cfd_test.f90, line 114: RETURN is only allowed in SUBROUTINEs and FUNCTIONs
This is obviously easy to fix.
For the LAPACK call, one source of explicit interfaces for these routines is the NAG Fortran Library (through the nag_library module). Since your real data is not single precision, you should be using dgesv instead of sgesv. Adding USE nag_library, ONLY: dgesv and switching to call dgesv instead of sgesv, then recompiling as above, reveals
Incorrect data type INTEGER(KIND=4) (expected INTEGER) for argument N (no. 1) of DGESV
so you should indeed be using default (4-byte integers) - at least for the LAPACK build on your system, which will almost certainly be using 4-byte integers. Thus you might want to forget all about kinding your integers and just use the default integer type for all. Correcting this gives
Array supplied for scalar argument LDA (no. 4) of DGESV
so you do need to add this argument. Maybe pass size(DMA2,1)?
With this argument added to the call the code compiles successfully, but without the definitions for your *LEGL functions I couldn't go through any run-time testing.
Here is my modified (and pretty-printed) version of your program
Program cfd_test
! Use my_lib
! Use nag_library, Only: dgesv
Implicit None
Integer, Parameter :: wp = kind(0.0D0)
Real (Kind=wp) :: ef, oper, sigma1, sigma2, tau
Integer :: i, inf, j, k, n, sum
Real (Kind=wp) :: dma(0:10, 0:10), dma2(0:10, 0:10), et(0:10), fu(0:10), &
so(0:10), vn(0:10), wt(0:10)
Integer :: pivot(10)
External :: dgesv, dmlegl, welegl, zelegl
Intrinsic :: kind, size
! SET THE PARAMETERS
sigma1 = 0._wp
sigma2 = 0._wp
tau = 1._wp
ef = 1._wp
Do n = 2, 10
! COMPUATION OF THE NODES, WEIGHTS AND DERIVATIVE MATRIX
Call zelegl(n, et, vn)
Call welegl(n, et, vn, wt)
Call dmlegl(n, 10, et, vn, dma)
! CONSTRUCTION OF THE MATRIX CORRESPONDING TO THE
! DIFFERENTIAL OPERATOR
Do i = 0, n
Do j = 0, n
sum = 0._wp
Do k = 0, n
sum = sum + dma(i, k)*dma(k, j)
End Do
oper = -sum
If (i==j) oper = -sum + tau
dma2(i, j) = oper
End Do
End Do
! CHANGE OF THE ENTRIES OF THE MATRIX ACCORDING TO THE
! BOUNDARY CONDITIONS
Do j = 0, n
dma2(0, j) = 0._wp
dma2(n, j) = 0._wp
End Do
dma2(0, 0) = 1._wp
dma2(n, n) = 1._wp
! CONSTRUCTION OF THE RIGHT-HAND SIDE VECTOR
Do i = 1, n - 1
fu(i) = ef
End Do
fu(0) = sigma1
fu(n) = sigma2
! SOLUTION OF THE LINEAR SYSTEM
Call dgesv(n, n, dma2, size(dma2,1), pivot, fu, n, inf)
Do i = 0, n
fu(i) = so(i)
End Do
Print *, pivot
End Do
End Program
In general your development experience will be the most pleasant if you use as good a checking compiler as you can get your hands on and if you make sure you ask it to diagnose as much as it can for you.
As far as I can tell, there could be a number of problems:
Your integers with INTEGER*8 might be too long, maybe INTEGER*4 or simply INTEGER would be better
You call SGESV on double arguments instead of DGESV
Your LDA argument is missing, so your code should perhaps look like CALL DGESV(N,N,DMA2,N,pivot,FU,N,inf) but you need to check whether this is what you want.
I am getting an eror "Invalid character in name at (1)" in my Fortran 77 program. Why is this?
It is in my read statement
100 READ(S,*,END=200) LINE
but I am not sure why
Code:
PROGRAM Exercise
C
C PARAMETERS
C
INTEGER UNUM
PARAMETER (UNUM=15)
C
C LOCAL VARIABLES
C
REAL LINES
C
C FUNCTION DECLARATIONS
C
REAL NUMLIN
C
C COMMON VARIABLES
C
C
C DATA STATEMENTS
C
C MAIN PROGRAM MODULE
C
OPEN(UNIT=UNUM, FILE = 'line.txt', STATUS='OLD')
LINES=NUNMLIN(UNUM)
C
C Rewinding to the top of the file because the pointer is at the end
C of the file
C
REWIND(UNUM)
CLOSE(UNUM)
CALL PROCES(UNUM,LINES)
STOP
END PROGRAM
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C SUBROUTINE PROCES
C
C dynamically allocates space
C
SUBROUTINE PROCES(U,L)
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C FUNCTIONS
C
C NUMLIN - counts the number of lines, uses the fact that the file
C is already open and passes this information to the next subroutine
C
REAL FUNCTION NUMLIN(S)
REAL NUMLIN
REAL S
CHARACTER*256 LINE
100 READ(S,*,END=200) LINE
NUMLIN=NUMLIN+1
GOTO 100
200 CONTINUE
RETURN
END
Error:
NumberCountingExercise.for:90.7:
100 READ(S,*,END=200) LINE
1
Error: Invalid character in name at (1)
NumberCountingExercise.for:93.7:
200 CONTINUE
1
Error: Invalid character in name at (1)
NumberCountingExercise.for:85.27:
In fixed source form, a statement label should appear in columns 1 to 5.
100 and 200 are (starting in column 7) in the statement field and are taken as being part of entities' names. A name must begin with a letter.
the next program has an error and I don't know which is the trouble with.
IMPLICIT NONE
DOUBLE PRECISION X(100),W(100),lambdainv,g,lambda,alfac
INTEGER i, N
N=100
alfac=939.D0*2.D22
CALL GAUSS_L(1.D0,100.D0,100,X,W)
lambdainv=0.D0
DO i=1,N
lambdainv=lambdainv+((W(i)*(X(i))**2)/(alfac+
> (X(i))**2))*g(X(i)))**2
END DO
lambda=lambdainv**(-1)
WRITE(*,*)'lambda=', lambda
STOP
END
c Funcion g
DOUBLE PRECISION FUNCTION g(X)
IMPLICIT NONE
DOUBLE PRECISION X, mu, pi
c Inicializamos las variables
mu=138.d0
pi=ATAN(1.D0)*4.D0
g=(2.d0*sqrt(mu**3))/((sqrt(pi))*(mu**2+X**2))
RETURN
END
The error is:
lambdainv=lambdainv+((W(i)*(X(i))**2)/(alfac+
1
Error: Unclassifiable statement at (1)
thanks!!
Your brackets are unbalanced in the corresponding line, when you take into account the continuation of that line!
Do you mean:
lambdainv=lambdainv+( W(i)*X(i)**2 / (alfac+
> X(i)**2)*g(X(i)))**2
(This is a wild guess, of course!)
I am trying to read a file cs251_1.dat in Fortran and then trying to create a new file using the data from cs251_1.dat. The file cs251_1.dat was written by another Fortran program and the data inside this file is two spaces followed by a three digit number followed by two spaces with a total of four numbers on a line. However, I get the following error
C:\Users\Cornelius\Documents\~Source5.f:3:
open(5, File = 'C:cs251_1.dat')
1
C:\Users\Cornelius\Documents\~Source5.f:6: (continued):
Integer A
2
Statement at (2) invalid in context established by statement at (1)
This is the program:
open(5, File = 'C:cs251_1.dat')
open(6, File = 'C:cs251_2.out')
Integer A, B, C, D
total = 0.
E = 1
Integer Selection = 1
total = Selection + 1
Print *, 'Let''s do some math!!'
* 16 continue
Read(5, 65) A, B, C, D
65 Format(I4, I4, I4, I4)
write(6,66)
66 Format(4(2x, I4))
You can't have a declaration after an active statement. That is what your compiler means by "Statement at (2) invalid in context established by statement at (1)". So change the order of the statements.