/** Builds the EIA Table */
  @SuppressWarnings("deprecation")
  private void yieldEiaTable() {
    EIATable eiaTable = null;
    int numberOfOpenedFiles = sourceFiles.size();
    // MainWindow.iniEiaTable = MainWindow.dupEiaTable;
    eiaTable = new EIATable(MainWindow.dupEdfFileHeaders, numberOfOpenedFiles);
    eiaTable.setUpdateSinceLastSave(true); // the initial update status should be true
    eiaTable.setSavedOnce(false);

    eiaTable.setMasterHeaderCategory(EDFTable.MasterHeaderCategory.EIA_WORKSET); // obsolete line

    MainWindow.setIniEiaTable(eiaTable);
  }
 /** Validates the EIA table and stores corresponding incompliances */
 public void validateEiaTable() {
   EIATable table = MainWindow.getIniEiaTable();
   MainWindow.setEiaIncompliances(table.parseEIATable());
 }
  /**
   * Parse EIA table and report the Incompliances
   *
   * @param eiaTable the EIA table to be processed
   * @param fileList the list of file name used to generate Incompliances
   * @return an array of Incompliances
   */
  public static ArrayList<Incompliance> parseEIATable(EIATable eiaTable, String[] fileList) {

    ArrayList<Incompliance> eiaIncompliances = new ArrayList<Incompliance>();

    if (fileList.length != eiaTable.getRowCount()) {
      return eiaIncompliances;
    }

    final int errorSrcTypeIndex = Incompliance.index_incomp_src_eia;
    final String incomplianceType = Incompliance.typeOfErrorHeader[errorSrcTypeIndex];
    Incompliance incomp;
    String description;
    boolean bASCII;

    final int COL_INDEX_VERSION = 0;
    final int COL_INDEX_LOCAL_PATIENT_ID = 1;
    final int COL_INDEX_LOCAL_RECORDING_ID = 2;
    final int COL_INDEX_START_DATE = 3;
    final int COL_INDEX_START_TIME = 4;
    final int COL_INDEX_NUMBER_OF_BYTES_IN_HEADER_RECORD = 5;
    final int COL_INDEX_RESERVED = 6;
    final int COL_INDEX_NUMBER_OF_DATA_RECORDS = 7;
    final int COL_INDEX_DURATION_OF_A_DATA_RECORD = 8;
    final int COL_INDEX_NUMBER_OF_SIGNALS_IN_DATA_RECORD = 9;

    int nrow = eiaTable.getRowCount();
    int col;
    for (int i = 0; i < nrow; i++) {

      String fileName = fileList[i];

      /**
       * ********************************************************** 8 ascii : version of this data
       * format (0) **********************************************************
       */
      col = COL_INDEX_VERSION + 1;
      String version = (String) eiaTable.getModel().getValueAt(i, col);
      if (version == null || version.equals("")) {
        // [Version](A.3) cannot be empty field
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Version](A.1) check for ascii
        bASCII = checkAsciiF(version);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Version](A.2) is equal to 0
          try {
            int ver = Integer.parseInt(version);
            if (ver != 0) {
              description = Incompliance.error_eia_version;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          } catch (NumberFormatException e) {
            description = Incompliance.error_eia_version;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          }
        }
      }

      /**
       * ********************************************************** 80 ascii : local patient
       * identification **********************************************************
       */
      col = COL_INDEX_LOCAL_PATIENT_ID + 1;
      String partient_id = (String) eiaTable.getModel().getValueAt(i, col);
      if (partient_id == null || partient_id.equals("")) {
        // [Partient_id](B.2) can be empty field
      } else {
        // [Partient_id](B.1) check for ascii
        bASCII = checkAsciiF(partient_id);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        }
      }

      /**
       * ********************************************************** 80 ascii : local recording
       * identification **********************************************************
       */
      col = COL_INDEX_LOCAL_RECORDING_ID + 1;
      String recording_id = (String) eiaTable.getModel().getValueAt(i, col);
      if (recording_id == null || recording_id.equals("")) {
        // [Recording_id](C.2) can be empty field
      } else {
        // [Recording_id](C.1) check for ascii
        bASCII = checkAsciiF(recording_id);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        }
      }

      /**
       * ********************************************************** 8 ascii : startdate of recording
       * (dd.mm.yy) **********************************************************
       */
      col = COL_INDEX_START_DATE + 1;
      String startdate = (String) eiaTable.getModel().getValueAt(i, col);
      if (startdate == null || startdate.equals("")) {
        // [Startdate](D.2) cannot be empty field
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Startdate](D.1) check for ascii
        bASCII = checkAsciiF(startdate);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Startdate](D.4) separator between digits should be only �period�
          String[] items = startdate.split("\\.");
          if (items.length != 3) {
            description = Incompliance.error_eia_dateformat;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          } else {
            // [Startdate](D.3) dd:00-31, mm:00-12, yy:00-99
            try {
              int dd = Integer.parseInt(items[0]);
              int mm = Integer.parseInt(items[1]);
              int yy = Integer.parseInt(items[2]);
              if (dd >= 0 && dd <= 31 && mm >= 0 && mm <= 12 && yy >= 00 && yy <= 99) {
                // valid date format
              } else {
                description = Incompliance.error_eia_daterange;
                incomp =
                    new Incompliance(
                        incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
                eiaIncompliances.add(incomp);
              }
            } catch (NumberFormatException e) {
              description = Incompliance.error_eia_daterange;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          }
        }
      }

      /**
       * ********************************************************** 8 ascii : starttime of recording
       * (hh.mm.ss) **********************************************************
       */
      col = COL_INDEX_START_TIME + 1;
      String starttime = (String) eiaTable.getModel().getValueAt(i, col);
      if (starttime == null || starttime.equals("")) {
        // [Start-time](E.2) cannot be empty field
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Start-time](E.1) check for ascii
        bASCII = checkAsciiF(starttime);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Start-time](E.4) separator between digits should be only �period�
          String[] items = starttime.split("\\.");
          if (items.length != 3) {
            description = Incompliance.error_eia_timeformat;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          } else {
            // [Start-time](E.3) hh:00-23, mm:00-59, ss:00-59
            try {
              int hh = Integer.parseInt(items[0]);
              int mm = Integer.parseInt(items[1]);
              int ss = Integer.parseInt(items[2]);
              if (hh >= 0 && hh <= 23 && mm >= 0 && mm <= 59 && ss >= 00 && ss <= 59) {
                // valid time format
              } else {
                description = Incompliance.error_eia_timerange;
                incomp =
                    new Incompliance(
                        incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
                eiaIncompliances.add(incomp);
              }
            } catch (NumberFormatException e) {
              description = Incompliance.error_eia_timerange;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          }
        }
      }

      /**
       * ********************************************************** 8 ascii : number of bytes in
       * header record **********************************************************
       */
      col = COL_INDEX_NUMBER_OF_BYTES_IN_HEADER_RECORD + 1;
      String nBytes = (String) eiaTable.getModel().getValueAt(i, col);
      if (nBytes == null || nBytes.equals("")) {
        // [Number_of_bytes](F.2) should not be empty
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Number_of_bytes](F.1) check for ascii
        bASCII = checkAsciiF(nBytes);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Number_of_bytes](F.3) is an integer
          try {
            int nbytes = Integer.parseInt(nBytes);
            if (nbytes <= 0) {
              description = Incompliance.error_eia_num_bytes;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          } catch (NumberFormatException e) {
            description = Incompliance.error_eia_num_bytes;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          }
        }
      }

      /**
       * ********************************************************** 44 ascii : reserved
       * **********************************************************
       */
      col = COL_INDEX_RESERVED + 1;
      String reserved = (String) eiaTable.getModel().getValueAt(i, col);
      if (reserved == null || reserved.equals("")) {
        // [Reserved](G.2) can be empty field
      } else {
        // [Reserved](G.1) check for ascii
        bASCII = checkAsciiF(reserved);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        }
      }

      /**
       * ********************************************************** 8 ascii : number of data records
       * (-1 if unknown) **********************************************************
       */
      col = COL_INDEX_NUMBER_OF_DATA_RECORDS + 1;
      String nDataRecords = (String) eiaTable.getModel().getValueAt(i, col);
      if (nDataRecords == null || nDataRecords.equals("")) {
        // [Num_of_DataRecords](H.2) should not be empty
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Num_of_DataRecords](H.1) check for ascii
        bASCII = checkAsciiF(nDataRecords);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Num_of_DataRecords](H.3) is a positive integer
          try {
            int ndatarecords = Integer.parseInt(nDataRecords);
            if (ndatarecords > 0 || ndatarecords == -1) {
              // valid values
            } else {
              description = Incompliance.error_eia_num_records;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          } catch (NumberFormatException e) {
            description = Incompliance.error_eia_num_records;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          }
        }
      }

      /**
       * ********************************************************** 8 ascii : duration of a data
       * record, in seconds **********************************************************
       */
      col = COL_INDEX_DURATION_OF_A_DATA_RECORD + 1;
      String duration = (String) eiaTable.getModel().getValueAt(i, col);
      if (duration == null || duration.equals("")) {
        // [Duration_of_a_data_record](I.2) should not be empty field
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Duration_of_a_data_record](I.1) check for ascii
        bASCII = checkAsciiF(duration);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Duration_of_a_data_record](I.3) is a positive floating point number (eg. 1, 0.2,
          // 0.001)
          try {
            float dur = Float.parseFloat(duration);
            if (dur < 0) {
              description = Incompliance.error_eia_duration;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          } catch (NumberFormatException e) {
            description = Incompliance.error_eia_duration;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          }
        }
      }

      /**
       * ********************************************************** 4 ascii : number of signals (ns)
       * in data record **********************************************************
       */
      col = COL_INDEX_NUMBER_OF_SIGNALS_IN_DATA_RECORD + 1;
      String nSignals = (String) eiaTable.getModel().getValueAt(i, col);
      if (nSignals == null || nSignals.equals("")) {
        // [Number_of_signals](J.2) cannot be empty
        description = Incompliance.error_eia_empty;
        incomp =
            new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
        eiaIncompliances.add(incomp);
      } else {
        // [Number_of_signals](J.1) check for ascii
        bASCII = checkAsciiF(nSignals);
        if (!bASCII) {
          description = Incompliance.error_eia_ascii;
          incomp =
              new Incompliance(incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
          eiaIncompliances.add(incomp);
        } else {
          // [Number_of_signals](J.3) is a positive integer
          try {
            int nsignals = Integer.parseInt(nSignals);
            if (nsignals <= 0) {
              description = Incompliance.error_eia_nsignals;
              incomp =
                  new Incompliance(
                      incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
              eiaIncompliances.add(incomp);
            }
          } catch (NumberFormatException e) {
            description = Incompliance.error_eia_nsignals;
            incomp =
                new Incompliance(
                    incomplianceType, description, fileName, i, col, errorSrcTypeIndex);
            eiaIncompliances.add(incomp);
          }
        }
      }
    } // for loop ends

    if (eiaIncompliances.size() > 0) {
      eiaTable.setEdfValid(false);
    }

    return eiaIncompliances;
  }