001 /*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2013
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas
009 *
010 * All Rights Reserved
011 *
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.
014 *
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 *
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023 * GNU Lesser Public License for more details.
024 *
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program. If not, see http://www.gnu.org/licenses.
027 */
028
029 package edu.wisc.ssec.mcidasv.data;
030
031 import java.io.BufferedReader;
032 import java.io.File;
033 import java.io.FileReader;
034 import java.io.InputStreamReader;
035
036 import java.net.URL;
037 import java.net.URLConnection;
038
039 import java.util.HashMap;
040
041 import visad.georef.EarthLocationTuple;
042
043 public class GroundStations
044 {
045 private static final String card00 = "KMSN,SSEC,43.1398578,-89.3375136,270.4";
046 public static String groundStationDB = "data/groundstations/groundstations_db.csv";
047 private HashMap<String, EarthLocationTuple> namedLocs = new HashMap<String, EarthLocationTuple>();
048
049 public GroundStations(String topCard)
050 {
051 // read data files for Ground Stations
052 try
053 {
054 BufferedReader gsReader = null; // initialization of reader
055
056 //see if local file exists, if not stream from web
057
058 // read local file
059 if (new File(groundStationDB).exists())
060 {
061 File gsFile = new File(groundStationDB);
062 FileReader gsFileReader = new FileReader(gsFile);
063 gsReader = new BufferedReader(gsFileReader); // from local file
064 }
065 else
066 {
067 // read from web
068 URL url = new URL("http://www.gano.name/shawn/JSatTrak/" + groundStationDB);
069 URLConnection c = url.openConnection();
070 InputStreamReader isr = new InputStreamReader(c.getInputStream());
071 gsReader = new BufferedReader(isr); // from the web
072 }
073
074 String nextLine = topCard;
075 if (topCard == null) {
076 nextLine = card00;
077 }
078
079 while (nextLine != null)
080 {
081 // split line into parts
082 String[] elements = nextLine.split(",");
083
084 if (elements.length == 5) // if the row is formatted correctly
085 {
086 Double dLat = new Double(elements[2]);
087 Double dLon = new Double(elements[3]);
088 Double dAlt = new Double(elements[4]);
089
090 EarthLocationTuple elt = new EarthLocationTuple(dLat, dLon, dAlt);
091 namedLocs.put(elements[1], elt);
092 }
093 nextLine = gsReader.readLine();
094 } // while there are more lines to read
095
096 gsReader.close();
097 }
098 catch (Exception e)
099 {
100 System.out.println("ERROR IN GROUND STATION READING POSSIBLE FILE FORMAT OR MISSING FILES:");
101 }
102 } // constructor
103
104 public int getGroundStationCount() {
105 return namedLocs.size();
106 }
107
108 public HashMap getGroundStations() {
109 return namedLocs;
110 }
111
112 }