Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do this in fortran, please help!!

Status
Not open for further replies.

kw2

Technical User
Dec 10, 2009
2
US
Hello,

I have a FORTRAN code that consists of some subroutines. I would like to send it to another person to modify one subroutine only and not all other subroutines or the main code. Is there a way of doing that? in other words, I would like him to not see the original code of the main program and other subroutines, only see the subroutine to be modified by him and he can still run the whole program. Is that possible?

Thank you for your help,
 
Hm, you don't seem to ever have compiled a code, are you a manager?

I suppose you've got all subroutines in one chunk, if not you wouldn't ask this.

Make a separate file for each subroutine and compile them to the object file.

You can pass the object files to the guy/girl who's not allowed to see the source and you also hand in the source code of that one and only subroutine he/she is allowed to see.

The other one can then recompile the subroutine to a new object file and link it with the other object files to an executable.

I don't know whether there exists a better method.
(If I understood well, the other one has to be able to recompile on his own)

 
Thank you GerritGroot

Actually I did compile and run fortran codes but for simple problems and I'm not an expert one like you.

The reason of question is because of copyright of the code that his own owner do not want others to see his full code but as part of it, its possible to change.

I follow your steps, but I do not know to do this step:
--The other one can then recompile the subroutine to a new object file and link it with the other object files to an executable.--

the question, how to link the new object for that specific subroutine file with the whole code object file I gave to him???

Thanks alot,
 
1) Identify the main program - how much non-visible code is there in the main program. If it is all of it, then do something like this. Say the code is
Code:
program main
   ....
   stop
end program
Change it to
subroutine mainsub
...
return
end subroutine mainsub
[/code]
And supply another source, mainy.f which has
Code:
program main
   call mainsub
   stop
end program
2) Identify the code to be modified. If it is a whole file, great. If it is part of a file, edit the file, take that part out into a whole file. Say this is called moddy.f
3) Create a library, libby, containing mainsub and all the other files except moddy.f
4) Copy mainy.f, moddy.f and libby to a separate directory. Try building with just mainy.f, moddy.f and the libby. If it builds then that is all you need to supply.

The third party modifies moddy.f, tries a test build and sends it back to you.
 
Dont worry about the manager remark, I was just kiddin', I'm not an expert myself.

xwb's solution is more elegant than mine, but I don't know how to make these libraries very well

If you have the main program and all subroutines in separate files, in gfortran you can do the following:

compiling, to get the object files:
gfortran -c mymainprogram.f90
gfortran -c mysubroutine1.f90
gfortran -c mysubroutine2.f90
gfortran -c mysubroutine3.f90
etc...

You then link with:

gfortran mymainprogram.o mysubroutine1.o mysubroutine2.o mysubroutine3.o -o myexe.exe

If you're only allowed to pass let's say subroutine2, you give the source of subroutine2 and the object files of the rest.

The other one can then recompile subroutine2 only to mysubroutine2.o and link them with the rest.

Gerrit

P.S.: I'm curious how the library option works. How to compile to the lib file and how to link it with the other objects (in gfortran for example)? I suppose he means making a DLL, there are some posts on that in this forum. I asked that on this forum about a month ago.
 
On Linux/Unix, for a static library, use ar, for a DLL use ld. ar is fairly simple, look up the man page for ld.

The parameters for ld vary from on version of Linux/Unix to another. Watch out especially for the -b flag. It means different things on different versions.

On Windows, it is very compiler dependent.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top