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.- [get | view] (2009-09-24 10:49:44, 501.2 KB) [[attachment:adass-2007.pdf]]
- [get | view] (2009-10-27 14:29:15, 709.4 KB) [[attachment:adass2009.pdf]]
- [get | view] (2011-11-22 16:37:35, 1053.8 KB) [[attachment:adass2011.pdf]]
- [get | view] (2009-09-24 10:56:59, 11508.3 KB) [[attachment:ast-5.2-0.tar.gz]]
- [get | view] (2009-10-30 13:30:20, 11553.7 KB) [[attachment:ast-5.3-1.tar.gz]]
- [get | view] (2011-04-05 12:39:19, 11994.6 KB) [[attachment:ast-5.6-0.tar.gz]]
- [get | view] (2011-05-24 14:49:42, 12040.2 KB) [[attachment:ast-5.7-0.tar.gz]]
- [get | view] (2011-06-07 20:58:18, 12075.5 KB) [[attachment:ast-5.7-1.tar.gz]]
- [get | view] (2011-07-18 18:52:08, 12141.4 KB) [[attachment:ast-5.7-2.tar.gz]]
- [get | view] (2011-11-22 16:40:11, 12192.1 KB) [[attachment:ast-6.0-1.tar.gz]]
- [get | view] (2011-10-31 11:00:18, 12189.3 KB) [[attachment:ast-6.0.tar.gz]]
- [get | view] (2011-11-22 16:37:59, 31.7 KB) [[attachment:ast.news]]
- [get | view] (2020-09-15 16:09:39, 4.7 KB) [[attachment:example.asdf]]
- [get | view] (2009-09-24 09:34:46, 3.1 KB) [[attachment:img1.gif]]
- [get | view] (2009-09-24 09:35:03, 3.3 KB) [[attachment:img2.gif]]
- [get | view] (2009-09-24 09:35:22, 3.2 KB) [[attachment:img3.gif]]
- [get | view] (2020-09-15 16:09:08, 4.1 KB) [[attachment:readasdf.c]]
- [get | view] (2009-09-25 16:24:18, 10.0 KB) [[attachment:stcschan-demo1.c]]
- [get | view] (2009-09-25 16:24:47, 8.7 KB) [[attachment:stcschan-demo2.c]]
- [get | view] (2009-09-25 16:25:12, 15.9 KB) [[attachment:stcschan-demo3.c]]
- [get | view] (2009-09-25 16:25:41, 8.5 KB) [[attachment:stcschan-demo4.c]]
- [get | view] (2009-09-25 16:26:06, 10.4 KB) [[attachment:stcschan-demo5.c]]
- [get | view] (2022-05-06 10:57:56, 2800.5 KB) [[attachment:sun210.pdf]]
- [get | view] (2022-05-06 10:58:45, 2804.1 KB) [[attachment:sun211.pdf]]
- [get | view] (2020-09-15 16:28:09, 2.8 KB) [[attachment:writeasdf.c]]
You are not allowed to attach a file to this page.