# Path: postproclib/postproc.py
# class PostProc:
# 
#     def __str__(self):
#         string =  ('\nAvailable outputs in ' + self.resultsdir + ' include:\n\n')
#         string += ('\t{0:^24s}\t{1:>10s}\n'.format('field', 'records'))
#         #string += ('\t{0:^24s}\t{1:^10s}\n'.format('-'*24, '-'*10))
#         for key,field in sorted(self.plotlist.items()):
#             line = '\t{0:<24s}=\t{1:>10f},\n'.format(key, field.maxrec)
#             string += line
#         return string 
# 
# Path: postproclib/pplexceptions.py
# class NoResultsInDir(Exception):
#     pass


import numpy as np
import os
import struct
import glob
    import matplotlib.pyplot as plt
from scipy.io import FortranFile
from .headerdata import *
from .postproc import PostProc
from .pplexceptions import NoResultsInDir
    from mpl_toolkits import mplot3d
        elif "vmd_out" in fname:
            self.fname = self.check_files(fout="vmd_out.dcd", ftmp="IGNOREFILE")
        else:
            raise IOError("fname", fname, " is not recognised in VMDReader") 

    def read_header(self, headername="/simulation_header"):

        #Load number of molecules data
        fname = self.fdir + headername
        with open(fname,"r") as f:
            for l in f:
                if "globalnp" in l:
                    n = int(l.split(";")[2])
                    break

        return n

    def check_files(self, dsize=4, ftmp="vmd_temp.dcd", fout="vmd_out.dcd"):

        #Check which MD files are available
        ftmp = self.fdir + "/" + ftmp#"/vmd_temp.dcd"
        fout = self.fdir + "/" + fout#"/vmd_out.dcd"
        #If both, check if temp is newer
        self.use_temp=False

        print(ftmp, fout, os.path.exists(ftmp), os.path.exists(fout))
        if (os.path.exists(ftmp) and os.path.exists(fout)):
            if (os.path.getmtime(ftmp) > os.path.getmtime(fout)):
                self.use_temp=True
        elif (os.path.exists(ftmp)):

# Path: postproclib/postproc.py
# class PostProc:
# 
#     def __str__(self):
#         string =  ('\nAvailable outputs in ' + self.resultsdir + ' include:\n\n')
#         string += ('\t{0:^24s}\t{1:>10s}\n'.format('field', 'records'))
#         #string += ('\t{0:^24s}\t{1:^10s}\n'.format('-'*24, '-'*10))
#         for key,field in sorted(self.plotlist.items()):
#             line = '\t{0:<24s}=\t{1:>10f},\n'.format(key, field.maxrec)
#             string += line
#         return string 
# 
# Path: postproclib/pplexceptions.py
# class NoResultsInDir(Exception):
#     pass


# Path: postproclib/mdmols.py
import numpy as np
import os
import struct
import glob
    import matplotlib.pyplot as plt
from scipy.io import FortranFile
from .headerdata import *
from .postproc import PostProc
from .pplexceptions import NoResultsInDir
    from mpl_toolkits import mplot3d

        elif "vmd_out" in fname:
            self.fname = self.check_files(fout="vmd_out.dcd", ftmp="IGNOREFILE")
        else:
            raise IOError("fname", fname, " is not recognised in VMDReader") 

    def read_header(self, headername="/simulation_header"):

        #Load number of molecules data
        fname = self.fdir + headername
        with open(fname,"r") as f:
            for l in f:
                if "globalnp" in l:
                    n = int(l.split(";")[2])
                    break

        return n

    def check_files(self, dsize=4, ftmp="vmd_temp.dcd", fout="vmd_out.dcd"):

        #Check which MD files are available
        ftmp = self.fdir + "/" + ftmp#"/vmd_temp.dcd"
        fout = self.fdir + "/" + fout#"/vmd_out.dcd"
        #If both, check if temp is newer
        self.use_temp=False

        print(ftmp, fout, os.path.exists(ftmp), os.path.exists(fout))
        if (os.path.exists(ftmp) and os.path.exists(fout)):
            if (os.path.getmtime(ftmp) > os.path.getmtime(fout)):
                self.use_temp=True
        elif (os.path.exists(ftmp)):

            self.use_temp=True