## com.bbn.openmap.layer.rpf
Class MakeToc

    java.lang.Object
      com.bbn.openmap.layer.rpf.MakeToc

public class MakeToc
extends java.lang.Object

This is a class that will generate A.TOC files that the RpfLayer requires. A.TOC files provide the RpfLayer with an idea of what data is available to it, its geographic coverage, and chart type. With the A.TOC contents, the RpfLayer is able to find which frames are appropriate for a given projection location. It is very important to have a valid A.TOC directory.

The RPF specification, MIL-STD-2411, has definitions for how frames are to be laid out and found within a RPF directory. All RPF data is supposed to lie under one RPF directory, and an A.TOC file, describing all the files and their groupings, should be directly within the RPF directory. That's why the RpfLayer needs a path to a RPF directory - it's really looking for the A.TOC file, and knows where to find it. It also needs a path to the RPF directory because it needs to prepend that path to the paths to the files that the A.TOC file knows about.

The A.TOC files that can be created with this MakeToc class can be created to contain absolute frame paths. The MakeToc class can take the paths to several RPF directories, and create a single A.TOC file that preserves all of their current file paths. You have to use alot of caution with this capability, however. These A.TOCs containing absolute file paths will not work if the data is moved to another machine, or if referenced by a machine with a different type file system (i.e. Windows). They may not work for other implementations of code that display RPF data - the code in this package has been modified to test for absolute file names.

That said, absolute file names should be used instead of giving the RpfLayer several RPF directories. The RpfTocHandler does much less work when it is allowed to group coverages together to make bigger areas.

This code was ported from C code provided in the original Mitre RPF package that had limits to the number of frames that could make up the areas. I'll be working to eliminate those limits, but I wanted to get a working version of the code out there. I'm also planning on modifying this class so that it can load the RpfTocHandler directly, therefore eliminating the need for A.TOCs altogether when there is more than one RPF directory.

       Usage:  java com.bbn.openmap.layer.rpf.MakeToc (RPF dir path) (RPF dir path) ...

This will create an A.TOC file in the current directory for the RPF files in the RPF directory paths. Use:

       java com.bbn.openmap.layer.rpf.MakeToc -help

for other options.

NOTE: Make sure that the RPF directories and their contents are in upper case. It's a spec requirement, although with CD copies and FTP downloads, the file name cases sometimes get switched. Use com.bbn.openmap.layer.rpf.ChangeCase to modify the file name cases. Also, if there is more than one RPF directory in the path to the image frames, use the absolute path option. Otherwise, the code will focus on making the top-most RPF directory the one to key the internal relative paths off of, and that might not be what you want.

See Also:
  `ChangeCase`

Nested Class Summary
`class` `MakeToc.Frame` An internal representation of a Frame file.
`class` `MakeToc.Group` An internal representation of a boundary rectangle for frames.

Field Summary
`static java.lang.String` `ATOC_FILENAME` Output file name of the A.TOC file.
`static int` `DEFAULT_MAX_SIDE` According to Dan Scholten's original code, this was 2 times the max - changed from 30 on 6/17/94 to 200 for 81 JNC's in zone 1.
`static double` `EPS`
`static double` `EPS2`
`protected int` `maxSide` The boundary edge frame length for groups.
`protected java.lang.String` `producer` The producer name for the frame files.
`protected ProgressSupport` `progressSupport`
`protected boolean` `relativeFramePaths` Flag to use relative frames paths - default is true.

Constructor Summary
`MakeToc()`

Method Summary
`protected boolean` `addFrameToGroup(MakeToc.Group grp, MakeToc.Frame frm, int index)` Does the actual checking to see if the frame gets added to the group, by checking the frame's location with the group's current boundaries, and resizing the group boundary if the frame is touching it.
`void` `addProgressListener(ProgressListener list)` Add a ProgressListener that will display build progress.
`void` `clearProgressListeners()` Clear all progress listeners.
`void` `create(java.lang.String[] rpfFilePaths, java.lang.String outputFile)` Create a A.TOC file specificed by the frame file list, at the location specified.
`void` `create(java.lang.String[] rpfFilePaths, java.lang.String outputFile, boolean dchum)` Create a A.TOC file specificed by the frame file list, at the location specified.
`java.lang.String` `createPadding(int length, boolean nullTerminated)`
`protected void` `fireProgressUpdate(int type, java.lang.String task, int frameNumber, int totalFrames)` Fire an build update to progress listeners.
`protected int` `getMaxSide()` Get the Maximum number of frames along a group boundary edge.
`java.lang.String` `getProducer()` Get the producer code currently set.
`boolean` `getRelativeFramePaths()`
`void` `groupFrames(java.util.Vector frames, java.util.Vector groups, boolean isDchum)` Take the Vector of frames, and group them into boundary rectangles, represented by groups.
`protected java.lang.String` `latlong2GEOREF(double latitude, double longitude)` This program attempts to convert latitudes and longitudes given in a decimal format into a GEOREF alphanumeric designation code.
`static void` `main(java.lang.String[] argv)` Create an A.TOC file.
`protected boolean` `near(double a, double b, double eps)` A little function to tell of one edge is near another.
`void` `organizeFrames(java.lang.String[] framePaths, RpfHeader head, java.util.Vector frames)` Get all the frame paths, and sort through them.
`java.lang.String` `promptForScale(java.lang.String query)` Prompt for input.
`void` `removeProgressListener(ProgressListener list)` Remove a ProgressListener that displayed build progress.
`java.lang.String[]` `searchForRpfFiles(java.lang.String[] startDirs)` Look for RPF frame files, given a bunch of places to start looking.
`protected void` `setMaxSide(int set)` Set the Maximum number of frames along a group boundary edge.
`void` `setProducer(java.lang.String setting)` Set the 5 letter producer code for the frames.
`void` `setRelativeFramePaths(boolean setting)` Set whether to use relative frame paths in the A.TOC file.
`void` `writeTOCFile(java.lang.String filename, RpfHeader head, java.util.Vector frames, java.util.Vector groups)` Create and write out an A.TOC file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_MAX_SIDE

    public static final int DEFAULT_MAX_SIDE

  According to Dan Scholten's original code, this was 2 times the max - changed from 30 on 6/17/94 to 200 for 81 JNC's in zone 1. This might not be enough for world-wide coverage of larger scale maps that are now available. This number may have to be increased depending on how much data you need.

  See Also:
    Constant Field Values

### EPS

    public static final double EPS

See Also:
  Constant Field Values

### EPS2

    public static final double EPS2

See Also:
  Constant Field Values

### ATOC_FILENAME

    public static final java.lang.String ATOC_FILENAME

  Output file name of the A.TOC file.

  See Also:
    Constant Field Values

### maxSide

    protected int maxSide

  The boundary edge frame length for groups.

### relativeFramePaths

    protected boolean relativeFramePaths

  Flag to use relative frames paths - default is true.

### producer

    protected java.lang.String producer

  The producer name for the frame files. Default is DMAAC.

### progressSupport

    protected ProgressSupport progressSupport

Constructor Detail

### MakeToc

    public MakeToc()

Method Detail

### main

    public static void main(java.lang.String[] argv)

  Create an A.TOC file.

  Parameters:
    `argv` - The arguments should at least include a path to a RPF file root directory. Other options can be found by using a -help option.

### create

    public void create(java.lang.String[] rpfFilePaths,
                       java.lang.String outputFile)
                throws MakeTocException

  Create a A.TOC file specificed by the frame file list, at the location specified.

  Parameters:
    `rpfFilePaths` - An array of all RPF Frame file paths. If these paths are relative, the MakeToc class should be set for that.
    `outputFile` - the complete pathname to an A.TOC file to be written.
  Throws:
    `MakeTocException` - if anything goes wrong.

### create

    public void create(java.lang.String[] rpfFilePaths,
                       java.lang.String outputFile,
                       boolean dchum)
                throws MakeTocException

  Create a A.TOC file specificed by the frame file list, at the location specified.

  Parameters:
    `rpfFilePaths` - An array of all RPF Frame file paths. If these paths are relative, the MakeToc class should be set for that.
    `outputFile` - the complete pathname to an A.TOC file to be written.
    `dchum` - If dchum is present, all frames get placed in their own group. False is default. Dchum are replacement subframes.
  Throws:
    `MakeTocException` - if anything goes wrong.

### searchForRpfFiles

    public java.lang.String[] searchForRpfFiles(java.lang.String[] startDirs)

  Look for RPF frame files, given a bunch of places to start looking. The output of this can be passed to the create method.

  Parameters:
    `startDirs` - Directory paths.
  Returns:
    an array of strings representing path names to RPF frame files.

### setRelativeFramePaths

    public void setRelativeFramePaths(boolean setting)

  Set whether to use relative frame paths in the A.TOC file.

### getRelativeFramePaths

    public boolean getRelativeFramePaths()

### setProducer

    public void setProducer(java.lang.String setting)

  Set the 5 letter producer code for the frames. If you didn't make the frames, they DMA probably did, so the default is applicable - DMAAC. There are a bunch of accepted codes in the MIL-STD-2411 for producers.

### getProducer

    public java.lang.String getProducer()

  Get the producer code currently set.

### setMaxSide

    protected void setMaxSide(int set)

  Set the Maximum number of frames along a group boundary edge. Don't change this after starting to group the frames.

### getMaxSide

    protected int getMaxSide()

  Get the Maximum number of frames along a group boundary edge.

### near

    protected boolean near(double a,
                           double b,
                           double eps)

  A little function to tell of one edge is near another.

### organizeFrames

    public void organizeFrames(java.lang.String[] framePaths,
                               RpfHeader head,
                               java.util.Vector frames)

  Get all the frame paths, and sort through them. This method sets up the frames vector and loads each Frame with it's attributes, so it can be grouped with its neighbors.

  Parameters:
    `framePaths` - the array of RPF file paths.
    `head` - an RpfHeader object to load with production information, that will be put into the A.TOC file.
    `frames` - the frame vector to load.

### promptForScale

    public java.lang.String promptForScale(java.lang.String query)

  Prompt for input.

### writeTOCFile

    public void writeTOCFile(java.lang.String filename,
                             RpfHeader head,
                             java.util.Vector frames,
                             java.util.Vector groups)
                      throws MakeTocException

  Create and write out an A.TOC file.

  Parameters:
    `filename` - the output filename.
    `head` - the RpfHeader containing header information.
    `frames` - the frame Vector.
    `groups` - the file groups Vector.
  Throws:
    `MakeTocException`

### groupFrames

    public void groupFrames(java.util.Vector frames,
                            java.util.Vector groups,
                            boolean isDchum)
                     throws MakeTocException

  Take the Vector of frames, and group them into boundary rectangles, represented by groups. If Dchum is present, all frames get placed in their own group.

  Parameters:
    `frames` - the frame Vector.
    `groups` - the group Vector.
    `isDchum` - flag to note if Dchum frames are present.
  Throws:
    `MakeTocException`

### addFrameToGroup

    protected boolean addFrameToGroup(MakeToc.Group grp,
                                      MakeToc.Frame frm,
                                      int index)
                               throws MakeTocException

  Does the actual checking to see if the frame gets added to the group, by checking the frame's location with the group's current boundaries, and resizing the group boundary if the frame is touching it. Assumes everything has been allocated in the group and frame. Not prepared for either being null.

  Parameters:
    `grp` - the group
    `frm` - the frame.
    `index` - the group index, referring to it's position in the Group Vector.
  Throws:
    `MakeTocException`

### latlong2GEOREF

    protected java.lang.String latlong2GEOREF(double latitude,
                                              double longitude)

  This program attempts to convert latitudes and longitudes given in a decimal format into a GEOREF alphanumeric designation code. The first letter of the code denotes the longitudinal 15 degree grid that contains the area of interest. The second letter denotes the latitudinal 15 degree grid. The third letter denotes the one degree longitudinal grid within the 15 degree longitudinal grid. The fourth letter denotes the one degree latitudinal grid within the 15 degree latitudinal grid. The fifth character is a number denoting the minutes longitudinally to the nearest 10. The sixth number denotes the minutes latitudinally to the nearest 10. Wouldn't it just have been easier to use the decimal latitudes and longitudes?

### createPadding

    public java.lang.String createPadding(int length,
                                          boolean nullTerminated)

### addProgressListener

    public void addProgressListener(ProgressListener list)

  Add a ProgressListener that will display build progress.

### removeProgressListener

    public void removeProgressListener(ProgressListener list)

  Remove a ProgressListener that displayed build progress.

### clearProgressListeners

    public void clearProgressListeners()

  Clear all progress listeners.

### fireProgressUpdate

    protected void fireProgressUpdate(int type,
                                      java.lang.String task,
                                      int frameNumber,
                                      int totalFrames)

  Fire an build update to progress listeners.

  Parameters:
    `frameNumber` - the current frame count
    `totalFrames` - the total number of frames.

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details