/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ //package SDDS.apps; import java.io.*; import java.lang.reflect.*; import SDDS.java.SDDS.*; /** * This program accesses a series of SDDS files and summarizes the * file header for each. It also provides lists of parameters and * column.

* usage: java sddsquery [<source-file> ...]
* [{-parameterlist | -arraylist | -columnlist | version}]
* [-delimiter=<delimiting-string>]
* [-appendunits[=bare]]
* [-sddsOutput=<filename>]

* *
* -parameterlist * The parameter names will be displayed
* -arraylist * The array names will be displayed
* -columnlist * The column names will be displayed
* -version * The file's SDDS version number will be displayed
* -delimiter * The elements in the output stream will be separated by the delimiter
* -appendunits * If a column or parameter has units then they will be appended to the output
* -sddsOutput * Creates an SDDS file containing information about the columns or parameters
* * @author Robert Soliday * * soliday@aps.anl.gov * @version 1.0 (November 23, 1999) * @since JDK 1.2 */ class sddsquery { static void printUsage() { String usage; usage = "usage: sddsquery [ ...]\n"; usage = usage + "[{-parameterlist | -arraylist | -columnlist | -version}]\n"; usage = usage + "[-delimiter=] [-appendunits[=bare]]\n"; usage = usage + "[-sddsOutput=]\n\n"; usage = usage + "This program accesses a series of SDDS files and\n"; usage = usage + "summarizes the file header for each. It also provides\n"; usage = usage + "lists of parameters and columns.\n\n"; usage = usage + "Program by Robert Soliday."; System.err.println(usage); } public static void main(String[] args) { String[][] commandLineArgs; String[] inputfile=null; String[] parameterNames=null, arrayNames=null, columnNames=null; String[] units=null, symbol=null, format=null, description=null; String delimiter = "\n"; String outputFile = null; int[] type, field_length; int arguments, elements, i, j, k, n, files=0; boolean parameterList = false; boolean arrayList = false; boolean columnList = false; boolean version = false; boolean appendUnits = false; boolean bare = false; BufferedOutputStream bos = new BufferedOutputStream(System.err, 4096 /* buffsize */); PrintWriter pw = new PrintWriter(bos, false /* auto flush */); commandLineArgs = SDDSUtil.parseCommandLine(args); arguments = Array.getLength(commandLineArgs); if (arguments==0) { printUsage(); return; } for (i=0;i 2) { System.err.println("invalid command line argument: " + args[i]); printUsage(); return; } appendUnits = true; if (elements == 2) { if (SDDSUtil.compare(commandLineArgs[i][1],"bare")) bare = true; } } else if (SDDSUtil.compare(commandLineArgs[i][0],"-sddsOutput")) { if (elements != 2) { System.err.println("invalid command line argument: " + args[i]); printUsage(); return; } outputFile = commandLineArgs[i][1]; } else { if ((elements != 1) || (commandLineArgs[i][0].charAt(0) == '-')) { System.err.println("invalid command line argument: " + args[i]); printUsage(); return; } files++; if (inputfile == null) inputfile = new String[1]; else inputfile = (String[])SDDSUtil.resize(inputfile,files); inputfile[files-1] = commandLineArgs[i][0]; } } if (inputfile == null) { System.err.println("missing SDDS file name"); printUsage(); return; } SDDSFile sdds, sddsout=null; if (outputFile != null) { sddsout = new SDDSFile(outputFile); String[] parNames = {"Class","Filename"}; String[] parTypes = {"string","string"}; if (!sddsout.defineParameters(parNames,parTypes)) { sddsout.printErrors(); return; } String[] colNames = {"Name","Units","Symbol","Format","Type","Description"}; String[] colTypes = {"string","string","string","string","string","string"}; if (!sddsout.defineColumns(colNames,colTypes)) { sddsout.printErrors(); return; } } for (i=0;i