We can also write a SINK routine, that obtains a line of output text
from the AST library by calling AST_GETLINE and then writes it to a
file. We can use this in basically the same way as the SOURCE routine
in the previous section ():
SUBROUTINE SINK( STATUS ) INTEGER L, STATUS CHARACTER * ( 200 ) BUFFER CALL AST_GETLINE( BUFFER, L, STATUS ) IF ( L .GT. 0 ) WRITE( 2, '(A)' ) BUFFER( : L ) END
In this case, our main program would supply the name of this SINK routine as the second argument to AST_CHANNEL (ensuring that it also appears in an EXTERNAL statement), as follows:
EXTERNAL SINK ... * Open the output file. OPEN( UNIT = 2, FILE = 'outfile.ast', STATUS = 'NEW' ) * Create a Channel and write an Object to it. CHANNEL = AST_CHANNEL( SOURCE, SINK, ' ', STATUS ) NOBJ = AST_WRITE( CHANNEL, OBJECT, STATUS ) ... * Annul the Channel and close the file when done. CALL AST_ANNUL( CHANNEL, STATUS ) CLOSE( 2 )
Note that we can specify a source and/or a sink routine for the Channel, and that these may use either the same file, or different files according to whether we are reading or writing. AST has no knowledge of the underlying file system, nor of file positioning. It just reads and writes sequentially. If you wish, for example, to reposition a file at the beginning in between reads and writes, then this can be done directly (and completely independently of AST) using standard Fortran statements.
If an error occurs in your source or sink routine, you can communicate
this to the AST library by setting the STATUS argument to any error
value. This will immediately terminate the read or write operation.
AST A Library for Handling World Coordinate Systems in Astronomy