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.hydra;
030
031 import visad.Data;
032 import visad.FlatField;
033 import visad.Set;
034 import visad.CoordinateSystem;
035 import visad.RealType;
036 import visad.RealTupleType;
037 import visad.SetType;
038 import visad.Linear2DSet;
039 import visad.Unit;
040 import visad.BaseUnit;
041 import visad.OffsetUnit;
042 import visad.FunctionType;
043 import visad.VisADException;
044 import visad.data.units.Parser;
045 import java.rmi.RemoteException;
046
047 import java.util.Hashtable;
048 import java.util.HashMap;
049 import java.util.StringTokenizer;
050
051 import java.io.BufferedReader;
052 import java.io.FileInputStream;
053 import java.io.IOException;
054 import java.io.InputStream;
055 import java.io.InputStreamReader;
056
057
058 public class Calipso2D extends ProfileAlongTrack {
059
060 double start_time;
061
062 public Calipso2D() {
063 }
064
065 public Calipso2D(MultiDimensionReader reader, HashMap metadata, boolean isVertTypeAlt) {
066 super(reader, metadata, isVertTypeAlt);
067 }
068
069 public Calipso2D(MultiDimensionReader reader, HashMap metadata) {
070 super(reader, metadata);
071 HashMap table = ProfileAlongTrack.getEmptyMetadataTable();
072 table.put(ProfileAlongTrack.array_name, "Surface_Elevation");
073 }
074
075 public float[] getVertBinAltitude() throws Exception {
076 String propertyFileName = null;
077 float[] altitude = new float[VertLen];
078 int line_cnt = 0;
079 try {
080 propertyFileName = (String) metadata.get(ancillary_file_name);
081 InputStream ios = getClass().getResourceAsStream(propertyFileName);
082 BufferedReader ancillaryReader = new BufferedReader(new InputStreamReader(ios));
083
084 while (true) {
085 String line = ancillaryReader.readLine();
086 if (line == null) break;
087 if (line.startsWith("!")) continue;
088 StringTokenizer strTok = new StringTokenizer(line);
089 String[] tokens = new String[strTok.countTokens()];
090 int tokCnt = 0;
091 while (strTok.hasMoreElements()) {
092 tokens[tokCnt++] = strTok.nextToken();
093 }
094 altitude[line_cnt] = (Float.valueOf(tokens[0]))*1000f;
095 line_cnt++;
096 }
097 ios.close();
098 }
099 catch (Exception e) {
100 System.out.println("fail on ancillary file read: "+propertyFileName);
101 }
102 return altitude;
103 }
104
105 public float[] getTrackTimes() throws Exception {
106 int[] start = new int[] {0,0};
107 int[] count = new int[] {TrackLen/10, 1};
108 int[] stride = new int[] {10,1};
109 double[] times = reader.getDoubleArray((String)metadata.get(profileTime_name), start, count, stride);
110 start_time = times[0];
111 double time_inc = (times[times.length-1] - times[0])/times.length;
112 float[] new_times = new float[TrackLen];
113 for (int t=0; t<TrackLen;t++) {
114 new_times[t] = (float) times[0] + (float)(t*time_inc);
115 }
116 return new_times;
117 }
118
119 public float[] getTrackLongitude() throws Exception {
120 int[] start = new int[] {0,0};
121 int[] count = new int[] {TrackLen, 1};
122 int[] stride = new int[] {1,1};
123 float[] vals = reader.getFloatArray((String)metadata.get(longitude_name), start, count, stride);
124 return vals;
125 }
126
127 public float[] getTrackLatitude() throws Exception {
128 int[] start = new int[] {0,0};
129 int[] count = new int[] {TrackLen, 1};
130 int[] stride = new int[] {1,1};
131 float[] vals = reader.getFloatArray((String)metadata.get(latitude_name), start, count, stride);
132 return vals;
133 }
134
135 public RealType makeVertLocType() throws Exception {
136 return RealType.Altitude;
137 }
138
139 public RealType makeTrackTimeType() throws Exception {
140 OffsetUnit unit = (OffsetUnit) Parser.parse("seconds since 1993-01-01 00:00:00Z");
141 OffsetUnit new_unit = new OffsetUnit(start_time, unit);
142 RealType timeType = RealType.getRealType("Track_Time", new_unit);
143 return timeType;
144 }
145
146 public FlatField getData(Object subset) throws Exception {
147 FlatField field = super.getData(subset);
148 return field;
149 }
150 }