CSV program Buffer getting full in GPS

guys its a CSV program but it works only once its buffer getting full after both string pls help here the code is

String str_data;
String SentenceIdentifier;
String Time;
String Latitude;
String DIR1;
String Longitude;
String DIR2;





void setup() {
    Serial.begin(9600);
    Serial.println("Enter GPS String");
                 

}
void loop() {
    while(Serial.available()>0){
              
              char c = Serial.read();
              str_data += c;
              if(c == '\r' || c == '\0')
              {
               int firstCommaIndex = str_data.indexOf(',');

               SentenceIdentifier = str_data.substring(1, firstCommaIndex);
               s = SentenceIdentifier.toInt();
               Serial.print("String Is = ");
               Serial.println(SentenceIdentifier);

               if (SentenceIdentifier == "GPGGA"){
                Serial.println(SentenceIdentifier);
               GPGGAparsing();
               }
               if(SentenceIdentifier == "GPRMC"){
                  Serial.println(SentenceIdentifier);
                GPRMCparsing();
     
                }
              // color();
               str_data = "";
              }
    }
    
}
//Parsing
void GPGGAparsing(){
  Serial.println("GPGGA accepted");
              int firstCommaIndex = str_data.indexOf(',');
              int secondCommaIndex = str_data.indexOf(',', firstCommaIndex+1);
              int thirdCommaIndex = str_data.indexOf(',', secondCommaIndex+1);
              int forthCommaIndex = str_data.indexOf(',', thirdCommaIndex+1);
              int fifthCommaIndex = str_data.indexOf(',', forthCommaIndex+1);
              int sixCommaIndex = str_data.indexOf(',', fifthCommaIndex+1);
              int sevenCommaIndex = str_data.indexOf(',', sixCommaIndex+1);
              int eightCommaIndex = str_data.indexOf(',', sevenCommaIndex+1);
              int nineCommaIndex = str_data.indexOf(',', eightCommaIndex+1);
              int tenCommaIndex = str_data.indexOf(',', nineCommaIndex+1);
              int elevenCommaIndex = str_data.indexOf(',', tenCommaIndex+1);
              int twelveCommaIndex = str_data.indexOf(',', elevenCommaIndex+1);
              int therteenCommaIndex = str_data.indexOf(',', twelveCommaIndex+1);
              int lastIndex = str_data.indexOf(',', therteenCommaIndex+1); 


                                                        
               SentenceIdentifier = str_data.substring(1, firstCommaIndex);
               Serial.print("Sentence Identifier = ");
               Serial.println(SentenceIdentifier);


               
               Time = str_data.substring(firstCommaIndex+1, secondCommaIndex);
               Serial.print("Time = ");
               Serial.println(Time);

               
               Latitude = str_data.substring(secondCommaIndex+1, thirdCommaIndex); 
                 DIR1  = str_data.substring(thirdCommaIndex+1,forthCommaIndex); 

               Serial.print("Latitude = ");
               Serial.println(Latitude+DIR1);
               
                 Longitude = str_data.substring(forthCommaIndex+1,fifthCommaIndex); 
                 DIR2  = str_data.substring(fifthCommaIndex+1,sixCommaIndex); 
               Serial.print("Longitude = ");
               Serial.println(Longitude+DIR2);

               
                String    FixQuality = str_data.substring(sixCommaIndex+1,sevenCommaIndex); 
               int fq = FixQuality.toInt();
               Serial.print("Fix Quality = ");
               Serial.println(fq);
              
                   String  NumberofSatellites = str_data.substring(sevenCommaIndex+1,eightCommaIndex);  
              int NoS = NumberofSatellites.toInt();
               Serial.print("NOS = ");
               Serial.println(NoS);
               
                 String    HorizontalDilutionofPrecision = str_data.substring(eightCommaIndex+1,nineCommaIndex );  
               Serial.print("Horizontal Dilution of Precision = ");
               Serial.println(HorizontalDilutionofPrecision);
               
               
                    String Altitude = str_data.substring(nineCommaIndex+1,tenCommaIndex );  
                    String unit = str_data.substring(tenCommaIndex+1,elevenCommaIndex );  
               Serial.print("Altitude = ");
               Serial.println(Altitude+unit);

               
                    String HeightofgeoidaboveWGS84ellipsoid = str_data.substring(elevenCommaIndex+1, twelveCommaIndex);  
                  String hu = str_data.substring(twelveCommaIndex+1,therteenCommaIndex );  

               Serial.print("Height of geoid above WGS84 ellipsoid = ");
               Serial.println(HeightofgeoidaboveWGS84ellipsoid+hu);
               
                 String  TimesincelastDGPS = str_data.substring(therteenCommaIndex+1,lastIndex);  
               
               
                          String    Checksum = str_data.substring(lastIndex+1); 
               Serial.print("Checksum = ");
               Serial.println(Checksum);
} 

void GPRMCparsing(){
  Serial.println("Gprmc accepted");
              int firstCommaIndex = str_data.indexOf(',');
              int secondCommaIndex = str_data.indexOf(',', firstCommaIndex+1);
              int thirdCommaIndex = str_data.indexOf(',', secondCommaIndex+1);
              int forthCommaIndex = str_data.indexOf(',', thirdCommaIndex+1);
              int fifthCommaIndex = str_data.indexOf(',', forthCommaIndex+1);
              int sixCommaIndex = str_data.indexOf(',', fifthCommaIndex+1);
              int sevenCommaIndex = str_data.indexOf(',', sixCommaIndex+1);
              int eightCommaIndex = str_data.indexOf(',', sevenCommaIndex+1);
              int nineCommaIndex = str_data.indexOf(',', eightCommaIndex+1);
              int tenCommaIndex = str_data.indexOf(',', nineCommaIndex+1);
              int elevenCommaIndex = str_data.indexOf(',', tenCommaIndex+1);
              int twelveCommaIndex = str_data.indexOf(',', elevenCommaIndex+1);


                                                        
               SentenceIdentifier = str_data.substring(1, firstCommaIndex);
               Serial.print("Sentence Identifier = ");
               Serial.println(SentenceIdentifier);


               
               Time = str_data.substring(firstCommaIndex+1, secondCommaIndex);
               Serial.print("Time = ");
               Serial.println(Time);

               String Valid = str_data.substring(secondCommaIndex+1, thirdCommaIndex);
               Serial.print("Time = ");
               Serial.println(Valid);
               
               Latitude = str_data.substring(thirdCommaIndex+1, forthCommaIndex); 
                 DIR1  = str_data.substring(forthCommaIndex+1,fifthCommaIndex); 

               Serial.print("Latitude = ");
               Serial.println(Latitude+DIR1);
               
                 Longitude = str_data.substring(fifthCommaIndex+1,sixCommaIndex); 
                 DIR2  = str_data.substring(sixCommaIndex+1,sevenCommaIndex); 
               Serial.print("Longitude = ");
               Serial.println(Longitude+DIR2);
        
               String speed = str_data.substring(sevenCommaIndex+1, eightCommaIndex);
               Serial.print("speed in knots = ");
               Serial.println(speed);
      
              String  course= str_data.substring(eightCommaIndex+1, nineCommaIndex);
               Serial.print("course = ");
               Serial.println(course);

               String date = str_data.substring(nineCommaIndex+1, tenCommaIndex);
               Serial.print("date= ");
               Serial.println(date);

             String  variation = str_data.substring(tenCommaIndex+1, elevenCommaIndex);
             String DIR3= str_data.substring(elevenCommaIndex+1, twelveCommaIndex);
               Serial.print("variation = ");
               Serial.println(variation+DIR3);               

               
                          String    Checksum = str_data.substring(twelveCommaIndex+1); 
               Serial.print("Checksum = ");
               Serial.println(Checksum);
}

Read till first comma, store. Read till next comma, store. Etc etc.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

sterretje ihave already done it

Robin2 it have 70% memory left and I have used char,double and many more but it shows errors for conversion it is a ready but buffer is getting full.

Laharsh:
Robin2 it have 70% memory left and I have used char,double and many more but it shows errors for conversion it is a ready but buffer is getting full.

I don't understand that comment as a response to what I wrote in Reply #2.

And I don't know what you mean by "buffer is getting full" - what buffer? How do you know it is getting full?

Have you tried my examples?

...R

it showing like this first
then,
when again I enter the gps string it just shows the sentence identifier which is in void loop

Laharsh:
it showing like this first
then,
when again I enter the gps string it just shows the sentence identifier which is in void loop

why aren't you using a library for this?

Laharsh:
sterretje ihave already done it

I thought that your problem is that you have to wait till the full message is received. Your code from the opening post does indeed do that; it reads the full message till '\r' or till '\0' (see below).

   if (c == '\r' || c == '\0')
    {
      ...
      ...

What I suggested is tat you read till a comma (not a '\r'), store it in the correct field, read till the next comma, store it in the correct field etc. You will have to keep track of the fields using a counter.

Laharsh:
Robin2 it have 70% memory left and I have used char,double and many more but it shows errors for conversion it is a ready but buffer is getting full.

The IDE reports use of static memory; it will not know about dynamic memory and the String class (capital S) uses dynamic memory allocation. Each time you add a character, it allocates new memory. If your received data is e.g. 100 characters long, you will have to subtract that from the 70% available memory.

What is the maximum length of your string?

I haven't specified the string length..

it shows like this when I re enter the string in below pic

You will have to define a maximum length for the simple reason that it will define how much memory you have to set aside (dynamically allocated or not) which in turn defines what type of Arduino to use. If your message is 1000 characters, e.g. an Uno might not be the correct choice if it has to do more than what you currently showed.