Commits
Benjamin Bean authored a384380c7e0 Merge
204 204 | _fileVersion = CURRENT_VERSION; |
205 205 | } |
206 206 | } |
207 207 | |
208 208 | void RegionTextParser::_parse(const String& contents, const String& fileDesc, bool requireImageRegion) { |
209 209 | _log->origin(LogOrigin("AsciiRegionFileParser", __func__)); |
210 210 | static const Regex startAnn("^ann[[:space:]]+"); |
211 211 | static const Regex startDiff("^-[[:space:]]*"); |
212 212 | static const Regex startGlobal("^global[[:space:]]+"); |
213 213 | AnnotationBase::unitInit(); |
214 - | /*Vector<String>*/ auto lines = stringToVector(contents, '\n'); |
214 + | auto lines = stringToVector(contents, '\n'); |
215 215 | uInt lineCount = 0; |
216 - | /*std::pair<Quantity, Quantity>*/ auto qFreqs = _overridingFreqRange |
216 + | auto qFreqs = _overridingFreqRange |
217 217 | ? std::pair<Quantity, Quantity>( |
218 218 | Quantity(_overridingFreqRange->first.getValue().getValue(), "Hz"), |
219 219 | Quantity(_overridingFreqRange->second.getValue().getValue(), "Hz") |
220 220 | ) |
221 221 | : std::pair<Quantity, Quantity>(Quantity(0), Quantity(0)); |
222 - | for(/*Vector<String>::iterator*/ auto iter=lines.cbegin(); iter!=lines.cend(); ++iter) { |
222 + | for(auto iter=lines.cbegin(); iter!=lines.cend(); ++iter) { |
223 223 | ++lineCount; |
224 224 | Bool annOnly = false; |
225 225 | ostringstream preambleoss; |
226 226 | preambleoss << fileDesc + " line# " << lineCount << ": "; |
227 - | /*String*/ const auto preamble = preambleoss.str(); |
227 + | const auto preamble = preambleoss.str(); |
228 228 | Bool difference = false; |
229 229 | iter->trim(); |
230 230 | if ( |
231 231 | iter->empty() || iter->startsWith("#") |
232 232 | ) { |
233 233 | // ignore comments and blank lines |
234 234 | _addLine(AsciiAnnotationFileLine(*iter)); |
235 235 | continue; |
236 236 | } |
237 237 | auto consumeMe = *iter; |
271 271 | newParams[AnnotationBase::RANGE].stringVal, preamble |
272 272 | ); |
273 273 | } |
274 274 | *_log << LogIO::NORMAL << preamble << "global found" << LogIO::POST; |
275 275 | continue; |
276 276 | } |
277 277 | // now look for per-line shapes and annotations |
278 278 | Vector<Quantity> qDirs; |
279 279 | vector<Quantity> quantities; |
280 280 | String textString; |
281 - | /*AnnotationBase::Type */ const auto annType = _getAnnotationType( |
281 + | const auto annType = _getAnnotationType( |
282 282 | qDirs, quantities, textString, consumeMe, preamble |
283 283 | ); |
284 284 | ParamSet currentParamSet = _getCurrentParamSet( |
285 285 | spectralParmsUpdated, newParams, consumeMe, preamble |
286 286 | ); |
287 287 | if ( |
288 288 | newParams.find(AnnotationBase::LABEL) == newParams.end() |
289 289 | || newParams[AnnotationBase::LABEL].stringVal.empty() |
290 290 | ) { |
291 291 | if (newParams.find(AnnotationBase::LABELCOLOR) != newParams.end()) { |
317 317 | } |
318 318 | else if( |
319 319 | _currentGlobals.find(AnnotationBase::RANGE) |
320 320 | == _currentGlobals.end() |
321 321 | || ! _currentGlobals.at(AnnotationBase::RANGE).freqRange |
322 322 | ) { |
323 323 | // no global frequency range, so use entire freq span |
324 324 | qFreqs = std::pair<Quantity, Quantity>(Quantity(0), Quantity(0)); |
325 325 | } |
326 326 | } |
327 - | /*ParamSet*/ auto globalsLessLocal = _currentGlobals; |
327 + | auto globalsLessLocal = _currentGlobals; |
328 328 | for ( |
329 - | /*ParamSet::const_iterator*/ auto iter=newParams.cbegin(); |
329 + | auto iter=newParams.cbegin(); |
330 330 | iter != newParams.cend(); ++iter |
331 331 | ) { |
332 332 | AnnotationBase::Keyword key = iter->first; |
333 333 | if (globalsLessLocal.find(key) != globalsLessLocal.end()) { |
334 334 | globalsLessLocal.erase(key); |
335 335 | } |
336 336 | } |
337 337 | _globalKeysToApply.resize(globalsLessLocal.size(), false); |
338 338 | uInt i = 0; |
339 339 | for ( |
378 378 | const static Regex startTwoPair("^" + sTwoPair); |
379 379 | const static Regex startOnePairAndText("^" + sOnePairAndText); |
380 380 | const static String sTwoPairOneSingle = bTwoPair |
381 381 | + ",[[:space:]]*[^\\[,]+[[:space:]]*\\]"; |
382 382 | const static Regex startTwoPairOneSingle("^" + sTwoPairOneSingle); |
383 383 | const static Regex startOnePairOneSingle("^" + sOnePairOneSingle); |
384 384 | consumeMe.trim(); |
385 385 | String tmp = consumeMe.through(Regex("[[:alpha:]]+")); |
386 386 | consumeMe.del(0, (Int)tmp.length()); |
387 387 | consumeMe.trim(); |
388 - | AnnotationBase::Type annotationType = AnnotationBase::typeFromString(tmp); |
388 + | auto annotationType = AnnotationBase::typeFromString(tmp); |
389 389 | std::pair<Quantity, Quantity> myPair; |
390 390 | switch(annotationType) { |
391 391 | case AnnotationBase::RECT_BOX: |
392 392 | ThrowIf( |
393 393 | ! consumeMe.contains(startTwoPair), |
394 394 | preamble + "Illegal box specification " |
395 395 | ); |
396 396 | qDirs = _extractNQuantityPairs(consumeMe, preamble); |
397 397 | |
398 398 | if (qDirs.size() != 4) { |
572 572 | const CoordinateSystem& csys, |
573 573 | std::shared_ptr<std::pair<MFrequency, MFrequency> > overridingFreqRange, |
574 574 | std::shared_ptr<Vector<Stokes::StokesTypes> > overridingCorrRange |
575 575 | ) { |
576 576 | ParamSet parms; |
577 577 | spectralParmsUpdated = false; |
578 578 | auto consumeMe = text; |
579 579 | // get key-value pairs on the line |
580 580 | while (consumeMe.size() > 0) { |
581 581 | ParamValue paramValue; |
582 - | AnnotationBase::Keyword key = AnnotationBase::UNKNOWN_KEYWORD; |
582 + | auto key = AnnotationBase::UNKNOWN_KEYWORD; |
583 583 | consumeMe.trim(); |
584 584 | consumeMe.ltrim(','); |
585 585 | consumeMe.trim(); |
586 586 | ThrowIf( |
587 587 | ! consumeMe.contains('='), |
588 588 | preamble + "Illegal extra characters on line (" |
589 589 | + consumeMe + "). Did you forget a '='?" |
590 590 | ); |
591 591 | const auto equalPos = consumeMe.find('='); |
592 592 | auto keyword = consumeMe.substr(0, equalPos); |
710 710 | } |
711 711 | paramValue.boolVal = (v == "true" || v == "t"); |
712 712 | } |
713 713 | else if (keyword == "labelcolor") { |
714 714 | key = AnnotationBase::LABELCOLOR; |
715 715 | } |
716 716 | else if (keyword == "labelpos") { |
717 717 | key = AnnotationBase::LABELPOS; |
718 718 | } |
719 719 | else if (keyword == "labeloff") { |
720 - | String v = paramValue.stringVal; |
720 + | auto v = paramValue.stringVal; |
721 721 | static const String sInt("[-+]?[0-9]+"); |
722 722 | static const Regex rInt(sInt); |
723 723 | if ( |
724 724 | ! v.contains( |
725 725 | Regex( |
726 726 | sInt + "[[:space:]]*,[[:space:]]*" + sInt |
727 727 | ) |
728 728 | ) |
729 729 | ) { |
730 730 | log << preamble << "Illegal label offset specification \"" |
731 731 | << v << "\"" << LogIO::EXCEPTION; |
732 732 | } |
733 733 | // the brackets have been stripped, add them back to make it easier |
734 734 | // to parse with a method already in existence |
735 - | Vector<String> pair = _extractSinglePair("[" + v + "]"); |
735 + | auto pair = _extractSinglePair("[" + v + "]"); |
736 736 | paramValue.intVec = vector<Int>(); |
737 737 | |
738 738 | for ( |
739 - | Vector<String>::const_iterator iter=pair.begin(); |
739 + | auto iter=pair.begin(); |
740 740 | iter != pair.end(); ++iter |
741 741 | ) { |
742 742 | if (! iter->matches(rInt)) { |
743 743 | log << preamble << "Illegal label offset specification, " |
744 744 | << *iter << " is not an integer" << LogIO::EXCEPTION; |
745 745 | } |
746 746 | paramValue.intVec.push_back(String::toInt(*iter)); |
747 747 | } |
748 748 | key = AnnotationBase::LABELOFF; |
749 749 | } |
784 784 | preamble + "Rest frequency specified but velocity range not specified" |
785 785 | ); |
786 786 | return currentParams; |
787 787 | } |
788 788 | |
789 789 | std::pair<Quantity, Quantity> RegionTextParser::_quantitiesFromFrequencyString( |
790 790 | const String& freqString, const String& preamble |
791 791 | ) const { |
792 792 | // the brackets have been stripped, add them back to make it easier |
793 793 | // to parse with a method already in existence |
794 - | String cString = "[" + freqString + "]"; |
794 + | auto cString = "[" + freqString + "]"; |
795 795 | ThrowIf(! cString.contains(startOnePair), |
796 796 | preamble + "Incorrect spectral range specification (" |
797 797 | + freqString + ")" |
798 798 | ); |
799 799 | return _extractSingleQuantityPair( |
800 800 | cString, preamble |
801 801 | ); |
802 802 | } |
803 803 | |
804 804 | void RegionTextParser::_createAnnotation( |
813 813 | ) { |
814 814 | CountedPtr<AnnotationBase> annotation; |
815 815 | Vector<Stokes::StokesTypes> stokes(0); |
816 816 | if ( |
817 817 | currentParamSet.find(AnnotationBase::CORR) != currentParamSet.end() |
818 818 | && _csys.hasPolarizationCoordinate() |
819 819 | ) { |
820 820 | stokes.resize(currentParamSet.at(AnnotationBase::CORR).stokes.size()); |
821 821 | stokes = currentParamSet.at(AnnotationBase::CORR).stokes; |
822 822 | } |
823 - | String dirRefFrame = currentParamSet.at(AnnotationBase::COORD).stringVal; |
824 - | String freqRefFrame = currentParamSet.find(AnnotationBase::FRAME) == currentParamSet.end() |
823 + | auto dirRefFrame = currentParamSet.at(AnnotationBase::COORD).stringVal; |
824 + | auto freqRefFrame = currentParamSet.find(AnnotationBase::FRAME) == currentParamSet.end() |
825 825 | ? "" : currentParamSet.at(AnnotationBase::FRAME).stringVal; |
826 - | String doppler = currentParamSet.find(AnnotationBase::VELTYPE) == currentParamSet.end() |
826 + | auto doppler = currentParamSet.find(AnnotationBase::VELTYPE) == currentParamSet.end() |
827 827 | ? "" : currentParamSet.at(AnnotationBase::VELTYPE).stringVal; |
828 828 | Quantity restfreq; |
829 829 | if ( |
830 830 | currentParamSet.find(AnnotationBase::RESTFREQ) != currentParamSet.end() |
831 831 | && ! readQuantity( |
832 832 | restfreq, currentParamSet.at(AnnotationBase::RESTFREQ).stringVal |
833 833 | ) |
834 834 | ) { |
835 835 | *_log << preamble << "restfreq value " |
836 836 | << currentParamSet.at(AnnotationBase::RESTFREQ).stringVal << " is not " |
1001 1001 | } |
1002 1002 | annotation->setGlobals(_globalKeysToApply); |
1003 1003 | AsciiAnnotationFileLine line(annotation); |
1004 1004 | _addLine(line); |
1005 1005 | } |
1006 1006 | |
1007 1007 | Array<String> RegionTextParser::_extractTwoPairs(uInt& end, const String& string) const { |
1008 1008 | end = 0; |
1009 1009 | Int firstBegin = string.find('[', 1); |
1010 1010 | Int firstEnd = string.find(']', firstBegin); |
1011 - | String firstPair = string.substr(firstBegin, firstEnd - firstBegin + 1); |
1011 + | auto firstPair = string.substr(firstBegin, firstEnd - firstBegin + 1); |
1012 1012 | Int secondBegin = string.find('[', firstEnd); |
1013 1013 | Int secondEnd = string.find(']', secondBegin); |
1014 - | String secondPair = string.substr(secondBegin, secondEnd - secondBegin + 1); |
1015 - | Vector<String> first = _extractSinglePair(firstPair); |
1016 - | Vector<String> second = _extractSinglePair(secondPair); |
1014 + | auto secondPair = string.substr(secondBegin, secondEnd - secondBegin + 1); |
1015 + | auto first = _extractSinglePair(firstPair); |
1016 + | auto second = _extractSinglePair(secondPair); |
1017 1017 | |
1018 1018 | end = secondEnd; |
1019 1019 | Array<String> ret(IPosition(2, 2, 2)); |
1020 1020 | ret(IPosition(2, 0, 0)) = first[0]; |
1021 1021 | ret(IPosition(2, 0, 1)) = first[1]; |
1022 1022 | ret(IPosition(2, 1, 0)) = second[0]; |
1023 1023 | ret(IPosition(2, 1, 1)) = second[1]; |
1024 1024 | return ret; |
1025 1025 | } |
1026 1026 | |
1027 1027 | Vector<String> RegionTextParser::_extractSinglePair(const String& string) { |
1028 1028 | Char quotes[2]; |
1029 1029 | quotes[0] = '\''; |
1030 1030 | quotes[1] = '"'; |
1031 1031 | Int firstBegin = string.find('[', 0) + 1; |
1032 1032 | Int firstEnd = string.find(',', firstBegin); |
1033 - | String first = string.substr(firstBegin, firstEnd - firstBegin); |
1033 + | auto first = string.substr(firstBegin, firstEnd - firstBegin); |
1034 1034 | first.trim(); |
1035 1035 | first.trim(quotes, 2); |
1036 1036 | Int secondBegin = firstEnd + 1; |
1037 1037 | Int secondEnd = string.find(']', secondBegin); |
1038 - | String second = string.substr(secondBegin, secondEnd - secondBegin); |
1038 + | auto second = string.substr(secondBegin, secondEnd - secondBegin); |
1039 1039 | second.trim(); |
1040 1040 | second.trim(quotes, 2); |
1041 1041 | Vector<String> ret(2); |
1042 1042 | ret[0] = first; |
1043 1043 | ret[1] = second; |
1044 1044 | return ret; |
1045 1045 | } |
1046 1046 | |
1047 1047 | String RegionTextParser::_doLabel( |
1048 1048 | String& consumeMe, const String& preamble |