public static void writeLogFile(String descript, String filename) {
   File file;
   FileOutputStream outstream;
   // BufferedWriter outstream;
   Date time = new Date();
   long bytes = 30000000;
   try {
     // Get log file
     String logfile = "C:\\" + filename + ".txt";
     file = new File(logfile);
     boolean exists = file.exists();
     if (!exists) {
       // create a new, empty node file
       try {
         file = new File(logfile);
         boolean success = file.createNewFile();
       } catch (IOException e) {
         System.out.println("Create Event Log file failed!");
       }
     }
     try {
       descript = descript + "\n";
       outstream = new FileOutputStream(file, true);
       for (int i = 0; i < descript.length(); ++i) {
         outstream.write((byte) descript.charAt(i));
       }
       outstream.close();
     } catch (IOException e) {
     }
   } catch (java.lang.Exception e) {
   }
 }
  public static void write_Byte_array(
      int Msg_head, int packetbytes_length, int numdecodedsamples, byte[] source) {
    int i = 0;
    int k = 0;
    int quote = 0;
    int residule = 0;
    long min, sec, millisec, time_pre;
    String descript_string = "";

    // System.out.println("Destination[0][0]:" + destination[0][0] + "\n " );
    // System.out.println("decodepacketbytepointer " + decodepacketbytepointer + " " +
    // decodepacketbitpointer + "\n " );

    // decompressed data less than packetbytes_length
    if (numdecodedsamples <= (packetbytes_length / 2 - 2)) // one sample is stored by two bytes
    {
      // change length here
      TOS_length = (Msg_head - 10 + 4 + numdecodedsamples * 2);
      APP_length = (TOS_length - 14);
      source[0] &= ~(0xff); // TOS_Msg length
      source[21] &= ~(0xff); // APP_Msg length
      source[0] |= (TOS_length & 0xff); // only one byte can be written
      source[21] |= (APP_length & 0xff); // only one byte can be written
      // System.out.println(" Length ****** " + source[0] + " " + source[21] + " "+ k + "\n " );
      source[20] &= ~(0xff);
      source[20] |= (SEISMIC_DATA_TYPE & 0xff); // only one byte can be written

      for (i = 0; i < (Msg_head + timestampbits / 8); i++) {
        // System.out.println(Msg_head + " " + timestampbits);
        // System.out.println(source[i] + " " + i);
        writeint(0, 8, source[i]);
      }
      // writeint(0,4,source[i]);//codingparameter written
      for (i = 0; i < numdecodedsamples; i++) {
        writeint(0, 16, decodedunfoldedsamples[i]);
      }
      // System.out.println("decodepacketbytepointer " + decodepacketbytepointer + " " +
      // decodepacketbitpointer + "\n " );
      /* reset variables for next packet read */
      decodepacketbitpointer = 0;
      decodepacketbytepointer = 0;
      // System.out.println("Destination[0][0]:" + destination[0][0] + "\n " );
      // Write to a file with the timestamp and numdecodedsamples
      // descript_string  += time_s;
      // descript_string += " ";
      descript_string += numdecodedsamples;
      // descript_string += " ";
      // descript_string +=decodedfoldedsamples[5];
      // descript_string += " ";
      // descript_string += decodedunfoldedsamples[1];
      // descript_string += " ";
      // descript_string += decodedunfoldedsamples[numdecodedsamples-2];
      descript_string += "\r\n";
      try {
        FileOutputStream outstream;
        outstream = new FileOutputStream(compress_logfile, true);
        for (int m = 0; m < descript_string.length(); ++m) {
          outstream.write((byte) descript_string.charAt(m));
        }
        outstream.close();
      } catch (IOException e) {
      }

    }
    // The number of bytes after decompression is longer than the compressed one, it should be
    // seperated into several packets
    // It should go here more frequently
    else {
      try {
        FileOutputStream outstream;
        outstream = new FileOutputStream(compress_logfile, true);

        quote = numdecodedsamples / (packetbytes_length / 2 - 2);
        // System.out.println("#####The Number of decompressed packets =  " + numdecodedsamples +
        // "quote " + quote + "\n");

        for (k = 0; k < quote; k++) {
          // change data type here
          source[20] &= ~(0xff);
          source[20] |= (SEISMIC_DATA_TYPE & 0xff); // only one byte can be written

          // change the sequence number here
          source[22] &= ~(0xff);
          source[23] &= ~(0xff);
          source[22] |= ((APP_seqo + k) & 0x00ff); // only one byte can be written
          source[23] |= ((APP_seqo + k) & 0xff00) >> 8; // only one byte can be written
          // System.out.println("Changing seqno ****** " + (APP_seqo+k) + " || " +
          // Integer.toHexString(source[23]) + " " + Integer.toHexString(source[22]) + "k" + k + "\n
          // " );

          for (i = 0; i < Msg_head; i++) {
            writeint(k, 8, source[i]);
          }
          if (k > 0) {
            // change time_stamp here
            timestamp += ((packetbytes_length) / 2 - 2) * timeinterval;
          }
          time_pre = timestamp;
          min = (timestamp / 60000);
          writeint(k, 6, min); // write minute byte
          timestamp = timestamp % 60000;
          sec = (timestamp / 1000);
          writeint(k, 6, sec); // write second byte
          timestamp = timestamp % 1000;
          millisec = timestamp;
          writeint(k, 10, millisec); // write millisecond byte
          writeint(k, 10, timeinterval); // write time interval
          timestamp = time_pre;

          // System.out.println("Changing timestamp******** " + timestamp + "| k ==" + k + "\n " );

          for (i = k * (packetbytes_length / 2 - 2);
              i < (k + 1) * (packetbytes_length / 2 - 2);
              i++) {
            writeint(k, 16, decodedunfoldedsamples[i]); // one sample costs two bytes
          }
          // System.out.println("decodepacketbytepointer " + decodepacketbytepointer + " " +
          // decodepacketbitpointer + "\n " );
          // reset variables for next packet read
          decodepacketbitpointer = 0;
          decodepacketbytepointer = 0;

          // System.out.println("Destination[0][0]:" + destination[0][0] + "\n " );

        }
        // Write to a file with the timestamp and numdecodedsamples
        // descript_string  += time_s;
        // descript_string += " ";
        descript_string += numdecodedsamples;
        descript_string += " ";
        // descript_string +=decodedfoldedsamples[1];
        // descript_string += " ";
        // descript_string += decodedunfoldedsamples[1];
        // descript_string += " ";
        // descript_string += decodedunfoldedsamples[numdecodedsamples-2];
        descript_string += "\r\n";

        for (int m = 0; m < descript_string.length(); ++m) {
          outstream.write((byte) descript_string.charAt(m));
        }
        descript_string = "";

        if ((residule = (numdecodedsamples) % (packetbytes_length / 2 - 2)) != 0) {
          // System.out.println("For the residule***************"  + "\n " );
          // change length here
          TOS_length = (Msg_head - 10 + 4 + residule * 2);
          APP_length = (TOS_length - 14);
          source[0] &= ~(0xff); // TOS_Msg length
          source[21] &= ~(0xff); // APP_Msg length
          source[0] |= (TOS_length & 0xff); // only one byte can be written
          source[21] |= (APP_length & 0xff); // only one byte can be written

          // change data type here
          source[20] &= ~(0xff);
          source[20] |= (SEISMIC_DATA_TYPE & 0xff); // only one byte can be written

          // change the sequenceNum here
          source[22] &= ~(0xff);
          source[23] &= ~(0xff);
          source[22] |= ((APP_seqo + quote) & 0x00ff); // only one byte can be written
          source[23] |= ((APP_seqo + quote) & 0xff00) >> 8; // only one byte can be written
          // System.out.println("Changing seqno ****** " + (APP_seqo+quote) + " || " +
          // Integer.toHexString(source[23]) + " " + Integer.toHexString(source[22]) + "quote" +
          // quote + "\n " );

          destination_last_row = new byte[TOS_length + 10];

          for (i = 0; i < Msg_head; i++) {
            writeint_last_row(8, source[i]);
          }

          // change time_stamp here
          timestamp += ((packetbytes_length) / 2 - 2) * timeinterval;
          time_pre = timestamp;
          min = (timestamp / 60000);
          writeint_last_row(6, min); // write minute byte
          timestamp = timestamp % 60000;
          sec = (timestamp / 1000);
          writeint_last_row(6, sec); // write second byte
          timestamp = timestamp % 1000;
          millisec = timestamp;
          writeint_last_row(10, millisec); // write millisecond byte
          writeint_last_row(10, timeinterval); // write time interval
          timestamp = time_pre;

          // System.out.println("Changing timestamp******** " + timestamp + "| residule ==" +
          // residule + "\n " );

          for (i = quote * (packetbytes_length / 2 - 2);
              i < ((quote) * (packetbytes_length / 2 - 2) + residule);
              i++) {
            writeint_last_row(16, decodedunfoldedsamples[i]);
          }
          // reset variables for next packet read
          decodepacketbitpointer = 0;
          decodepacketbytepointer = 0;
          // Write to a file with the timestamp and numdecodedsamples
          /*descript_string  += time_s;
          descript_string += " ";
          descript_string += residule;
          descript_string += "\r\n";
          for (int m=0; m<descript_string.length();++m){
          	outstream.write((byte)descript_string.charAt(m));
          }
          descript_string = "";*/
        }

        outstream.close();
      } catch (IOException e) {
      }
      // return 1;
    }
  }