001    /*
002     * $Id: CloudSat2D.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.FunctionType;
043    import visad.VisADException;
044    import java.rmi.RemoteException;
045    
046    import java.util.Hashtable;
047    import java.util.HashMap;
048    import java.util.StringTokenizer;
049    
050    import java.io.BufferedReader;
051    import java.io.FileInputStream;
052    import java.io.IOException;
053    import java.io.InputStream;
054    import java.io.InputStreamReader;
055    
056    
057    public 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    }