| 1 |
/* praat_TableOfReal.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2018,2021-2024,2026 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "Matrix.h" |
| 20 |
#include "praat_TableOfReal.h" |
| 21 |
|
| 22 |
// MARK: - TABLEOFREAL |
| 23 |
|
| 24 |
// MARK: Help |
| 25 |
|
| 26 |
DIRECT (HELP_TableOfReal_help) { |
| 27 |
HELP (U"TableOfReal") |
| 28 |
} |
| 29 |
|
| 30 |
// MARK: Draw |
| 31 |
|
| 32 |
FORM (GRAPHICS_TableOfReal_drawAsNumbers, U"Draw as numbers", nullptr) { |
| 33 |
NATURAL (fromRow, U"From row", U"1") |
| 34 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 35 |
CHOICE (format, U"Format", 3) |
| 36 |
OPTION (U"decimal") |
| 37 |
OPTION (U"exponential") |
| 38 |
OPTION (U"free") |
| 39 |
OPTION (U"rational") |
| 40 |
NATURAL (precision, U"Precision", U"5") |
| 41 |
OK |
| 42 |
DO |
| 43 |
GRAPHICS_EACH (TableOfReal) |
| 44 |
TableOfReal_drawAsNumbers (me, GRAPHICS, fromRow, toRow, format, precision); |
| 45 |
GRAPHICS_EACH_END |
| 46 |
} |
| 47 |
|
| 48 |
FORM (GRAPHICS_TableOfReal_drawAsNumbers_if, U"Draw as numbers if...", nullptr) { |
| 49 |
NATURAL (fromRow, U"From row", U"1") |
| 50 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 51 |
CHOICE (format, U"Format", 3) |
| 52 |
OPTION (U"decimal") |
| 53 |
OPTION (U"exponential") |
| 54 |
OPTION (U"free") |
| 55 |
OPTION (U"rational") |
| 56 |
NATURAL (precision, U"Precision", U"5") |
| 57 |
FORMULA (condition, U"Condition", U"self <> 0") |
| 58 |
OK |
| 59 |
DO |
| 60 |
GRAPHICS_EACH (TableOfReal) |
| 61 |
TableOfReal_drawAsNumbers_if (me, GRAPHICS, fromRow, toRow, format, precision, condition, interpreter); |
| 62 |
GRAPHICS_EACH_END |
| 63 |
} |
| 64 |
|
| 65 |
FORM (GRAPHICS_TableOfReal_drawAsSquares, U"Draw table as squares", nullptr) { |
| 66 |
NATURAL (fromRow, U"From row", U"1") |
| 67 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 68 |
NATURAL (fromColumn, U"From column", U"1") |
| 69 |
INTEGER (toColumn, U"To column", U"0") |
| 70 |
BOOLEAN (garnish, U"Garnish", true) |
| 71 |
OK |
| 72 |
DO |
| 73 |
GRAPHICS_EACH (TableOfReal) |
| 74 |
TableOfReal_drawAsSquares (me, GRAPHICS, fromRow, toRow, fromColumn, toColumn, garnish); |
| 75 |
GRAPHICS_EACH_END |
| 76 |
} |
| 77 |
|
| 78 |
FORM (GRAPHICS_TableOfReal_drawHorizontalLines, U"Draw horizontal lines", nullptr) { |
| 79 |
NATURAL (fromRow, U"From row", U"1") |
| 80 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 81 |
OK |
| 82 |
DO |
| 83 |
GRAPHICS_EACH (TableOfReal) |
| 84 |
TableOfReal_drawHorizontalLines (me, GRAPHICS, fromRow, toRow); |
| 85 |
GRAPHICS_EACH_END |
| 86 |
} |
| 87 |
|
| 88 |
FORM (GRAPHICS_TableOfReal_drawLeftAndRightLines, U"Draw left and right lines", nullptr) { |
| 89 |
NATURAL (fromRow, U"From row", U"1") |
| 90 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 91 |
OK |
| 92 |
DO |
| 93 |
GRAPHICS_EACH (TableOfReal) |
| 94 |
TableOfReal_drawLeftAndRightLines (me, GRAPHICS, fromRow, toRow); |
| 95 |
GRAPHICS_EACH_END |
| 96 |
} |
| 97 |
|
| 98 |
FORM (GRAPHICS_TableOfReal_drawTopAndBottomLines, U"Draw top and bottom lines", nullptr) { |
| 99 |
NATURAL (fromRow, U"From row", U"1") |
| 100 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 101 |
OK |
| 102 |
DO |
| 103 |
GRAPHICS_EACH (TableOfReal) |
| 104 |
TableOfReal_drawTopAndBottomLines (me, GRAPHICS, fromRow, toRow); |
| 105 |
GRAPHICS_EACH_END |
| 106 |
} |
| 107 |
|
| 108 |
FORM (GRAPHICS_TableOfReal_drawVerticalLines, U"Draw vertical lines", nullptr) { |
| 109 |
NATURAL (fromRow, U"From row", U"1") |
| 110 |
INTEGER (toRow, U"To row", U"0 (= all)") |
| 111 |
OK |
| 112 |
DO |
| 113 |
GRAPHICS_EACH (TableOfReal) |
| 114 |
TableOfReal_drawVerticalLines (me, GRAPHICS, fromRow, toRow); |
| 115 |
GRAPHICS_EACH_END |
| 116 |
} |
| 117 |
|
| 118 |
// MARK: Query |
| 119 |
|
| 120 |
FORM (INTEGER_TableOfReal_getColumnIndex, U"Get column index", nullptr) { |
| 121 |
SENTENCE (columnLabel, U"Column label", U"") |
| 122 |
OK |
| 123 |
DO |
| 124 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 125 |
const integer result = TableOfReal_columnLabelToIndex (me, columnLabel); |
| 126 |
QUERY_ONE_FOR_REAL_END (U" (index of column ", columnLabel, U")") |
| 127 |
} |
| 128 |
|
| 129 |
FORM (STRING_TableOfReal_getColumnLabel, U"Get column label", nullptr) { |
| 130 |
NATURAL (columnNumber, U"Column number", U"1") |
| 131 |
OK |
| 132 |
DO |
| 133 |
QUERY_ONE_FOR_STRING (TableOfReal) |
| 134 |
if (columnNumber > my numberOfColumns) |
| 135 |
Melder_throw (me, U": your column number should not be greater than the number of columns."); |
| 136 |
conststring32 result = my columnLabels ? my columnLabels [columnNumber].get() : U""; |
| 137 |
QUERY_ONE_FOR_STRING_END |
| 138 |
} |
| 139 |
|
| 140 |
FORM (REAL_TableOfReal_getColumnMean_index, U"Get column mean", nullptr) { |
| 141 |
NATURAL (columnNumber, U"Column number", U"1") |
| 142 |
OK |
| 143 |
DO |
| 144 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 145 |
if (columnNumber > my numberOfColumns) |
| 146 |
Melder_throw (me, U": your column number should not be greater than the number of columns."); |
| 147 |
const double result = TableOfReal_getColumnMean (me, columnNumber); |
| 148 |
QUERY_ONE_FOR_REAL_END (U" (mean of column ", columnNumber, U")") |
| 149 |
} |
| 150 |
|
| 151 |
FORM (REAL_TableOfReal_getColumnMean_label, U"Get column mean", nullptr) { |
| 152 |
SENTENCE (columnLabel, U"Column label", U"") |
| 153 |
OK |
| 154 |
DO |
| 155 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 156 |
const integer columnNumber = TableOfReal_columnLabelToIndex (me, columnLabel); |
| 157 |
if (columnNumber == 0) |
| 158 |
Melder_throw (me, U": your column label does not exist."); |
| 159 |
const double result = TableOfReal_getColumnMean (me, columnNumber); |
| 160 |
QUERY_ONE_FOR_REAL_END (U" (mean of column ", columnLabel, U")") |
| 161 |
} |
| 162 |
|
| 163 |
FORM (REAL_TableOfReal_getColumnStdev_index, U"Get column standard deviation", nullptr) { |
| 164 |
NATURAL (columnNumber, U"Column number", U"1") |
| 165 |
OK |
| 166 |
DO |
| 167 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 168 |
if (columnNumber > my numberOfColumns) |
| 169 |
Melder_throw (me, U": your column number should not be greater than the number of columns."); |
| 170 |
const double result = TableOfReal_getColumnStdev (me, columnNumber); |
| 171 |
QUERY_ONE_FOR_REAL_END (U" (standard deviation of column ", columnNumber, U")") |
| 172 |
} |
| 173 |
|
| 174 |
FORM (REAL_TableOfReal_getColumnStdev_label, U"Get column standard deviation", nullptr) { |
| 175 |
SENTENCE (columnLabel, U"Column label", U"1") |
| 176 |
OK |
| 177 |
DO |
| 178 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 179 |
const integer columnNumber = TableOfReal_columnLabelToIndex (me, columnLabel); |
| 180 |
if (columnNumber == 0) |
| 181 |
Melder_throw (me, U": column label does not exist."); |
| 182 |
double result = TableOfReal_getColumnStdev (me, columnNumber); |
| 183 |
QUERY_ONE_FOR_REAL_END (U" (standard deviation of column ", columnLabel, U")") |
| 184 |
} |
| 185 |
|
| 186 |
DIRECT (INTEGER_TableOfReal_getNumberOfColumns) { |
| 187 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 188 |
const integer result = my numberOfColumns; |
| 189 |
QUERY_ONE_FOR_REAL_END (U" columns") |
| 190 |
} |
| 191 |
|
| 192 |
DIRECT (INTEGER_TableOfReal_getNumberOfRows) { |
| 193 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 194 |
const integer result = my numberOfRows; |
| 195 |
QUERY_ONE_FOR_REAL_END (U" rows") |
| 196 |
} |
| 197 |
|
| 198 |
FORM (INTEGER_TableOfReal_getRowIndex, U"Get row index", nullptr) { |
| 199 |
SENTENCE (rowLabel, U"Row label", U"") |
| 200 |
OK |
| 201 |
DO |
| 202 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 203 |
const integer result = TableOfReal_rowLabelToIndex (me, rowLabel); |
| 204 |
QUERY_ONE_FOR_REAL_END (U" (index of row ", rowLabel, U")") |
| 205 |
} |
| 206 |
|
| 207 |
FORM (STRING_TableOfReal_getRowLabel, U"Get row label", nullptr) { |
| 208 |
NATURAL (rowNumber, U"Row number", U"1") |
| 209 |
OK |
| 210 |
DO |
| 211 |
QUERY_ONE_FOR_STRING (TableOfReal) |
| 212 |
if (rowNumber > my numberOfRows) |
| 213 |
Melder_throw (me, U": your row number should not be greater than the number of rows."); |
| 214 |
conststring32 result = my rowLabels ? my rowLabels [rowNumber].get() : U""; |
| 215 |
QUERY_ONE_FOR_STRING_END |
| 216 |
} |
| 217 |
|
| 218 |
FORM (REAL_TableOfReal_getValue, U"Get value", nullptr) { |
| 219 |
NATURAL (rowNumber, U"Row number", U"1") |
| 220 |
NATURAL (columnNumber, U"Column number", U"1") |
| 221 |
OK |
| 222 |
DO |
| 223 |
QUERY_ONE_FOR_REAL (TableOfReal) |
| 224 |
TableOfReal_checkRowNumberWithinRange (me, rowNumber); |
| 225 |
TableOfReal_checkColumnNumberWithinRange (me, columnNumber); |
| 226 |
const double result = my data [rowNumber] [columnNumber]; |
| 227 |
QUERY_ONE_FOR_REAL_END (U" (value in column ", columnNumber, U" of row ", rowNumber, U")") |
| 228 |
} |
| 229 |
|
| 230 |
// MARK: Modify |
| 231 |
|
| 232 |
FORM (MODIFY_TableOfReal_formula, U"TableOfReal: Formula", U"Formula...") { |
| 233 |
COMMENT (U"for row from 1 to nrow do for col from 1 to ncol do self [row, col] = ...") |
| 234 |
FORMULA (formula, U"Formula", U"if col = 5 then self + self [6] else self fi") |
| 235 |
OK |
| 236 |
DO |
| 237 |
MODIFY_EACH_WEAK (TableOfReal) |
| 238 |
TableOfReal_formula (me, formula, interpreter, nullptr); |
| 239 |
MODIFY_EACH_WEAK_END |
| 240 |
} |
| 241 |
|
| 242 |
FORM (MODIFY_TableOfReal_insertColumn, U"Insert column", nullptr) { |
| 243 |
NATURAL (columnNumber, U"Column number", U"1") |
| 244 |
OK |
| 245 |
DO |
| 246 |
MODIFY_EACH (TableOfReal) |
| 247 |
TableOfReal_insertColumn (me, columnNumber); |
| 248 |
MODIFY_EACH_END |
| 249 |
} |
| 250 |
|
| 251 |
FORM (MODIFY_TableOfReal_insertRow, U"Insert row", nullptr) { |
| 252 |
NATURAL (rowNumber, U"Row number", U"1") |
| 253 |
OK |
| 254 |
DO |
| 255 |
MODIFY_EACH (TableOfReal) |
| 256 |
TableOfReal_insertRow (me, rowNumber); |
| 257 |
MODIFY_EACH_END |
| 258 |
} |
| 259 |
|
| 260 |
FORM (MODIFY_TableOfReal_removeColumn, U"Remove column", nullptr) { |
| 261 |
NATURAL (columnNumber, U"Column number", U"1") |
| 262 |
OK |
| 263 |
DO |
| 264 |
MODIFY_EACH (TableOfReal) |
| 265 |
TableOfReal_removeColumn (me, columnNumber); |
| 266 |
MODIFY_EACH_END |
| 267 |
} |
| 268 |
|
| 269 |
FORM (MODIFY_TableOfReal_removeRow, U"Remove row", nullptr) { |
| 270 |
NATURAL (rowNumber, U"Row number", U"1") |
| 271 |
OK |
| 272 |
DO |
| 273 |
MODIFY_EACH (TableOfReal) |
| 274 |
TableOfReal_removeRow (me, rowNumber); |
| 275 |
MODIFY_EACH_END |
| 276 |
} |
| 277 |
|
| 278 |
FORM (MODIFY_TableOfReal_setColumnLabel_index, U"Set column label", nullptr) { |
| 279 |
NATURAL (columnNumber, U"Column number", U"1") |
| 280 |
SENTENCE (label, U"Label", U"") |
| 281 |
OK |
| 282 |
DO |
| 283 |
MODIFY_EACH (TableOfReal) |
| 284 |
TableOfReal_setColumnLabel (me, columnNumber, label); |
| 285 |
MODIFY_EACH_END |
| 286 |
} |
| 287 |
|
| 288 |
FORM (MODIFY_TableOfReal_setColumnLabel_label, U"Set column label", nullptr) { |
| 289 |
SENTENCE (oldLabel, U"Old label", U"") |
| 290 |
SENTENCE (newLabel, U"New label", U"") |
| 291 |
OK |
| 292 |
DO |
| 293 |
MODIFY_EACH (TableOfReal) |
| 294 |
const integer columnNumber = TableOfReal_columnLabelToIndex (me, oldLabel); |
| 295 |
TableOfReal_setColumnLabel (me, columnNumber, newLabel); |
| 296 |
MODIFY_EACH_END |
| 297 |
} |
| 298 |
|
| 299 |
FORM (MODIFY_TableOfReal_setRowLabel_index, U"Set row label", nullptr) { |
| 300 |
NATURAL (rowNumber, U"Row number", U"1") |
| 301 |
SENTENCE (label, U"Label", U"") |
| 302 |
OK |
| 303 |
DO |
| 304 |
MODIFY_EACH (TableOfReal) |
| 305 |
TableOfReal_setRowLabel (me, rowNumber, label); |
| 306 |
MODIFY_EACH_END |
| 307 |
} |
| 308 |
|
| 309 |
FORM (MODIFY_TableOfReal_setValue, U"Set value", U"TableOfReal: Set value...") { |
| 310 |
NATURAL (rowNumber, U"Row number", U"1") |
| 311 |
NATURAL (columnNumber, U"Column number", U"1") |
| 312 |
REAL_OR_UNDEFINED (newValue, U"New value", U"0.0") |
| 313 |
OK |
| 314 |
DO |
| 315 |
MODIFY_EACH (TableOfReal) |
| 316 |
TableOfReal_checkRowNumberWithinRange (me, rowNumber); |
| 317 |
TableOfReal_checkColumnNumberWithinRange (me, columnNumber); |
| 318 |
my data [rowNumber] [columnNumber] = newValue; |
| 319 |
MODIFY_EACH_END |
| 320 |
} |
| 321 |
|
| 322 |
FORM (MODIFY_TableOfReal_setRowLabel_label, U"Set row label", nullptr) { |
| 323 |
SENTENCE (oldLabel, U"Old label", U"") |
| 324 |
WORD (newLabel, U"New label", U"") |
| 325 |
OK |
| 326 |
DO |
| 327 |
MODIFY_EACH (TableOfReal) |
| 328 |
const integer rowNumber = TableOfReal_rowLabelToIndex (me, oldLabel); |
| 329 |
TableOfReal_setRowLabel (me, rowNumber, newLabel); |
| 330 |
MODIFY_EACH_END |
| 331 |
} |
| 332 |
|
| 333 |
FORM (MODIFY_TableOfReal_sortByColumn, U"Sort rows by column", nullptr) { |
| 334 |
INTEGER (column, U"Column", U"1") |
| 335 |
INTEGER (secondaryColumn, U"Secondary column", U"0") |
| 336 |
OK |
| 337 |
DO |
| 338 |
MODIFY_EACH (TableOfReal) |
| 339 |
TableOfReal_sortByColumn (me, column, secondaryColumn); |
| 340 |
MODIFY_EACH_END |
| 341 |
} |
| 342 |
|
| 343 |
FORM (MODIFY_TableOfReal_sortByLabel, U"Sort rows by label", nullptr) { |
| 344 |
COMMENT (U"Secondary sorting keys:") |
| 345 |
INTEGER (column1, U"Column1", U"1") |
| 346 |
INTEGER (column2, U"Column2", U"0") |
| 347 |
OK |
| 348 |
DO |
| 349 |
MODIFY_EACH (TableOfReal) |
| 350 |
TableOfReal_sortByLabel (me, column1, column2); |
| 351 |
MODIFY_EACH_END |
| 352 |
} |
| 353 |
|
| 354 |
// MARK: Extract |
| 355 |
|
| 356 |
DIRECT (NEW_TableOfReal_extractColumnLabelsAsStrings) { |
| 357 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 358 |
autoStrings result = TableOfReal_extractColumnLabelsAsStrings (me); |
| 359 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 360 |
} |
| 361 |
|
| 362 |
FORM (NEW_TableOfReal_extractColumnsByNumber, U"Extract columns by number", nullptr) { |
| 363 |
COMMENT (U"Create a new TableOfReal from the following existing columns.") |
| 364 |
NATURALVECTOR (columnNumbers, U"Column numbers", RANGES_, U"1 2") |
| 365 |
OK |
| 366 |
DO |
| 367 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 368 |
autoTableOfReal result = TableOfReal_extractColumnsByNumber (me, columnNumbers); |
| 369 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_cols") |
| 370 |
} |
| 371 |
|
| 372 |
FORM (NEW_TableOfReal_extractColumnsWhere, U"Extract columns where", nullptr) { |
| 373 |
COMMENT (U"Extract all columns with at least one cell where the following condition holds.") |
| 374 |
FORMULA (condition, U"Condition", U"col mod 3 = 0 ; this example extracts every third column") |
| 375 |
OK |
| 376 |
DO |
| 377 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 378 |
autoTableOfReal result = TableOfReal_extractColumnsWhere (me, condition, interpreter); |
| 379 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_cols") |
| 380 |
} |
| 381 |
|
| 382 |
FORM (NEW_TableOfReal_extractColumnsWhoseLabel, U"Extract columns whose label...", nullptr) { |
| 383 |
OPTIONMENU_ENUM (kMelder_string, extractAllColumnsWhoseLabel, |
| 384 |
U"Extract all columns whose label...", kMelder_string::DEFAULT) |
| 385 |
SENTENCE (___theText, U"...the text", U"a") |
| 386 |
OK |
| 387 |
DO |
| 388 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 389 |
autoTableOfReal result = TableOfReal_extractColumnsWhoseLabel (me, extractAllColumnsWhoseLabel, ___theText); |
| 390 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_", ___theText) |
| 391 |
} |
| 392 |
|
| 393 |
FORM (NEW_TableOfReal_extractColumnsWhereRow, U"Extract columns where row", nullptr) { |
| 394 |
NATURAL (extractAllColumnsWhereRow, U"Extract all columns where row...", U"1") |
| 395 |
OPTIONMENU_ENUM (kMelder_number, ___is___, U"...is...", kMelder_number::DEFAULT) |
| 396 |
REAL (___theValue, U"...the value", U"0.0") |
| 397 |
OK |
| 398 |
DO |
| 399 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 400 |
autoTableOfReal result = TableOfReal_extractColumnsWhereRow (me, extractAllColumnsWhereRow, ___is___, ___theValue); |
| 401 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_", extractAllColumnsWhereRow, U"_", Melder_iround (___theValue)) |
| 402 |
} |
| 403 |
|
| 404 |
DIRECT (NEW_TableOfReal_extractRowLabelsAsStrings) { |
| 405 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 406 |
autoStrings result = TableOfReal_extractRowLabelsAsStrings (me); |
| 407 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 408 |
} |
| 409 |
|
| 410 |
FORM (NEW_TableOfReal_extractRowsByNumber, U"Extract rows by number", nullptr) { |
| 411 |
COMMENT (U"Create a new TableOfReal from the following existing rows.") |
| 412 |
NATURALVECTOR (rowNumbers, U"Row numbers", RANGES_, U"1 2") |
| 413 |
OK |
| 414 |
DO |
| 415 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 416 |
autoTableOfReal result = TableOfReal_extractRowsByNumber (me, rowNumbers); |
| 417 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_rows") |
| 418 |
} |
| 419 |
|
| 420 |
FORM (NEW_TableOfReal_extractRowsWhere, U"Extract rows where", nullptr) { |
| 421 |
COMMENT (U"Extract all rows with at least one cell where the following condition holds.") |
| 422 |
FORMULA (condition, U"Condition", U"row mod 3 = 0 ; this example extracts every third row") |
| 423 |
OK |
| 424 |
DO |
| 425 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 426 |
autoTableOfReal result = TableOfReal_extractRowsWhere (me, condition, interpreter); |
| 427 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_rows") |
| 428 |
} |
| 429 |
|
| 430 |
FORM (NEW_TableOfReal_extractRowsWhereColumn, U"Extract rows where column", nullptr) { |
| 431 |
NATURAL (extractAllRowsWhereColumn, U"Extract all rows where column...", U"1") |
| 432 |
OPTIONMENU_ENUM (kMelder_number, ___is___, U"...is...", kMelder_number::DEFAULT) |
| 433 |
REAL (___theValue, U"...the value", U"0.0") |
| 434 |
OK |
| 435 |
DO |
| 436 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 437 |
autoTableOfReal result = TableOfReal_extractRowsWhereColumn (me, extractAllRowsWhereColumn, ___is___, ___theValue); |
| 438 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_", extractAllRowsWhereColumn, U"_", Melder_iround (___theValue)) |
| 439 |
} |
| 440 |
|
| 441 |
FORM (NEW_TableOfReal_extractRowsWhoseLabel, U"Extract rows whose label", nullptr) { |
| 442 |
OPTIONMENU_ENUM (kMelder_string, extractAllRowsWhoseLabel, |
| 443 |
U"Extract all rows whose label...", kMelder_string::DEFAULT) |
| 444 |
SENTENCE (___theText, U"...the text", U"a") |
| 445 |
OK |
| 446 |
DO |
| 447 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 448 |
autoTableOfReal result = TableOfReal_extractRowsWhoseLabel (me, extractAllRowsWhoseLabel, ___theText); |
| 449 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_", ___theText) |
| 450 |
} |
| 451 |
|
| 452 |
// MARK: Convert |
| 453 |
|
| 454 |
DIRECT (NEW1_TablesOfReal_append) { |
| 455 |
COMBINE_ALL_TO_ONE (TableOfReal) |
| 456 |
autoTableOfReal result = TablesOfReal_appendMany (& list); |
| 457 |
COMBINE_ALL_TO_ONE_END (U"appended") |
| 458 |
} |
| 459 |
|
| 460 |
DIRECT (NEW_TableOfReal_to_Matrix) { |
| 461 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 462 |
autoMatrix result = TableOfReal_to_Matrix (me); |
| 463 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 464 |
} |
| 465 |
|
| 466 |
FORM (NEW_TableOfReal_to_Table, U"TableOfReal: To Table", nullptr) { |
| 467 |
SENTENCE (labelOfFirstColumn, U"Label of first column", U"rowLabel") |
| 468 |
OK |
| 469 |
DO |
| 470 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 471 |
autoTable result = TableOfReal_to_Table (me, labelOfFirstColumn); |
| 472 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 473 |
} |
| 474 |
|
| 475 |
FORM_SAVE (SAVE_TableOfReal_writeToHeaderlessSpreadsheetFile, U"Save TableOfReal as spreadsheet", 0, U"txt") { |
| 476 |
SAVE_ONE (TableOfReal, U"save the selected TableOfReal object to the headerless spreadsheet file") |
| 477 |
TableOfReal_writeToHeaderlessSpreadsheetFile (me, file); |
| 478 |
SAVE_ONE_END |
| 479 |
} |
| 480 |
|
| 481 |
void praat_TableOfReal_init (ClassInfo klas) { |
| 482 |
if (klas == classTableOfReal) |
| 483 |
praat_addAction1 (classTableOfReal, 0, U"TableOfReal help", nullptr, 0, HELP_TableOfReal_help); |
| 484 |
praat_addAction1 (klas, 1, U"Save as headerless spreadsheet file... || Write to headerless spreadsheet file...", |
| 485 |
nullptr, 0, SAVE_TableOfReal_writeToHeaderlessSpreadsheetFile); |
| 486 |
praat_addAction1 (klas, 0, U"Draw -", nullptr, 0, nullptr); |
| 487 |
praat_addAction1 (klas, 0, U"Draw as numbers...", |
| 488 |
nullptr, 1, GRAPHICS_TableOfReal_drawAsNumbers); |
| 489 |
praat_addAction1 (klas, 0, U"Draw as numbers if...", |
| 490 |
nullptr, 1, GRAPHICS_TableOfReal_drawAsNumbers_if); |
| 491 |
praat_addAction1 (klas, 0, U"Draw as squares...", |
| 492 |
nullptr, 1, GRAPHICS_TableOfReal_drawAsSquares); |
| 493 |
praat_addAction1 (klas, 0, U"-- draw lines --", |
| 494 |
nullptr, 1, nullptr); |
| 495 |
praat_addAction1 (klas, 0, U"Draw vertical lines...", |
| 496 |
nullptr, 1, GRAPHICS_TableOfReal_drawVerticalLines); |
| 497 |
praat_addAction1 (klas, 0, U"Draw horizontal lines...", |
| 498 |
nullptr, 1, GRAPHICS_TableOfReal_drawHorizontalLines); |
| 499 |
praat_addAction1 (klas, 0, U"Draw left and right lines...", |
| 500 |
nullptr, 1, GRAPHICS_TableOfReal_drawLeftAndRightLines); |
| 501 |
praat_addAction1 (klas, 0, U"Draw top and bottom lines...", |
| 502 |
nullptr, 1, GRAPHICS_TableOfReal_drawTopAndBottomLines); |
| 503 |
praat_addAction1 (klas, 0, U"Query -", nullptr, 0, nullptr); |
| 504 |
praat_addAction1 (klas, 1, U"Get number of rows", |
| 505 |
nullptr, 1, INTEGER_TableOfReal_getNumberOfRows); |
| 506 |
praat_addAction1 (klas, 1, U"Get number of columns", |
| 507 |
nullptr, 1, INTEGER_TableOfReal_getNumberOfColumns); |
| 508 |
praat_addAction1 (klas, 1, U"Get row label...", |
| 509 |
nullptr, 1, STRING_TableOfReal_getRowLabel); |
| 510 |
praat_addAction1 (klas, 1, U"Get column label...", |
| 511 |
nullptr, 1, STRING_TableOfReal_getColumnLabel); |
| 512 |
praat_addAction1 (klas, 1, U"Get row index...", |
| 513 |
nullptr, 1, INTEGER_TableOfReal_getRowIndex); |
| 514 |
praat_addAction1 (klas, 1, U"Get column index...", |
| 515 |
nullptr, 1, INTEGER_TableOfReal_getColumnIndex); |
| 516 |
praat_addAction1 (klas, 1, U"-- get value --", |
| 517 |
nullptr, 1, nullptr); |
| 518 |
praat_addAction1 (klas, 1, U"Get value...", |
| 519 |
nullptr, 1, REAL_TableOfReal_getValue); |
| 520 |
if (klas == classTableOfReal) { |
| 521 |
praat_addAction1 (klas, 1, U"-- get statistics --", |
| 522 |
nullptr, 1, nullptr); |
| 523 |
praat_addAction1 (klas, 1, U"Get column mean (index)...", |
| 524 |
nullptr, 1, REAL_TableOfReal_getColumnMean_index); |
| 525 |
praat_addAction1 (klas, 1, U"Get column mean (label)...", |
| 526 |
nullptr, 1, REAL_TableOfReal_getColumnMean_label); |
| 527 |
praat_addAction1 (klas, 1, U"Get column stdev (index)...", |
| 528 |
nullptr, 1, REAL_TableOfReal_getColumnStdev_index); |
| 529 |
praat_addAction1 (klas, 1, U"Get column stdev (label)...", |
| 530 |
nullptr, 1, REAL_TableOfReal_getColumnStdev_label); |
| 531 |
} |
| 532 |
praat_addAction1 (klas, 0, U"Modify -", nullptr, 0, nullptr); |
| 533 |
praat_addAction1 (klas, 0, U"Formula...", |
| 534 |
nullptr, 1, MODIFY_TableOfReal_formula); |
| 535 |
praat_addAction1 (klas, 0, U"Set value...", |
| 536 |
nullptr, 1, MODIFY_TableOfReal_setValue); |
| 537 |
praat_addAction1 (klas, 0, U"Sort by label...", |
| 538 |
nullptr, 1, MODIFY_TableOfReal_sortByLabel); |
| 539 |
praat_addAction1 (klas, 0, U"Sort by column...", |
| 540 |
nullptr, 1, MODIFY_TableOfReal_sortByColumn); |
| 541 |
praat_addAction1 (klas, 0, U"-- structure --", |
| 542 |
nullptr, 1, nullptr); |
| 543 |
praat_addAction1 (klas, 0, U"Remove row (index)...", |
| 544 |
nullptr, 1, MODIFY_TableOfReal_removeRow); |
| 545 |
praat_addAction1 (klas, 0, U"Remove column (index)...", |
| 546 |
nullptr, 1, MODIFY_TableOfReal_removeColumn); |
| 547 |
praat_addAction1 (klas, 0, U"Insert row (index)...", |
| 548 |
nullptr, 1, MODIFY_TableOfReal_insertRow); |
| 549 |
praat_addAction1 (klas, 0, U"Insert column (index)...", |
| 550 |
nullptr, 1, MODIFY_TableOfReal_insertColumn); |
| 551 |
praat_addAction1 (klas, 0, U"-- set --", |
| 552 |
nullptr, 1, nullptr); |
| 553 |
praat_addAction1 (klas, 0, U"Set row label (index)...", |
| 554 |
nullptr, 1, MODIFY_TableOfReal_setRowLabel_index); |
| 555 |
praat_addAction1 (klas, 0, U"Set row label (label)...", |
| 556 |
nullptr, 1, MODIFY_TableOfReal_setRowLabel_label); |
| 557 |
praat_addAction1 (klas, 0, U"Set column label (index)...", |
| 558 |
nullptr, 1, MODIFY_TableOfReal_setColumnLabel_index); |
| 559 |
praat_addAction1 (klas, 0, U"Set column label (label)...", |
| 560 |
nullptr, 1, MODIFY_TableOfReal_setColumnLabel_label); |
| 561 |
praat_addAction1 (klas, 0, U"Synthesize -", nullptr, 0, nullptr); |
| 562 |
praat_addAction1 (klas, 0, U"Append", |
| 563 |
nullptr, 1, NEW1_TablesOfReal_append); |
| 564 |
praat_addAction1 (klas, 0, U"Extract part -", nullptr, 0, nullptr); |
| 565 |
praat_addAction1 (klas, 0, U"Extract rows by number... || Extract row ranges...", |
| 566 |
nullptr, 1, NEW_TableOfReal_extractRowsByNumber); |
| 567 |
praat_addAction1 (klas, 0, U"Extract rows where column...", |
| 568 |
nullptr, 1, NEW_TableOfReal_extractRowsWhereColumn); |
| 569 |
praat_addAction1 (klas, 0, U"Extract rows whose label... || Extract rows where label...", |
| 570 |
nullptr, 1, NEW_TableOfReal_extractRowsWhoseLabel); |
| 571 |
praat_addAction1 (klas, 0, U"Extract rows where...", |
| 572 |
nullptr, 1, NEW_TableOfReal_extractRowsWhere); |
| 573 |
praat_addAction1 (klas, 0, U"Extract columns by number... || Extract column ranges...", |
| 574 |
nullptr, 1, NEW_TableOfReal_extractColumnsByNumber); |
| 575 |
praat_addAction1 (klas, 0, U"Extract columns where row...", |
| 576 |
nullptr, 1, NEW_TableOfReal_extractColumnsWhereRow); |
| 577 |
praat_addAction1 (klas, 0, U"Extract columns whose label... || Extract columns where label...", |
| 578 |
nullptr, 1, NEW_TableOfReal_extractColumnsWhoseLabel); // alternative GuiMenu_DEPRECATED_2021 |
| 579 |
praat_addAction1 (klas, 0, U"Extract columns where...", |
| 580 |
nullptr, 1, NEW_TableOfReal_extractColumnsWhere); |
| 581 |
praat_addAction1 (klas, 0, U"Extract -", nullptr, 0, nullptr); |
| 582 |
praat_addAction1 (klas, 0, U"Extract row labels as Strings", |
| 583 |
nullptr, 1, NEW_TableOfReal_extractRowLabelsAsStrings); |
| 584 |
praat_addAction1 (klas, 0, U"Extract column labels as Strings", |
| 585 |
nullptr, 1, NEW_TableOfReal_extractColumnLabelsAsStrings); |
| 586 |
praat_addAction1 (klas, 0, U"Convert -", nullptr, 0, nullptr); |
| 587 |
praat_addAction1 (klas, 0, U"To Table...", |
| 588 |
nullptr, 1, NEW_TableOfReal_to_Table); |
| 589 |
praat_addAction1 (klas, 0, U"To Matrix", |
| 590 |
nullptr, 1, NEW_TableOfReal_to_Matrix); |
| 591 |
} |
| 592 |
|
| 593 |
/* End of file praat_TableOfReal.cpp */ |