Revision 449

View differences:

org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/VariableSelectionPanel.java
50 50
	private JComboBox               levelCombo           = null;
51 51
	private JComboBox               timeCombo            = null;
52 52
	private JPanel                  dimPanel             = null;
53
	private UpDownPanel             varUpDown            = null;
54
	private UpDownPanel             timeUpDown           = null;
55
	private UpDownPanel             levelUpDown          = null;
56
	private JPanel                  varPanel             = null;
57
	private JPanel                  timePanel            = null;
58
	private JPanel                  levelPanel           = null;
53 59

  
54 60
	public VariableSelectionPanel() {
55 61
		xdimLabel = new JLabel(PluginServices.getText(this, "xdim"));
......
77 83
		add(levelLabel, gridBagConstraints1);
78 84
		
79 85
		gridBagConstraints1.gridy = 2;
80
		add(getLevelCombo(), gridBagConstraints1);
86
		add(getLevelPanel(), gridBagConstraints1);
81 87
		
82 88
		gridBagConstraints1.gridy = 3;
83 89
		add(timeLabel, gridBagConstraints1);
84 90
		
85 91
		gridBagConstraints1.gridy = 4;
86
		add(getTimeCombo(), gridBagConstraints1);
92
		add(getTimePanel(), gridBagConstraints1);
87 93
		
88 94
		gridBagConstraints1.gridy = 5;
89 95
		add(gridVariableLabel, gridBagConstraints1);
90 96
		
91 97
		gridBagConstraints1.gridy = 6;
92
		add(getGridVariableCombo(), gridBagConstraints1);
98
		add(getVarPanel(), gridBagConstraints1);
93 99
		
94 100
		gridBagConstraints1.gridy = 7;
95 101
		add(varDescriptionLabel, gridBagConstraints1);
......
181 187
		}
182 188
		return gridVariableCombo;
183 189
	}
190
	
191
	/**
192
	 * Gets the panel of variable controls
193
	 * @return
194
	 */
195
	private JPanel getVarPanel() {
196
		if(varPanel == null) {
197
			varPanel = new JPanel();
198
			varPanel.setLayout(new GridBagLayout());
199
			
200
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
201
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
202
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
203
			gridBagConstraints1.weightx = 1.0;
204
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
205
			
206
			gridBagConstraints1.gridx = 0;
207
			gridBagConstraints1.gridy = 0;
208
			varPanel.add(getGridVariableCombo(), gridBagConstraints1);
209
			
210
			gridBagConstraints1.fill = GridBagConstraints.NONE;
211
			gridBagConstraints1.weightx = 0.0;
212
			gridBagConstraints1.gridx = 1;
213
			gridBagConstraints1.gridy = 0;
214
			varPanel.add(getVarUpDownPanel(), gridBagConstraints1);
215
		}
216
		return varPanel;
217
	}
218
	
219
	/**
220
	 * Gets the panel of time controls
221
	 * @return
222
	 */
223
	private JPanel getTimePanel() {
224
		if(timePanel == null) {
225
			timePanel = new JPanel();
226
			timePanel.setLayout(new GridBagLayout());
227
			
228
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
229
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
230
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
231
			gridBagConstraints1.weightx = 1.0;
232
			gridBagConstraints1.weighty = 1.0;
233
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
234
			
235
			gridBagConstraints1.gridx = 0;
236
			gridBagConstraints1.gridy = 0;
237
			timePanel.add(getTimeCombo(), gridBagConstraints1);
238
			
239
			gridBagConstraints1.fill = GridBagConstraints.NONE;
240
			gridBagConstraints1.weightx = 0.0;
241
			gridBagConstraints1.weighty = 0.0;
242
			gridBagConstraints1.gridx = 1;
243
			gridBagConstraints1.gridy = 0;
244
			timePanel.add(getTimeUpDownPanel(), gridBagConstraints1);
245
		}
246
		return timePanel;
247
	}
248
	
249
	/**
250
	 * Gets the panel of level controls
251
	 * @return
252
	 */
253
	private JPanel getLevelPanel() {
254
		if(levelPanel == null) {
255
			levelPanel = new JPanel();
256
			levelPanel.setLayout(new GridBagLayout());
257
			
258
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
259
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
260
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
261
			gridBagConstraints1.weightx = 1.0;
262
			gridBagConstraints1.weighty = 1.0;
263
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
264
			
265
			gridBagConstraints1.gridx = 0;
266
			gridBagConstraints1.gridy = 0;
267
			levelPanel.add(getLevelCombo(), gridBagConstraints1);
268
			
269
			gridBagConstraints1.fill = GridBagConstraints.NONE;
270
			gridBagConstraints1.weightx = 0.0;
271
			gridBagConstraints1.weighty = 0.0;
272
			gridBagConstraints1.gridx = 1;
273
			gridBagConstraints1.gridy = 0;
274
			levelPanel.add(getLevelUpDownPanel(), gridBagConstraints1);
275
		}
276
		return levelPanel;
277
	}
278
	
279
	public UpDownPanel getVarUpDownPanel() {
280
		if(varUpDown == null) {
281
			varUpDown = new UpDownPanel();
282
		}
283
		return varUpDown;
284
	}
285
	
286
	public UpDownPanel getTimeUpDownPanel() {
287
		if(timeUpDown == null) {
288
			timeUpDown = new UpDownPanel();
289
		}
290
		return timeUpDown;
291
	}
292
	
293
	public UpDownPanel getLevelUpDownPanel() {
294
		if(levelUpDown == null) {
295
			levelUpDown = new UpDownPanel();
296
		}
297
		return levelUpDown;
298
	}
184 299
}
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/UpDownPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.netcdf.app.netcdfclient.gui.panel;
20

  
21
import java.awt.GridBagConstraints;
22
import java.awt.GridBagLayout;
23

  
24
import javax.swing.JButton;
25
import javax.swing.JPanel;
26

  
27
/**
28
 * Panel for up and down button
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public class UpDownPanel extends JPanel {
32
	private static final long       serialVersionUID     = 1L;
33
	private JButton                 up                   = null;
34
	private JButton                 down                 = null;
35

  
36
	public UpDownPanel() {
37
		init();
38
	}
39
	
40
	private void init() {
41
		setLayout(new GridBagLayout());
42
		
43
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
44
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
45
		gridBagConstraints1.anchor = GridBagConstraints.CENTER;
46
		gridBagConstraints1.weightx = 1.0;
47
		gridBagConstraints1.weighty = 1.0;
48
		
49
		add(getDownButton(), gridBagConstraints1);
50
				
51
		gridBagConstraints1.gridx = 1;
52
		add(getUpButton(), gridBagConstraints1);
53
	}
54

  
55
	public JButton getUpButton() {
56
		if(up == null) {
57
			up = new JButton(">");
58
			//up.setPreferredSize(new Dimension(32, 12));
59
		}
60
		return up;
61
	}
62
	
63
	public JButton getDownButton() {
64
		if(down == null) {
65
			down = new JButton("<");
66
			//down.setPreferredSize(new Dimension(32, 12));
67
		}
68
		return down;
69
	}
70
}
0 71

  
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/NetCDFPanel.java
49 49
 * @author Nacho Brodin (nachobrodin@gmail.com)
50 50
 */
51 51
public class NetCDFPanel extends DefaultButtonsPanel implements IWindow, ActionListener, ButtonsPanelListener {
52
	private static final long             serialVersionUID = 1L;
53
	private static String                 NOVALUE          = "---";
54
	private VariableSelectionPanel        panel            = null;
55
	private FLyrRaster                    lyr              = null;
52
	private static final long             serialVersionUID  = 1L;
53
	private static String                 NOVALUE           = "---";
54
	private VariableSelectionPanel        panel             = null;
55
	private FLyrRaster                    lyr               = null;
56
	private boolean                       blockRefreshEvent = false;
56 57
	
57 58
	/**
58 59
	 * This method initializes
......
79 80
		
80 81
		gbc.insets = new Insets(0, 0, 0, 0);
81 82
		gbc.fill = GridBagConstraints.BOTH;
83
		gbc.anchor = GridBagConstraints.CENTER;
82 84
		gbc.weightx = 1.0;
83 85
		gbc.weighty = 1.0;
84 86
		
85 87
		add(getVariableSelectionPanel(), gbc);
88
		panel.getLevelCombo().addActionListener(this);
89
		panel.getTimeCombo().addActionListener(this);
90
		panel.getGridVariableCombo().addActionListener(this);
91
		panel.getVarUpDownPanel().getUpButton().addActionListener(this);
92
		panel.getVarUpDownPanel().getDownButton().addActionListener(this);
93
		panel.getTimeUpDownPanel().getUpButton().addActionListener(this);
94
		panel.getTimeUpDownPanel().getDownButton().addActionListener(this);
95
		panel.getLevelUpDownPanel().getUpButton().addActionListener(this);
96
		panel.getLevelUpDownPanel().getDownButton().addActionListener(this);
86 97
	}
87 98
	
88 99
	/**
......
165 176
	 * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo()
166 177
	 */
167 178
	public WindowInfo getWindowInfo() {
168
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
179
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
169 180
		m_viewinfo.setTitle(PluginServices.getText(this, "NetCDF_Properties"));
170 181
		m_viewinfo.setHeight(300);
171 182
		m_viewinfo.setWidth(280);
......
186 197
	 */
187 198
	public void actionPerformed(ActionEvent e) {
188 199
		if(e.getSource() == panel.getGridVariableCombo()) {
200
			blockRefreshEvent = true;
189 201
			try {
190 202
				loadDescription((String)panel.getGridVariableCombo().getSelectedItem());
191 203
				loadLevel();
......
193 205
			} catch (IOException e1) {
194 206
				panel.getTxtDescription().setText("?");
195 207
			}
208
			blockRefreshEvent = false;
196 209
		}
210
		
211
		if(e.getSource() == panel.getVarUpDownPanel().getDownButton()) {
212
			panel.getGridVariableCombo().setSelectedIndex(
213
					Math.min(panel.getGridVariableCombo().getSelectedIndex() + 1,
214
					panel.getGridVariableCombo().getItemCount() - 1));
215
		}
216
		
217
		if(e.getSource() == panel.getVarUpDownPanel().getUpButton()) {
218
			panel.getGridVariableCombo().setSelectedIndex(
219
					Math.max(panel.getGridVariableCombo().getSelectedIndex() - 1,
220
					0));
221
		}
222
		
223
		if(e.getSource() == panel.getTimeUpDownPanel().getDownButton()) {
224
			panel.getTimeCombo().setSelectedIndex(
225
					Math.min(panel.getTimeCombo().getSelectedIndex() + 1,
226
					panel.getTimeCombo().getItemCount() - 1));
227
		}
228
		
229
		if(e.getSource() == panel.getTimeUpDownPanel().getUpButton()) {
230
			panel.getTimeCombo().setSelectedIndex(
231
					Math.max(panel.getTimeCombo().getSelectedIndex() - 1,
232
					0));
233
		}
234
		
235
		if(e.getSource() == panel.getLevelUpDownPanel().getDownButton()) {
236
			panel.getLevelCombo().setSelectedIndex(
237
					Math.min(panel.getLevelCombo().getSelectedIndex() + 1,
238
					panel.getLevelCombo().getItemCount() - 1));
239
		}
240
		
241
		if(e.getSource() == panel.getLevelUpDownPanel().getUpButton()) {
242
			panel.getLevelCombo().setSelectedIndex(
243
					Math.max(panel.getLevelCombo().getSelectedIndex() - 1,
244
					0));
245
		}
246
		
247
		//Apply when a selection changes
248
		if(!blockRefreshEvent &&
249
			(e.getSource() == panel.getGridVariableCombo() || 
250
			e.getSource() == panel.getTimeCombo() || 
251
			e.getSource() == panel.getLevelCombo())) 
252
			actionButtonPressed(null);
197 253
	}
198 254

  
199 255
	/*
......
202 258
	 */
203 259
	public void actionButtonPressed(ButtonsPanelEvent e) {
204 260
		// Bot?n de Aplicar
205
		if (e.getButton() == ButtonsPanel.BUTTON_APPLY) {
206
			//try {
207
				//DataManager datamanager = DALLocator.getDataManager();
208
				//FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters) datamanager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
209
				//DataServerExplorer explorer = datamanager.openServerExplorer(FilesystemServerExplorer.NAME, explorerParams);
210
				//NewDataStoreParameters newParams = explorer.getAddParameters(NetCDFProvider.NAME);
211
				NetCDFDataParameters newParams = (NetCDFDataParameters)lyr.getDataStore().getParameters();
212
				newParams.setDynValue(NetCDFDataParameters.FIELD_VARIABLE, panel.getGridVariableCombo().getSelectedItem());
213
				String value = (String)panel.getTimeCombo().getSelectedItem().toString();
214
				newParams.setDynValue(NetCDFDataParameters.FIELD_TIME, value.compareTo(NOVALUE) == 0 ? 0 : panel.getTimeCombo().getSelectedIndex());
215
				value = (String)panel.getLevelCombo().getSelectedItem().toString();
216
				newParams.setDynValue(NetCDFDataParameters.FIELD_LEVEL, value.compareTo(NOVALUE) == 0 ? new Integer(0) : new Integer(panel.getLevelCombo().getSelectedIndex()));
217
				
218
				try {
219
					lyr.getDataStore().getStatistics().forceToRecalc();
220
					lyr.getDataStore().getStatistics().calculate();
221
				} catch (FileNotOpenException e1) {
222
					RasterToolsUtil.messageBoxError("error_stats", this, e1);
223
				} catch (RasterDriverException e1) {
224
					RasterToolsUtil.messageBoxError("error_stats", this, e1);
225
				} catch (ProcessInterruptedException e1) {
226
				}
227
				
228
				lyr.getMapContext().invalidate();
229
			/*} catch (ValidateDataParametersException e1) {
230
				// TODO Auto-generated catch block
231
				e1.printStackTrace();
232
			} catch (InitializeException e1) {
233
				// TODO Auto-generated catch block
234
				e1.printStackTrace();
235
			} catch (ProviderNotRegisteredException e1) {
236
				// TODO Auto-generated catch block
237
				e1.printStackTrace();
238
			} catch (DataException e1) {
239
				// TODO Auto-generated catch block
240
				e1.printStackTrace();
241
			}*/
261
		if (e == null || e.getButton() == ButtonsPanel.BUTTON_APPLY) {
262
			//DataManager datamanager = DALLocator.getDataManager();
263
			//FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters) datamanager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
264
			//DataServerExplorer explorer = datamanager.openServerExplorer(FilesystemServerExplorer.NAME, explorerParams);
265
			//NewDataStoreParameters newParams = explorer.getAddParameters(NetCDFProvider.NAME);
266
			NetCDFDataParameters newParams = (NetCDFDataParameters)lyr.getDataStore().getParameters();
267
			newParams.setDynValue(NetCDFDataParameters.FIELD_VARIABLE, panel.getGridVariableCombo().getSelectedItem());
268
			String value = (String)panel.getTimeCombo().getSelectedItem().toString();
269
			newParams.setDynValue(NetCDFDataParameters.FIELD_TIME, value.compareTo(NOVALUE) == 0 ? 0 : panel.getTimeCombo().getSelectedIndex());
270
			value = (String)panel.getLevelCombo().getSelectedItem().toString();
271
			newParams.setDynValue(NetCDFDataParameters.FIELD_LEVEL, value.compareTo(NOVALUE) == 0 ? new Integer(0) : new Integer(panel.getLevelCombo().getSelectedIndex()));
242 272

  
243
			//NetCDFDataParameters params = ((NetCDFDataParameters)lyr.getDataStore().getParameters());
273
			//The statistics have to be recalculated for each subdataset
274
			try {
275
				lyr.getDataStore().getStatistics().forceToRecalc();
276
				lyr.getDataStore().getStatistics().calculate();
277
			} catch (FileNotOpenException e1) {
278
				RasterToolsUtil.messageBoxError("error_stats", this, e1);
279
			} catch (RasterDriverException e1) {
280
				RasterToolsUtil.messageBoxError("error_stats", this, e1);
281
			} catch (ProcessInterruptedException e1) {
282
			}
283

  
284
			//If there is a color table this will have to be adapted to subdataset range
285
			if(lyr.getRender().getColorTable() != null)
286
				lyr.getRender().getColorTable().createColorTableInRange(lyr.getDataStore().getStatistics().getMinimun(), lyr.getDataStore().getStatistics().getMaximun(), false);
287
			lyr.getMapContext().invalidate();
244 288
		}
245 289
		
246 290
		// Bot?n de Cerrar
247
		if (e.getButton() == ButtonsPanel.BUTTON_CANCEL)
291
		if (e != null && e.getButton() == ButtonsPanel.BUTTON_CLOSE)
248 292
			PluginServices.getMDIManager().closeWindow(this);
249 293
	}
250 294
}
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFProvider.java
184 184
            try { 
185 185
            	gridNetCDF = GridDataset.open(((RasterFileStoreParameters)params).getFile().getAbsolutePath());
186 186
            	gridList = gridNetCDF.getGrids();
187
            	if(gridList.size() == 0)
188
            		throw new OpenException("There is not a grid variable", null);
187 189
            	selectedGridDataType = gridList.get(0);
188 190
                //netCDFFile = NetcdfFile.open(((RasterFileStoreParameters)params).getFile().getAbsolutePath());
189 191
            } catch (IOException e) {
......
365 367
			int level = getLevelValue();
366 368
			Range rangeY = new Range(pos, pos + blockHeight - 1, 1);
367 369
			Range rangeX = new Range(0, (int)(getWidth() - 1), 1);
368
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, getTime(1), getLevel(1), rangeY, rangeX);
370
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null /*getTime(1), getLevel(1)*/, rangeY, rangeX);
369 371
			Array values = dt.readDataSlice(time, level, -1, -1);
370 372
			return arrayValuesToBuffer(values, buf, rangeX.length(), rangeY.length(), null);
371 373
		} catch (IOException e) {
......
382 384
	public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
383 385
		if(x < 0 || y < 0 || x >= getWidth() || y >= getHeight())
384 386
			throw new InvalidSetViewException("Request out of grid");
385
		
386
		return null;
387
		try {
388
			int strideX = 1;
389
			int strideY = 1;
390
			Range rangeY = new Range((int)(getHeight() - y), (int)(getHeight() - y), strideY);
391
			Range rangeX = new Range(x, x, strideX);
392
			
393
			selectSubdataset();
394
			int time = getTimeValue();
395
			int level = getLevelValue();
396
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null, rangeY, rangeX);
397
			Array values = dt.readDataSlice(time, level, -1, -1);
398
			Object data = null;
399
			
400
			if(getDataType()[0] == Buffer.TYPE_BYTE) {
401
				data = new java.lang.Integer(values.getByte(0));
402
			}
403

  
404
			if(getDataType()[0] == Buffer.TYPE_SHORT) {
405
				data = new java.lang.Integer(values.getShort(0));
406
			}
407

  
408
			if(getDataType()[0] == Buffer.TYPE_INT) {
409
				data = new java.lang.Integer(values.getInt(0));
410
			}
411

  
412
			if(getDataType()[0] == Buffer.TYPE_FLOAT) {
413
				data = new java.lang.Float(values.getFloat(0));
414
			}
415
			if(getDataType()[0] == Buffer.TYPE_DOUBLE) {
416
				data = new java.lang.Double(values.getDouble(0));
417
			}
418
			return data;
419
		} catch (IOException e) {
420
			throw new RasterDriverException("Error reading a slice", e);
421
		} catch (InvalidRangeException e) {
422
			throw new RasterDriverException("Error reading a slice", e);
423
		}
387 424
	}
388 425

  
389 426
	/*
......
416 453
		try {
417 454
			int strideX = 1;
418 455
			int strideY = 1;
419
			//Range rangeY = new Range((int)ul.getY(), (int)(lr.getY() - 1), strideY);
420 456
			Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY);
421 457
			Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX);
422 458
			
423 459
			selectSubdataset();
424
			int time = getTimeValue();//param.hasDynValue(NetCDFDataParameters.FIELD_TIME) ? ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue() : 0;
425
			int level = getLevelValue();//param.hasDynValue(NetCDFDataParameters.FIELD_LEVEL) ? ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue() : 0;
426
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, getTime(strideX), getLevel(strideX), rangeY, rangeX);
460
			int time = getTimeValue();
461
			int level = getLevelValue();
462
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null /*getTime(strideX), getLevel(strideX)*/, rangeY, rangeX);
427 463
			Array values = dt.readDataSlice(time, level, -1, -1);
428 464
			rasterBuf = arrayValuesToBuffer(values, rasterBuf, rangeX.length(), rangeY.length(), bandList);
429 465
		} catch (IOException e) {
......
441 477
	 * @return
442 478
	 * @throws InvalidRangeException
443 479
	 */
480
	@SuppressWarnings("unused")
444 481
	private Range getTime(int strideX) throws InvalidRangeException {
445 482
		int time = getTimeValue();
446
		//if(time != -1) {
447
			return new Range(time, time, strideX);
448
		//}
449
		//return null;
483
		return new Range(time, time, strideX);
450 484
	}
451 485
	
452 486
	private int getTimeValue() {
......
462 496
	 * @return
463 497
	 * @throws InvalidRangeException
464 498
	 */
499
	@SuppressWarnings("unused")
465 500
	private Range getLevel(int strideX) throws InvalidRangeException {
466 501
		int level = getLevelValue();
467
		//if(level != -1) {
468
			return new Range(level, level, strideX);
469
		//}
470
		//return null;
502
		return new Range(level, level, strideX);
471 503
	}
472 504
	
473 505
	private int getLevelValue() {
......
489 521
					if(gridList.get(j).getName().compareTo(variable) == 0) {
490 522
						selectedGridDataType = gridList.get(j);
491 523
						reloadMetadataFromGrid();
492
						String sd = j + "-" + getLevelValue() + "-" +  getTimeValue();
493
						System.out.println("====>" + sd);
494
						super.selectSubdataset(sd);
524
						String id = j + "-" + getLevelValue() + "-" +  getTimeValue();
525
						super.selectSubdataset(id);
495 526
					}
496 527
				}
497 528
			}
......
616 647
		try {
617 648
			int strideX = width / rasterBuf.getWidth();
618 649
			int strideY = height / rasterBuf.getHeight();
619
			//Range rangeY = new Range((int)ul.getY(), (int)(lr.getY() - 1), strideY);
620 650
			Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY);
621 651
			Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX);
622 652
			
623 653
			selectSubdataset();
624
			int time = getTimeValue();//param.hasDynValue(NetCDFDataParameters.FIELD_TIME) ? ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue() : 0;
625
			int level = getLevelValue();//param.hasDynValue(NetCDFDataParameters.FIELD_LEVEL) ? ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue() : 0;
626
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, getTime(strideX), getLevel(strideX), rangeY, rangeX);
654
			int time = getTimeValue();
655
			int level = getLevelValue();
656
			GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null /*getTime(strideX), getLevel(strideX)*/, rangeY, rangeX);
627 657
			Array values = dt.readDataSlice(time, level, -1, -1);
628 658
			rasterBuf = arrayValuesToBuffer(values, rasterBuf, rangeX.length(), rangeY.length(), bandList);
629 659
		} catch (IOException e) {
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFDataParameters.java
143 143
					//Loads levels
144 144
					CoordinateAxis1D zAxis = gcs.getVerticalAxis();
145 145
					if(zAxis != null) {
146
						double[] d = zAxis.getCoordEdges();
146
						double[] d = calcSliceValue(zAxis.getCoordEdges());
147 147
						rankByVar.put(pair[0], d);
148 148
					}
149 149
					
......
161 161
	}
162 162
	
163 163
	/**
164
	 * Calculates the array of levels
165
	 * @param coordsEdges
166
	 * @return
167
	 */
168
	private double[] calcSliceValue(double[] coordsEdges) {
169
		if(coordsEdges == null)
170
			return null;
171
		double[] values = new double[coordsEdges.length - 1];
172
		for (int i = 0; i < coordsEdges.length - 1; i++) {
173
			values[i] = ((coordsEdges[i] + coordsEdges[i + 1]) / 2);
174
		}
175
		return values;
176
	}
177
	
178
	/**
164 179
	 * Gets the list of dates
165 180
	 * @param var
166 181
	 * @return

Also available in: Unified diff