Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!wuarchive!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!davis From: davis@pacific.mps.ohio-state.edu ("John E. Davis") Newsgroups: comp.lang.fortran Subject: pointer to function in Fortran??? Message-ID: Date: 11 Oct 90 06:53:17 GMT Sender: news@pacific.mps.ohio-state.edu Reply-To: davis@pacific.mps.ohio-state.edu (John E. Davis) Distribution: comp Organization: "Dept. of Physics, The Ohio State University" Lines: 77 Hi, What is the easiest way that I can define a variable that points to a function in fortran? That is, I want to have a variable that contains the address of some function subprogram and I want to be able to change this varaible to point to other subprograms. Why do I want to do this? I am writing a routine that does integrals of the form g(x) = f(x) * a_messy_expression(x). So I have a subprogram such as: real*8 function do_integral(f,... other parameters) external f . . C! C! Now, In this subprogram, I call some standard library routines to do parts C! of the integral and the standard library routines need to be called as in: C! . . call std_lib_routine(g,....other parameters....) . . where the standard library needs g to be a function of the single variable x. However, my g(x) also depends on another function f(x). If I had only one function f(x), then there would be no problem. However I have several functions f(x). These easiest thing would be to define f to be a pointer to a function and pass the pointer value through a common block to the function subprogram for g(x). Then whenever the standard library evaluates g(x), the f in g(x) will be pointing at the correct f(x). Is this clear? All this could be avoided if the standard library routine allowed f to be passed as well as g as in: real*8 function do_integral(f,...) external f,g . . call std_lib_routine(g,f,...) . . end subroutine std_lib_routine(g,f,...) external g,f . . g_of_x = g(f,x) . . end real*8 function g(f,x) external f . . g = f(x) * messy_expression(x) end But the standard library does not operate this way. Of course I can always duplicate code but and reanme things but this is not very elegant. What do fortran programmers do in a situation like this? Thanks, -- John bitnet: davis@ohstpy internet: davis@pacific.mps.ohio-state.edu