001 /*
002 * $Id: Calipso2D.java,v 1.10 2012/02/19 17:35:40 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv.data.hydra;
032
033 import visad.Data;
034 import visad.FlatField;
035 import visad.Set;
036 import visad.CoordinateSystem;
037 import visad.RealType;
038 import visad.RealTupleType;
039 import visad.SetType;
040 import visad.Linear2DSet;
041 import visad.Unit;
042 import visad.BaseUnit;
043 import visad.OffsetUnit;
044 import visad.FunctionType;
045 import visad.VisADException;
046 import visad.data.units.Parser;
047 import java.rmi.RemoteException;
048
049 import java.util.Hashtable;
050 import java.util.HashMap;
051 import java.util.StringTokenizer;
052
053 import java.io.BufferedReader;
054 import java.io.FileInputStream;
055 import java.io.IOException;
056 import java.io.InputStream;
057 import java.io.InputStreamReader;
058
059
060 public class Calipso2D extends ProfileAlongTrack {
061
062 double start_time;
063
064 public Calipso2D() {
065 }
066
067 public Calipso2D(MultiDimensionReader reader, HashMap metadata, boolean isVertTypeAlt) {
068 super(reader, metadata, isVertTypeAlt);
069 }
070
071 public Calipso2D(MultiDimensionReader reader, HashMap metadata) {
072 super(reader, metadata);
073 HashMap table = ProfileAlongTrack.getEmptyMetadataTable();
074 table.put(ProfileAlongTrack.array_name, "Surface_Elevation");
075 }
076
077 public float[] getVertBinAltitude() throws Exception {
078 String propertyFileName = null;
079 float[] altitude = new float[VertLen];
080 int line_cnt = 0;
081 try {
082 propertyFileName = (String) metadata.get(ancillary_file_name);
083 InputStream ios = getClass().getResourceAsStream(propertyFileName);
084 BufferedReader ancillaryReader = new BufferedReader(new InputStreamReader(ios));
085
086 while (true) {
087 String line = ancillaryReader.readLine();
088 if (line == null) break;
089 if (line.startsWith("!")) continue;
090 StringTokenizer strTok = new StringTokenizer(line);
091 String[] tokens = new String[strTok.countTokens()];
092 int tokCnt = 0;
093 while (strTok.hasMoreElements()) {
094 tokens[tokCnt++] = strTok.nextToken();
095 }
096 altitude[line_cnt] = (Float.valueOf(tokens[0]))*1000f;
097 line_cnt++;
098 }
099 ios.close();
100 }
101 catch (Exception e) {
102 System.out.println("fail on ancillary file read: "+propertyFileName);
103 }
104 return altitude;
105 }
106
107 public float[] getTrackTimes() throws Exception {
108 int[] start = new int[] {0,0};
109 int[] count = new int[] {TrackLen/10, 1};
110 int[] stride = new int[] {10,1};
111 double[] times = reader.getDoubleArray((String)metadata.get(profileTime_name), start, count, stride);
112 start_time = times[0];
113 double time_inc = (times[times.length-1] - times[0])/times.length;
114 float[] new_times = new float[TrackLen];
115 for (int t=0; t<TrackLen;t++) {
116 new_times[t] = (float) times[0] + (float)(t*time_inc);
117 }
118 return new_times;
119 }
120
121 public float[] getTrackLongitude() throws Exception {
122 int[] start = new int[] {0,0};
123 int[] count = new int[] {TrackLen, 1};
124 int[] stride = new int[] {1,1};
125 float[] vals = reader.getFloatArray((String)metadata.get(longitude_name), start, count, stride);
126 return vals;
127 }
128
129 public float[] getTrackLatitude() throws Exception {
130 int[] start = new int[] {0,0};
131 int[] count = new int[] {TrackLen, 1};
132 int[] stride = new int[] {1,1};
133 float[] vals = reader.getFloatArray((String)metadata.get(latitude_name), start, count, stride);
134 return vals;
135 }
136
137 public RealType makeVertLocType() throws Exception {
138 return RealType.Altitude;
139 }
140
141 public RealType makeTrackTimeType() throws Exception {
142 OffsetUnit unit = (OffsetUnit) Parser.parse("seconds since 1993-01-01 00:00:00Z");
143 OffsetUnit new_unit = new OffsetUnit(start_time, unit);
144 RealType timeType = RealType.getRealType("Track_Time", new_unit);
145 return timeType;
146 }
147
148 public FlatField getData(Object subset) throws Exception {
149 FlatField field = super.getData(subset);
150 return field;
151 }
152 }