1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | #include "sopnamsp.h"
|
---|
7 | #include "histinit.h"
|
---|
8 | #include "dvlist.h"
|
---|
9 | #include "ntuple.h"
|
---|
10 | #include "fitsntuple.h"
|
---|
11 | #include "fitstarray.h"
|
---|
12 | #include "array.h"
|
---|
13 |
|
---|
14 | int main(int narg, char *arg[])
|
---|
15 | {
|
---|
16 | if (narg < 3) {
|
---|
17 | cout << "obj_fits/Erreur arg - Usage obj_fits r/r2/w/w2 fitsfilename " << endl;
|
---|
18 | cout << " w : Create a FITS file with a matrix and an NTuple " << endl;
|
---|
19 | cout << " r : Read a matrix and an NTuple from a Fits File " << endl;
|
---|
20 | cout << " 2 : Image on secondary header " << endl;
|
---|
21 | exit(1);
|
---|
22 | }
|
---|
23 | try {
|
---|
24 | SophyaInit();
|
---|
25 | string flnm = arg[2];
|
---|
26 | bool imgonph = true;
|
---|
27 | if (*(arg[1]+1) == '2') imgonph = false;
|
---|
28 | if (*arg[1] == 'r') {
|
---|
29 | cout << " obj_fits/Info: Opening input FitsFile " << endl;
|
---|
30 | FitsInFile fiis(flnm);
|
---|
31 | fiis.firstImageOnPrimaryHeader(imgonph);
|
---|
32 |
|
---|
33 | cout << " Reading Matrix m from FITS " << endl;
|
---|
34 | Matrix m;
|
---|
35 | fiis >> m;
|
---|
36 | cout << m << endl;
|
---|
37 |
|
---|
38 | cout << " Reading NTuple from FITS " << endl;
|
---|
39 | NTuple nt;
|
---|
40 | fiis >> nt ;
|
---|
41 | nt.Show();
|
---|
42 | }
|
---|
43 | else {
|
---|
44 | cout << " obj_fits/Info: Opening output FitsFile " << endl;
|
---|
45 | FitsOutFile fios(flnm);
|
---|
46 | fios.firstImageOnPrimaryHeader(imgonph);
|
---|
47 |
|
---|
48 | cout << " Creating Matrix m " << endl;
|
---|
49 | Matrix m(50,70);
|
---|
50 | m = RegularSequence(35., 0.2);
|
---|
51 | m.Info()["SVERSION"] = SophyaVersion();
|
---|
52 | m.Info().SetComment("SVERSIO", "Sophya Version");
|
---|
53 | m.Info()["OBJ_FITS"] = "Test Matrix" ;
|
---|
54 | cout << m << endl;
|
---|
55 |
|
---|
56 | cout << " Writing Matrix m to FITS " << endl;
|
---|
57 | fios << m ;
|
---|
58 |
|
---|
59 | cout << " Creating NTuple " << endl;
|
---|
60 | const char * names[3] = {"XPos", "YPos", "Val"};
|
---|
61 | int i,j, k;
|
---|
62 | float xnt[3];
|
---|
63 |
|
---|
64 | NTuple nt1(3, names, 20);
|
---|
65 |
|
---|
66 | k = 0;
|
---|
67 | for(j=0; j<8; j++)
|
---|
68 | for(i=0; i<12; i++)
|
---|
69 | { xnt[0] = i+0.5; xnt[1] = j+0.5; xnt[2] = k;
|
---|
70 | nt1.Fill(xnt); k++; }
|
---|
71 |
|
---|
72 | nt1.Info().Comment() = "NTuple de Test - Cree par obj_fits.cc";
|
---|
73 | nt1.Info()["Version"] = SophyaVersion();
|
---|
74 | nt1.Show();
|
---|
75 |
|
---|
76 | cout << " Writing NTuple to FITS " << endl;
|
---|
77 | fios << nt1 ;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | catch (PThrowable & exc) {
|
---|
81 | cerr << " Catched Exception " << (string)typeid(exc).name()
|
---|
82 | << " - Msg= " << exc.Msg() << endl;
|
---|
83 | }
|
---|
84 | catch (...) {
|
---|
85 | cerr << " some other exception was caught ! " << endl;
|
---|
86 | }
|
---|
87 |
|
---|
88 | }
|
---|