Attachment 'readasdf.c'

Download

Toggle line numbers
   1 #include <stdlib.h>
   2 #include <stdio.h>
   3 #include "ast.h"
   4 
   5 /* This program shows how to create an AST FrameSet from WCS information
   6    stored in ASDF format in an external YAML file. Invoke it as follows:
   7 
   8    % readasdf <yamlfile>
   9 
  10    where <yamlfile> is the path to an existing file holding the ASDF
  11    WCS information. An AST FrameSet will be created from the ASDF (if
  12    possible) and one or two simple operations permformed using the
  13    FrameSet. The results of these operations will be displayed.
  14 
  15    Notes:
  16 
  17    - The AST library must be configured with libyaml support,
  18    otherwise an error will be reported (by default, AST is configured
  19    with libyaml support if the libyaml library can be found).
  20 
  21    - The AST library must be configured with libyaml support,
  22    otherwise an error will be reported (by default, AST is configured
  23    with libyaml support if the libyaml library can be found).
  24 
  25    - AST currently does not support the complete ASDF WCS schema. When
  26    reading an AST Object from an ASDF YAML file, the following restrictions
  27    to the ASDF file apply:
  28 
  29       o  The ASDF spectral_frame, temporal_frame and composite_frame
  30       classes are not supported.
  31       o  Only the following celestial coordinate frames are supported:
  32       icrs, fk4, fk4noeterms, fk5, galactic, supergalactic, altaz,
  33       barycentricmeanecliptic.
  34       o  Earth locations must be specified using the WGS84 ellipsoid.
  35       o  Times must be specified in one of the following formats: iso,
  36       byear, jyear, jd, mjd.
  37       o  Only the following transform classes are supported:
  38       identity, scale, multiplyscale, remap_axes, shift, compose,
  39       concatenate, constant, fix_inputs, affine, rotate2d,
  40       rotate_sequence_3d, rotate3d, linear1d, ortho_polynomial
  41       (chebyshev only), planar2d, polynomial. In addition, all sky
  42       projections are supported.
  43 
  44 */
  45 
  46 
  47 int main(int argc, char *argv[]){
  48 
  49 /* Local variables: */
  50    AstYamlChan *channel;
  51    AstObject *obj;
  52    double xin, yin, aout, bout;
  53 
  54 /* Check a file name has been supplied. */
  55    if( argc != 2 ) {
  56       printf("Usage:\n   % readasdf <yamlfile>\n" );
  57       exit( EXIT_FAILURE );
  58    }
  59 
  60 /* Begin an AST Object context. */
  61    astBegin;
  62 
  63 /* Create a YamlChan to read WCS information from the supplied file. */
  64    channel = astYamlChan( NULL, NULL, "SourceFile=%s", argv[1] );
  65 
  66 /* Attempt to read an AST object from the channel. */
  67    obj = astRead( channel );
  68 
  69 /* Exit if an AST object could not be created from the contents of the
  70    file. */
  71    if( !obj && astOK ) {
  72       printf("Could not read an AST object from file %s.", argv[1] );
  73       exit( EXIT_FAILURE );
  74    }
  75 
  76 /* Display the class of AST object that was read from the file. */
  77    printf( "An AST %s was read from file %s.\n", astGetC( obj, "Class" ),
  78            argv[1] );
  79 
  80 /* If it is a FrameSet, display the name of the current and base coordinate
  81    systems (inverting a FrameSet swaps the base and current Frames). */
  82    if( astIsAFrameSet( obj ) ){
  83       printf( "Current Frame is %d-dimensional and describes %s %s "
  84               "coordinates.\n", astGetI( obj, "Naxes" ),
  85               astGetC( obj, "System" ), astGetC( obj, "Domain" ) );
  86 
  87       astInvert( obj );
  88       printf( "Base Frame is %d-dimensional and describes %s %s "
  89               "coordinates.\n", astGetI( obj, "Naxes" ),
  90               astGetC( obj, "System" ), astGetC( obj, "Domain" ) );
  91       astInvert( obj );
  92 
  93 /* If both Frames are 2-dimensional, display the current frame coordinates
  94    corresponding to base frame coordinates (0,0). */
  95       if( astGetI( obj, "Nin" ) == 2 && astGetI( obj, "Nout" ) == 2 ) {
  96          xin = 0.0;
  97          yin = 0.0;
  98          astTran2( obj, 1, &xin, &yin, 1, &aout, &bout );
  99 
 100          printf("Base Frame position (0,0) gives %s=%s and %s=%s\n",
 101                 astGetC( obj, "Symbol(1)" ), astFormat( obj, 1, aout ),
 102                 astGetC( obj, "Symbol(2)" ), astFormat( obj, 2, aout ) );
 103       }
 104    }
 105 
 106 /* End the AST Object context. This will automatically annull all AST
 107    Objects created in the context. */
 108    astEnd;
 109 
 110 /* Return a value indicating if an error occurred. */
 111    return astOK ? EXIT_SUCCESS : EXIT_FAILURE;
 112 }
 113 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.