Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Use Statement

reneeculver
Beginner
3,808 Views
"Error1 error #6278: This USE statement is not positioned correctly within the scoping unit.D:\\System Utilities\\Adventure\\Adventure\\Adventure(intel)\\Adventure\\ASUBS.FOR16"

What does this mean and where should I place the USE statement?

Renee
0 Kudos
19 Replies
Robert_van_Amerongen
New Contributor III
3,808 Views
Renee,

I cannot look into your source, but I presume that any of your USE statements was not placed correctly, that is, it was not placed immediately after a PROGRAM, a SUBROUTINE, a FUNCTION or a MODULE statement, and before any other specification statement.
Take a look in a hand book where this type of coding requirements is addressed.

Robert
0 Kudos
reneeculver
Beginner
3,808 Views
Thank you very much Robert.

I have a issue with the intel technical documentation. Overal it is not effective. Intel does use actual models...no one writes fortran the way that they appear (all in uppper case) in the books. The examples are elementary. Or we can go to the definitions and reach another level of abstrusness ans came up with pure definitions, disconnected from any kind of reality and "groundedness.

I knew that there was a problen in the placement of the use statement from the error messaage. I'd have to look for place to put it.

I hope your around later.

Renee
0 Kudos
Steven_L_Intel1
Employee
3,808 Views
You'd be surprised what people write - and the uppercase syntax is widely used in the Fortran standard. Indeed, all keywords are defined in uppercase, with other text indicating that case is ignored when considering keywords and identifiers.

The Intel documentation is reference material, and there is a clear chart towards the beginning that diagrams which statements can appear where. This is adapted from the standard.

I do think that you would benefit from reading a textbook on the Fortran languge. There are several listed in the introductory material in the Intel Fortran Language Reference.
0 Kudos
reneeculver
Beginner
3,808 Views
Well I still have an error and I've tried several permutatons.

The error is now that the external routine is undefined.

The code is:

C!DEC$ ATTRIBUTES DLLImport :: kernel32 ! This is now a comment!!!!! (believe it or not)

!use kernel32

C*** A5TOA1

SUBROUTINE A5TOA1(A,B,C,QQ,LENG)

C use kernel32

C A AND B CONTAIN A 1- TO 12-CHARACTER WORD IN A6 FORMAT, C CONTAINS ANOTHER

C WORD AND/OR PUNCTUATION. THEY ARE UNPACKED TO ONE CHARACTER PER WORD IN THE

C ARRAY "CHARS".

This isthe firstsubroutine of the of the other file in the program.

This is about the first executble code, although it's not the first "common declarations. There is NO ogram statement.

A word on what I am doing.... I am restoting the first computer game and taking it to 32 and 64 bits. Given that it is a historic piece of code, I am keeping my uses minimal. I am adding a window close event. That's why I need a reference to Kernel32. It has a reference to SETCONSOLECTRLHANDLER which is asynchronous.

call SETCONSOLECTRLHANDLER(CloseWindow,.true.)

OPEN (UNIT=16,FILE='ADVTXT.dat',STATUS='OLD',FORM=

1 'UNFORMATTED',ACCESS='SEQUENTIAL',iostat=ioval)

if (ioval .ne. 0) then

Print 67,iovar

67 format("ADVTXT.dat not present. Err=",i4)

call sleep(10)

stop

end if


Renee

0 Kudos
reneeculver
Beginner
3,808 Views
"I do think that you would benefit from reading a textbook on the Fortran languge. There are several listed in the introductory material in the Intel Fortran Language Reference."

I was a Principle Design Engineer at Digital, the company that the compiler came frrom and used to be a expert at it BUT there was no such thing as a DLL back then and there was not such thing as a window close because there was no such thing as a Window. In the late70's, I don't remember aUSE statement.I wouldn't mind buying a reference book on fortran. Since I've developed in Fortran, I went to Bliss, which was our system implementation language.

Renee
0 Kudos
Steven_L_Intel1
Employee
3,808 Views
I was a Consulting Software Engineer in DEC's compiler group, and was a developer and/or project lead on VAX FORTRAN, DEC Fortran for OpenVMS Alpha and Digital Visual Fortran. I was also the lead developer on the VAX FORTRAN, VAX Pascal and VAX Ada run-time libraries prior to my move to the Fortran compiler project. If your use of Fortran stopped with the VAX, then you never learned Fortran 90 which is where the USE statement appeared. I am quite familiar with BLISS, having used it my entire 23 years at DEC and Compaq.

When I suggest that you need a Fortran textbook, it is because it is clear you need a refresher on the Fortran language as it exists today. If you were more familiar with Fortran, you would not have quite as much difficulty as you are.

The USE statement makes a module of precompiled declarations available to a program unit. It immediately follows the SUBROUTINE, FUNCTION or PROGRAM statements. In Intel Visual Fortran, we provide a number of modules that declare Windows API interfaces. KERNEL32 is one of them.

You have the lines:

C!DEC$ ATTRIBUTES DLLImport :: kernel32 ! This is now a comment!!!!! (believe it or not)

!use kernel32

preceding the SUBROUTINE and you have garbled them. Those lines should be removed.

If you are intent on adding Win32 calls to ADVENTURE, which I don't recommend, I would recommend buying and reading Compaq Visual Fortran: A Guide to Creating Windows Applications by Norman Lawrence. Nearly all of it applies to Intel Visual Fortran as well.

Two popular textbooks on Fortran are Fortran 95/2003 Explained and the Fortran 2003 Handbook. (The former book is being revised to cover Fortran 2008 soon.)

I do think that your additions to ADVENTURE are unnecessary and do not properly honor its heritage. At most all you need to do is add a READ from the terminal or maybe a call to GETCHARQQ to prevent the console window from closing when the program exits until the user presses a key.) But if you wish to do this as a way of learning Win32 programming, then by all means do so.

0 Kudos
reneeculver
Beginner
3,808 Views
I shall order the books. Please don't forget that HELP in VS2010 has problems also.

So I have been at a real disadvantage as I've had no help texts or texts to resort to and if I had all the help
Inteldocumentation is notvery useful.

You are welcome to show me the modifications you make in adventure. I am interested in preserving it. But I am not interested in seeing it do a stack dump. I don't see how your recomendations will work in a single-threaded design which Adventure is.. And I do see this as a way of learning Win32.

Renee
0 Kudos
reneeculver
Beginner
3,808 Views
By the way, I was offered the job of Consulting engineer. I turned it down because I wanted to keep coding.

Renee
0 Kudos
reneeculver
Beginner
3,808 Views
OK....

I have1 external variable that can't be found which is the setconsolecntrHandler below'

call SETCONSOLECTRLHANDLER(CloseWindow,.true.)

OPEN (UNIT=16,FILE='ADVTXT.dat',STATUS='OLD',FORM=

1 'UNFORMATTED',ACCESS='SEQUENTIAL',iostat=ioval)

if (ioval .ne. 0) then .... mumble

The linkages are:

Program Adventure
!DEC$ ATTRIBUTES DLLIMPORT :: kernel32

IMPLICIT INTEGER(A-Z)

And thats it. Can anyone tell me how the Kernel32 is linked? setconsolecntrHandler is in Kernel32.dll.
I added the program statement because the program had none of any kimd.

Renee

0 Kudos
nvaneck
New Contributor I
3,808 Views

A Fortran IV version already exists. It compiles fine, but has problems, e.g., "IF (i.gt.0.and.x(i).gt.0)"

0 Kudos
psantos
Beginner
3,808 Views
Hello reneeculver,

You don't need to import kernel32 with "!DEC$ ATTRIBUTES DLLIMPORT :: kernel32". Remove the import directive and add "USE KERNEL32" in the subroutine (or program) where you invoke SETCONSOLECTRLHANDLER . Intel has already created interfaces to FORTRAN. Hope this solves your problem.

Pedro
0 Kudos
reneeculver
Beginner
3,808 Views

Thank you, Pedro. I'm afraid that has induced other compilation problems, which are randomized.

Renee

0 Kudos
reneeculver
Beginner
3,808 Views

To everyone's good fortune, I have ordered one of the Fortran books from Amazon and it should be here the day after tomorrow. Let us hope it has the USE statement in it.

Renee

0 Kudos
Steven_L_Intel1
Employee
3,808 Views
Quoting reneeculver
By the way, I was offered the job of Consulting engineer. I turned it down because I wanted to keep coding.

You're thinking of something different, then. At DEC, "Consulting Engineer" was a promotion in grade that had to be approved by a review board. It did not necessarily mean a change in what you did. Intel has a similar thing they call Principal Engineer.

0 Kudos
reneeculver
Beginner
3,808 Views
No, I am not thinking of something different. In VMS it meant almost no coding or very little coding. I would have gone before a review board. My supervisors name was Scott Davis. In other words, while I was there, (88-92). I didn't know any consultants who did just coding. That omits Andy Goldstein, because I don't know what he did. He may have remained technical ....I don't know.

Renee
0 Kudos
joerg_kuthe
Novice
3,808 Views
To link kernel32 you simply add that name to the "Additional Dependencies" of Linker | Input view of your project's property pages (in VS). It is even likely that you don't have to add that import library's name (which is true for my projects in VS2005) since the .dll's import library (kernel32.lib) is linked anyway as soon as you specify the proper module (USE KERNEL32 in your case).
Generally, when using a WinAPI function, you usually don't import the DLL the way you do, e.g.
!DEC$ ATTRIBUTES DLLIMPORT :: kernel32
You simply specify the name of the corresponding import library. E.g., you want to use the WinAPI function
BOOL GetUserName(
LPTSTR lpBuffer,
LPDWORD nSize
);

specify Advapi32 in the "Additional Dependencies" of Linker | Input view of your project's property pages (in VS).

In fact, I guess there is problem that originally causes all the "trouble". Your subroutine misses the INTERFACE to
BOOL SetConsoleCtrlHandler(
PHANDLER_ROUTINE HandlerRoutine,
BOOL Add
);

which ist supplied by the statement
USE KERNEL32
in your SUBROUTINE's header (before any other declaration statement, before an IMPLICIT ... statement).
Again, if KERNEL32 is USEd, this provides for the necessary linker information.
Thus, you don't have to specify anything to the linker then. I hope this helps.

Jrg
www.qtsoftware.com


0 Kudos
reneeculver
Beginner
3,808 Views
I appreciate your reply so much.

I must have been tired because I had a reference in code to SetConsoleCtrlHandler. However that is the one remaining undefined external.

"Error 1 error LNK2019: unresolved external symbol SETCONSOLECTRLHANDLER referenced in function SETUPEXIT ASUBS.obj"

Here is setupexit:

Logical Function SetupExit

integer*4 ff

ff= SetConsoleCtrlHandler(closewindow,.true.)

setupexit=.true.

Return

End

Under Project Properties and the linker I do have Kernel32.dll. I wish I had a link map because that would tell me where the linker is looking for SetConsoleCtrlHandlerin Kernel32.dll. I have now eliminated all USE statements.

Are there enviroment variables that point to the system I am running under? Right now, I am trying to build under a 64 bit system.

Renee

0 Kudos
Steven_L_Intel1
Employee
3,808 Views
You need USE KERNEL32 in every function or subroutine that references a routine from that library.
0 Kudos
reneeculver
Beginner
3,808 Views
THANK YOU, STEVE.

It finally built with that piece of information.

Renee
0 Kudos
Reply