Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace KolokwiumNr22
- {
- class Program
- {
- static string[,] pomiary = null;
- static List<double> temperaturaMniejsza = new List<double>();
- static string[,] pomiaryM = null;
- static List<double> temperaturaWieksza = new List<double>();
- static string[,] pomiaryW = null;
- public static void Wczytaj(string sciezka)
- {
- FileStream fs = new FileStream(sciezka, FileMode.OpenOrCreate, FileAccess.Read);
- StreamReader re = new StreamReader(fs);
- try
- {
- if (File.Exists(sciezka))
- {
- string linia = null;
- string[] linie = File.ReadAllLines(sciezka);
- pomiary = new string[linie.Length, 6];
- int k = 0;
- while ((linia = re.ReadLine()) != null)
- {
- string[] param = linia.Split(';');
- for (int i = 0; i < param.Length; i++)
- {
- pomiary[k, i] = param[i];
- }
- k++;
- }
- }
- }
- catch (IOException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- finally
- {
- if (re != null)
- {
- re.Close();
- }
- }
- }
- static void ReduceToArrays()
- {
- //int u = 0;
- //int p = 0;
- for (int i = 1; i < pomiary.GetLength(0); i++)
- {
- double x = double.Parse(pomiary[i, 5]);
- if (x <= 20)
- {
- temperaturaMniejsza.Add(x);
- //Console.WriteLine("M: " + temperaturaMniejsza[u]);
- //u++;
- }
- else
- {
- temperaturaWieksza.Add(x);
- //Console.WriteLine("W: " + temperaturaWieksza[p]);
- //p++;
- }
- }
- temperaturaMniejsza.Add(19.999999); //NIE WIEM KOMPLETNIE CZEMU, ALE TO POMOGŁO Z WYJĄTKIEM "POZA ROZMIAREM TABLICY" XDD
- temperaturaWieksza.Add(999999); //NIE WIEM KOMPLETNIE CZEMU, ALE TO POMOGŁO Z WYJĄTKIEM "POZA ROZMIAREM TABLICY" XDD
- pomiaryM = new string[temperaturaMniejsza.Count, 6];
- pomiaryW = new string[temperaturaWieksza.Count, 6];
- int m = 0;
- int w = 0;
- Console.WriteLine("REDUCE");
- Console.WriteLine("Pomiary: " + pomiary.GetLength(0));
- Console.WriteLine("PomiaryM: " + pomiaryM.GetLength(0));
- Console.WriteLine("PomiaryW: " + pomiaryW.GetLength(0));
- for (int i = 1; i < pomiary.GetLength(0); i++)
- {
- double y = double.Parse(pomiary[i, 5]);
- //Console.WriteLine(i);
- //Console.Write(y + " = " + temperaturaMniejsza[m] + "\t");
- if (y == temperaturaMniejsza[m])
- {
- //Console.WriteLine("M: " + m);
- //Console.WriteLine("Mniejsza");
- for (int j = 0; j < 6; j++)
- {
- pomiaryM[m, j] = pomiary[i, j];
- //Console.WriteLine(pomiaryM[m, j] + "=" + pomiary[i, j]);
- }
- m++;
- }
- else
- {
- //Console.WriteLine("W: " + w);
- //Console.WriteLine("Wieksza");
- for (int j = 0; j < 6; j++)
- {
- pomiaryW[w, j] = pomiary[i, j];
- //Console.WriteLine(pomiaryW[w, j] + "=" + pomiary[i, j]);
- }
- w++;
- }
- }
- }
- public static void Zapisz(string sciezka, string[,] arr)
- {
- try
- {
- using(StreamWriter readStream = new StreamWriter(sciezka))
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < 6; j++)
- {
- readStream.Write(arr[i, j] + ";");
- }
- readStream.WriteLine();
- }
- }
- }
- catch (IOException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- static void ShowArray(string[,] arr)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- Console.Write("{0,-13} ", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- string path = @"..\..\Dane\pomiaryVT.csv";
- string path1 = @"..\..\Dane\pomiaryM.csv";
- if (!File.Exists(path1))
- File.Create(path1);
- string path2 = @"..\..\Dane\pomiaryW.csv";
- if (!File.Exists(path2))
- File.Create(path2);
- try
- {
- Wczytaj(path);
- ReduceToArrays();
- //ShowArray(pomiary);
- Zapisz(path1, pomiaryM);
- Zapisz(path2, pomiaryW);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- Console.WriteLine("KONIEC");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement