In addition to writing out coordinate values generated by your program
(), you may also need to accept
coordinates entered by a user, or perhaps read from a file. In this
case, you will probably want to allow ``free-format'' input, so that
the user has some flexibility in the format that can be used. You will
probably also want to detect any typing errors.
Let's assume that you want to read a number of lines of text, each
containing the world coordinates of a single point, and to split each
line into individual numerical coordinate values. Using the FrameSet
pointer WCSINFO obtained earlier (), you could
proceed as follows:
CHARACTER TEXT * ( 80 )
DOUBLE PRECISION COORD( 10 )
INTEGER IAXIS, N, NAXES, T
...
* Obtain the number of coordinate axes (if not already known).
NAXES = AST_GETI( WCSINFO, 'Naxes', STATUS )
* Loop to read each line of input text, in this case from the
* standard input channel (your programming environment will probably
* provide a better way of reading text than this). Set the index T to
* the start of each line read.
2 CONTINUE
READ( *, '(A)', END=99 ) TEXT
T = 1
* Attempt to read a coordinate for each axis.
DO 3 IAXIS = 1, NAXES
N = AST_UNFORMAT( WCSINFO, IAXIS, TEXT( T : ), COORD( IAXIS ),
: STATUS )
* If nothing was read and this is not the first axis and the end of
* the text has not been reached, try stepping over a separator and
* reading again.
IF ( ( N .EQ. 0 ) .AND. ( IAXIS .GT. 1 ) .AND.
: ( T .LT. LEN( STRING ) ) ) THEN
T = T + 1
N = AST_UNFORMAT( WCSINFO, IAXIS, TEXT( T : ),
COORD( IAXIS ), STATUS )
END IF
* Quit if nothing was read, otherwise move on to the next coordinate.
IF ( N .EQ. 0 ) GO TO 4
T = T + N
3 CONTINUE
4 CONTINUE
* Test for the possible errors that may occur...
* Error detected by AST (a message will have been issued).
IF ( STATUS .NE. 0 ) THEN
GO TO 99
* Error in input data at character TEXT( T + N : T + N ).
ELSE IF ( ( T .LT. LEN( STRING ) ) .OR. ( N .EQ. 0 ) ) THEN
<handle the error, or report your own message here>
GO TO 99
ELSE
<coordinates were read OK>
END IF
* Return to read the next input line.
GO TO 2
99 CONTINUE
This algorithm has the advantage of accepting free-format input in whatever style is appropriate for the world coordinates in use (under the control of the FrameSet whose pointer you provide). For example, wavelength values might be read as floating point numbers (e.g. ``1.047'' or ``4787''), whereas celestial positions could be given in sexagesimal format (e.g. ``12:34:56'' or ``12 34.5'') and would be converted into radians. Individual coordinate values may be separated by white space and/or any non-ambiguous separator character, such as a comma.
For more information on reading coordinate values using the
AST_UNFORMAT function, see . For
details of how sexagesimal formats are handled, and the forms of input
that may be used for for celestial coordinates, see
.
AST A Library for Handling World Coordinate Systems in Astronomy