fortran 数组函数的函数调用中怎么返回一数组

后使用快捷导航没有帐号?
只需一步, 快速开始
只需一步,快速开始
查看: 2073|回复: 8
subroutine或function识别数组(怎么让数组成为函数参数)
在线时间 小时
登录后查看更多精彩内容~
才可以下载或查看,没有帐号?
原意是想用数组进行平均值矩平值还有方差等的计算,就想着用函数比较简单些。
但是发现函数里面用数组作为参数是不可以运行的。(程序检验硬是说我的函数参数错了)
我想问下有什么方法可以让数组作为函数参数进行运算吗?或者各路大神小神可以给我个程序让我自己去拜读一下~
谢谢各位!!!!{:soso_e112:}
密码修改失败请联系qq:
在线时间 小时
你可以在子程序里面进行相关的运算 返回运算的结果即可
密码修改失败请联系qq:
在线时间 小时
数组本来就可以当做参数传递的,直接传入数组名就行让别人给你代码还不如把错误的那段贴出来
密码修改失败请联系qq:
在线时间 小时
&成长值: 825
mofangbao 发表于
数组本来就可以当做参数传递的,直接传入数组名就行让别人给你代码还不如把错误的那段贴出来
数组传递的是地址
密码修改失败请联系qq:
在线时间 小时
兰溪之水 发表于
数组传递的是地址
额。。。fortran里面传递变量默认都是地址的啊。。。这还用说么
密码修改失败请联系qq:
在线时间 小时
&成长值: 825
mofangbao 发表于
额。。。fortran里面传递变量默认都是地址的啊。。。这还用说么
数好像不是地址。。。忘了,以前C语言老考这类题。。。
密码修改失败请联系qq:
在线时间 小时
兰溪之水 发表于
数好像不是地址。。。忘了,以前C语言老考这类题。。。
像传递4、5、6这些数不是变量哦,哈哈,兰溪你也有忘了的时候
密码修改失败请联系qq:
在线时间 小时
可以直接传递数组,你在你的subroutine的声明中定义好数组,写好计算程序就可以了呀。调用的时候直接将主程序中的数组名作为参数传递给subroutine。如果你的数组事先不知道大小,那就使用module或者interface给subroutine加个接口。
密码修改失败请联系qq:
在线时间 小时
非常感谢各位~~~问题解决啦~
如果在开头能写成数组形式就可以了~
我之前写错了,写成了subroutine(b(n),s2,s1)subroutine s(b,s2,s1)
integer,parameter::n=20
real b(n)复制代码
密码修改失败请联系qq:君,已阅读到文档的结尾了呢~~
精品:fortran 数组 fortran 动态数组 fortran 二维数组 fortran 计时函数 fortran 对数函数 fortran 数组赋值 fortran 数组求和 fortran指数函数 fortran int函数 fortran函数
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
第七讲数组的使用及Fortran函数
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
风光背后,不是肮脏就是沧桑,再多的人,走不进去,一样孤单。
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
Description:Determines the maximum value of the elements in an array value, or, if the DIM argument is supplied, determines the maximum value along each row of the array in the DIM direction. If MASK is present, only the elements for which MASK is .TRUE. are considered. If the array has zero size, or all of the elements of MASK are .FALSE., then the result is -HUGE(ARRAY) if ARRAY is numeric, or a string of nulls if ARRAY is of character type.&Standard:Fortran 95 and later&Class:Transformational function&Syntax:RESULT = MAXVAL(ARRAY, DIM [, MASK])&RESULT = MAXVAL(ARRAY [, MASK])return value:If DIM is absent, or if ARRAY has a rank of one, the result is a scalar. If DIM is present, the result is an array with a rank one less than the rank of ARRAY, and a size corresponding to the size of ARRAY with the DIM dimension removed. In all cases, the result is of the same type and kind as ARRAY.简单说一下,maxva可以用来求定一个数组的最大值,当然我们也可以用来限定条件,比如maxval(data,data&1e4),可以用来计算data这个数组里小于10^4的最大值,对于一些地方还是很有用的;2、MOD-Remainder functionDescription:MOD(A,P) computes the remainder of the division of A by P.&Standard:Fortran 77 and later&Class:Elemental function&Syntax:RESULT = MOD(A, P)&Arguments:A Shall be a scalar of type INTEGER or REAL.&P Shall be a scalar of the same type and kind as A and not equal to zero.&Return value:The return value is the result of A - (INT(A/P) * P). The type and kind of the return value is the same as that of the arguments. The returned value has the same sign as A and a magnitude less than the magnitude of P.mod是常用的取余函数。3、SUM — Sum of array elementsDescription:Adds the elements of ARRAY along dimension DIM if the corresponding element in MASK is TRUE.Class:Transformational function&Syntax:RESULT = SUM(ARRAY[, MASK])&RESULT = SUM(ARRAY, DIM[, MASK])&Arguments:ARRAY Shall be an array of type INTEGER, REAL or COMPLEX.&DIM (Optional) shall be a scalar of type INTEGER with a value in the range from 1 to n, where n equals the rank of ARRAY.&MASK (Optional) shall be of type LOGICAL and either be a scalar or an array of the same shape as ARRAY.&Return value:The result is of the same type as ARRAY.If DIM is absent, a scalar with the sum of all elements in ARRAY is returned. Otherwise, an array of rank n-1, where n equals the rank of ARRAY, and a shape similar to that of ARRAY with dimension DIM dropped is returned.sum为求和函数。4、SIZE — Determine the size of an arrayDescription:Determine the extent of ARRAY along a specified dimension DIM, or the total number of elements in ARRAY if DIM is absent.&Standard:Fortran 95 and later, with KIND argument Fortran 2003 and later&Class:Inquiry function&Syntax:RESULT = SIZE(ARRAY[, DIM [, KIND]])&Arguments:ARRAY Shall be an array of any type. If ARRAY is a pointer it must be associated and allocatable arrays must be allocated.&DIM (Optional) shall be a scalar of type INTEGER and its value shall be in the range from 1 to n, where n equals the rank of ARRAY.&KIND (Optional) An INTEGER initialization expression indicating the kind parameter of the result.&Return value:The return value is of type INTEGER and of kind KIND. If KIND is absent, the return value is of default integer kind.
阅读(7807)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'Fortran里几个有用的函数',
blogAbstract:'1、MAXVAL — Maximum value of an array&Description:Determines the maximum value of the elements in an array value, or, if the DIM argument is supplied, determines the maximum value along each row of the array in the DIM direction. If MASK is present, only the elements for which MASK is .TRUE. are considered. If the array has zero size, or all of the elements of MASK',
blogTag:'',
blogUrl:'blog/static/4',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:4,
permalink:'blog/static/4',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'风光背后,不是肮脏就是沧桑,再多的人,走不进去,一样孤单。',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}fortran&如何提取TXT中某列的数据存入一个数组,再对数组做处理 — 编程爱好者社区
主题:fortran&如何提取TXT中某列的数据存入一个数组,再对数组做处理
[专家分:0]
1&&&&991.2&&&&946.1&&&&0.05&&&&0.0042&&&&1.64&&&&44693.822&&&&958.1&&&&847.7&&&&0.287&&&&0.0095&&&&0.77&&&&41607.113&&&&918.8&&&&317.1&&&&0.146&&&&0.0088&&&&0.83&&&&39786.994&&&&982.3&&&&342.7&&&&0.297&&&&0.0169&&&&0.64&&&&37142.65&&&&893.9&&&&465.2&&&&0.322&&&&0.0074&&&&1.13&&&&42344.916&&&&1010.9&&&&1098.6&&&&0.127&&&&0.0062&&&&0.58&&&&41300.297&&&&975.9&&&&457.3&&&&0.256&&&&0.0132&&&&1.61&&&&43883.298&&&&954.6&&&&420.7&&&&0.399&&&&0.003&&&&0.92&&&&39171.059&&&&921.6&&&&373.4&&&&0.203&&&&0.0051&&&&1.7&&&&40344.3610&&&&945.1&&&&282.7&&&&0.368&&&&0.0123&&&&0.59&&&&36571.8711&&&&905&&&&509&&&&0.391&&&&0.0151&&&&1.03&&&&42504.6312&&&&941&&&&572.1&&&&0.105&&&&0.0129&&&&1.83&&&&41944.8813&&&&891.3&&&&593.2&&&&0.271&&&&0.003&&&&1.57&&&&42175.6514&&&&965.3&&&&803.9&&&&0.332&&&&0.0079&&&&0.76&&&&41304.9715&&&&1032.4&&&&996.4&&&&0.377&&&&0.0071&&&&1.36&&&&41329.2316&&&&838.6&&&&914.2&&&&0.306&&&&0.0139&&&&1.9&&&&42925.0417&&&&932.7&&&&219.2&&&&0.112&&&&0.0054&&&&0.51&&&&36040.0218&&&&858.4&&&&1020&&&&0.41&&&&0.0045&&&&1.33&&&&38832.8219&&&&1015.9&&&&539.7&&&&0.16&&&&0.0148&&&&1.05&&&&40171.4620&&&&1028.4&&&&780.2&&&&0.193&&&&0.0162&&&&1.75&&&&42564.0721&&&&875.1&&&&744&&&&0.23&&&&0.0111&&&&1.13&&&&40026.3222&&&&882.6&&&&236.1&&&&0.081&&&&0.0087&&&&1.43&&&&39412.4723&&&&852.2&&&&690.9&&&&0.064&&&&0.012&&&&1.2&&&&41157.8924&&&&986.1&&&&1137.6&&&&0.343&&&&0.0037&&&&0.96&&&&43133.8725&&&&1000.7&&&&1116.7&&&&0.142&&&&0.0068&&&&1.49&&&&43078.5926&&&&864.5&&&&1065.4&&&&0.353&&&&0.0103&&&&1.23&&&&42872.9727&&&&928.8&&&&1172.9&&&&0.218&&&&0.0021&&&&1.79&&&&42082.0828&&&&842.5&&&&640.7&&&&0.179&&&&0.016&&&&0.87&&&&41902.0229&&&&872.8&&&&886.1&&&&0.207&&&&0.0112&&&&0.7&&&&41819.3630&&&&1003.5&&&&653.5&&&&0.098&&&&0.0142&&&&1.31&&&&42043.831&&&&906.3&&&&814.1&&&&0.243&&&&0.0101&&&&1.53&&&&43629.89将所有数据提取存入到一个A(31,7)的数组中,然后以A(i,7)(i=1-31)为参考按升序排列,重新获得一个新的A'(31,7)数组,请教各位高手该如何操作?
本帖地址:&
回复列表 (共10个回复)
[专家分:4680]
标题还是容易理解的,文中的表述就让人费解了。do&i=1,31&&read(10,*)&(a(i,j),j=1,7)&&b(i)&=&a(i,k)&!k&为你要的列enddo
[专家分:0]
非常感谢您的回复,我是个Fortran90初学者上面那些数据都是在一个txt文档里&我要做的就是把他们提取出来存在一个二位数组里面,然后要对这个二位数组进行一个换行,换行的依据就是以数组的最后一列为依据,对最后一列数据按从小到大的顺序排列&按排列的顺序进行数组的换行。或者,不知道能否用31个一维数组来做,请高手指点了。谢谢
[专家分:0]
[quote]标题还是容易理解的,文中的表述就让人费解了。do&i=1,31&&read(10,*)&(a(i,j),j=1,7)&&b(i)&=&a(i,k)&!k&为你要的列enddo[/quote]2楼&非常感谢您的回复,我是个Fortran90初学者上面那些数据都是在一个txt文档里&我要做的就是把他们提取出来存在一个二位数组里面,然后要对这个二位数组进行一个换行,换行的依据就是以数组的最后一列为依据,对最后一列数据按从小到大的顺序排列&按排列的顺序进行数组的换行。或者,不知道能否用31个一维数组来做,请高手指点了。谢谢
[专家分:4680]
[quote]非常感谢您的回复,我是个Fortran90初学者上面那些数据都是在一个txt文档里&我要做的就是把他们提取出来存在一个二位数组里面,然后要对这个二位数组进行一个换行,换行的依据就是以数组的最后一列为依据,对最后一列数据按从小到大的顺序排列&按排列的顺序进行数组的换行。或者,不知道能否用31个一维数组来做,请高手指点了。谢谢[/quote]这个简单,如下program&mainimplicit&noneinteger::i,jreal(kind=8),dimension(31,7)::a,tmpopen(10,file='data.txt',status='old')!数据读入do&i=1,31&&read(10,*)&(a(i,j),j=1,7)enddo!数据排序do&i=1,31&&do&j=i+1,31&&&if&(a(i,7)&a(j,7))&then&&&&tmp(j,:)&=&a(j,:)&&&&a(j,:)&=&a(i,:)&&&&&a(i,:)&=tmp(j,:)&&&endif&&enddoenddo!排序后输出do&i=1,31&&write(*,'(7f12.5)')&(a(i,j),j=1,7)enddoend&program
[专家分:16630]
tmp&需要那么大吗?&tmp(7)&足够了吧。
[专家分:4680]
[quote]tmp&需要那么大吗?&tmp(7)&足够了吧。[/quote]31*7不是很大,便于理解就用了和原来一样的形状。
[专家分:4680]
按asymptotic的建议,换成下面的代码也一样实现program&mainimplicit&noneinteger::i,jreal(kind=8),dimension(31,7)::areal(kind=8),dimension(7)::tmpopen(10,file='data.txt',status='old')!数据读入do&i=1,31&&read(10,*)&(a(i,j),j=1,7)enddo!数据排序do&i=1,31&&do&j=i+1,31&&&if&(a(i,7)&a(j,7))&then&&&&tmp(:)&=&a(j,:)&&&&a(j,:)&=&a(i,:)&&&&&a(i,:)&=tmp(:)&&&endif&&enddoenddo!排序后输出do&i=1,31&&write(*,'(7f12.5)')&(a(i,j),j=1,7)enddoend&program
[专家分:0]
[quote]按asymptotic的建议,换成下面的代码也一样实现program&mainimplicit&noneinteger::i,jreal(kind=8),dimension(31,7)::areal(kind=8),dimension(7)::tmpopen(10,file='data.txt',status='old')!数据读入do&i=1,31&&read(10,*)&(a(i,j),j=1,7)enddo!数据排序do&i=1,31&&do&j=i+1,31&&&if&(a(i,7)&a(j,7))&then&&&&tmp(:)&=&a(j,:)&&&&a(j,:)&=&a(i,:)&&&&&a(i,:)&=tmp(:)&&&endif&&enddoenddo!排序后输出do&i=1,31&&write(*,'(7f12.5)')&(a(i,j),j=1,7)enddoend&program[/quote]非常感谢指点&,这还只是我的一个算法的一小部分,后面还有很多需要用程序来写,刚开始学fortran所以很吃力,后面的程序&遇到困难还请您多多指教&不胜感谢啊&。
[专家分:21040]
建议楼主还是赶紧多看书才是:)
[专家分:0]
[quote]建议楼主还是赶紧多看书才是:)[/quote]没办法&毕业前临时换的课题&时间有点紧&只能尽力而为了
您尚未登录,请登录后再回复。

我要回帖

更多关于 fortran 函数输出数组 的文章

 

随机推荐