001/* 002 * $Id: Calipso2D.java,v 1.8 2011/03/24 16:06:33 davep Exp $ 003 * 004 * This file is part of McIDAS-V 005 * 006 * Copyright 2007-2011 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 031package edu.wisc.ssec.mcidasv.data.hydra; 032 033import visad.Data; 034import visad.FlatField; 035import visad.Set; 036import visad.CoordinateSystem; 037import visad.RealType; 038import visad.RealTupleType; 039import visad.SetType; 040import visad.Linear2DSet; 041import visad.Unit; 042import visad.BaseUnit; 043import visad.OffsetUnit; 044import visad.FunctionType; 045import visad.VisADException; 046import visad.data.units.Parser; 047import java.rmi.RemoteException; 048 049import java.util.Hashtable; 050import java.util.HashMap; 051import java.util.StringTokenizer; 052 053import java.io.BufferedReader; 054import java.io.FileInputStream; 055import java.io.IOException; 056import java.io.InputStream; 057import java.io.InputStreamReader; 058 059 060public class Calipso2D extends ProfileAlongTrack { 061 062 double start_time; 063 ArrayAdapter sfcElev_adapter; 064 065 public Calipso2D() { 066 } 067 068 public Calipso2D(MultiDimensionReader reader, HashMap metadata) { 069 super(reader, metadata); 070 HashMap table = ProfileAlongTrack.getEmptyMetadataTable(); 071 table.put(ProfileAlongTrack.array_name, "Surface_Elevation"); 072 sfcElev_adapter = new ArrayAdapter(reader, table); 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}