Some observations:
1) Seville & Cordoba in August will be hot hot hot! (Possibly +40ºC between 11:00 and 17.00) You will be hard pushed to do much therefore in two days. If time is a constraint I would recommend scratching Cordoba and spend two days in Seville.
2) Day 12 Tarifa - Lagos is going to be a very long day, you will have to route via Seville as previously explained:
Timetable for coaches between Tarifa and Seville can be found here:
http://www.tgcomes.es/horarios_33_english.htm
The bus at 08:00 arriving Seville at 11:00.
There is a DAMAS/EVA bus to Lagos at 13:30 arriving 16:40.
See Cubsur's excellent site here
Note that this routing by coach is really the only feasible way of travelling by public transport from Gib/Tarifa/Cadiz to the Algarve/Lagos.
There is no train connection between Seville and Portugal/Algarve and the only flights between Mainland Spain and Portugal is the Ryanair Faro to Madrid Flight 4 days a week.
There are no direct flights between Faro International Airport (Airport for the Algarve - situated 70kms from Lagos) and Faro. TAP/Air Portugal offer a service but it routes via Lisbon and is a pain owing to frequent delays and cancellations.
A much better way to visit Porto would be to catch the early train from Lagos which connects with the Alfa-Pendular Express from Faro and arrives Porto at 12:44.
If you go to my blog at:
http://barlaventostravelblog.blogspot.com
scroll down on the right till you get to the panel entitled:
>>Algarve & Portugal - Travel Transport Links
You will find a link entitled:
Porto - Lisbon - Porto Train Timetable.
Click and you will download a timetable for the Alfa Pendular Service including the service from Faro.
You can also find in the same panel a link to the Algarve line train timetable.
A final thought now I have come to think about it!
Spanish airline ClickAir operates Barcelona - Tangier although costs of flights in August are expensive. Early August - + Euro 300. Mid August onwards circa Euro 170.00 & taxes. However, if you are already flying to Seville.....
So you could fly Barcelona - Tangier direct spend your few days in souks seeing the carpet salesmen and then take the ferry to Tarifa.
Then take the bus to Seville.
Spend a couple of days in Seville and maybe Cordoba and then go Lagos.
A further option is the above flights are to expensive is to fly Barcelona to the airport at Jerez la Frontera near Cadiz and then get a bus teh last 130km from there to Tarifa. Spanish low costs SPANAIR, CLICKAIR, S.A. and VUELING AIRLINES appear to operate this route according to AENA the Spanish airports authority.
Then ferry over to Morocco and then do Seville on your way back.