[ Pobierz całość w formacie PDF ]
does not support directed rounding modes:
integer ieeer
character*1 mode, out, in
ieeer = ieee_flags( 'set', 'direction', 'tozero', out )
FORTRAN 77 Library Routines 353
7
Example 2: Clear rounding direction to default (round toward nearest):
character*1 out, in
ieeer = ieee_flags('clear','direction', in, out )
Example 3: Clear all accrued exception-occurred bits:
character*18 out
ieeer = ieee_flags( 'clear', 'exception', 'all', out )
Example 4: If Example 3 generates the overflow exception, detect it as follows:
character*18 out
ieeer = ieee_flags( 'get', 'exception', 'overflow', out )
The above code setsout tooverflow andieeer to 25. Similar coding detects
exceptions, such as invalid or inexact.
354 FORTRAN 77 Reference Manual
7
Example 5: hand1.f, write and use a signal handler (Solaris 2.x):
external hand
real r / 14.2 /, s / 0.0 /
i = ieee_handler( 'set', 'division', hand )
t = r/s
end
integer function hand ( sig, sip, uap )
integer sig, address
structure /fault/
integer address
end structure
structure /siginfo/
integer si_signo
integer si_code
integer si_errno
record /fault/ fault
end structure
record /siginfo/ sip
address = sip.fault.address
write (*,10) address
10 format('Exception at hex address ', z8 )
end
Read the Numerical Computation Guide. See also: floatingpoint(3),
signal(3), sigfpe(3), f77_floatingpoint(3F), ieee_flags(3M), and
ieee_handler(3M).
7.12 fdate: Return Date and Time in an ASCII String
The subroutine or function:
call fdate( string )
string character*24 Output
FORTRAN 77 Library Routines 355
7
or:
string = fdate() If you use it as a function, the calling
routine must define the type and
Return value character*24 Output
length of fdate.
Example 1: fdate as a subroutine:
character*24 string
call fdate( string )
write(*,*) string
end
Output:
Wed Aug 3 15:30:23 1994
Example 2: fdate as a function, same output:
character*24 fdate
write(*,*) fdate()
end
See also: ctime(3), time(3F), and idate(3F).
7.13 flush: Flush Output to a Logical Unit
The subroutine is:
call flush( lunit )
lunit INTEGER Input Logical unit
The flush subroutine flushes the contents of the buffer for the logical unit,
lunit, to the associated file. This is most useful for logical units 0 and 6 when
they are both associated with the control terminal.
See also fclose(3S).
356 FORTRAN 77 Reference Manual
7
7.14 fork: Create a Copy of the Current Process
The function is:
n = fork()
Return value INTEGER Output n>0: n=Process ID of copy
n
The fork function creates a copy of the calling process. The only distinction
between the two processes is that the value returned to one of them, referred to
as the parent process, will be the process ID of the copy. The copy is usually
referred to as the child process. The value returned to the child process will
be zero.
All logical units open for writing are flushed before the fork to avoid
duplication of the contents of I/O buffers in the external files.
Example: fork():
integer fork, pid
pid = fork()
end
A corresponding exec routine has not been provided because there is no
satisfactory way to retain open logical units across theexec routine. However,
the usual function of fork/exec can be performed using system(3F). See
also: fork(2), wait(3F), kill(3F), system(3F), and perror(3F).
7.15 free: Deallocate Memory Allocated by Malloc
The subroutine is:
call free ( ptr )
ptr pointer Input
free deallocates a region of memory previously allocated by malloc. The
region of memory is returned to the memory manager; it is not explicitly
available to the user s program.
FORTRAN 77 Library Routines 357
7
Example: free():
real x
pointer ( ptr, x )
ptr = malloc ( 10000 )
call free ( ptr )
end
See Section 7.40, malloc: Allocate Memory and Get Address, for details.
7.16 fseek,ftell: Determine Position and Reposition a File
fseek and ftell are routines that permit repositioning of a file. ftell
returns a file s curent position as an offset of so many bytes from the beginning
of the file. At some later point in the program, fseek can use this saved offset
value to reposition the file to that same place for reading.
CAUTION: On sequential files, following a call to fseek by an output
operation (e.g. WRITE) causes all data records following thefseek ed position
to be deleted and replaced by the new data record (and an end-of-file mark).
Rewriting a record in place can only be done with direct access files.
fseek: Reposition a File on a Logical Unit
The function is:
n = fseek( lunit, offset, from )
lunit INTEGER Input Open logical unit
offset INTEGER Input Offset in bytes relative to position specified
by from
from INTEGER Input 0=Beginning of file
1=Current position
2=End of file
Return value INTEGER Output n=0: OK; n>0: System error code
358 FORTRAN 77 Reference Manual
7
Example: fseek() Reposition MyFile to two bytes from the beginning:
integer fseek, lunit/1/, offset/2/, from/0/, n
open( UNIT=lunit, FILE='MyFile' )
n = fseek( lunit, offset, from )
if ( n .gt. 0 ) stop 'fseek error'
end
ftell: Return Current Position of File
The function is:
n = ftell( lunit )
lunit INTEGER Input Open logical unit
Return value INTEGER Input n>=0: n=Offset in bytes from start of file
n
Example: ftell():
integer ftell, lunit/1/, n
open( UNIT=lunit, FILE='MyFile' )
* &
n = ftell( lunit )
if ( n .lt. 0 ) stop 'ftell error'
end
See also fseek(3S) and perror(3F).
FORTRAN 77 Library Routines 359
7
7.17 getarg,iargc: Get Command-line Arguments
gettarg and iargc return command-line arguments.
getarg: Get the kth Command-Line Argument
The subroutine is:
call getarg( k, arg )
k INTEGER Input Index of argument (0=first=command name)
arg character*n Output kth argument
n INTEGER Size of arg Large enough to hold longest argument
iargc: Get the Count of Command-Line Arguments
The function is:
m = iargc()
Return value INTEGER Output Number of arguments on the command line
Example: iargc and getarg, get argument count and each argument:
character argv*10
integer i, iargc, n
n = iargc()
do i = 1, n [ Pobierz całość w formacie PDF ]
zanotowane.pl doc.pisz.pl pdf.pisz.pl freetocraft.keep.pl
does not support directed rounding modes:
integer ieeer
character*1 mode, out, in
ieeer = ieee_flags( 'set', 'direction', 'tozero', out )
FORTRAN 77 Library Routines 353
7
Example 2: Clear rounding direction to default (round toward nearest):
character*1 out, in
ieeer = ieee_flags('clear','direction', in, out )
Example 3: Clear all accrued exception-occurred bits:
character*18 out
ieeer = ieee_flags( 'clear', 'exception', 'all', out )
Example 4: If Example 3 generates the overflow exception, detect it as follows:
character*18 out
ieeer = ieee_flags( 'get', 'exception', 'overflow', out )
The above code setsout tooverflow andieeer to 25. Similar coding detects
exceptions, such as invalid or inexact.
354 FORTRAN 77 Reference Manual
7
Example 5: hand1.f, write and use a signal handler (Solaris 2.x):
external hand
real r / 14.2 /, s / 0.0 /
i = ieee_handler( 'set', 'division', hand )
t = r/s
end
integer function hand ( sig, sip, uap )
integer sig, address
structure /fault/
integer address
end structure
structure /siginfo/
integer si_signo
integer si_code
integer si_errno
record /fault/ fault
end structure
record /siginfo/ sip
address = sip.fault.address
write (*,10) address
10 format('Exception at hex address ', z8 )
end
Read the Numerical Computation Guide. See also: floatingpoint(3),
signal(3), sigfpe(3), f77_floatingpoint(3F), ieee_flags(3M), and
ieee_handler(3M).
7.12 fdate: Return Date and Time in an ASCII String
The subroutine or function:
call fdate( string )
string character*24 Output
FORTRAN 77 Library Routines 355
7
or:
string = fdate() If you use it as a function, the calling
routine must define the type and
Return value character*24 Output
length of fdate.
Example 1: fdate as a subroutine:
character*24 string
call fdate( string )
write(*,*) string
end
Output:
Wed Aug 3 15:30:23 1994
Example 2: fdate as a function, same output:
character*24 fdate
write(*,*) fdate()
end
See also: ctime(3), time(3F), and idate(3F).
7.13 flush: Flush Output to a Logical Unit
The subroutine is:
call flush( lunit )
lunit INTEGER Input Logical unit
The flush subroutine flushes the contents of the buffer for the logical unit,
lunit, to the associated file. This is most useful for logical units 0 and 6 when
they are both associated with the control terminal.
See also fclose(3S).
356 FORTRAN 77 Reference Manual
7
7.14 fork: Create a Copy of the Current Process
The function is:
n = fork()
Return value INTEGER Output n>0: n=Process ID of copy
n
The fork function creates a copy of the calling process. The only distinction
between the two processes is that the value returned to one of them, referred to
as the parent process, will be the process ID of the copy. The copy is usually
referred to as the child process. The value returned to the child process will
be zero.
All logical units open for writing are flushed before the fork to avoid
duplication of the contents of I/O buffers in the external files.
Example: fork():
integer fork, pid
pid = fork()
end
A corresponding exec routine has not been provided because there is no
satisfactory way to retain open logical units across theexec routine. However,
the usual function of fork/exec can be performed using system(3F). See
also: fork(2), wait(3F), kill(3F), system(3F), and perror(3F).
7.15 free: Deallocate Memory Allocated by Malloc
The subroutine is:
call free ( ptr )
ptr pointer Input
free deallocates a region of memory previously allocated by malloc. The
region of memory is returned to the memory manager; it is not explicitly
available to the user s program.
FORTRAN 77 Library Routines 357
7
Example: free():
real x
pointer ( ptr, x )
ptr = malloc ( 10000 )
call free ( ptr )
end
See Section 7.40, malloc: Allocate Memory and Get Address, for details.
7.16 fseek,ftell: Determine Position and Reposition a File
fseek and ftell are routines that permit repositioning of a file. ftell
returns a file s curent position as an offset of so many bytes from the beginning
of the file. At some later point in the program, fseek can use this saved offset
value to reposition the file to that same place for reading.
CAUTION: On sequential files, following a call to fseek by an output
operation (e.g. WRITE) causes all data records following thefseek ed position
to be deleted and replaced by the new data record (and an end-of-file mark).
Rewriting a record in place can only be done with direct access files.
fseek: Reposition a File on a Logical Unit
The function is:
n = fseek( lunit, offset, from )
lunit INTEGER Input Open logical unit
offset INTEGER Input Offset in bytes relative to position specified
by from
from INTEGER Input 0=Beginning of file
1=Current position
2=End of file
Return value INTEGER Output n=0: OK; n>0: System error code
358 FORTRAN 77 Reference Manual
7
Example: fseek() Reposition MyFile to two bytes from the beginning:
integer fseek, lunit/1/, offset/2/, from/0/, n
open( UNIT=lunit, FILE='MyFile' )
n = fseek( lunit, offset, from )
if ( n .gt. 0 ) stop 'fseek error'
end
ftell: Return Current Position of File
The function is:
n = ftell( lunit )
lunit INTEGER Input Open logical unit
Return value INTEGER Input n>=0: n=Offset in bytes from start of file
n
Example: ftell():
integer ftell, lunit/1/, n
open( UNIT=lunit, FILE='MyFile' )
* &
n = ftell( lunit )
if ( n .lt. 0 ) stop 'ftell error'
end
See also fseek(3S) and perror(3F).
FORTRAN 77 Library Routines 359
7
7.17 getarg,iargc: Get Command-line Arguments
gettarg and iargc return command-line arguments.
getarg: Get the kth Command-Line Argument
The subroutine is:
call getarg( k, arg )
k INTEGER Input Index of argument (0=first=command name)
arg character*n Output kth argument
n INTEGER Size of arg Large enough to hold longest argument
iargc: Get the Count of Command-Line Arguments
The function is:
m = iargc()
Return value INTEGER Output Number of arguments on the command line
Example: iargc and getarg, get argument count and each argument:
character argv*10
integer i, iargc, n
n = iargc()
do i = 1, n [ Pobierz całość w formacie PDF ]