Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: open file i...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 8165 of 8773
Post > Topic >>

Re: open file in subroutine

by blitheli <blitheli@[EMAIL PROTECTED] > Apr 23, 2008 at 06:03 AM

On 4=D4=C223=C8=D5, =CF=C2=CE=E74=CA=B155=B7=D6, wangning16...@[EMAIL PROTECTED]
> I had already produce an open file with data in the main program, but
> I want to use the data in the file in the subroutine. However,it seems
> didn't use when I call it. I don't know what's wrong,please help me!
> Thank you very much!
>
> subroutine get_trio
>
>  .......
>
>    open(111, file=3D"surf_111_3.dat")
>    open(112, file=3D"random.dat")
>
>    do i=3D1,200
>       read (111,*) k, posx(i),
> posy(i)
>    end do
>
>    read(111,*) a
>    do i =3D1, 25
>       write (112,"(25( i3,f6.1,f6.1))") a(i), posx(a(i)), posy(a(i))
>    end do
>
>   .......
>    do i =3D 1, n
>       do j =3D i + 1, n
>         rxij =3D posx(a(i)) - posx(a(j))
>         if (abs(rxij) .gt. l/2)  then
>         rxij =3D l - abs(rxij)
>         end if
>         ryij =3D posy(a(i)) - posy(a(j))
>         if (abs(ryij) .gt. l/2)  then
>         ryij =3D l - abs(ryij)
>         end if
>         disij =3D sqrt(rxij**2 + ryij**2)
> ......
> It said that a scalar-valued expression is required in this context.

I think it is better to write like this:

Module Constants
implicit none
public

integer,parameter:: file_handle=3D11,file_handle2=3D12  ! you can add more
parameter file handle here

character(len=3D*), parameter :: file_name, file_name2  ! you can add
more parameter names here

End module Constants

!------------------------

program main
implicit none
=2E...

open(unit=3Dfile_handle,file=3Dfile_name)
open(unit=3Dfile_handle2,file=3Dfile_name2)
=2E..
call subr()
=2E..
close(file_handle)
close(file_handle2)
end
!--------------------
subroutine subr(a,b,...)
implicit none
=2E..
=2E..
write(unit=3Dfile_handle,fmt=3D...)a,b.....
=2E...
End subroutine subr
 




 5 Posts in Topic:
open file in subroutine
wangning16934@[EMAIL PROT  2008-04-23 01:55:22 
Re: open file in subroutine
Klaus Wacker <wacker@[  2008-04-23 09:37:03 
Re: open file in subroutine
Dick Hendrickson <dick  2008-04-23 13:06:09 
Re: open file in subroutine
blitheli <blitheli@[EM  2008-04-23 06:03:35 
Re: open file in subroutine
Terence <tbwright@[EMA  2008-04-23 22:24:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 14:09:58 CDT 2008.