function writeattributes(file, p::Parameters)
    attrs(file)["Integrator"] = p.integrator.name
    attrs(file)["Thermostat"] = p.thermo.name
    attrs(file)["Potential"] = p.potential.name
    attrs(file)["nsteps"] = p.nsteps
    attrs(file)["dtsampling"] = p.dtsampling
    attrs(file)["dtintegration"] = p.dt
    attrs(file)["Q"] = p.Q
    attrs(file)["T"] = p.T
    attrs(file)["nsimulations"] = p.nsimulations
end

"""
A .hdf5 file is generated where the lyapunov spectrum for each initial condition (nsimulations = number of initial conditions) is saved.
"""
function lyapunov_exponents(p::Parameters)
    
    data = Matrix{Float64}(p.nsimulations,6)
    
    for i in 1:p.nsimulations
        data[i,:] = lyapunov_simulation(p)
        #println("Simulation$i done")
    end

    return data
end


"""
    A long trajectory is generated by parts (coincident with nsimulations) and saved in an .hdf5  file 
"""
function trajectory(p::Parameters)


    beta = 1./p.T
    r0 = initialcondition(beta, p.Q)
    tx = trajectory_simulation(p, r0)
    r0 = tx[end,:][2:end]
    println("Part 1 done. ")

    for i in 2:p.nsimulations
        traj = trajectory_simulation(p, r0)
        traj = traj[2:end,:]
        traj[:,1] += (i-1)*p.nsteps*p.dt
        tx = vcat(tx, traj)
        r0 = traj[end,:][2:end]
        println("Part $i done.")
    end

    return tx
end


"""
Creates the file "filename".hdf5 with attributes associated to the passed parameters and
whose dataset is the Matrix generated by the function lyapunov_exponents
"""
function save_lyapunov(filename::String, data::Matrix{Float64}, p::Parameters)
    try
        mkdir("../data")
    end

    file = h5open("../data/filename.hdf5", "w")
    writeattributes(file,p)
   
    file["data"] = data
    close(file)

    println("The file $filename.hdf5 was saved in the folder `../data/`")
end


"""
Creates the file "filename".hdf5 with attributes associated to the passed parameters and
whose dataset is the Matrix generated by the function lyapunov_exponents
"""
function save_trajectory(filename::String, data::Matrix{Float64}, p::Parameters)
    try
        mkdir("../data")
    end

    file = h5open("../data/filename.hdf5", "w")
    writeattributes(file,p)
   
    file["data"] = data
    close(file)

    println("The file $filename.hdf5 was saved in the folder `../data/`")

end




