Serial output of multiple NMEA inputs

Hi, im new with programming and arduino, recently I'm working to combine 3 transducers which are connected to MAX232 to Arduino Mega 2560's serials without using NMEA multiplexer:-

Serial1 - Heading sensor
NMEA output e.g. : $HCHDT,
Serial2 - Eco Sounder sensor
NMEA output : $SDDPT,$SDDBT,$SDMTW,
Serial3 - GPS
NMEA output e.g. : $GPRMB,$GPGGA,$GPGSV,$GPGLL,$GPBOD,$PGRME,$PGRMZ,$GPRTE,

From serial1, it is parsed to Hxxx.x from $HCHDT
From serial2, it is parsed to Dxxx.x from $SDDPT
From serial3, it is parsed to LTxxxx.xxLGxxxxx.xx

I wish to show it in serial like this, Hxxx.xDxxx.xLTxxxx.xxLGxxxxx.xx
but it just show this instead:

D003.6H029.2H029.2D003.6LTLG
H029.2D003.6H029.2LTLG
D003.6H029.2H029.2D003.0LTLG
H029.2D003.0H029.2LTLG
H029.2D003.0H029.2LTLG
D003.0H029.2H029.2LTLG
H029.2D003.8H029.2LTLG
D003.5H029.2D003.5H029.2LTLG
D003.5H029.2H029.2LTLG
D003.5H029.2D003.5H029.2LTLG
D003.5H029.2H029.2LTLG
D002.8H029.2D002.8H029.2LTLG
H029.2D002.8H029.2LTLG
D002.8H029.2H029.2LTLG
H030.1D004.0H031.6LTLG
D003.6H031.7D003.6H032.0LTLG
H032.3D003.6H032.5LTLG
D003.6H033.4D003.6H033.5LTLG
H033.5D003.6H033.9LTLG
D003.0H034.1D003.0H034.2LTLG
H034.2D003.0H034.2LTLG
D003.0H034.2H034.2LTLG
H034.2D003.8H034.2LTLG
D003.5H034.2D003.5H034.2LTLG
H034.2D003.5H034.6LTLG
D003.5H035.8D003.5H035.9

Question is, is there any way to slow down heading output.. And it will only show the output when parsed value from sensors exist?

Codes:
void setup()

//INDICATOR
int ledPin = 13;

//VARIABLES
int byteCompass = -1;
int byteGPS = -1;
int byteEcho = -1;
char compass[40];
char echo[80];
char gps[200];
char HdrComp[5] = "HDT";
char HdrGPS[5] = "RMC";
char HdrEcho[5] = "DPT";
char StrC[10] = "";
char StrG[10] = "";
char StrG2[10] = "";
char StrE[10] = "";

//COUNTERS
int countaa = 0;
int checka = 0;
int counta = 0;
int countbb = 0;
int checkb = 0;
int countb = 0;
int countcc = 0;
int checkc = 0;
int countc = 0;
int serialflag = 0;

//VERIFIER
int indexCompass[10];
int indexGPS[50];
int indexEcho[10];

void loop()

void loop()
{
  
  digitalWrite(ledPin, HIGH);
  byteCompass = Serial1.read();
  byteEcho = Serial2.read();
  byteGPS = Serial3.read();
  //Serial.write(byteEcho); //Checkpoint 1 <-- CHECK IF SUCCESSFULLY TRANSFORM TO INT 
  
  // THIS SECTION IS FOR COMPASS ------------------------------------------------>
  int x = 0;
  if (byteCompass > 0)
  {     
    compass[countaa] = byteCompass;
    //Serial.print(compass[countaa]); //Checkpoint 2 <-- CHECK IF SUCCESSFULLY TRANSFORM TO CHAR ARRAY 
    countaa++;
    if (byteCompass==36) //Check if $ appear
    {
      digitalWrite(ledPin, LOW);
      countaa = 1;
      checka=0;
      counta=0;
      for (int d=3;d<6;d++)
      {
        //Serial.print(d); //Checkpoint 3 <-- CHECK IF DEFINED HEADER IS SAME AS INPUT HEADER
        //Serial.print("  compass = "); //DEBUG PURPOSE
        //Serial.print(compass[d]); //DEBUG PURPOSE
        //Serial.print("   HdrComp = "); //DEBUG PURPOSE
        //Serial.println(HdrComp[d-3]); //DEBUG PURPOSE
        if (compass[d]==HdrComp[d-3]) 
        {
          checka++; //set flag
          //Serial.println(checka); //Checkpoint 4 <-- CHECK FLAG VALUE IF FOR EACH CORRECTED HEADER
        }   
      }
      if (checka==3) 
      {
        //check position of , and *
        for (int e;e<strlen(compass);e++) 
        {
          if (compass[e]==',') 
          {
            indexCompass[counta]=e;
            counta++;
          }
          if (compass[e]=='*')
          {
            indexCompass[8]=e;
            counta++;
          }
        }
        strncpy(StrC,compass+indexCompass[0]+1,indexCompass[1]-indexCompass[0]-1); //copy between , , 
        //Serial.println(StrC); //Checkpoint 5 <-- CHECK COPIED VALUE  
        //rearrange in H format      
        for(int f=5;f>=0;f--)
        {
          StrC[f] = StrC[f-1];
        }
        StrC[0] = 'H';        
        Serial.print(StrC);        
        digitalWrite(ledPin, HIGH);
      }  
    }    
  }
  
  // THIS SECTION IS FOR ECHO SOUNDER ------------------------------------------------>
  if (byteEcho > 0)
  {     
    echo[countbb] = byteEcho;
    //Serial.print(echo[countbb]); //Checkpoint 2 <-- CHECK IF SUCCESSFULLY TRANSFORM TO CHAR ARRAY 
    countbb++;
    if (byteEcho==36)
    {
      digitalWrite(ledPin, LOW);
      countbb = 1;
      checkb=0;
      countb=0;
      for (int d=3;d<6;d++)
      {
        //Serial.print(d); //Checkpoint 3 <-- CHECK IF DEFINED HEADER IS SAME AS INPUT HEADER
        //Serial.print("  echo = "); //DEBUG PURPOSE
        //Serial.print(echo[d]); //DEBUG PURPOSE
        //Serial.print("   HdrEcho = "); //DEBUG PURPOSE
        //Serial.println(HdrEcho[d-3]); //DEBUG PURPOSE
        if (echo[d]==HdrEcho[d-3]) 
        {
          checkb++; 
          //Serial.println(checkb); //Checkpoint 4 <-- CHECK FLAG VALUE IF FOR EACH CORRECTED HEADER
        }   
      }
      if (checkb==3)
      {
        for (int e;e<strlen(echo);e++)
        {
          if (echo[e]==',')
          {
            indexEcho[countb]=e;
            countb++;
          }
          if (echo[e]=='*')
          {
            indexEcho[8]=e;
            countb++;
          }
        }
        strncpy(StrE,echo+indexEcho[0]+1,indexEcho[1]-indexEcho[0]-1);
        //Serial.println(StrE); //Checkpoint 5 <-- CHECK COPIED VALUE        
        for(int f=5;f>=0;f--)
        {
          StrE[f] = StrE[f-1];
        }
        StrE[0] = 'D';        
        Serial.print(StrE);
        digitalWrite(ledPin, HIGH);
      }  
    }    
  }
  // THIS SECTION IS FOR GPS------------------------------------------------>
  if (byteGPS > 0)
   {     
    gps[countcc] = byteGPS;
    //Serial.print(gps[countcc]); //Checkpoint 2 <-- CHECK IF SUCCESSFULLY TRANSFORM TO CHAR ARRAY 
    countcc++;
    if (byteGPS==36)
    {
      digitalWrite(ledPin, LOW);
      countcc = 1;
      checkc=0;
      countc=0;
      for (int d=3;d<6;d++)
      {
        //Serial.print(d); //Checkpoint 3 <-- CHECK IF DEFINED HEADER IS SAME AS INPUT HEADER
        //Serial.print("  gps = "); //DEBUG PURPOSE
        //Serial.print(gps[d]); //DEBUG PURPOSE
        //Serial.print("   HdrGPS = "); //DEBUG PURPOSE
        //Serial.println(HdrGPS[d-3]); //DEBUG PURPOSE
        if (gps[d]==HdrGPS[d-3]) 
        {
          checkc++; 
          //Serial.println(checkc); //Checkpoint 4 <-- CHECK FLAG VALUE IF FOR EACH CORRECTED HEADER
        }   
      }
      if (checkc==3)
      {
        for (int e;e<strlen(gps);e++)
        {
          if (gps[e]==',')
          {
            indexGPS[countc]=e;
            countc++;
          }
          if (gps[e]=='*')
          {
            indexGPS[30]=e;
            countc++;
          }
        }
        strncpy(StrG,gps+indexGPS[2]+1,indexGPS[3]-indexGPS[2]-1);
        //Serial.println(StrG); //Checkpoint 5 <-- CHECK COPIED VALUE        
        for(int f=8;f>=0;f--)
        {
          StrG[f] = StrG[f-2];
        }
        StrG[0] = 'L';
        StrG[1] = 'T';
        Serial.print(StrG);        
        strncpy(StrG2,gps+indexGPS[4]+1,indexGPS[5]-indexGPS[4]-1);
        //Serial.println(StrG2); //Checkpoint 6 <-- CHECK COPIED VALUE
        for(int g=9;g>=0;g--)
        {
          StrG2[g] = StrG2[g-2];
        }
        StrG2[0] = 'L';
        StrG2[1] = 'G';
        Serial.println(StrG2);        
        digitalWrite(ledPin, HIGH);
      }
    }
  }  
  clearStr(StrC); 
  clearStr(StrE);
  clearStr(StrG);
  clearStr(StrG2);  
}

Your code has 3 sections and each of them is controlled by these statements.

  if (byteCompass > 0)
  if (byteEcho > 0)
  if (byteGPS > 0)

which prevent the program section outputting anything unless the value being checked is greater than zero. That implies that when the value is greater than zero there is valid data. Is that true ?

If it is true and you want to output values when data exists for all 3 sensors then, after reading the 3 values from serial 1, 2 and 3 you need to control the output section of the program by testing if all 3 values are greater than zero
if ((byteCompass > 0) && (byteEcho > 0) && (byteGPS > 0))then only output data if the combined test is true.

UKHeliBob:
if ((byteCompass > 0) && (byteEcho > 0) && (byteGPS > 0))then only output data if the combined test is true.

Thanks for your reply,
I tried the combined test, but 3 of them seems never exist as >0 at a time.

I attach the void setup() at the first post. perhaps i did something wrong with the variables.

You're outputting values from all three sources at the same time, but of course the incoming messages arrive independently and so you will actually only receive one at a time.

When do you want to output your result set?

One option would be to store the latest value from each source, and each time a new message arrives (from any source) you output the latest values from all sources.

Another option would be to output the latest values of all sources at regular intervals.

Another option would be to output the latest values of all sources when all sources have been updated (since the previous output).

There are other options, too.