bool IACFile::ParsePressureSection(void) { wxString token; for (;;) { token = tokenFind(_T("8????")); if (!token.IsEmpty()) { // parse pressure system token // if( std::find(m_newlineTokens.begin(), m_newlineTokens.end(), m_tokensI) == m_newlineTokens.end() ) // wxMessageBox(_T("FP: ") + token); IACPressureSystem sys; sys.m_type = TokenNumber(token, 1, 1); sys.m_char = TokenNumber(token, 2, 1); sys.m_val = TokenNumber(token, 3, 2); sys.m_int = -1; // guess pressure offset if (sys.m_type == 1 && sys.m_val > 30) { sys.m_val += 900; } else if (sys.m_type == 5 && sys.m_val < 70) { sys.m_val += 1000; } else if (sys.m_val > 50) { sys.m_val += 900; } else { sys.m_val += 1000; } ParsePositions(sys, SECTION_PRESSURE); if (!m_tokens[m_tokensI].StartsWith(_T("8"))) ParseMovement(sys); m_pressure.Add(sys); } else { PushbackToken(); break; } } return true; }
bool IACFile::ParseSections(void) { wxString token; do { token = tokenFind(_T("999??"), true); if (!token.IsEmpty()) { //?? 00=>Pressure Systems // 11=>Frontal Systems // 22=>Isobars // 55=>Tropical Section int section = TokenNumber(token, 3, 2); switch (section) { case SECTION_PRESSURE: ParsePressureSection(); break; case SECTION_FRONTAL: ParseFrontalSection(); break; case SECTION_ISOBAR: ParseIsobarSection(); break; case SECTION_TROPICAL: ParseTropicalSection(); break; default: break; } } } while (!token.IsEmpty()); return true; }
bool IACFile::ParseMovement(IACSystem &sys) { wxString token; token = tokenFind(); if (!token.IsEmpty()) { // if invalid movement, ignore, push back int dir = 10 * TokenNumber(token, 1, 2); if (dir < 361) { sys.m_movement = TokenNumber(token, 0, 1); sys.m_direction = dir; sys.m_speed = TokenNumber(token, 3, 2); return true; } else { // invalif movement, push back PushbackToken(); return false; } } else { return false; } }
bool IACFile::ParseFrontalSection(void) { wxString token; for (;;) { token = tokenFind(_T("66???")); if (!token.IsEmpty()) { // parse pressure system token IACFrontalSystem sys; sys.m_type = TokenNumber(token, 2, 1); sys.m_val = -1; sys.m_int = TokenNumber(token, 3, 1); sys.m_char = TokenNumber(token, 4, 1); ParsePositions(sys, SECTION_FRONTAL); ParseMovement(sys); m_frontal.Add(sys); } else { // no more frontal systems. PushbackToken(); break; } } return true; }
bool IACFile::ParseTropicalSection(void) { wxString token; for (;;) { token = tokenFind(_T("55???")); if (!token.IsEmpty()) { // parse pressure system token IACTropicalSystem sys; sys.m_type = TokenNumber(token, 2, 1); sys.m_int = TokenNumber(token, 3, 1); sys.m_char = TokenNumber(token, 4, 1); // tropical system token MAY be followed by 555PP pressure token // in this case it is a tropical LOW or cyclone token = tokenFind(_T("555??")); if (token.IsEmpty()) { // no, push back token - it is a position PushbackToken(); } else { sys.m_val = TokenNumber(token, 3, 2); // guess pressure offset if (sys.m_val > 50) { sys.m_val += 900; } else { sys.m_val += 1000; } } ParsePositions(sys, SECTION_TROPICAL); ParseMovement(sys); m_tropical.Add(sys); } else { PushbackToken(); break; } } return true; }
bool IACFile::ParseIsobarSection(void) { wxString token; for (;;) { token = tokenFind(_T("44???")); if (!token.IsEmpty()) { IACIsobarSystem sys; sys.m_val = TokenNumber(token, 2, 3); if (sys.m_val < 500) { sys.m_val += 1000; } // Position ParsePositions(sys, SECTION_ISOBAR); m_isobars.Add(sys); } else { // no more frontal systems. PushbackToken(); break; } } return true; }
bool IACFile::ParsePositions(IACSystem &sys, int section) { wxString token; wxString lasttoken; bool firsttime = true; for (;;) { lasttoken = token; token = tokenFind(); bool morepos = true; // heuristic about when the last postion is read // either on illegal octant "4" or by a step of more than 1 // in octant int lastoct = TokenNumber(lasttoken, 0, 1); int oct = TokenNumber(token, 0, 1); int diff = abs(lastoct - oct); if (m_positionsType == POS_OCTANTS && oct == 4) { morepos = false; } else if (m_positionsType == POS_OCTANTS && (diff > 1) && (diff < 8)) { morepos = false; } else if (section == SECTION_FRONTAL && token.Matches(_T("66???")) && (m_positionsType == 88 || m_newlineTokens.size() < 10 // In case the file seems formatted with new lines, we take advantage of it and say // that new system must start on new line || std::find(m_newlineTokens.begin(), m_newlineTokens.end(), m_tokensI - 1) != m_newlineTokens.end())) { morepos = false; } else if (section == SECTION_PRESSURE && token.StartsWith(_T("8")) && (m_positionsType == 88 || m_newlineTokens.size() < 10 // In case the file seems formatted with new lines, we take advantage of it and say // that new system must start on new line || std::find(m_newlineTokens.begin(), m_newlineTokens.end(), m_tokensI - 1) != m_newlineTokens.end())) { morepos = false; } else if (token.Matches(_T("999??"))) { morepos = false; } else if (section == SECTION_ISOBAR && (token.Matches(_T("440??")) || token.Matches(_T("449??")) || token.Matches(_T("448??")))) { morepos = false; } else if (token == _T("19191")) { morepos = false; } /* // lets be even more strict and limit positions to // SW-Pacific if( !((oct == 6) || (oct == 7))) { morepos = false; } GeoPoint pos(token); // decode position // Position must be in the area bounded by 0S..35S and 120W/150E if( (pos.y < -35.0) || (pos.y > 0.0) || ((pos.x > -120.0) && (pos.x < 150)) ) { morepos = false; } */ if (!token.IsEmpty() && (firsttime || morepos)) { // ignore double entries following eachother if (token != lasttoken) { GeoPoint pos(token, m_positionsType); sys.m_positions.Add(pos); if (pos.x >= 0.0) { if (pos.x < m_minlone) m_minlone = pos.x; if (pos.x > m_maxlone) m_maxlone = pos.x; } else { if (pos.x < m_minlonw) m_minlonw = pos.x; if (pos.x > m_maxlonw) m_maxlonw = pos.x; } if (pos.y < m_minlat) m_minlat = pos.y; if (pos.y > m_maxlat) m_maxlat = pos.y; // if( pos.x < 0.1 && pos.x > -0.1 ) // wxMessageBox( token ); } else { // we got two identical position entries // meaning "no more" // stop parsing positions, but read one // more token to stay in sync if (m_positionsType == 88) token = tokenFind(); // break; } } else { break; } if (firsttime) { firsttime = false; } } PushbackToken(); if (token.IsEmpty()) { return false; } else { return true; } }
bool CSrScriptFile::Tokenize (void) { static const int CSP = 1; static const int CNM = 2; static const int CAL = 3; static const int COP = 4; static const int CDO = 5; static const int CCM = 6; static const int CST = 7; static const int CEN = 8; static const int CLN = 9; static const int CCN = 10; static const int s_CharTypes[256] = { CEN, 0, 0, 0, 0, 0, 0, 0, 0,CSP,CLN, 0, 0,CLN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CSP,COP,CST, 0, 0,COP,COP, 0,COP,COP,COP,COP,COP,COP,COP,COP, CNM,CNM,CNM,CNM,CNM,CNM,CNM,CNM,CNM,CNM, 0,CCM,COP,COP,COP, 0, 0,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL, CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,COP,CCN,COP, 0,CAL, 0,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL, CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CDO,COP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const char* pParse; bool Result; m_Tokens.Destroy(); srtimer_t TokenTimer; SrStartTimer(TokenTimer); pParse = m_ScriptText.c_str(); while (*pParse) { while (s_CharTypes[*pParse] == CSP) ++pParse; switch (s_CharTypes[*pParse]) { case CCN: ++pParse; while (s_CharTypes[*pParse] == CSP) ++pParse; while (s_CharTypes[*pParse] == CLN) ++pParse; while (s_CharTypes[*pParse] == CSP) ++pParse; break; case CLN: Result = TokenEOL(pParse); if (!Result) return false; break; break; case CNM: Result = TokenNumber(pParse); if (!Result) return false; break; case CAL: Result = TokenAlpha(pParse); if (!Result) return false; break; case CDO: Result = TokenDocument(pParse); if (!Result) return false; break; case CCM: Result = TokenComment(pParse); if (!Result) return false; break; case COP: Result = TokenOperator(pParse); if (!Result) return false; break; case CST: Result = TokenString(pParse); if (!Result) return false; break; default: AddSrGeneralError("Found unknown character '%c'(0x%02X) in script!", *pParse, *pParse); return false; } } srscripttoken_t* pToken = m_Tokens.AddNew(); pToken->Type = SR_TOKEN_END; SrEndTimer(TokenTimer, "Script Tokenized in "); //DumpTokens(); return true; }