63 #include <InternalErr.h>
64 #include <dods-limits.h>
86 static string &remove_paths(
string &src)
88 size_t p1 = src.find_first_of(
'/');
89 if (p1 == string::npos)
91 size_t p2 = src.find_last_of(
'/');
96 src.erase(p1, p2-p1+1);
119 static string freeform_error_message()
123 throw BESInternalError(
"Called the FreeForm error message code, but there was no error.", __FILE__, __LINE__);
133 string problem = error->
problem;
134 string message = error->
message;
135 oss << remove_paths(problem) <<
": " << remove_paths(message) << endl;
156 long read_ff(
const char *dataset,
const char *if_file,
const char *o_format,
char *o_buffer,
unsigned long bsize)
164 throw BESInternalError(
"FreeForm could not allocate a 'stdargs' object.", __FILE__, __LINE__);
174 std_args->
log_file = (
char *)
"/dev/null";
177 std_args->
log_file = (
char *)
"/tmp/ffdods.log";
194 throw BESInternalError(
"FreeForm could not allocate a 'newform_log' object.", __FILE__, __LINE__);
199 int status =
newform(std_args, newform_log, 0 );
201 BESDEBUG(
"ff",
"FreeForm: newform returns " << status << endl);
204 string message = freeform_error_message();
205 BESDEBUG(
"ff",
"FreeForm: error message " << message << endl);
234 for (
int i = 0; i < len; ++i)
269 throw Error(
"ff_types: DODS type " + D2type_name(dods_type) +
" does not map to a FreeForm type.");
296 throw Error(
"ff_prec: DODS type " + D2type_name(dods_type) +
" does not map to a FreeForm type.");
310 str <<
"binary_output_data \"DODS binary output data\"" << endl;
311 str << name <<
" 1 " << width <<
" " <<
ff_types(type)
312 <<
" " <<
ff_prec(type) << endl;
320 int ndim,
const long *start,
const long *
edge,
const
321 long *stride,
string * dname)
324 str <<
"binary_output_data \"DODS binary output data\"" << endl;
325 str << name <<
" 1 " << width <<
" ARRAY";
327 for (
int i = 0; i < ndim; i++)
328 str <<
"[" <<
"\"" << dname[i] <<
"\" " << start[i] + 1 <<
" to "
329 << start[i] + (edge[i] - 1) * stride[i] +
330 1 <<
" by " << stride[i] <<
" ]";
334 DBG(cerr <<
"ND output format: " << str.str() << endl);
346 static string delimiter =
".";
348 if (new_delimiter !=
"")
349 delimiter = new_delimiter;
362 static string extension =
".fmt";
364 if (new_extension !=
"")
365 extension = new_extension;
418 snprintf(Msgt,
Msgt_size,
"Error in Standard Data Bin");
426 snprintf(Msgt,
Msgt_size,
"Error making name table for %s",
438 if (format_data_list)
441 snprintf(Msgt,
Msgt_size,
"Error setting an input format for %s",
450 snprintf(Msgt,
Msgt_size,
"Error creating array information for %s",
457 snprintf(Msgt,
Msgt_size,
"Error determining input header file names for %s",
470 snprintf(Msgt,
Msgt_size,
"Error creating array information for %s",
475 error = merge_redundant_conduits((*dbin_h)->array_conduit_list);
477 snprintf(Msgt,
Msgt_size,
"Error merging redundent conduits");
494 static char Msgt[255];
503 SetUps->
input_file =
const_cast<char*
>(filename.c_str());
534 return access(filename, F_OK) == 0;
560 size_t delim = dataset.rfind(
"#");
561 if (delim != string::npos)
562 FileName = dataset.substr(delim + 1, dataset.length() - delim + 1);
564 delim = dataset.rfind(
"/");
565 if (delim != string::npos)
566 FileName = dataset.substr(delim + 1, dataset.length() - delim + 1);
572 delim = FileName.find(
"_");
573 if ( delim != string::npos ) {
574 BaseName = FileName.substr(0,delim+1);
577 throw Error(
"Could not find input format for: " + dataset);
581 string DatePart = FileName.substr(delim+1, FileName.length()-delim+1);
583 if (FormatPath[FormatPath.length()-1] !=
'/')
584 FormatPath.append(
"/");
586 if ( (DatePart.find(
"_") != string::npos) || (DatePart.length() < 10) )
587 FormatFile = FormatPath + BaseName +
"averaged.fmt";
589 FormatFile = FormatPath + BaseName +
"daily.fmt";
591 return string(FormatFile);
615 size_t delim = dataset.rfind(
"#");
616 if (delim != string::npos)
617 FileName = dataset.substr(delim + 1, dataset.length() - delim + 1);
619 delim = dataset.rfind(
"/");
620 if (delim != string::npos)
621 FileName = dataset.substr(delim + 1, dataset.length() - delim + 1);
626 delim = FileName.find(
"_");
627 if ( delim != string::npos ) {
628 BaseName = FileName.substr(0,delim+1);
631 string msg =
"Could not find input format for: ";
633 throw InternalErr(msg);
636 string DatePart = FileName.substr(delim+1, FileName.length()-delim+1);
638 if (FormatPath[FormatPath.length()-1] !=
'/')
639 FormatPath.append(
"/");
641 if ( (DatePart.find(
"_") != string::npos) || (DatePart.length() < 10) )
642 FormatFile = FormatPath + BaseName +
"averaged.das";
644 FormatFile = FormatPath + BaseName +
"daily.das";
646 return string(FormatFile);
654 switch (btp->type()) {
670 case dods_structure_c:
671 case dods_sequence_c:
680 switch (btp->type()) {
696 case dods_structure_c:
697 case dods_sequence_c:
713 switch (var->type()) {
715 return static_cast<Byte*
>(var)->value();
718 return static_cast<Int16*
>(var)->value();
721 return static_cast<Int32*
>(var)->value();
724 return static_cast<UInt16*
>(var)->value();
727 return static_cast<UInt32*
>(var)->value();
730 throw InternalErr(__FILE__, __LINE__,
731 "Tried to get an integer value for a non-integer datatype!");
740 switch (var->type()) {
748 return static_cast<Float32*
>(var)->value();
751 return static_cast<Float64*
>(var)->value();
754 throw InternalErr(__FILE__, __LINE__,
755 "Tried to get an float value for a non-numeric datatype!");
#define BES_SYNTAX_USER_ERROR
bool is_integer_type(BaseType *btp)
char * input_format_title
exception thrown if inernal error encountered
const string find_ancillary_rss_formats(const string &dataset, const string &, const string &)
Find the RSS (Remote Sensing Systems) format file using their naming convention.
FF_ARRAY_DIPOLE_PTR input
long Records(const string &filename)
Figure out how many records there are in the dataset.
bool file_exist(const char *filename)
bool is_float_type(BaseType *btp)
int SetDodsDB(FF_STD_ARGS_PTR std_args, DATA_BIN_HANDLE dbin_h, char *Msgt)
Given a set of standard arguments (input filenames), allocate a DATA-BIN_HANDLE and return an error c...
char * output_format_buffer
FF_ARRAY_DIPOLE_PTR output
struct struct_ff_std_args::struct_std_args_user user
dods_float64 get_float_value(BaseType *var)
const string & format_extension(const string &new_extension)
Set or get the format file extension.
const string make_output_format(const string &name, Type type, const int width)
Make a FreeForm output format specification.
const string makeND_output_format(const string &name, Type type, const int width, int ndim, const long *start, const long *edge, const long *stride, string *dname)
BOOLEAN is_a_warning(FF_ERROR_PTR error)
FF_ERROR_PTR pull_error(void)
dods_uint32 get_integer_value(BaseType *var)
Get the value of the BaseType Variable.
Abstract exception class for the BES with basic string message.
char * input_format_buffer
FF_BUFSIZE_PTR output_bufsize
unsigned int is_stdin_redirected
const string ff_types(Type dods_type)
void free_ff_char_vector(char **v, int len)
Free a char ** vector that db_ask() allocates.
int ff_prec(Type dods_type)
static string get_RSS_format_files()
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
const string & format_delimiter(const string &new_delimiter)
Set or get the format file delimiter.
const string find_ancillary_rss_das(const string &dataset, const string &, const string &)
Find the RSS (Remote Sensing Systems) format file using their naming convention.
long read_ff(const char *dataset, const char *if_file, const char *o_format, char *o_buffer, unsigned long bsize)
Read from a file/database using the FreeForm API.