Design Document for CIB2LAS

CIB2LAS

AUTHOR: Brad Gross

Functional Summary:

Ingest a Controlled Image Base (CIB) Format image and save to a LAS image

Comments:

The routine CIB2LAS was created to convert Controlled Image Base (CIB) formatted images into a LAS image. CIB format is a dataset of orthophotos, made from rectified grayscale aerial images. CIB data conforms to the Raster Product Format (RPF) standard. CIB data is derived directly from digital images and are compressed and reformatted to conform to the RPF standard. CIB files are physically formatted within a National Imagery Transmission Format (NITF) message.

This module is written to convert CIB image data to a LAS image file, other image (product) categories which conform to RPF image format and NITF (National Imagery Transmission Format) file format may also be able to be converted with some modification. CIB is a one product type that conforms to RFP format. Others are CADRG and ADRG, Compressed and un-compressed ARC Digitized Raster Graphics, ADRI ARC digitized Raster Imagery, CDTED and DTED, Compressed and un-compressed Digital Terrain Elevation Data.

Background:

CIB is a database of digital images of the Earth. Pixel resolution is typically one (1), five (5), or ten (10) meters. The data is organized into eighteen (18) zones. The sixteen (16) zones in the non-polar region completely circle the earth in bands in an eastwardly direction. There are two (2) polar zones, one at each pole. Data in each zone is organized in grids (rows and columns). These rows and columns consist of frame files (contained in discrete frame files).

Each frame file contains 1536 lines of 1536 samples. The frame files are further divided into 36 sub-frames in a 6 row x 6 column matrix. Each subframe is 256 x 256 pixels. The CIB data is structurally organized IAW the RPF standard (MIL-STD-2411). This standard indicates that the frame files be stored in a hiearchial manner and overall structure is contained within the TOC file. Frame files are contained in distribution rectangles called boundary rectangles. Boundary rectangles consist of all rows and columns (of discrete frame files) within it's specified coverage area. Some frame files may be empty (not exist).

A Table of Contents File (TOC) is stored in the volume's root directory "/RPF". The TOC file informs the application software (user) how to re-assemble the frame files into a composite image (boundary rectangle). CIB volumes may contain more than one boundary rectangle. A boundary rectangle defines the geographic coverage area for all frame files contained within it. CIB volumes also may also contain overview images. Overview images are representative of the geographic area covered by a boundary rectangle. An overview image is a composite image of all frame files in the boundary rectangle after down-sampling, and may contain geographic boundaries added to help locate the boundary rectangle within larger images.

Boundary rectangles on a CIB volume may or may not be contiguous. CIB data is seamless in that there is pixels overlapping frame to frame. There are no additional pixels added for image framing. The files in a CIB volume conform to National Imagery Transmission Format Standard (NIFT) (MIL-STD-2500B) and the overall structure of a CIB volume conforms to the RPF format.

CIB data conforms to the ARC projections system. Data in the non-polar regions is in the Equirectangular projection, data in the polar zones in the Azimuthal Equidistant Projection, polar aspect, sphereical form.

CIB data may not include 100% coverage. Areas where there is no data will be filled with transparent pixels. If an entire frame contains transparent pixels, the frame will not be sent, and the empty frame will be indicated in the TOC file.

CIB data is grayscale and contains only one (1) band. CIB data may or may not be compressed. If compressed, it will be compressed using the VQ algorithm with a compression ration of approximately 15:1. CIB uses the WGS-84 Datum.

CIB (Controlled Image Base):

Document:

MIL-PRF-89041

Intended Use:

This specification is intended to provide guidlines for the preparation and use of CIB data to support various weapons, C3I theater battle management, mission planning, and digital moving map systems.

Purpose:

The purpose of this document is to specify the data format and characteristics of CIB data for producers and users.

Scope:

This specification provides requirements for the preparation and use of Raster Product Format (RPF) Controlled Image Base (CIB) data.

RPF (Raster Product Format):

Document:

MIL-STD-2411

Scope:

Raster Product Format (RPF) is a standard data structure for geospatial databases composed of rectangular arrays of pixel values (e.g. digitized maps or images) in compressed or uncompressed form. RPF is intended to enable application software to use the data in RPF format on computer-readable interchange media directly without further manipulation or transformation.

Purpose:

The RPF is intended to define a common format for interchange of raster data between producers of such data in DoD and users of data, to help facilitate interoperability among mission-critical systems.

NITFS (National Imagery Transmission Format Standard):

Document:

MIL-STD-2500B

Scope: Establishes the requirements for the file format component of the National Imagery Transmission Format Standard (NITFS). The NITFS is a collection of related standards and specifications developed to provide a foundation for interoperability in the dissemination of imagery and imagery associated data among different computer systems.

Purpose: Provides a detailed description of the standard file format structure. It specifies valid data content and format for all fields defined within the NITF file.

Compatibility: NITF 2.1 is compatible with NATO standard NSIF (Nato Secondary Image Format) and ISO standard BIIF (Basic Imagery Interchange Format).

Applicable Documentation for CIB

Document No. Description Revision Date
MIL-PRF-89041 Controlled Image Base (CIB) Ammendment 1 31 July 1995
MIL-STD-2411 Raster Product Format (RPF) Notice 117 January 1995
MIL-STD-2411-1 Registered Data Values for Raster Product Format Original30 August 1994
MIL-STD-2411-2 Integration of Raster Product Format into National Imagery Transmission Format Original 26 August 1994
MIL-STD-2500B National Imagery Transmission Format Ver 2.1 for the transmission of NITF standard Rev. B 12 October 1998
MIL-A-89007 ARC Digitized Raster Graphics (ADRG) Original 22 February 1990

Some of these documents are currently undergoing updating

These documents can be found in the cib2las/DESIGN/REF_DOCS directory or at NIMA'S website. (use link below)

www.nima.mil.publications/specs/index.html

CIB (RPF) Volume (file system structure):

/RPF DIRECTORY (root directory) | | |_______Table of Contents file "A.TOC" |_______Over view images files "*.OVR" |_______/FRAME FILE DIRECTORIES | |_____frame files

Figure 2: CIB (RPF) directory Structure

A CIB image is defined by the frames contained in a boundary rectangle. A boundary rectangle is composed of a matrix (eg. 6 x 4 ) of frames. Information for each frame is contained in a frame file in a frame file directory. The TOC file indicates each frame file's location in the boundary rectangle. Each frame is composed of 6 x 6 sub-frames. A sub-frame is composed of a 256 x 256 pixel image. CIB data is seamless in that there is no overlap from one frame to another. A CIB volume may contain more than one boundary rectangle which may or may not be contiguous.


   CIB VOLUME:

A.TOC (Table of Contents File Sections)

[Header Section]
 contains general volume information
 
 header record contents
[boundary rectangle section]
 contains a list of boundary rectangles records                
       
 each boundary record's contents

[frame file index section]
 contains a list of frame files records
 
   each frame file record's contents 
 [colortable index section]
 contains information on color tables

 [location section]
 contains information on record locations with in the TOC file

Example CIB Boundary Rectangle Region Structure

Figure 3: Example Boundary Rectangle from MIL-STD-2411

Example CIB Boundary Rectangle Structure (----------- 6 horizontal frames ------------) _________________________________________________ | | | | | | | | | | | | | | | 0 | 1 | 2 | 3 | 4 | 5 | | | | | | | | |_______|_______|_______|_______|_______|_______| (-- 4 vertical x 6 horiz. | | | | | | | frames this boundary | | | | | | | region (will vary) | 6 | 7 | 8 | 9 | 10 | 11 | | | | | | | | |_______|_______|_______|_______|_______|_______| | | | | | | | | | | | | | | | 12 | 13 | 14 | 15 | 16 | 17 | (---- 4 vertical frames | | | | | | | |_______|_______|_______|_______|_______|_______| - _ | | | | | | | | | | | | | | | | | Boundary Rectangle | | 18 | X | 20 | 21 | 22 | 23 | | defined by all frame | | | | | | | | | | | files in a directory | |_______| | | |_______|_______|_______|_______| |_ _| | | | | | | | | | | | | \ / \ / V CIB Frame File Image Structure (----- 1536 pixels ----) _______________________ __ __ | | | | | | | | | 0 | 1 | 2 | 3 | 4 | 5 | | |___|___|___|___|___|___| | | | | | | | | | (---- 6 x 6 subframes in a frame | 6 | 7 | 8 | 9 | 10| 11| | (required by standard) |___|___|___|___|___|___| | | | | | | | | | | 12| 13| 14| 15| 16| 17| | (---- 1536 pixels |___|___|___|___|___|___| | _ _ | | | | | | | | | | | 18| 19| 20| 21| 22| 23| | | This frame is a discrete file | |___|___|___|___|___|___| | |_ _| | | | | | | | | | 24| 25| 26| 27| 28| 29| | |___|___|___|___|___|___| | | | | | | | | | | 30| * | 32| 33| 34| 35| | |___| | |___|___|___|___| __|__ | | V CIB Sub-frame Structure ___ | | (-- subframe 256 x 256 pixels | 31| (required by standard) |___|

CIB Zones

Figure 1: CIB Zones

Original Code

The original code for this module is sgibrowse, a NIMAMUSE application. It includes modifications by EDC staff and others for tesing and feasibility studies of this module.

Viewing Software

CIB can be viewed using NIMAMuse. NIMAMUSE contains the Raster Importer that will allow CIB data to be imported for viewing. Muse also contains the CIB Browser which can be used to point data locations. NIMAMuse can be obtained from their website "http://164.214.2.59:80/geospatial/SW_TOOLS/NIMAMUSE"

The application within NIMAMUSE for viewing CIB images is sgibrowse which can be found under the CIB2LAS directory in directory sgibrwse.

Requirements:

  1. A single image is written in LAS format
  2. A single input window is allowed. The window is specified by either upper left and lower right corner coordinates (lat/long or projection), upper left coordinates and number of lines, samples, or upper left line, sample and number of lines, samples. The window may span more than one CIB frame.
  3. A list of tile numbers (shown on the CD case graphic) to ingest is allowed. The tiles shown on the CD correlate to the boundary rectangles, although the geographic area the boundary rectangle actually covers may vary slightly (in the tenths of degrees) from what is shown on the CD case.
  4. The input CIB image may be read from either a locally mounted hard disk, a locally-mounted CD drive, or a remote CD drive that is network available and supported by LAS operators.
  5. A user-specified fill value is used for all output image pixels that are not present in the input CIB image or are transparent pixels in the input CIB image.

Scope/Limitations:

  • Only hard disk and single-volume CDs are supported CIB image sources.
  • The overview map/image frames are not written to LAS format.
  • Only one CIB image is input.
  • Since CIB images are only grayscale, only one band is ever output.
  • Since CIB images only use up to 255 values, the output image is always byte.
  • If a fill value other than the transparent value specified in original CIB image is used, the MIN/MAX values may be the fill value. CIB images may have transparent pixels, which will have a different value than non-transparent pixels. CIB images have 216 data pixel values possible, and 217 including the transparent pixel value if present.

  • LAS DDR file fields mapping from CIB data

    DDR Field Origination Information

    DDR Field Description Originated from CIB
    nl number of lines in image number of vertical frames * 1536 (default) or based on user inputs
    ns number of samples in image number of horizontal frames * 1536 (default) or based on user inputs
    nbands number of bands in image defined by CIB to be one (1)
    dtype data type of pixels byte as required by CIB, 255 values max (8 bit) (unsigned char)
    master_line line relative to master image 1, image is master
    master_sample sample relative to master image 1, image is master
    valid[8] validity flags
    projection code set VALID: CIB polar zones in Equirectangular Projection (LAS Projection #17) by defn. Non-polar CIB zones use the Azimuthal Equidistant Projection by definition. (LAS Projection #12) See Map Projections --- A Working Manual Professional Paper 1395 pg 90-91 for Equirectangular Projections and pg 191 for Azimuthal Equidistant Projections.
    zone code VALID: Set zone code to INVALID zone 62
    datum code set VALID: All CIB data in WGS84 Datum (LAS #317) by definition
    proj_coef set VALID projection coordinates enterred
    ground units set VALID: units set to meters (original CIB coordinates are in degreees, corner coordinates below are converted to meters prior to writing DDR due to limitations of C_TRANS();
    ground distance set VALID: pixel - pixel distance in meters
    corner coordinates set VALID: projection coordinates are valid
    line/sample increments set VALID: original un-sampled image
    proj_coefficients
    [0] Sphere Listed as necessary for Equirectangular Projection, but with Datum present, SMajor and SMinor must be enterred to eliminate errors. Sphere radius for images with datums is returned from gctpc function shpsz as 6370997.0 meters. This radius value is used in conversions from geographic coordinates to projections coordinates and back, but is not saved in ddr
    [0] SMajor CIB data is LAS datum #317, used c_getdatum to get SMajor and SMinor axis
    [1] SMinor CIB data is LAS datum #317, used c_getdatum to get SMajor and SMinor axis
    [4] CentMer By defn. CIB Central Meridian for ARC projection system, Non-Polar Zone Projection - Equirectangular projection Central Meridain is located at 0.00 degress West Longitude (from MIL-A-89007 ARC Digitized Raster Graphics Fig. 22 pg. 68
    [5] TrueScale Enterred based on CIB zone that image is in. The Center of True Scale Latitudes for each zone are found listed in MIL-A-89007 ARC Digitized Raster Graphics (ADRG) Appendix Table IV Page 64.
    [6] FE CIB data does not use False Easting
    [7] FN CIB data does not use False Northing
    proj_code GCTP projection code by defn. CIB polar zone images in Equirectangular Projection (LAS #17), polar images are in the Azimuthal Equidistant Projection (LAS #12). CIB polar zones not supported due to lack of data for testing.
    zone_code UTM or State Plane zone set to 62 (invalid), not a zone type projection
    datum_code GCTP datum code By definition, CIB datum is WGS-84 (LAS #317)
    system computer system data is on read from environment DATASYS
    proj_units[12] Projection units meters, required by TRANSLAS (CIB coordinates are in degrees. Corner coordinates are converter prior to writing ddr.)
    last_used_date last access date set by call to c_lused()
    last_used_time last access time set by call to c_lused()
    proj_coef[15] GCTP projection parameters Set according to appropriate information in CIB documentation
    upleft[2] Corner coordinates units: meters, calculated based on CIB frame file fields < northwest /upper left longitude > and field < northwest/upper left latitude > in frame file coverage section of frame file found in first (western most) column found in last (northern most) row of CIB image. Frame file values are in degrees. Use gctpc to convert to meters
    loleft[2] latitude/longitude or units: meters, calculated base on CIB frame file field < southwest /lower left longitude > and field < southwest/lower left latitude > in frame file coverage section of frame file found in first (western most) column found in last (northern most) row of CIB image. Converted from geographic coordinates to projections coordinages using gctpc.
    upright[2] northing/easting order or units: meters, calculated based on CIB frame file field < northeast /upper right longitude > and field < northeast/upper right latitude > in frame file coverage section of frame file found in first (western most) column found in last (northern most) row of CIB image. Converted from geographic coordinates to projections coordinages using gctpc.
    loright[2] projection coordinates (y/x) units: meters, calculated based on CIB frame file field < southeast /lower right longitude > and TOC field < southeast/lower right latitude > in frame file coverage section of frame file found in first (western most) column found in last (northern most) row of CIB image. Converted from geographic coordinates to projections coordinates using gctpc.
    pdist_y projection distance/pixel (y-direction) Enterred based on CIB frame file field < North-South/vertical resolution > distance between pixels in meters (y-direction)
    pdist_x projection distance/pixel (x-direction) Enterred based on CIB frame file field < East-West/horizontal resolution > distance between pixels in meters (x-direction)
    line_inc line increment for sampling 1, no sub-sampling
    sample_inc sample increment for sampling 1, no sub-sampling
    BDDR
    bandno band no. of the record 1, CIB contains 1 band, required by specification
    valid min/max validity flag of the band if MINMAX environment set, flag is VALID, otherwise INVALID
    minval minimum value of the band obtained from image pixel data
    maxval maximum value of the band obtained from image pixel data
    source source of data Read RPF Frame file [attribute section] attrib id = 22 image source if present
    instrument type of sensor unavailable, set to blank
    direction direction of capture process unavailable, set to blank
    date capture date set by c_lused() at ingest
    time capture time set by c_lused() at ingest

    PARAMETERS:

    CIB2LAS Input Parameters
    Parameter Description Optional Default
    - INDIR INput DIRectory, Path to CIB volume RPF directory. Optional if ingesting from a CD and the RPF directory is in the root directory YES
    - OUTOUTput name, LAS output image name NO
    - COMMENT COMMENT, Text (instructions) sent to operator for mounting a particular CD. YES
    - WINDOW WINDOW, If UNITS is LS, then WINDOW specifies the starting line, starting sample, number of lines, number of samples. Otherwise WINDOW specifies Geographic coordinates (UNITS = DEG or DMS) or Projection Coordinates (UNITS = PRO) defining the windowing of the input CIB image. The four window parameters specify the corner coordinates: Upper Left (North West) Lat. (Y) and Long. (X) and Lower Right (South East) Lat. (Y) and Long. (X) YES
    - UNITSWindow UNITS specifies the type of units used in WINDOW above. NO LS
    Valid units are:
    LS Line - Sample
    DEG Degrees
    DMS Degrees Minutes Seconds (+DDDMMMSSS.SS)
    PRO Projection Coordinates (meters)
    - FILL FILL value for empty frames and frame areas that contain transparent pixels, i.e. no data. NO 0
    - TILENUM The TILE NUMbers, from the CD case graphic, that the user wishes to ingest. YES

    Overall design:

    Flow diagram:

    
        CIB2LAS
          |
          |___ CMSTATUS outfile
          |--- MAIN
          |       |--- cib2las()
          |               |--- c_inlas()
          |               |--- get_par()
          |               |       |--- p_find(COMMENT)
          |               |       |--- p_find(INDIR)
          |               |       |--- c_cmhost(INDIR)
          |               |       |--- p_find(OUT)
          |               |       |--- p_find(FILL)
          |               |       |--- p_find(UNITS)
          |               |       |--- p_find(WINDOW)
          |               |       |       |--- IF UNITS ARE LS
          |               |       |       |      |--- read WINDOW      
          |               |       |       |--- IF UNITS ARE DMS or DEG
          |               |       |       |      |--- IF UNITS ARE DEG
          |               |       |       |      |          |--- read window       
          |               |       |       |      |--- ELSE-IF UNITS ARE DMS
          |               |       |       |      |          |--- c_decdeg(ULLAT)
          |               |       |       |      |          |--- c_decdeg(ULLONG)
          |               |       |       |      |          |--- c_decdeg(LRLAT)
          |               |       |       |      |          |--- c_decdeg(LRLONG)      
          |               |       |       |      |--- calc_rectangular_coors()
          |               |       |       |               |--- get_zone()
          |               |       |       |               |--- get_truescalelat()
          |               |       |       |               |--- equiforint()      
          |               |       |       |               |--- equifor()     
          |               |       |       |--- ELSE-IF UNITS ARE PRO
          |               |       |       |       |--- read WINDOW   
          |               |       |--- p_find(msgtim)     
          |               |       |--- p_find(minmax)    
          |               |--- mount_cd
          |               |       |--- c_tpopen()
          |               |       |--- gethostname()
          |               |       |--- c_up2low()
          |               |       |--- q_intg(MOUNTED)
          |               |       |--- q_string(DRIVE)
          |               |       |--- q_string(DEVICE)
          |               |       |--- q_out()
          |               |--- c_cmhost(out)
          |               |--- read_toc(A.TOC)
          |               |       |--- c_cmtae(filename)
          |               |       |--- IF fopen(toc) FAIL
          |               |       |        |--- c_up2low(toc)
          |               |       |               |
          |               |       |               |--- IF fopen(toc) FAIL
          |               |       |                       |
          |               |       |                       |--- c_low2up(toc)
          |               |       |                               |
          |               |       |                               |--- IF fopen(toc) FAIL
          |               |       |                                       |      
          |               |       |                                       |--- fatal error 
          |               |       |--- fread(standard date)
          |               |       |--- locUDHD()      
          |               |       |--- fread(header)            
          |               |       |--- parse_locations            
          |               |       |--- malloc(list ff records)            
          |               |       |--- setup_bound_rects(bound_rect_array)
          |               |       |            |--- FOR EACH boundary rectangle record
          |               |       |            |         |--- fread(min/max lat/long)
          |               |       |            |--- malloc(bound_rect_matrix)
          |               |       |            |--- FOR EACH boundary rectangle record
          |               |       |            |         |--- fread(upper/lower lat/long)
          |               |       |            |--- free(bound_rect_array)
          |               |       |--- FOR EACH ff record
          |               |               |--- fread(ff)  
          |               |               |--- locate_frame(ff) 
          |               |                      |--- get_rows()
          |               |                      |--- get_columns()
          |               |--- CIB2LASout
          |               |       |--- IF fopen(ff) FAIL
          |               |       |        |--- c_up2low(ff)
          |               |       |               |--- IF fopen(ff) FAIL
          |               |       |                      |--- c_low2up(ff)
          |               |       |                             |--- IF fopen(ff) FAIL
          |               |       |                                    |--- fatal error
          |               |       |--- read_frame_coverage
          |               |       |--- read_frame_attributes
          |               |       |--- IF type = slssnlns
          |               |       |        |--- calc_corners()
          |               |       |--- ELSE-IF type = coors4
          |               |       |        |--- update_ddr()
          |               |       |        |--- c_wndconv() 
          |               |       |        |--- calc_corners()
          |               |       |--- ELSE-IF type = default
          |               |       |        |--- calc_corners()
          |               |       |--- malloc(columns)     
          |               |       |--- malloc(framebuf)
          |               |       |--- malloc(framebuf[i])
          |               |       |--- malloc(linebuf)
          |               |       |--- c_eopenr()      
          |               |       |--- q_intg(outfilecreated)
          |               |       |--- q_out()
          |               |       |--- c_inittm()
          |               |       |--- c_startm()            
          |               |       |--- FOR EACH ff read_frame(ff)
          |               |       |      |--- IF open(ff) FAIL
          |               |       |      |      |--- c_up2low(ff)
          |               |       |      |             |--- IF fopen(ff) FAIL
          |               |       |      |                    |--- c_low2up(ff)
          |               |       |      |                            |--- IF fopen(ff) FAIL
          |               |       |      |                                   |--- return error      
          |               |       |      |--- find_RPF_hdr()       
          |               |       |      |--- get_hdr() 
          |               |       |      |--- find_loc()     
          |               |       |      |--- get_loc()   
          |               |       |      |--- FOR EACH record 
          |               |       |      |       |--- SWITCH(record type)
          |               |       |      |              |--- get_cov()
          |               |       |      |              |--- get_comphdr()         
          |               |       |      |              |--- get_comptbl()         
          |               |       |      |              |--- get_colhdr()         
          |               |       |      |              |--- get_colmap()         
          |               |       |      |              |--- get_imghdr()         
          |               |       |      |              |--- get_imgdsp()         
          |               |       |      |              |--- get_imgmask()
          |               |       |      |              |--- get_colcon()   
          |               |       |      |              |--- get_imgpix()/get_uimgpix()   
          |               |       |      |              |--- get_atthdr()   
          |               |       |      |              |--- get_atttbl()   
          |               |       |      |              |--- get_attcov()   
          |               |       |      |              |--- get_newhdr()   
          |               |       |      |              |--- get_newtbl()   
          |               |       |      |--- bld_img()/bld_uimg()      
          |               |       |      |--- wrt_img()      
          |               |       |--- c_ewrite()            
          |               |       |--- getminmax()
          |               |       |--- c_stoptm()            
          |               |       |--- update_ddr()
          |               |               |--- c_intddr()
          |               |               |--- c_intbdr() 
          |               |               |--- c_getdatum()
          |               |               |--- c_degdms(cent merid)
          |               |               |--- get_truescalelat(zone)
          |               |               |--- c_degdms(true lat)
          |               |               |--- c_degdms(fe)
          |               |               |--- c_degdms(fn)
          |               |               |--- getenv(DATASYS)
          |               |               |--- c_putddr()
          |               |               |--- c_putbdr()      
          |               |               |--- c_lused()      
          |               |--- unmount_cd 
          |               |       |--- c_tpreop()
          |               |       |--- c_tpclos()
          |               |       |--- q_intg(MOUNTED)
          |               |       |--- q_out()
          |               |--- c_complt()/c_clean()
          |--- IF CD mounted
          |     |--- RELDRIVE  
          |
         END
    
        toc = talble of contents
        ff  = frame file
        
    

    Algorithm:

    
    Read and validate user inputs
        operator instructions/request for CD mount (optional)
        CIB directory path (optional if CD)
        LAS output filename
        Window Units
        FILL value for transparent pixels and empty frames  
        Window Parameters
            if UNITS == PRO
                convert corner parmaters to degrees
                    get zone specified corners in
                    get latitude of true scale for zone
                    call equiinv to convert corners from meters to degrees
            if UNITS == DMS
                convert corner parametes to degrees
                    call c_decdeg to convert dms to degrees
            check corner values against limits        
       retrieve globals
    If user parameters contains a comment,
      mount CD
    Convert output name from a LAS name to a host name
    Read CIB image Table of Contents (A.TOC)
        Open Table of Contents File
        Read in and perform checks on Table of Contents
        build a matrix representing the geographic locations of the boundary rects
        use the boundary rectangle matrix to number the boundary rectangles to 
             correlate to the numbering on the graphic on the CD case
        build a list of frame files in CIB volume
        for each frame file
            read in path in CIB volume to frame file list
            read in frame file name to list
            read in boundary rectangle containing frame file to list
            from frame file name 
                get frame file zone, save in list
                calculate frame file sequential frame number 
                calculate frame file row in zone save in list
                calculate frame file column in zone save in list
         end for each...
    Calculate Limits of CIB image in its' zone (min/max column and min/max row)
    Allocate a list of pointers to frame file records (list)
    Set entire list of pointers to NULL to indicate empty frame files (empty list)
    Set pointers to point to appropriate frame file records so frame file can be
        manipulted using their row and column numbers /Make list appear like a 
        matrix (array) of rows and columns.
    Calculate portions of CIB image to output and write out
        if minmax indicated,
            set minimum to max value
        find the first non-empty frame file in the first row to use to obtain
           the upper left corner coordinates of the CIB Volume image.
        get frame file's name and path
        get the frame file's zone code
        if the frame file is a polar image,
            raise fatal error
            exit 
        endif
        Open frame file and read coverage section (Lat. and Long.)
        Correct the longitude value of the coverage section
            to first column of CIB image (may be empty frame files in row)
        Correct latitude and longitude to be center pixels base vs.
            corner pixel base
        Read in pixel-pixel resolution from frame file for calculations
        Read source attribute from frame file (use as datasource in ddr)
        Calculate portions of CIB Volume to output
            If user specified SSNSSLNL, window units = LS (line sample)    
                if specified values exceed input image size
                    raise fatal error
                    exit
                endif spec...
                Correct ss,sl to 0 based vales
                calculate first column of CIB image to output
                calculate last column of CIB image to output
                calculate first row of CIB image to output
                calculate last row of CIB image to output
                calculate the corner coordinates of the specified output image
                calculate the number of lines in the first row
            end if SSNSSLNL
            if user specified COORS4 UNITS = DEG, DMS, or PRO
                if latitude specified > upper left corner of CIB image
                    raise fatal error
                    exit
                endif
                if longitude specified &ly longitude of left edge of CIB volume 
                     raise fatal error
                     exit
                endif lat...
                calculate starting sample of CIB image to output
                calculate starting line of CIB image to output
                calculate UL latitude of image being output
                calculate UL longitude of image being output
                calculate LR latitude of image being output
                calculate LR longitude of image being output
                calculate first column of CIB image to output
                calculate last column of CIB image to output
                calculate first row of CIB image to output
                calculate last row of CIB image to output
                calculate the number of lines in first row to output
            end if COORS4
            if user specified no image parameters (DEFAULT)
                calculate first column of CIB image to output
                calculate last column of CIB image to output
                calculate first row of CIB image to output
                calculate last row of CIB image to output
                set starting sample of CIB image to output to 0
                calculate number of samples of CIB image to output 
                set starting line of CIB image to output to
                calculate number of lines of CIB image to output
                set number of lines to output in first row to 1536 (1 frame file)
                calculate UL latitude of image being output
                calculate UL longitude of image being output
                calculate LR latitude of image being output
                calculate LR longitude of image being output
            endif DEFAULT   
        check enterred/calculated number of samples and lines against 
            samples and lines in CIB image
        calculate output image size
        if output image size > 10Gb (CIBMAXIMGSIZE)
             raise fatal error
             free allocated memory
             exit
        allocate memory to store information on each column in image to be output
          (info includes, starting sample, ending sample, number of samples) 
        set values for first column
        set default values into remaining columns
        set values for last column
        allocate memory for linebuf, will hold one line of output image        
        create output file
        set current output line to 1 (eline)
        initialize output message routine
        for each row in output image
            calculate actual row in CIB image
            for each column in output image
                if frame file exists for this row and column
                    get frame file path and name from list
                    read frame file image into framebuf[column]
                        if file compressed
                            uncompress
                        convert pixel values from CLUT entries to actual colors
                            if pixel CLUT entry #217 (transparent pixel)
                                put fill value in pixel
                else (empty frame file)
                    fill framebuf[column] with fill value
                endif frame file exi...
            end for each col...       
            calculate starting line of row to output
            calculate ending line of row to output
            for row starting line to row ending line
                write out line to output image
                if minmax specified
                    update min/max to include this line
            end for star...
        end for each row...
        stop message routine
        if size of output image not size specified
            raise fatal error
            free allocated memory
            exit
        end if size
        look through attributes of corner frame file for datasoure
            if datasource found (paramid==1)
                 get value
        Create ddr file and update
            set datum value 317
            call getdatum to retieve smajor and smior axis
            set projection parameters for smajor axis
            set projection parameters for sminor axis
            set projection parameters for Central Meridain
            call get_truescalelat to get Latitude of true scale for CIB zone image
                is located in
            set projection parameters for Latitude of True Scale 
            set projection parameters for FE and FN
            set all ddr code validity flags to valid
            for each corner coordinate 
                Convert image corner coordinates from degrees to meters
                    (required by translas, only Geo projection can be in units other 
                     feet or meters)
                     read necessary info from ddr
                     call equiforint
                     call equifor to convert from degree to meters
                save corner in meters into ddr
            end for each cor..
            set projection units to meters
            set projection x distance to CIB East-West Resolution
            set projection y distance to CIB North-South Resolution
            set masterline/master sample 1, original unsampled image
            set line increment/sample increment to 1.0 original unsampled image
            set band to 1, only 1 band in CIB
            set min and max values
            get set ddr system to DATASYS enviroment variable
            set ddr datasource to CIB source attribute
            write ddr
            call c_lused to update last used date and time.
        free allocated memory
    if cd is mounted
        unmount cd
    write CIB2LAS completion message
    

    Error Conditions:

    Non-Fatal Error Messages:
    1. [cib2las-fatal] Error DATASYS undefined

      Environment global variable DATASYS is undefined. Contact your system administrator.

    2. [cib2las-ddr] Error writing DDR

      An error occurred while writing out ddr information.

    3. [cib2las-bdr] Error writing BDR

      An error occurred while writing out bdr information for ddr.

    4. [cib2las-ddr] Error Updating Last Used fields

      An error occurred while updating the last used fields in the ddr file.

    5. [cib2las-ddr] Error converting < XXXXXXX YYYYYYYYY> to degrees

      An error occurred when specified ddr projection coefficeint value was being converted from packed dms to degrees.

    6. [cib2las-ddr] Error setting < XXXXXX XXXXXX>

      An error occurred while trying to update and set the indicated ddr projection parameter.

    7. [cib2las-ddr] Error conveting corner coordinates

      An error occurred while converting the image coordinates take from the CIB image from degrees to projection coordinates in meters.

    8. [cib2las-ddr] Error retrieving datum info

      An error occurred while retrieving the datum values.

    9. [cib2las-tae] Error passing < XXXXXXXX> to TAE

      An error occurred while trying to pass the specified variable back to TAE.

    10. [cib2las-tae] Error passing variables to TAE

      An error has occurred while passing variables to TAE.

    11. [cib2las-cd] Error encountered reopening CD

      An error has occurred while trying to unmout a CD.

    12. [cib2las-cd] Error encountered closing CD

      An error has occurred while trying to unmout a CD.

    13. [cib2las-read] Error Reading Frame File 008ZMU16.I11

      An error has occurred while reading the specified frame file.

    14. [cib2las-read] Error reading attributes from frame file: 008ZMU16.I11

      An error has occurred while trying to read attributes of a frame file.

    15. [cib2las-toc] Error in head.standard_num:MIL-STD-89041

      An error has occurred while trying to read the standard number from the RPF header in A.TOC.

    16. [cib2las-source] Error reading image datasource

      An error has occurred while trying the read the source attribute of the frame file.

    Fatal Error Messages:
    1. [cib2las-read] Error opening frame file 008ZMU16.I11 to read coverage.

      An error has occurred while trying to open the indicated file to read the frame file's coverage.

    2. [cib2las-coverage] Error reading CIB image coverage

      An error has occurred while reading the coverage from the specified frame file.

    3. [cib2las-toc] Error reading RPF TOC file A.TOC locations

      An error has occurred while trying to read the locations section from the RPF header file. The locations section indicates the starting location and size of the remaining sections of the Table of Contents file.

    4. [cib2las-input] Error Specified samples exceed image size

      The combination of starting sample and number of samples specified exceeds the boundary of the CIB input image.

    5. [cib2las-input] Error Specified lines exceed image size

      The combination of starting line and number of lines specified exceeds the boundary of the CIB input image.

    6. [cib2las-input] Error Specified UL Lat > imput image UL Lat.

      The Upper left latitude of the output image must be < = the upper left corner of the input image.

    7. [cib2las-input] Error Specified UL Long < imput image UL Long.

      The Upper left longitude of the output image must be > = the upper left longitude of the input image.

    8. [cib2las-alloc] Error allocating dynamic memory

      An error has occurred while attempting to allocate dynamic memory. Contact you administrator if problem persists.

    9. [cib2las-open] Error opening output image lasout.img

      An error has occurred while trying to open the output image. Verify path and filename are correct.

    10. [cib2las-write] Error writing output image

      An error occurred while writing to the output image.

    11. [cib2las-size] Error writing output image, size wrong

      The output image size does not match the input image size as specified.

    12. [cib2las-fatal] Fatal Error mounting CD

      A fatal error occurred while mounting a remote CD.

    13. [cib2las-fatal] Error converting LAS output name to host output name

      An error occurred while converting the LAS output file name into a host filename.

    14. [cib2las-fatal] Fatal Error Reading TOC

      An error occurred while trying to read the Raster Product Format (RPF) Table of contents file (TOC) named A.TOC located in a subdirectory named RPF under the specified input directory INDIR. If an error occurs here verify you specified the correct input directory. It should have a sub- directory called "RPF" which will contain the TOC file with frame files contained in sub-directories beneath that.

    15. [cib2las-fatal] Error converting LAS INDIR to host INDIR

      A fatal error occurred while converting the LAS input directory to a host input directory.

    16. [cib2las-tae] Error fill value missing

      The fill value is missing. The fill value is used for empty frame files and transparent pixels. the default value is 0 (black) and the range is 0-255.

    17. [cib2las-tae] Error in < XX LLLLLLL> (< YYYY> ) LATITUDE/LONGITUDE

      The specified input coordinate exceeds its' limits. Latitude must be < = 90 degrees (+/-) and longitude must be < = 180 degrees (+/-). Re-enter correct value.

    18. [cib2las-locate] Error calculating frame file 008ZMU16.I11 location

      The images in the CIB database are divided into zones. Within each zone the are rows and columns of frame files. Each zone has a different number of rows and columns. The last six digits of the frame file name are the radix 34 value of the sequentional frame file number. Using this number and the number of rows and columns in the zone, the row and column number (of the specified frame file) can be determined. These row and column numbers are used to reassemble the image.

    19. [cib2las-cd] Error encountered mounting CD

      A fatal error occurred while attempting to mount the remote CD see previous above.

    20. [cib2las-hostname] Error reading the hostname

      An error occurred while trying to get hostname during remote CD mounting.

    21. [cib2las-read] Error opening frame file 008ZMU16.I11

      An error occurred while trying to read the specified frame file.

    22. [cib2las-read] Error locating RPF header A.TOC

      An error occurred while trying to read the header in the RPF table of contents file.

    23. [cib2las-read] Error finding [location] section of A.TOC

      An error occurred while trying to locate the [locations] section of the RPF TOC file.

    24. [cib2las-read] Error reading frame file coverage for 008ZMU16.I11

      An error occurred while trying to read the coverage section of the specified frame file. The coverage section is used to calculate the coverage of the entire image.

    25. [cib2las-exists] Error Output image < XXXX> already exists

      At least one file with the same name already exists in that directory. It may be an image file, a ddr file, a history file, or any combination. Reccommend moving existing file, renaming it, or changing output file name.

    26. [cib2las-input] SE Latitude 26.622600 must be < 22.658220

      When entering coordinates, the SE corner must be below and to the right of the Norht West corner. Need to re-enter the correct coordinates

    27. [cib2las-input] SE Longitude 103.251320 must be > 103.301012

      When entering coordinates, the SE corner must be below and to the right of the Norht West corner. Need to re-enter the correct coordinates

    28. [cib2las-input] Missing window specifications

      Some of the WINDOW specifications are missing. You must either leave all blank or specify four. They are the uppler left corner and lower right corner of the output image. If left blank, then the entire CIB image will be ingested.

    29. [cib2las-toc] Error moving file pointer in <xxxxx.xxx>

      An error occurred while performing an fseek (move file pointer) in the specified file.

    30. [cib2las-toc] Error reading from <xxxxx.xxx>

      An error occurred while reading from the specified file.

    31. [cib2las-coors] Error converting corner coordinates

      An error occurred while trying to convert the corner coordinates of the CIB image from degrees to meters.

    32. [cib2las-ddr] Error saving temporary DDR file <xxxxx.ddr>

      An error occurred while trying to create a temporary DDR for use in call to c_wndconv to caluclate portions of CIB image to output.

    33. [cib2las-window] No window

      This error will occur when the window specified by the window coordinates is completely outside of the input CIB image.

    34. [cib2las-toc] No frame files found

      An error occurred while trying to read the table of contents file. An error occurred causing an empty list to be returned.

    35. [cib2las-boundnumber] Error determining boundary rectangle numbering

      There was an error when attempting to determine the boundary rectangle numbering.

    36. [cib2las-boundnumber] Attempting to place multiple boundary rectangle references into same matrix location

      This error will occur when more than one boundary rectangle is calculated to be located at the same one degree square location within the boundary rectangle matrix when only a single boundary rectangle is used to describe each one degree square geographic area.

    37. [cib2las-boundnumber] Boundary rectangle position within matrix exceeds limit

      The calculated location for the boundary rectangle matrix exceeds the limits of the matrix.

    38. [cib2las-zone] Could not determine zone code from boundary rectangle

      When the user specifies the boundary rectangles to ingest, the most northwest boundary rectangle is used to determine the zone code. There was an error when attempting to retrieve the zone code for this region.

    Testing criteria:

    1. Test specifying CIB image with no windowing (default)
    2. Test specifying with windowing by specifiing SL SS NL NS
    3. Test specifying with windowing by specifying UL and LR Coordinates in degrees (Geographic coordinates)
    4. Test specifying with windowing by specifying UL and LR Coordinates in meters (Projection coordinates)
    5. Test image with transparent pixels and empty frame files
      Testing Notes:
      1. Use CIBtest.PDF to test code after changes
      2. Test files available and PDF above can be found in /DESING/test directory
      3. Information on expected outputs for expected test cases will be listed in test.txt