source: trunk/src/MathUtils.cc@ 165

Last change on this file since 165 was 137, checked in by kil064, 20 years ago

split MathUtils::hanning function into MathUtils2.cc as the
new MU::statistics function is not templated

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1//#---------------------------------------------------------------------------
2//# MathUtilities.cc: General math operations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# ATNF
6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31
32#include <casa/aips.h>
33#include <casa/Arrays/MaskedArray.h>
34#include <casa/Arrays/MaskArrMath.h>
35#include <casa/BasicSL/String.h>
36
37#include "MathUtils.h"
38
39using namespace casa;
40//using namespace asap;
41
42
43
44float mathutil::statistics (const std::string& which, const MaskedArray<Float>& data)
45{
46 String str(which);
47 str.upcase();
48 if (str.contains(String("MIN"))) {
49 return min(data);
50 } else if (str.contains(String("MAX"))) {
51 return max(data);
52 } else if (str.contains(String("SUMSQ"))) {
53 return sumsquares(data);
54 } else if (str.contains(String("SUM"))) {
55 return sum(data);
56 } else if (str.contains(String("MEAN"))) {
57 return mean(data);
58 } else if (str.contains(String("VAR"))) {
59 return variance(data);
60 } else if (str.contains(String("STDDEV"))) {
61 return stddev(data);
62 } else if (str.contains(String("AVDEV"))) {
63 return avdev(data);
64 } else if (str.contains(String("RMS"))) {
65 uInt n = data.nelementsValid();
66 return sqrt(sumsquares(data)/n);
67 } else if (str.contains(String("MED"))) {
68 return median(data);
69 }
70}
71
Note: See TracBrowser for help on using the repository browser.