00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_ls_oct_ascii_h)
00024 #define octave_ls_oct_ascii_h 1
00025
00026 #include <cfloat>
00027
00028 #include <sstream>
00029 #include <string>
00030
00031 #include "str-vec.h"
00032
00033 #include "ls-ascii-helper.h"
00034
00035
00036 #define CELL_ELT_TAG "<cell-element>"
00037
00038
00039
00040 #ifndef OCT_RBV
00041 #define OCT_RBV DBL_MAX / 100.0
00042 #endif
00043
00044 extern OCTINTERP_API std::string
00045 extract_keyword (std::istream& is, const char *keyword,
00046 const bool next_only = false);
00047
00048 extern OCTINTERP_API std::string
00049 read_ascii_data (std::istream& is, const std::string& filename, bool& global,
00050 octave_value& tc, octave_idx_type count);
00051
00052 extern OCTINTERP_API bool
00053 save_ascii_data (std::ostream& os, const octave_value& val_arg,
00054 const std::string& name, bool mark_as_global, int precision);
00055
00056 extern OCTINTERP_API bool
00057 save_ascii_data_for_plotting (std::ostream& os, const octave_value& t,
00058 const std::string& name);
00059
00060 extern OCTINTERP_API bool
00061 save_three_d (std::ostream& os, const octave_value& t,
00062 bool parametric = false);
00063
00064
00065
00066
00067
00068
00069
00070
00071 template <class T>
00072 bool
00073 extract_keyword (std::istream& is, const char *keyword, T& value,
00074 const bool next_only = false)
00075 {
00076 bool status = false;
00077 value = T();
00078
00079 char c;
00080 while (is.get (c))
00081 {
00082 if (c == '%' || c == '#')
00083 {
00084 std::ostringstream buf;
00085
00086 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
00087 ;
00088
00089 if (isalpha (c))
00090 buf << c;
00091
00092 while (is.get (c) && isalpha (c))
00093 buf << c;
00094
00095 std::string tmp = buf.str ();
00096 bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
00097
00098 if (match)
00099 {
00100 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
00101 ;
00102
00103 is.putback (c);
00104 if (c != '\n' && c != '\r')
00105 is >> value;
00106 if (is)
00107 status = true;
00108 skip_until_newline (is, false);
00109 break;
00110 }
00111 else if (next_only)
00112 break;
00113 }
00114 }
00115 return status;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 template <class T>
00127 bool
00128 extract_keyword (std::istream& is, const string_vector& keywords,
00129 std::string& kw, T& value, const bool next_only = false)
00130 {
00131 bool status = false;
00132 kw = "";
00133 value = 0;
00134
00135 char c;
00136 while (is.get (c))
00137 {
00138 if (c == '%' || c == '#')
00139 {
00140 std::ostringstream buf;
00141
00142 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
00143 ;
00144
00145 if (isalpha (c))
00146 buf << c;
00147
00148 while (is.get (c) && isalpha (c))
00149 buf << c;
00150
00151 std::string tmp = buf.str ();
00152
00153 for (int i = 0; i < keywords.length (); i++)
00154 {
00155 int match = (tmp == keywords[i]);
00156
00157 if (match)
00158 {
00159 kw = keywords[i];
00160
00161 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
00162 ;
00163
00164 is.putback (c);
00165 if (c != '\n' && c != '\r')
00166 is >> value;
00167 if (is)
00168 status = true;
00169 skip_until_newline (is, false);
00170 return status;
00171 }
00172 }
00173
00174 if (next_only)
00175 break;
00176 }
00177 }
00178 return status;
00179 }
00180
00181 #endif
00182
00183
00184
00185
00186
00187
00188