FeatureNumList::VectorIntType* FeatureNumList::StrToUInt16Vetor (const KKStr& s) { bool valid = true; VectorIntType* results = new VectorUint16 (); KKStrParser parser (s); parser.TrimWhiteSpace (" "); while (parser.MoreTokens ()) { KKStr field = parser.GetNextToken (",\t"); if (field.Empty ()) continue; auto dashPos = field.LocateCharacter ('-'); if (!dashPos) { kkint32 n = field.ToInt32 (); if ((n < 0) || ((kkuint32)n > maxIntType)) { valid = false; break; } results->push_back ((IntType)n); } else { // We are looking at a range kkint32 startNum = field.SubStrSeg (0, dashPos).ToInt32 (); kkint32 endNum = field.SubStrPart (dashPos + 1).ToInt32 (); if ((startNum > endNum) || (startNum < 0) || ((kkuint32)endNum > maxIntType)) { valid = false; break; } for (kkint32 z = startNum; z <= endNum; ++z) results->push_back ((IntType)z); } } if (!valid) { delete results; results = NULL; } else { sort (results->begin (), results->end ()); } return results; } /* StrToUInt16Vetor */
PointListPtr PointList::FromDelStr (const KKStr& _s) { PointListPtr result = new PointList (true); KKStr s (_s); s.TrimLeft (); while (s.Len () > 0) { char nextCh = s.FirstChar (); char endPairChar = 0; if (nextCh == '[') endPairChar = ']'; else if (nextCh == '(') endPairChar = ')'; else { // Not Bracketed. endPairChar = 0; kkint16 row = (kkint16)s.ExtractTokenInt (",\t\n\t"); kkint16 col = (kkint16)s.ExtractTokenInt (",\t\n\t"); result->PushOnBack (new Point (row, col)); } if (endPairChar != 0) { KKStr pairStr = ""; auto idx = s.Find (endPairChar); if (idx) { pairStr = s.SubStrSeg (0, idx); s = s.SubStrPart (idx + 1); } else { pairStr = s; s = ""; } kkint16 row = (kkint16)pairStr.ExtractTokenInt (","); kkint16 col = (kkint16)pairStr.ExtractTokenInt (","); result->PushOnBack (new Point (row, col)); nextCh = s.FirstChar (); if ((nextCh == ',') || (nextCh == '\n') || (nextCh == '\r') || (nextCh == '\t')) s.ChopFirstChar (); } s.TrimLeft (); } return result; } /* FromDelStr */
/**************************************************************************************** * DetermineClassFromFileName * * Given an Image File Name(fileName) will return and mlClass. Will use the * path name in fileName to determine class. If the class does not exist in * mlClasses, will create a new instance and add it to mlClasses. * * After talking to the user it has come to light that the first sub-directory in * a path will dictate what class he/she feels a image belongs to. * Ex: * .../Protista/ * .../Protista/SubDir1 * .../Trichodesmium * .../Trichodesmium/SubDir1 * .../Trichodesmium/SubDir2 * * The idea is that when trying to determine what class a image really is we look * at the first sub-dir name in the path. We may also have to deal with seq-num's * as part of the name, in that case we strip the _ and following numbers from the * name to get the correct class name. ****************************************************************************************/ MLClassPtr OurNeighbors::DetermineClassFromFileName (const KKStr& fileName) { KKStr filename_copy = fileName; // If there are no path separator characters('\' or '/') characters in name // then we will not be able to determine the class. auto x = osLocateFirstSlashChar (filename_copy); if (!x || (x.value () < 1)) return mlClasses->GetUnKnownClass (); KKStr className = filename_copy.SubStrSeg (0, x); // now lets get rid of any possible trailing seq number. // We are assuming that a underscore{"_") character separates the calcs name from the seq number. // So if there is an underscore character, and all the characters to the right of it are // underscore characters, then we will remove the underscore and the following numbers. x = className.LocateLastOccurrence ('_'); if (x) { // Now lets eliminate any sequence number in name // We are assuming that a underscore{"_") character separates the class name from the seq number. // So if there is an underscore character, and all the characters to the right of it are // numeric characters, then we will remove the underscore and the following numbers. kkuint32 y = x.value () + 1; bool allFollowingCharsAreNumeric = true; while ((y < className.Len ()) && (allFollowingCharsAreNumeric)) { char ch = className[y]; allFollowingCharsAreNumeric = ((ch >= '0') && (ch <= '9')); y++; } if (allFollowingCharsAreNumeric) { className = className.SubStrSeg (0, x); } } // Now that we have a string with the class name, lets get a pointer // to a mlClass object from mlClasses , if none there then we get // to create a new class. MLClassPtr mlClass = mlClasses->GetMLClassPtr (className); return mlClass; } /* DetermineClassFromFileName */
void InstrumentDataGPS::ParseDegreeMinutesStr (const KKStr& str, double& degrees, double& minutes ) const { degrees = 0.0; minutes = 0.0; auto x = str.LocateCharacter ('.'); if (!x) return; KKStr degStr = str.SubStrSeg (0, x - 2); KKStr minStr = str.SubStrPart (x - 2); degrees = atof (degStr.Str ()); minutes = atof (minStr.Str ()); } /* ParseDegreeMinutesStr */
void ImportGPSDataGPGGA (const KKStr& fileName) { RunLog log; DataBasePtr dbConn = new DataBase (log); ifstream i (fileName.Str ()); if (!i.is_open ()) { log.Level (-1) << endl << endl << "ImpotrtGPSData Could not open file[" << fileName << "]" << endl << endl; return; } log.Level (10) << endl << endl << endl << endl << endl << "ImpotrtGPSData FileName[" << fileName << "]" << endl << endl << endl; char buff[20480]; bool firstPass = true; int lastMinute = 0; int linesRead = 0; KKStr ln (256); DateTime lastDateTime; while (i.getline (buff, sizeof (buff))) { linesRead++; ln = buff; ln.TrimLeft (); if (!ln.LocateStr ("GPGGA")) continue; VectorKKStr fields = ln.Parse (","); if (fields.size () < 8) continue; if (!fields[2].EqualIgnoreCase ("$GPGGA")) continue; /* 0 1 2 3 4 5 6 7 8 06/01/2010, 23:59:59.818, $GPGGA, 235958, 2840.927, N, 08828.458, W, 2, 09,22.10,0,M,,,14,0000*12 06/02/2010, 00:00:10.818, $GPGGA, 000009, 2840.931, N, 08828.482, W, 1, 09,0.89,0,M,,,,*2D 06/02/2010, 00:00:21.802, $GPGGA, 000020, 2840.929, N, 08828.505, W, 1, 09,0.89,0,M,,,,*21 06/02/2010, 00:00:31.818, $GPGGA, 000030, 2840.924, N, 08828.526, W, 1, 09,0.89,0,M,,,,*2C 06/02/2010, 00:00:42.818, $GPGGA, 000041, 2840.917, N, 08828.547, W, 1, 09,0.89,0,M,,,,*2D 06/02/2010, 00:00:53.802, $GPGGA, 000052, 2840.906, N, 08828.568, W, 1, 09,1.00,0,M,,,,*22 06/02/2010, 00:01:03.802, $GPGGA, 000102, 2840.895, N, 08828.585, W, 1, 09,0.89,0,M,,,,*2E 06/02/2010, 00:01:13.818, $GPGGA, 000112, 2840.883, N, 08828.600, W, 1, 09,0.89,0,M,,,,*26 */ KKStr dateStr = fields[0]; KKStr timeStr = fields[1]; KKStr latStr = fields[4]; KKStr logStr = fields[6]; auto x = latStr.LocateCharacter ('.'); if (!x) continue; KKStr latMinStr = latStr.SubStrPart (x - 2); KKStr latDegStr = latStr.SubStrSeg (0, x - 2); double latitude = latDegStr.ToDouble () + latMinStr.ToDouble () / 60.0; if (fields[5].EqualIgnoreCase ("S")) latitude = 0.0 - latitude; x = logStr.LocateCharacter ('.'); if (!x) continue; KKStr logMinStr = logStr.SubStrPart (x - 2); KKStr logDegStr = logStr.SubStrSeg (0, x - 2); double longitude = logDegStr.ToDouble () + logMinStr.ToDouble () / 60.0; if (fields[7].EqualIgnoreCase ("W")) longitude = 0.0 - longitude; DateType gmtDate (dateStr); TimeType gmtTime (timeStr); DateTime gmtDateTime (gmtDate, gmtTime); DateTime localTime = gmtDateTime; localTime.HoursAdd (-4); DateTime startDT = localTime; DateTime endDT = localTime; if (firstPass) { firstPass = false; startDT.SecondsAdd (-180); } else { DateTime deltaDT = localTime - lastDateTime; long deltaSecs = (long)deltaDT.Seconds (); startDT.SecondsAdd (-(deltaSecs / 2)); } endDT.SecondsAdd (30); if (gmtTime.Minute () != lastMinute) { lastMinute = gmtTime.Minute (); log.Level (10) << "LinesRead[" << linesRead << "] File[" << osGetRootName (fileName) << "] GMT Time[" << gmtDate.MMM_DD_YYYY () << " - " << gmtTime.HH_MM_SS () << "]" << endl; } if ((endDT.Month () < 6) && (endDT.Day () < 28)) { } else { dbConn->InstrumentDataUpdateLatitudeAndLongitude (startDT, endDT, latitude, longitude); } lastDateTime = localTime; } i.close (); delete dbConn; dbConn = NULL; } /* ImportGPSDataGPGGA */
void Configuration::LoadFile (RunLog& log) { log.Level (10) << "Configuration::LoadFile: " << fileName << endl; kkint32 lastLineNum = 0; if (fileName == "") { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** File-Name is blank" << endl << endl; FormatGood (false); return; } FILE* inFile = osFOPEN (fileName.Str (), "r"); if (!inFile) { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** Opening File: " << fileName << endl << endl; FormatGood (false); return; } char buff[10240]; kkint32 lineCount = 0; curSectionName = ""; ConfSectionPtr curSection = NULL; while (std::fgets (buff, sizeof (buff), inFile)) { lastLineNum++; KKStr line (buff); line.TrimRight (); line.TrimLeft (); StripOutAnyComments (line); log.Level (70) << line << endl; StripOutAnyComments (line); if (line.Empty ()) { // If we have a blank line, we do nothing. } else if (line.FirstChar () == '[') { // Looks like definition of new section. if (line.LastChar () == ']') { curSectionName = line.SubStrSeg (1, line.Len () - 2); curSectionName.TrimLeft (); curSectionName.TrimRight (); curSectionName.Upper (); curSection = new ConfSection (curSectionName, lastLineNum); sections->AddConfSection (curSection); log.Level (30) << "LoadFile SectionName[" << curSectionName << "]." << endl; } else { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** LineNumber[" << lastLineNum << "] Improper Section Name[" << line << "]." << endl << endl; formatGood = false; } } else { if (!curSection) { log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** Format Error LineNumber[" << lastLineNum << "]" << endl << " No Section Defined." << endl << endl; formatGood = false; curSectionName = "GLOBAL"; curSection = new ConfSection (curSectionName, lastLineNum); sections->AddConfSection (curSection); } auto equalIdx = line.LocateCharacter ('='); if (!equalIdx) { // We have a improperly formated line. log.Level (-1) << endl << "Configuration::LoadFile ***ERROR*** LineNumber[" << lastLineNum << "] Improperly Formated Line[" << line << "]." << endl; formatGood = false; } else { KKStr settingName (line.SubStrSeg (0, equalIdx)); settingName.TrimLeft (); settingName.TrimRight (); settingName.Upper (); KKStr settingValue (line.SubStrPart (equalIdx + 1)); settingValue.TrimLeft (); settingValue.TrimRight (); log.Level (30) << "LoadFile SectionName[" << curSectionName << "], " << "Setting[" << settingName << "], Value[" << settingValue << "]." << endl; curSection->AddSetting (settingName, settingValue, lastLineNum); } lineCount++; } } std::fclose (inFile); } /* LoadFile */
void StripOutAnyComments (KKStr& line) { auto idx = line.LocateStr("//"); if (idx) line = line.SubStrSeg(0, idx); } /* StripOutAnyComments */