subroutine

In Perl, how can I check from which module a given function was imported?

折月煮酒 提交于 2019-11-26 16:24:45
问题 I have a code which calls the function. But I don't know the module this function belongs to. I need it to modify this function. How can I check it? 回答1: The Devel::Peek module is very handy to get all sorts of information about variables. One of the things you can do with it is dump a reference to a subroutine and get the name of the glob it came from: $ perl -MDevel::Peek -MList::Util=first -e'Dump(\&first)' SV = IV(0x1094e20) at 0x1094e28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x11183b0 SV =

How to alias a function name in Fortran

谁说我不能喝 提交于 2019-11-26 16:18:58
Not sure if the title is well put. Suggestions welcome. Here's what I want to do. Check a condition, and then decide which function to use in a loop. For example: if (a < 0) then loop_func = func1 else loop_func = func2 endif I can then use loop_func as a pointer when writing my loop. Both functions take exactly the same inputs, and are different approaches on tackling the problem based on the value of a . This will allow me to only have one block of code, instead of two nearly identical blocks. This could apply to subroutines too. Any ideas how this might be implemented? Thank you. Yes,

Does Fortran preserve the value of internal variables through function and subroutine calls?

前提是你 提交于 2019-11-26 14:30:34
问题 After much painful debugging, I believe I've found a unique property of Fortran that I'd like to verify here at stackoverflow. What I've been noticing is that, at the very least, the value of internal logical variables are preserved across function or subroutine calls. Here is some example code to illustrate my point: PROGRAM function_variable_preserve IMPLICIT NONE CHARACTER(len=8) :: func_negative_or_not ! Declares function name INTEGER :: input CHARACTER(len=8) :: output input = -9 output

When should I use the & to call a Perl subroutine?

眉间皱痕 提交于 2019-11-26 13:02:14
I have heard that people shouldn't be using & to call Perl subs, i.e: function($a,$b,...); # opposed to &function($a,$b,...); I know for one the argument list becomes optional, but what are some cases where it is appropriate to use the & and the cases where you should absolutely not be using it? Also how does the performace increase come into play here when omitting the & ? IMO, the only time there's any reason to use & is if you're obtaining or calling a coderef, like: sub foo() { print "hi\n"; } my $x = \&foo; &$x(); The main time that you can use it that you absolutely shouldn't in most

How can a scalar be passed to a vector (1D array) to a Fortran subroutine?

拥有回忆 提交于 2019-11-26 12:32:29
问题 There is this program: INTEGER i,k REAL*8 mp(15,48) REAL*8 sp(15) k=0 do i=1,12 k=k+1 call Equaltensors(sp,mp(1,k),15) enddo end c===================== subroutine Equaltensors(tensA,tensB,n) REAL*8 tensA(n),tensB(n) INTEGER i do i=1,n tensB(i)=tensA(i) enddo return end So basically the value of mp(1,1) and so on is passed to the subroutine as a vector tensB(15) with n=15. What I don\'t understand is how a real number can be stored in a one-dimension array in a subroutine. 回答1: The title of

What does the function declaration “sub function($$)” mean?

放肆的年华 提交于 2019-11-26 09:59:38
问题 I have been using Perl for some time, but today I came across this code: sub function1($$) { //snip } What does this mean in Perl? 回答1: It is a function with a prototype that takes two scalar arguments. There are strong arguments for not actually using Perl prototypes in general - as noted in the comments below. The strongest argument is probably: Far More Than Everything You've Ever Wanted to Know about Prototypes in Perl There's a discussion on StackOverflow from 2008: SO 297034 There's a

Line truncated, Syntax error in argument list

徘徊边缘 提交于 2019-11-26 09:58:06
问题 When I compile the program below, I have an error and a warning in the call Coor_Trans command line as Warning: Line truncated Error: Syntax error in argument list I compile the program several times, but it does not work. Maybe there is something wrong with my call command. program 3D implicit none integer :: i,j,k integer, parameter :: FN=2,FML=5,FMH=5 integer, parameter :: NBE=FN*FML*FMH real, parameter :: pi = 4*atan(1.0) real(kind=4), dimension(1:FN,1:FML+1,1:FMH+1) :: BEXL,BEYL,BEZL

How to alias a function name in Fortran

纵然是瞬间 提交于 2019-11-26 04:46:23
问题 Not sure if the title is well put. Suggestions welcome. Here\'s what I want to do. Check a condition, and then decide which function to use in a loop. For example: if (a < 0) then loop_func = func1 else loop_func = func2 endif I can then use loop_func as a pointer when writing my loop. Both functions take exactly the same inputs, and are different approaches on tackling the problem based on the value of a . This will allow me to only have one block of code, instead of two nearly identical

Correct use of modules, subroutines and functions in Fortran

て烟熏妆下的殇ゞ 提交于 2019-11-26 04:21:26
问题 I\'ve recently learnt about interface blocks when adding a function to my Fortran program. Everything works nice and neatly, but now I want to add a second function into the interface block. Here is my interface block: interface function correctNeighLabel (A,i,j,k) integer :: correctNeighLabel integer, intent(in) :: i,j,k integer,dimension(:,:,:),intent(inout) :: A end function function correctNeighArray (B,d,e,f) character :: correctNeighArray integer, intent(in) :: d,e,f character,

When should I use the & to call a Perl subroutine?

寵の児 提交于 2019-11-26 02:54:28
问题 I have heard that people shouldn\'t be using & to call Perl subs, i.e: function($a,$b,...); # opposed to &function($a,$b,...); I know for one the argument list becomes optional, but what are some cases where it is appropriate to use the & and the cases where you should absolutely not be using it? Also how does the performace increase come into play here when omitting the & ? 回答1: IMO, the only time there's any reason to use & is if you're obtaining or calling a coderef, like: sub foo() {