- 积分
- 224
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-4-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 大气小白 于 2015-5-18 19:54 编辑
楼主大二小白狗,由于Fortran和GASDS课程合并,老师Fortran讲的太浅,不对老师和学校作太多评论,自学中.....
废话不多说,直接上代码
module getdata
implicit none
character(len=79),save::filename
integer,parameter::fileid=10
integer,save::error=0
integer,save::warrning=0
integer,save::i=0,j,k
real,save,allocatable::a(:)
logical,save::alive=0
end module
!contains
subroutine get()
!program get
use getdata
implicit none
real hp
print*,'please enter file name:'
read(*,*)filename
inquire(file=filename,exist=alive)
if(alive)then
open(fileid,file=filename,status='old',iostat=warrning)
if(warrning>0)then
print*,"warrning"
end if
do while(.true.)
read(fileid,*,iostat=error)hp
write(*,"(f9.2)")hp
write(*,*)i
if(error>0)then
print*,"warrning"
end if
if(error/=0)exit
i=i+1
end do
else
write(*,*)"does't exist."
end if
rewind(fileid)
if(allocated(a))deallocate(a)
allocate(a(i))
if(.not.allocated(a))then
write(*,*)"allocate buffer error!"
end if
do j=1,i
read(fileid,*)a(j)
write(*,'(f9.2)')a(j)
end do
return
end subroutine
!end module
以上代码本来想写在一个module里面,作获得数据之用,单独编写的时候完美运行,但在编为一个主程序时就出现了3个ERROR,为解决问题尝试了各种办法,把它直接写成subroutine还是不能调用,一下是主函数部分及错误代码(ps.主函数没有写完,只是为了测试调用功能)
program main
use getdata
implicit none
real,allocatable::dhp(:)
integer::b,c
integer,parameter::station=160
write(*,*)"enter b"
read(*,*)b
do c=1,b
call subroutine get() !!!!此行为61行
allocate(dhp(i))
end do
end program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~错误代码~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
错误 3 error #6460: This is not a field name that is defined in the encompassing structure. [GET] C:\f90\Console1\Console1\getdata.f90 61错误 2 error #6404: This name does not have a type, and must have an explicit type. [SUBROUTINE] C:\f90\Console1\Console1\getdata.f90 61
错误 1 error #5082: Syntax error, found IDENTIFIER 'GET' when expecting one of: ( <END-OF-STATEMENT> ; % [ . C:\f90\Console1\Console1\getdata.f90 61
还请大神们多多指教
|
|