/*=========================================================================

  Program:   Orbit Visualization Tool
  Source:    $Source: /stor/devel/ovt2g/ovt/datatype/DumpRecord.java,v $
  Date:      $Date: 2001/03/17 18:40:31 $
  Version:   $Revision: 1.7 $


Copyright (c) 2000 OVT Team (Kristof Stasiewicz, Mykola Khotyaintsev, 
Yuri Khotyaintsev)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification is permitted provided that the following conditions are met:

 * No part of the software can be included in any commercial package without
written consent from the OVT team.

 * Redistributions of the source or binary code must retain the above
copyright notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT OR
INDIRECT DAMAGES  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.

OVT Team (http://ovt.irfu.se)   K. Stasiewicz, M. Khotyaintsev, Y.
Khotyaintsev

=========================================================================*/

package ovt.datatype;

import java.lang.*;
import java.io.*;

/** 
 *
 * @author  kono
 * @version 
 */
public class DumpRecord extends Object{
  
  public static final byte numOfFields = 15;
  
  public static final byte TIME = 0;
  public static final byte POS_X = 1;
  public static final byte POS_Y = 2;
  public static final byte POS_Z = 3;
  public static final byte[] POS = { POS_X, POS_Y, POS_Z };
  public static final byte R = 4;
  public static final byte VEL = 5;
  public static final byte FP1_LAT = 6;
  public static final byte FP1_LON = 7;
  public static final byte FP2_LAT = 8;
  public static final byte FP2_LON = 9;
  public static final byte[][] FP = { {FP1_LAT, FP1_LON}, {FP2_LAT, FP2_LON}};
  public static final byte DIST_TO_MP = 10;
  public static final byte B = 11;
  public static final byte SPIN_B = 12;
  public static final byte SPIN_V = 13;
  public static final byte SPIN_S = 14;
  public static final byte[] SPIN = { SPIN_B, SPIN_V, SPIN_S };
  
  public static final byte SPIN_LABEL = 30;
  public static final byte POS_LABEL = 31;
  public static final byte FOOT_LABEL= 32;
  public static final byte MP_DIST_LABEL = 33;
  
  private static final String[] tags = {
        "Time",
        "POS X",
        "POS Y",
        "POS Z",
        "Radius",
        "Velocity",
        "FP1 LAT",
        "FP1 LON",
        "FP2 LAT",
        "FP2 LON",
        "DIST to MP",
        "B",
        "SPIN B",
        "SPIN V",
        "SPIN S" }; 
  
  public static final String strMP_DIST_LABEL = "Distance to magnetopause";
  public static final String strSPIN_LABEL = "Spin axis angles (degrees)";
  
  private String[] fields = new String[numOfFields];
  
  public DumpRecord(){
    for(int i=0;i<numOfFields;++i)
      switch(i){
        case MP_DIST_LABEL: setField(i, new String(strMP_DIST_LABEL)); continue;
        case SPIN_LABEL: setField(i, new String(strSPIN_LABEL)); continue;
        default: setField(i, " ");
      }
  }
  
  public DumpRecord(DumpRecord source){
    for(byte i=0;i<numOfFields;++i)
      this.fields[i] = new String(source.fields[i]);
  }
  
  public String getField(int id){
    if(id<0 || id>=numOfFields)
      return "";
    else
      return new String(this.fields[id]);
  }
  
  public void setField(int id,String value){
    if(id>=0 && id<numOfFields && value.length()!=0)
      fields[id] = new String(value);
  }
  
  public Object clone(){
    return new DumpRecord(this);
  }
  
  public void print(){
    System.out.println("Printing DumpRecord:");
    for(int i=0;i<this.numOfFields;++i)
      System.out.println(getField(i));
  }
  
  public static String getName(int type) {
      try {
          return tags[type];
      } catch (IndexOutOfBoundsException e2) {
        throw new IllegalArgumentException("No such record type : '"+type+"'");
      }
  }
  
  public static int getType(String name) {
      for (int i=0; i<numOfFields; i++)
          if (name.equals(tags[i])) return i;
      throw new IllegalArgumentException("No such record type : '"+name+"'");
  }
}
