# Path: credits.py
# def fileVersion(program=None, year=False):
#     ver = '?'
#     ver_yr = '????'
#     if program == None:
#         check = sys.argv[0]
#     else:
#         s = program.rfind('.')
#         if s > 0 and program[s:] == '.html':
#             check = program
#         elif s < len(program) - 4:
#             check = program + sys.argv[0][sys.argv[0].rfind('.'):]
#         else:
#             check = program
#     if check[-3:] == '.py':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     elif check[-5:] == '.html':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     else:
#         if sys.platform == 'win32' or sys.platform == 'cygwin':
#             try:
#                 if check.find('\\') >= 0:  # if full path
#                     info = GetFileVersionInfo(check, '\\')
#                 else:
#                     info = GetFileVersionInfo(os.getcwd() + '\\' + check, '\\')
#                 ms = info['ProductVersionMS']
#               #  ls = info['FileVersionLS']
#                 ls = info['ProductVersionLS']
#                 ver = str(HIWORD(ms)) + '.' + str(LOWORD(ms)) + '.' + str(HIWORD(ls)) + '.' + str(LOWORD(ls))
#                 ver_yr = str(HIWORD(ls))
#             except:
#                 try:
#                     info = os.path.getmtime(os.getcwd() + '\\' + check)
#                     ver = '3.0.' + datetime.fromtimestamp(info).strftime('%Y.%m%d')
#                     ver_yr = datetime.fromtimestamp(info).strftime('%Y')
#                     if ver[9] == '0':
#                         ver = ver[:9] + ver[10:]
#                 except:
#                     pass
#     if year:
#         return ver_yr
#     else:
#         return ver


import datetime
import gzip
import os
import sys
import time
import displayobject
from netCDF4 import Dataset
from PyQt4 import QtCore, QtGui
from credits import fileVersion
        if not os.path.exists(inp_file):
            if inp_file.find('MERRA300') >= 0:
                inp_file = inp_file.replace('MERRA300', 'MERRA301')
            else:
                return
        if not os.path.exists(inp_file):
            return
        unzip_file = self.unZip(inp_file)
        if self.return_code != 0:
            return
        cdf_file = Dataset(unzip_file, 'r')
        i = unzip_file.rfind('/')
        self.log += '\nFile:\n    '
        self.log += unzip_file[i + 1:] + '\n'
        self.log += ' Format:\n    '
        try:
            self.log += str(cdf_file.Format) + '\n'
        except:
            self.log += '\n'
        self.log += ' Dimensions:\n    '
        vals = ''
        keys = list(cdf_file.dimensions.keys())
        values = list(cdf_file.dimensions.values())
        if type(cdf_file.dimensions) is dict:
            for i in range(len(keys)):
                vals += keys[i] + ': ' + str(values[i]) + ', '
        else:
            for i in range(len(keys)):
                bits = str(values[i]).strip().split(' ')
                vals += keys[i] + ': ' + bits[-1] + ', '

# Path: credits.py
# def fileVersion(program=None, year=False):
#     ver = '?'
#     ver_yr = '????'
#     if program == None:
#         check = sys.argv[0]
#     else:
#         s = program.rfind('.')
#         if s > 0 and program[s:] == '.html':
#             check = program
#         elif s < len(program) - 4:
#             check = program + sys.argv[0][sys.argv[0].rfind('.'):]
#         else:
#             check = program
#     if check[-3:] == '.py':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     elif check[-5:] == '.html':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     else:
#         if sys.platform == 'win32' or sys.platform == 'cygwin':
#             try:
#                 if check.find('\\') >= 0:  # if full path
#                     info = GetFileVersionInfo(check, '\\')
#                 else:
#                     info = GetFileVersionInfo(os.getcwd() + '\\' + check, '\\')
#                 ms = info['ProductVersionMS']
#               #  ls = info['FileVersionLS']
#                 ls = info['ProductVersionLS']
#                 ver = str(HIWORD(ms)) + '.' + str(LOWORD(ms)) + '.' + str(HIWORD(ls)) + '.' + str(LOWORD(ls))
#                 ver_yr = str(HIWORD(ls))
#             except:
#                 try:
#                     info = os.path.getmtime(os.getcwd() + '\\' + check)
#                     ver = '3.0.' + datetime.fromtimestamp(info).strftime('%Y.%m%d')
#                     ver_yr = datetime.fromtimestamp(info).strftime('%Y')
#                     if ver[9] == '0':
#                         ver = ver[:9] + ver[10:]
#                 except:
#                     pass
#     if year:
#         return ver_yr
#     else:
#         return ver


# Path: makerainfall2.py
import datetime
import gzip
import os
import sys
import time
import displayobject
from netCDF4 import Dataset
from PyQt4 import QtCore, QtGui
from credits import fileVersion

        if not os.path.exists(inp_file):
            if inp_file.find('MERRA300') >= 0:
                inp_file = inp_file.replace('MERRA300', 'MERRA301')
            else:
                return
        if not os.path.exists(inp_file):
            return
        unzip_file = self.unZip(inp_file)
        if self.return_code != 0:
            return
        cdf_file = Dataset(unzip_file, 'r')
        i = unzip_file.rfind('/')
        self.log += '\nFile:\n    '
        self.log += unzip_file[i + 1:] + '\n'
        self.log += ' Format:\n    '
        try:
            self.log += str(cdf_file.Format) + '\n'
        except:
            self.log += '\n'
        self.log += ' Dimensions:\n    '
        vals = ''
        keys = list(cdf_file.dimensions.keys())
        values = list(cdf_file.dimensions.values())
        if type(cdf_file.dimensions) is dict:
            for i in range(len(keys)):
                vals += keys[i] + ': ' + str(values[i]) + ', '
        else:
            for i in range(len(keys)):
                bits = str(values[i]).strip().split(' ')
                vals += keys[i] + ': ' + bits[-1] + ', '

        self.log += vals[:-2] + '\n'