/* File: StreamYScanDescriptor.java * Copyright (C) 2002-2003 The University of Iowa * Created by: Jeremy Faden * Jessica Swanner * Edward E. West * * This file is part of the das2 library. * * das2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.das2.stream; import org.das2.datum.DatumVector; import org.das2.datum.Units; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.das2.datum.LoggerManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class StreamYScanDescriptor implements SkeletonDescriptor, Cloneable { private static final Logger logger = LoggerManager.getLogger("das2.d2s.yscan"); private static final String g_sCkAry[] = { "name","type","nitems","yTags","yTagInterval","yTagMin","yTagMax" }; private Units yUnits = Units.dimensionless; private Units zUnits = Units.dimensionless; private double[] yTags; private int nitems; private String name = ""; private DataTransferType transferType = DataTransferType.SUN_REAL4; Map properties= new HashMap(); public StreamYScanDescriptor( Element element ) throws StreamException { if ( element.getTagName().equals("yscan") ) { processElement(element); } else { processLegacyElement(element); } } // make y tags using interval specification. This version can walk down 1 of there // paths: Calc tags from 0, calc tags form a minimum value, calc tags from a // maximum value private double[] makeYtagsUsingInterval(Element element, int nItems, double rInterval) throws StreamException { String sMin = element.getAttribute("yTagMin"); String sMax = element.getAttribute("yTagMax"); int i; double[] lYtags = new double[nItems]; if( sMin.isEmpty() && sMax.isEmpty()){ for(i = 0; i plane."); } } if ( !element.hasAttribute("yUnits") ) { logger.warning("required attribute yUnits is missing, using dimensionless."); } if ( !element.hasAttribute("zUnits") ) { logger.warning("required attribute zUnits is missing, using dimensionless."); } } nitems = Integer.parseInt(element.getAttribute("nitems")); if(nitems < 1){ throw new StreamException("yscan 'nitems' value is less than 1"); } String yTagsText = element.getAttribute("yTags"); if(yTagsText.length() > 0){ // yTags = new double[nitems]; String[] tokens = yTagsText.split("\\s*,\\s*"); for(int i = 0; i < nitems; i++){ yTags[i] = Double.parseDouble(tokens[i]); } } else{ // See if yTagInterval is in use instead String sInterval = element.getAttribute("yTagInterval"); if(sInterval.length() > 0){ double rInterval = Double.parseDouble(sInterval); yTags = makeYtagsUsingInterval(element, nitems, rInterval); } else{ // Just default to index entries yTags = new double[nitems]; for(int i = 0; i < nitems; i++) yTags[i] = i; } } String typeStr = element.getAttribute("type"); DataTransferType type = DataTransferType.getByName(typeStr); transferType = type; String yUnitsString = element.getAttribute("yUnits"); if (yUnitsString != null) { yUnits = Units.lookupUnits(yUnitsString); } String zUnitsString = element.getAttribute("zUnits"); if (zUnitsString != null) { zUnits = Units.lookupUnits(zUnitsString); } String lname = element.getAttribute("name"); if ( lname != null ) { this.name = lname; } NodeList nl = element.getElementsByTagName("properties"); logger.log(Level.FINER, "element y has {0} properties", nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Element el = (Element) nl.item(i); Map m = StreamTool.processPropertiesElement(el); // make sure we don't conflict with the 6 reserved properites above for(String sPropName: m.keySet()){ for(String sReserved: g_sCkAry){ if(sPropName.equals(sReserved)) throw new StreamException("Can't use reserved property name '"+ sReserved + "inside a plane properties element."); } } properties.putAll(m); } } private void processLegacyElement(Element element) { try { if ( !element.getTagName().equals("YScan") ) { throw new IllegalArgumentException("xml tree root node is not the right type. "+ "Node type is: "+element.getTagName()); } nitems= Integer.parseInt(element.getAttribute("nitems")); if ( element.getAttribute("yCoordinate") != null ) { String yCoordinateString= element.getAttribute("yCoordinate"); yTags= new double[nitems]; int parseIdx=0; for (int i=0; i"; } @Override public Object getProperty(String name) { return properties.get(name); } @Override public Map getProperties() { return new HashMap(properties); } }