/*************************************************************************\
* 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.lang.reflect.*;
import SDDS.java.SDDS.*;
/**
* This program is used to convert SDDS files between ASCII and binary,
* and to filter out unwanted columns and/or rows.
* usage: java sddsconvert [-pipe[={'input' | 'output'}]
* [<source-file>] [<target-file>]
* [{-binary | -ascii}]
* [-endianOut={'big'|'little'}] [-endianIn={'big'|'little'}]
* [-description=<text>,<contents>]
* [-fromPage=<pageNumber>] [-toPage=<pageNumber>]
* [-delete={'column' | 'parameter' | 'array'},<matching-string>[,...]]
* [-retain={'column' | 'parameter' | 'array'},<matching-string>[,...]]
* [-rename={'column' | 'parameter' | 'array'},<oldname>=<newname>[,...]]
* [-nowarnings]
*
* -binary |
* The output file will be written in binary format |
* -ascii |
* The output file will be written in ASCII format |
* -endianOut |
* The output file will be written in big or little endian |
* -endianIn |
* The input file will be read in big or little endian |
* -description |
* Add the text and contents to the description of the output file |
* -fromPage |
* First page in input file to write to output file |
* -toPage |
* Last page in input file to write to output file |
* -delete |
* Delete the column(s), parameter(s) or array(s) from output file |
* -retain |
* Retain the column(s), parameter(s) or array(s) in the output file |
* -rename |
* Rename the column(s), parameter(s) or array(s) in the output file |
* -nowarnings |
* Do not warn if existing file will be replaced |
*
*
* @author Robert Soliday
*
* soliday@aps.anl.gov
* @version 1.0 (November 23, 1999)
* @since JDK 1.2
*
* @version 1.1 (December 3, 2001)
* @since JDK 1.3
*/
class sddsconvert {
static void printUsage() {
String usage;
usage = "usage: java sddsconvert [-pipe[={'input' | 'output'}]\n";
usage = usage + "[] []\n";
usage = usage + "[{-binary | -ascii}]\n";
usage = usage + "[-endianOut={'big'|'little'}] [-endianIn={'big'|'little'}]\n";
usage = usage + "[-description=,]\n";
usage = usage + "[-fromPage=] [-toPage=]\n";
usage = usage + "[-delete={'column' | 'parameter' | 'array'},[,...]]\n";
usage = usage + "[-retain={'column' | 'parameter' | 'array'},[,...]]\n";
usage = usage + "[-rename={'column' | 'parameter' | 'array'},=[,...]]\n";
usage = usage + "[-nowarnings]\n\n";
usage = usage + "This program is used to convert SDDS files between ASCII and binary,\n";
usage = usage + "and to filter out unwanted columns and/or rows.\n\n";
usage = usage + "Program by Robert Soliday.";
System.err.println(usage);
}
public static void main(String[] args) {
String[][] commandLineArgs;
String[] deleteColumns=null, deleteParameters=null, deleteArrays=null;
String[] retainColumns=null, retainParameters=null, retainArrays=null;
String[] columnNames=null, parameterNames=null, arrayNames=null;
String[] renameColumns=null, renameParameters=null, renameArrays=null;
String inputfile=null, outputfile=null;
String descriptionText=null, descriptionContents=null;
int arguments, elements, i, j, k, n;
int fromPage=1, toPage=1;
int pageCount;
boolean changeMode = false;
boolean binary = false;
boolean changeEndian = false;
boolean littleEndian = false;
boolean changeEndianIn = false;
boolean littleEndianIn = false;
boolean changeDescription = false;
boolean specifyToPage = false;
boolean nowarnings = false;
boolean pipeIn = false;
boolean pipeOut = false;
boolean found;
commandLineArgs = SDDSUtil.parseCommandLine(args);
arguments = Array.getLength(commandLineArgs);
if (arguments==0) {
printUsage();
return;
}
for (i=0;i