subroutine

fortran operator overloading: function or subroutine

五迷三道 提交于 2019-11-28 01:44:48
问题 I recently updated my .f90 code to .f03, and I was expecting to see speedup because my older version involved many allocating and deallocating (7 3D arrays--45x45x45) at each iteration inside a do loop (4000 in total). Using derived types, I allocate these arrays at the beginning of the simulation and deallocate them at the end. I thought that I would see speedup, but it's actually running significantly slower (30 min as opposed to 23 min). I ran a profiler, and it looks like the add/subtract

FORTRAN - allocatable array in subroutine

倾然丶 夕夏残阳落幕 提交于 2019-11-28 01:25:01
问题 I'm trying to use an allocatable array in a subroutine but the compiler complains that Error: Dummy argument 'locs' with INTENT(IN) in variable definition context (ALLOCATE object) at (1) The only thing I could find was that I am supposed to use an explicit interface, which I am doing. Here the relevant code for the subroutine: RECURSIVE SUBROUTINE together(locs, LL, RL) INTEGER, DIMENSION(:,:), ALLOCATABLE, INTENT(IN) :: locs INTEGER, INTENT(IN) :: LL, RL ALLOCATE(locs(LL,RL)) END SUBROUTINE

Calling perl subroutines from the command line

时间秒杀一切 提交于 2019-11-28 00:54:13
问题 Ok so i was wondering how i would go about calling a perl subroutine from the command line. So if my program is Called test, and the subroutine is called fields i would like to call it from the command line like. test fields 回答1: Use a dispatch table. #!/usr/bin/perl use strict; use warnings; use 5.010; sub fields { say 'this is fields'; } sub another { say 'this is another subroutine'; } my %functions = ( fields => \&fields, another => \&another, ); my $function = shift; if (exists

Module calling an external procedure with implicit interface

孤人 提交于 2019-11-28 00:33:35
The following code, combining module procedures and external procedures : module module_dummy implicit none contains subroutine foo(a) real, intent(inout) :: a(:) call bar(a) end subroutine foo end module module_dummy program main use module_dummy implicit none integer, parameter :: nelems = 100000000 real, allocatable :: a(:) allocate( a(nelems) ) a = 0.0 call foo(a) print *, a(1:10) deallocate(a) end program main subroutine bar(a) implicit none real, intent(inout) :: a(:) a = 1.0 end subroutine bar seems to fail either: with a segmentation fault printing a block of 0.000 instead of a block

Passing strings for execution in Fortran subroutines

為{幸葍}努か 提交于 2019-11-28 00:30:24
In the following subroutine I would like to pass a string variables named str . If it is 'poly' , 'gaus' , 'slat' , then it has a predefined action ( fval = see code below ). I would like to have the user specify a function to use and pass that as a string variable. That is ... If str = '3*cos(i*t)' , then i would like to have fval be equal to 3*cos(i*t) . How can I get Fortran to interpret the string entered as a command to be executed by Fortran? subroutine f(fval, i, t, str) implicit none integer, parameter :: ikind = selected_int_kind(8) integer, parameter :: dbl = selected_real_kind(15

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

帅比萌擦擦* 提交于 2019-11-27 23:09:37
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 = func_negative_or_not(input) WRITE(*,10) input, " is ", output 10 FORMAT("FUNCTION: ", I2, 2A) CALL

Perl - Subroutine redefined

坚强是说给别人听的谎言 提交于 2019-11-27 14:27:29
问题 I have asked this question before or searched and seen others ask - why am I getting the warning " Subroutine mySub redefined at ../lib/Common.pm line x "? and you always get the answer you declared the sub twice in the same code . I created this test package: ENTIRE FILE --------------- package MyCommonPkg; use strict; sub thisSubroutineIsNotDefinedAnywhereElse{ } 1; ENTIRE FILE --------------- and I USE this package from a perl script, which uses other packages, that use this package also,

Is there a difference between Perl's shift versus assignment from @_ for subroutine parameters?

孤人 提交于 2019-11-27 14:00:52
问题 Let us ignore for a moment Damian Conway's best practice of no more than three positional parameters for any given subroutine. Is there any difference between the two examples below in regards to performance or functionality? Using shift : sub do_something_fantastical { my $foo = shift; my $bar = shift; my $baz = shift; my $qux = shift; my $quux = shift; my $corge = shift; } Using @_ : sub do_something_fantastical { my ($foo, $bar, $baz, $qux, $quux, $corge) = @_; } Provided that both

What's the best way to discover all subroutines a Perl module has?

和自甴很熟 提交于 2019-11-27 11:37:31
问题 What's the best way to programatically discover all of the subroutines a perl module has? This could be a module, a class (no @EXPORT), or anything in-between. Edit: All of the methods below look like they will work. I'd probably use the Class::Sniff or Class::Inspector in production. However, Leon's answer is marked as 'accepted' since it answers the question as posed, even though no strict 'refs' has to be used. :-) Class::Sniff may be a good choice as it progresses; it looks like a lot of

How to pass subroutine names as arguments in Fortran?

霸气de小男生 提交于 2019-11-27 09:08:39
What is the syntax for passing subroutine names as arguments? Schematically: . . call action ( mySubX ( argA, argB ) ) . . subroutine action ( whichSub ( argA, argB ) ) ... call subroutine whichSub ( argA, argB ) ... end subroutine action The goal is to have call subroutine whichSub ( argA, argB ) act as call subroutine mySubX ( argA, argB ) . My preference is to avoid avoid passing a switch parameter and then use SELECT CASE. It is call action(mySubX) provided action looks as subroutine action(sub) !either - not recommmended, it is old FORTRAN77 style external sub !or - recommended interface