package org.mbari.seepsearch.tools;

import java.io.File;

 /**
 * <p>Component that can be used to create a copy location for placing modified
 * data. This is useful to avoid overwritting existing data files while
 * maintaining the directory structure.</p>
 *
 * <p>The Seep Search project is a sub-project of the Continental
 * Margin Fluids and Gases project (200010). It involves the analysis of
 * archived ROV data to obtain understanding of seep distritution in Monterey
 * Bay.</p>
 *
 * <p>The Purpose of this Java package is to intercompare ROV Navigation files,
 * VIMS data on seep community observations and the EM-300 bathymetry. We are
 * looking for locations where the ROV navigation files and the EM-300 data
 * have similar depths between the 2 data sets, which implies that the ROV is
 * observing the sea floor.</p><hr><br>
 *
 * <p>MBARI provides this documentation and code &quot;as is&quot;, with no
 * warranty, express or implied, of its quality or consistency. It is provided
 * without support and without obligation on the part of the Monterey Bay
 * Aquarium Research Institute to assist in its use, correction, modification,
 * or enhancement. This information should not be published or distributed to
 * third parties without specific written permission from MBARI.</p><br>
 *
 * Copyright 2002 MBARI.<br>
 * MBARI Proprietary Information. All rights reserved.<br><hr><br>
 *
 * $Log: RovNavFileOutputComponent.java,v $
 * Revision 1.4  2002/08/30 21:45:31  brian
 * Minor modifications
 *
 * Revision 1.3  2002/02/25 16:40:09  brian
 * Modified tools to ignore eastings and northings columns.
 *
 * Revision 1.2  2002/02/09 00:07:19  brian
 * Working tools to calculate ROV altitude. There's a glitch that occurs for a few files. Need to look into this
 *<br><hr><br>
 *
 * @author  : $Author: brian $
 * @version : $Revision: 1.4 $
 */
public class RovNavFileOutputComponent extends RovNavFileProcess {

    /**
     * Constructor
     * @param rovDataPath The location on the input files
     */
    public RovNavFileOutputComponent(String rovDataPath) {
        super(rovDataPath);
    }


    /**
     * Checks to see that the output directory tree matches that of the input
     * tree. If it doesn't it creates one.
     * @param navFile
     */
    public void internalProcess(File navFile) {
        /**@todo: implement this org.mbari.seepsearch.tools.RovNavFileAccessor abstract method*/
        /** @todo This method should make sure that a directory tree is created in the
         *  appropriate location */
         File outputFile = getOutputFile(navFile);
         File parent = outputFile.getParentFile();
         if (!parent.exists()) {
            boolean OK = parent.mkdirs();
            if (!OK) {
                System.err.println("Unable to create " + parent.getAbsolutePath());
            }
         }
    }

    /**
     * Provides the output location, based on the output path, to write too that
     * coresponds to the input file.
     * @param inputFile The input file that we don't want overwritten
     * @return The approrpiate output location to write files to. null is
     * returned if the input or output locations do not exist or can not be accessed
     * to restricted permissions.
     */
    public File getOutputFile(File inputFile) {
        File outputFile = null;
        if ((inputFile.exists()) || (inputFile.canRead())) {
            // Check to see if output directory exists
            String absolutePath = inputFile.getAbsolutePath();
            int i = absolutePath.indexOf(rovDataPath) + rovDataPath.length();
            String pathRelativeToRoot = absolutePath.substring(i);
            outputFile = new File(outputPath, pathRelativeToRoot);
        }
        return outputFile;
    }

    /**
     * Sets the root of the output path. A subtree of directories that matches
     * the input path is created.
     * @param outputPath
     */
    public void setOutputPath(String outputPath) {
        this.outputPath = outputPath;
    }

    /**
     * Returns the root of the output path.
     * @return
     */
    public String getOutputPath() {
        return outputPath;
    }




    private String outputPath;

}