00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00041
#include "JulianizeVMatrix.h"
00042
#include <plearn/base/PDate.h>
00043
#include <plearn/base/PDateTime.h>
00044
00045
namespace PLearn {
00046
using namespace std;
00047
00048
00049
PLEARN_IMPLEMENT_OBJECT(JulianizeVMatrix,
"ONE LINE DESCR",
00050
"JulianizeVMatrix provides a conversion from a VMat containing dates\n"
00051
"in an explicit 3-column (YYYY,MM,DD) or 6-column (YYYY,MM,DD,HH,MM,SS)\n"
00052
"format to a Julian day number format (including fractional part to\n"
00053
"represent the hour within the day). The dates can be at any columns,\n"
00054
"not only columns 0-2 (or 0-5). More than a single date can be\n"
00055
"converted.\n");
00056
00057
00058 JulianizeVMatrix::JulianizeVMatrix()
00059 :
inherited()
00060
00061 { }
00062
00063 JulianizeVMatrix::JulianizeVMatrix(
VMat underlying,
00064 DateCode date_code,
00065
int starting_column)
00066 :
inherited(underlying->length(), newWidth(underlying, date_code)),
00067 underlying_(underlying),
00068 cols_codes_(1), und_row_(underlying.width())
00069 {
00070
cols_codes_[0] = make_pair(starting_column, date_code);
00071
setVMFields();
00072 }
00073
00074
00075 void JulianizeVMatrix::getNewRow(
int i,
const Vec& v)
const
00076
{
00077
underlying_->getRow(i,
und_row_);
00078
00079 Vec::iterator
00080 src_beg =
und_row_.
begin(),
00081 src_it =
und_row_.
begin(),
00082 src_end =
und_row_.
end(),
00083 dst_it = v.
begin();
00084
vector< pair<int,DateCode> >::const_iterator
00085 codes_it =
cols_codes_.begin(),
00086 codes_end =
cols_codes_.end();
00087
00088
for ( ; codes_it < codes_end ; ++codes_it ) {
00089
00090 dst_it =
copy(src_it, src_beg + codes_it->first, dst_it);
00091 src_it = src_beg + codes_it->first;
00092
00093
00094
double converted_date = 0;
00095
int YYYY,MM,DD,hh,mm,ss;
00096 YYYY =
int(*src_it++);
00097 MM = int(*src_it++);
00098 DD = int(*src_it++);
00099
switch(codes_it->second) {
00100
case Date:
00101 converted_date =
PDate(YYYY,MM,DD).toJulianDay();
00102
break;
00103
case DateTime:
00104 hh = int(*src_it++);
00105 mm = int(*src_it++);
00106 ss = int(*src_it++);
00107 converted_date =
PDateTime(YYYY,MM,DD,hh,mm,ss).toJulianDay();
00108
break;
00109 }
00110 *dst_it++ = converted_date;
00111 }
00112
00113
00114
copy(src_it, src_end, dst_it);
00115 }
00116
00117 void JulianizeVMatrix::declareOptions(
OptionList& ol)
00118 {
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 inherited::declareOptions(ol);
00132 }
00133
00134 void JulianizeVMatrix::build_()
00135 {
00136
00137 }
00138
00139
00140 void JulianizeVMatrix::build()
00141 {
00142 inherited::build();
00143
build_();
00144 }
00145
00146 void JulianizeVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00147 {
00148 inherited::makeDeepCopyFromShallowCopy(copies);
00149
deepCopyField(
underlying_, copies);
00150
deepCopyField(
und_row_, copies);
00151
00152 }
00153
00154 void JulianizeVMatrix::setVMFields()
00155 {
00156
Array<VMField>& orig_fields =
underlying_->getFieldInfos();
00157
int new_field = 0;
00158
int cur_field = 0, end_field = orig_fields.
size();
00159
vector< pair<int,DateCode> >::iterator it =
cols_codes_.begin(),
00160 end =
cols_codes_.end();
00161
00162
for ( ; cur_field < end_field ; ++cur_field, ++new_field) {
00163
00164
if (it != end && it->first == cur_field) {
00165
switch(it->second) {
00166
case Date:
00167 this->declareField(new_field,
"Date", VMField::Date);
00168
break;
00169
case DateTime:
00170 this->declareField(new_field,
"DateTime", VMField::Date);
00171
break;
00172 }
00173 cur_field +=
dateCodeWidth(it->second)-1;
00174 ++it;
00175 }
00176
else {
00177 this->declareField(new_field, orig_fields[cur_field].name,
00178 orig_fields[cur_field].fieldtype);
00179 }
00180 }
00181 }
00182
00183
00184 }
00185