Attachment 'writeasdf.c'

Download

Toggle line numbers
   1 #include <stdlib.h>
   2 #include <stdio.h>
   3 #include "ast.h"
   4 
   5 /* This program shows how to write an AST FrameSet out as ASDF YAML.
   6    Invoke it as follows:
   7 
   8    % writeasdf <yamlfile>
   9 
  10    where <yamlfile> is the path to a new file file to create holding the
  11    ASDF WCS information. The AST FrameSet will be a formed from a simple
  12    FITS-WCS header.
  13 
  14    Notes:
  15 
  16    - The AST library must be configured with libyaml support,
  17    otherwise an error will be reported (by default, AST is configured
  18    with libyaml support if the libyaml library can be found).
  19 
  20    - AST currently does not support the complete ASDF WCS schema. When
  21    writing an AST Object to an ASDF YAML file, the following restrictions
  22    on the AST object apply:
  23 
  24       o  Only Frames, Mappings and FrameSets can be written.
  25       o  Frames must be basic Frames or SkyFrames.
  26       o  The following SkyFrame systems are not supported: GAPPT,
  27          HELIOECLIPTIC, J2000 (note, "J2000" is different to "FK5 J2000"
  28          - "FK5 J2000" is supported), UNKNOWN.
  29       o  Only the following Mapping classes are supported: CmpMap, TranMap,
  30          UnitMap, ZoomMap, ShiftMap, WinMap, MatrixMap, PermMap, WcsMap,
  31          PolyMap, ChebyMap.
  32 
  33 */
  34 
  35 
  36 int main(int argc, char *argv[]){
  37 
  38 /* Local variables: */
  39    AstYamlChan *yamlchan;
  40    AstFitsChan *fitschan;
  41    AstFrameSet *fs;
  42 
  43 /* Check a file name has been supplied. */
  44    if( argc != 2 ) {
  45       printf("Usage:\n   % writeasdf <yamlfile>\n" );
  46       exit( EXIT_FAILURE );
  47    }
  48 
  49 /* Begin an AST Object context. */
  50    astBegin;
  51 
  52 /* Create a FitsChan and store a simple FITS-WCS header in it (a TAN
  53    projection of the north celestial pole). */
  54    fitschan = astFitsChan( NULL, NULL, " " );
  55    astPutFits( fitschan, "CRPIX1  = 0", 0 );
  56    astPutFits( fitschan, "CRPIX2  = 0", 0 );
  57    astPutFits( fitschan, "CDELT1  = 0.0003", 0 );
  58    astPutFits( fitschan, "CDELT2  = 0.0003", 0 );
  59    astPutFits( fitschan, "CTYPE1  = 'RA---TAN'", 0 );
  60    astPutFits( fitschan, "CTYPE2  = 'DEC--TAN'", 0 );
  61    astPutFits( fitschan, "CRVAL1  = 0.0", 0 );
  62    astPutFits( fitschan, "CDELT2  = 90.0", 0 );
  63 
  64 /* Rewind the FitsCHan by clearing its Card attribute, and then read a
  65    FrameSet from it. */
  66    astClear( fitschan, "Card" );
  67    fs = astRead( fitschan );
  68 
  69 /* Create a YamlChan to write the FrameSet to the output YAML file. */
  70    yamlchan = astYamlChan( NULL, NULL, "SinkFile=%s", argv[1] );
  71 
  72 /* Attempt to write the FrameSet to the YamlChan. */
  73    if( astWrite( yamlchan, fs ) != 1 && astOK ) {
  74       printf("Could not write an AST FrameSet as ASDF to file %s.", argv[1] );
  75       exit( EXIT_FAILURE );
  76    }
  77 
  78 /* End the AST Object context. This will automatically annull all AST
  79    Objects created in the context. */
  80    astEnd;
  81 
  82 /* Return a value indicating if an error occurred. */
  83    return astOK ? EXIT_SUCCESS : EXIT_FAILURE;
  84 }
  85 

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.