protected Object
    readAtomicScalar(VarNotes vi, TypeNotes ti)
            throws DapException
    {
        DapVariable atomvar = (DapVariable) getTemplate();
        // Get into memory
        Nc4prototypes nc4 = ((Nc4DSP) this.dsp).getJNI();
        int ret;
        DapType basetype = ti.getType();
        Object result = null;
        if(basetype.isFixedSize()) {
            long memsize = ((DapType) ti.get()).getSize();
            Nc4Pointer mem = Nc4Pointer.allocate(memsize);
            readcheck(nc4, ret = nc4.nc_get_var(vi.gid, vi.id, mem.p));
            setMemory(mem);
            result = getatomicdata(ti.getType(), 1, mem.size, mem);
        } else if(basetype.isStringType()) {
            String[] s = new String[1];
            readcheck(nc4, ret = nc4.nc_get_var_string(vi.gid, vi.id, s));
            result = s;
        } else if(basetype.isOpaqueType()) {
            Nc4Pointer mem = Nc4Pointer.allocate(ti.getSize());
            readcheck(nc4, ret = nc4.nc_get_var(vi.gid, vi.id, mem.p));
            setMemory(mem);
            ByteBuffer[] buf = new ByteBuffer[1];
            buf[0] = mem.p.getByteBuffer(0, ti.getSize());
            result = buf;
        } else
            throw new DapException("Unexpected atomic type: " + basetype);
        return result;
    }

protected
Object
readAtomicScalar
(
VarNotes
vi
,
TypeNotes
ti
)
throws
DapException
{
DapVariable
atomvar
=
(
DapVariable
)
getTemplate
(
)
;
// Get into memory
Nc4prototypes
nc4
=
(
(
Nc4DSP
)
this
.
dsp
)
.
getJNI
(
)
;
int
ret
;
DapType
basetype
=
ti
.
getType
(
)
;
Object
result
=
;
if
(
basetype
.
isFixedSize
(
)
)
{
long
memsize
=
(
(
DapType
)
ti
.
get
(
)
)
.
getSize
(
)
;
Nc4Pointer
mem
=
Nc4Pointer
.
allocate
(
memsize
)
;
readcheck
(
nc4
,
ret
=
nc4
.
nc_get_var
(
vi
.
gid
,
vi
.
id
,
mem
.
p
)
)
;
setMemory
(
mem
)
;
result
=
getatomicdata
(
ti
.
getType
(
)
,
1
,
mem
.
size
,
mem
)
;
}
else
if
(
basetype
.
isStringType
(
)
)
{
String
[
]
s
=
new
String
[
1
]
;
readcheck
(
nc4
,
ret
=
nc4
.
nc_get_var_string
(
vi
.
gid
,
vi
.
id
,
s
)
)
;
result
=
s
;
}
else
if
(
basetype
.
isOpaqueType
(
)
)
{
Nc4Pointer
mem
=
Nc4Pointer
.
allocate
(
ti
.
getSize
(
)
)
;
readcheck
(
nc4
,
ret
=
nc4
.
nc_get_var
(
vi
.
gid
,
vi
.
id
,
mem
.
p
)
)
;
setMemory
(
mem
)
;
ByteBuffer
[
]
buf
=
new
ByteBuffer
[
1
]
;
buf
[
0
]
=
mem
.
p
.
getByteBuffer
(
0
,
ti
.
getSize
(
)
)
;
result
=
buf
;
}
else
throw
new
DapException
(
"Unexpected atomic type: "
+
basetype
)
;
return
result
;
}

Read a top-level scalar atomic variable

@param vi
@param ti
@return
@throws DapException

Read a top - level scalar atomic variable


static List<Nc4Cursor>
    getCursorPath(Nc4Cursor cursor)
    {
        List<Nc4Cursor> path = new ArrayList<>();
        for(; ; ) {
            if(!cursor.getScheme().isCompoundArray()) // suppress
                path.add(0, cursor);
            if(cursor.getScheme() == Scheme.SEQUENCE) {
                // Stop here because the sequence has the vlen mem as its mem
                break;
            }
            Nc4Cursor next = (Nc4Cursor) cursor.getContainer();
            if(next == null) {
                assert cursor.getTemplate().isTopLevel();
                break;
            }
            assert next.getTemplate().getSort() == DapSort.VARIABLE;
            cursor = next;
        }
        return path;
    }

Given a cursor, get a list of "containing" cursors
with the following constraints.
1. the first element in the path is a top-level variable.
2. the remaining elements are the enclosing compound variables
3. the last element is the incoming cursor.

@param cursor
@return

Given a cursor get a list of containing cursors with the following constraints . 1 . the first element in the path is a top - level variable . 2 . the remaining elements are the enclosing compound variables 3 . the last element is the incoming cursor .


public static Object getUIDefaultOfClass(Class clazz, String property) {
      Object retVal = null;
      UIDefaults defaults = getUIDefaultsOfClass(clazz);
      List<Object> listKeys = Collections.list(defaults.keys());
      for (Object key : listKeys) {
         if (key.equals(property)) {
            return defaults.get(key);
         }
         if (key.toString().equalsIgnoreCase(property)) {
            retVal = defaults.get(key);
         }
      }
      return retVal;
   }

public static Object getUIDefaultOfClass ( Class clazz , String property ) { Object retVal = null ; UIDefaults defaults = getUIDefaultsOfClass ( clazz ) ; List < Object > listKeys = Collections . list ( defaults . keys ( ) ) ; for ( Object key : listKeys ) { if ( key . equals ( property ) ) { return defaults . get ( key ) ; } if ( key . toString ( ) . equalsIgnoreCase ( property ) ) { retVal = defaults . get ( key ) ; } } return retVal ; }

Convenience method for retrieving the UIDefault for a single property
of a particular class.

@param clazz the class of interest
@param property the property to query
@return the UIDefault property, or null if not found

Convenience method for retrieving the UIDefault for a single property of a particular class .


public static <T extends JComponent> Class getJClass(T component) {
      Class<?> clazz = component.getClass();
      while (!clazz.getName().matches("javax.swing.J[^.]*$")) {
         clazz = clazz.getSuperclass();
      }
      return clazz;
   }

public static < T extends JComponent > Class getJClass ( T component ) { Class < ? > clazz = component . getClass ( ) ; while ( ! clazz . getName ( ) . matches ( "javax.swing.J[^.]*$" ) ) { clazz = clazz . getSuperclass ( ) ; } return clazz ; }

Convenience method to obtain the Swing class from which this
component was directly or indirectly derived.

@param component The component whose Swing superclass is to be
determined
@return The nearest Swing class in the inheritance tree

Convenience method to obtain the Swing class from which this component was directly or indirectly derived .


public void
    compile()
            throws DapException
    {
        assert (this.dataset != null && this.databuffer != null);
        // iterate over the variables represented in the databuffer
        for(DapVariable vv : this.dataset.getTopVariables()) {
            D4Cursor data = compileVar(vv, null);
            this.dsp.addVariableData(vv, data);
        }
    }

The goal here is to process the serialized
databuffer and locate top-level variable positions
in the serialized databuffer. Access to non-top-level
variables is accomplished on the fly.

@return
@throws DapException

The goal here is to process the serialized databuffer and locate top - level variable positions in the serialized databuffer . Access to non - top - level variables is accomplished on the fly .


protected D4Cursor
    compileStructureArray(DapVariable var, D4Cursor container)
            throws DapException
    {
        DapStructure dapstruct = (DapStructure) var.getBaseType();
        D4Cursor structarray = new D4Cursor(Scheme.STRUCTARRAY, this.dsp, var, container)
                .setOffset(getPos(this.databuffer));
        List<DapDimension> dimset = var.getDimensions();
        long dimproduct = DapUtil.dimProduct(dimset);
        D4Cursor[] instances = new D4Cursor[(int) dimproduct];
        Odometer odom = Odometer.factory(DapUtil.dimsetToSlices(dimset), dimset);
        while(odom.hasNext()) {
            Index index = odom.next();
            D4Cursor instance = compileStructure(var, dapstruct, structarray);
            instance.setIndex(index);
            instances[(int) index.index()] = instance;
        }
        structarray.setElements(instances);
        return structarray;
    }

protected D4Cursor compileStructureArray ( DapVariable var , D4Cursor container ) throws DapException { DapStructure dapstruct = ( DapStructure ) var . getBaseType ( ) ; D4Cursor structarray = new D4Cursor ( Scheme . STRUCTARRAY , this . dsp , var , container ) . setOffset ( getPos ( this . databuffer ) ) ; List < DapDimension > dimset = var . getDimensions ( ) ; long dimproduct = DapUtil . dimProduct ( dimset ) ; D4Cursor [ ] instances = new D4Cursor [ ( int ) dimproduct ] ; Odometer odom = Odometer . factory ( DapUtil . dimsetToSlices ( dimset ) , dimset ) ; while ( odom . hasNext ( ) ) { Index index = odom . next ( ) ; D4Cursor instance = compileStructure ( var , dapstruct , structarray ) ; instance . setIndex ( index ) ; instances [ ( int ) index . index ( ) ] = instance ; } structarray . setElements ( instances ) ; return structarray ; }

Compile a structure array.

@param var    the template
@param container if inside a compound object
@return A DataCompoundArray for the databuffer for this struct.
@throws DapException


protected D4Cursor
    compileStructure(DapVariable var, DapStructure dapstruct, D4Cursor container)
            throws DapException
    {
        int pos = getPos(this.databuffer);
        D4Cursor d4ds = new D4Cursor(Scheme.STRUCTURE, (D4DSP) this.dsp, var, container)
                .setOffset(pos);
        List<DapVariable> dfields = dapstruct.getFields();
        for(int m = 0; m < dfields.size(); m++) {
            DapVariable dfield = dfields.get(m);
            D4Cursor dvfield = compileVar(dfield, d4ds);
            d4ds.addField(m, dvfield);
            assert dfield.getParent() != null;
        }
        return d4ds;
    }

protected D4Cursor compileStructure ( DapVariable var , DapStructure dapstruct , D4Cursor container ) throws DapException { int pos = getPos ( this . databuffer ) ; D4Cursor d4ds = new D4Cursor ( Scheme . STRUCTURE , ( D4DSP ) this . dsp , var , container ) . setOffset ( pos ) ; List < DapVariable > dfields = dapstruct . getFields ( ) ; for ( int m = 0 ; m < dfields . size ( ) ; m ++ ) { DapVariable dfield = dfields . get ( m ) ; D4Cursor dvfield = compileVar ( dfield , d4ds ) ; d4ds . addField ( m , dvfield ) ; assert dfield . getParent ( ) != null ; } return d4ds ; }

Compile a structure instance.

@param dapstruct The template
@param container
@return A DataStructure for the databuffer for this struct.
@throws DapException


protected D4Cursor
    compileSequenceArray(DapVariable var, D4Cursor container)
            throws DapException
    {
        DapSequence dapseq = (DapSequence) var.getBaseType();
        D4Cursor seqarray = new D4Cursor(Scheme.SEQARRAY, this.dsp, var, container)
                .setOffset(getPos(this.databuffer));
        List<DapDimension> dimset = var.getDimensions();
        long dimproduct = DapUtil.dimProduct(dimset);
        D4Cursor[] instances = new D4Cursor[(int) dimproduct];
        Odometer odom = Odometer.factory(DapUtil.dimsetToSlices(dimset), dimset);
        while(odom.hasNext()) {
            Index index = odom.next();
            D4Cursor instance = compileSequence(var, dapseq, seqarray);
            instance.setIndex(index);
            instances[(int) index.index()] = instance;
        }
        seqarray.setElements(instances);
        return seqarray;
    }

protected D4Cursor compileSequenceArray ( DapVariable var , D4Cursor container ) throws DapException { DapSequence dapseq = ( DapSequence ) var . getBaseType ( ) ; D4Cursor seqarray = new D4Cursor ( Scheme . SEQARRAY , this . dsp , var , container ) . setOffset ( getPos ( this . databuffer ) ) ; List < DapDimension > dimset = var . getDimensions ( ) ; long dimproduct = DapUtil . dimProduct ( dimset ) ; D4Cursor [ ] instances = new D4Cursor [ ( int ) dimproduct ] ; Odometer odom = Odometer . factory ( DapUtil . dimsetToSlices ( dimset ) , dimset ) ; while ( odom . hasNext ( ) ) { Index index = odom . next ( ) ; D4Cursor instance = compileSequence ( var , dapseq , seqarray ) ; instance . setIndex ( index ) ; instances [ ( int ) index . index ( ) ] = instance ; } seqarray . setElements ( instances ) ; return seqarray ; }

Compile a sequence array.

@param var the template
@return A DataCompoundArray for the databuffer for this sequence.
@throws DapException


public D4Cursor
    compileSequence(DapVariable var, DapSequence dapseq, D4Cursor container)
            throws DapException
    {
        int pos = getPos(this.databuffer);
        D4Cursor seq = new D4Cursor(Scheme.SEQUENCE, this.dsp, var, container)
                .setOffset(pos);
        List<DapVariable> dfields = dapseq.getFields();
        // Get the count of the number of records
        long nrecs = getCount(this.databuffer);
        for(int r = 0; r < nrecs; r++) {
            pos = getPos(this.databuffer);
            D4Cursor rec = (D4Cursor) new D4Cursor(D4Cursor.Scheme.RECORD, this.dsp, var, container)
                    .setOffset(pos).setRecordIndex(r);
            for(int m = 0; m < dfields.size(); m++) {
                DapVariable dfield = dfields.get(m);
                D4Cursor dvfield = compileVar(dfield, rec);
                rec.addField(m, dvfield);
                assert dfield.getParent() != null;
            }
            seq.addRecord(rec);
        }
        return seq;
    }

Compile a sequence as a set of records.

@param dapseq
@param container
@return
@throws DapException

Compile a sequence as a set of records .


read a long in little endian format

@return long from next 8 bytes in stream, littleEndian order


public Field getField(String name) {
    Field fld = flds.get(name);
    if (fld == null) return null;
    return (fld instanceof FieldResizable) ? ((FieldResizable)fld).getDelegate() : fld;
  }

public Field getField ( String name ) { Field fld = flds . get ( name ) ; if ( fld == null ) return null ; return ( fld instanceof FieldResizable ) ? ( ( FieldResizable ) fld ) . getDelegate ( ) : fld ; }

Find the field with the specified name.
@param name of Field
@return Field or null if not found

Find the field with the specified name .


public Object getFieldValue(String name) {
    Field fld = getField(name);
    if (fld == null) throw new IllegalArgumentException("no field named "+name);
    return fld.getValue();
  }

public
Object
getFieldValue
(
String
name
)
{
Field
fld
=
getField
(
name
)
;
if
(
fld
==
)
throw
new
IllegalArgumentException
(
"no field named "
+
name
)
;
return
fld
.
getValue
(
)
;
}

Get current value of the named field
@param name of field
@return value of named field


public void setFieldValue(String name, Object value) {
    Field fld = getField(name);
    if (fld == null) throw new IllegalArgumentException("no field named "+name);
    fld.setValue(value);
  }

public
void
setFieldValue
(
String
name
,
Object
value
)
{
Field
fld
=
getField
(
name
)
;
if
(
fld
==
)
throw
new
IllegalArgumentException
(
"no field named "
+
name
)
;
fld
.
setValue
(
value
)
;
}

Set the current value of the named field
@param name of field
@param value of field


public Field addField(Field fld) {
    addField( fld, cursorCol, cursorRow, null);
    cursorRow++;
    return fld;
  }

public Field addField ( Field fld ) { addField ( fld , cursorCol , cursorRow , null ) ; cursorRow ++ ; return fld ; }

Add a field created by the user.
@param fld add this field.


public Field.CheckBox addCheckBoxField(String fldName, String label, boolean defValue) {
    Field.CheckBox fld = new Field.CheckBox(fldName, label, defValue, storeData);
    addField( fld);
    return fld;
  }

public Field . CheckBox addCheckBoxField ( String fldName , String label , boolean defValue ) { Field . CheckBox fld = new Field . CheckBox ( fldName , label , defValue , storeData ) ; addField ( fld ) ; return fld ; }

Add a boolean field as a checkbox.
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValue default value


public Field.Date addDateField(String fldName, String label, Date defValue) {
    Field.Date fld = new Field.Date(fldName, label, defValue, storeData);
    addField( new FieldResizable(fld, this));
    return fld;
  }

public Field . Date addDateField ( String fldName , String label , Date defValue ) { Field . Date fld = new Field . Date ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ; }

Add a field that edits a date
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValue default value


public Field.Double addDoubleField(String fldName, String label, double defValue) {
    Field.Double fld = new Field.Double(fldName, label, defValue, -1, storeData);
    addField( new FieldResizable(fld, this));
    return fld;
  }

public Field . Double addDoubleField ( String fldName , String label , double defValue ) { Field . Double fld = new Field . Double ( fldName , label , defValue , - 1 , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ; }

Add a field that edits a double
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValue default value


public Field.Int addIntField(String fldName, String label, int defValue) {
    Field.Int fld = new Field.Int(fldName, label, defValue, storeData);
    addField( new FieldResizable(fld, this));
    return fld;
  }

public Field . Int addIntField ( String fldName , String label , int defValue ) { Field . Int fld = new Field . Int ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ; }

Add a field that edits an integer
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValue default value


public Field.Password addPasswordField(String fldName, String label, String defValue) {
    Field.Password fld = new Field.Password(fldName, label, defValue, storeData);
    addField( new FieldResizable(fld, this));
    return fld;
  }

public Field . Password addPasswordField ( String fldName , String label , String defValue ) { Field . Password fld = new Field . Password ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ; }

Add a password text field.
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValue default value


public Field.Text addTextField(String fldName, String label, String defValue) {
    Field.Text fld = new Field.Text(fldName, label, defValue, storeData);
    addField( new FieldResizable(fld, this));
    return fld;
  }

public Field . Text addTextField ( String fldName , String label , String defValue ) { Field . Text fld = new Field . Text ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ; }

Add a text field.
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValue default value
@return the Field.Text object that was added


public Field.TextCombo addTextComboField(String fldName, String label, java.util.Collection defValues, int nKeep, boolean editable) {
    Field.TextCombo fld = new Field.TextCombo(fldName, label, defValues, nKeep, storeData);
    addField( fld);
    fld.setEditable( editable);
    return fld;
  }

public Field . TextCombo addTextComboField ( String fldName , String label , java . util . Collection defValues , int nKeep , boolean editable ) { Field . TextCombo fld = new Field . TextCombo ( fldName , label , defValues , nKeep , storeData ) ; addField ( fld ) ; fld . setEditable ( editable ) ; return fld ; }

Add a text combobox field.
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param defValues list of default values (Strings) to include in the comboBox. May be null.
These are added to the combobox (at the end) no matter how many there are.
@param nKeep number of most recently used values to keep
@param editable whether the user can add new entries the list to select from.


public Field.TextArea addTextAreaField(String fldName, String label, String def, int nrows) {
    Field.TextArea fld = new Field.TextArea(fldName, label, def, nrows, storeData);
    addField( fld);
    return fld;
  }

public Field . TextArea addTextAreaField ( String fldName , String label , String def , int nrows ) { Field . TextArea fld = new Field . TextArea ( fldName , label , def , nrows , storeData ) ; addField ( fld ) ; return fld ; }

Add a TextArea field.
@param fldName the name to store the data in the PersistenceManagerData
@param label used as the label on the panel
@param def default value
@param nrows number of rows


public void addHeading(String heading, int row) {
    layoutComponents.add( new LayoutComponent( heading, 0, row, null));
  }

public void addHeading ( String heading , int row ) { layoutComponents . add ( new LayoutComponent ( heading , 0 , row , null ) ) ; }

Add a heading at the specified row. this spans all columns

Add a heading at the specified row . this spans all columns


public void addComponent(Component comp, int col, int row, String constraint) {
    layoutComponents.add( new LayoutComponent( comp, col, row, constraint));
  }

public void addComponent ( Component comp , int col , int row , String constraint ) { layoutComponents . add ( new LayoutComponent ( comp , col , row , constraint ) ) ; }


public void addEmptyRow(int row, int size) {
    layoutComponents.add( new LayoutComponent( null, size, row, null));
  }

public void addEmptyRow ( int row , int size ) { layoutComponents . add ( new LayoutComponent ( null , size , row , null ) ) ; }

Add a seperator after the last field added.

Add a seperator after the last field added .


static public Frame findActiveFrame() {
    Frame[] frames = JFrame.getFrames();
    for (Frame frame : frames) {
      if (frame.isVisible())
        return frame;
    }
    return null;
  }

static public Frame findActiveFrame ( ) { Frame [ ] frames = JFrame . getFrames ( ) ; for ( Frame frame : frames ) { if ( frame . isVisible ( ) ) return frame ; } return null ; }


public float getCellSpacing() throws DescriptorException {
    float[] cellRanges = myCELV.getCellRanges();
    //
    // use the first cell spacing as our expected value
    //
    float cellSpacing = cellRanges[1] - cellRanges[0];
    //
    // Check the rest of the cells against the expected value, allowing
    // 1% fudge
    //
    for (int i = 2; i < cellRanges.length; i++) {
      float space = cellRanges[i] - cellRanges[i - 1];
      if (!Misc.nearlyEquals(space, cellSpacing) && (Math.abs(space / cellSpacing - 1.0) > 0.01)) {
        throw new DescriptorException("variable cell spacing");
      }
    }
    return cellSpacing;
  }

Get the cell spacing.  An exception is thrown if the cell spacing
is not constant.

@return the cell spacing, in meters
@throws DescriptorException if the cell spacing is not constant.

Get the cell spacing . An exception is thrown if the cell spacing is not constant .


public final Factor[] getFactors() {
        final Factor[] factors = new Factor[_factors.length];
        System.arraycopy(_factors, 0, factors, 0, factors.length);
        return factors;
    }

public final Factor [ ] getFactors ( ) { final Factor [ ] factors = new Factor [ _factors . length ] ; System . arraycopy ( _factors , 0 , factors , 0 , factors . length ) ; return factors ; }

Returns the array of Factor-s constituting this dimension.

@return The array of Factor-s constituting this dimension.

Returns the array of Factor - s constituting this dimension .


protected Factor[] mult(final Dimension that) {
        // relys on _factors always sorted
        final Factor[] factors1 = _factors;
        final Factor[] factors2 = that._factors;
        int i1 = 0;
        int i2 = 0;
        int k = 0;
        Factor[] newFactors = new Factor[factors1.length + factors2.length];
        for (;;) {
            if (i1 == factors1.length) {
                final int n = factors2.length - i2;
                System.arraycopy(factors2, i2, newFactors, k, n);
                k += n;
                break;
            }
            if (i2 == factors2.length) {
                final int n = factors1.length - i1;
                System.arraycopy(factors1, i1, newFactors, k, n);
                k += n;
                break;
            }
            final Factor f1 = factors1[i1];
            final Factor f2 = factors2[i2];
            final int comp = f1.getID().compareTo(f2.getID());
            if (comp < 0) {
                newFactors[k++] = f1;
                i1++;
            }
            else if (comp == 0) {
                final int exponent = f1.getExponent() + f2.getExponent();
                if (exponent != 0) {
                    newFactors[k++] = new Factor(f1, exponent);
                }
                i1++;
                i2++;
            }
            else {
                newFactors[k++] = f2;
                i2++;
            }
        }
        if (k < newFactors.length) {
            final Factor[] tmp = new Factor[k];
            System.arraycopy(newFactors, 0, tmp, 0, k);
            newFactors = tmp;
        }
        return newFactors;
    }

protected
Factor
[
]
mult
(
final
Dimension
that
)
{
// relys on _factors always sorted
final
Factor
[
]
factors1
=
_factors
;
final
Factor
[
]
factors2
=
that
.
_factors
;
int
i1
=
0
;
int
i2
=
0
;
int
k
=
0
;
Factor
[
]
newFactors
=
new
Factor
[
factors1
.
length
+
factors2
.
length
]
;
for
(
;
;
)
{
if
(
i1
==
factors1
.
length
)
{
final
int
n
=
factors2
.
length
i2
;
System
.
arraycopy
(
factors2
,
i2
,
newFactors
,
k
,
n
)
;
k
+=
n
;
break
;
}
if
(
i2
==
factors2
.
length
)
{
final
int
n
=
factors1
.
length
i1
;
System
.
arraycopy
(
factors1
,
i1
,
newFactors
,
k
,
n
)
;
k
+=
n
;
break
;
}
final
Factor
f1
=
factors1
[
i1
]
;
final
Factor
f2
=
factors2
[
i2
]
;
final
int
comp
=
f1
.
getID
(
)
.
compareTo
(
f2
.
getID
(
)
)
;
if
(
comp
<
0
)
{
newFactors
[
k
++
]
=
f1
;
i1
++
;
}
else
if
(
comp
==
0
)
{
final
int
exponent
=
f1
.
getExponent
(
)
+
f2
.
getExponent
(
)
;
if
(
exponent
!=
0
)
{
newFactors
[
k
++
]
=
new
Factor
(
f1
,
exponent
)
;
}
i1
++
;
i2
++
;
}
else
{
newFactors
[
k
++
]
=
f2
;
i2
++
;
}
}
if
(
k
<
newFactors
.
length
)
{
final
Factor
[
]
tmp
=
new
Factor
[
k
]
;
System
.
arraycopy
(
newFactors
,
0
,
tmp
,
0
,
k
)
;
newFactors
=
tmp
;
}
return
newFactors
;
}

Multiplies this dimension by another dimension.

@param that
The other dimension.
@return The product of the Factor-s of this dimension and the Factor-s of
the other dimension.

Multiplies this dimension by another dimension .


protected Factor[] pow(final int power) {
        Factor[] factors;
        if (power == 0) {
            factors = new Factor[0];
        }
        else {
            factors = getFactors();
            if (power != 1) {
                for (int i = factors.length; --i >= 0;) {
                    factors[i] = factors[i].pow(power);
                }
            }
        }
        return factors;
    }

protected Factor [ ] pow ( final int power ) { Factor [ ] factors ; if ( power == 0 ) { factors = new Factor [ 0 ] ; } else { factors = getFactors ( ) ; if ( power != 1 ) { for ( int i = factors . length ; -- i >= 0 ; ) { factors [ i ] = factors [ i ] . pow ( power ) ; } } } return factors ; }

Raises this dimension to a power.

@param power
The power to raise this dimension by.
@return The Factor-s of this dimension raised to the power
power.


public final boolean isReciprocalOf(final Dimension that) {
        final Factor[] theseFactors = _factors;
        final Factor[] thoseFactors = that._factors;
        boolean isReciprocalOf;
        if (theseFactors.length != thoseFactors.length) {
            isReciprocalOf = false;
        }
        else {
            int i;
            for (i = theseFactors.length; --i >= 0;) {
                if (!theseFactors[i].isReciprocalOf(thoseFactors[i])) {
                    break;
                }
            }
            isReciprocalOf = i < 0;
        }
        return isReciprocalOf;
    }

public final boolean isReciprocalOf ( final Dimension that ) { final Factor [ ] theseFactors = _factors ; final Factor [ ] thoseFactors = that . _factors ; boolean isReciprocalOf ; if ( theseFactors . length != thoseFactors . length ) { isReciprocalOf = false ; } else { int i ; for ( i = theseFactors . length ; -- i >= 0 ; ) { if ( ! theseFactors [ i ] . isReciprocalOf ( thoseFactors [ i ] ) ) { break ; } } isReciprocalOf = i < 0 ; } return isReciprocalOf ; }

Indicates if this Dimension is the reciprocal of another dimension.

@param that
The other dimension.
@return true if and only if this dimension is the reciprocal
of the other dimension.

Indicates if this Dimension is the reciprocal of another dimension .


public final boolean isDimensionless() {
        for (int i = _factors.length; --i >= 0;) {
            if (!_factors[i].isDimensionless()) {
                return false;
            }
        }
        return true;
    }

public final boolean isDimensionless ( ) { for ( int i = _factors . length ; -- i >= 0 ; ) { if ( ! _factors [ i ] . isDimensionless ( ) ) { return false ; } } return true ; }

Indicates if this dimension is dimensionless. A dimension is
dimensionless if it has no Factor-s or if all Factor-s are, themselves,
dimensionless.

@return true if and only if this dimension is dimensionless.

Indicates if this dimension is dimensionless . A dimension is dimensionless if it has no Factor - s or if all Factor - s are themselves dimensionless .


public static Grib1ParamTables factory(String paramTablePath, String lookupTablePath) throws IOException {
    if (paramTablePath == null && lookupTablePath == null) return new Grib1ParamTables();
    Lookup lookup = null;
    Grib1ParamTableReader override = null;

    Grib1ParamTableReader table;
    if (paramTablePath != null) {
      table = localTableHash.get(paramTablePath);
      if (table == null) {
        table = new Grib1ParamTableReader(paramTablePath);
        localTableHash.put(paramTablePath, table);
        override = table;
      }
    }

    if (lookupTablePath != null) {
      lookup = new Lookup();
      if (!lookup.readLookupTable(lookupTablePath))
        throw new FileNotFoundException("cant read lookup table=" + lookupTablePath);
    }

    return new Grib1ParamTables(lookup, override);
  }

public
static
Grib1ParamTables
factory
(
String
paramTablePath
,
String
lookupTablePath
)
throws
IOException
{
if
(
paramTablePath
==
&&
lookupTablePath
==
)
return
new
Grib1ParamTables
(
)
;
Lookup
lookup
=
;
Grib1ParamTableReader
override
=
;
Grib1ParamTableReader
table
;
if
(
paramTablePath
!=
)
{
table
=
localTableHash
.
get
(
paramTablePath
)
;
if
(
table
==
)
{
table
=
new
Grib1ParamTableReader
(
paramTablePath
)
;
localTableHash
.
put
(
paramTablePath
,
table
)
;
override
=
table
;
}
}
if
(
lookupTablePath
!=
)
{
lookup
=
new
Lookup
(
)
;
if
(
!
lookup
.
readLookupTable
(
lookupTablePath
)
)
throw
new
FileNotFoundException
(
"cant read lookup table="
+
lookupTablePath
)
;
}
return
new
Grib1ParamTables
(
lookup
,
override
)
;
}

Get a Grib1ParamTables object, optionally specifying a parameter table or lookup table specific to this dataset.

@param paramTablePath  path to a parameter table, in format Grib1ParamTable can read.
@param lookupTablePath path to a lookup table, in format Lookup.readLookupTable() can read.
@return Grib1Tables
@throws IOException on read error

Get a Grib1ParamTables object optionally specifying a parameter table or lookup table specific to this dataset .


public static Grib1ParamTables factory(org.jdom2.Element paramTableElem) {
    if (paramTableElem == null) return new Grib1ParamTables();
    return new Grib1ParamTables(null, new Grib1ParamTableReader(paramTableElem));
  }

public static Grib1ParamTables factory ( org . jdom2 . Element paramTableElem ) { if ( paramTableElem == null ) return new Grib1ParamTables ( ) ; return new Grib1ParamTables ( null , new Grib1ParamTableReader ( paramTableElem ) ) ; }

Get a Grib1Tables object, optionally specifiying a parameter table in XML specific to this dataset.

@param paramTableElem parameter table in XML
@return Grib1Tables

Get a Grib1Tables object optionally specifiying a parameter table in XML specific to this dataset .


public static boolean addParameterTableLookup(String lookupFilename) throws IOException {
    Lookup lookup = new Lookup();
    if (!lookup.readLookupTable(lookupFilename))
      return false;

    synchronized (lock) {
      standardLookup.tables.addAll(standardTablesStart, lookup.tables);
      standardTablesStart += lookup.tables.size();
    }
    return true;
  }

public static boolean addParameterTableLookup ( String lookupFilename ) throws IOException { Lookup lookup = new Lookup ( ) ; if ( ! lookup . readLookupTable ( lookupFilename ) ) return false ; synchronized ( lock ) { standardLookup . tables . addAll ( standardTablesStart , lookup . tables ) ; standardTablesStart += lookup . tables . size ( ) ; } return true ; }

Add all tables in list to standard tables

@param lookupFilename filename containing list of tables
@return true if  read ok, false if file not found
@throws IOException if file found but read error


public static void addParameterTable(int center, int subcenter, int tableVersion, String tableFilename) {
    Grib1ParamTableReader table = new Grib1ParamTableReader(center, subcenter, tableVersion, tableFilename);
    synchronized (lock) {
      standardLookup.tables.add(standardTablesStart, table);
      standardTablesStart++;
    }
  }

public static void addParameterTable ( int center , int subcenter , int tableVersion , String tableFilename ) { Grib1ParamTableReader table = new Grib1ParamTableReader ( center , subcenter , tableVersion , tableFilename ) ; synchronized ( lock ) { standardLookup . tables . add ( standardTablesStart , table ) ; standardTablesStart ++ ; } }

Add table to standard tables for a specific center, subcenter and version.

@param center        center id
@param subcenter     subcenter id, or -1 for all
@param tableVersion  table verssion, or -1 for all
@param tableFilename file to read parameter table from

Add table to standard tables for a specific center subcenter and version .


@Override
    protected Unit myRaiseTo(final int power) throws RaiseException {
        if (power == 0) {
            return DerivedUnitImpl.DIMENSIONLESS;
        }
        if (power == 1) {
            return this;
        }
        throw new RaiseException(this);
    }

@ Override protected Unit myRaiseTo ( final int power ) throws RaiseException { if ( power == 0 ) { return DerivedUnitImpl . DIMENSIONLESS ; } if ( power == 1 ) { return this ; } throw new RaiseException ( this ) ; }

Raise this unit to a power.

@param power
The power to raise this unit by. The only meaningful values
are 0 and 1.
@return The result of raising this unit by the power power.
@throws RaiseException
Can't raise this unit to {@code power}, which is neither 0
nor 1.


public float[] toDerivedUnit(final float[] input, final float[] output)
            throws ConversionException {
        for (int i = input.length; --i >= 0;) {
            output[i] = (float) (Math.exp(input[i] * lnBase));
        }
        return reference.toDerivedUnit(output, output);
    }

public float [ ] toDerivedUnit ( final float [ ] input , final float [ ] output ) throws ConversionException { for ( int i = input . length ; -- i >= 0 ; ) { output [ i ] = ( float ) ( Math . exp ( input [ i ] * lnBase ) ) ; } return reference . toDerivedUnit ( output , output ) ; }

Converts values in this unit to the equivalent values in the convertible
derived unit.

@param input
The values in this unit.
@param output
The equivalent values in the convertible derived unit. May be
the same array as input.
@return output.
@throws ConversionException
Can't convert between units.

Converts values in this unit to the equivalent values in the convertible derived unit .


private static void initUnitTable() {
    unitTable = new Hashtable<>();
    // temperatures
    unitTable.put("t", "K");
    unitTable.put("td", "K");
    unitTable.put("thte", "K");
    // winds
    unitTable.put("u", "m/s");
    unitTable.put("v", "m/s");
    unitTable.put("w", "m/s");
    // pressure
    unitTable.put("p", "hPa");
    unitTable.put("mmsl", "hPa");
    // moisture
    unitTable.put("rh", "%");
    // misc
    unitTable.put("rhfz", "%");
    unitTable.put("zagl", "m");
  }

private
static
void
initUnitTable
(
)
{
unitTable
=
new
Hashtable
<>
(
)
;
// temperatures
unitTable
.
put
(
"t"
,
"K"
)
;
unitTable
.
put
(
"td"
,
"K"
)
;
unitTable
.
put
(
"thte"
,
"K"
)
;
// winds
unitTable
.
put
(
"u"
,
"m/s"
)
;
unitTable
.
put
(
"v"
,
"m/s"
)
;
unitTable
.
put
(
"w"
,
"m/s"
)
;
// pressure
unitTable
.
put
(
"p"
,
"hPa"
)
;
unitTable
.
put
(
"mmsl"
,
"hPa"
)
;
// moisture
unitTable
.
put
(
"rh"
,
"%"
)
;
// misc
unitTable
.
put
(
"rhfz"
,
"%"
)
;
unitTable
.
put
(
"zagl"
,
"m"
)
;
}

Initialize the unit table.  This is used if there are no
units in the file.

Initialize the unit table . This is used if there are no units in the file .


private Variable makeVerticalVariable(int vert_sys, int n_levels,
                                        float[] vert_args)
          throws IOException {

    String vert_unit = null;
    String vert_type;
    ArrayFloat.D1 data = new ArrayFloat.D1(n_levels);
    AxisType axisType = null;

    switch (vert_sys) {

      case (0):
        vert_unit = null;
        vert_type = "height";
        break;

      case (1):
      case (2):
        vert_unit = "km";
        vert_type = "altitude";
        axisType = AxisType.Height;
        break;

      case (3):
        vert_unit = "mbar";
        vert_type = "pressure";
        axisType = AxisType.Pressure;
        break;

      default:
        throw new IOException("vert_sys unknown");
    }

    Variable vertVar = new Variable(ncfile, null, null, vert_type);
    vertVar.setDimensions(LEVEL);
    vertVar.setDataType(DataType.FLOAT);
    if (vert_unit != null) {
      vertVar.addAttribute(new Attribute(CDM.UNITS, vert_unit));
    }
    if (axisType != null) {
      vertVar.addAttribute(new Attribute(_Coordinate.AxisType,
              axisType.toString()));
    }

    switch (vert_sys) {

      case (0):
      case (1):
        for (int i = 0; i < n_levels; i++) {
          data.set(i, vert_args[0] + vert_args[1] * i);
        }
        break;

      case (2):  // Altitude in km - non-linear
        for (int i = 0; i < n_levels; i++) {
          data.set(i, vert_args[i]);
        }
        break;

      case (3):  // heights of pressure surfaces in km - non-linear
        try {
          Vis5DVerticalSystem.Vis5DVerticalCoordinateSystem vert_cs =
                  new Vis5DVerticalSystem.Vis5DVerticalCoordinateSystem();
          float[][] pressures = new float[1][n_levels];
          System.arraycopy(vert_args, 0, pressures[0], 0, n_levels);
          for (int i = 0; i < n_levels; i++) {
            pressures[0][i] *= 1000;  // km->m
          }
          pressures = vert_cs.fromReference(pressures);  // convert to pressures
          for (int i = 0; i < n_levels; i++) {
            data.set(i, pressures[0][i]);
          }
        } catch (VisADException ve) {
          throw new IOException("unable to make vertical system");
        }
        break;
    }
    vertVar.setCachedData(data, false);
    return vertVar;
  }

Create a vertical dimension variable based on the info.  Based on
visad.data.vis5d.Vis5DVerticalSystem.

@param vert_sys  the vertical system id
@param n_levels  the number of levels
@param vert_args the vertical system arguments
@return the vertical dimesion variable
@throws IOException problem reading the file or creating the data

Create a vertical dimension variable based on the info . Based on visad . data . vis5d . Vis5DVerticalSystem .


protected static String peekName(RandomAccessFile file)
          throws DescriptorException {
    try {
      long filepos = file.getFilePointer();
      byte[] nameBytes = new byte[4];
      if (file.read(nameBytes) == -1)
        return null;  // EOF
      file.seek(filepos);
      return new String(nameBytes, CDM.utf8Charset);

    } catch (IOException ex) {
      throw new DescriptorException(ex);
    }
  }

protected
static
String
peekName
(
RandomAccessFile
file
)
throws
DescriptorException
{
try
{
long
filepos
=
file
.
getFilePointer
(
)
;
byte
[
]
nameBytes
=
new
byte
[
4
]
;
if
(
file
.
read
(
nameBytes
)
==
1
)
return
;
// EOF
file
.
seek
(
filepos
)
;
return
new
String
(
nameBytes
,
CDM
.
utf8Charset
)
;
}
catch
(
IOException
ex
)
{
throw
new
DescriptorException
(
ex
)
;
}
}

Return the name of the DORADE descriptor at the current location
in the file.  The current location will not be changed.

@param file the DORADE sweep file, positioned at the beginning of a
descriptor
@return the name of the DORADE descriptor starting at the current
file position, or null if no descriptor name is available
@throws DescriptorException

Return the name of the DORADE descriptor at the current location in the file . The current location will not be changed .


protected short grabShort(byte[] bytes, int offset) {
    int ndx0 = offset + (littleEndianData ? 1 : 0);
    int ndx1 = offset + (littleEndianData ? 0 : 1);
    // careful that we only allow sign extension on the highest order byte
    return (short) (bytes[ndx0] << 8 | (bytes[ndx1] & 0xff));
  }

Unpack a two-byte integer from the given byte array.

@param bytes  byte array to be read
@param offset number of bytes to skip in the byte array before reading
@return the unpacked short value

Unpack a two - byte integer from the given byte array .


protected static int grabInt(byte[] bytes, int offset,
                               boolean littleEndianData) {
    int ndx0 = offset + (littleEndianData ? 3 : 0);
    int ndx1 = offset + (littleEndianData ? 2 : 1);
    int ndx2 = offset + (littleEndianData ? 1 : 2);
    int ndx3 = offset + (littleEndianData ? 0 : 3);

    // careful that we only allow sign extension on the highest order byte
    return (bytes[ndx0] << 24 |
            (bytes[ndx1] & 0xff) << 16 |
            (bytes[ndx2] & 0xff) << 8 |
            (bytes[ndx3] & 0xff));
  }

Unpack a four-byte integer from the given byte array.

@param bytes            byte array to be read
@param offset           number of bytes to skip in the byte array before reading
@param littleEndianData true iff the byte array contains little-endian
data
@return the unpacked integer value

Unpack a four - byte integer from the given byte array .


protected float grabFloat(byte[] bytes, int offset)
          throws DescriptorException {
    try {
      byte[] src;
      if (littleEndianData) {
        src = new byte[4];
        src[0] = bytes[offset + 3];
        src[1] = bytes[offset + 2];
        src[2] = bytes[offset + 1];
        src[3] = bytes[offset];
        offset = 0;
      } else {
        src = bytes;
      }
      DataInputStream stream =
              new DataInputStream(new ByteArrayInputStream(src, offset, 4));
      return stream.readFloat();
    } catch (Exception ex) {
      throw new DescriptorException(ex);
    }
  }

protected float grabFloat ( byte [ ] bytes , int offset ) throws DescriptorException { try { byte [ ] src ; if ( littleEndianData ) { src = new byte [ 4 ] ; src [ 0 ] = bytes [ offset + 3 ] ; src [ 1 ] = bytes [ offset + 2 ] ; src [ 2 ] = bytes [ offset + 1 ] ; src [ 3 ] = bytes [ offset ] ; offset = 0 ; } else { src = bytes ; } DataInputStream stream = new DataInputStream ( new ByteArrayInputStream ( src , offset , 4 ) ) ; return stream . readFloat ( ) ; } catch ( Exception ex ) { throw new DescriptorException ( ex ) ; } }

Unpack a four-byte IEEE float from the given byte array.

@param bytes  byte array to be read
@param offset number of bytes to skip in the byte array before reading
@return the unpacked float value

Unpack a four - byte IEEE float from the given byte array .


protected double grabDouble(byte[] bytes, int offset)
          throws DescriptorException {
    try {
      byte[] src;
      if (littleEndianData) {
        src = new byte[8];
        src[0] = bytes[offset + 7];
        src[1] = bytes[offset + 6];
        src[2] = bytes[offset + 5];
        src[3] = bytes[offset + 4];
        src[4] = bytes[offset + 3];
        src[5] = bytes[offset + 2];
        src[6] = bytes[offset + 1];
        src[7] = bytes[offset];
        offset = 0;
      } else {
        src = bytes;
      }
      DataInputStream stream =
              new DataInputStream(new ByteArrayInputStream(src, offset, 8));
      return stream.readDouble();
    } catch (Exception ex) {
      throw new DescriptorException(ex);
    }
  }

protected double grabDouble ( byte [ ] bytes , int offset ) throws DescriptorException { try { byte [ ] src ; if ( littleEndianData ) { src = new byte [ 8 ] ; src [ 0 ] = bytes [ offset + 7 ] ; src [ 1 ] = bytes [ offset + 6 ] ; src [ 2 ] = bytes [ offset + 5 ] ; src [ 3 ] = bytes [ offset + 4 ] ; src [ 4 ] = bytes [ offset + 3 ] ; src [ 5 ] = bytes [ offset + 2 ] ; src [ 6 ] = bytes [ offset + 1 ] ; src [ 7 ] = bytes [ offset ] ; offset = 0 ; } else { src = bytes ; } DataInputStream stream = new DataInputStream ( new ByteArrayInputStream ( src , offset , 8 ) ) ; return stream . readDouble ( ) ; } catch ( Exception ex ) { throw new DescriptorException ( ex ) ; } }

Unpack an eight-byte IEEE float from the given byte array.

@param bytes  byte array to be read
@param offset number of bytes to skip in the byte array before reading
@return the unpacked double value

Unpack an eight - byte IEEE float from the given byte array .


private void aa(final String alias, final String name)
          throws UnitExistsException, NoSuchUnitException,
          UnitParseException, SpecificationException, UnitDBException,
          PrefixDBException, OperationException, NameException,
          UnitSystemException {
    aa(alias, name, null);
  }

private void aa ( final String alias , final String name ) throws UnitExistsException , NoSuchUnitException , UnitParseException , SpecificationException , UnitDBException , PrefixDBException , OperationException , NameException , UnitSystemException { aa ( alias , name , null ) ; }

Adds an alias for a unit to the database.

@param alias The alias for the unit.
@param name  The name of the unit.
@throws UnitExistsException    Attempt to redefine an existing unit.
@throws NameException          Bad unit name.
@throws UnitParseException     A string specification couldn't be parsed.
@throws SpecificationException Bad string specification.
@throws UnitDBException        Problem with the unit database.
@throws PrefixDBException      Problem with the prefix database.
@throws NameException          Bad unit name.
@throws OperationException     Improper unit operation.
@throws UnitSystemException    Problem with UnitSystem.

Adds an alias for a unit to the database .


private void as(final String symbol, final String name)
          throws UnitExistsException, NoSuchUnitException,
          UnitParseException, SpecificationException, UnitDBException,
          PrefixDBException, OperationException, NameException,
          UnitSystemException {
    addSymbol(symbol, name);
  }

private void as ( final String symbol , final String name ) throws UnitExistsException , NoSuchUnitException , UnitParseException , SpecificationException , UnitDBException , PrefixDBException , OperationException , NameException , UnitSystemException { addSymbol ( symbol , name ) ; }

Adds a symbol for a unit to the database.

@param symbol The symbol for the unit.
@param name   The name of the unit.
@throws UnitExistsException    Attempt to redefine an existing unit.
@throws NameException          Bad unit name.
@throws UnitParseException     A string specification couldn't be parsed.
@throws SpecificationException Bad string specification.
@throws UnitDBException        Problem with the unit database.
@throws PrefixDBException      Problem with the prefix database.
@throws NameException          Bad unit name.
@throws OperationException     Improper unit operation.
@throws UnitSystemException    Problem with UnitSystem.

Adds a symbol for a unit to the database .


public static Converter
    create(Unit fromUnit, Unit toUnit)
	throws ConversionException
    {
	return fromUnit.getConverterTo(toUnit);
    }

public static Converter create ( Unit fromUnit , Unit toUnit ) throws ConversionException { return fromUnit . getConverterTo ( toUnit ) ; }

Factory method for creating a unit converter.
@param fromUnit		The unit from which to convert.
@param toUnit            The unit to which to convert.
@throws ConversionException      The units are not convertible.

Factory method for creating a unit converter .


public void setStructureData(List<StructureData> structureData) throws IOException {
    dataModel = new StructureDataModel(structureData);
    initTable(dataModel);
  }

public void setStructureData ( List < StructureData > structureData ) throws IOException { dataModel = new StructureDataModel ( structureData ) ; initTable ( dataModel ) ; }

Set the data as a collection of StructureData.

@param structureData List of type StructureData
@throws IOException on io error

Set the data as a collection of StructureData .


public void setPointFeatureData(List<PointFeature> obsData) throws IOException {
    dataModel = new PointFeatureDataModel(obsData);
    initTable(dataModel);
  }

public void setPointFeatureData ( List < PointFeature > obsData ) throws IOException { dataModel = new PointFeatureDataModel ( obsData ) ; initTable ( dataModel ) ; }

Set the data as a collection of PointFeature.

@param obsData List of type PointFeature
@throws IOException on io error

Set the data as a collection of PointFeature .


public void draw(java.awt.Graphics2D g, AffineTransform pixelAT) {
    g.setColor(color);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g.setStroke(new java.awt.BasicStroke(0.0f));

    Rectangle2D clipRect = (Rectangle2D) g.getClip();
    Iterator siter = getShapes(g, pixelAT);
    while (siter.hasNext()) {
      Shape s = (Shape) siter.next();
      Rectangle2D shapeBounds = s.getBounds2D();
      if (shapeBounds.intersects(clipRect))
        g.draw(s);
    }
  }

public void draw ( java . awt . Graphics2D g , AffineTransform pixelAT ) { g . setColor ( color ) ; g . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_OFF ) ; g . setStroke ( new java . awt . BasicStroke ( 0.0f ) ) ; Rectangle2D clipRect = ( Rectangle2D ) g . getClip ( ) ; Iterator siter = getShapes ( g , pixelAT ) ; while ( siter . hasNext ( ) ) { Shape s = ( Shape ) siter . next ( ) ; Rectangle2D shapeBounds = s . getBounds2D ( ) ; if ( shapeBounds . intersects ( clipRect ) ) g . draw ( s ) ; } }

Draws all the features that are within the graphics clip rectangle,
using the previously set displayProjection.

@param g the Graphics2D context on which to draw
@param pixelAT  transforms "Normalized Device" to Device coordinates

Draws all the features that are within the graphics clip rectangle using the previously set displayProjection .


protected Iterator getShapes(java.awt.Graphics2D g, AffineTransform normal2device) {
    if (shapeList != null)
      return shapeList.iterator();

    if(Debug.isSet("projection/LatLonShift"))
      System.out.println("projection/LatLonShift GisFeatureRenderer.getShapes called");

    ProjectionImpl dataProject = getDataProjection();

    // a list of GisFeatureAdapter-s
    List featList = getFeatures();

    shapeList = new ArrayList(featList.size());

    Iterator iter = featList.iterator();

    while (iter.hasNext())
        {
        AbstractGisFeature feature = (AbstractGisFeature) iter.next();
        Shape shape;
        if (dataProject == null)
            shape = feature.getShape();
        else if (dataProject.isLatLon())  {
            // always got to run it through if its lat/lon
            shape = feature.getProjectedShape(displayProject);
            //System.out.println("getShapes dataProject.isLatLon() "+displayProject);
        } else if (dataProject == displayProject) {
            shape = feature.getShape();
            //System.out.println("getShapes dataProject == displayProject");
        } else {
            shape = feature.getProjectedShape(dataProject, displayProject);
            //System.out.println("getShapes dataProject != displayProject");
        }

        shapeList.add(shape);
        }

    return shapeList.iterator();
  }

get the set of shapes to draw, convert projections if need be

get the set of shapes to draw convert projections if need be


public void processStream(InputStream is) throws IOException {
    int pos = -1;
    Buffer b = null;
    while (true) {
      b = (pos < 0) ? readBuffer(is) : readBuffer(is, b, pos);
      pos = processBuffer(b, is);
      if (b.done) break;
    }
  }

public void processStream ( InputStream is ) throws IOException { int pos = - 1 ; Buffer b = null ; while ( true ) { b = ( pos < 0 ) ? readBuffer ( is ) : readBuffer ( is , b , pos ) ; pos = processBuffer ( b , is ) ; if ( b . done ) break ; } }


private boolean readBuffer(InputStream is, byte[] dest, int start, int want) throws IOException {
    int done = 0;
    while (done < want) {
      int got = is.read(dest, start + done, want - done);
      if (got < 0)
        return false;
      done += got;
    }

    if (showRead) System.out.println("Read buffer at " + bytesRead + " len=" + done);
    bytesRead += done;
    return true;
  }

private
boolean
readBuffer
(
InputStream
is
,
byte
[
]
dest
,
int
start
,
int
want
)
throws
IOException
{
int
done
=
0
;
while
(
done
<
want
)
{
int
got
=
is
.
read
(
dest
,
start
+
done
,
want
done
)
;
if
(
got
<
0
)
return
false
;
done
+=
got
;
}
if
(
showRead
)
System
.
out
.
println
(
"Read buffer at "
+
bytesRead
+
" len="
+
done
)
;
bytesRead
+=
done
;
return
true
;
}

read into dest byte array, until buffer is full or end of stream

read into dest byte array until buffer is full or end of stream


private void getMoreBytes() throws IOException {
        currentOffset = 0;   // reset current array offset to 0
        int bytesRead = 0;   // bytes read so far
        int lookingFor = 0;  // character in endSequence to look for
        for (; bytesRead < lineBuf.length; bytesRead++) {
            int c = in.read();
            if (c == -1)
                break;  // break on EOL and return what we have so far

            lineBuf[bytesRead] = (byte) c;
            if (lineBuf[bytesRead] == endSequence[lookingFor]) {
                lookingFor++;
                if (lookingFor == endSequence.length) {
                    endFound = true;
                    break;
                }
            } else if (lineBuf[bytesRead] == endSequence[0]) { // CHANGED JC
                lookingFor = 1;
            } else {
                lookingFor = 0;
            }
        }
        bytesRemaining = bytesRead;  // number of bytes we've read
    }

Get more bytes into buffer.  Stop when endSequence is found.

Get more bytes into buffer . Stop when endSequence is found .


public int read(byte b[], int off, int len) throws IOException {
        if (len <= 0) {
            return 0;
        }

        int c = read();
        if (c == -1)
            return -1;
        b[off] = (byte) c;

        // We've read one byte successfully, let's try for more
        int i = 1;
        try {
            for (; i < len; i++) {
                c = read();
                if (c == -1) {
                    break;
                }
                b[off + i] = (byte) c;
            }
        } catch (IOException e) {
        }
        return i;
    }

Reads up to len bytes of data from this input stream into an array of
bytes. This method blocks until some input is available.

Reads up to len bytes of data from this input stream into an array of bytes . This method blocks until some input is available .


public long skip(long n) {
        if (bytesRemaining >= n) {
            bytesRemaining -= n;
            return n;
        } else {
            int oldBytesRemaining = bytesRemaining;
            bytesRemaining = 0;
            return oldBytesRemaining;
        }
    }

public long skip ( long n ) { if ( bytesRemaining >= n ) { bytesRemaining -= n ; return n ; } else { int oldBytesRemaining = bytesRemaining ; bytesRemaining = 0 ; return oldBytesRemaining ; } }

Skips over and discards n bytes of data from the input stream.

Skips over and discards n bytes of data from the input stream .


void addDimensionsToNetcdfFile(NetcdfFile ncfile, Group g) {
    if (!isVertDimensionUsed())
      return;

    int nlevs = levels.size();
    if ( coordValues != null )
      nlevs = coordValues.length;
    ncfile.addDimension(g, new Dimension(getVariableName(), nlevs, true));
  }

void addDimensionsToNetcdfFile ( NetcdfFile ncfile , Group g ) { if ( ! isVertDimensionUsed ( ) ) return ; int nlevs = levels . size ( ) ; if ( coordValues != null ) nlevs = coordValues . length ; ncfile . addDimension ( g , new Dimension ( getVariableName ( ) , nlevs , true ) ) ; }

Add this coord as a dimension to the netCDF file

@param ncfile file to add to
@param g      group in the file


private int coordIndex(GridRecord record) {
    double val = record.getLevel1();
    double val2 = record.getLevel2();
    if (usesBounds && (val > val2)) {
      val = record.getLevel2();
      val2 = record.getLevel1();
    }

    for (int i = 0; i < levels.size(); i++) {
      LevelCoord lc = (LevelCoord) levels.get(i);
      if (usesBounds) {
        if (ucar.nc2.util.Misc.nearlyEquals(lc.value1, val) && ucar.nc2.util.Misc.nearlyEquals(lc.value2, val2)) {
          return i;
        }
      } else {
        if (ucar.nc2.util.Misc.nearlyEquals(lc.value1, val)) {
          return i;
        }
      }
    }
    return -1;
  }

private int coordIndex ( GridRecord record ) { double val = record . getLevel1 ( ) ; double val2 = record . getLevel2 ( ) ; if ( usesBounds && ( val > val2 ) ) { val = record . getLevel2 ( ) ; val2 = record . getLevel1 ( ) ; } for ( int i = 0 ; i < levels . size ( ) ; i ++ ) { LevelCoord lc = ( LevelCoord ) levels . get ( i ) ; if ( usesBounds ) { if ( ucar . nc2 . util . Misc . nearlyEquals ( lc . value1 , val ) && ucar . nc2 . util . Misc . nearlyEquals ( lc . value2 , val2 ) ) { return i ; } } else { if ( ucar . nc2 . util . Misc . nearlyEquals ( lc . value1 , val ) ) { return i ; } } } return - 1 ; }

Get the coordinate index for the record

@param record record in question
@return index or -1 if not found


public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) {
    NOWRadheader localHeader = new NOWRadheader();

    return (localHeader.isValidFile(raf));
  }

public boolean isValidFile ( ucar . unidata . io . RandomAccessFile raf ) { NOWRadheader localHeader = new NOWRadheader ( ) ; return ( localHeader . isValidFile ( raf ) ) ; }

checking the file

@param raf
@return the valid of file checking


public void open(ucar.unidata.io.RandomAccessFile raf, ucar.nc2.NetcdfFile file,
                   ucar.nc2.util.CancelTask cancelTask)
          throws IOException {
    super.open(raf, ncfile, cancelTask);
    headerParser = new NOWRadheader();

    try {
      headerParser.read(this.raf, ncfile);
    } catch (Exception e) {
    }

    // myInfo = headerParser.getVarInfo();
    pcode = 0;
    ncfile.finish();
  }

public
void
open
(
ucar
.
unidata
.
io
.
RandomAccessFile
raf
,
ucar
.
nc2
.
NetcdfFile
file
,
ucar
.
nc2
.
util
.
CancelTask
cancelTask
)
throws
IOException
{
super
.
open
(
raf
,
ncfile
,
cancelTask
)
;
headerParser
=
new
NOWRadheader
(
)
;
try
{
headerParser
.
read
(
this
.
raf
,
ncfile
)
;
}
catch
(
Exception
e
)
{
}
// myInfo = headerParser.getVarInfo();
pcode
=
0
;
ncfile
.
finish
(
)
;
}

Open the file and read the header part

@param raf
@param file
@param cancelTask
@throws java.io.IOException


public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException {

    // subset
    Object data;
    Array outputData;
    byte[] vdata = null;
    NOWRadheader.Vinfo vinfo;
    ByteBuffer bos;
    List<Range> ranges = section.getRanges();

    vinfo = (NOWRadheader.Vinfo) v2.getSPobject();
    vdata = headerParser.getData((int) vinfo.hoff);

    bos = ByteBuffer.wrap(vdata);
    data = readOneScanData(bos, vinfo, v2.getShortName());
    outputData = Array.factory(v2.getDataType(), v2.getShape(), data);
    outputData = outputData.flip(1);

    // outputData = outputData.flip(2);
    return (outputData.sectionNoReduce(ranges).copy());

    // return outputData;
  }

public
Array
readData
(
Variable
v2
,
Section
section
)
throws
IOException
,
InvalidRangeException
{
// subset
Object
data
;
Array
outputData
;
byte
[
]
vdata
=
;
NOWRadheader
.
Vinfo
vinfo
;
ByteBuffer
bos
;
List
<
Range
>
ranges
=
section
.
getRanges
(
)
;
vinfo
=
(
NOWRadheader
.
Vinfo
)
v2
.
getSPobject
(
)
;
vdata
=
headerParser
.
getData
(
(
int
)
vinfo
.
hoff
)
;
bos
=
ByteBuffer
.
wrap
(
vdata
)
;
data
=
readOneScanData
(
bos
,
vinfo
,
v2
.
getShortName
(
)
)
;
outputData
=
Array
.
factory
(
v2
.
getDataType
(
)
,
v2
.
getShape
(
)
,
data
)
;
outputData
=
outputData
.
flip
(
1
)
;
// outputData = outputData.flip(2);
return
(
outputData
.
sectionNoReduce
(
ranges
)
.
copy
(
)
)
;
// return outputData;
}

Read the data for each variable passed in

@param v2
@param section
@return output data
@throws IOException
@throws ucar.ma2.InvalidRangeException


public byte[] readOneRowData(byte[] ddata, int rLen, int xt) throws IOException, InvalidRangeException {
    int run;
    byte[] bdata = new byte[xt];
    int nbin = 0;
    int total = 0;

    for (run = 0; run < rLen; run++) {
      int drun = DataType.unsignedByteToShort(ddata[run]) >> 4;
      byte dcode1 = (byte) (DataType.unsignedByteToShort(ddata[run]) & 0Xf);

      for (int i = 0; i < drun; i++) {
        bdata[nbin++] = dcode1;
        total++;
      }
    }

    if (total < xt) {
      for (run = total; run < xt; run++) {
        bdata[run] = 0;
      }
    }

    return bdata;
  }

public byte [ ] readOneRowData ( byte [ ] ddata , int rLen , int xt ) throws IOException , InvalidRangeException { int run ; byte [ ] bdata = new byte [ xt ] ; int nbin = 0 ; int total = 0 ; for ( run = 0 ; run < rLen ; run ++ ) { int drun = DataType . unsignedByteToShort ( ddata [ run ] ) >> 4 ; byte dcode1 = ( byte ) ( DataType . unsignedByteToShort ( ddata [ run ] ) & 0Xf ) ; for ( int i = 0 ; i < drun ; i ++ ) { bdata [ nbin ++ ] = dcode1 ; total ++ ; } } if ( total < xt ) { for ( run = total ; run < xt ; run ++ ) { bdata [ run ] = 0 ; } } return bdata ; }

Read data from encoded values and run len into regular data array

@param ddata is encoded data values
@return the data array of row data


private void createFromDataset(NetcdfDataset ncd) {
        // get coordinate variables, disjunct from variables
    for (CoordinateAxis axis : ncd.getCoordinateAxes()) {
      coordvars.put(axis.getShortName(), axis);
    }

    // dup the variable set
    ddsvars = new ArrayList<>(50);

    // collect grid array variables and set of coordinate variables used in grids
    for (Variable v : ncd.getVariables()) {
      if (coordvars.containsKey(v.getShortName())) continue;  // skip coordinate variables
      ddsvars.add(v);

      boolean isgridarray = (v.getRank() > 1) && (v.getDataType() != DataType.STRUCTURE) && (v.getParentStructure() == null);
      if (!isgridarray) continue;
      List<Dimension> dimset = v.getDimensions();
      int rank = dimset.size();
      for (int i = 0; isgridarray && i < rank; i++) {
        Dimension dim = dimset.get(i);
        if (dim.getShortName() == null)
          isgridarray = false;
        else {
          Variable gv = coordvars.get(dim.getShortName());
          if (gv == null)
            isgridarray = false;
        }
      }
      if (isgridarray) {
        gridarrays.put(v.getFullName(), v);
        for (Dimension dim : dimset) {
          Variable gv = coordvars.get(dim.getShortName());
          if (gv != null)
            used.put(gv.getFullName(), gv);
        }
      }
    }

        // Create the set of coordinates
    for (Variable cv : ncd.getCoordinateAxes()) {
      BaseType bt = createVariable(ncd, cv);
      addVariable(bt);
    }

    // Create the set of variables
    for (Variable cv : ddsvars) {
      BaseType bt = createVariable(ncd, cv);
      addVariable(bt);
    }
  }

take advantage of the work already done by NetcdfDataset


private BaseType createVariable(NetcdfFile ncfile, Variable v) {
    BaseType bt;
    if (v.getRank() == 0)  // scalar
      bt = createScalarVariable(ncfile, v);

    else if (v.getDataType() == DataType.CHAR) {
      if (v.getRank() > 1)
        bt = new NcSDCharArray(v);
      else
        bt = new NcSDString(v);

    } else if (v.getDataType() == DataType.STRING) {
      if (v.getRank() == 0)
        bt = new NcSDString(v);
      else
        bt = new NcSDArray(v, new NcSDString(v));

    } else  // non-char multidim array
      bt = createArray(ncfile, v);

    return bt;

  }

private
BaseType
createVariable
(
NetcdfFile
ncfile
,
Variable
v
)
{
BaseType
bt
;
if
(
v
.
getRank
(
)
==
0
)
// scalar
bt
=
createScalarVariable
(
ncfile
,
v
)
;
else
if
(
v
.
getDataType
(
)
==
DataType
.
CHAR
)
{
if
(
v
.
getRank
(
)
>
1
)
bt
=
new
NcSDCharArray
(
v
)
;
else
bt
=
new
NcSDString
(
v
)
;
}
else
if
(
v
.
getDataType
(
)
==
DataType
.
STRING
)
{
if
(
v
.
getRank
(
)
==
0
)
bt
=
new
NcSDString
(
v
)
;
else
bt
=
new
NcSDArray
(
v
,
new
NcSDString
(
v
)
)
;
}
else
// non-char multidim array
bt
=
createArray
(
ncfile
,
v
)
;
return
bt
;
}


void fireMapAreaEvent() {
    if (debugZoom)
      System.out.println("NP.fireMapAreaEvent ");

     // decide if we need a new Projection: for LatLonProjection only
    if (project.isLatLon()) {
      LatLonProjection llproj = (LatLonProjection) project;
      ProjectionRect box = getMapArea();
      double center = llproj.getCenterLon();
      double lonBeg = LatLonPointImpl.lonNormal(box.getMinX(), center);
      double lonEnd = lonBeg + box.getMaxX() - box.getMinX();
      boolean showShift = Debug.isSet("projection/LatLonShift") || debugNewProjection;
      if (showShift) System.out.println("projection/LatLonShift: min,max = "+ box.getMinX()+" "+
            box.getMaxX()+" beg,end= "+lonBeg+" "+lonEnd+ " center = "+center);

      if ( (lonBeg < center-180) || (lonEnd > center+180)) {  // got to do it
        double wx0 = box.getX() + box.getWidth()/2;
        llproj.setCenterLon( wx0);              // shift cylinder seam
        double newWx0 = llproj.getCenterLon();  // normalize wx0 to [-180,180]
        setWorldCenterX(newWx0);             // tell navigation panel to shift
        if (showShift)
          System.out.println("projection/LatLonShift: shift center to "+wx0+"->"+newWx0);

        // send projection event instead of map area event
        lmProject.sendEvent( new NewProjectionEvent(this, llproj));
        return;
      }
    }

    // send new map area event
    lmMapArea.sendEvent( new NewMapAreaEvent( this, getMapArea()));
  }


public void setMapArea(ProjectionRect ma) {
    if (debugBB) System.out.println("NP.setMapArea "+ ma);
    navigate.setMapArea(ma);
  }

public
void
setMapArea
(
ProjectionRect
ma
)
{
if
(
debugBB
)
System
.
out
.
println
(
"NP.setMapArea "
+
ma
)
;
navigate
.
setMapArea
(
ma
)
;
}


public void setMapArea(LatLonRect llbb) {
    if (debugBB) System.out.println("NP.setMapArea (ll) "+ llbb);
    navigate.setMapArea( project.latLonToProjBB(llbb));
  }

public
void
setMapArea
(
LatLonRect
llbb
)
{
if
(
debugBB
)
System
.
out
.
println
(
"NP.setMapArea (ll) "
+
llbb
)
;
navigate
.
setMapArea
(
project
.
latLonToProjBB
(
llbb
)
)
;
}

Set the Map Area by converting LatLonRect to a ProjectionRect.

Set the Map Area by converting LatLonRect to a ProjectionRect .


public void setLatLonCenterMapArea( double lat, double lon) {
    ProjectionPoint center = project.latLonToProj(lat, lon);

    ProjectionRect ma = getMapArea();
    ma.setX( center.getX() - ma.getWidth()/2);
    ma.setY( center.getY() - ma.getHeight()/2);

    setMapArea(ma);
  }

public void setLatLonCenterMapArea ( double lat , double lon ) { ProjectionPoint center = project . latLonToProj ( lat , lon ) ; ProjectionRect ma = getMapArea ( ) ; ma . setX ( center . getX ( ) - ma . getWidth ( ) / 2 ) ; ma . setY ( center . getY ( ) - ma . getHeight ( ) / 2 ) ; setMapArea ( ma ) ; }


public void setProjectionImpl( ProjectionImpl p) {
      // transfer selection region to new coord system
    if (geoSelection != null)  {
      LatLonRect geoLL = project.projToLatLonBB(geoSelection);
      setGeoSelection( p.latLonToProjBB( geoLL));
    }

      // switch projections
    project = p;
    navigate.setMapArea(project.getDefaultMapArea());
    if (Debug.isSet("projection/set") || debugNewProjection)
      System.out.println("projection/set NP="+ project);

      // transfer reference point to new coord system
    if (hasReference)  {
      refWorld.setLocation(project.latLonToProj( refLatLon));
    }

  }

Set the Projection, change the Map Area to the projection's default.

Set the Projection change the Map Area to the projection s default .


public void addActionsToMenu (JMenu menu) {
    BAMutil.addActionToMenu( menu, zoomIn);
    BAMutil.addActionToMenu( menu, zoomOut);
    BAMutil.addActionToMenu( menu, zoomBack);
    BAMutil.addActionToMenu( menu, zoomDefault);

    menu.addSeparator();

    BAMutil.addActionToMenu( menu, moveUp);
    BAMutil.addActionToMenu( menu, moveDown);
    BAMutil.addActionToMenu( menu, moveRight);
    BAMutil.addActionToMenu( menu, moveLeft);

    menu.addSeparator();

    BAMutil.addActionToMenu( menu, setReferenceAction);
  }

public void addActionsToMenu ( JMenu menu ) { BAMutil . addActionToMenu ( menu , zoomIn ) ; BAMutil . addActionToMenu ( menu , zoomOut ) ; BAMutil . addActionToMenu ( menu , zoomBack ) ; BAMutil . addActionToMenu ( menu , zoomDefault ) ; menu . addSeparator ( ) ; BAMutil . addActionToMenu ( menu , moveUp ) ; BAMutil . addActionToMenu ( menu , moveDown ) ; BAMutil . addActionToMenu ( menu , moveRight ) ; BAMutil . addActionToMenu ( menu , moveLeft ) ; menu . addSeparator ( ) ; BAMutil . addActionToMenu ( menu , setReferenceAction ) ; }

Add all of the toolbar's actions to a menu.
@param menu the menu to add the actions to

Add all of the toolbar s actions to a menu .


private void redrawLater(int delay) {
    boolean already = (redrawTimer != null) && (redrawTimer.isRunning());
    if (debugThread) System.out.println( "redrawLater isRunning= "+ already);
    if (already)
      return;

      // initialize Timer the first time
    if (redrawTimer == null) {
      redrawTimer = new javax.swing.Timer(0, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          drawG();
          redrawTimer.stop(); // one-shot timer
        }
      });
    }
      // start the timer running
    redrawTimer.setDelay(delay);
    redrawTimer.start();
  }

private
void
redrawLater
(
int
delay
)
{
boolean
already
=
(
redrawTimer
!=
)
&&
(
redrawTimer
.
isRunning
(
)
)
;
if
(
debugThread
)
System
.
out
.
println
(
"redrawLater isRunning= "
+
already
)
;
if
(
already
)
return
;
// initialize Timer the first time
if
(
redrawTimer
==
)
{
redrawTimer
=
new
javax
.
swing
.
Timer
(
0
,
new
ActionListener
(
)
{
public
void
actionPerformed
(
ActionEvent
e
)
{
drawG
(
)
;
redrawTimer
.
stop
(
)
;
// one-shot timer
}
}
)
;
}
// start the timer running
redrawTimer
.
setDelay
(
delay
)
;
redrawTimer
.
start
(
)
;
}

from panning, so wait delay msecs before doing the redraw.

from panning so wait delay msecs before doing the redraw .


private void newScreenSize(Rectangle b) {
    boolean sameSize = (b.width == myBounds.width) && (b.height == myBounds.height);
    if (debugBounds) System.out.println( "NavigatedPanel newScreenSize old= "+myBounds);
    if (sameSize && (b.x == myBounds.x) && (b.y == myBounds.y))
      return;

    myBounds.setBounds(b);
    if (sameSize)
      return;

    if (debugBounds) System.out.println( "  newBounds = " +b);

    // create new buffer the size of the window
    //if (bImage != null)
    //  bImage.dispose();

    if ((b.width > 0) && (b.height > 0)) {
      bImage = new BufferedImage(b.width, b.height, BufferedImage.TYPE_INT_RGB); // why RGB ?
    } else {                                                                     // why not device dependent?
      bImage = null;
    }

   navigate.setScreenSize(b.width, b.height);
  }

when component resizes we need a new buffer


public void setSelected( VariableIF v ) {
        if (v == null) { return; }

        // construct chain of variables
        final List<VariableIF> vchain = new ArrayList<>();
        vchain.add( v);

        VariableIF vp = v;
        while (vp.isMemberOfStructure()) {
            vp = vp.getParentStructure();
            vchain.add( 0, vp); // reverse
        }

        // construct chain of groups
        final List<Group> gchain = new ArrayList<>();
        Group gp = vp.getParentGroup();

        gchain.add( gp);
        while (gp.getParentGroup() != null) {
            gp = gp.getParentGroup();
            gchain.add( 0, gp); // reverse
        }

        final List<Object> pathList = new ArrayList<>();

        // start at root, work down through the nested groups, if any
        GroupNode gnode = (GroupNode) model.getRoot();
        pathList.add( gnode);
        Group parentGroup = gchain.get(0); // always the root group

        for (int i=1; i < gchain.size(); i++) {
            parentGroup = gchain.get(i);
            gnode = gnode.findNestedGroup( parentGroup);
            assert gnode != null;
            pathList.add( gnode);
        }

        vp = vchain.get(0);
        VariableNode vnode = gnode.findNestedVariable( vp);
        if (vnode == null) { return; } // not found
        pathList.add( vnode);

        // now work down through the structure members, if any
        for (int i=1; i < vchain.size(); i++) {
            vp = vchain.get(i);
            vnode = vnode.findNestedVariable( vp);
            if (vnode == null) { return; } // not found
            pathList.add(vnode);
        }

        // convert to TreePath, and select it
        final Object[] paths = pathList.toArray();
        final TreePath treePath = new TreePath(paths);
        tree.setSelectionPath( treePath);
        tree.scrollPathToVisible( treePath);
    }

Set the currently selected Variable.

@param v select this Variable, must be already in the tree.


public double getDouble(int offset)
    {
        DapVariable d4var = (DapVariable) getTemplate();
        long[] dimsizes = DapUtil.getDimSizes(d4var.getDimensions());
        return getDouble(DapUtil.offsetToIndex(offset, dimsizes));
    }

public double getDouble ( int offset ) { DapVariable d4var = ( DapVariable ) getTemplate ( ) ; long [ ] dimsizes = DapUtil . getDimSizes ( d4var . getDimensions ( ) ) ; return getDouble ( DapUtil . offsetToIndex ( offset , dimsizes ) ) ; }


protected double getDouble(dap4.core.util.Index idx)
    {
        assert data.getScheme() == Scheme.ATOMIC;
        try {
            Object value = data.read(idx);
            value = Convert.convert(DapType.FLOAT64, this.basetype, value);
            return (Double) java.lang.reflect.Array.get(value, 0);
        } catch (IOException ioe) {
            throw new IndexOutOfBoundsException(ioe.getMessage());
        }
    }

protected double getDouble ( dap4 . core . util . Index idx ) { assert data . getScheme ( ) == Scheme . ATOMIC ; try { Object value = data . read ( idx ) ; value = Convert . convert ( DapType . FLOAT64 , this . basetype , value ) ; return ( Double ) java . lang . reflect . Array . get ( value , 0 ) ; } catch ( IOException ioe ) { throw new IndexOutOfBoundsException ( ioe . getMessage ( ) ) ; } }

Get the array element at a specific dap4 index as a double

@param idx of element to get
@return value at index cast to double if necessary.


protected Object getObject(dap4.core.util.Index idx)
    {
        assert data.getScheme() == Scheme.ATOMIC;
        try {
            Object value = data.read(idx);
            value = java.lang.reflect.Array.get(value, 0);
            return value;
        } catch (IOException ioe) {
            throw new IndexOutOfBoundsException(ioe.getMessage());
        }
    }

protected Object getObject ( dap4 . core . util . Index idx ) { assert data . getScheme ( ) == Scheme . ATOMIC ; try { Object value = data . read ( idx ) ; value = java . lang . reflect . Array . get ( value , 0 ) ; return value ; } catch ( IOException ioe ) { throw new IndexOutOfBoundsException ( ioe . getMessage ( ) ) ; } }

Get the array element at a specific dap4 index as an Object

@param idx of element to get
@return value at index cast to Object if necessary.


String gini_GetSectorID(int ent_id) {
    String name;
    switch (ent_id) {
      case 0:
        name = "Northern Hemisphere Composite";
        break;
      case 1:
        name = "East CONUS";
        break;
      case 2:
        name = "West CONUS";
        break;
      case 3:
        name = "Alaska Regional";
        break;
      case 4:
        name = "Alaska National";
        break;
      case 5:
        name = "Hawaii Regional";
        break;
      case 6:
        name = "Hawaii National";
        break;
      case 7:
        name = "Puerto Rico Regional";
        break;
      case 8:
        name = "Puerto Rico National";
        break;
      case 9:
        name = "Supernational";
        break;
      case 10:
        name = "NH Composite - Meteosat/GOES E/ GOES W/GMS";
        break;
      case 11:
        name = "Central CONUS";
        break;
      case 12:
        name = "East Floater";
        break;
      case 13:
        name = "West Floater";
        break;
      case 14:
        name = "Central Floater";
        break;
      case 15:
        name = "Polar Floater";
        break;
      default:
        name = "Unknown-ID";
    }

    return name;
  }

Return the string of Sector for the GINI image file


private double readScaledInt(ByteBuffer buf) {
    // Get the first two bytes
    short s1 = buf.getShort();

    // And the last one as unsigned
    short s2 = DataType.unsignedByteToShort(buf.get());

    // Get the sign bit, converting from 0 or 2 to +/- 1.
    int posneg = 1 - ((s1 & 0x8000) >> 14);

    // Combine the first two bytes (without sign bit) with the last byte.
    // Multiply by proper factor for +/-
    int nn = (((s1 & 0x7FFF) << 8) | s2) * posneg;
    return (double) nn / 10000.0;
  }

Read a scaled, 3-byte integer from file and convert to double

Read a scaled 3 - byte integer from file and convert to double


public Parameter findParameterIgnoreCase(String name) {
    for (Parameter a : params) {
      if (name.equalsIgnoreCase(a.getName()))
        return a;
    }
    return null;
  }

public Parameter findParameterIgnoreCase ( String name ) { for ( Parameter a : params ) { if ( name . equalsIgnoreCase ( a . getName ( ) ) ) return a ; } return null ; }

Convenience function; look up Parameter by name, ignoring case.

@param name the name of the attribute
@return the Attribute, or null if not found

Convenience function ; look up Parameter by name ignoring case .


@Override
    public boolean
    hasNext()
    {
        if(this.current >= odomset.size())
            return false;
        Odometer ocurrent = odomset.get(this.current);
        if(ocurrent.hasNext())
            return true;
        // Try to move to next odometer
        this.current++;
        return hasNext();
    }

@
Override
public
boolean
hasNext
(
)
{
if
(
this
.
current
>=
odomset
.
size
(
)
)
return
false
;
Odometer
ocurrent
=
odomset
.
get
(
this
.
current
)
;
if
(
ocurrent
.
hasNext
(
)
)
return
true
;
// Try to move to next odometer
this
.
current
++
;
return
hasNext
(
)
;
}


private void swapByteOrder() {
    // NB: we are setting bigEndian to be opposite the system arch
    String arch = System.getProperty("os.arch");
    if (arch.equals("x86") ||                    // Windows, Linux
            arch.equals("arm") ||                // Window CE
            arch.equals("x86_64") ||         // Windows64, Mac OS-X
            arch.equals("amd64") ||      // Linux64?
            arch.equals("alpha")) {  // Utrix, VAX, DECOS
      bigEndian = true;
    } else {
      bigEndian = false;
    }
  }

Swap the byte order from the system default


public int[] getTimeStepsPerFile(String filename) {
    if (chsubs != null) {
      for (Chsub ch : chsubs) {
        if (filename.contains(ch.subString)) {
          return new int[]{ch.numTimes, ch.startTimeIndex};
        }
      }
    }
    return new int[]{timeStepsPerFile, 0};
  }

public int [ ] getTimeStepsPerFile ( String filename ) { if ( chsubs != null ) { for ( Chsub ch : chsubs ) { if ( filename . contains ( ch . subString ) ) { return new int [ ] { ch . numTimes , ch . startTimeIndex } ; } } } return new int [ ] { timeStepsPerFile , 0 } ; }

Get the number of timesteps per file and the starting offset

@param filename the filename to check
@return the starting index and number of times in that file


public String getFileName(int eIndex, int tIndex) {

    String dataFilePath = dataFile;

    if ((getTemplateType() == ENS_TEMPLATE) || (getTemplateType() == ENS_TIME_TEMPLATE)) {
      dataFilePath = getEnsembleDimension().replaceFileTemplate(dataFilePath, eIndex);
    }

    dataFilePath = getTimeDimension().replaceFileTemplate(dataFilePath, tIndex);
    if ((chsubs != null) && (dataFilePath.contains(CHSUB_TEMPLATE_ID))) {
      for (Chsub ch : chsubs) {
        if ((tIndex >= ch.startTimeIndex) && (tIndex <= ch.endTimeIndex)) {
          dataFilePath = dataFilePath.replace(CHSUB_TEMPLATE_ID, ch.subString);
          break;
        }
      }
    }
    return getFullPath(dataFilePath);
  }

public String getFileName ( int eIndex , int tIndex ) { String dataFilePath = dataFile ; if ( ( getTemplateType ( ) == ENS_TEMPLATE ) || ( getTemplateType ( ) == ENS_TIME_TEMPLATE ) ) { dataFilePath = getEnsembleDimension ( ) . replaceFileTemplate ( dataFilePath , eIndex ) ; } dataFilePath = getTimeDimension ( ) . replaceFileTemplate ( dataFilePath , tIndex ) ; if ( ( chsubs != null ) && ( dataFilePath . contains ( CHSUB_TEMPLATE_ID ) ) ) { for ( Chsub ch : chsubs ) { if ( ( tIndex >= ch . startTimeIndex ) && ( tIndex <= ch . endTimeIndex ) ) { dataFilePath = dataFilePath . replace ( CHSUB_TEMPLATE_ID , ch . subString ) ; break ; } } } return getFullPath ( dataFilePath ) ; }

Get the file name for the particular time and ensemble index

@param eIndex ensemble index
@param tIndex time index
@return the appropriate filename


private List<String> getFileNames() throws IOException {
    if (fileNames == null) {
      fileNames = new ArrayList<>();
      timeStepsPerFile = tDim.getSize();
      if (!isTemplate()) {  // single file
        fileNames.add(getFullPath(getDataFile()));
      } else {               // figure out template type
        long start = System.currentTimeMillis();
        List<String> fileSet = new ArrayList<>();
        String template = getDataFile();
        if (GradsTimeDimension.hasTimeTemplate(template)) {
          if (template.contains(GradsEnsembleDimension.ENS_TEMPLATE_ID)) {
            templateType = ENS_TIME_TEMPLATE;
          } else {
            templateType = TIME_TEMPLATE;
          }
        } else {  // not time - either ens or chsub
          if (template.contains(GradsEnsembleDimension.ENS_TEMPLATE_ID)) {
            templateType = ENS_TEMPLATE;
          } else {
            templateType = TIME_TEMPLATE;
          }
        }
        if (templateType == ENS_TEMPLATE) {
          for (int e = 0; e < eDim.getSize(); e++) {
            fileSet.add(
                    getFullPath(
                            eDim.replaceFileTemplate(template, e)));
          }
        } else if ((templateType == TIME_TEMPLATE)
                || (templateType == ENS_TIME_TEMPLATE)) {
          int numens = (templateType == TIME_TEMPLATE)
                  ? 1
                  : eDim.getSize();
          for (int t = 0; t < tDim.getSize(); t++) {
            for (int e = 0; e < numens; e++) {
              String file = getFileName(e, t);
              if (!fileSet.contains(file)) {
                fileSet.add(file);
              }
            }
          }
          // this'll be a bogus number if chsub was used
          timeStepsPerFile = tDim.getSize()
                  / (fileSet.size() / numens);
        }
        //System.out.println("Time to generate file list = "
        //                   + (System.currentTimeMillis() - start));
        fileNames.addAll(fileSet);
      }
      //long start2 = System.currentTimeMillis();
      // now make sure they exist
      for (String file : fileNames) {
        File f = new File(file);
        if (!f.exists()) {
          log.error("File: " + f + " does not exist");
          throw new IOException("File: " + f + " does not exist");
        }
      }
      //System.out.println("Time to check file list = "
      //                   + (System.currentTimeMillis() - start2));
    }
    return fileNames;
  }

Get the list of filenames

@return the filenames
@throws IOException file does not exist.


private String getDDFPath() {
    if (pathToDDF == null) {
      int lastSlash = ddFile.lastIndexOf("/");
      if (lastSlash < 0) {
        lastSlash = ddFile.lastIndexOf(File.separator);
      }
      pathToDDF = (lastSlash < 0)
              ? ""
              : ddFile.substring(0, lastSlash + 1);

    }
    return pathToDDF;
  }

private String getDDFPath ( ) { if ( pathToDDF == null ) { int lastSlash = ddFile . lastIndexOf ( "/" ) ; if ( lastSlash < 0 ) { lastSlash = ddFile . lastIndexOf ( File . separator ) ; } pathToDDF = ( lastSlash < 0 ) ? "" : ddFile . substring ( 0 , lastSlash + 1 ) ; } return pathToDDF ; }

Get the path to the Data Descriptor File

@return the path to the Data Descriptor File


private String getFullPath(String filename) {

    String file;
    String ddfPath = getDDFPath();
    if (filename.startsWith("^")) {
      file = filename.replace("^", "");
      file = ddfPath + file;
    } else {
      File f = new File(filename);
      if (!f.isAbsolute()) {
        file = ddfPath + filename;
      } else {
        file = filename;
      }
    }

    return file;
  }

private String getFullPath ( String filename ) { String file ; String ddfPath = getDDFPath ( ) ; if ( filename . startsWith ( "^" ) ) { file = filename . replace ( "^" , "" ) ; file = ddfPath + file ; } else { File f = new File ( filename ) ; if ( ! f . isAbsolute ( ) ) { file = ddfPath + filename ; } else { file = filename ; } } return file ; }

Get the full path for a given filename

@param filename the raw filename
@return the full filename


private void addChsub(Chsub sub) {
    if (chsubs == null) {
      chsubs = new ArrayList<>();
    }
    chsubs.add(sub);
  }

private void addChsub ( Chsub sub ) { if ( chsubs == null ) { chsubs = new ArrayList <> ( ) ; } chsubs . add ( sub ) ; }


public TimeCoordIntvValue convertReferenceDate(CalendarDate refDate, CalendarPeriod timeUnit) {
    if (timeUnit == null) {
      throw new IllegalArgumentException("null time unit");
    }
    int startOffset = timeUnit.getOffset(refDate, start);   // LOOK wrong - not dealing with value ??
    int endOffset = timeUnit.getOffset(refDate, end);
    return new TimeCoordIntvValue(startOffset, endOffset);
  }

Calculate the offset in units of timeUnit from the given reference date?


int readWMO(ucar.unidata.io.RandomAccessFile raf ) throws IOException
    {
        int pos = 0;
        //long     actualSize = 0;
        raf.seek(pos);
        int readLen = 35;

        // Read in the contents of the NEXRAD Level III product head
        byte[] b = new byte[readLen];
        int rc = raf.read(b);
        if ( rc != readLen )
        {
            // out.println(" error reading nids product header");
            return 0;
        }

        // new check
        int iarr2_1 = bytesToInt(b[0], b[1], false);
        int iarr2_16 = bytesToInt(b[30], b[31], false);
        int iarr2_10 = bytesToInt(b[18], b[19], false);
        int iarr2_7 = bytesToInt(b[12], b[13], false);
        if ( ( iarr2_1 == iarr2_16 ) &&
             ( ( iarr2_1 >=   16  ) && ( iarr2_1 <= 299) ) &&
             ( iarr2_10  ==   -1 ) &&
             ( iarr2_7   <    10000 ) )  {
             noHeader = true;
             return 1;

        }
        //Get product message header into a string for processing

        String pib = new String(b, CDM.utf8Charset);
        if(  pib.indexOf("SDUS")!= -1){
            noHeader = false;
            return 1;
        } else if ( raf.getLocation().indexOf(".nids") != -1) {
            noHeader = true;
            return 1;
       // } else if(checkMsgHeader(raf) == 1) {
        //    noHeader = true;
       //     return 1;
        } else
            return 0;
    }

read the header of input file and parsing the WMO part
@param raf    input file
@return        1 if checking passing
@throws IOException


public byte[] getUncompData(int offset, int len){
      if( len == 0 ) len = uncompdata.length - offset;
      byte[] data = new byte[len];
      System.arraycopy(uncompdata, offset, data, 0, len);
      return data;
    }

public byte [ ] getUncompData ( int offset , int len ) { if ( len == 0 ) len = uncompdata . length - offset ; byte [ ] data = new byte [ len ] ; System . arraycopy ( uncompdata , offset , data , 0 , len ) ; return data ; }

read the compressed data

@param offset   offset of the compressed data
@param len      length of data to compress
@return         uncompressed byte array


int pcode_12n13n14( int[] pos, int[] dlen, int hoff, int len, boolean isZ, String structName, int code )
    {
       //int vlen = len;

        int vlen = 0;
        for(int i=0; i<len; i++ ){
           vlen = vlen + dlen[i];
        }

        ArrayList dims =  new ArrayList();
        Dimension sDim = new Dimension("graphicSymbolSize", vlen);
        ncfile.addDimension( null, sDim);
        dims.add( sDim);

        Structure dist = new Structure(ncfile, null, null, structName);
        dist.setDimensions(dims);
        ncfile.addVariable(null, dist);
        dist.addAttribute( new Attribute(CDM.LONG_NAME, "special graphic symbol for code "+code));

        Variable i0 = new Variable(ncfile, null, dist, "x_start");
        i0.setDimensions((String)null);
        i0.setDataType(DataType.FLOAT);
        i0.addAttribute( new Attribute(CDM.UNITS, "KM"));
        dist.addMemberVariable(i0);
        Variable j0 = new Variable(ncfile, null, dist, "y_start");
        j0.setDimensions((String)null);
        j0.setDataType(DataType.FLOAT);
        j0.addAttribute( new Attribute(CDM.UNITS, "KM"));
        dist.addMemberVariable(j0);

       int[] pos1 = new int[len];
       int[] dlen1 = new int[len];
       System.arraycopy(dlen, 0, dlen1, 0, len);
       System.arraycopy(pos, 0, pos1, 0, len);
       dist.setSPobject( new Vinfo ( 0, 0, 0, 0, hoff, 0, isR, isZ, pos1, dlen1, code, 0));
       return 1;
     }

int
pcode_12n13n14
(
int
[
]
pos
,
int
[
]
dlen
,
int
hoff
,
int
len
,
boolean
isZ
,
String
structName
,
int
code
)
{
//int vlen = len;
int
vlen
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
vlen
=
vlen
+
dlen
[
i
]
;
}
ArrayList
dims
=
new
ArrayList
(
)
;
Dimension
sDim
=
new
Dimension
(
"graphicSymbolSize"
,
vlen
)
;
ncfile
.
addDimension
(
,
sDim
)
;
dims
.
add
(
sDim
)
;
Structure
dist
=
new
Structure
(
ncfile
,
,
,
structName
)
;
dist
.
setDimensions
(
dims
)
;
ncfile
.
addVariable
(
,
dist
)
;
dist
.
addAttribute
(
new
Attribute
(
CDM
.
LONG_NAME
,
"special graphic symbol for code "
+
code
)
)
;
Variable
i0
=
new
Variable
(
ncfile
,
,
dist
,
"x_start"
)
;
i0
.
setDimensions
(
(
String
)
)
;
i0
.
setDataType
(
DataType
.
FLOAT
)
;
i0
.
addAttribute
(
new
Attribute
(
CDM
.
UNITS
,
"KM"
)
)
;
dist
.
addMemberVariable
(
i0
)
;
Variable
j0
=
new
Variable
(
ncfile
,
,
dist
,
"y_start"
)
;
j0
.
setDimensions
(
(
String
)
)
;
j0
.
setDataType
(
DataType
.
FLOAT
)
;
j0
.
addAttribute
(
new
Attribute
(
CDM
.
UNITS
,
"KM"
)
)
;
dist
.
addMemberVariable
(
j0
)
;
int
[
]
pos1
=
new
int
[
len
]
;
int
[
]
dlen1
=
new
int
[
len
]
;
System
.
arraycopy
(
dlen
,
0
,
dlen1
,
0
,
len
)
;
System
.
arraycopy
(
pos
,
0
,
pos1
,
0
,
len
)
;
dist
.
setSPobject
(
new
Vinfo
(
0
,
0
,
0
,
0
,
hoff
,
0
,
isR
,
isZ
,
pos1
,
dlen1
,
code
,
0
)
)
;
return
1
;
}

construct a dataset for special graphic symbol packet with code 12, 13, and 14

@param pos, dlen, hoff, len, isZ, structName, code

@return  1 if successful

construct a dataset for special graphic symbol packet with code 12 13 and 14


int pcode_25( int[] pos, int hoff, int len, boolean isZ )
   {

      ArrayList dims =  new ArrayList();

      Dimension sDim = new Dimension("circleSize", len);
      ncfile.addDimension( null, sDim);
      dims.add( sDim);

      Structure dist = new Structure(ncfile, null, null, "circleStruct");
      dist.setDimensions(dims);
      ncfile.addVariable(null, dist);
      dist.addAttribute( new Attribute(CDM.LONG_NAME, "Circle Packet"));

      Variable ii0 = new Variable(ncfile, null, dist, "x_center");
      ii0.setDimensions((String)null);
      ii0.setDataType(DataType.SHORT);
      dist.addMemberVariable(ii0);
      Variable ii1 = new Variable(ncfile, null, dist, "y_center");
      ii1.setDimensions((String)null);
      ii1.setDataType(DataType.SHORT);
      dist.addMemberVariable(ii1);
      Variable jj0 = new Variable(ncfile, null, dist, "radius");
      jj0.setDimensions((String)null);
      jj0.setDataType(DataType.SHORT);
      dist.addMemberVariable(jj0);

      int[] pos1 = new int[len];
      System.arraycopy(pos, 0, pos1, 0, len);
      dist.setSPobject( new Vinfo (0, 0, 0, 0, hoff, 0, isR, isZ, pos1, null, 25, 0));

      return 1;
   }

int
pcode_25
(
int
[
]
pos
,
int
hoff
,
int
len
,
boolean
isZ
)
{
ArrayList
dims
=
new
ArrayList
(
)
;
Dimension
sDim
=
new
Dimension
(
"circleSize"
,
len
)
;
ncfile
.
addDimension
(
,
sDim
)
;
dims
.
add
(
sDim
)
;
Structure
dist
=
new
Structure
(
ncfile
,
,
,
"circleStruct"
)
;
dist
.
setDimensions
(
dims
)
;
ncfile
.
addVariable
(
,
dist
)
;
dist
.
addAttribute
(
new
Attribute
(
CDM
.
LONG_NAME
,
"Circle Packet"
)
)
;
Variable
ii0
=
new
Variable
(
ncfile
,
,
dist
,
"x_center"
)
;
ii0
.
setDimensions
(
(
String
)
)
;
ii0
.
setDataType
(
DataType
.
SHORT
)
;
dist
.
addMemberVariable
(
ii0
)
;
Variable
ii1
=
new
Variable
(
ncfile
,
,
dist
,
"y_center"
)
;
ii1
.
setDimensions
(
(
String
)
)
;
ii1
.
setDataType
(
DataType
.
SHORT
)
;
dist
.
addMemberVariable
(
ii1
)
;
Variable
jj0
=
new
Variable
(
ncfile
,
,
dist
,
"radius"
)
;
jj0
.
setDimensions
(
(
String
)
)
;
jj0
.
setDataType
(
DataType
.
SHORT
)
;
dist
.
addMemberVariable
(
jj0
)
;
int
[
]
pos1
=
new
int
[
len
]
;
System
.
arraycopy
(
pos
,
0
,
pos1
,
0
,
len
)
;
dist
.
setSPobject
(
new
Vinfo
(
0
,
0
,
0
,
0
,
hoff
,
0
,
isR
,
isZ
,
pos1
,
,
25
,
0
)
)
;
return
1
;
}

construct a dataset for special symbol packet with code 25

@param pos, size, code, hoff, len, structName, isZ

@return  1 if successful


int checkMsgHeader(ucar.unidata.io.RandomAccessFile raf ) throws IOException
    {
        int      rc;
        long     actualSize ;
        int      readLen ;

        actualSize = raf.length();
        int pos = 0;
        raf.seek(pos);

        // Read in the whole contents of the NEXRAD Level III product since
        // some product require to go through the whole file to build the  struct of file.

        readLen = (int)actualSize;

        byte[] b = new byte[readLen];
        rc = raf.read(b);
        if ( rc != readLen )
        {
            log.warn(" error reading nids product header "+raf.getLocation());
        }
        ByteBuffer bos = ByteBuffer.wrap(b);
        return read_msghead( bos, 0 );

    }

check level III file header

@param raf      input file
@return         1 if success, and 0 if fail
@throws IOException