C++时间库和八度.oct文件
问题描述:
我想写一个使用linasm-1.13 library的八度C++ .oct函数,但我似乎无法从/ usr/share/zoneinfo /工作基本加载tzdata。我简单的测试功能至今C++时间库和八度.oct文件
#include <octave/oct.h>
#include <Time.h> // the linasm-1.13 library
DEFUN_DLD (tz, args, nargout,
"-*- texinfo -*-\n\
@deftypefn {Function File} {} tz (@var{YYYYMMDDHHMMSS})\n\
\n\
@end deftypefn")
{
octave_value_list retval_list ;
unsigned int tz ;
const char *ny_time = "/usr/share/zoneinfo/America/New_York" ;
tz = Time::LoadTimeZone(ny_time) ;
return retval_list ;
其中,与mkoctfile编译,给出了这样的错误
>> mkoctfile tz.cc
tz.cc: In function ‘octave_value_list Ftz(const octave_value_list&, int)’:
tz.cc:24:34: error: cannot call member function ‘unsigned int Time::LoadTimeZone(const char*)’ without object
tz = Time::LoadTimeZone(ny_time) ;
^
warning: mkoctfile: building exited with failure status
我对此的理解是,ny_time不被识别的对象,但我已尽力将ny_time强制转换为字符串,详见this accepted SO answer。
我这样做是因为根据linasm page的LoadTimeZone的输入应该是“tzfile的路径,它描述了所需的时区”。我哪里错了?
答
我认为你必须#include "source.cc"
文件,而不仅仅是#include "header.h"
文件。在你的情况下,我想你应该加上:#include "Time.cc"
或类似的东西。我不知道为什么,但是这对我工作Rafat's Hussain wavemin library,但我只有4个文件,它必须是令人难以置信的繁琐与大量的文件。
这就是我所做的(这是Rafat提供的测试代码与他的库提供的修改版本)。
#include "wavemin.h"
#include "waveaux.h"
#include "wavemin.cc"
#include "waveaux.cc"
#include <octave/oct.h>
double ensayo();
double absmax(double *array, int N);
DEFUN_DLD(helloctave2, argv, , "Usage: hello()"){
wave_object obj;
wt_object wt;
double *inp, *out, *diff;
int N, i, J;
char *name = "db4";
obj = wave_init(name);// Initialize the wavelet
N = 14; //Length of Signal
inp = (double*)malloc(sizeof(double)* N); //Input signal
out = (double*)malloc(sizeof(double)* N);
diff = (double*)malloc(sizeof(double)* N);
//wmean = mean(temp, N);
for (i = 0; i < N; ++i) {
inp[i] = i;
}
J = 1; //Decomposition Levels
wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object
setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
setWTConv(wt, "direct");
dwt(wt, inp);// Perform DWT
//DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
for (i = 0; i < wt->outlength; ++i) {
octave_stdout << wt->output[i];
octave_stdout << "\n";
}
idwt(wt, out);// Perform IDWT (if needed)
// Test Reconstruction
for (i = 0; i < wt->siglength; ++i) {
diff[i] = out[i] - inp[i];
}
octave_stdout << absmax(diff, wt->siglength);
octave_stdout << "\n";
octave_value_list retval;
return retval;
}
double
absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}
从错误消息看来,您需要首先构造一个Time对象,然后在该对象上调用LoadTimeZone。所以,你可能还需要在'Time'类中提供一个Octave包装器,然后需要Octave代码来提供它。 –
顺便说一下,在大多数情况下,我更喜欢使用Swig来手动编写绑定,因为Swig会为您处理许多繁琐的细节(并且它支持生成Octave绑定)。 –
如果您使用的是C++ 11或更高版本,则可以考虑使用以下替代时区库:https://howardhinnant.github.io/date/tz.html它具有出色的文档和支持。 –