Parser.cs 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.IO;
  6. using WebApplication3.Models;
  7. using System.Globalization;
  8. using Microsoft.VisualBasic.FileIO;
  9. namespace WebApplication3.Clases
  10. {
  11. public class Parser
  12. {
  13. public WellData[] ParseWellData(string textFile)
  14. {
  15. if (File.Exists(textFile))
  16. {
  17. StreamReader file = new StreamReader(textFile);
  18. //WellData[] wellData = null;
  19. List<WellData> wellDataList = null;
  20. WellData wellData = null;
  21. string ln;
  22. int cont = 0;
  23. int index = 0;
  24. bool intervalSkipped = false;
  25. int finalBloque = 0;
  26. string[] values;
  27. while ((ln = file.ReadLine()) != null)
  28. {
  29. if (wellData == null)
  30. {
  31. //wellData = new WellData[int.Parse(ln)];
  32. wellDataList = new List<WellData>(int.Parse(ln));
  33. wellData = new WellData();
  34. cont++;
  35. continue;
  36. }
  37. if (!intervalSkipped)
  38. {
  39. switch (cont)
  40. {
  41. case 1:
  42. //wellData[index].ActiveFlag = (ln == "0") ? false : true;
  43. wellData.ActiveFlag = ln != "0";
  44. break;
  45. case 2:
  46. //wellData[index].WellName = ln;
  47. wellData.WellName = ln;
  48. break;
  49. case 3:
  50. //wellData[index].X = double.Parse(ln);
  51. wellData.X = ln;
  52. break;
  53. case 4:
  54. //wellData[index].Y = double.Parse(ln);
  55. wellData.Y = ln;
  56. break;
  57. case 5:
  58. //wellData[index].ZMin = ln;
  59. values = ln.Split(" ");
  60. wellData.ZMin = values[0].Replace(".", ",");
  61. break;
  62. case 6:
  63. //wellData[index].ZMax = ln;
  64. values = ln.Split(" ");
  65. wellData.ZMax = values[0].Replace(".", ",");
  66. break;
  67. case 7:
  68. //wellData[index].ScreenIntervals = int.Parse(ln);
  69. wellData.ScreenIntervals = int.Parse(ln);
  70. //cont += (wellData[index].ScreenIntervals * 2) - 1;
  71. intervalSkipped = true;
  72. //leemos tantas lineas hay como intervalos de pantalla (al ser 2 parametros por cada intervalo es nIntervalos * 2
  73. //for (int i = 0; i < wellData[index].ScreenIntervals * 2; i++)
  74. for (int i = 0; i < wellData.ScreenIntervals * 2; i++)
  75. {
  76. file.ReadLine();
  77. cont++;
  78. }
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. else
  85. {
  86. //if (wellData[index].PumpPeriods == 0)
  87. if (wellData.PumpPeriods == 0)
  88. {
  89. //wellData[index].PumpPeriods = int.Parse(ln);
  90. wellData.PumpPeriods = int.Parse(ln);
  91. //se calcula en que linea termina el bloque del pozo
  92. //finalBloque = cont + wellData[index].PumpPeriods + 1;
  93. finalBloque = cont + 1 + wellData.PumpPeriods * 3;
  94. }
  95. else
  96. {
  97. TimeSerieInterno ts = new TimeSerieInterno();
  98. string aux = "";
  99. //Rate rate = new Rate();
  100. ts.Hora = ln;
  101. //rate.StartTime = float.Parse(ln.Replace('.', ','));
  102. ln = file.ReadLine();
  103. cont++;
  104. if(cont == finalBloque - 1)
  105. {
  106. aux = ln;
  107. }
  108. ln = file.ReadLine();
  109. cont++;
  110. //Separamos la cadena por " "
  111. //TODO -> igual es un \t
  112. string[] exploded = ln.Split(" ");
  113. //Solo nos interesa el primer valor
  114. string value = exploded[0].Replace('.', ',');
  115. ts.Valor = value;
  116. ts.Info = ln.Replace(exploded[0] + ' ', "");
  117. //rate.Value = double.Parse(value);
  118. //wellData[index].Rates.Add(rate);
  119. wellData.Rates.Add(ts);
  120. if(aux != "")
  121. {
  122. ts = new TimeSerieInterno();
  123. ts.Hora = aux;
  124. ts.Valor = value;
  125. ts.Info = ln.Replace(exploded[0] + ' ', "");
  126. wellData.Rates.Add(ts);
  127. }
  128. }
  129. }
  130. cont++;
  131. //hemos llegado al final del primer bloque de pozo, preparamos para el siguiente
  132. if (finalBloque == cont)
  133. {
  134. intervalSkipped = false;
  135. index++;
  136. wellDataList.Add(wellData);
  137. wellData = new WellData();
  138. cont = 1;
  139. }
  140. }
  141. file.Close();
  142. return wellDataList.ToArray();
  143. }
  144. return null;
  145. }
  146. public RechargeData[] ParseRechargeData(string textFile,out string recharge_geometry)
  147. {
  148. List<RechargeData> recharges = new List<RechargeData>();
  149. RechargeData rechargeData = null;
  150. TimeSerieInterno timeSerie;
  151. string rechargeProperty="";
  152. recharge_geometry = "";
  153. if (File.Exists(textFile))
  154. {
  155. Console.WriteLine("File exist");
  156. string text = File.ReadAllText(textFile);
  157. string[] data = text.Split("\r\n\r\n");
  158. int layers = int.Parse(data[0][0].ToString());
  159. int blankLinePerBlock = layers + 1;
  160. int rechargeBlockInex = blankLinePerBlock * 2;
  161. Console.WriteLine(data[rechargeBlockInex]);
  162. string[] explode = data[rechargeBlockInex].Split("\r\n");
  163. for(int i = 3; i < explode.Length; i++)
  164. {
  165. string[] values = explode[i].Split(" ", StringSplitOptions.RemoveEmptyEntries);
  166. //Si hay cambio de propiedad se crea otro RechargeData
  167. if(rechargeProperty != values[0])
  168. {
  169. if(rechargeProperty != "")
  170. {
  171. recharges.Add(rechargeData);
  172. }
  173. rechargeData = new RechargeData();
  174. rechargeData.Nombre = "Recarga_" + values[0];
  175. rechargeProperty = values[0];
  176. }
  177. timeSerie = new TimeSerieInterno();
  178. timeSerie.Hora = values[2];
  179. timeSerie.Valor = values[1];
  180. timeSerie.Info = values[4] + " " + values[5];
  181. rechargeData.Rates.Add(timeSerie);
  182. //se anyade el ultimo registro de tiempo ya que solo nos quedamos con la primera marca de tiempo de cada linea
  183. if(i == explode.Length - 1)
  184. {
  185. timeSerie = new TimeSerieInterno();
  186. timeSerie.Hora = values[3];
  187. timeSerie.Valor = values[1];
  188. timeSerie.Info = values[4] + " " + values[5];
  189. rechargeData.Rates.Add(timeSerie);
  190. }
  191. }
  192. recharge_geometry = data[rechargeBlockInex + layers];
  193. //Se anyade la ultima instancia de rechargeData ya que no se produce cambio en la ultima iteracion del bucle
  194. recharges.Add(rechargeData);
  195. return recharges.ToArray();
  196. }
  197. else
  198. {
  199. Console.WriteLine("File does not exist");
  200. }
  201. return null;
  202. }
  203. public List<string> ParseInFile(string textFile)
  204. {
  205. Console.WriteLine("File exist");
  206. string text = File.ReadAllText(textFile);
  207. List<string> lines = new();
  208. List<string> aux = new();
  209. //Introducimos todas las lineas
  210. aux.AddRange(text.Split("\r\n").ToList());
  211. //Se eliminan las referencias a ficheros que no son validos para el modelo
  212. aux.RemoveAll(x => x.Contains("WHS") || x.Contains("NDC") || x.Contains("CLB") || x == "");
  213. foreach (string row in aux)
  214. {
  215. string[] rowSplit = row.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  216. Console.WriteLine(rowSplit);
  217. if (rowSplit[0] == "LIST" && int.Parse(rowSplit[1]) < 10)
  218. {
  219. rowSplit[1] = "12";
  220. }
  221. //Se tiene que parsear la 3a parte del string porque contiene la ruta absoluta del ordenador donde se han originado los ficheros
  222. List<string> ficheroSplit = rowSplit[2].Split("\\").ToList();
  223. rowSplit[2] = ficheroSplit.Last();
  224. lines.Add(rowSplit[0] + " " + rowSplit[1] + " " + rowSplit[2]);
  225. }
  226. return lines;
  227. }
  228. public ZoneBalance[] ParseZonesBalance(string textFile)
  229. {
  230. List<ZoneBalance> zonesOutput = new List<ZoneBalance>();
  231. string text = File.ReadAllText(textFile);
  232. string[] data = text.Split(" test \r\n \r\n", StringSplitOptions.RemoveEmptyEntries);
  233. List<string> data_aux = data[1].Split("\r\n").ToList();
  234. string zones = data_aux.Find(x => x.Contains("zones"));
  235. int index = data_aux.IndexOf(zones);
  236. string[] zone_names = data_aux[index + 1].Split(" ", StringSplitOptions.RemoveEmptyEntries);
  237. int zonesConectionPerZone = zone_names.Length - 1;
  238. Logger logger = Logger.GetInstance();
  239. for (int z = 2; z < data.Length; z++)
  240. {
  241. List<string> balanceData = data[z].Split("\r\n", StringSplitOptions.RemoveEmptyEntries).ToList();
  242. ZoneBalance zoneBalance = new ZoneBalance();
  243. string storage, constantHead, drains, recharge, total, percentDisparity;
  244. string auxFind, auxSplit, zoneConnectionLine;
  245. string[] split;
  246. split = balanceData[0].Trim().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  247. zoneBalance.Zone = split[4];
  248. zoneBalance.StressPeriod = int.Parse(split[12]);
  249. #region IN
  250. //buscamos el indice en el cual empieza el bloque de los datos de salida
  251. auxFind = balanceData.Find(x => x.Contains("IN:"));
  252. index = balanceData.IndexOf(auxFind);
  253. //el primer dado del bloque se encuentra 2 indices despues del obtenido
  254. index += 2;
  255. auxSplit = balanceData[index].Split("STORAGE =")[1];
  256. storage = auxSplit;
  257. index++;
  258. auxSplit = balanceData[index].Split("CONSTANT HEAD =")[1].Trim();
  259. constantHead = auxSplit;
  260. index++;
  261. auxSplit = balanceData[index].Split("DRAINS =")[1].Trim();
  262. drains = auxSplit;
  263. index++;
  264. auxSplit = balanceData[index].Split("RECHARGE =")[1].Trim();
  265. recharge = auxSplit;
  266. index++;
  267. //Zone connections
  268. for (int i = index; i < index + zonesConectionPerZone; i++)
  269. {
  270. zoneConnectionLine = balanceData[i].Trim();
  271. split = zoneConnectionLine.Split("to");
  272. ZoneConnection zoneConnection = new ZoneConnection();
  273. zoneConnection.From = split[0].Split("Zone")[1].Trim();
  274. zoneConnection.To = split[1].Split("=")[0].Trim();
  275. zoneConnection.Value = split[1].Split("=")[1].Trim();
  276. zoneBalance.In.ZoneConnections.Add(zoneConnection);
  277. }
  278. //Para el total hay que buscar el indice porque al haber fluctuacion entre zonas no podemos saber el indice fijo de la linea donde se encuentra de forma directa
  279. auxFind = balanceData.Find(x => x.Contains("Total IN"));
  280. index = balanceData.IndexOf(auxFind);
  281. auxSplit = balanceData[index].Split("Total IN =")[1].Trim();
  282. total = auxSplit;
  283. zoneBalance.In.Storage = storage;
  284. zoneBalance.In.ConstantHead = constantHead;
  285. zoneBalance.In.Drains = drains;
  286. zoneBalance.In.Recharge = recharge;
  287. zoneBalance.In.Total = total;
  288. #endregion
  289. #region OUT
  290. //buscamos el indice en el cual empieza el bloque de los datos de salida
  291. auxFind = balanceData.Find(x => x.Contains("OUT:"));
  292. index = balanceData.IndexOf(auxFind);
  293. //el primer dado del bloque se encuentra 2 indices despues del obtenido
  294. index += 2;
  295. auxSplit = balanceData[index].Split("STORAGE =")[1];
  296. storage = auxSplit;
  297. index++;
  298. auxSplit = balanceData[index].Split("CONSTANT HEAD =")[1].Trim();
  299. constantHead = auxSplit;
  300. index++;
  301. auxSplit = balanceData[index].Split("DRAINS =")[1].Trim();
  302. drains = auxSplit;
  303. index++;
  304. auxSplit = balanceData[index].Split("RECHARGE =")[1].Trim();
  305. recharge = auxSplit;
  306. index++;
  307. //Zone connections
  308. for (int i = index; i < index + zonesConectionPerZone; i++)
  309. {
  310. zoneConnectionLine = balanceData[i].Trim();
  311. split = zoneConnectionLine.Split("to");
  312. ZoneConnection zoneConnection = new ZoneConnection();
  313. zoneConnection.From = split[0].Split("Zone")[1].Trim();
  314. zoneConnection.To = split[1].Split("=")[0].Trim();
  315. zoneConnection.Value = split[1].Split("=")[1].Trim();
  316. zoneBalance.Out.ZoneConnections.Add(zoneConnection);
  317. }
  318. //Para el total hay que buscar el indice porque al haber fluctuacion entre zonas no podemos saber el indice fijo de la linea donde se encuentra de forma directa
  319. auxFind = balanceData.Find(x => x.Contains("Total OUT"));
  320. index = balanceData.IndexOf(auxFind);
  321. auxSplit = balanceData[index].Split("Total OUT =")[1].Trim();
  322. total = auxSplit;
  323. zoneBalance.Out.Storage = storage;
  324. zoneBalance.Out.ConstantHead = constantHead;
  325. zoneBalance.Out.Drains = drains;
  326. zoneBalance.Out.Recharge = recharge;
  327. zoneBalance.Out.Total = total;
  328. #endregion
  329. auxFind = balanceData.Find(x => x.Contains("IN - OUT"));
  330. index = balanceData.IndexOf(auxFind);
  331. auxSplit = balanceData[index].Split("IN - OUT = ")[1].Trim();
  332. total = auxSplit;
  333. auxFind = balanceData.Find(x => x.Contains("Percent Discrepancy = "));
  334. index = balanceData.IndexOf(auxFind);
  335. auxSplit = balanceData[index].Split("Percent Discrepancy = ")[1].Trim();
  336. percentDisparity = auxSplit;
  337. zoneBalance.TotalInOut = total;
  338. zoneBalance.PercentDiscrepancy = percentDisparity;
  339. zonesOutput.Add(zoneBalance);
  340. }
  341. return zonesOutput.ToArray();
  342. }
  343. public ZoneBalance[] ParseWholeModelBalance(string textfile)
  344. {
  345. string text = File.ReadAllText(textfile);
  346. string[] data = text.Split(" DRAWDOWN WILL BE SAVED ON UNIT 151 AT END OF TIME STEP 10, STRESS PERIOD", StringSplitOptions.RemoveEmptyEntries);
  347. List<ZoneBalance> zoneBalances = new List<ZoneBalance>();
  348. for (int i = 1; i < data.Length; i++)
  349. {
  350. ZoneBalance cummulative = new ZoneBalance();
  351. ZoneBalance current = new ZoneBalance();
  352. cummulative.Zone = "Zone 0";
  353. cummulative.StressPeriod = i;
  354. cummulative.Type = 1;
  355. current.Zone = "Zone 0";
  356. current.StressPeriod = i;
  357. current.Type = 2;
  358. List<string> data_aux = data[i].Split("\r\n").ToList();
  359. string[] split = data_aux[2].Split("STRESS PERIOD");
  360. #region IN
  361. split = data_aux[10].Split("STORAGE =", StringSplitOptions.RemoveEmptyEntries);
  362. cummulative.In.Storage = split[1].Trim();
  363. current.In.Storage = split[2].Trim();
  364. split = data_aux[11].Split("CONSTANT HEAD =", StringSplitOptions.RemoveEmptyEntries);
  365. cummulative.In.ConstantHead = split[1].Trim();
  366. current.In.ConstantHead = split[2].Trim();
  367. split = data_aux[12].Split("DRAINS =", StringSplitOptions.RemoveEmptyEntries);
  368. cummulative.In.Drains = split[1].Trim();
  369. current.In.Drains = split[2].Trim();
  370. split = data_aux[13].Split("RECHARGE =", StringSplitOptions.RemoveEmptyEntries);
  371. cummulative.In.Recharge = split[1].Trim();
  372. current.In.Recharge = split[2].Trim();
  373. split = data_aux[15].Split("TOTAL IN =", StringSplitOptions.RemoveEmptyEntries);
  374. cummulative.In.Total = split[1].Trim();
  375. current.In.Total = split[2].Trim();
  376. #endregion
  377. #region OUT
  378. split = data_aux[19].Split("STORAGE =", StringSplitOptions.RemoveEmptyEntries);
  379. cummulative.Out.Storage = split[1].Trim();
  380. current.Out.Storage = split[2].Trim();
  381. split = data_aux[20].Split("CONSTANT HEAD =", StringSplitOptions.RemoveEmptyEntries);
  382. cummulative.Out.ConstantHead = split[1].Trim();
  383. current.Out.ConstantHead = split[2].Trim();
  384. split = data_aux[21].Split("DRAINS =", StringSplitOptions.RemoveEmptyEntries);
  385. cummulative.Out.Drains = split[1].Trim();
  386. current.Out.Drains = split[2].Trim();
  387. split = data_aux[22].Split("RECHARGE =", StringSplitOptions.RemoveEmptyEntries);
  388. cummulative.Out.Recharge = split[1].Trim();
  389. current.Out.Recharge = split[2].Trim();
  390. split = data_aux[24].Split("TOTAL OUT =", StringSplitOptions.RemoveEmptyEntries);
  391. cummulative.Out.Total = split[1].Trim();
  392. current.Out.Total = split[2].Trim();
  393. #endregion
  394. split = data_aux[26].Split("IN - OUT =", StringSplitOptions.RemoveEmptyEntries);
  395. cummulative.TotalInOut = split[1].Trim();
  396. current.TotalInOut = split[2].Trim();
  397. split = data_aux[28].Split("PERCENT DISCREPANCY =", StringSplitOptions.RemoveEmptyEntries);
  398. cummulative.PercentDiscrepancy = split[1].Trim();
  399. current.PercentDiscrepancy = split[2].Trim();
  400. zoneBalances.Add(cummulative);
  401. zoneBalances.Add(current);
  402. }
  403. return zoneBalances.ToArray();
  404. }
  405. public List<Piezometria> ParseBinaryFile(string file, uint? simulacionId)
  406. {
  407. List<Piezometria> piezometria = new List<Piezometria>();
  408. Logger.WriteLog("Parseando fichero binario");
  409. if (File.Exists(file))
  410. {
  411. try
  412. {
  413. using (FileStream fs = new FileStream(file, FileMode.Open))
  414. using (BinaryReader brr = new BinaryReader(fs))
  415. {
  416. Logger.WriteLog("Fichero existente y abierto");
  417. while (fs.Length != fs.Position) // This will throw an exception for non-seekable streams (stream.CanSeek == false), but filestreams are seekable so it's OK here
  418. {
  419. Piezometria p = new();
  420. p.IdSimulacion = simulacionId;
  421. int KSTP = brr.ReadInt32();
  422. int KPER = brr.ReadInt32();
  423. var PERTIM = brr.ReadSingle();
  424. var TOTIM = brr.ReadSingle();
  425. char[] auxDESC = brr.ReadChars(16);
  426. string DESC = new(auxDESC);
  427. int NCOL = brr.ReadInt32();
  428. int NROW = brr.ReadInt32();
  429. int ILAY = brr.ReadInt32();
  430. p.Layer = ILAY;
  431. p.StressPeriod = KPER;
  432. p.Rows = NROW;
  433. p.Columns = NCOL;
  434. List<float> values = new();
  435. for (int i = 0; i < NROW * NCOL; i++)
  436. {
  437. values.Add(brr.ReadSingle());
  438. }
  439. int c = 1;
  440. string original = "";
  441. string convertida = "";
  442. foreach (float v in values)
  443. {
  444. if (c < NCOL)
  445. {
  446. original += v + " ";
  447. //Check for range + color conversion
  448. //convertida += Constants.piezometry_conversion[v.ToString()] + ",";
  449. }
  450. else if (c == NCOL)
  451. {
  452. //Add \n to the string
  453. original += "\n";
  454. //convertida += "\n";
  455. c = 0;
  456. }
  457. c++;
  458. }
  459. p.Original = original;
  460. p.Convertida = convertida;
  461. piezometria.Add(p);
  462. }
  463. }
  464. }catch(Exception ex)
  465. {
  466. Logger.WriteLog(ex.Message);
  467. Logger.WriteLog(ex.InnerException.Message);
  468. }
  469. }
  470. return piezometria;
  471. }
  472. public void GetGeolocalizationFromFile(string file,out string worldX,out string worldY)
  473. {
  474. string text = File.ReadAllText(file);
  475. List<string> data = text.Split("\r\n").ToList();
  476. //string geolocationData = data[2];
  477. string geolocation_line = data.Find(x=> x.Contains("<Georeference"));
  478. string[] geolocation_data = geolocation_line.Split(" ");
  479. string[] world_origin_x = geolocation_data[1].Split("=");
  480. string[] world_origin_y = geolocation_data[2].Split("=");
  481. worldX = world_origin_x[1].Replace("\"",string.Empty);
  482. worldY = world_origin_y[1].Replace("\"",string.Empty);
  483. }
  484. public WellData[] parseWellCSV(string file)
  485. {
  486. List<WellData> wellsData = new();
  487. WellData wellData = null;
  488. using (TextFieldParser csvParser = new TextFieldParser(file))
  489. {
  490. csvParser.CommentTokens = new string[] { "#" };
  491. csvParser.SetDelimiters(new string[] { "," });
  492. csvParser.HasFieldsEnclosedInQuotes = true;
  493. // Skip the row with the column names
  494. csvParser.ReadLine();
  495. string wellName = "";
  496. string[] aux = Array.Empty<string>();
  497. TimeSerieInterno tsInterno;
  498. int pumpPeriods = 0;
  499. while (!csvParser.EndOfData)
  500. {
  501. // Read current line fields, pointer moves to the next line.
  502. string[] fields = csvParser.ReadFields();
  503. if (wellName != fields[0])
  504. {
  505. if (wellName == "")
  506. {
  507. aux = new string[fields.Length];
  508. }
  509. else
  510. {
  511. wellData.PumpPeriods = pumpPeriods;
  512. wellsData.Add(wellData);
  513. tsInterno = new();
  514. tsInterno.Hora = aux[11];
  515. tsInterno.Valor = aux[12];
  516. wellData.Rates.Add(tsInterno);
  517. pumpPeriods = 0;
  518. }
  519. wellData = new();
  520. wellData.WellName = fields[0];
  521. wellData.X = fields[1];
  522. wellData.Y = fields[2];
  523. wellData.Top = fields[5];
  524. wellData.Bot = fields[6];
  525. wellData.ZMin = fields[4];
  526. wellData.ZMax = fields[3];
  527. wellData.ScreenIntervals = 1;
  528. //wellData.ZMin = "";
  529. //wellData.ZMax = "";
  530. wellData.ActiveFlag = false;
  531. wellName = fields[0];
  532. }
  533. tsInterno = new ();
  534. tsInterno.Hora = fields[10];
  535. tsInterno.Valor = fields[12];
  536. wellData.Rates.Add(tsInterno);
  537. fields.CopyTo(aux, 0);
  538. pumpPeriods++;
  539. }
  540. wellData.PumpPeriods = pumpPeriods;
  541. tsInterno = new();
  542. tsInterno.Hora = aux[11];
  543. tsInterno.Valor = aux[12];
  544. wellData.Rates.Add(tsInterno);
  545. wellsData.Add(wellData);
  546. }
  547. return wellsData.ToArray();
  548. }
  549. public RechargeData[] parseRechargeCSV(string file)
  550. {
  551. List<RechargeData> rechargeDatas = new();
  552. RechargeData rechargeData = new();
  553. TimeSerieInterno ts;
  554. string[] aux = Array.Empty<string>();
  555. using (TextFieldParser csvParser = new TextFieldParser(file))
  556. {
  557. csvParser.CommentTokens = new string[] { "#" };
  558. csvParser.SetDelimiters(new string[] { "," });
  559. csvParser.HasFieldsEnclosedInQuotes = true;
  560. // Skip the row with the column names
  561. csvParser.ReadLine();
  562. while (!csvParser.EndOfData)
  563. {
  564. // Read current line fields, pointer moves to the next line.
  565. string[] fields = csvParser.ReadFields();
  566. if(rechargeData.Nombre == null)
  567. {
  568. rechargeData.Nombre = fields[0];
  569. aux = new string[fields.Length];
  570. }
  571. ts = new();
  572. ts.Valor = fields[3];
  573. ts.Hora = fields[1];
  574. //ts.HoraEnd = fields[2];
  575. rechargeData.Rates.Add(ts);
  576. fields.CopyTo(aux, 0);
  577. }
  578. ts = new();
  579. ts.Valor = aux[3];
  580. ts.Hora = aux[2];
  581. //ts.HoraEnd = fields[2];
  582. rechargeData.Rates.Add(ts);
  583. rechargeDatas.Add(rechargeData);
  584. }
  585. return rechargeDatas.ToArray();
  586. }
  587. public PiezometerData[] parsePiezometerCSV(string file)
  588. {
  589. List<PiezometerData> piezometerDatas = new();
  590. PiezometerData piezometerData = null;
  591. TimeSerieInterno ts;
  592. string[] aux = Array.Empty<string>();
  593. string piezometerName = "";
  594. using (TextFieldParser csvParser = new TextFieldParser(file))
  595. {
  596. csvParser.CommentTokens = new string[] { "#" };
  597. csvParser.SetDelimiters(new string[] { "," });
  598. csvParser.HasFieldsEnclosedInQuotes = true;
  599. // Skip the row with the column names
  600. csvParser.ReadLine();
  601. while (!csvParser.EndOfData)
  602. {
  603. // Read current line fields, pointer moves to the next line.
  604. string[] fields = csvParser.ReadFields();
  605. if (piezometerName != fields[0])
  606. {
  607. if(piezometerName == "")
  608. {
  609. aux = new string[fields.Length];
  610. }else
  611. {
  612. }
  613. piezometerData = new();
  614. piezometerData.Name = fields[0];
  615. piezometerData.X = fields[1];
  616. piezometerData.Y = fields[2];
  617. piezometerData.Z = fields[3];
  618. piezometerData.Prof = fields[4];
  619. piezometerData.Screen_top = fields[5];
  620. piezometerData.Screen_bot = fields[6];
  621. }
  622. ts = new();
  623. ts.DateIn = fields[8];
  624. ts.Hora = fields[9];
  625. ts.Valor = fields[10];
  626. piezometerData.Rates.Add(ts);
  627. //fields.CopyTo(aux, 0);
  628. }
  629. }
  630. return piezometerDatas.ToArray();
  631. }
  632. }
  633. }