subroutine

Passing an allocatable character to a subroutine with unlimited polymorphic dummy argument in Fortran

痞子三分冷 提交于 2019-12-02 08:57:59
问题 I'm trying to write a routine that is able to convert a string into different kinds of data type, based on unlimited polymorphism. The idea is the user call this routine, passing the variable where it wants to store the data, and the routine to define the conversion based on the variable/argument type. An excerpt of this routine is here: subroutine GetAsScalar (this, value, status) !Arguments------------------------------------------------------------- class(TKeyword) :: this class(*) ::

How can I implement if(condition1 && condition2) in MIPS?

懵懂的女人 提交于 2019-12-02 08:29:00
问题 I have written the following function to check whether a character is a digit or not: # IsDigit - tests a if a character a digit or not # arguments: # $a0 = character byte # return value: # $v0 = 1 - digit # 0 - not a digit IsDigit: lb $t0, ($a0) # obtain the character li $t1, 48 # '0' - character li $t2, 57 # '9' - character bge $t0, $t1, condition1 condition1: ble $t0, $t2, condition2 li $v0, 0 j return condition2: li $v0, 1 return: # return jr $ra Is there any better way to do or write

Perl special variable “@_” in a subroutine not working

半腔热情 提交于 2019-12-02 08:16:51
This script rips out the urls from a downloaded webpage. I had some trouble with this script - when I use the "my $csv_html_line = @_ ;" and then print out the "@html_LineArray" - it just prints out "1's" . When I replace the "my $csv_html_line = @_ ;" with "my $csv_html_line = shift ;" the script works fine. I do not know what the difference is betweeh the "= @_" and shift - becuase I thought that without specifying something, in a subroutine, shift shift froms "@_". #!/usr/bin/perl use warnings; use strict ; sub find_url { my $csv_html_line = @_ ; #my $csv_html_line = shift ; my @html

Pass hash to subroutine comes to error in perl

和自甴很熟 提交于 2019-12-02 03:17:58
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 $ssh = Net::OpenSSH->new("<user_id>\@$s_name", timeout=>30); $ssh->error and die "Unable to connect $s

Subroutine with array element as argument

风格不统一 提交于 2019-12-02 01:36:45
In my program subroutine stlstp passing work(2,1) as parameter to stlfts(...) subroutine. work(2,1) will be double value at that index, but how subroutine converting it as single dimension array x(n) ? When I print x value in stlfts(...) subroutine, it is printing elements of n size, example: STLFTS....X,,, 0.0000000000000000 1.4964418382246345E-317 1.48978578 58438612E-317 1.4964339331743010E-317 1.4964418382246345E-317 4.3367611401 .... My understanding is, except 1st value, all other values in this x are garbage, but not sure how this assignment will will effect original reference? can

Do I always have to provide Tkx's -command argument an anonymous subroutine?

时光怂恿深爱的人放手 提交于 2019-12-02 00:28:06
I find it a bit weird that I have to wrap defined subroutines anonymously when specifying the -command argument for Tkx widgets. An excerpt from a TkDocs tutorial demonstrates this: my $cb = $frm->new_ttk__button ( -text => "Calculate", -command => sub {calculate();} ); sub calculate { $meters = int(0.3048*$feet*10000.0+.5)/10000.0 || ''; } Why doesn't it work when I write -command => &calculate() or -command => \&calculate() ? You don't have the syntax quite right. Your examples call the subroutine (the & bypasses any prototypes) and passes either the return value ( &calculate() ) or a

nasm calling subroutine from another file

风流意气都作罢 提交于 2019-12-01 08:32:23
I'm doing a project that attaches a subroutine that I wrote to a main file included by the teacher. He gave us the instructions for making our subroutine global but apparently I'm an idiot. The two asm files are in the same folder, I'm using nasm -f elf -g prt_dec.asm and ld prt_dec and then doing the same for main.asm. Here's the relevant code in the main.asm: SECTION .text ; Code section. global _start ; let loader see entry point extern prt_dec _start: mov ebx, 17 mov edx, 214123 mov edi, 2223187809 mov ebp, 1555544444 mov eax, dword 0x0 call prt_dec call prt_lf The line call prt_dec throws

Does Fortran intent(inout) pass a copy of the value, or pointer/reference to RAM address?

ぐ巨炮叔叔 提交于 2019-12-01 06:32:23
As title states I wish to know does Fortran intent(inout) pass a copy of the value, or a pointer/reference to RAM address? The reason I need to know this is I need to pass a (relatively) big data matrix. If it creates a local copy that would cause me problems. Thank you! Fortran does not specify details of how function and subroutine arguments are passed, but it does require that if a procedure modifies an intent(out) or intent(inout) argument then the changes will be visible to the caller after the procedure returns. It is common for compilers to implement this requirement by passing

Fortran - Return an anonymous function from subroutine

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 06:31:36
I am trying to generalize a function call from a subroutine. So my idea is something like this if (case1) then call MainSubroutine1(myFun) elseif (case2) call MainSubroutine2(myFun) end if do i = 1,4 data = myFun(i) end do I realize this is kind of vague but I am not sure if this is possible. Thank you, John edit 1/31/14 7:57 AM I am sorry for the vague way I phrased this. I was thinking something similar to what @haraldki did but I was hoping that I could define an anonymous function within MainSubroutine1 and MainSubroutine2 and transfer that definition out to the main code. This is because

Does Fortran intent(inout) pass a copy of the value, or pointer/reference to RAM address?

痴心易碎 提交于 2019-12-01 05:03:15
问题 As title states I wish to know does Fortran intent(inout) pass a copy of the value, or a pointer/reference to RAM address? The reason I need to know this is I need to pass a (relatively) big data matrix. If it creates a local copy that would cause me problems. Thank you! 回答1: Fortran does not specify details of how function and subroutine arguments are passed, but it does require that if a procedure modifies an intent(out) or intent(inout) argument then the changes will be visible to the