001 /*
002 * $Id: ProfileAlongTrack3D.java,v 1.11 2012/02/19 17:35:42 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 import java.util.HashMap;
033 import visad.Set;
034 import visad.RealTupleType;
035 import visad.RealType;
036 import visad.Gridded3DSet;
037
038
039 public class ProfileAlongTrack3D extends MultiDimensionAdapter {
040
041 public ProfileAlongTrack adapter2D;
042 MultiDimensionReader reader;
043 float[] vertLocs;
044 RealTupleType domain3D;
045
046
047 public ProfileAlongTrack3D(ProfileAlongTrack adapter2D) {
048 super(adapter2D.getReader(), (HashMap) adapter2D.getMetadata());
049 this.adapter2D = adapter2D;
050 this.reader = adapter2D.getReader();
051 rangeProcessor = adapter2D.getRangeProcessor();
052 try {
053 init();
054 } catch (Exception e) {
055 System.out.println("init failed");
056 }
057 }
058
059 void init() throws Exception {
060 vertLocs = adapter2D.getVertBinAltitude();
061 domain3D = RealTupleType.SpatialEarth3DTuple;
062 rangeType = adapter2D.getRangeType();
063 }
064
065
066 public Set makeDomain(Object subset) throws Exception {
067 double[] vert_coords = (double[]) ((HashMap)subset).get(ProfileAlongTrack.vertDim_name);
068 double[] track_coords = (double[]) ((HashMap)subset).get(ProfileAlongTrack.trackDim_name);
069
070 int vert_idx = adapter2D.getVertIdx();
071 int track_idx = adapter2D.getTrackIdx();
072
073 float[] lonValues = null;
074 float[] latValues = null;
075
076 String lonArrayName = (String) ((HashMap)getMetadata()).get(ProfileAlongTrack.longitude_name);
077 String latArrayName = (String) ((HashMap)getMetadata()).get(ProfileAlongTrack.latitude_name);
078
079 int[] start = null;
080 int[] count = null;
081 int[] stride = null;
082
083 int rank = (reader.getDimensionLengths(lonArrayName)).length;
084
085 if (rank == 2) {
086 start = new int[2];
087 count = new int[2];
088 stride = new int[2];
089
090 start[vert_idx] = (int) 0;
091 count[vert_idx] = (int) 1;
092 stride[vert_idx] = (int) vert_coords[2];
093
094 start[track_idx] = (int) track_coords[0];
095 count[track_idx] = (int) ((track_coords[1] - track_coords[0])/track_coords[2] + 1f);
096 stride[track_idx] = (int) track_coords[2];
097 }
098 else if (rank == 1) {
099 start = new int[1];
100 count = new int[1];
101 stride = new int[1];
102 start[0] = (int) track_coords[0];
103 count[0] = (int) ((track_coords[1] - track_coords[0])/track_coords[2] + 1f);
104 stride[0] = (int) track_coords[2];
105 }
106
107 if (reader.getArrayType(lonArrayName) == Float.TYPE ) {
108 lonValues = reader.getFloatArray(lonArrayName, start, count, stride);
109 latValues = reader.getFloatArray(latArrayName, start, count, stride);
110 }
111
112 int vert_len = (int) ((vert_coords[1] - vert_coords[0])/vert_coords[2] + 1f);
113 int track_len = count[track_idx];
114
115 float[] altitudes = new float[vert_len];
116 for (int k=0; k<vert_len;k++) {
117 altitudes[k] = vertLocs[(int)vert_coords[0] + k*((int)vert_coords[2])];
118 }
119
120 float[][] alt_lon_lat = new float[3][vert_len*track_len];
121 oneD_threeDfill(lonValues, latValues, track_len, altitudes, vert_len, alt_lon_lat);
122
123 return new Gridded3DSet(domain3D, alt_lon_lat, vert_len, track_len);
124 }
125
126
127 public HashMap getDefaultSubset() {
128 return adapter2D.getDefaultSubset();
129 }
130
131 public HashMap getSubsetFromLonLatRect(HashMap subset, double minLat, double maxLat, double minLon, double maxLon) {
132 return adapter2D.getSubsetFromLonLatRect(subset, minLat, maxLat, minLon, maxLon);
133 }
134
135 public HashMap getSubsetFromLonLatRect(double minLat, double maxLat, double minLon, double maxLon) {
136 return adapter2D.getSubsetFromLonLatRect(minLat, maxLat, minLon, maxLon);
137 }
138
139 public HashMap getSubsetFromLonLatRect(double minLat, double maxLat, double minLon, double maxLon, int xStride, int yStride, int zStride) {
140 return adapter2D.getSubsetFromLonLatRect(minLat, maxLat, minLon, maxLon, xStride, yStride, zStride);
141 }
142
143 public static void oneD_threeDfill(float[] b, float[] c, int leny, float[] a, int lenx, float[][] abc) {
144 int cnt = 0;
145 for (int i=0; i<leny; i++) {
146 for (int j=0; j<lenx; j++) {
147 abc[0][cnt] = b[i];
148 abc[1][cnt] = c[i];
149 abc[2][cnt] = a[j];
150 cnt++;
151 }
152 }
153 }
154
155 }