Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

The scope of a file descriptor
Is the scope of a file descriptor limited to the subroutine/function
where the file is opened, or can it be passed as an argument to another
subroutine? I.e., is it possible to open a file in the main part of a
program and write/read the file from some subroutine? I'm looking for a
Fortran equivalent of doing the following in C++:

void some_output (fstream& fout, int x)
{
fout << x;
}

int main ()
{
fstream afile ("somefile.txt", ios::out);
some_output (afile, 5);
afile.close();
}


Report this thread to moderator Post Follow-up to this message
Old Post
s8ngsu3@yahoo.com
12-28-04 02:12 PM


Re: The scope of a file descriptor
s8ngsu3@yahoo.com wrote:
>
> Is the scope of a file descriptor limited to the subroutine/function
> where the file is opened, or can it be passed as an argument to another
> subroutine? I.e., is it possible to open a file in the main part of a
> program and write/read the file from some subroutine? I'm looking for a
> Fortran equivalent of doing the following in C++:
>
> void some_output (fstream& fout, int x)
> {
> fout << x;
> }
>
> int main ()
> {
> fstream afile ("somefile.txt", ios::out);
> some_output (afile, 5);
>     afile.close();
> }

Fortran does not use file descriptors: files in Fortran programs
are opened to a particular logical unit number, simply an integer
value. This is _global_ to the whole program and as long as you
do not close the file (using that same integer value) or open
another file using that same value, the connection remains.

Safe values for the LU number are (generally speaking) between
10 and 99.

The above could read:

subroutine some_output( luout, x )
integer :: luout, x

write(luout,*) x
end subroutine

program myprogram
integer :: luout

luout = 10
open( luout, 'somefile.txt' )
call some_output( luout, 5 )

close( luout )
end program

You do not need to use a variable, but it helps keeping
the code clean :)

You can use the INQUIRE statement to find out what if any
file a LU number is connected to and other properties.

Regards,

Arjen

Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
12-28-04 02:12 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:22 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.