# Path: pygeons/mjd.py
# @_memoize
# def mjd(s,fmt):
#   ''' 
#   Converts a date string into Modified Julian Date (MJD)
#   
#   Parameters
#   ----------
#   s : string
#     Date string
# 
#   fmt : string
#     Format string indicating how to parse *s*
#       
#   Returns
#   -------
#   out : int
#     Modified Julian Date
# 
#   '''
#   d = datetime.strptime(s,fmt)
#   out = (d - _REFERENCE_DATETIME).days
#   return out


import numpy as np
import logging
from pygeons.mjd import mjd
  # split by delimiter
  lst = line.split(delim)
  # find the index containing field
  for i,j in enumerate(lst): 
    if field in j: 
      field_idx = i
      break

  # entry after the one containing field
  if (field_idx + 1) >= len(lst):
    raise ValueError(
      'No value associated with the field "%s". Make sure the '
      'correct delimiter is being used' % field)    

  out = lst[field_idx + 1]
  # remove white space
  out = out.strip()
  return out


def parse_csv(file_str):
  ''' 
  Reads data from a single PyGeoNS csv file
  '''
  fmt = '%Y-%m-%d'
  delim = ','

  def date_conv(date_str): 
    # return a float, rather than an integer, to be consistent with 
    # the other data types

# Path: pygeons/mjd.py
# @_memoize
# def mjd(s,fmt):
#   ''' 
#   Converts a date string into Modified Julian Date (MJD)
#   
#   Parameters
#   ----------
#   s : string
#     Date string
# 
#   fmt : string
#     Format string indicating how to parse *s*
#       
#   Returns
#   -------
#   out : int
#     Modified Julian Date
# 
#   '''
#   d = datetime.strptime(s,fmt)
#   out = (d - _REFERENCE_DATETIME).days
#   return out


# Path: pygeons/io/parser.py
import numpy as np
import logging
from pygeons.mjd import mjd

  # split by delimiter
  lst = line.split(delim)
  # find the index containing field
  for i,j in enumerate(lst): 
    if field in j: 
      field_idx = i
      break

  # entry after the one containing field
  if (field_idx + 1) >= len(lst):
    raise ValueError(
      'No value associated with the field "%s". Make sure the '
      'correct delimiter is being used' % field)    

  out = lst[field_idx + 1]
  # remove white space
  out = out.strip()
  return out


def parse_csv(file_str):
  ''' 
  Reads data from a single PyGeoNS csv file
  '''
  fmt = '%Y-%m-%d'
  delim = ','

  def date_conv(date_str): 
    # return a float, rather than an integer, to be consistent with 
    # the other data types

    return float(mjd(date_str,fmt))