41using std::ostringstream;
45#include <libdap/D4Attributes.h>
46#include <libdap/Error.h>
47#include <libdap/debug.h>
50#include "FFSequence.h"
51#include "FFD4Sequence.h"
61FFSequence::ptr_duplicate()
63 return new FFSequence(*
this);
68FFSequence::FFSequence(
const string &n,
const string &d,
const string &iff) :
69 Sequence(n, d), d_input_format_file(iff)
73FFSequence::~FFSequence()
78static long Records(
const string &filename)
81 DATA_BIN_PTR dbin = NULL;
82 FF_STD_ARGS_PTR SetUps = NULL;
83 PROCESS_INFO_LIST pinfo_list = NULL;
84 PROCESS_INFO_PTR pinfo = NULL;
85 static char Msgt[255];
87 SetUps = ff_create_std_args();
93 SetUps->user.is_stdin_redirected = 0;
94 SetUps->input_file =
const_cast<char*
>(filename.c_str());
96 SetUps->output_file = NULL;
98 error = SetDodsDB(SetUps, &dbin, Msgt);
99 if (error && error < ERR_WARNING_ONLY) {
104 ff_destroy_std_args(SetUps);
106 error = db_ask(dbin, DBASK_PROCESS_INFO, FFF_INPUT | FFF_DATA,
111 pinfo_list = dll_first(pinfo_list);
113 pinfo = ((PROCESS_INFO_PTR) (pinfo_list)->data.u.pi);
115 long num_records = PINFO_SUPER_ARRAY_ELS(pinfo);
117 ff_destroy_process_info_list(pinfo_list);
134 DBG(cerr <<
"Entering FFSequence::read..." << endl);
139 if ((BufPtr >= BufSiz) && (BufSiz != 0))
148 o_fmt <<
"binary_output_data \"DODS binary output data\"" << endl;
149 for (Vars_iter p = var_begin(); p != var_end(); ++p) {
150 if ((*p)->synthesized_p())
152 if ((*p)->type() == dods_str_c)
153 endbyte +=
static_cast<FFStr&
>(**p).size();
155 endbyte += (*p)->width();
157 o_fmt << (*p)->name() <<
" " << stbyte <<
" " << endbyte <<
" " << ff_types((*p)->type()) <<
" "
158 << ff_prec((*p)->type()) << endl;
159 stbyte = endbyte + 1;
162 DBG(cerr << o_fmt.str());
165 long num_rec = Records(dataset());
170 BufSiz = num_rec * (stbyte - 1);
171 BufVal =
new char[BufSiz];
173 long bytes = read_ff(dataset().c_str(), d_input_format_file.c_str(), o_fmt.str().c_str(), BufVal, BufSiz);
176 throw Error(
"Could not read requested data from the dataset.");
179 for (Vars_iter p = var_begin(); p != var_end(); ++p) {
186void FFSequence::transfer_attributes(AttrTable *at)
189 Vars_iter var = var_begin();
190 while (var != var_end()) {
191 (*var)->transfer_attributes(at);
197void FFSequence::transform_to_dap4(D4Group *root, Constructor *container)
204 FFD4Sequence *dest =
new FFD4Sequence(name(), dataset(), d_input_format_file);
205 Constructor::transform_to_dap4(root, dest);
206 container->add_var_nocopy(dest);
209 for (Constructor::Vars_citer i = var_begin(), e = var_end(); i != e; ++i) {
210 BaseType *new_var = (*i)->transform_to_dap4(root, dest);
212 new_var->set_parent(dest);
213 dest->add_var_nocopy(new_var);
216 throw InternalErr(__FILE__, __LINE__,
"transform_to_dap4() returned null, but no Grid could be here.");
221 dest->attributes()->transform_to_dap4(get_attr_table());
223 dest->set_is_dap4(
true);
224 dest->set_parent(container);