ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cifstrem.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  *
7  * ADModelbuilder and associated libraries and documentations are
8  * provided under the general terms of the "BSD" license.
9  *
10  * License:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * 3. Neither the name of the University of California, Otter Research,
24  * nor the ADMB Foundation nor the names of its contributors may be used
25  * to endorse or promote products derived from this software without
26  * specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
46 #ifndef CIFSTREM_H
47 #define CIFSTREM_H
48 
49 #include <fvar.hpp>
50 
51 #if defined(__GNUC__) && (__GNUC__ < 3)
52  #pragma interface
53 #endif
54 
55 #include <stdio.h>
56 
57 #ifdef __WAT32__
58  #include <iostream.h>
59  #include <strstrea.h>
60 #endif
61 #ifdef __BCPLUSPLUS__
62  #include <strstrea.h>
63 #endif
64 #ifdef __ZTC__
65  #include <iomanip.hpp>
66  #include <strstrea.hpp>
67 #endif
68 #ifdef __NDPX__
69  #include <sstream.h>
70  extern "C" {
71  #include <dos.h>
72  }
73 #endif
74 #if defined(__GNUC__)
75  #if (__GNUC__ < 3)
76  #include <strstream.h>
77  #else
78  #include <sstream>
79  #endif
80 #endif
81 
82 #include <ctype.h>
83 #include <stdlib.h>
84 #include <string.h>
85 #include <adstring.hpp>
86 
87 #ifndef FVAR_HPP
88  class dvar_vector;
89  class dvector;
90  class svector;
91  class ivector;
92  class lvector;
93  class dvar_matrix;
94  class d3_array;
95  class d4_array;
96  class dvar3_array;
97  class dvar4_array;
98  class s3_array;
99  class dmatrix;
100  class smatrix;
101  class imatrix;
102  class lmatrix;
103  class prevariable;
104  class dvariable;
105 #endif
106 
107 #ifndef DOUBLE
108  class svector;
109  class smatrix;
110  class s3_array;
111 #endif
112 
113 
114 #define FILTER_BUF_SIZE 8000
115 #define SIGNATURE_LENGTH 80
116 
117 class cifstream : public ifstream
118 {
119  streambuf* bp;
124  int line;
125  int field;
127 
128  void get_field(char * s,int space_flag=0);
129  void report_error(const char* s = NULL);
130  void set_eof_bit(void);
131 
132 public:
133 #ifdef __BCPLUSPLUS__
134  cifstream() : ifstream() { ; }
135 #endif
136 #ifdef __NDPX__
137  cifstream() : ifstream() { ; }
138 #endif
139 #ifdef __ZTC__
140  cifstream() : ios(&buffer), ifstream() { ; }
141 #endif
142 
143 #if defined(__BORLANDC__)
144  #if (__BORLANDC__ > 0x0520)
145  cifstream(const char*, int=0 , char cc = '#');
146  #else
147  cifstream(const char*, int = ios::nocreate, char cc = '#');
148  #endif
149 #else
150  #if defined(__GNUC__) && (__GNUC__ < 3)
151  cifstream(const char*, int = ios::nocreate, char cc = '#');
152  #else
153  cifstream(const char*, int = std::ios_base::in , char cc = '#');
154  #endif
155 #endif
156 
157  virtual ~cifstream();
158 
159 #if defined(__BORLANDC__)
160 # if (__BORLANDC__ > 0x0520)
161  void open(const char*, int );
162 # else
163  void open(const char*, int = ios::nocreate);
164 # endif
165 #else // not BORLAND
166  #if defined(__GNUC__) && (__GNUC__ < 3)
167  void open(const char*, int = ios::nocreate);
168  #else
169  void open(const char*, int);
170  #endif
171 #endif
172 
173  void filter();
174 
175  adstring get_file_name(void);
177  char* comment() { return comment_line; }
178 #ifdef DEBUG
179  char* get_signature() { return &signature_line[0]; }
181 #endif
182  char* signature();
183 
184  cifstream& operator>>(const dvariable& z);
185  // cifstream& operator>>(const prevariable& z);
186  cifstream& operator>>(long long& i);
187  cifstream& operator>>(const long long& i);
188  cifstream& operator>>(const long& i);
189  cifstream& operator>>(const int& i);
190  cifstream& operator>>(const double& x);
191  cifstream& operator>>(const float& x);
192  cifstream& operator>>(char* x);
193  cifstream& operator>>(const char* x);
194  cifstream& operator>>(const adstring& x);
198  cifstream& getline(char*, int, char = '\n');
199 
200  cifstream& operator>>(const dvar_vector& z);
201  cifstream& operator>>(const dvector& z);
202  //cifstream& operator>>(svector& z);
203  cifstream& operator>>(const lvector& z);
204  cifstream& operator>>(const ivector& z);
205 
207  void set_use_eof() {ignore_eof = 1;}
208 };
209 
210 cifstream& operator>>(cifstream& istr, const prevariable& z);
211 cifstream& operator>>(cifstream& istr, const dvar_matrix& z);
212 cifstream& operator>>(cifstream& istr, const dvar3_array& z);
213 cifstream& operator>>(cifstream& istr, const dvar4_array& z);
214 cifstream& operator>>(cifstream& istr, const dvar5_array& z);
215 cifstream& operator>>(cifstream& istr, const dmatrix& z);
216 cifstream& operator>>(cifstream& istr, const d3_array& z);
217 cifstream& operator>>(cifstream& istr, const d4_array& z);
218 cifstream& operator>>(cifstream& istr, const d5_array& z);
219 cifstream& operator>>(cifstream& istr, const d6_array& z);
220 cifstream& operator>>(cifstream& istr, const d7_array& z);
221 //cifstream& operator>>(cifstream& istr, s3_array& z);
222 //cifstream& operator>>(cifstream& istr,smatrix& z);
223 cifstream& operator>>(cifstream& istr, const imatrix& z);
224 cifstream& operator>>(cifstream& istr, const i3_array& z);
225 cifstream& operator>>(cifstream& istr, const i4_array& z);
226 cifstream& operator>>(cifstream& istr, const i5_array& z);
227 //cifstream& operator>>(cifstream& istr, lmatrix& z);
228 
229 #endif //#define CIFSTREM_H
Base class for dvariable.
Definition: fvar.hpp:1315
Description not yet available.
Definition: fvar.hpp:7054
virtual ~cifstream()
Destructor.
Definition: cifstrem.cpp:27
Description not yet available.
Definition: imatrix.h:69
Description not yet available.
Definition: fvar.hpp:5433
#define x
char comment_line[SIGNATURE_LENGTH+1]
Definition: cifstrem.h:121
cifstream(const char *, int=std::ios_base::in, char cc= '#')
Definition: cifstrem.cpp:86
Vector of double precision numbers.
Definition: dvector.h:50
char * signature()
Get the signature line of inputfile.
Definition: cifstrem.cpp:44
int line
Definition: cifstrem.h:124
void get_field(char *s, int space_flag=0)
Extract a single field into s from data file.
Definition: cifstrem.cpp:171
Description not yet available.
Definition: fvar.hpp:656
void set_eof_bit(void)
Definition: cifstrem.cpp:30
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: fvar.hpp:6673
cifstream & operator>>(const dvariable &z)
Reads input into var from comment formatted input file.
Definition: dfadcif.cpp:25
Description not yet available.
Definition: fvar.hpp:5769
Description not yet available.
Definition: fvar.hpp:7500
Description not yet available.
Definition: fvar.hpp:5161
void set_ignore_eof()
Definition: cifstrem.h:206
cifstream & getline(char *, int, char= '\n')
Definition: cifstrem.cpp:473
void filter()
Move file pointer past comments and empty lines to next data field.
Definition: cifstrem.cpp:124
#define SIGNATURE_LENGTH
Definition: cifstrem.h:115
char * comment()
Returns the last comment line.
Definition: cifstrem.h:177
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
Description not yet available.
Definition: fvar.hpp:6498
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
int field
Definition: cifstrem.h:125
void set_use_eof()
Definition: cifstrem.h:207
Description not yet available.
Definition: fvar.hpp:2819
Description not yet available.
Definition: fvar.hpp:4197
adstring get_file_name(void)
Definition: cifstrem.cpp:81
istream & operator>>(const istream &input, const d3_array &arr3)
Read values from input stream into arr3.
Definition: d3_io.cpp:60
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
Description not yet available.
Definition: fvar.hpp:6067
Description not yet available.
Definition: fvar.hpp:6331
streambuf * bp
Definition: cifstrem.h:119
void report_error(const char *s=NULL)
Definition: cifstrem.cpp:519
Description not yet available.
Definition: fvar.hpp:3944
Description not yet available.
Definition: fvar.hpp:3727
adstring file_name
Definition: cifstrem.h:123
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
static double cc
Definition: cnorlogmix.cpp:13
void open(const char *, int)
char COMMENT_CHAR
Definition: cifstrem.h:120
int ignore_eof
Definition: cifstrem.h:126
char signature_line[SIGNATURE_LENGTH+1]
Definition: cifstrem.h:122