001/*
002 * $Id: CloudSat2D.java,v 1.9 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.FunctionType;
043import visad.VisADException;
044import java.rmi.RemoteException;
045
046import java.util.Hashtable;
047import java.util.HashMap;
048import java.util.StringTokenizer;
049
050import java.io.BufferedReader;
051import java.io.FileInputStream;
052import java.io.IOException;
053import java.io.InputStream;
054import java.io.InputStreamReader;
055
056
057public class CloudSat2D extends ProfileAlongTrack {
058
059      public CloudSat2D() {
060      }
061
062      public CloudSat2D(MultiDimensionReader reader, HashMap metadata) {
063        super(reader, metadata);
064      }
065
066      public float[] getVertBinAltitude() throws Exception {
067        String propertyFileName = null;
068        float[] altitude = new float[VertLen];
069        try {
070        propertyFileName = (String) metadata.get(ancillary_file_name);
071        InputStream ios = getClass().getResourceAsStream(propertyFileName);
072        BufferedReader ancillaryReader = new BufferedReader(new InputStreamReader(ios));
073
074        int line_cnt = 0;
075        while (true) {
076          String line = ancillaryReader.readLine();
077          if (line == null) break;
078          if (line.startsWith("!")) continue;
079          StringTokenizer strTok = new StringTokenizer(line);
080          String[] tokens = new String[strTok.countTokens()];
081          int tokCnt = 0;
082          while (strTok.hasMoreElements()) {
083            tokens[tokCnt++] = strTok.nextToken();
084          }
085          altitude[line_cnt] = (Float.valueOf(tokens[0]))*1000f;
086          line_cnt++;
087        }
088        ios.close();
089        }
090        catch (Exception e) {
091          System.out.println("fail on ancillary file read: "+propertyFileName);
092        }
093        return altitude;
094      }
095
096      public float[] getTrackTimes() throws Exception {
097        return null;
098      }
099
100      public RealType makeVertLocType() throws Exception {
101        return RealType.Altitude;
102      }
103
104      public RealType makeTrackTimeType() throws Exception {
105        return null;
106      }
107
108      public float[] getTrackLongitude() throws Exception {
109        int[] start = new int[] {0};
110        int[] count = new int[] {TrackLen};
111        int[] stride = new int[] {1};
112        float[] vals = reader.getFloatArray((String)metadata.get(longitude_name), start, count, stride);
113        return vals;
114      }
115
116      public float[] getTrackLatitude() throws Exception {
117        int[] start = new int[] {0};
118        int[] count = new int[] {TrackLen};
119        int[] stride = new int[] {1};
120        float[] vals = reader.getFloatArray((String)metadata.get(latitude_name), start, count, stride);
121        return vals;
122      }
123
124      public HashMap getDefaultSubset() {
125        HashMap subset = ProfileAlongTrack.getEmptySubset();
126
127        double[] coords = (double[])subset.get("TrackDim");
128        coords[0] = 1000.0;
129        coords[1] = (TrackLen - 1000.0) - 1;
130        coords[2] = 5.0;
131        subset.put("TrackDim", coords);
132
133        coords = (double[])subset.get("VertDim");
134        coords[0] = 10.0;
135        coords[1] = (VertLen) - 1;
136        coords[2] = 2.0;
137        subset.put("VertDim", coords);
138        return subset;
139      }
140
141}