fortran中的use和call的区别
时间: 2023-04-04 20:02:41 浏览: 459
在Fortran中,use和call是两个不同的关键字,它们的作用也不同。use用于在程序中引用一个模块,而call用于调用一个子程序。具体来说,use语句用于将一个模块中的变量、常量、类型、子程序等引入到当前程序中,以便在程序中使用。而call语句用于调用一个子程序,将控制权转移到被调用的子程序中执行,执行完毕后再返回到调用程序中继续执行。
相关问题
Fortran 77 call
In Fortran 77, you can call a subroutine or function by using the CALL statement followed by the subroutine or function name and any arguments in parentheses.
For example, consider the following subroutine:
```
SUBROUTINE MY_SUB(A, B, C)
INTEGER A, B, C
C = A + B
RETURN
END
```
To call this subroutine from within your main program, you would use the following code:
```
INTEGER A, B, C
A = 1
B = 2
CALL MY_SUB(A, B, C)
```
After the CALL statement, you pass the variables A and B as arguments to the subroutine MY_SUB. The subroutine adds A and B together and returns the result in the variable C. In this example, C will be set to 3.
lapack在fortran中怎么用
LAPACK是一个数值线性代数库,用于在Fortran中进行线性代数计算。这个库包含了很多有用的函数和子程序,可以用于解决线性方程组、矩阵分解、特征值计算等常见的数值线性代数问题。
在Fortran中使用LAPACK,首先需要引用LAPACK库,并在代码中添加对应的模块。通常可以在程序开始的地方使用"USE LAPACK"语句来引用LAPACK库。
使用LAPACK的函数和子程序时,需要提供相应的参数。例如,如果要解决线性方程组Ax=b,可以使用LAPACK的函数"DGESV"来进行求解。这个函数需要提供矩阵A、向量b以及输出向量x的参数。函数调用的语法如下:
CALL DGESV(N, NRHS, A, LDA, IPIV, B, LDB, INFO)
其中,N表示矩阵的维度,NRHS表示方程组的个数,A是输入矩阵,LDA是矩阵A的列数,IPIV是用于记录行交换信息的数组,B是输入的右端项向量,LDB是右端项向量B的长度,INFO是输出参数,用于指示函数调用的执行情况。
除了函数"DGESV",LAPACK还提供了很多其他的函数和子程序,如矩阵分解函数"DGESVD"、特征值计算函数"DSYEVD"等。这些函数的使用方法类似,只需要根据具体问题选择相应的函数和提供相应的参数即可。
总而言之,使用LAPACK库在Fortran中进行数值线性代数计算可以通过引用LAPACK库,并使用对应的函数和子程序来完成。函数和子程序的参数需要根据具体问题来提供。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)