1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1999
27 // Please read the full copyright statement in the file COPYRIGHT_URI.
28 //
29 // Authors:
30 //      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
31 
32 // Implementation for TestFloat32. See TestByte.cc
33 //
34 // 3/22/99 jhrg
35 
36 
37 #include "config.h"
38 
39 #include <math.h>
40 
41 #ifndef WIN32
42 #include <unistd.h>
43 #else
44 #include <io.h>
45 #include <fcntl.h>
46 #include <process.h>
47 #endif
48 
49 #include "TestFloat32.h"
50 #include "debug.h"
51 
52 extern int test_variable_sleep_interval;
53 
54 #if ( defined(__sun__) && ( HOST_SOLARIS < 10 ))
trunc(double x)55 double trunc(double x)
56 {
57        return x < 0 ? -floor(-x) : floor(x);
58 }
59 #endif
60 
61 void
_duplicate(const TestFloat32 & ts)62 TestFloat32::_duplicate(const TestFloat32 &ts)
63 {
64     d_series_values = ts.d_series_values;
65 }
66 
TestFloat32(const string & n)67 TestFloat32::TestFloat32(const string &n) : Float32(n), d_series_values(false)
68 {
69     d_buf = 0.0;
70 }
71 
TestFloat32(const string & n,const string & d)72 TestFloat32::TestFloat32(const string &n, const string &d)
73     : Float32(n, d), d_series_values(false)
74 {
75     d_buf = 0.0;
76 }
77 
TestFloat32(const TestFloat32 & rhs)78 TestFloat32::TestFloat32(const TestFloat32 &rhs) : Float32(rhs), TestCommon(rhs)
79 {
80     _duplicate(rhs);
81 }
82 
83 TestFloat32 &
operator =(const TestFloat32 & rhs)84 TestFloat32::operator=(const TestFloat32 &rhs)
85 {
86     if (this == &rhs)
87 	return *this;
88 
89     dynamic_cast<Float32 &>(*this) = rhs; // run Constructor=
90 
91     _duplicate(rhs);
92 
93     return *this;
94 }
95 
96 BaseType *
ptr_duplicate()97 TestFloat32::ptr_duplicate()
98 {
99     return new TestFloat32(*this); // Copy ctor calls duplicate to do the work
100 }
101 
102 void
output_values(std::ostream & out)103 TestFloat32::output_values(std::ostream &out)
104 {
105     print_val(out, "", false);
106 }
107 
108 bool
read()109 TestFloat32::read()
110 {
111     DBG(cerr << "Entering TestFloat32::read for " << name() << endl);
112     if (read_p())
113 	return true;
114 
115     if (test_variable_sleep_interval > 0)
116 	sleep(test_variable_sleep_interval);
117 
118     if (get_series_values()) {
119         d_buf += 10.0;
120         d_buf = (float)(trunc(10000 * sin(trunc(d_buf))) / 100);
121     }
122     else {
123         d_buf = (float)99.999;
124     }
125 
126     set_read_p(true);
127 
128     DBG(cerr << "In TestFloat32::read, _buf = " << d_buf << endl);
129 
130     return true;
131 }
132