This discussion is archived
1 Reply Latest reply: Oct 4, 2006 12:33 AM by 798906 RSS

how to create a two dimensional array?

807607 Newbie
Currently Being Moderated
i am so sorry about my last thread, as i first time post thread in a forum.

how to create a two dimensional array with the following code? anyone can help me?
import java.io.* ;

class BinaryFile
{
  //Use this constant to specify big-endian integers.

  public static final short BIG_ENDIAN = 1 ;

  //use this constant to specify little-endian constants
  public static final short LITTLE_ENDIAN = 2 ;

  //the underlying file.
  protected RandomAccessFile _file ;

  //are we in LITTLE_ENDIAN or BIG_ENDIAN mode.
  protected short _endian ;

  //are we reading signed or unsigned numbers.
  protected boolean _signed ;

  //the constructor.
  //param f the file to read/write from/to.
  public BinaryFile ( RandomAccessFile f )
  {
    _file = f ;
    _endian = LITTLE_ENDIAN ;
    _signed = false ;
  }

  public void setEndian ( short i ) throws Exception
  {
    if ( ( i == BIG_ENDIAN ) || ( i == LITTLE_ENDIAN ) )
    {
      _endian = i ;
    }
    else
    {
      throw ( new Exception(
       "Must be BinaryFile.LITTLE_ENDIAN or BinaryFile.BIG_ENDIAN" ) ) ;
    }
  }

  public int getEndian ()
  {
    return _endian ;
  }

  public void setSigned ( boolean b )
  {
    _signed = b ;
  }

  public boolean getSigned ()
  {
    return _signed ;
  }

  public String readFixedString ( int length ) throws java.io.IOException
  {
    String rtn = "" ;
    for ( int i = 0 ; i < length ; i++ )
    {
      rtn += ( char ) _file.readByte() ;
    }
    return rtn ;
  }

  protected short readUnsignedByte () throws java.io.IOException
  {
    return ( short ) ( _file.readByte() & 0xff ) ;
  }

  public short readByte () throws java.io.IOException
  {
    if ( _signed )
    {
      return ( short ) _file.readByte() ;
    }
    else
    {
      return ( short ) _file.readUnsignedByte() ;
    }
  }

  public int readWord () throws java.io.IOException
  {
    short a, b ;
    int result ;

    a = readUnsignedByte() ;
    b = readUnsignedByte() ;

    if ( _endian == BIG_ENDIAN )
    {
      result = ( ( a << 8 ) | b ) ;
    }
    else
    {
      result = ( a | ( b << 8 ) ) ;
    }

    if ( _signed )
    {
      if ( ( result & 0x8000 ) == 0x8000 )
      {
     result = - ( 0x10000 - result ) ;
      }
    }
    return result ;
  }

  public void align ( int a ) throws java.io.IOException
  {
    if ( ( _file.getFilePointer() % a ) > 0 )
    {
      long pos = _file.getFilePointer() / a ;
      _file.seek( ( pos + 1 ) * a ) ;
    }
  }
}

class BinaryExample
{
  public static void main(String args[]) throws FileNotFoundException
  {
    int i ;
    String stra, strb, strc, strd, stre ;

    RandomAccessFile file ;
    BinaryFile bin ;

    //set the endian mode to run the test in
    final short endian = BinaryFile.LITTLE_ENDIAN ;
    //set the signed mode to run the test in
    final boolean signed = false ;
    try
    {
      file = new RandomAccessFile( "011.dat", "r" ) ;
      bin = new BinaryFile( file ) ;
      bin.setEndian( endian ) ;
      bin.setSigned( signed ) ;
      //wafer ID
      stra = bin.readFixedString( 25 ) ;
      //wafer Number
      strb = bin.readFixedString( 2 ) ;
      //cassette No.
      strc = bin.readFixedString( 1 ) ;
      //slot no.
      strd = bin.readFixedString( 2 ) ;
      //test count
      stre = bin.readFixedString( 1 ) ;
      //pass total
      int a = bin.readWord() ;
      //fail total
      int b = bin.readWord() ;
      //test total
      int c = bin.readWord() ;

      System.out.println( "Wafer ID  \t:" + stra + "\n" ) ;
      System.out.println( "Wafer No. \t:" + strb + "\n" ) ;
      System.out.println( "Cassette No.\t:" + strc + "\n" ) ;
      System.out.println( "Slot No.\t:" + strd + "\n" ) ;
      System.out.println( "Test count\t:" + stre + "\n" ) ;
      System.out.println( "Pass total\t:" + a + "\n" ) ;
      System.out.println( "Fail total\t:" + b + "\n" ) ;
      System.out.println( "Test total\t:" + c + "\n" ) ;
      //Wafer start time
      System.out.print( "Wafer start time\t:" ) ;
      for ( int r = 0 ; r < 12 ; r++ )
      {
     short st = bin.readByte() ;
     System.out.print( Short.toString( st ) ) ;
      }
      System.out.print( "\n" ) ;
      //wafer end time
      System.out.print( "Wafer end time\t:" ) ;
      for ( int q = 0 ; q < 12 ; q++ )
      {
     short et = bin.readByte() ;
     System.out.print( Short.toString( et ) ) ;
      }
      System.out.print( "\n" ) ;
      short record = bin.readByte() ;
      //No. of records
      System.out.print( "No.of records\t:" + record + "\n" ) ;
      int disX = bin.readWord() ;
      //initial die distance y
      int disY = bin.readWord() ;
      System.out.print( "Initial die distance X\t\t:" + disX + "\n" ) ;
      System.out.print( "Initial die distance Y\t\t:" + disY + "\n" ) ;
      System.out.print( "\n" ) ;

      for ( i = 0 ; i < record ; i++ )
      {
     //first address X of record
     int addX = bin.readWord() ;
     //first address Y of record
     int addY = bin.readWord() ;
     //No. of dies
     short dies = bin.readByte() ;
     //System.out.print(i+"\n");
     //System.out.print("addX=" + addX+"\n");
     //System.out.print("addY=" + addY+"\n");
     //System.out.print("Dies=" + dies+"\n");
     for ( int z = 0 ; z < ( 2 * dies ) ; z++ )
     {
       short ld = bin.readByte() ;
       Short.toString( ld ) ;
       if ( ld == 192 )
       {
         System.out.print( "." ) ;
       }
       else if ( ld == 224 )
       {
         System.out.print( "u" ) ;
       }
       else if ( ld == 56 )
       {
         System.out.print( "8" ) ;
       }
       else if ( ld == 241 )
       {
         System.out.print( "u" ) ;
       }
     }
     System.out.print( "\n" ) ;
      }
      int dd = bin.readWord() ;
      System.out.println( "Die data\t:" + dd + "\n" ) ;
      file.close() ;
    }
    catch ( Exception e )
    {
      System.out.println("**Error:" + e.getMessage());
    }
  }

}