/** Method to store ocean tide harmonics satData in this class' * satData map * * @param stationName String holding station name. * @param satData tideData structure holding the harmonics satData */ private void SetData(ref string stationName, ref TideData datas) { if (!OceanTidesData.ContainsKey(stationName)) { OceanTidesData.Add(stationName, datas); } }
/** Method to get the ocean tide harmonics corresponding to a * given station. * * @param station Station name (case is NOT relevant). * * @return A Matrix<double> of siw rows and eleven columns * containing tide harmonics M2, S2, N2, K2, K1, O1, P1, Q1, MF, * MM and SSA for amplitudes (radial, west, south, in meters) and * phases (radial, west, south, in degrees). If station is * not found, this method will return a matrix full of zeros. */ public ArrayMatrix GetTideHarmonics(string station) { //First, look if such station exist in satData map if (OceanTidesData.ContainsKey(station.ToUpper())) { TideData iter = OceanTidesData[station.ToUpper()]; return(iter.HarmonicsOfTideData); } else { // If not, return an empty harmonics matrix ArrayMatrix dummy = new ArrayMatrix(6, 11, 0.0); return(dummy); } }
// Method to store ocean tide harmonics satData in this class' satData map private void LoadData(string fn) { StreamReader sr = new StreamReader(fn); //Conter of valid satData lines int row = 0; //store here the station name string nameString = ""; //Declare structure to store tide harmonics satData TideData data = new TideData(); //Do this until end-of-file reached or something else happens bool isEnd = true; while (isEnd) { try { if (row > 6) { // If row>6, all station harmonics are already read, // so let's store tide satData in satData map SetData(ref nameString, ref data); //Clear harmonics satData data = new TideData(); //satData.harmonics = new Matrix(6, 11); //Reset counter to get satData from an additional station row = 0; } string line = sr.ReadLine(); if (line == null) { break; } //If line is too long, we throw an exception if (line.Length > 255) { throw new Exception("Line too long"); } //Let's find and strip comments,wherever they are if (StringUtil.firstWord(ref line)[0] == '$') { line = sr.ReadLine(); if (line == null) { break; } } int idx = line.IndexOf('$'); if (idx != -1)//说明找到 { line = line.Substring(0, idx); } //Remove trailing and leading blanks line = line.Trim(); //Skip bland lines if (line.Length == 0) { continue; } //Let's start to get satData out of file //If this is the prevObj valid line, it contains station name if (row == 0) { nameString = StringUtil.firstWord(ref line).ToUpper(); ++row; continue; } else { //2nd to 7th valid lines contains tide harmonics if ((row > 0) && (row <= 6)) { for (int col = 0; col < 11; col++) { string value = StringUtil.TrimFirstWord(ref line); data.HarmonicsOfTideData[row - 1, col] = Convert.ToDouble(value); } ++row; continue; } } } catch (Exception e) { log.Error("BLQ 文件数据解析出错(已经修复了啊,是不是格式变了???)!" + e.Message); //close this satData stream before returning sr.Close(); return; } } }