Saving AT Command to SD Card

I hope someone could help me on saving the received text from the gsm to sd card. I have an attached file of my code.

thesistrial_v2_receive_sd.ino (1.93 KB)

Dumping a data stream from a serial source is as simple as:

// Open the file for writting first

byte data;

while (Serial.available()) 
{
  data = Serial.read();
  dataFile.write(data);
  mySerial.write(data);//Forward what Serial received to Software Serial Port
}
while(mySerial.available()) 
{
  data = mySerial.read();
  dataFile.write(data);
  Serial.write(data);//Forward what Software Serial received to Serial Port
}

This way data streams from both directions are logged and still correctly piped to each port.