Package com.solfin.viperfish

Source Code of com.solfin.viperfish.Viperfish

/*
*  Viperfish.java
*
*  Created on May 10, 2005, 7:55 PM
*
*  $Id: Viperfish.java 4 2006-08-21 13:04:48Z gabriel $
*
*
*     The contents of this file are subject to the Mozilla Public License
*     Version 1.1 (the "License"); you may not use this file except in
*     compliance with the License. You may obtain a copy of the License at
*     http://www.mozilla.org/MPL/
*
*     Software distributed under the License is distributed on an "AS IS"
*     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
*     License for the specific language governing rights and limitations
*     under the License.
*
*     The Original Code is Viperfish.
*
*     The Initial Developer of the Original Code is Gabriel Galibourg.
*     Portions created by Gabriel Galibourg are Copyright (C) 2005-2006
*     Gabriel Galibourg. All Rights Reserved.
*
*     Contributor(s):
*
*/

package com.solfin.viperfish;

import java.util.Vector;

import com.solfin.tools.Config;

import gnu.getopt.Getopt;
import gnu.getopt.LongOpt;

/**
*
* @author gabriel
*/
public class Viperfish {
   
    private Viperfish() {
        // do nothing
    }
    public static void main(String[] args) {
//        com.solfin.grib.GribUnit  gu;
//        gu=new com.solfin.grib.GribUnit("Temperature");
//        gu=new com.solfin.grib.GribUnit("Temperature");
//        gu=new com.solfin.grib.GribUnit("Presure");
//        gu=new com.solfin.grib.GribUnit("Presure");
//        gu=new com.solfin.grib.GribUnit("Temperature");
//        System.err.println("gu.preferred="+gu.getPreferred());
//        System.err.println("gu.display="+gu.getDisplay());
//        System.err.println("gu.unit="+gu.getUnit());
//        System.err.println("gu.toSi="+gu.toSI(32.0));
//        System.err.println("gu.fromSi="+gu.fromSI(292.0));
//        System.exit(0);
       
        /**
         * retrieve the program name. Use an instanciation of Viperfish
         * class itself since its empty aside from the main().
         */
        Viperfish v=new Viperfish();
        String programName=v.getClass().getName();
        programName = programName.substring(programName.lastIndexOf('.')+1);
       
        /**
         * vector to store all grib filenames into
         */
        final Vector<String> fileNames=new Vector<String>();
       
        /**
         * resource (config) directory setting, which we set to the directory
         * .viperfish in the user's home directory.
         */
        String resourceDir;
        try {
            resourceDir=System.getProperty("user.home")+"/.viperfish";
        } catch (java.lang.SecurityException e) {
            resourceDir="./.viperfish";
        }
       
        String arg;
        LongOpt[] longopts = new LongOpt[3];
        longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
        longopts[1] = new LongOpt("resourcedir", LongOpt.REQUIRED_ARGUMENT, null, 'r');
        longopts[2] = new LongOpt("configdir", LongOpt.REQUIRED_ARGUMENT, null, 'c');
        //
        Getopt g = new Getopt(programName, args, "-:hc:r:", longopts);
        //g.setOpterr(false); // We'll do our own error handling
        //
        int c;
        while ((c = g.getopt()) != -1)
            switch (c) {
                case 0: // when you have just a long option - never happens because all
                    // my long options have a short equivalent.
                    break;
                    //
                case 1: // when I see a string which does not look like an option - must be a file name
                    fileNames.add(g.getOptarg());
                    break;
                    //
                case 2: // when we have an error???
                    break;
                    //
                case 'c':
                case 'r':
                    resourceDir = g.getOptarg();
                    break;
                    //
                case 'h':
                    System.out.println("Usage: "+programName+" [-c configDir] [-h] [gribFiles]...");
                    System.exit(1);
                    break;
                   
                    //case ':':
                    //    System.out.println("Argument needed for option "+(char)g.getOptopt());
                    //    break;
                    //    //
                    //case '?':
                    //    System.out.println("The option '"+(char)g.getOptopt()+"' is not valid");
                    //    break;
                    //    //
                default:
                    break;
            }
           
            // now process args which did not make it to Getopt.
            for (int i = g.getOptind(); i < args.length ; i++) {
                fileNames.add(args[i]);
            }
           
           
            /**
             * now set resource directory
             */
            Config.setResourceDir(resourceDir);
           
           
            //    UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
            //    for (int i = 0; i < info.length; i++) {
            //        System.out.println(info[i].toString());
            //    }
           
           
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new Controller(fileNames);
                }
            });
    }
}
TOP

Related Classes of com.solfin.viperfish.Viperfish

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.