nidas v1.2.3
CalFile.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2006, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_CORE_CALFILE_H
28#define NIDAS_CORE_CALFILE_H
29
30#include "DOMable.h"
31#include <nidas/util/UTime.h>
34
35#include <vector>
36#include <fstream>
37
38#include <regex.h>
39
40namespace nidas { namespace core {
41
42class DSMSensor;
43
167public:
168
169 CalFile();
170
176 CalFile(const CalFile&);
177
183 CalFile& operator=(const CalFile&);
184
188 ~CalFile();
189
190 const std::string& getFile() const;
191
195 void setFile(const std::string& val);
196
202 const std::string& getPath() const;
203
209 void setPath(const std::string& val);
210
215 static std::vector<std::string> getAllPaths()
216 {
217 _staticMutex.lock();
218 std::vector<std::string> tmp = _allPaths;
219 _staticMutex.unlock();
220 return tmp;
221 }
222
226 const std::string& getCurrentFileName() const
227 {
228 if (_include) return _include->getCurrentFileName();
229 return _currentFileName;
230 }
231
237 void setName(const std::string& val)
238 {
239 _name = val;
240 }
241
242 const std::string& getName() const
243 {
244 return _name;
245 }
246
247 int getLineNumber() const
248 {
249 if (_include) return _include->getLineNumber();
250 return _nline;
251 }
252
260 void open();
261
266 void close() throw();
267
271 bool eof() const {
272 if (_include) return false;
273 return _eofState;
274 }
275
276 const std::string& getTimeZone() const { return _timeZone; }
277
283 void
284 setTimeZone(const std::string& val);
285
286 const std::string& getDateTimeFormat() const
287 {
288 return _dateTimeFormat;
289 }
290
296 void setDateTimeFormat(const std::string& val);
297
308
355 int readCF(nidas::util::UTime& time, float* data, int ndata,
356 std::vector<std::string>* fields=0);
357
364 const std::vector<std::string>&
366
369 {
370 return _currentTime;
371 }
372
381 float
382 getFloatField(int column, const std::vector<std::string>* fields = 0);
383
400 int
401 getFields(int begin, int end, float* data,
402 const std::vector<std::string>* fields = 0);
403
404 /*
405 * Return the value of the next time in the file.
406 * If there is no next record in the file, the returned value
407 * will be far off in the future.
408 */
410 {
411 return _nextTime;
412 }
413
420 void setDSMSensor(const DSMSensor* val);
421
422 const DSMSensor* getDSMSensor() const;
423
427 void fromDOMElement(const xercesc::DOMElement* node);
428
429protected:
430
435
448 void readLine();
449
456 bool
458
465 int
466 parseInclude();
467
471 void openInclude(const std::string& name);
472
478 int
479 readCFInclude(nidas::util::UTime& time, float* data, int ndata,
480 std::vector<std::string>* fields_out);
481
482
483private:
484
498
503 int readCFNoLock(nidas::util::UTime& time, float* data, int ndata,
504 std::vector<std::string>* fields);
505
506 std::string _name;
507
508 std::string _fileName;
509
510 std::string _path;
511
512 std::string _currentFileName;
513
514 std::string _timeZone;
515
517
518 std::string _dateTimeFormat;
519
520 std::ifstream _fin;
521
522 static const int INITIAL_CURLINE_LENGTH = 128;
523
525
526 char *_curline;
527
529
531
533
535
537 std::vector<std::string> _currentFields;
538
543
548
553
555
557
559
560 static int _reUsers;
561
562 static bool _reCompiled;
563
564 static regex_t _dateFormatPreg;
565
566 static regex_t _timeZonePreg;
567
568 static regex_t _includePreg;
569
570 static void freeREs();
571
575 static void compileREs();
576
577 static std::vector<std::string> _allPaths;
578
580};
581
582}} // namespace nidas namespace core
583
584#endif
A class for reading ASCII files containing a time series of calibration data.
Definition CalFile.h:166
void setName(const std::string &val)
An instance of CalFile can have a name.
Definition CalFile.h:237
void close()
Close file.
Definition CalFile.cc:303
int getLineNumber() const
Definition CalFile.h:247
const std::string & getCurrentFileName() const
Return the full file path of the current file.
Definition CalFile.h:226
const std::string & getTimeZone() const
Definition CalFile.h:276
std::string _dateTimeFormat
Definition CalFile.h:518
int _curlineLength
Definition CalFile.h:524
static std::vector< std::string > getAllPaths()
Return all the paths that have been set in all CalFile instances, in the order they were seen.
Definition CalFile.h:215
nidas::util::UTime _timeAfterInclude
Time stamp of record after include "file".
Definition CalFile.h:547
bool eof() const
Have we reached eof.
Definition CalFile.h:271
static void freeREs()
Definition CalFile.cc:99
nidas::util::UTime _currentTime
Definition CalFile.h:536
const DSMSensor * _sensor
Definition CalFile.h:556
static void compileREs()
Definition CalFile.cc:66
nidas::util::Mutex _mutex
Definition CalFile.h:579
std::vector< std::string > _currentFields
Definition CalFile.h:537
const std::vector< std::string > & getCurrentFields(nidas::util::UTime *time=0)
Return the time and fields of the current record, the one last read with readCF().
Definition CalFile.cc:322
float getFloatField(int column, const std::vector< std::string > *fields=0)
Convert the field at index column in the fields vector to a number, and return the number.
Definition CalFile.cc:664
static regex_t _dateFormatPreg
Definition CalFile.h:564
static regex_t _includePreg
Definition CalFile.h:568
bool _eofState
Definition CalFile.h:530
nidas::util::UTime search(const nidas::util::UTime &tsearch)
Search forward in a file, returning the time of the last record in the file with a time less than or ...
Definition CalFile.cc:349
nidas::util::UTime getCurrentTime()
Definition CalFile.h:368
CalFile * _include
Definition CalFile.h:554
std::string _currentFileName
Definition CalFile.h:512
std::string _path
Definition CalFile.h:510
nidas::util::UTime _timeFromInclude
Time stamp of last record in include file with time <= _includeTime.
Definition CalFile.h:552
CalFile()
Definition CalFile.cc:108
nidas::util::UTime _includeTime
Time stamp of include "file" record.
Definition CalFile.h:542
int readCF(nidas::util::UTime &time, float *data, int ndata, std::vector< std::string > *fields=0)
Read the time and data from the current record, and return the number of values read.
Definition CalFile.cc:434
static regex_t _timeZonePreg
Definition CalFile.h:566
char * _curline
Definition CalFile.h:526
void open()
Open the file.
Definition CalFile.cc:269
~CalFile()
Closes the file if necessary.
Definition CalFile.cc:170
void setPath(const std::string &val)
Set the search path to find the file, and any included files: one or more directory paths separated b...
Definition CalFile.cc:210
CalFile & operator=(const CalFile &)
Assignment operator, like the copy constructor.
Definition CalFile.cc:151
void setTimeZone(const std::string &val)
Set the timezone for the dates & times read from the file.
Definition CalFile.cc:184
const std::string & getName() const
Definition CalFile.h:242
std::string _timeZone
Definition CalFile.h:514
int readCFInclude(nidas::util::UTime &time, float *data, int ndata, std::vector< std::string > *fields_out)
Internal version of readCF() which reads records from the current include file, if any.
Definition CalFile.cc:480
nidas::util::UTime nextTime()
Definition CalFile.h:409
std::string _name
Definition CalFile.h:506
nidas::util::UTime readTime()
Read lines, parsing special comment lines and skipping other comments or blank lines,...
Definition CalFile.cc:415
static std::vector< std::string > _allPaths
Definition CalFile.h:577
int _curpos
Definition CalFile.h:528
void setDSMSensor(const DSMSensor *val)
Set the DSMSensor associated with this CalFile.
Definition CalFile.cc:243
const DSMSensor * getDSMSensor() const
Definition CalFile.cc:248
std::ifstream _fin
Definition CalFile.h:520
static nidas::util::Mutex _staticMutex
Definition CalFile.h:558
nidas::util::UTime parseTime()
Definition CalFile.cc:389
const std::string & getDateTimeFormat() const
Definition CalFile.h:286
void readLine()
Read forward to next non-comment line in CalFile.
Definition CalFile.cc:672
bool parseTimeComments()
Check the current line for special comments with timezone and datetime format settings.
Definition CalFile.cc:732
void openInclude(const std::string &name)
Definition CalFile.cc:773
const std::string & getFile() const
Definition CalFile.cc:193
const std::string & getPath() const
Set the search path to find the file, and any included files: one or more directory paths separated b...
Definition CalFile.cc:205
int parseInclude()
If the current calfile record line is an include directive, parse the include filename,...
Definition CalFile.cc:444
static bool _reCompiled
Definition CalFile.h:562
void fromDOMElement(const xercesc::DOMElement *node)
Definition CalFile.cc:793
int getFields(int begin, int end, float *data, const std::vector< std::string > *fields=0)
Parse a range of columns from the fields vector as numbers and store them in the array data.
Definition CalFile.cc:605
bool _utcZone
Definition CalFile.h:516
void setDateTimeFormat(const std::string &val)
Set the format for reading the date & time from the file.
Definition CalFile.cc:253
std::string _fileName
Definition CalFile.h:508
static int _reUsers
Definition CalFile.h:560
int readCFNoLock(nidas::util::UTime &time, float *data, int ndata, std::vector< std::string > *fields)
Definition CalFile.cc:534
nidas::util::UTime _nextTime
Definition CalFile.h:534
int _nline
Definition CalFile.h:532
void setFile(const std::string &val)
Set the base name of the file to be opened.
Definition CalFile.cc:198
static const int INITIAL_CURLINE_LENGTH
Definition CalFile.h:522
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method,...
Definition DOMable.h:51
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
A class for parsing, formatting and doing operations on time, based on Unix time conventions,...
Definition UTime.h:95
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31