0

I had the following code in a big file containing 5000 lines.

function w_de(a)
real(dl) :: w_de, al
real(dl), intent(IN) :: a

if(.not. use_tabulated_w) then
    w_de = w_lam+wa_ppf*(1._dl-a)*alfa   !!! PLEASE JUST SEE THIS PART
else
    al=dlog(a)
    if(al.lt.a_ppf(1)) then
        w_de=w_ppf(1)                   
    elseif(al.gt.a_ppf(nw_ppf)) then
        w_de=w_ppf(nw_ppf)             
    else
        call cubicsplint(a_ppf,w_ppf,ddw_ppf,nw_ppf,al,w_de)
    endif
endif
end function w_de 

this code works correctly and all components w_lam, wa_ppf, alfa, tabulated_w are defined in some places in 5000 lines of code. We do not need them in this question. PLEASE JUST SEE w_de = w_lam... LINE.

Because of some reasons and som testing issue I have written the code above as

function wq(an)
real(dl)::wq, an
wq=w_lam+wa_ppf*(1._dl-an)*alfa
end function wq

function w_de(a)
real(dl) :: w_de, al,wq
real(dl), intent(IN) :: a

if(.not. use_tabulated_w) then
    w_de = wq(a)     !! JUST SEE THIS PART
else
    al=dlog(a)
    if(al.lt.a_ppf(1)) then
        w_de=w_ppf(1)                   
    elseif(al.gt.a_ppf(nw_ppf)) then
        w_de=w_ppf(nw_ppf)             
    else
        call cubicsplint(a_ppf,w_ppf,ddw_ppf,nw_ppf,al,w_de)
    endif
endif
end function w_de 

But compinig the second form of codes gets an error

/tmp/ipo_ifortqAvaYt3.o: In function `lambdageneral_mp_w_de_':
ipo_out3.f:(.text.hot00005+0xdbe): undefined reference to `wq_'
....
make: *** [camb] Error 1

I do not understand what is the problem. Thank you

David
  • 63
  • 1
  • 11
  • Where is `wq()` defined? In a module or externally? How does the `lambdageneral` module look like and what does it contain? Does it contain `wq()`? See [mcve]. – Vladimir F Героям слава Aug 23 '18 at 11:56
  • @VladimirF Hi, Dont do you see `wq`? `function wq(an)`!!! and I do not have `lambdangeneral` fortran said this not me. and there is no such a thing in lines – David Aug 23 '18 at 11:59
  • @VladimirF I just wrote one line in a separate function, why this error? – David Aug 23 '18 at 12:05
  • At the line indicated by you a function called wq is referenced. The linker can not find this function. This is what generates the error. Quite why the linker can not find the function wq can not be worked out with what you have shown, but the most likely reasons are that you haven't written it, or the file containing it is not supplied to the linker, or that wq is private to a module and thus can not be seen out side that module. – Ian Bush Aug 23 '18 at 12:16
  • @David You DO have a `lambdageneral` module. That's why the linker says the call is from `lambdageneral_mp_w_de_`. So please do show us the structure of your code **including the modules** in which the functions are placed. – Vladimir F Героям слава Aug 23 '18 at 12:18
  • And of course I do see the definition of `wq` but I have no idea where it is actually placed. In which source file and in which module. And that is the important thing. I don't care too much how does it actually look inside `wq`, but where you actually have it is important. Not where it is in your question but where it is in your source files. Where did you copy it from. – Vladimir F Героям слава Aug 23 '18 at 12:21
  • @VladimirF Ah yes, both of them are in that module `lambdagernal` Shoould I take the `wq` out of this module? – David Aug 23 '18 at 12:29
  • @VladimirF, If yes, I took the `wq` out of that module and fortran says `A kind-param must be a digit-string or a scalar-int-constant-name.` – David Aug 23 '18 at 12:33
  • 1
    "wq" is declared locally in the line "real(dl) :: w_de, al,wq" in addition to the definition right above w_de(), so I guess the linker is trying to find an external one. So, maybe we remove wq from that local declaration (like "real(dl) :: w_de, al")? – roygvib Aug 23 '18 at 12:34
  • @roygvib If I remove `wq` fortran will ask me to define that. If I take the `wq`out of `lambdagernal` modul fortran says ` kind-param must be a digit-string or a scalar-int-constant-name.` – David Aug 23 '18 at 12:39
  • 2
    Could you try to remove only the "wq" in "real(dl) :: w_de, al,wq" in the second code, while retaining the function definition of wq() above? (Because your function wq() is placed inside a module, it has an explicit interface, so no need to declare its name as real(dl) again.) – roygvib Aug 23 '18 at 12:42
  • @roygvib I did it but many errors occured. Many errors of other parts of code which `w_de` is used in them. – David Aug 23 '18 at 12:46
  • Ouch I actually did look whether there is any `real :: wq`, but I just missed it. – Vladimir F Героям слава Aug 23 '18 at 12:47
  • @David There is a similar (essentially the same) case shown above as "duplicate", so I think it will be useful to first check that page (I believe the trouble is for the same reason.) – roygvib Aug 23 '18 at 12:49
  • @VladimirF I write in `real::` but did not solve the problem – David Aug 23 '18 at 12:51
  • @roygvib they suggested exactly what you said, but my problem still exist – David Aug 23 '18 at 12:52
  • @VladimirF I rewrite the code and it complied without any problem according to the duplicated quetion – David Aug 23 '18 at 13:00
  • @roygvib IIt solved, I removed `wq` from `real` but it got me error, I rewrite the whole code again and it complied correctly. I did not understand what the problem was after your and the duplcated question stated some modifications] – David Aug 23 '18 at 13:02
  • Hmm, so the problem solved? (Another pattern of the trouble is that one fails to recompile some of the modified source files while running the old executable (a.out etc)). If solved, nice :-) – roygvib Aug 23 '18 at 13:06
  • @roygvib I am Python user and I am modifying `CAMB` cosmological code, and there are too many new things I am deal with. – David Aug 23 '18 at 13:22
  • 1
    @David No problem, Fortran is very tricky, so I think it takes time to get used to it... RE possible pitfalls, [this page](http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html) might be useful (if not yet checked). Good luck! – roygvib Aug 23 '18 at 13:32

0 Answers0