Mercurial > octave-nkf
comparison src/ls-oct-ascii.cc @ 5956:cdef72fcd206
[project @ 2006-08-22 20:36:56 by jwe]
author | jwe |
---|---|
date | Tue, 22 Aug 2006 20:36:57 +0000 |
parents | b2167e370f82 |
children | 85c7dc4afe6b |
comparison
equal
deleted
inserted
replaced
5955:fc46f9c99028 | 5956:cdef72fcd206 |
---|---|
70 // The number of decimal digits to use when writing ascii data. | 70 // The number of decimal digits to use when writing ascii data. |
71 static int Vsave_precision = 16; | 71 static int Vsave_precision = 16; |
72 | 72 |
73 // Functions for reading ascii data. | 73 // Functions for reading ascii data. |
74 | 74 |
75 static Matrix | |
76 strip_infnan (const Matrix& m) | |
77 { | |
78 octave_idx_type nr = m.rows (); | |
79 octave_idx_type nc = m.columns (); | |
80 | |
81 Matrix retval (nr, nc); | |
82 | |
83 octave_idx_type k = 0; | |
84 for (octave_idx_type i = 0; i < nr; i++) | |
85 { | |
86 for (octave_idx_type j = 0; j < nc; j++) | |
87 { | |
88 double d = m (i, j); | |
89 if (xisnan (d)) | |
90 goto next_row; | |
91 else | |
92 retval (k, j) = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d; | |
93 } | |
94 k++; | |
95 | |
96 next_row: | |
97 continue; | |
98 } | |
99 | |
100 if (k > 0) | |
101 retval.resize (k, nc); | |
102 | |
103 return retval; | |
104 } | |
105 | |
106 // Extract a KEYWORD and its value from stream IS, returning the | 75 // Extract a KEYWORD and its value from stream IS, returning the |
107 // associated value in a new string. | 76 // associated value in a new string. |
108 // | 77 // |
109 // Input should look something like: | 78 // Input should look something like: |
110 // | 79 // |
336 | 305 |
337 // Save the data from TC along with the corresponding NAME, and global | 306 // Save the data from TC along with the corresponding NAME, and global |
338 // flag MARK_AS_GLOBAL on stream OS in the plain text format described | 307 // flag MARK_AS_GLOBAL on stream OS in the plain text format described |
339 // above for load_ascii_data. If NAME is empty, the name: line is not | 308 // above for load_ascii_data. If NAME is empty, the name: line is not |
340 // generated. PRECISION specifies the number of decimal digits to print. | 309 // generated. PRECISION specifies the number of decimal digits to print. |
341 // If STRIP_NAN_AND_INF is TRUE, rows containing NaNs are deleted, | 310 // If STRIP_NAN_AND_INF is 1, rows containing NaNs are deleted, |
342 // and Infinite values are converted to +/-OCT_RBV (A Real Big Value, | 311 // and Infinite values are converted to +/-OCT_RBV (A Real Big Value, |
343 // but not so big that gnuplot can't handle it when trying to compute | 312 // but not so big that gnuplot can't handle it when trying to compute |
344 // axis ranges, etc.). | 313 // axis ranges, etc.). If STRIP_NAN_AND_INF is 2, rows containing |
314 // NaNs are converted to blank lines in the output file and infinite | |
315 // values are converted to +/-OCT_RBV. | |
345 // | 316 // |
346 // Assumes ranges and strings cannot contain Inf or NaN values. | 317 // Assumes ranges and strings cannot contain Inf or NaN values. |
347 // | 318 // |
348 // Returns 1 for success and 0 for failure. | 319 // Returns 1 for success and 0 for failure. |
349 | 320 |
350 // FIXME -- should probably write the help string here too. | 321 // FIXME -- should probably write the help string here too. |
351 | 322 |
352 bool | 323 bool |
353 save_ascii_data (std::ostream& os, const octave_value& val_arg, | 324 save_ascii_data (std::ostream& os, const octave_value& val_arg, |
354 const std::string& name, bool& infnan_warned, | 325 const std::string& name, bool& infnan_warned, |
355 bool strip_nan_and_inf, bool mark_as_global, | 326 int strip_nan_and_inf, bool mark_as_global, |
356 int precision) | 327 int precision) |
357 { | 328 { |
358 bool success = true; | 329 bool success = true; |
359 | 330 |
360 if (! name.empty ()) | 331 if (! name.empty ()) |
384 save_ascii_data_for_plotting (std::ostream& os, const octave_value& t, | 355 save_ascii_data_for_plotting (std::ostream& os, const octave_value& t, |
385 const std::string& name) | 356 const std::string& name) |
386 { | 357 { |
387 bool infnan_warned = true; | 358 bool infnan_warned = true; |
388 | 359 |
389 return save_ascii_data (os, t, name, infnan_warned, false, false, 0); | 360 return save_ascii_data (os, t, name, infnan_warned, 2, false, 0); |
390 } | 361 } |
391 | 362 |
392 // Maybe this should be a static function in tree-plot.cc? | 363 // Maybe this should be a static function in tree-plot.cc? |
393 | 364 |
394 // If TC is matrix, save it on stream OS in a format useful for | 365 // If TC is matrix, save it on stream OS in a format useful for |