by car from barcelona ,you should make it in 6H and from Madrid in 7H30, about depending on your driving and its a great trip over the pyrénées!!! i highly recommended at least once in your life; this is to Lourdes.
as per trains
the central station in Barcelona to France is at estacion de Francia,near parc de la ciudatela OR the new station at Sants closer to center city. you go to Paris at gare d'Austerlitz same as from Madrid(out of madrid is chamartin).At
www.renfe.es ou
www.voyages-sncf.com (click on GB flag for english or Spain for spanish,lower part of screen left)
to go to lourdes from spain you would have to change trains again at narbonne, then toulouse then arrive at lourdes, too long. Car is better from spain or take the train to paris and go paris-lourdes!another long trip.