int verifyLookupTables()
  chan_key *rorc;
  char filename[512];
  char msgbuf[512];
  int ch;
  int id;
  int ret = 0;
  int retval = 0;
  RCU_SETTINGS rcu;
  FILE *flogfout;
  // Open Lookuptable logfile
  sprintf(msgbuf,"%slookuplist.txt",daq_param.configdir);
  flogfout = fopen(msgbuf,"w");
  if (flogfout == NULL) {
    sprintf(msgbuf,"*ERROR %s: could not open %slookuplist.txt",__FUNCTION__,daq_param.configdir);
    printMessage(daq_param.outf,msgbuf);
  }
  for (ch = 0; ch < daq_rorc.found; ch++) {
    if (daq_rorc.active[ch]) {
      // Open rorc
      id = daq_rorc.rcuid[ch];
      rorc = get_channel(rmap[id].revision,rmap[id].serial,rmap[id].channel);
      // Could not open rorc device
      if(rorc->status != R_OPEN) {
        sprintf(msgbuf,"%s: *ERROR* Failed to get rorc id %d serial %d channel %d\n",
                __FUNCTION__,id,rmap[id].serial,rmap[id].channel);
        printMessage(daq_param.outf,msgbuf);
        retval++;
      }
      else {
        // Print RCU ID in lookup table error log
        if (flogfout != NULL) {
          fprintf(flogfout,"RCU.ID %d\n",id);
        }
        sprintf(filename,"%srcu-%d.cfg",daq_param.configdir,id);
        sprintf(msgbuf,"%s: running for rcuid %d with config file %s\n",
                __FUNCTION__,id,filename);
        printMessage(daq_param.outf,msgbuf);
        memset(rcu.acl,0,sizeof(rcu.acl));
        ret = RcuReadoutList(&rcu,daq_rorc.rcuid[ch],filename);
        if (ret) {
          sprintf(msgbuf,"%s: *ERROR* RcuReadoutList %s failed with status %d\n",__FUNCTION__,
                  filename,ret);
          printMessage(daq_param.outf,msgbuf);
          retval++;
        }
        else {
          RcuDumpReadoutList(&rcu);
          ret = AltroVerifyLookupTable(rorc,rcu.acl,daq_param.altro_lookup_type,
                                  daq_param.altro_lookup_dest,daq_param.altro_lookup_verify,flogfout);
          if (ret != 0) {
            sprintf(msgbuf,"%s: *ERROR*  lookup table status  RCU %d LOOKUP %d = %d\n",__FUNCTION__,daq_rorc.rcuid[ch],daq_param.altro_lookup_type,ret);
          }
          else {
            sprintf(msgbuf,"%s: lookup table status  RCU %d LOOKUP %d = %d\n",__FUNCTION__,daq_rorc.rcuid[ch],daq_param.altro_lookup_type,ret);
          }
          printMessage(daq_param.outf,msgbuf);
          retval += ret;
        }
        release_channel(rorc);
      }
    }
  }
  if (flogfout != NULL) fclose(flogfout);
  return retval;
}



int AltroVerifyLookupTable(chan_key *dev,u_long *acl,int type,int dest,int verify, FILE *flog)
{
  int j,k;
  u_long errst;
  int error;
  int iret = 0;
  u_long buffer[1024];
  char msgbuf[512];

  /* Generate or read a lookup table, dump it in /tmp/lookuptable.dat and load it */

  if (type == ALTRO_LOOKUP_NONE) return iret;
  sprintf(msgbuf,"%s: for TYPE = %d DEST = %d VERIFY = %d\n",__FUNCTION__,type,dest,verify);
  printMessage(daq_param.outf,msgbuf);

  if (type == ALTRO_LOOKUP_INVERT_0_7) {
     for (j = 0; j < 1024; j++) buffer[1023-j] = j;
     type = ALTRO_LOOKUP_INVERT;
  }
  else if (type == ALTRO_LOOKUP_2AA) {
     for (j = 0; j < 1024; j++) buffer[j] = 0x2AA;
  }
  else if (type == ALTRO_LOOKUP_155) {
     for (j = 0; j < 1024; j++) buffer[j] = 0x155;
  }
  else if (type == ALTRO_LOOKUP_PEAKS) {
    for (j = 0; j < 64; j++) buffer[j] = j*2;
    for (j = 64; j < 128; j++) buffer[j] = 0;
    for (j = 128; j < 196; j++) buffer[j] = 0x2AA;
    for (j = 196; j < 256; j++) buffer[j] = 0;
    for (j = 256; j < 260; j++) buffer[j] = 0x155;
    for (j = 260; j < 512; j++) buffer[j] = 0;
    for (j = 512; j < 900; j++) buffer[j] = j;
    for (j = 900; j < 1024; j++) buffer[j] = 0;
  }
  else if (type == ALTRO_LOOKUP_FILE) {
    sprintf(msgbuf,"%s using %slookuptable.dat\n",__FUNCTION__,daq_param.configdir);
    printMessage(daq_param.outf,msgbuf);
    sprintf(msgbuf,"%s%s",daq_param.configdir,"lookuptable.dat");
    iret = readFileLookupTable(msgbuf,buffer);
    if (iret != 0) {
      sprintf(msgbuf,"%s *ERROR* could not open lookuptable.dat\n",__FUNCTION__);
      printMessage(daq_param.outf,msgbuf);
      return iret;
    }
  }
  else if (type == ALTRO_LOOKUP_ZERO) {
    for (j = 0; j < 1024; j++) buffer[j] = 0;
  }
  else if (type == ALTRO_LOOKUP_3FF) {
    for (j = 0; j < 1024; j++) buffer[j] = 0x3FF;
  }
  else if (type == ALTRO_LOOKUP_WALK1) {
    for (j = 0; j < 1024; j++) buffer[j] = (1 << (j % 10));
  }
  else if (type == ALTRO_LOOKUP_RANDOM) {
    for (j = 0; j < 1024; j++) buffer[j] = 0;
  }
  else {
    for (j = 0; j < 1024; j++) buffer[j] = j;
  }
  for (j = 0, k = 0; j < FEC_RCU; j++) {
    if (dest == 0) error = AltroReadLookup(dev,j,&acl[k],buffer,type,1,&errst);
    else error = RcuReadLookup(dev,j,&acl[k],buffer,type,1);
    if (error) {
        sprintf(msgbuf,"%s: *ERROR* verify for FEC %d error = %08X errst = %lX DEST= %d\n",__FUNCTION__,j,error,errst,dest);
        printMessage(daq_param.outf,msgbuf);
        iret++;
        if (flog != NULL) fprintf(flog,"FEC.ID %d\nFEC.WR 1\nFEC.ERROR %d\nFEC.ERRST %lX\n",j,error,errst);
      }
    }
    k = k + ALTRO_FEC;
  }
  return iret;
}
