📄 flib.gml
字号:
.ix 'command line'
.ix 'arguments'
The function
.id IARGC
allows an application to determine the number of arguments (including
the program name) used to invoke the program.
The function
.id IGETARG
can be used to retrieve an argument.
.np
Arguments supplied to a program are assigned indices.
Argument zero is the program name, argument one is the first argument,
etc.
The function
.id IGETARG
requires two arguments.
The first argument is the index of the argument to retrieve and is of
type INTEGER.
The second argument is of type CHARACTER and is used to return the
argument.
The size of the argument (number of characters) is returned.
.exam begin
INCLUDE 'FSUBLIB.FI'
CHARACTER*128 ARG
INTEGER ARGC, ARGLEN
ARGC = IARGC()
ARGLEN = IGETARG( 0, ARG )
PRINT *, 'Program name is ', ARG(1:ARGLEN)
DO I = 1, ARGC - 1
ARGLEN = IGETARG( I, ARG )
PRINT '(A, I2, 2A)', 'Argument ', I, ' is ',
1 ARG(1:ARGLEN)
END DO
END
.exam end
.autonote Notes:
.note
The FORTRAN include file :FNAME.fsublib.fi:eFNAME., located in the
:FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory, contains typing
and calling information for this subprogram.
The :FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory should be
included in the
.ev &incvarup
environment variable so that the compiler can locate the include file.
.endnote
.*
.if '&cmpclass' ne 'load-n-go' .do begin
.*
.section Math Error Functions
.*
.np
.ix 'subprograms' 'math error functions'
.ix 'utility subprograms' 'math error functions'
.ix 'math error functions'
Math error functions are called when an error is detected in a math
library function.
For example, if the second argument to the
.id AMOD
intrinsic function is zero, a math error function will be called.
A number of math error functions are defined in the FORTRAN run-time
libraries and perform default actions when an error is detected.
These actions typically produce an error message to the screen.
.np
It is possible to replace the FORTRAN run-time library version of the
math error functions with your own versions.
The file :FNAME._matherr.for:eFNAME located in the
:FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory can be used as a
template for defining your own math error functions.
The following functions represent the set of math error functions.
.autopoint
.point
The function
.id __imath2err
is called for math functions of type INTEGER that take two arguments
of type INTEGER.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the first argument passed to the
math function and the third argument is a pointer to the second
argument passed to the math function.
The error function returns a value that is then used as the return
value for the math function.
.point
The function
.id __amath1err
is called for math functions of type REAL that take one argument of
type REAL.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the argument passed to the math
function.
The error function returns a value that is then used as the return
value for the math function.
.point
The function
.id __amath2err
is called for math functions of type REAL that take two arguments of
type REAL.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the first argument passed to the
math function and the third argument is a pointer to the second
argument passed to the math function.
The error function returns a value that is then used as the return
value for the math function.
.point
The function
.id __math1err
is called for math functions of type DOUBLE PRECISION that take one
argument of type DOUBLE PRECISION.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the argument passed to the math
function.
The error function returns a value that is then used as the return
value for the math function.
.point
The function
.id __math2err
is called for math functions of type DOUBLE PRECISION that take two
arguments of type DOUBLE PRECISION.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the first argument passed to the
math function and the third argument is a pointer to the second
argument passed to the math function.
The error function returns a value that is then used as the return
value for the math function.
.point
The function
.id __zmath2err
is called for math functions of type COMPLEX that take two arguments
of type COMPLEX.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the first argument passed to the
math function and the third argument is a pointer to the second
argument passed to the math function.
The error function returns a value that is then used as the return
value for the math function.
.point
The function
.id __qmath2err
is called for math functions of type DOUBLE COMPLEX that take two
arguments of type DOUBLE COMPLEX.
The first argument represents the error information and is an argument
of type INTEGER that is passed by value.
The second argument is a pointer to the first argument passed to the
math function and the third argument is a pointer to the second
argument passed to the math function.
The error function returns a value that is then used as the return
value for the math function.
.endpoint
.np
The include file :FNAME.mathcode.fi:eFNAME. is included by the file
:FNAME._matherr.for:eFNAME. and is located in the
:FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory.
It defines the information that is contained in the error information
argument that is passed to all math error functions.
.*
.do end
.*
.section INTEGER Function SEEKUNIT
.*
.np
.ix 'subprograms' 'SEEKUNIT function'
.ix 'utility subprograms' 'SEEKUNIT function'
.ix 'SEEKUNIT function'
The INTEGER function
.id SEEKUNIT
permits seeking to a particular byte offset within a file connected
to a FORTRAN unit.
The file must be opened with the following attributes:
.illust begin
FORM='UNFORMATTED'
ACCESS='SEQUENTIAL'
RECORDTYPE='FIXED'
.illust end
.np
The function
.id SEEKUNIT
requires three arguments of type INTEGER, the unit number, the offset
to seek, and the type of positioning to do.
The seek positioning may be absolute (indicated by 0) or relative to
the current position (indicated by 1).
It returns an INTEGER value representing the new offset in the file.
A returned value of -1 indicates that the function call failed.
.np
This function is particularly useful for applications that wish to
change the input/output position for a file connected to a unit.
.np
The following example will set the current input/output position of
the file connected to the specified unit.
.exam begin
EXTERNAL SEEKUNIT
INTEGER SEEKUNIT
INTEGER SEEK_SET, SEEK_CUR
PARAMETER (SEEK_SET=0, SEEK_CUR=1)
INTEGER POSITION
CHARACTER*80 RECORD
OPEN( UNIT=8, FILE='file', FORM='UNFORMATTED',
1 ACCESS='SEQUENTIAL', RECORDTYPE='FIXED' )
POSITION = SEEKUNIT( 8, 10, SEEK_SET )
IF( POSITION .NE. -1 )THEN
PRINT *, 'New position is', POSITION
READ( UNIT=8 ) RECORD
PRINT *, RECORD
ENDIF
END
.exam end
.autonote Notes:
.note
The FORTRAN include file :FNAME.fsublib.fi:eFNAME., located in the
:FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory, contains typing
and calling information for this subprogram.
The :FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory should be
included in the
.ev &incvarup
environment variable so that the compiler can locate the include file.
.note
A value of -1 is returned if the requested positioning cannot be done.
.endnote
.*
.if '&cmpclass' ne 'load-n-go' .do begin
.*
.section INTEGER Function SETJMP/Subroutine LONGJMP
.*
.np
.ix 'subprograms' 'SETJMP function'
.ix 'utility subprograms' 'SETJMP function'
.ix 'SETJMP function'
.ix 'subprograms' 'LONGJMP subroutine'
.ix 'utility subprograms' 'LONGJMP subroutine'
.ix 'LONGJMP subroutine'
The INTEGER function
.id SETJMP
saves the current executing environment, making it possible to restore
that environment by subsequently calling the
.id LONGJMP
subroutine.
For example, it is possible to implement error handling by using
.id SETJMP
to record the point to which a return will occur following an error.
When an error is detected in a called subprogram, that subprogram uses
.id LONGJMP
to jump back to the recorded position.
The original subprogram which called
.id SETJMP
must still be active (it cannot have returned to the subprogram which
called it).
.np
The
.id SETJMP
function requires one argument.
The argument is a structure of type
.id jmp_buf
and is used to save the current environment.
The return value is an integer and is zero when initially called.
It is non-zero if the return is the result of a call to the
.id LONGJMP
subroutine.
An
.KW IF
statement is often used to handle these two cases.
This is demonstrated in the following example.
.exam begin
include 'fsignal.fi'
include 'setjmp.fi'
record /jmp_buf/ jmp_buf
common jmp_buf
external break_handler
integer rc
call fsignal( SIGBREAK, break_handler )
rc = setjmp( jmp_buf )
if( rc .eq. 0 )then
call do_it()
else
print *, 'abnormal termination:', rc
endif
end
subroutine do_it()
loop
end loop
end
subroutine break_handler()
include 'setjmp.fi'
record /jmp_buf/ jmp_buf
common jmp_buf
call longjmp( jmp_buf, -1 )
end
.exam end
.autonote Notes:
.note
The FORTRAN include file :FNAME.setjmp.fi:eFNAME. contains typing and
calling information for
.id SETJMP
and
.id LONGJMP
and must be included.
Similarly, :FNAME.fsignal.fi:eFNAME. must be included when using the
.id FSIGNAL
function.
These files are located in the
:FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory.
The :FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory should be
included in the
.ev &incvarup
environment variable so that the compiler can locate these include
files.
.endnote
.*
.do end
.*
.section INTEGER Function SETSYSHANDLE
.*
.np
.ix 'subprograms' 'SETSYSHANDLE function'
.ix 'utility subprograms' 'SETSYSHANDLE function'
.ix 'SETSYSHANDLE function'
The INTEGER function
.id SETSYSHANDLE
allows an application to set the system file handle for a specified
unit.
.np
The function
.id SETSYSHANDLE
requires an argument of type INTEGER, the unit number,
and an argument of type INTEGER*2, the handle,
and returns an INTEGER value representing the success or fail
status of the function call.
A returned value of -1 indicates that the function call failed
and 0 indicates that the function call succeeded.
.np
This function is particularly useful for applications that wish to
set the system file handle for a unit.
The system file handle may have been obtained from a non-FORTRAN
subroutine or function.
.np
The following example will set the system file handle for a paricular
unit.
.tinyexam begin
INCLUDE 'FSUBLIB.FI'
INTEGER STDIN, STDOUT
PARAMETER (STDIN=0, STDOUT=1)
OPEN( UNIT=8, FORM='FORMATTED' )
I = SYSHANDLE( 8 )
PRINT *, 'Old handle was', I
I = SETSYSHANDLE( 8, STDOUT )
IF( I .EQ. 0 )THEN
WRITE( UNIT=8, FMT=* ) 'Output to UNIT 8 which is stdout'
ENDIF
END
.tinyexam end
.autonote Notes:
.note
The FORTRAN include file :FNAME.fsublib.fi:eFNAME., located in the
:FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory, contains typing
and calling information for this subprogram.
The :FNAME.&pathnam.&pc.src&pc.fortran:eFNAME. directory should be
included in the
.ev &incvarup
environment variable so that the compiler can locate the include file.
.note
A value of -1 is returned if the unit is not connected to a file.
:cmt. Note that an
:cmt. .kw OPEN
:cmt. statement does not actually allocate a system file handle for the
:cmt. file; the first input/output operation will do the allocation.
.note
Units 5 and 6 are preconnected to the standard input and standard
output devices respectively.
.endnote
.*
.section INTEGER*2 Function SYSHANDLE
.*
.np
.ix 'subprograms' 'SYSHANDLE function'
.ix 'utility subprograms' 'SYSHANDLE function'
.ix 'SYSHANDLE function'
The INTEGER*2 function
.id SYSHANDLE
allows an application to obtain the system file handle
for a specified unit.
.np
The function
.id SYSHANDLE
requires one argument of type INTEGER, the unit number.
and returns an INTEGER*2 value representing the system file handle.
.np
This function is particularly useful for applications that wish to pass
the system file handle to non-FORTRAN subroutines or functions that
wish to perform input/output to a FORTRAN 77 file.
.np
The following example will print the system file handles for the
standard input and standard output devices.
.exam begin
INCLUDE 'FSUBLIB.FI'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -