private void readEPWFile(StreamReader epw) { LocationData ld = new LocationData(); ld.defineEPWFields(); string line = epw.ReadLine(); string[] data; while (line != null) { data = line.Split(','); switch (data[0]) { case "LOCATION": getLocationData(data, ref ld); break; case "DATA PERIODS": line = epw.ReadLine(); //read first hour while (line != null) { ld.hourlyData.Add(getHourlyValueList(line)); line = epw.ReadLine(); } break; } line = epw.ReadLine(); } ld.cleanHourlyValues(); ld.cleanMonthlyValues(); string directory = this.directory + ld.where; ClimaJSONWriter climajson = new ClimaJSONWriter(ld, directory); recordPlace(ld.where, ld.name); //cd.Add(ld); epw.Close(); }
private void readWEAFile(string fileName) { // FORMAT AT http://wiki.naturalfrequency.com/wiki/WeatherTool/File_Format LocationData ld = new LocationData(); //fillFieldLists(ld); ld.defineWEAHourlyFields(); ld.defineWEAMonthlyFields(); int hour = 0; int day = 0; int wData = 0; int month = 0; using (BinaryReader b = new BinaryReader(File.Open(fileName, FileMode.Open))) { var identifier = b.ReadBytes(16); var myString = System.Text.Encoding.UTF8.GetString(identifier); ld.name = StringTools.CleanInput(new string(b.ReadChars(32))); nameClean(ref ld); ld.where = StringTools.CleanInput(new string(b.ReadChars(32))); ld.where = "COL"; //hourly data while (day < 365) { while (hour < 24) { List <double> hourlyvalues = new List <double>(); for (int i = 0; i < 8; i++) { //read the 8 hourly values hourlyvalues.Add((double)BitConverter.ToInt16(b.ReadBytes(2), 0)); } for (int i = 0; i < hourlyvalues.Count; i++) { if (i == 0) { hourlyvalues[i] = hourlyvalues[i] / 10.0; } if (i == 2) { hourlyvalues[i] = hourlyvalues[i] / 10 * 0.277778; //convert km/h to m/s } if (i == 6) { hourlyvalues[i] = Math.Round(hourlyvalues[i] / 10.0); } } ld.hourlyData.Add(hourlyvalues); hour++; } hour = 0; day++; } while (wData < 28) { List <double> monthlyvalues = new List <double>(); while (month < 12) { monthlyvalues.Add((double)BitConverter.ToInt32(b.ReadBytes(4), 0)); month++; } ld.monthlyData.Add(monthlyvalues); month = 0; wData++; } ld.longitude = b.ReadSingle(); ld.timezone = b.ReadSingle(); ld.latitude = b.ReadSingle(); ld.altitude = b.ReadSingle(); ld.day = BitConverter.ToInt32(b.ReadBytes(4), 0); ld.sky = BitConverter.ToInt32(b.ReadBytes(4), 0); if (b.BaseStream.Position == b.BaseStream.Length) { //reach eof } else { //more stuff to read somethings wrong! } } ld.cleanHourlyValues(); ld.cleanMonthlyValues(); this.cd.Add(ld); }