subroutine

Fastest way of calling a subroutine

倾然丶 夕夏残阳落幕 提交于 2019-12-06 10:44:28
问题 As far as I know, in Perl, we can call a subroutine from a Module by using these techniques: Export subroutine foo , import the module which has this subroutine. Finally call it in your perl script. Create an Object of that Module in your perl script finally call foo using that Object . Directly call foo using its path, like this myDir::Module::foo(); . If I am always confused which is better way of calling a subroutine foo . If I have a dynamic script, which I run from the browser and not

Call parallel fortran MPI subroutine from R

一曲冷凌霜 提交于 2019-12-06 05:59:17
问题 I would like to write some parallel Fortran code in a subroutine that can be called by R (I would like to read in data from R and send it to a parallel Fortran MPI). I have noticed, however, that when I run the following program as a subroutine (i.e. substitute "subroutine" for "program"), the code no longer compiles (it does compile when it is a program). I am compiling the code using the mpif90 from MPICH in Linux. Is it possible to initialize and finalize an MPI in a subroutine in Fortran?

Can a Perl subroutine return data but keep processing?

*爱你&永不变心* 提交于 2019-12-06 00:51:13
问题 Is there any way to have a subroutine send data back while still processing? For instance (this example used simply to illustrate) - a subroutine reads a file. While it is reading through the file, if some condition is met, then "return" that line and keep processing. I know there are those that will answer - why would you want to do that? and why don't you just ...?, but I really would like to know if this is possible. 回答1: A common way to implement this type of functionality is with a

Should I call Perl subroutines with no arguments as marine() or marine?

╄→гoц情女王★ 提交于 2019-12-04 23:32:04
As per my sample code below, there are two styles to call a subroutine: subname and subname() . #!C:\Perl\bin\perl.exe use strict; use warnings; use 5.010; &marine(); # style 1 &marine; # style 2 sub marine { state $n = 0; # private, persistent variable $n $n += 1; print "Hello, sailor number $n!\n"; } Which one, &marine(); or &marine; , is the better choice if there are no arguments in the call? In Learning Perl , where this example comes from, we're at the very beginning of showing you subroutines. We only tell you to use the & so that you, as the beginning Perler, don't run into a problem

Contains statement

南楼画角 提交于 2019-12-04 21:17:16
问题 I am not understanding the importance of CONTAINS statement in fortran 90 For example PROGRAM BLABLA IMPLICIT NONE INTEGER :: i,j,k i = 1; j = 1;k =1 PRINT *, i,j,k CALL ABC(i,j,k) PRINT *, i,j,k CONTAINS SUBROUTINE ABC(r,s,t) IMPLICIT NONE INTEGER, INTENT(IN) :: r,s INTEGER, INTENT(OUT) :: t t = r + s END SUBROUTINE ABC END PROGRAM BLABLA and one by defining subroutines outside the main program. I understand for functions, one need to specify the type of the function, but for subroutines it

Using a variable from outer scope in a sub called in foreach

戏子无情 提交于 2019-12-04 19:00:29
I am using cygwin. What this script does is load the iphone pics that I have loaded into a directory on the desktop. It opens it up in image viewer, to let me take a look at the picture. system("cygstart $dirname/$oldfile") ; Then it gives me the option to rename the picture. It is throwing errors though, and not renaming the picture. Use of uninitialized value $oldfile in concatenation (.) or string at ./rename_image.pl line 29, <STDIN> line 6. oldfile is a global varaible, the functions should see the variable. #!/usr/bin/perl # use strict ; use warnings ; my $oldfile; my $new_name; my

Using subroutines written in Fortran 90 with Abaqus Standard

我怕爱的太早我们不能终老 提交于 2019-12-04 17:07:44
I am using Abaqus with user-defined subroutines. To the best of my knowledge, Abaqus Standard or Explicit can be used with subroutines written specifically in Fortran 77 language, not the improved Fortran 90/95 language! Is there a way how to use Fortran 90 and later with Abaqus? By default, Abaqus expects user subroutines to be written in the older fixed-format style. However, you can use just about any modern language feature supported by your compiler. 1 This includes using modules, new intrinsics, derived types, etc, as long as you adhere to the fixed-format style. But if you find the

How can I use hashes as arguments to subroutines in Perl?

爱⌒轻易说出口 提交于 2019-12-04 16:24:58
问题 I was asked to modify some existing code to add some additional functionality. I have searched on Google and cannot seem to find the answer. I have something to this effect... %first_hash = gen_first_hash(); %second_hash = gen_second_hash(); do_stuff_with_hashes(%first_hash, %second_hash); sub do_stuff_with_hashes { my %first_hash = shift; my %second_hash = shift; # do stuff with the hashes } I am getting the following errors: Odd number of elements in hash assignment at ./gen.pl line 85. Odd

Fastest way of calling a subroutine

六眼飞鱼酱① 提交于 2019-12-04 16:24:11
As far as I know, in Perl, we can call a subroutine from a Module by using these techniques: Export subroutine foo , import the module which has this subroutine. Finally call it in your perl script. Create an Object of that Module in your perl script finally call foo using that Object . Directly call foo using its path, like this myDir::Module::foo(); . If I am always confused which is better way of calling a subroutine foo . If I have a dynamic script, which I run from the browser and not command line, which approach one should go for so that the script takes less time. Thanks. There is a

excel vba call subroutine with variables

半世苍凉 提交于 2019-12-04 16:14:45
问题 I defined the following subroutine: Sub EnterCellValueMonthNumber(cells As range, number As Integer) range(cells).Select ActiveCell.FormulaR1C1 = number End Sub When I call the subroutine like this: EnterCellValueMonthNumber ("N23:Q23",1) I get the following error message: Compile error Expected: = I have no idea why I get this message. Does anyone know what I am missing? 回答1: You would call the sub as EnterCellValueMonthNumber "N23:Q23", 1 No brackets. Or Call EnterCellValueMonthNumber("N23