subroutine

Call parallel fortran MPI subroutine from R

孤人 提交于 2019-12-04 11:07:50
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? If not, is it still possible to somehow call a parallel Fortran MPI from R? If not in Fortran, can

Can a Perl subroutine return data but keep processing?

故事扮演 提交于 2019-12-04 06:26:38
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. A common way to implement this type of functionality is with a callback function: { open my $log, '>', 'logfile' or die $!; sub log_line {print $log @_} } sub process_file { my

Pass hash to subroutine comes to error in perl

耗尽温柔 提交于 2019-12-04 05:31:02
问题 My code as below, my %srvs = ( serv_1 => { agents => 'agent_path', ... ... }, serv_2 => { <same like above> }, serv_3 => { ... ........ ........ serv_8 => { ... }, ); switch ("$option") { case 1 { print "Option 1 selected. \n"; &main; } case 2 { print "Option 2 selected. \n"; stop(\%srvs); } case 3 { print "Option 3 selected. \n"; start(\%srvs); } else { print "Option are not valid. \n"; exit 0; } } sub stop { my $servs = @_; foreach my $s_name (sort keys %{$servs}) { print "$s_name \n"; my

How can I take a reference to a Perl subroutine?

六月ゝ 毕业季﹏ 提交于 2019-12-04 02:58:54
I'm having some trouble figuring out how to make a reference to a subroutine in an external module file. Right now, I'm doing this: External file package settingsGeneral; sub printScreen { print $_[0]; } Main use settingsGeneral; my $printScreen = settingsGeneral::printScreen; &$printScreen("test"); but this result into an error: Can't use string ("1") as a subroutine ref while "strict refs" in use As noted in perlmodlib , you should start your module's name with an uppercase letter: Perl informally reserves lowercase module names for 'pragma' modules like integer and strict . Other modules

Using CALL for labels in a batch script

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 16:36:44
问题 When using the CALL command to call a label in a batch script, and you end the sub-routine with GOTO:eof, what happens from there? Does it return back to where the sub-routine's CALL is located? Or does it continue on after the location of the call script? For example: ECHO It's for my college fund. CALL :OMGSUB ECHO *runs away and cries like a little girl* :OMGSUB ECHO Your mom goes to college. GOTO:eof ECHO *picks up jewelry box* After GOTO:eof which line will it echo next? 回答1: Why not

Dynamically Create AutoHotkey Hotkey to Function/Subroutine

时光怂恿深爱的人放手 提交于 2019-12-03 13:13:32
问题 The AutoHotkey command Hotkey allows for the creation of dynamic hotkeys at runtime, but its syntax and documentation seems to limit it to built-in or existing labels/subroutines, which makes it much less useful: Hotkey, KeyName [, Label, Options] Is there a way to get it to work like regular, hard-coded hotkeys? For example: #z::MsgBox foobar ; Typical, hard-coded hotkey pops up a message-box Hotkey, z, MsgBox foobar ; Nope; complains about missing label “MsgBox foobar” It looks like it

Printing out the code of an anonymous subroutine

和自甴很熟 提交于 2019-12-03 12:27:31
问题 I'm currently working in a very complex Perl architecture, and I want to create some debugging tools. Since a lot of the behavior involves anonymous subroutines, I'd like to analyze some of the behavior, and all I have to work with is a reference to the subroutine. In short, is there a way to print the code (since Perl is interpreted it may still be available?) of a subroutine reference? 回答1: The core module B::Deparse provides this functionality. use B::Deparse (); my $deparse = B::Deparse-

Assembly 'call' vs 'jmp'

别等时光非礼了梦想. 提交于 2019-12-03 11:24:05
问题 I got told to try and use 'jmp rather than 'call', but 'jmp' is not liking me .. when I jump it doesn't return (so it never exits and not happy days ), but calling returns and exits as normal. I am happy using 'call' but is there actually a reason I should try and overcome 'jmp' ? This simple code just shows if when I jmp it never returns and exits. _start: jmp _Print jmp _Exit ret _Exit: ; normal exit ret _Print ; print something ret also .. I'm running this all in a Linux terminal if that

excel vba call subroutine with variables

你。 提交于 2019-12-03 10:26:29
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? You would call the sub as EnterCellValueMonthNumber "N23:Q23", 1 No brackets. Or Call EnterCellValueMonthNumber("N23:Q23", 1) Brackets, and Call before it. Also, your Sub is expecting a Range object as the first argument and

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

我的梦境 提交于 2019-12-03 09:36:00
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 number of elements in hash assignment at ./gen.pl line 86. Use of uninitialized value in concatenation