LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2011, 12:38 PM   #1
fu3lc3ll$
LQ Newbie
 
Registered: May 2011
Posts: 6

Rep: Reputation: Disabled
Post Incorporating subroutine in main program


Hi,
Being new to linux programing, would like to know how to incorporate a subroutine file ( that is saved in separate file ) to the main program file?
Say, i have a main program called as vauto.f ( written in F77 ) and complied with gfortran and run successfully using the help from Mr. Colucix ( Many thanks, Mr. Colucix ). Got an output file (RFILE) after running this program. I want to post process this out put file giving this as input to some other program, that is written as sub routine in a separate file, four.f. I tried to incorporate this subroutine into the main program v.auto.f and ran into several compiling errors and before saving those errors my system went dead so could not post here the errors ( sorry about that ).
Think myself as a very new programer. what would you advice me to do??
==
a. create an object file of that subroutine file and link that to main file and compile both of them and get output file
b. After obtaining the result file from the first program (RFILE), run this subroutine ( but how to do that?? is my question bugging me for more than 4 days, tried different things and met with failure ).
=====
For our kind attention, have attached the main program (vauto.f), RFILE, four.f
======
Will be highly obliged if any one of experts here help me with this.

Thanks in advance.
Attached Files
File Type: txt four.txt (4.3 KB, 14 views)
File Type: txt vauto.txt (5.7 KB, 12 views)
File Type: txt RFILE.txt (4.3 KB, 8 views)
 
Old 05-23-2011, 01:35 PM   #2
16pide
Member
 
Registered: Jan 2010
Posts: 418

Rep: Reputation: 83
I'd like to question first why you picked F77 as your language to start programming.
The 77 in it means 1977, 34 years ago ...

You could go to C, C++, or Java for example that are much more modern.

Now, regarding your question, if you say that other source is written as a subroutine, why would you need to write to a file to pass parameters?

At least in C, I would just call the subroutine passing the arrays of values as parameters
 
Old 05-23-2011, 03:08 PM   #3
16pide
Member
 
Registered: Jan 2010
Posts: 418

Rep: Reputation: 83
I read your files a bit more. And I'm puzzled:
vauto-1.f is a program, it generates a data file, and does not call the FILONC subroutine
four-2.f defines the FILONC subroutine, and it does not read from disk.

So basically those 2 can't work together, at least not this way.

You can add this to the end of vauto-1.f to make it add four-2.f FILONC subroutine to it.

Then, in vauto-1.f, instead of writing to an external file, you should create memory arrays to hold the data.

And then, at the end, call the FILONC subroutine with the right parameters.

I stopped coding in Fortran back in the 80s, so ...

FYI, that source seems to be publised on the Internet, so by using google with your errors or with extracts of the code, you may find your solution.

Good luck!
 
Old 05-23-2011, 04:32 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Basically you can transform the subroutine in a program, if all the calculations are self-contained. You can also insert the code as a subroutine of the main program (as 16pide suggested) if and only if it provides all the required arguments.

On my system, using gfortran, it compiles well if I do only three changes:
Code:
      SUBROUTINE FILONC ( DT, DOM, NMAX, C, CHAT )
becomes
Code:
      PROGRAM FILONC
Then I added at the very beginning of the code the declaration:
Code:
      PARAMETER  ( NMAX = 200 )
since the argument NMAX serves as dimension to declare some other stuff. The number 200 is just a random number: here you need to put the correct value. Finally I removed the RETURN statement at the end and the trick is done.

However, the challenge now is to add I/O statements to read all the required data that are passed as argument to the original SUBROUTINE, that is DT, DOM, C, CHAT. I cannot see a relationship whit the input file RFILE.txt. If you know what is the meaning of these variables and you can provide all of them, it should be easy to put the correct OPEN/READ/CLOSE statements as already done for the MAIN program.

The official online reference about these programs is http://www.ccp5.ac.uk/librar.shtml which is a collection of software provided together with a text book. If you can obtain a copy of the book (maybe from the library at your university or from a dusty shelf somewhere) things may become clearer.

Last edited by colucix; 05-23-2011 at 04:37 PM.
 
Old 05-24-2011, 03:03 AM   #5
fu3lc3ll$
LQ Newbie
 
Registered: May 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Smile Thanks for the suggestions!!!

Hello
Thanks a lot for the advices and suggestions. I find F77 more easier to learn ( well to my capacity i would say) first and then switch to more sophisticated programing languages such as F90, 95, C, C++ or Java depending on the needs.
Thanks a lot also for providing the UK site ( web link ) that has this program. Good to know where i should start my search with. I will see whether i can get a copy of the book that is referenced in that link.

Thanks again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I add this program to main menu? muneer1st Fedora 7 12-11-2008 12:05 PM
Incorporating .NET code into a webpage Maverick1182 Programming 5 12-07-2006 06:27 PM
Want to execute program with out main eshwar_ind Programming 4 03-01-2004 10:03 AM
how can i remove the program in the main menu? Txlyo Red Hat 6 11-17-2003 04:13 AM
What is the main used program for coding Java? Tyir Programming 2 10-20-2003 08:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration