find a field in the input level by a part of its name or its full name return value: index of first element of field namePartial gives the name/partial to search for nEl specifies the maximum number of input elements (for checking valid range of field index) -1 will enable autodetection from reader_->getLevelN(); N , optional, a pointer to variable (long) that will be filled with the number of e
| 391 | // the index of the current field will be the value of *more |
| 392 | // *fieldIdx: index of field (not element!) |
| 393 | long cDataProcessor::findField(const char *namePartial, int fullName, long *N, |
| 394 | const char **fieldName, long nEl, int *more, int *fieldIdx) |
| 395 | { |
| 396 | const FrameMetaInfo * fmeta = reader_->getFrameMetaInfo(); |
| 397 | if (fmeta == NULL) |
| 398 | return -1; |
| 399 | int ri=0; |
| 400 | long idx; |
| 401 | if (fullName) { |
| 402 | idx = fmeta->findField( namePartial , &ri, more ); |
| 403 | } else { |
| 404 | idx = fmeta->findFieldByPartialName( namePartial , &ri, more ); |
| 405 | } |
| 406 | long nInput, inputStart; |
| 407 | const char *inputName; |
| 408 | if (nEl <= 0) |
| 409 | nEl = reader_->getLevelN(); |
| 410 | if (idx < 0) { |
| 411 | nInput = nEl; |
| 412 | inputStart = 0; |
| 413 | inputName = NULL; |
| 414 | if (fullName) { |
| 415 | SMILE_IWRN(4,"Requested input field '%s' not found, check your config! Defaulting to use first field. Available fields:", namePartial); |
| 416 | } else { |
| 417 | SMILE_IWRN(4,"Requested input field matching pattern '*%s*' not found, check your config! Defaulting to use first field. Available fields:", namePartial); |
| 418 | } |
| 419 | if (SMILE_LOG_GLOBAL != NULL && SMILE_LOG_GLOBAL->getLogLevel_wrn() >= 4) |
| 420 | fmeta->printFieldNames(); |
| 421 | //SMILE_IWRN(2,"Requested input field '*%s*' not found, defaulting to use full input vector!",namePartial); |
| 422 | } else { |
| 423 | inputStart = fmeta->fieldToElementIdx( idx ) + ri; |
| 424 | nInput = fmeta->field[idx].N; |
| 425 | inputName = fmeta->field[idx].name; |
| 426 | } |
| 427 | // FIXME: this function should return -1 if the field is not found and everyone using |
| 428 | // this function should check for a valid index! |
| 429 | |
| 430 | if ((nInput+inputStart > nEl)&&(nEl>0)) nInput = nEl-inputStart; |
| 431 | if (inputStart < 0) inputStart = 0; |
| 432 | |
| 433 | if (fieldIdx != NULL) *fieldIdx = idx; |
| 434 | if (N != NULL) *N = nInput; |
| 435 | if (fieldName != NULL) *fieldName = inputName; |
| 436 | return inputStart; |
| 437 | } |
| 438 | |
| 439 | // |
| 440 | // search for an element by its partial name (if multiple matches are found, only the first is returned) |
no test coverage detected