Type * error in gfortran - fortran

When I run my code I get the following error for all the statements that have the following format. Is there any problem with the type statement? If yes kindly provide me with a solution. I running my code on a Ubuntu 14.10 system. The program is very long hence I am not posting it now however if required I can surely send it.
recfunk_ascii.f:622.12:
type *,'enter back-azimuth limits ib1,ib2 (integers!)'
1
Error: Invalid character in name at (1)

Type is an obsolete and completely non-standard statement (see http://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnbi/index.html). It is not portable because many compilers do not recognize it. It should be changed to a PRINT statement, as #francescalus suggest in the comment.
print *,'enter back-azimuth limits ib1,ib2 (integers!)'

Related

fatal error C1017: invalid integer constant expression when using "#if (false)"

Have following code which is working under Linux but gives error for MSVS
#if (false)
....
#endif
The error is: fatal error C1017: invalid integer constant expression
I found this report on Microsoft's web:
http://msdn.microsoft.com/en-us/library/h5sh3k99.aspx
While the info described there differs a little bit compared to my case as I didn't use the "#define"
So my question is:
Is there any way to make it working for MSVC without changing code ?
If the code must be updated, what's the best solution for this kind of case?
It looks like your version of MS compiler does not support false as a built-in constant. This is not surprising, because Microsoft has a spotty record of supporting standards for C and C++.
One way to make this work without changing the code is to pass command-line parameters to the compiler to define false as 0 and true as 1:
-Dfalse=0 -Dtrue=1
Is there any way to make it working for MSVC without changing code ?
Not really. Defining a macro for false is forbidden by the standard for good reasons, [macro.names]/2:
A translation unit shall not #define or #undef names lexically
identical to keywords, to the identifiers listed in Table 3, or to the
attribute-tokens described in 7.6.
And I don't see any other way.
If the code must be updated, what's the best solution for this kind of
case?
Substitute 0 for false.

Problems compiling and executing this code in C++

I'm trying to compile this code in TurboC++ 3.0. However, I got these errors:
DOS.H 77: Too many types in declaration
DOS.H 77: { expected
DOS.H 77: Declaration does not specify a tag or an identifier
SARSAL.CPP 72: Cannot cast from 'int' to 'time'
I checked the directories of the libraries and I have run the code in BorlandC++ 5.02 (unfortunately, I get the graphics error or this error: Constructor cannot have a return type specification, in the method void Agente::Agente), DevC++ and Code::Blocks without success.
The code was provided by our AI teacher and supposedly works fine. How do I get it to compile?
Thanks for the help.
I normally wouldn't answer this kind of post (and not just because of the "TurboC++" issue) but we were all newbies at some point and needed help but didn't know how to ask for it, so I'll give you a hand.
First and foremost: DON'T USE TurboC++. As others have said, it's ancient and will require you to learn a language that's very different than the C++ of today and will teach you many many bad habits (e.g. #include <iostream.h> which is wrong).
With that out of the way, let's get started, shall we?
You define a constructor (around line 70) and give it a return type of void. This is wrong: constructors don't have return types. The correct syntax is:
Agente::Agente(void)
{
randomize();
}
Perhaps TurboC++ requires a return type (see?) or perhaps this was just your mistake, but either way, this is a bug because that is not C++ code.
Moving forward, you have this on line 127:
if((Archivo = fopen("C:\Documents and Settings\ArCiGo\Escritorio\SOFTWARE_2\DATOS.TXT","r"))!=NULL)
The character \ is special in C++ (e.g. \n represents a newline and \x01 is the character with value 1.
If you want to use it, you must escape it with another \ like this:
if((Archivo = fopen("C:\\Documents and Settings\\ArCiGo\\Escritorio\\SOFTWARE_2\\DATOS.TXT","r"))!=NULL)
There are other places where you do the same thing. Fix those and try again. I bet that you will have a lot better luck and fewer errors to worry about.
For future reference, when you are looking for help try to post a SHORT, self-contained program that exhibits the error that you are getting, so that others don't need to wade through hundreds of lines of code and worry about missing header files and platform-specific differences.

gfortran - assign string to parameter

[NOTE: contains repetition of previous question but posted separately as separate issues]
I am compiling a program which is known to compile with ifort using gfortran. However the compiler fails on the line
PARAMETER (POS='^')
with the compile error:
conv_prof.mac:9.21:
Included at conv_prof.f:811:
PARAMETER (POS='^')
1
Error: Can't convert CHARACTER(1) to REAL(4) at (1)
make: *** [conv_prof.o] Error 1
As it turns out the POS parameter is not used (it is likely a legacy parameter) so I may simply uncomment this line to compile, but I would like to know if anyone might have any idea why this is an issue in gfortran and not ifort?
Cheers,
Derek
The Intel compiler is the descendant of a long line of Fortran compilers. Its ancestors implemented all sorts of non-standard behaviour and, in the true spirit of Fortran, the latest versions of the compiler ought to compile the most ancient codes. You can often tell ifort to warn of non-standard features in your codes by judicious use of compiler flags.
gfortran, on the other hand, does not (by default) accept much in the way of non-standard syntax, other than those forms of non-standard syntax which have been so widely used that many unsuspecting programmers think that they are standard forms (eg real*4 and the like).
Your snippet looks to me to come from the days prior to FORTRAN77 when the language didn't really acknowledge the existence of such new-fangled ideas as non-numeric variables. In this case I recommend that you follow gfortran in disallowing this code, rather than Intel Fortran.
The specific extension here is that ifort allows a program to "assign" a character value into a real object. Perhaps it was intended to use this extension - but a more likely explanation is that a type declaration statement for the parameter pos is missing prior to the PARAMETER statement.
Technically I don't think the standard requires a diagnostic in this case (this isn't a violation of the syntax rules or constraints of the standard - it is a violation of the requirements placed on the program in the body text), but you'll get a diagnostic from ifort if you turn on standards checking (/stand or -stand, depending on your platform).

gfortran WRITE and FORMAT not appearing to need to conform on intel comiler

I am compiling a program which is known to compile with ifort using gfortran. However, the compiler fails on the line
WRITE (11,1325) ((IFILE,FILENAME(IFILE)),IFILE=1,IFILES)
with the compile error:
main_file.f:205.32:
WRITE (11,1325) ((IFILE,FILENAME(IFILE)),IFILE=1,IFILES)
1
Error: Expected PARAMETER symbol in complex constant at (1)
make: *** [main_file.o] Error 1
Changing this line to (note removal of '(' and ')')
WRITE (11,1480) (IFILE,FILENAME(IFILE),IFILE=1,IFILES)
to match the subsequent line
1480 FORMAT (1X,I1,' ',A40)
solves the problem, but I was wondering if anyone may know why is this mistake not captured by the Intel compiler. In this instance, it seems to be gfortran which is giving the correct behaviour. My compile flags are:
gfortran -fno-automatic -mcmodel=medium -O2 -ffast-math main_file.o -o main_file
As others have posted in the similar recent questions, due to its heritage the Intel compiler allows a number of extensions by default. The compiler will emit a diagnostic if you supply the appropriate standard check option (/stand on Windows, for example).
I'm not sure of the specific source of this particular extension, but it covers a somewhat occasional syntax misunderstanding, where people would put the "arguments" to the write or read "function" in parentheses...
READ (*,*) (not_valid_syntax)
(In a write statement an expression in parentheses is itself an expression, and that is a valid output list item - a few years back the Intel compiler would get a bit confused about that.)
Quite an interesting issue. It works only for arrays:
print *, ((1,["a","b"]),i=1,10)
end
works, but
print *, ((1,"a"),i=1,10)
end
fails with ifort:
: error #6063: An INTEGER or REAL data type is required in this context. ['a']
print *, ((1,"a"),i=1,10)
God knows what the parser thinks it is in the first working case, maybe an incomplete nested implied do? For sure it is not legal Fortran syntax and should by refused by compiler which requires standard Fortran. Intel may have reasons to accept this syntax.

GDB prints wrong values

I've got a bit of a problem with debugging a C++ program using GDB.
When I use print object.member, it doesn't always print the value of the variable correctly. Instead, it prints the value of one of the arguments to the function I'm debugging. And it doesn't change through the function, although I change the value of object.member throughout.
And the thing is, the program is rather large and consists of several modules, with partially specialised templates and such, so I can't post it all here.
Now I tried to create a minimal testcase, but whatever simple I tried, I can't make it work. I mean, not work.
So all I can ask is, has anybody ever seen this behaviour in GDB, and have you found out what caused it and how to solve it?
There are question here about similar behaviour, but those amount to the program not being compiled properly (optimisation levels too high etc). I compiled it with -Wall -Wextra -pedantic -g -O0, so that can't be it.
And the program runs fine; I can cout << object.member; and that outputs the expected value, so I don't know what to try now.
I've seen similar behaviour before. Unfortunately, gdb is really 'C' based so although it will deal with C++, I've found it occasionally to be quite picky about displaying values.
When displaying more complex items (such as maps, strings or the dereferenced contents of smart pointers) you have to sometimes be quite explicit about dereferencing and casting variables.
Another possibility is the function itself - anything unusual about it? Is it templated for example?
Can you create a reference to this variable in your code and try displaying that? Or take the address of the variable and derefrence the contents - only if it's publicly available of course.
Naturally the source code must match what you've compiled so must be older than the exe but gdb will normally warn you about such things