Fortran string formatting issues [duplicate] - fortran

This question already has answers here:
invalid character name at (1)
(2 answers)
Compilation error: Invalid character in name at (1)
(1 answer)
Closed 3 years ago.
I'm having some issues coding in fortran for a school assignment. I'm trying to write a sentence all on one line (per request of the instructor), but I'm having format issues.
From my understanding I need to use the & to concat the two lines (see below)
I've tried multiple variants of this but I'm having no luck.
'''[j87n896#csci305 fortran]$ gfortran money.f -o money
money.f:94:67:
94 | write(*,*) lunks,'lunkers',loons,'loonters',lits,'littles' &
| 1:
95 | & poons, 'pooneys'
| 1
Error: Invalid character in name at (1)'''

In case you are coding in fixed form - and I believe you are - line continuation is done by adding any non-zero and non-blank character in the sixth column of the second line:
write(*,*) lunks,'lunkers',loons,'loonters',lits,'littles',
+ poons, 'pooneys'
In the case above, I have used a +, but any non-zero/blank char in the 6th column of the second line will do it. You can also extend it to split into more lines by adding chars at the 6th column of the third line, fourth line and so on.
In case you are coding in free form, the continuation is done by adding a & in the end of the first line and in the beginning of the next line (although this last one is not always required):
write(*,*) lunks,'lunkers',loons,'loonters',lits,'littles', &
& poons, 'pooneys'
You may benefit from reading this unofficial copy of the Fortran Standard. Item 6.3.2.4 describes continuation in free format, while item 6.3.3.3 describes continuation in fixed format (which I believe to be your case). You should not expect to understand every single thing you read there, but the sooner you start to try, the sooner it will make some sense for you.
Also, in your example there is a comma missing right after 'littles'. I've fixed that in both examples. Check it out.

Related

Syntax error in compiling an old Fortran code [duplicate]

This question already has answers here:
Syntax error in a Fortran FORMAT statement
(1 answer)
Fortran :: Syntax error in OPEN statement at (1)
(1 answer)
Syntax error in argument list of a subroutine
(1 answer)
Closed 1 year ago.
I am using someone's Fortran scripts, I have changed a little bit in that. Now I am having a syntax error while executing it. I am new to Fortran so not able to figure it out.
The code is as follows:
integer i_canorg
integer i
integer n
integer canorg(n)
real r1demdoms(n)
real r1supdoms(n)
real r1supdomcan(n)
real r1rivout(n)
real r1envflw(n)
if(canorg(i).ne.0)then
i0l_canorg=canorg(i)
call calc_supcan1(i_canorg,r1demdoms(i),r1supdoms(i),r1rivout(i_canorg),r1envflw(i_canorg),r1supdomcan(i))
end if
The code is very long, I additionally added the if command and i_canorg parameter.
I am getting the following error while running the code:
348 | call calc_supcan1(i0lcanorg,r1demdoms(i),r1supdoms(i),r1rivout(i_canorg),r1envflw(i_canorg),r1supdomcan(i))
| 1
Error: Syntax error in argument list at (1)
What can be the reason behind this syntax error?
The reason the program is not compiling is that the line is too long, and unfortunately your compiler's error is not helpful for figuring that out. The dead giveaway is that, including the six spaces at the beginning of the line in the error message, the 1 in the error message is at column 73. Your compiler is interpreting the source code in fixed source form, which has some very particular requirements: see section 3.3.2 of N1191 for complete details.
Your compiler should have an option to specify that your source code should be interpreted in free source form. Based on your error message, it looks like you are most likely using gfortran, which has the command-line option -ffree-line-length-[n]. Check the documentation and set it to an appropriate value for your source code.
If you wish to continue to use fixed source form, then the line has to be broken into multiple lines with a continuation character in the sixth column of each continued line. The character can be anything except a space ( ) or a zero (0), and is ignored if it is in a comment line (a line beginning with the letter C or an asterisk (*)). This is one possible way of fixing the line:
****** <- note the six special columns at the beginning of the line
call calc_supcan1(i_canorg,r1demdoms(i),r1supdoms(i),
> r1rivout(i_canorg),r1envflw(i_canorg),r1supdomcan(i))

What does this syntax mean in fortran?

I am working on a project and as I have not coded with Fortran before, I am struggling a lot. My professor gave me a code file which I need to fix but I don't understand the syntax.
So, in the file he has
g = some formula,
1 some formula
2 * some formula
3 / some formula.
What does 1, 2, 3, * and / do?
I asked my Professor, and he said that this is Fortran 77 code and 1, 2, 3 are used as indexing in column 6 and the g is in column 7 as that's how the Fortran code is written. But I was very confused why Fortran 77 only accepts code after column 7?
Thank you for all the replies.
What you are most likely looking at is Fixed source-form statement continuation which is part of the Fixed source form.
Fixed-form formatting is an old way of formatting code which still stems from the old punched-cards. Lines could only be 72 characters long, but sometimes you needed more. Hence, the statement-continuation character:
Except within commentary, character position 6 is used to indicate continuation. If character position 6 contains a blank or zero, the line is the initial line of a new statement, which begins in character position 7. If character position 6 contains any character other than blank or zero, character positions 7–72 of the line constitute a continuation of the preceding non-comment line.
source: Fortran 2018 Standard, Section 6.3.3.3
Which character is used as statement-continuation marker, is up to the programmer and his style. Often you see a <ampersand>-character (&), or <dollar>-character ($) or the <asterisk>-character (*) like so:
c23456789012345678901234567890123456789012345678901234567890123456789012
g = something long
& + something_longer
& + something_even_longer
However, in the really old days, people often numbered their lines.
c23456789012345678901234567890123456789012345678901234567890123456789012
0g = something long
1 + something_longer
2 + something_even_longer
and because space was limited, they removed all spaces, which sometimes becomes very confusing when you have numbers in your line:
c23456789012345678901234567890123456789012345678901234567890123456789012
0g=1.2345+
10.35697-
22.5789
This does not add 10.35697 and subtract 22.5789, but adds 0.35697 and subtracts 2.5789
The usage of numbers as statement continuation markers is again inherited from the punched-cards. A single punched-card represented a single Fortran statement. And on the card, the row and column numbers were printed (Thanks to High Performance Mark for this information)
Note: the asterisk and slash in the OP are nothing more than the normal multiplication and division.

problem with define dimensions of variables fortran 77

I found this one old fortran 77 program printed in one old book, and i typed in the program but it isnt running. When I give the dimensions of variables, appear the next:
DIMENSION XN(20),YN(20),W(20),NUMAJ(20),NUMAAJ(20),SSW(20)
1,NEJI(5,20),QX(20,20),QY(20,20),IACTE(20),N1(20),N2(20),X(20)
2,Y(20),DD(20),TT(20),NUMAJA(20)
And the error code:
Error: Non-numeric character in statement label at (1)
Error: Unclassifiable statement at (1)
Thanks a lot,
Comparing the original and edited version shows still incorrect indenting: fixed format reserves columns 1-5 for labels, 6 for the continuation character and starting from 7 for the statements. If column 6 is not a space the line continues the previous line.
In the 3 line example above the characters "1" and "2" are the continuation characters of line 2 and 3, so they have to be exactly in column 6. The first line has no label or continuation character so it must start in column 7. The comment from #melpomene was incomplete regarding continuation character and based on the old version where one space less was used (the edited version has one space too much).

Notepad ++ : Regular expression to join multiple lines in single line [duplicate]

This question already has an answer here:
Notepad++ : Insert blank new line after match of some string
(1 answer)
Closed 4 years ago.
I have to join lines to make questions (having serial no. in order 1,2,3....) in one line and all options as shown below in another single line ? Example :
1.For his alleged
involvements in
espio-nage
(1) abc
(2) saf
(3) asf
(4) aqg
Output should be:
1. For his alleged involvement in espio-nage...
(1)abc (2)saf (3)asf (4)aqg
Note:I just want to make it compact to read in kindle reader so that maximum space will get utilised
I think
\r?\n(?!\(1|\d)
(And replace with empty string) will do what you want
Explanation: Looks for a newline that's not followed by either (1 or a single digit.
If you ever have more than 9 options that will cause problems as it'll split before (10 (11 etc. - in which case \r?\n(?!\(1\)|\d) should do it
Select text/elements and press CTRL+J

Proper Fortran compiler to execute a program

I have little knowledge of the Fortran language. I have come across some programs written in the 90s (see attached snapshot showing just a portion of a long script).
I'd like to know what kind of compiler is appropriate to execute such codes? I have installed gfortran-4.2.3 on my mac. I'm also not sure about the indentation in the attached code: if C (comment) is at column 1, does the main code start at column 9 or 7? what about the position of numbers placed in between referred by GO TO?
This is not Fortran 90. This is Fortran 77.
That said, gfortran is able to compile this code. Make sure that the file extension for the file is .f so that gfortran realises it's fixed-form.
The C needs to be in the first column, the numbers that you reference are labels, they can be between column 1 and 5. The asterisk at line 198 is a continuation character, meaning that this should be treated as part of the previous line. It must be in column 6. Everything else needs to be between columns 7 and 72 (inclusive)
Oh, and the 3-digit numbers at the very beginning are line numbers, and must not be in the source code.
Edited to add: Since you have to type it all again anyway, you might as well make it free-form:
Replace the C in the first column with !, and change the way continuation lines are marked: Turn this:
write (*, *) "This is some long text,
* which doesn't fit into a line"
Into this:
write(*, *) "This is some long text, " // &
"which doesn't fit into a line"
Everything else can stay like it is. (You can now use proper indentation, too!)
New Edit
So you've pasted the code that you wrote and the error messages, so I'm replying to that now.
In Fixed Form, any character past column 72 is ignored. You have a few lines with long strings, where the terminating quotation mark is in that ignored region.
Make sure that no line exceeds the 72nd row.