25 #include <wx/filename.h>
27 #include "TCDataSource.h"
28 #include "TCDS_Ascii_Harmonic.h"
29 #include "TCDS_Binary_Harmonic.h"
31 #include <wx/arrimpl.cpp>
32 WX_DEFINE_OBJARRAY(ArrayOfTCDSources);
34 TCDataSource::TCDataSource() {
36 pTCDS_Ascii_Harmonic = NULL;
37 pTCDS_Binary_Harmonic = NULL;
40 TCDataSource::~TCDataSource() {
41 wxLogMessage(_T(
"UnLoading Tide/Current data source: %s"),
42 m_data_source_path.c_str());
44 delete pTCDS_Ascii_Harmonic;
45 delete pTCDS_Binary_Harmonic;
48 TC_Error_Code TCDataSource::LoadData(
const wxString &data_file_path) {
49 m_data_source_path = data_file_path;
50 wxLogMessage(_T(
"Loading Tide/Current data source: %s"),
51 m_data_source_path.c_str());
53 wxFileName fname(data_file_path);
55 if (!fname.FileExists())
return TC_FILE_NOT_FOUND;
57 if (fname.GetExt() == _T(
"IDX") || fname.GetExt() == _T(
"idx")) {
60 pTCDS_Ascii_Harmonic = pdata;
61 }
else if (fname.GetExt() == _T(
"tcd") || fname.GetExt() == _T(
"TCD")) {
64 pTCDS_Binary_Harmonic = pdata;
67 TC_Error_Code err_code;
69 err_code = m_pfactory->LoadData(data_file_path);
72 unsigned int max_index = GetMaxIndex();
73 for (
unsigned int i = 0; i < max_index; i++) {
76 pIDX->pDataSource =
this;
77 strncpy(pIDX->source_ident, m_data_source_path.mb_str(),
79 pIDX->source_ident[MAXNAMELEN - 1] =
'\0';
83 err_code = TC_FILE_NOT_FOUND;
88 int TCDataSource::GetMaxIndex(
void) {
90 return m_pfactory->GetMaxIndex();
95 IDX_entry *TCDataSource::GetIndexEntry(
int n_index) {
97 if (n_index < m_pfactory->GetMaxIndex())
98 return m_pfactory->GetIndexEntry(n_index);
105 TC_Error_Code TCDataSource::LoadHarmonicData(
IDX_entry *pIDX) {
106 switch (pIDX->source_data_type) {
107 case SOURCE_TYPE_ASCII_HARMONIC:
108 return pTCDS_Ascii_Harmonic->LoadHarmonicData(pIDX);
111 case SOURCE_TYPE_BINARY_HARMONIC:
112 return pTCDS_Binary_Harmonic->LoadHarmonicData(pIDX);
116 return TC_GENERIC_ERROR;