#Dictionary of dictionaries
Grid_frame =  ({k : Series(v) for k, v in Grid_Values.iteritems()})

#Trick to create a frame with different lengths
# Grid_frame = DataFrame({k : Series(v) for k, v in Grid_Values.iteritems()})

#Generate the scripts with the lines we want to print the flux
ct.lines_to_extract(ScriptFolder)

#Fore the each grid point run a cloudy simulation
Model_dict = OrderedDict()
for age in Grid_Values['age']:
    for zStar in Grid_Values['zStars']:
        for zGas in Grid_Values['zGas']:                                        
            for ionization_parameter in Grid_Values['u']: 
                
                Model_dict['Name']      = 'S_Ar_Test_' + 'age'+ age + '_zStar' + zStar + '_zGas' + zGas + '_u' + ionization_parameter
                Model_dict['age']       = age
                Model_dict['zStars']    = zStar
                Model_dict['zGas']      = zGas
                Model_dict['u']         = ionization_parameter
    
                ScriptName              = Model_dict['Name'] + '.in'
    
                #Generate the script
                ct.popstar_S_Ar_Grid_Hbeta(ScriptFolder, Model_dict)
                  
                #Run the cloudy script
                ct.run_script(ScriptName, ScriptFolder)
  
print 'Data treated'
    for zStar in Grid_Values['zStars']:
        for zGas in Grid_Values['zGas']:
            for ionization_parameter in Grid_Values['u']:

                Model_dict[
                    'Name'] = 'S_Ar_Test_' + 'age' + age + '_zStar' + zStar + '_zGas' + zGas + '_u' + ionization_parameter
                Model_dict['age'] = age
                Model_dict['zStars'] = zStar
                Model_dict['zGas'] = zGas
                Model_dict['u'] = ionization_parameter

                Model_dict['abundances_command'] = 'abundances H=0.0 He=-1.0'
                for key in Solar_abundances:
                    Model_dict[
                        'abundances_command'] = '{previous_line} {new_element}={abundance}'.format(
                            previous_line=Model_dict['abundances_command'],
                            new_element=key,
                            abundance=round(
                                Solar_abundances[key] + nplog10(float(zGas)),
                                3))

                ScriptName = Model_dict['Name'] + '.in'

                #Generate the script
                ct.popstar_S_Ar_Grid(ScriptFolder, Model_dict)
                #                 ct.popstar_S_Ar_Grid_absAbundances(ScriptFolder, Model_dict)

                #Run the cloudy script
                ct.run_script(ScriptName, ScriptFolder)

print 'Data treated'