#!/usr/bin/env python3
#------------------------------------------------------------------------------
#    The MB-system:  mbm_phins2fnv   27 June 2023
#
#    Copyright (c) 2025-2025 by
#    David W. Caress (caress@mbari.org)
#      Monterey Bay Aquarium Research Institute
#      Moss Landing, California, USA
#    Dale N. Chayes 
#      Center for Coastal and Ocean Mapping
#      University of New Hampshire
#      Durham, New Hampshire, USA
#    Christian dos Santos Ferreira
#      MARUM
#      University of Bremen
#      Bremen Germany
#      
#    MB-System was created by Caress and Chayes in 1992 at the
#      Lamont-Doherty Earth Observatory
#      Columbia University
#      Palisades, NY 10964
#
#    See README.md file for copying and redistribution conditions.
#------------------------------------------------------------------------------
# Translate processed Phins INS data to an fnv file for use in MB-System processing
#
# David W. Caress
# 3 March 2024
#------------------------------------------------------------------------------

import sys
import getopt
import pandas as pd

shortOpts = "hi:o:v"
longOpts = ["help", "input=", "output=", "verbose"]

def usage():
  pname, sname = os.path.split(sys.argv[0])
  sys.stderr.write("usage: % s %s < path > \n" % (sname, str(longOpts)))
  print( """
  -h --help                    Print this message
  -i --input=file              Path to input file
  -o --output=file             Path to output file
  -v --verbose                 Verbose output to shell
  """ )
  sys.exit()

def main (args, opts={}):

  # Handle command line options
  inputfile = ""
  inputset = False
  outputfile = ""
  outputset = False
  verbose = False
  for o, a in opts:
    if o in ("-h", "--help"):
      usage()
    elif o in ("-i", "--input"):
      inputfile = a
      inputset = True
    elif o in ("-o", "--output"):
      outputfile = a
      outputset = True
    elif o in ("-v", "--verbose"):
      verbose = True
    else:
      assert False, "unhandled option: "+o+" "+a

  # If inputfile not set then quit
  if not inputset :
    print ("Input file not set\nMacro mbm_phins2fnv exiting...")
    sys.exit()

  # If inputfile not set then quit
  if not outputset :
    print ("Output file not set\nMacro mbm_phins2fnv exiting...")
    sys.exit()

  # Read the input data
  data = pd.read_csv(inputfile , sep='\\s+', comment='#')
  print(data)
  
  # loop over all rows outputting the desired columns
  

if __name__ == "__main__":
  # Parse command line arguments
  try:
      opts, args = getopt.gnu_getopt(sys.argv[1:], shortOpts, longOpts)
  except getopt.GetoptError as err:
      # print help information and exit:
      print (str(err)) # will print something like "option -a not recognized"
      usage()

  # Run main script
  main (args,opts)

