source: BAORadio/AmasArchive/Amas 21cm/transfert/transfert/Abell85/offset.cc@ 672

Last change on this file since 672 was 672, checked in by campagne, 13 years ago
File size: 3.5 KB
RevLine 
[672]1#include "machdefs.h"
2
3//---- System et stdc++ include files
4#include <stdio.h>
5#include <stdlib.h>
6#include <math.h>
7#include <ctype.h>
8#include <string.h>
9#include <iostream>
10#include <fstream>
11#include <complex>
12
13#include <typeinfo>
14#include <string>
15#include <vector>
16#include <map>
17#include <functional>
18#include <list>
19
20//---- Sophya include files
21#include "sopnamsp.h"
22#include "basetools.h"
23#include "systools.h"
24#include "sutils.h"
25#include "ntools.h"
26#include "array.h"
27#include "histats.h"
28
29//---- Spiapp include files
30#include "nobjmgr.h"
31#include "servnobjm.h"
32
33//---- Include files from additionnal modules
34
35//---- function to compare bits on double
36int_8 BitCmp64(double v,int_8 flg)
37{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}
38
39//---- function for Adding and displaying Objects
40void Keep_Object(AnyDataObj & obj, string const & nom)
41{
42 string name = nom;
43 NamedObjMgr om;
44 if (om.GetObj(name))
45 cerr << "KeepObj()/Warning Already kept object " << endl;
46 else om.AddObj(obj, name);
47}
48
49void Display_Object(AnyDataObj & obj, string const & opt, string const & nom)
50 {
51 string name = nom;
52 NamedObjMgr om;
53 if (!om.GetObj(name))
54 om.AddObj(obj, name);
55 om.DisplayObj(name, opt);
56}
57
58//---- function for getting and setting ObjectManager variables
59void Set_ObjMgrVar(MuTyV v, string const & nom)
60{
61 NamedObjMgr om;
62 om.SetVar(nom, (string)v);
63}
64
65MuTyV Get_ObjMgrVar(const char * nom)
66{
67 string name = nom; NamedObjMgr om;
68 MuTyV v = om.GetVar(name);
69 return v;
70}
71
72//---- Macro for Objects and variables saving
73#define KeepObj(obj) Keep_Object(obj, #obj)
74#define GetOMVar(var) Get_ObjMgrVar( #var )
75#define SetOMVar(var) Set_ObjMgrVar(var, #var )
76
77//---- Macro Displaying objects and command execution
78#define DispObj(obj, att) Display_Object(obj, att, #obj);
79
80#define ExecCmd(cmd) srvo.ExecuteCommand(cmd);
81
82
83
84//-------------------------------------------------//
85//----------------- User Functions ----------------//
86//-------------------------------------------------//
87
88extern "C" {
89 int meanoffset( vector<string>& args );
90}
91
92int meanoffset( vector<string>& args )
93{
94// Some definitions to help using spiapp;
95NamedObjMgr omg;
96Services2NObjMgr& srvo = *omg.GetServiceObj();
97
98//-------------- Object List --------------
99//Number of objects = 1
100string ___nomobj;
101
102___nomobj = "inarr";
103TVector< r_4 > * ___inarr = dynamic_cast< TVector< r_4 > * >(omg.GetObj(___nomobj));
104if(___inarr==NULL) throw NullPtrError("CxxExecutor::PutObject: Non existing object inarr... please update file");
105TVector< r_4 > & inarr = (*___inarr);
106
107
108//--------------------------------------------//
109//----------------- User Code ----------------//
110//--------------------------------------------//
111//#include "/home/bao/tmp/PIATmp_iAIt8R/cxx_spiapp.h"
112//extract from input array 2 bands [fMin1st,fMax1st] U [fMin2nd,fMax2nd]
113
114 sa_size_t fMin1st = (sa_size_t)inarr.NElts()*(atof(args[0].data())-1250.)/250.;
115 sa_size_t fMax1st = (sa_size_t)inarr.NElts()*(atof(args[1].data())-1250.)/250.;
116 sa_size_t fMin2nd = (sa_size_t)inarr.NElts()*(atof(args[2].data())-1250.)/250.;
117 sa_size_t fMax2nd = (sa_size_t)inarr.NElts()*(atof(args[3].data())-1250.)/250.;
118
119
120 TVector<r_4> outarr1(inarr.SubVector(Range(fMin1st,fMax1st)),false);
121 TVector<r_4> outarr2(inarr.SubVector(Range(fMin2nd,fMax2nd)),false);
122
123 r_4 mean1 = outarr1.Sum()/outarr1.NElts();
124 r_4 mean2 = outarr2.Sum()/outarr2.NElts();
125
126 r_4 mean = (mean1+mean2)/2.;
127
128 TVector<r_4> outarr(inarr,false);
129 outarr -= mean;
130
131 KeepObj(outarr);
132
133
134 return 0;
135}
Note: See TracBrowser for help on using the repository browser.