In my fortran project, I attempt to simply create an output file with some headers in it using the following code:
OPEN(987, file = 'OutputFile.txt', status = 'unknown')
WRITE(987, '(37(A,$))') 'GammaB_CB[1,1,1]',CHAR(9), &
'Rb_CB[1,1,1]', CHAR(9), &
'Rp_CB[1,1,1]', CHAR(9), &
'def0', CHAR(9), &
However, when I compile, the compiler sends back the following error for the line WRITE(987, ...) :
error #5082: Syntax error, found '&' when expecting one of: ( <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
It is strange because this piece of code compiles in another fortran project I have made before. Why it does not compile for my new project ? Is there any project configuration I should look at ?
You best use the </> icon to insert source code (under the ... icon), because then indentation is preserved. One possible explanation is that you are now using a fixed-form source file. In that case, the continuation has to be via the sixth column - hence the indentation is important :).
You didn't show us the entire error (including the name of the source file). My guess, and reproduced with an experiment, is that you have named your file with a file type other than .f90, such as .f or .for. This tells the compiler that it is fixed-form source, and you'll get exactly this error in such a case.
The fix would be to rename the file to have a .f90 file type.
You are right: my project where Open/write synthax works is named in .f90, while my project where Open/write synthax does not work is named in .for: see attached.
However, if I rename the single file cage_bande.for in cage_bande.f90, the compilation generates other errors: see attached.
Should I rename all my files fomr .for to .f90 ? (I have 10' to 100' fortran files !).
the errors you show are in constante.txt - a text file??? why are you compiling .TXT file? shouldn't that be a .f90 file also?
.for extension will be compiled as old fixed source form.
.f90 extension for free source form.
You may want to read one of my favorite posts, Doctor Fortran in "Source Form Just Wants to be Free" - Doctor Fortran (stevelionel.com)
The sources you show use the free source form. In order for them to be compiled properly, they should have the .f90 file type. You may have some other source files that are fixed-form, those can be .for. You will have to look at each source and determine which form it uses.