Fortran77: what does the asterisk (*) means in subroutine argument? [duplicate] - fortran
This question already has answers here:
What is * in FORTRAN 77
(1 answer)
How can a scalar be passed to a vector (1D array) to a Fortran subroutine?
(2 answers)
Closed 3 years ago.
I have some problem with scipy.interpolate.splrep, so I have no choice by to dig into some very old Fortran77 code.
And one thing I can not understand is here:
https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/curfit.f#L257
it calls a subroutine fpcurf
call fpcurf(iopt,x,y,w,m,xb,xe,k,s,nest,tol,maxit,k1,k2,n,t,c,fp,
* wrk(ifp),wrk(iz),wrk(ia),wrk(ib),wrk(ig),wrk(iq),iwrk,ier)
where the wrk is one dimension array
and the signature of fpcurf is
subroutine fpcurf(iopt,x,y,w,m,xb,xe,k,s,nest,tol,maxit,k1,k2,
* n,t,c,fp,fpint,z,a,b,g,q,nrdata,ier)
c ..
c ..scalar arguments..
real*8 xb,xe,s,tol,fp
integer iopt,m,k,nest,maxit,k1,k2,n,ier
c ..array arguments..
real*8 x(m),y(m),w(m),t(nest),c(nest),fpint(nest),
* z(nest),a(nest,k1),b(nest,k2),g(nest,k2),q(m,k1)
integer nrdata(nest)
you can find it at https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/fpcurf.f
And obviously the signature doesn't match (since wrk is array, and wrk[xxx] is a scalar). Can anyone explain why? I noticed that there is a asterisk (*) here, does it mean anything special?
Maybe anyone familiar with Fortran could please take a look at this function and figure out why the call doesn't match the subroutine signature?
Related
Compact if check involving multiple strings in Fortran [duplicate]
This question already has an answer here: How to check if Fortran array contains value? (1 answer) Closed 2 years ago. Is there a way to check if a string is equal to any of the list together instead of individually explicitly check with a ==? For example, if(color=='violet' .or. color=='indigo' .or. color=='blue' .or.& color=='green' .or. color=='yellow' .or. color=='orange' .or. color=='red') then print *, "It is a rainbow color" end if Is there a way compact way to do this? Something like if(color=='violet|indigo|blue|green|yellow|orange|red') ?
You can put the colors into an array and use any. if (any(color == [character(6) :: "violet","indigo","blue","green","yellow","orange","red"]))
Variable dependent formatting in Fortran90 [duplicate]
This question already has answers here: Format string for output dependent on a variable (4 answers) Closed 2 years ago. I am trying to understand "variable dependent formatting", specifically where the repeat count in FORTRAN format statement is a variable instead of a fixed number. I have gone through one of the similar questions here, where this is addressed by defining a format variable. I have tried to implement a similar type of test code but I get a run-time error saying "Fortran runtime error: Missing initial left parenthesis in format". I am attaching the code that I have. Could you please let me know where I am going wrong. Thank you program main implicit none integer num,i real,dimension(:),allocatable :: logar character(len = 100) fmt print*, "enter any number" read*,num allocate(logar(num)) do i = 1,num logar(i) = log(i/3.14) end do open(unit=200,file="num.txt",status="unknown") write(fmt,'( I4,"(f10.5)" )') num print*,fmt write(200,fmt) (logar(i),i=1,num) end program
Change write(fmt,'( I4,"(f10.5)" )') num to write(fmt,'(a, I4,"(f10.5)",a )') '(', num, ')' Else, you are missing the parenthesis in fmt. Formats strings are delimited by parentheses.
In recursive Fortran subroutines, what is local to the individual call of the subroutine, and what is "global"? [duplicate]
This question already has answers here: Why is the counter variable unexpectedly increased in every subroutine call? [duplicate] (1 answer) Does Fortran preserve the value of internal variables through function and subroutine calls? (3 answers) Why is there an implied SAVE attribute in Fortran? [duplicate] (1 answer) Fortran assignment on declaration and SAVE attribute gotcha (2 answers) Closed 4 years ago. I have the following simple code (which is an example of something I am trying to do in a much more complicated code): module linkmod type link character(len=1) :: name type(link), pointer :: next => null() end type link contains recursive subroutine tell_name(a) type(link), target :: a type(link), pointer :: b !b is useless, except to illustrate my point integer :: num_outputs = 0 b => a if (associated(b%next)) call tell_name(b%next) print *, b%name num_outputs = num_outputs + 1 print *, num_outputs end subroutine tell_name end module linkmod program driver use linkmod type(link) :: a type(link), pointer :: b a%name = 'a' allocate(a%next) b => a%next b%name='b' allocate(b%next) b => b%next b%name = 'c' allocate(b%next) b => b%next b%name = 'd' call tell_name(a) end program I compile and run and get the following output: d 1 c 2 b 3 a 4 Now, I get lucky here because this is the behavior I need, namely, when a call to tell_name() is exited, b in the calling instance has retained the value it had before the calling instance made the call, but num_outputs has been set to what it became in the called instance. (Apologies if that was hard to read. I tried my best there.) The thing is, I don't really understand why things work this way. Why do not both b and num_outputs retain the values they were assigned in the called instance? Or, alternatively, why do they not both re-acquire the values they had in the calling instance, previous to the call? What is the general rule here? On the other hand, what if I wanted num_outputs in a calling instance to be unaffected by what happens in any called instance. How would I arrange that? (BTW, I wrote up an alternative version of the code where I replaced the recursive subroutine with a derived type procedure, called as call b%next%tell_name() I get the exact same behavior with it.)
fortran basic help 'd' operator [duplicate]
This question already has an answer here: Closed 10 years ago. Possible Duplicate: postfix 'd+0' in Fortran real literal expressions I have this code line in Fortran 90: OVERN2 = 1.d+0/DBLE(FLOAT(NMODE2)) NMODE2 is an integer, OVERN2 is a REAL*8. Can you please explain to me what this line does? I don't understand the .d+0/ part? if you can also translate that to C or any other easier language.
1.d+0 is just a double precision literal in scientific notation, i.e. 1.0e0 or just 1.0. In C it would be: double overn2 = 1.0 / (double)nmode2;
DATA declaration in Fortran [duplicate]
This question already has an answer here: what does DATA TKX/2HKX/ mean in fortran? (1 answer) Closed 1 year ago. Does anyone know the meaning of 4HEND in the following line which comes from an old Fortran code? DATA XHEND / 4HEND /
4HEND is a Hollerith code to represent the character string "END ". In very old FORTRAN, the variable XHEND might even be a 4-byte integer or real used to hold character data. If implicit typing was in effect in this program, XHEND would have been a real. Another recent question with Hollerith codes: Writing both characters and digits in an array
It replaces assignment XHEND='END '