#!/usr/bin/python

###loading shell commands
import os, os.path, sys, shutil
from scipy.fftpack import fftn
# from PyQt4.QtGui import *
import struct
import numpy as np
import math
from test import *
from spaceAnalysisOnly import *
#import sys
import textwrap
import argparse
# ... do something with args.output ...
    # ... do something with args.verbose ..
#from evtk.hl import gridToVTK

def run(args):
    myxmin=args.myxmin
    myxmax=args.myxmax
    myymin=args.myymin
    myymax=args.myymax
    mycomp=args.mycomp
    print str(args)
    #print 'Number of arguments:', len(sys.argv), 'arguments.'
    #print 'Argument List:', str(sys.argv)

    myname = args.myname
    myanalysis = FieldAnalysis(filename=myname)
    myanalysis.do_fft(zposition=0, comp=mycomp)
    grande=40
    piccolo=0
    myanalysis.saveffttxt(varname=myname, kxmin=-1*grande, kxmax=0, kymin=-1.*piccolo, kymax=grande)

    myanalysis.createCone(nmax=40,phimin=40, phimax=50, nbin=400)
    myanalysis.analiseConeAndPrint(varname=myname, kxmin=-1*grande, kxmax=0, kymin=-1.*piccolo, kymax=grande)
    myanalysis.printConeAnalysis(varname=myname)

    myanalysis.createCone(nmax=40,phimin=42.5, phimax=47.5, nbin=400)
    myanalysis.analiseConeAndPrint(varname=myname, kxmin=-1*grande, kxmax=0, kymin=-1.*piccolo, kymax=grande)
    myanalysis.printConeAnalysis(varname=myname)

    myanalysis.createCone(nmax=40,phimin=44, phimax=46, nbin=400)
    myanalysis.analiseConeAndPrint(varname=myname, kxmin=-1*grande, kxmax=0, kymin=-1.*piccolo, kymax=grande)
    myanalysis.printConeAnalysis(varname=myname)



parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
        description=textwrap.dedent('''\
        FFT of my files
        --------------------------------
        loop on components (0:x 1:y 2:z)

        '''))
parser.add_argument('-i', type=str, dest='myname', required=True,
                    help='filename of the file to be analised')
parser.add_argument('-xmin', type=float, dest='myxmin', default=-1e5,
                    help='xmin of the box to be analysed')
parser.add_argument('-xmax', type=float, dest='myxmax', default=1e5,
                    help='xmax of the box to be analysed')
parser.add_argument('-ymin', type=float, dest='myymin', default=-1e5,
                    help='ymin of the box to be analysed')
parser.add_argument('-ymax', type=float, dest='myymax', default=1e5,
                    help='ymax of the box to be analysed')
parser.add_argument('-comp', type=int, dest='mycomp', required=True, help='component to analize')
args = parser.parse_args()
run(args)
