subroutine

Fortran: Calling a function in a module from a procedure in another module

北慕城南 提交于 2019-12-11 06:13:07
问题 I admit the title might be a bit obscure, so let me give an example of what I want to do and what doesn't work. I have a main program which calls a subroutine which is in a module: Program Test_program Use module_A Implicit none Integer :: i i = 1 call subroutine_A(i) End program Test_program this subroutine_A is in module A, and in turns calls a function_B which is in module_B: module module_A use module_B implicit none contains subroutine subroutine_A(i) implicit none integer, intent(in) ::

Reference passing is changing the values of a matrix

给你一囗甜甜゛ 提交于 2019-12-11 04:54:07
问题 I'm trying to make a code in Fortran90 (compiling with ifort) in which I multiply two matrices. I'm writing code for this because one of the matrices is sparse, so you can do the multiplication without allocating memory for the whole matrix. I have two subroutines. The first one, multiplies the sparse matrix ( k in diagonal, and l at both sides of the diagonal) and a vector ( b ). The result is passed to the main function trough pointer r . I chose using subroutines and no functions because

How to stop a subroutine and raise a flag?

半世苍凉 提交于 2019-12-11 04:19:55
问题 I am writing a program in Fortran 95 (to be compiled with with gfortran) containing a subroutine that performs a certain computation. As suggested in "Fortran 95/2003 for Scientists & Engineers" by S. J. Chapman, I am trying to stop the subroutine when an error is encountered and "throw" [1] an error flag that is "catch"ed [1] by the calling program, that will take all the necessary actions. Ideally, I am going for something like: ! Pseudo-code PROGRAM my_prog integer :: error_flag CALL my

Loading derived types with a subroutine within a module in modern Fortran

微笑、不失礼 提交于 2019-12-10 18:04:20
问题 Goal: use the subroutine load_things to load a library of structures of type su2 . Running gfortran simple.f90 produces Undefined symbols for architecture x86_64: "_load_things_", referenced from: _MAIN__ in cc7DuxGQ.o (maybe you meant: ___myclass_MOD_load_things_sub) ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status The main program follows: program simple use myClass implicit none integer :: nThings type ( su2 ) :: reflections call load_things (

batch script subroutine: Passing arguments

萝らか妹 提交于 2019-12-08 15:44:48
问题 My understanding is that in order to get the date from a file passed into a subroutine as an argument, you must re-set that argument as a variable within the subroutine. Is this correct? This doesn't make since to me, so I am wondering if I do not fully understand what is going on. I can use the passed in argument in practically any other subroutine code except for date extraction. set setupEXE=setup.exe CALL :SUB_CheckCorrectDate %setupEXE% GOTO EOF ::---------------------------------- :SUB

Common block and subroutine argument

做~自己de王妃 提交于 2019-12-08 11:15:35
If I have a variable called var which is in a common block named myCB may I use the same name to pass an argument between two other subroutines which are not using the common block myCB ? The code is like below. Subroutine SR1(Var) !something here using Var end Subroutine SR1 Subroutine SR2() .... Call SR1(B) .... end Subroutine SR2 Subroutine SR3() common \myCB\ Var ... ! something using the other Var shared with SR4 ...... end Subroutine SR3 Subroutine SR4() common \myCB\ Var .... ... ! something using the other Var shared with SR3 .... end Subroutine SR4 I do have problem with Var passing

Should a subroutine always return explicitly?

假如想象 提交于 2019-12-07 19:46:33
问题 If perlcritic says "having no returns in a sub is wrong", what is the alternative if they really aren't needed? I've developed two apparently bad habits: I explicitly assign variables to the '$main::' namespace. I then play with those variables in subs. For example, I might do.. #!/usr/bin/perl use strict; use warnings; @main::array = (1,4,2,6,1,8,5,5,2); &sort_array; &push_array; &pop_array; sub sort_array{ @main::array = sort @main::array; for (@main::array){ print "$_\n"; } } sub push

Why subroutine needs to be written after the declaration of variables used in it?

寵の児 提交于 2019-12-07 01:47:28
问题 Let's assume we have this code, why it fails with the explicit package name error since the function is called only after the declaration of the $value ? use strict; use warnings; sub print_value{ print "\n$value"; } my $value = 2; print_value(); This fails at compile time with : Global symbol "$value" requires explicit package name at file.pl line 5. Execution of file.pl aborted due to compilation errors. And this code works perfectly fine: use strict; use warnings; my $value = 2; print

How should I pass objects to subroutines?

拜拜、爱过 提交于 2019-12-07 00:22:23
问题 Is one of these the best or the worst approach? utilize the scope: my $cache = CHI->new( driver => 'File', expires_in => 3600 ); sub one { if ( my $data = $cache->get( 'key_one' ) ) { # ... } sub two { if ( my $data = $cache->get( 'key_two' ) ) { # ... } passing the object as argument: my $cache = CHI->new( driver => 'File', expires_in => 3600 ); sub one { my ( $cache ) = @_; if ( my $data = $cache->get( 'key_one' ) ) { # ... } sub two { my ( $argument1, $cache ) = @_; if ( my $data = $cache-

Should a subroutine always return explicitly?

只谈情不闲聊 提交于 2019-12-06 14:28:48
If perlcritic says "having no returns in a sub is wrong", what is the alternative if they really aren't needed? I've developed two apparently bad habits: I explicitly assign variables to the '$main::' namespace. I then play with those variables in subs. For example, I might do.. #!/usr/bin/perl use strict; use warnings; @main::array = (1,4,2,6,1,8,5,5,2); &sort_array; &push_array; &pop_array; sub sort_array{ @main::array = sort @main::array; for (@main::array){ print "$_\n"; } } sub push_array{ for ( 1 .. 9 ){ push @main::array, $_; } } sub pop_array { for ( 1 .. 3 ){ pop @main::array; } } I