forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using external procedures, subprograms or functions
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
kaliuzhkin



Joined: 17 Sep 2012
Posts: 22

PostPosted: Wed Oct 04, 2017 7:18 pm    Post subject: Using external procedures, subprograms or functions Reply with quote

So far, all my FTN95 programs have been single units, that is, a main program with no other units. That single unit is in a file.

Iíd like to extend to using additional units but have run into procedural issues. In particular, I want the main program to be in one file and an external function to be in another file. All my efforts to compile and run have been unsuccessful. Iíve only been able to get this to work if I merge the two units into a single file, perhaps using an INCLUDE statement. Can I do it with two separate files?

Here is the code in the two separate files:

(C:\Kalish_data\FORTRAN source\95\Fortran 95 Counihan\ch07p109\ch07p109_ex_003_Main.f95)
WINAPP !for CLEARWIN
PROGRAM Main
!
! Fortran 95, Martin Counihan
! Chapter 7, Introducing external procedures, page 109
! Section 7.1, Functions page 109
!
! The text provides a FUNCTION Cot(x) which determines the Cotangent
! of x, an angle given in radians. This is the main program which
! obtains an angle in degrees and uses the FUNCTION Cot to determine
! the Cotangent of an angle in degrees.
!
IMPLICIT NONE
REAL:: Cot, AngDeg, AngRad, CoTangent, Pi = 3.14159265358979
!
WRITE(*,*) "Please enter an angle in degrees. We will &
&determine its Cotangent. ..."
READ(*,*) AngDeg
AngRad = AngDeg*pi/180.
WRITE(*,*) "The angle = ", AngRad, " in radians."
CoTangent = Cot(AngRad)
WRITE(*,*) "The cotangent = ", CoTangent
!
END PROGRAM Main


(C:\Kalish_data\FORTRAN source\95\Fortran 95 Counihan\ch07p109\ch07p109_ex_003_Function.f95)
WINAPP !for CLEARWIN
FUNCTION Cot(x)
!
! Fortran 95, Martin Counihan
! Chapter 7, Introducing external procedures, page 109
! Section 7.1, Functions page 109
!
! The text provides a FUNCTION Cot(x) which determines the Cotangent
! of x, an angle given in radians. This is that FUNCTION.
!
IMPLICIT NONE
REAL:: Cot, eps, s, c
REAL, INTENT(IN):: x !Can use x but can't modify it.
!
eps = EPSILON(x)
Singularity: IF ((-eps.LE.x).AND.(x.LE.eps)) THEN
WRITE(*,*) "Error: cotangent function called with a zero argument"
Cot = Huge(x)
ELSE Singularity
s = SIN(x)
c = COS(x)
Cot = c/s
END IF Singularity
!
END FUNCTION Cot


If I compile the FUNCTION in Plato, it says, ď*** No main, WinMain or LibMain function *** CompilationĒ
If I compile the Main program in Plato, it is successful.

Iím not able to get anywhere with project in Plato.

If I compile the Main program in Command Prompt with FTN95.exe, I get

WARNING the following symbols are missing:
COT c:\Kalish_data\FORTRAN source\95\Fortran 95 Counihan\ch07p109\lgotemp@.obj
(C:\KALISH_DATA\FORTRAN SOURCE\95\FORTRAN 95 COUNIHAN\CH07P109\CH07P109_EX_003_MAIN.F95)
Creating executable: .EXE.exe
Creating Linker map file: .MAP.map

If I compile the Function in Command Prompt with FTN95.exe, I get

*** No main, WinMain or LibMain function
*** Compilation abandoned

Also, I havenít been able to compile the two units so as to obtain .OBJ files for use with SLINK.exe.

There must be some way to do this.

Thanks,
Dan
Back to top
View user's profile Send private message Send e-mail
DanRRight



Joined: 10 Mar 2008
Posts: 1548
Location: South Pole, Antarctica

PostPosted: Wed Oct 04, 2017 8:46 pm    Post subject: Reply with quote

Here is my way of working using the Command Prompt.

1) Download nice file management tool called Total Commander. My friends always thank me for this suggestion and install it first on any new computer. I have 6 (!) of them working at the same time, each for different project and having no idea how others may work with Windows efficiently without such great tool. Different colors help not to be buried in the information completely.



2) use the command script like this changing two or more file names with your ones.

3) Then working will be as easy and pleasant as clicking or Ctrl+Filename on keyboard. Your errors are in the files conveniently called with the letter A.

(All that was for 32bit case. Remove SIMPLE.DLL /stack:850000000 if this is 64 and add to FTN95 line the /64 switch for 64bit compiler, change SLINK to SLINK64, and SDBG to SDBG64. In the SLINK64 line add /file YourExeName.EXE though this is not needed in the latest version). You can remove in 32bits SIMPLE.DLL which is for making older Simpleplot utility called %pl looking nicer and /stack:850000000 is for large programs which utilize almost all your accessible memory

4) If you just click on BAT file it will run debugger with many useful debug options. Calling the script with additional letter(s) will direct at different compilation options from checking everything to not checking anything, to optimize.

I use letters N, NN, S, NO for /NOCHECK and run, /NOCHECK and not run, /DEBUG with SDBG, and OPTIMIZE respectively. Z is for /NOCHECK with no other options
The default is debugging and running with SDBG. With time you can make the script much more complex then that.


Code:
if (%1)==(n)     goto nocheck
if (%1)==(N)     goto nocheck

if (%1)==(s)     goto SDBG
if (%1)==(S)     goto SDBG

if (%1)==(nn)    goto nocheck2
if (%1)==(NN)    goto nocheck2

if (%1)==(no)    goto noch_opt
if (%1)==(NO)    goto noch_opt

if (%1)==(z)     goto Z
if (%1)==(Z)     goto Z



!.............. DEBUG UNDEF .........
del MProgram.exe
ftn95 MProgram.for /free /err /set_error_level error 298 /check /full_debug /no_truncate /zeroise /undef >a_FTN95___
ftn95 Subr.for /err /set_error_level error 298 /check /debug /undef /zeroise                             >a_FTN95pie___
slink MProgram.obj Subr.obj SIMPLE.DLL /stack:850000000                                                  >a_link___
goto SDBG

!..............NOCHECK .........
:nocheck
del MProgram.exe
ftn95 MProgram.for /free /no_truncate                    >a_FTN95___
ftn95 Subr.for                                           >a_FTN95pie___
slink MProgram.obj Subr.obj            /stack:850000000  >a_link___
MProgram.exe
goto end

!..............NOCHECK .........
:nocheck2
del MProgram.exe
ftn95 MProgram.for /free /no_truncate /set_error_level error 298  >a_FTN95___
ftn95 Subr.for                                                    >a_FTN95pie___
slink MProgram.obj Subr.obj            /stack:850000000           >a_link___
goto end


!..............Optimize .........
:noch_opt
del MProgram.exe
ftn95 MProgram.for /free /no_truncate /nocheck /opt /set_error_level error 298 >a_FTN95___
ftn95 Subr.for /opt                                         >a_FTN95pie___
slink MProgram.obj Subr.obj            /stack:850000000     >a_link___
goto end


!..............NOCHECK .........
:Z
del MProgram.exe
ftn95 MProgram.for /free /no_truncate                      >a_FTN95___
ftn95 Subr.for                                             >a_FTN95pie___
slink MProgram.obj Subr.obj                                >a_link___
goto end


!.............RUN SDBG .........
:SDBG
SDBG MProgram.exe


:end


Last edited by DanRRight on Fri Oct 13, 2017 7:33 pm; edited 8 times in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 4919
Location: Salford, UK

PostPosted: Wed Oct 04, 2017 8:59 pm    Post subject: Reply with quote

There is a section in the Plato "getting started" topic about creating a "project". Here is the online link...

http://silverfrost.com/ftn95-help/plato/simplefortranproject.aspx
Back to top
View user's profile Send private message
kaliuzhkin



Joined: 17 Sep 2012
Posts: 22

PostPosted: Thu Oct 05, 2017 8:02 pm    Post subject: Reply with quote

Dan: Thanks for the reference to Total Commander. It looks promising. I'll add it to my utility tools SysInternals and Nir Software. I'll try your script when I'm back home.

Paul: I've already gone through that link. I still don't see how to use two different files. If it does explain that, please show me.

Oh, my post needs a correction: it's CONTAINS, not INCLUDE. The sample programs, say Part 1 L, in the FTN95 Tutorial Help use CONTAINS. It still doesn't help because we're still talking about a single file. Smile
Back to top
View user's profile Send private message Send e-mail
davidb



Joined: 17 Jul 2009
Posts: 526
Location: UK

PostPosted: Fri Oct 06, 2017 1:42 pm    Post subject: Reply with quote

There is no need to over-complicate things. You have two files in your example and you are not using modules so ...

Compile each file:

Code:

ftn95 /c ch07p109_ex_003_Main.f95
ftn95 /c ch07p109_ex_003_Function.f95

Then link the object files:
Code:

slink ch07p109_ex_003_Main.obj ch07p109_ex_003_Function.obj


The order of compilation becomes important if you use modules so post back if you need help with them. Order of linking should never matter.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1652
Location: Yateley, Hants, UK

PostPosted: Fri Oct 06, 2017 3:27 pm    Post subject: Reply with quote

Ooops David,

Didn't you read that /c now has a different function?

Eddie
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 526
Location: UK

PostPosted: Fri Oct 06, 2017 3:53 pm    Post subject: Reply with quote

Thanks Eddie.

I am still using 7.2 here because of bugs in 8.1.

Where is the information on the new use of /C ?

Obviously my post above will need adapting if /C no longer means "suppress link". But the principles are the same.

David.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Fri Oct 06, 2017 4:09 pm    Post subject: Re: Reply with quote

davidb wrote:
Thanks Eddie.

I am still using 7.2 here because of bugs in 8.1.

Where is the information on the new use of /C ?

Obviously my post above will need adapting if /C no longer means "suppress link". But the principles are the same.


Quote:
/Cfg Enters the compiler local configuration screen.


By default, no linking is done, so no option is needed to suppress linking. If you do want to link, the /link option is available. To compile, link and run, we have /LGO.
Back to top
View user's profile Send private message
kaliuzhkin



Joined: 17 Sep 2012
Posts: 22

PostPosted: Fri Oct 06, 2017 9:19 pm    Post subject: Reply with quote

Total Commander is not free. You've got 30 days and then its $40. Sad

I'll look at these command prompt commands later.

Dan: how to run those scripts? In a batch file?
Back to top
View user's profile Send private message Send e-mail
DanRRight



Joined: 10 Mar 2008
Posts: 1548
Location: South Pole, Antarctica

PostPosted: Fri Oct 06, 2017 11:39 pm    Post subject: Reply with quote

Yes, use that in the BAT file

I think Total Commander was free before (I bought it 20 years ago) with some little annoyance after 30 days...Anyway if you try it you will join 70+ million people who installed such type of Windows enhancement apps.

There are other similar utilities copying famous Norton Commander for DOS. On my Android cellphone I use Ghost Commander - the same kind of utilities, which on the phones is even better then TC
Back to top
View user's profile Send private message
kaliuzhkin



Joined: 17 Sep 2012
Posts: 22

PostPosted: Thu Oct 12, 2017 8:28 pm    Post subject: Reply with quote

The compiler option is /-Link. Now I can successfully compile the programs in command prompt, link the object files with SLINK.exe and run the executable file. Hooray!

However, SLINK has problems if the programs are compiled with the /64 option.

Note: in another thread, I asked "What options should I select in order to produce object files? /
-CLR and /-LINK? " http://forums.silverfrost.com/viewtopic.php?p=18711#18711 It's nice to have the answer after two years of frustration. Smile
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 4919
Location: Salford, UK

PostPosted: Thu Oct 12, 2017 9:42 pm    Post subject: Reply with quote

SLINK64 is the 64 bit linker.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Fri Oct 13, 2017 10:20 am    Post subject: Re: Reply with quote

kaliuzhkin wrote:
... Note: in another thread, I asked "What options should I select in order to produce object files? ...http://forums.silverfrost.com/viewtopic.php?p=18711#18711 It's nice to have the answer after two years of frustration. :-)

Two years? John Campbell answered you after just three days.

Dan K, Wed Aug 26, 2015 3:56 pm: "What options should I select in order to produce object files? "

John Campbell, Sat Aug 29, 2015 10:31 pm: "...You can compile the program using the command : FTN95 test This will produce a file test.obj or some error messages."
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 1548
Location: South Pole, Antarctica

PostPosted: Fri Oct 13, 2017 7:42 pm    Post subject: Reply with quote

I do not know why, this is beyond me, but all compiler developers do not care to create very short movies "How to start using compiler in 1 minute or less", movies "Tricks of compilation", ""Tricks of debugging", movie demonstrating all the good examples etc. Take your teenage daughters and they will do 10 of them in one day. Good example - site iFixit dot com

https://www.youtube.com/watch?v=nlUQfXwvQLc

The start of using of anything is always the hardest part. One small thing is missing and the whole picture is total mess and darkness.

I remember Salford'a attempt of making such movies as far as 20 years back. This was about FTN90. But the compiler was a total flop and the presenter clearly knew that being very uncomfortable and afraid to look straight into the camera Smile. Was it bad or good but I bought it then Smile That compiler was quickly dropped in favor of FTN95 which accomoddated older FTN77 and added new Fortran 90 features.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 732

PostPosted: Sat Oct 14, 2017 12:56 am    Post subject: Re: Reply with quote

DanRRight wrote:
I do not know why, this is beyond me, but all compiler developers do not care to create very short movies


Probably for the same reasons as for the Ten Commandments being distributed as HST (Heavy Stone Tablet) files rather than DVD.

A one minute movie is not going to cover much. Paul's recent movie on the new features of Plato, etc. is much longer.

A programmer's manual contains a table of contents and an index. These days, such manuals come in the form of files with lots of links that help with finding information and quickly navigating to the pages of interest. I am not aware of any such navigational aids for watching movies.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group