Class cwscript

java.lang.Object
noaa.coastwatch.tools.cwscript

public final class cwscript extends Object

The script tool runs a shell script written in BeanShell syntax.

Name

cwscript - runs a shell script written in BeanShell.

Synopsis

cwscript input [ARGUMENTS]

Options:

-h, --help
--version

Description

The script tool runs a shell script written in the BeanShell language, which is a simplified variant of Java. All of the CoastWatch API is available to the code using import statments. The arguments passed on the command line of the tool are available in the shell script by accessing the String[] args array starting with args[0] as the first argument.

Parameters

Main parameters:

input
The input shell script file.

Options:

-h, --help
Prints a brief help message.
--version
Prints the software version.

Exit status

0 on success, > 0 on failure. Possible causes of errors:

  • Invalid command line option
  • Invalid input file name
  • Error encountered running the shell script

Examples

The following script prints the start time of a data file:

 import noaa.coastwatch.io.EarthDataReaderFactory;

 reader = EarthDataReaderFactory.create (args[0]);
 print (reader.getInfo().getStartDate());
 

A sample run on a CoastWatch HDF file:

 phollema$ cwscript start_time.bsh 2018_217_0309_n18_wj.hdf
 Sat Aug 04 20:09:27 PDT 2018
 

Another example script prints out the latitude and longitude values along the satellite subpoint of a data file:

 import noaa.coastwatch.io.EarthDataReaderFactory;
 import noaa.coastwatch.util.DataLocation;

 input = args[0];
 reader = EarthDataReaderFactory.create (input);
 lat = reader.getVariable ("latitude");
 lon = reader.getVariable ("longitude");
 dims = lat.getDimensions();

 rows = dims[0];
 cols = dims[1];
 print (rows);
 print (cols);

 for (int i = 0; i < rows; i++) {
   loc = new DataLocation (i, cols/2);
   print (lat.getValue (loc) + " " + lon.getValue (loc));
 } // for
 

The output from running on a NOAA 1b format Metop-2 FRAC file:

 phollema$ cwscript sat_subpoint.bsh NSS.FRAC.M2.D10206.S1053.E1235.B1953132.SV
 4733
 2048
 66.71659851074219 -1.3313000202178955
 66.7074966430664 -1.341499924659729
 66.69829559326172 -1.351599931716919
 66.68930053710938 -1.3616999387741089
 66.68009948730469 -1.3717999458312988
 66.6709976196289 -1.3819999694824219
 66.66189575195312 -1.3919999599456787
 ...
 

The example script below shows how to use the new noaa.coastwatch.util.chunk API to retrieve chunks of data from a data variable in any file:

 import noaa.coastwatch.io.EarthDataReader;
 import noaa.coastwatch.io.EarthDataReaderFactory;
 import noaa.coastwatch.util.chunk.DataChunk;
 import noaa.coastwatch.util.chunk.ChunkPosition;
 import noaa.coastwatch.util.chunk.GridChunkProducer;

 reader = EarthDataReaderFactory.create (args[0]);
 lat = reader.getVariable ("latitude");
 producer = new GridChunkProducer (lat);
 pos = new ChunkPosition (2);
 pos.start[0] = 0;
 pos.start[1] = 0;
 pos.length[0] = pos.length[1] = 16;
 chunk = producer.getChunk (pos);

 print (chunk);
 

Running this script on a CoastWatch HDF format VIIRS granule produces:

 phollema$ cwscript chunk_type.bsh VXSRCW.B2018205.180733.hdf
 noaa.coastwatch.util.chunk.FloatChunk@edf4efb
 

Graphics windows can also be created from a script, using the cwgscript launcher which properly sets up a graphics environment. The following script run with cwgscript displays a view of a variable in an input file:

 import java.awt.Color;
 import javax.swing.JFrame;

 import noaa.coastwatch.gui.EarthDataViewFactory;
 import noaa.coastwatch.gui.EarthDataViewPanel;
 import noaa.coastwatch.gui.GUIServices;
 import noaa.coastwatch.gui.WindowMonitor;
 import noaa.coastwatch.io.EarthDataReader;
 import noaa.coastwatch.io.EarthDataReaderFactory;
 import noaa.coastwatch.render.CoastOverlay;
 import noaa.coastwatch.render.LatLonOverlay;

 file = args[0];
 var = args[1];

 // Set up the view
 reader = EarthDataReaderFactory.create (file);
 view = EarthDataViewFactory.getInstance().create (reader, var);
 view.addOverlay (new CoastOverlay (Color.WHITE));
 view.addOverlay (new LatLonOverlay (Color.WHITE));
 view.resizeHeight (600);

 // Create a panel
 panel = new EarthDataViewPanel (view);
 panel.setPreferredSize (view.getSize (null));

 // Create a graphics frame to show
 frame = new JFrame (file);
 frame.setContentPane (panel);
 frame.addWindowListener (new WindowMonitor());
 frame.pack();

 // Show the frame onscreen
 GUIServices.showFrame (frame);
 

A sample call on a NetCDF file to display SST data is as follows:

 phollema$ cwgscript view.bsh ncdcOisst2Agg_7a1d_a943_b8c6.nc sst
 
Since:
3.4.1
Author:
Peter Hollemans
  • Method Details

    • main

      public static void main(String[] argv) throws bsh.EvalError, IOException
      Performs the main function.
      Parameters:
      argv - the list of command line parameters.
      Throws:
      bsh.EvalError
      IOException