ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.