/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
 */
public class IdxParser {

  public static synchronized void parsewindgenIdxFile(ConcurrentHashMap<Integer, Station> stationData, File idxFile) throws FileNotFoundException, IOException {
    if ((stationData != null) && (idxFile != null)) {
      try (FileReader fIn = new FileReader(idxFile); BufferedReader reader = new BufferedReader(fIn);) {
        String line;
        while ((line = reader.readLine()) != null) {
          String[] parts = line.replaceAll("\\s+", " ").trim().split(" ", 16);
          Station station;
          station = new Station();
          station.setStationY(Double.parseDouble(parts[0]) + Double.parseDouble(parts[1]) * 0.0166667);
          station.setStationX(Double.parseDouble(parts[3]) + Double.parseDouble(parts[4]) * 0.0166667);
          station.setStart(Integer.parseInt(parts[7]));
          station.setEnd(Integer.parseInt(parts[8]));
          station.setStationId(Integer.parseInt(parts[12]));
          station.setCountry(parts[13]);
          station.setState(parts[14]);
          station.setName(parts[15]);
          stationData.put(station.getStationId(), station);
        }
      }
    }
  }
}
