This question already has answers here:
Extract substring of Fortran string array
(3 answers)
Extract a single character from a Fortran string
(1 answer)
Access character at specific index in a string in Fortran
(1 answer)
Closed 3 years ago.
I would like to evaluate if the 3rd letter of variable myline is 'C' or not.
I try this:
program main
implicit none
type line
integer :: count = 5
character(len=48) :: list = 'ABCDE'
end type
type(line) :: myline
character(len=1) :: letter = 'C'
write(*,*) myline%count, myline%list
if(myline%list(3) == letter) then
write(*,*) 'TRUE'
else
write(*,*) 'FALSE'
end if
end program
But I get:
$ /usr/local/bin/gfortran8 -mcmodel=medium -fcheck=all -Wl,-rpath=/usr/local/lib/gcc8 -o test test.f90
test.f90:15:15:
if(myline%list(3) == letter) then
1
Error: Syntax error in IF-expression at (1)
test.f90:17:5:
else
1
Error: Unexpected ELSE statement at (1)
test.f90:19:4:
end if
1
Error: Expecting END PROGRAM statement at (1)
I am using gfortran (gcc8) and the Fortran 90 standard.
In Fortran, a character substring reference always needs a start and end position. So what you want here is myline%list(3:3).
You can omit the end position (retaining the colon), for example (3:), and that means the rest of the string. Similarly you can omit the start position and it means from the first character (:3).
As a suggestion, letter would be better declared with the parameter attribute as it is a constant, but what you have would work.
I have been using fortran 77 for several months and line continuation character doesn't work sometimes.
if((b1(j).eq.0d0).and.(b3(j).ne.0d0))then
write(22,*) a1(j),a2(j),a3(j),a4(j),a5(j),a6(j),a7(j),a8(j),
& a9(j),a10(j),a11(j),a12(j),a13(j),a14(j),a15(j),
& b3(j),0.2
else if((b3(j).eq.0d0).and.(b1(j).ne.0d0))then
write(22,*) a1(j),a2(j),a3(j),a4(j),a5(j),a6(j),a7(j),
& a8(j),a9(j),a10(j),a11(j),a12(j),a13(j),
& a14(j),a15(j),b1(j),b2(j)
end if
This is the code and when I compile it, the compiler says that '&' is a invalid character. What I am really curious is that sometimes it works and sometimes it does not. Probably I have a basic misunderstanding in fortran syntax.
final.f:59:72: Error: Expected expression in WRITE statement at (1)
final.f:60:9:
& b3(j),0.2
1
Error: Invalid character in name at (1)
final.f:63:72: Error: Expected expression in WRITE statement at (1)
final.f:64:9:
& a14(j),a15(j),b1(j),b2(j)
1
Error: Invalid character in name at (1)
Anybody can help me?
parameter(m=813,n=616)
real*8 a5(m),a6(m),a7(m),a8(m),a9(m),a10(m),a11(m),a12(m),a13(m)
integer*8 a1(m),a2(m),a3(m),a4(m),p1(n)
real*8 p2(n),p3(n),p4(n),p5(n),p6(n),a14(m),a15(m)
real*8 b1(m),b2(m),b3(m)
character skip80*80
open(11,file='dist.dat')
open(12,file='mksa.dat')
open(13,file='mksb.dat')
open(14,file='mksc.dat')
open(15,file='mksi.dat')
open(22,file='ksaf.dat')
open(23,file='ksbf.dat')
open(24,file='kscf.dat')
open(25,file='ksif.dat')
read(12,*)skip80
do i=1,m
read(12,*) a1(i),a2(i),a3(i),a4(i),a5(i),a6(i),a7(i),
& a8(i),a9(i),a10(i),a11(i),a12(i),a13(i),a14(i),a15(i)
end do
do i=1,n
read(11,*) p1(i),p2(i),p3(i),p4(i),p5(i),p6(i)
end do
do j=1,m
do i=1,n
if(a1(j).eq.p1(i))then
b1(j)=p4(i)
b2(j)=p5(i)
b3(j)=p6(i)
end if
end do
if((b1(j).eq.0d0).and.(b3(j).ne.0d0))then
write(22,*) a1(j),a2(j),a3(j),a4(j),a5(j),a6(j),a7(j),a8(j)
& ,a9(j),a10(j),a11(j),a12(j),a13(j),a14(j),a15(j)
& ,b3(j),0.2
else if((b3(j).eq.0d0).and.(b1(j).ne.0d0))then
write(22,*) a1(j),a2(j),a3(j),a4(j),a5(j),a6(j),a7(j)
& ,a8(j),a9(j),a10(j),a11(j),a12(j),a13(j)
& ,a14(j),a15(j),b1(j),b2(j)
end if
end do
end
I don't know why this code doesn't work:
Dim a
a = InputBox("What time do you want?")
If InStr(a, "pm") Then
(Replace(a, "pm", ""))
a = a + 12
c = MsgBox(a, 0, Time)
WScript.Quit
Else
End If
b = MsgBox(a & form, 0, "L")
Whenever I try to start it, it responds with:
"Error: Expected Statement"
Is it because the Replace statement isn't right or because there's a mistake in the rest of the script?
When you try to run that code you should get the following error
Microsoft VBScript compilation error: Expected statement
Line 4
which will lead you to the culprit which is
(Replace(a, "pm",""))
which isn't a valid statement in VBScript hence the error.
Based on what you are trying to do the script needs to return the result of the Replace() function call, something like this
a = Replace(a, "pm","")
I would like to write a Basic function for Calc that return #VALUE! testable with ISERR().
Function foo()
foo = #VALUE!
End Function
But that foo function return 0 and not some error #VALUE!. How should I do it?
It looks like #VALUE! is only shown when there is a calculation error in the spreadsheet. So it is not possible to return such an error.
Instead, cause a #VALUE! error by returning text when a number is expected:
Function get_number() As Any
'get_number = 0 'This line will not cause an error.
get_number = "" 'This line will cause #VALUE! because it is not a number.
End Function
Set the formula to =ISERR(GET_NUMBER() + 0).
See https://forum.openoffice.org/en/forum/viewtopic.php?t=44830.
This is my program
Subroutine( m,n, bb,AA)
integer::m,n
Real bb(m),AA(m,n)
print*,'enter b value'
read*,bb
print*,'enter A value'
read *,AA
Print*, bb
Print *, AA
end
This is the error, how to solve it;
Compiler Output:
YCbT17Kz.f:1.2:
Subroutine( m,n, bb,AA)
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:1.2:
Subroutine( m,n, bb,AA)
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:2.2:
integer::m,n
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:2.2:
integer::m,n
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:4.1:
Real bb(m),AA(m,n)
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:4.1:
Real bb(m),AA(m,n)
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:6.4:
print*,'enter b value'
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:6.4:
print*,'enter b value'
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:7.2:
read*,bb
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:7.2:
read*,bb
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:8.1:
print*,'enter A value'
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:8.1:
print*,'enter A value'
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:9.2:
read *,AA
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:9.2:
read *,AA
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:11.1:
Print*, bb
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:11.1:
Print*, bb
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:12.1:
Print *, AA
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:12.1:
Print *, AA
1
Error: Unclassifiable statement at (1)
YCbT17Kz.f:13.1:
end
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:13.1:
end
1
Error: Unclassifiable statement at (1)
Subroutine( m,n, bb,AA)
is not a valid Fortran syntax. The language requires
Subroutine name_of_the_subroutine(m, n, bb, AA)
The error message
Real bb(m),AA(m,n)
1
Error: Non-numeric character in statement label at (1)
YCbT17Kz.f:4.1:
suggests you are probably using the fixed source form where a numeric label is expected in columns 1-5. The statement itself must start at column 7 or later. But I can imagine it could be a consequence of a previous error.
The best thing is to try to correct the first error and rename the file to have the suffix .f90 which denotes the free form source as #francescalus suggests in the comment. It is quite possible it will reveal other errors, which you might want to solve yourself or ask a new question about them.
If the online compiler does not allow changing the file name you can try forcing the free form source by a compiler option such as -ffree-form for gfortran and similar for other compilers.