#!/usr/bin/env python
""""
European XFEL HDF5 files exploration tool

Usage: euxfel_h5tool.py [-shvi] PATH

-h, --help         Show this screen.
-v, --version      Show version.
-s, --structure    Display structure of file
-i, --info         Display summary info of file


"""

import logging
import sys

import docopt
import h5py
import matplotlib.pyplot as plt
import numpy as np

import euxfel_h5tools

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)



if __name__ == "__main__":

    arguments = docopt.docopt(__doc__, version=0.9)
    logging.debug("arguments = {}".format(arguments))

    filename = arguments['PATH']

    if arguments['--structure'] == True:
            # Only works with one file at the moment
            print("Overview of structure")
            f = h5py.File(filename, 'r')
            euxfel_h5tools.rec_print_h5_level(f, maxlen=3)

    if arguments['--info'] == True:
        euxfel_h5tools.stat([filename])

@@ -18,18 +18,16 @@
 thon%0A%22%22%22
-%22%0A
 European
@@ -67,16 +67,18 @@
 %0A%0AUsage:
+%0A 
  euxfel_
@@ -92,21 +92,151 @@
 py %5B
--shvi%5D PATH%0A%0A
+options%5D PATH ...%0A  euxfel_h5tool.py --help      # use to display options%0A  euxfel_h5tool.py --h         # use to display options%0A%0AOptions:%0A%0A  
 -h, 
@@ -268,16 +268,18 @@
 screen.%0A
+  
 -v, --ve
@@ -303,16 +303,18 @@
 ersion.%0A
+  
 -s, --st
@@ -350,16 +350,18 @@
 of file%0A
+  
 -i, --in
@@ -401,16 +401,316 @@
 f file%0A%0A
+Details:%0A%0A  PATH is meant to point to a directory of files, or a list of files,%0A  or a single FILE.%0A%0A  Some options will only work for a single file. Some will iterate%0A  over a list of files if given multiple files.%0A%0A  Others will make sense of a directory full of files belonging to the%0A  same run.%0A
 %0A%22%22%22%0A%0Aim
@@ -733,10 +733,9 @@
 ort 
-sy
+o
 s%0A%0Ai
@@ -762,59 +762,8 @@
 h5py
-%0Aimport matplotlib.pyplot as plt%0Aimport numpy as np
 %0A%0Aim
@@ -861,16 +861,64 @@
 DEBUG)%0A%0A
+# get version from external file?%0Aversion = 0.1%0A
 %0A%0Aif __n
@@ -990,11 +990,15 @@
 ion=
-0.9
+version
 )%0A  
@@ -1058,173 +1058,692 @@
     
-filename = arguments%5B'PATH'%5D%0A%0A    if arguments%5B'--structure'%5D == True:%0A            # Only works with one file at the moment%0A            print(%22Overview of structure%22
+path = arguments%5B'PATH'%5D%0A    if len(path) == 1:   # could be file or directory%0A%0A        if os.path.isdir(path):%0A            # if PATH is directory, read list of files, TODO%0A            filenames = os.path.listdir(path)%0A    else:%0A        # assume that all arguments are files%0A        filenames = arguments%5B'PATH'%5D%0A        for filename in filenames:%0A            assert os.path.isfile(filename)%0A%0A    # Iterate over files for options that process single files%0A    if arguments%5B'--structure'%5D == True:%0A            # Only works with one file at the moment%0A%0A            for filename in filenames:%0A                print(%22-%22*70)%0A                print(%22Structure for file '%7B%7D'%22.format(filename)
 )%0A  
@@ -1756,11 +1756,16 @@
     
-f =
+    with
  h5p
@@ -1785,17 +1785,31 @@
 me, 'r')
-%0A
+ as f:%0A        
         
@@ -1928,16 +1928,15 @@
 tat(
-%5B
 filename
 %5D)%0A
@@ -1932,11 +1932,11 @@
 filename
-%5D
+s
 )%0A

Tidy up command line interface (to be continued)