Esempio n. 1
0
void SimBax::operator()()
{
    uniform_int_distribution<int> readStart(0, t.size());
    ofstream fastq(fastqFilename);

    resetStrings();
    const int numReads = t.size() * depth / readLen;

    int nextOut = numReads/10;
    int pct = 0;
    chrono::time_point<chrono::system_clock> start;
    start = chrono::system_clock::now();
    cout << "Inilisation finished, simulating reads.\n";
    
    for (int readNum = 0 ; readNum < numReads ; readNum++ )
    {
        long addedSoFar = baseCall.size();
        string fastqPhreds;
        makeRead(readLen, readStart(gen), fastqPhreds);
        const int lengthRead = baseCall.size() - addedSoFar;
        reads.push_back(lengthRead);
        writeFastq(baseCall.substr(addedSoFar, lengthRead)
                   ,fastqPhreds
                   ,fastq
                   ,readNum);

        if (readNum == nextOut)
        {
            chrono::time_point<chrono::system_clock> current;
            current = chrono::system_clock::now();
            chrono::duration<double> elapsed = start - current;
            nextOut += numReads/10;
            pct += 10;
            cout << pct << "% done. Time ellapsed :"
                 << elapsed.count() << " seconds\n";
        }

    }
    
    cout << "Wrinting data to file.\n";
    BaxH5 baxh5(baxFilename);
    baxh5.writeReads(baseCall
                    ,deletionQV
                    ,deletionTag
                    ,insertionQV
                    ,mergeQV
                    ,preBaseFrame
                    ,pulseIndex
                    ,substitutionQV
                    ,subsititutionTag
                    ,qualityValue
                    ,widthInFrame
                    ,reads);
}
Esempio n. 2
0
// Called in ISR context called when a data is received
bool USBMSD::EP2_OUT_callback() {
    uint32_t size = 0;
    uint8_t buf[MAX_PACKET_SIZE_EPBULK];
    readEP(EPBULK_OUT, buf, &size, MAX_PACKET_SIZE_EPBULK);
    switch (stage) {
            // the device has to decode the CBW received
        case READ_CBW:
            CBWDecode(buf, size);
            break;

            // the device has to receive data from the host
        case PROCESS_CBW:
            switch (cbw.CB[0]) {
                case WRITE10:
                case WRITE12:
                    memoryWrite(buf, size);
                    break;
                case VERIFY10:
                    memoryVerify(buf, size);
                    break;
            }
            break;

            // an error has occured: stall endpoint and send CSW
        default:
            stallEndpoint(EPBULK_OUT);
            csw.Status = CSW_ERROR;
            sendCSW();
            break;
    }

    //reactivate readings on the OUT bulk endpoint
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    return true;
}
Esempio n. 3
0
bool USBCDC::readEP_NB(uint8_t * buffer, uint16_t * size) {
    if (!USBDevice::readEP_NB(EPBULK_OUT, buffer, size, MAX_CDC_REPORT_SIZE))
        return false;
    if (!readStart(EPBULK_OUT, MAX_CDC_REPORT_SIZE))
        return false;
    return true;
}
Esempio n. 4
0
void SSLSocket::onConnect(uv_connect_t* handle, int status)
{
    TraceS(this) << "On connect" << endl;
    if (status) {
        setUVError("SSL connect error", status);
        return;
    }
    else
        readStart();

    SSL* ssl = SSL_new(_context->sslContext());

    // TODO: Automatic SSL session handling.
    // Maybe add a stored session to the network manager.
    if (_session)
        SSL_set_session(ssl, _session->sslSession());

    SSL_set_connect_state(ssl);
    SSL_do_handshake(ssl);

    _sslAdapter.init(ssl);
    _sslAdapter.flush();

    //emitConnect();
    onSocketConnect();
    TraceS(this) << "On connect: OK" << endl;
}
Esempio n. 5
0
// Called in ISR context on each start of frame
void USBAudio::SOF(int frameNumber) {
    uint32_t size = 0;

    if (!interruptOUT) {
        // read the isochronous endpoint
        if (buf_stream_in != NULL) {
            if (USBDevice::readEP_NB(EPISO_OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN)) {
                if (size) {
                    available = true;
                    readStart(EPISO_OUT, PACKET_SIZE_ISO_IN);
                    buf_stream_in = NULL;
                }
            }
        }
    }

    if (!interruptIN) {
        // write if needed
        if (buf_stream_out != NULL) {
            USBDevice::writeNB(EPISO_IN, (uint8_t *)buf_stream_out, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
            buf_stream_out = NULL;
        }
    }

    SOF_handler = true;
}
Esempio n. 6
0
bool USBHID::read(HID_REPORT *report)
{
    uint32_t bytesRead = 0;
    bool result;
    result = USBDevice::readEP(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
    if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
        return false;
    report->length = bytesRead;
    return result;
}
Esempio n. 7
0
//------------------------------------------------------------------------------
bool SdSpiCard::readBlocks(uint32_t block, uint8_t* dst, size_t count) {
  if (!readStart(block)) {
    return false;
  }
  for (uint16_t b = 0; b < count; b++, dst += 512) {
    if (!readData(dst, 512)) {
      return false;
    }
  }
  return readStop();
}
Esempio n. 8
0
void TCPSocket::acceptConnection()
{
    // Create the shared socket pointer;
    // if it is not handled it will be destroyed.
    // TODO: Allow accepted sockets to use different event loops.
    auto socket = net::makeSocket<net::TCPSocket>(loop()); //std::make_shared<net::TCPSocket>(this->loop());
    TraceLS(this) << "Accept connection: " << socket->ptr() << endl;
    uv_accept(ptr<uv_stream_t>(), socket->ptr<uv_stream_t>()); // uv_accept should always work
    socket->readStart();        
    AcceptConnection.emit(Socket::self(), socket);
}
Esempio n. 9
0
bool USBAudio::EP3_OUT_callback() {
    uint32_t size = 0;
    interruptOUT = true;
    if (buf_stream_in != NULL) {
        readEP(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN);
        available = true;
        buf_stream_in = NULL;
    }
    readStart(EP3OUT, PACKET_SIZE_ISO_IN);
    return false;
}
Esempio n. 10
0
// Called in ISR context
// Set configuration. Return false if the
// configuration is not supported.
bool USBCDCMSC::USBCallback_setConfiguration(uint8_t configuration) {
    if (configuration != DEFAULT_CONFIGURATION) {
        return false;
    }

    // Configure endpoints > 0
    addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
    addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
    addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);

    // Configure endpoints > 0
    addEndpoint(MSDBULK_IN, MAX_PACKET_SIZE_MSDBULK);
    addEndpoint(MSDBULK_OUT, MAX_PACKET_SIZE_MSDBULK);

    // We activate the endpoint to be able to recceive data
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);

    //activate readings
    readStart(MSDBULK_OUT, MAX_PACKET_SIZE_MSDBULK);
    return true;
}
Esempio n. 11
0
bool USBMouseKeyboard::EP1_OUT_callback() {
    uint32_t bytesRead = 0;
    uint8_t led[65];
    USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE);
    
    // we take led[1] because led[0] is the report ID
    lock_status = led[1] & 0x07;
    
    // We activate the endpoint to be able to recceive data
    if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
        return false;
    return true;
}
Esempio n. 12
0
// Called in ISR context
// Set configuration. Return false if the configuration is not supported.
bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) {
    if (configuration != DEFAULT_CONFIGURATION) {
        return false;
    }

    // Configure isochronous endpoint
    realiseEndpoint(EPISO_OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS);
    realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS);

    // activate readings on this endpoint
    readStart(EPISO_OUT, PACKET_SIZE_ISO_IN);
    return true;
}
Esempio n. 13
0
// Called in ISR context
// Set configuration. Return false if the
// configuration is not supported.
bool USBMSD::USBCallback_setConfiguration(uint8_t configuration) {
    if (configuration != DEFAULT_CONFIGURATION) {
        return false;
    }

    // Configure endpoints > 0
    addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
    addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);

    //activate readings
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    return true;
}
Esempio n. 14
0
bool USBHID::readNB(HID_REPORT *report)
{
    uint32_t bytesRead = 0;
    bool result;
    result = USBDevice::readEP_NB(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
    // if readEP_NB did not succeed, does not issue a readStart
    if (!result)
        return false;
    report->length = bytesRead;
    if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
        return false;
    return result;
}
Esempio n. 15
0
bool RJBaseUSBDevice::USBCallback_setConfiguration(uint8_t configuration) {
    LOG(INIT, "RJBaseUSBDevice::USBCallback_setConfiguration() called");

    // Configuration 1 is our only configuration
    if (configuration != 1) return false;

    addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);

    // activate the endpoint to be able to recceive data
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);

    return true;
}
Esempio n. 16
0
/** reads a diff file */
static
SCIP_RETCODE readDiffFile(
   SCIP*                 scip,               /**< SCIP data structure */
   LPINPUT*              lpinput,            /**< LP reading data */
   const char*           filename            /**< name of the input file */
   )
{
   assert(lpinput != NULL);

   /* open file */
   lpinput->file = SCIPfopen(filename, "r");
   if( lpinput->file == NULL )
   {
      SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
      SCIPprintSysError(filename);
      return SCIP_NOFILE;
   }

   /* free transformed problem */
   if( SCIPgetStage(scip) >= SCIP_STAGE_PROBLEM )
   {
      SCIP_CALL( SCIPfreeTransform(scip) );
   }

   /* parse the file */
   lpinput->section = LP_START;
   while( lpinput->section != LP_END && !hasError(lpinput) )
   {
      switch( lpinput->section )
      {
      case LP_START:
         SCIP_CALL( readStart(scip, lpinput) );
         break;

      case LP_OBJECTIVE:
         SCIP_CALL( readObjective(scip, lpinput) );
         break;

      case LP_END: /* this is already handled in the while() loop */
      default:
         SCIPerrorMessage("invalid Diff file section <%d>\n", lpinput->section);
         return SCIP_INVALIDDATA;
      }
   }

   /* close file */
   SCIPfclose(lpinput->file);

   return SCIP_OKAY;
}
Esempio n. 17
0
bool USBMIDI::EP2_OUT_callback() {
    uint8_t buf[64];
    uint32_t len;
    readEP(EPBULK_OUT, buf, &len, 64);

    if (midi_evt != NULL) {
        for (int i=0; i<len; i+=4) {
            midi_evt(MIDIMessage(buf+i));
        }
    }

    // We reactivate the endpoint to receive next characters
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    return true;
}
Esempio n. 18
0
void TCPSocket::onConnect(uv_connect_t* handle, int status)
{
    TraceLS(this) << "On connect" << endl;
    
    // Error handled by static callback proxy
    if (status == 0) {
        if (readStart())
            onSocketConnect();
    }
    else {
        setUVError("Connection failed", status);    
        //ErrorLS(this) << "Connection failed: " << error().message << endl;
    }
    delete handle;
}
Esempio n. 19
0
bool USBCDCMSC::EP2_OUT_callback() {
    uint8_t c[65];
    uint16_t size = 0;

    //we read the packet received and put it on the circular buffer
    readEP(c, &size);
    for (int i = 0; i < size; i++) {
        cdcbuf.queue(c[i]);
    }

    //call a potential handler
    rx.call();

    // We reactivate the endpoint to receive next characters
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    return true;
}
Esempio n. 20
0
void BooRedisAsync::connectComplete(const boost::system::error_code& error)
{
    if (!error)
    {
        m_connectTimer->cancel();
        readStart();
        m_onceConnected = true;
        m_connected = true;

        onLogMessage("Successfully connected to Redis " + endpointToString(getEndpointIterator()),LOG_LEVEL_INFO);
        onConnect();

        if (!m_writeInProgress && !m_writeBuffer.empty())
            writeStart();
    }
    else
        onError(error);
}
Esempio n. 21
0
void SMSC95xxUSB::readFinished(FileSystemMessage *message)
{
    DEBUG("identifier = " << message->identifier << " result = " << (int)message->result);

    if (!m_rxPacket)
    {
        ERROR("unexpected readFinish with no receive packet buffer");
        return;
    }

    // Extract packet
    // USBMessage *usb = (USBMessage *) message->buffer;
    // TODO: Offset field contains virtual address of input data buffer
    u8 *data = (u8 *) message->offset; //usb->buffer;
    u32 receiveCmd = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
    Size frameLength = (receiveCmd & RxCommandFrameLength) >> 16;

    if (frameLength == 0 || frameLength > m_packetSize)
    {
        ERROR("invalid framelength: " << frameLength);
    }
    else
    {
        DEBUG("packet is " << frameLength << " bytes long");

        // Publish the packet to our parent
        m_rxPacket->size = frameLength;
        m_smsc->process(m_rxPacket, ReceiveCommandSize);

        // Release the packet buffer
        m_smsc->getReceiveQueue()->release(m_rxPacket);
        m_rxPacket = 0;

        // TODO: this should not be done like this
        // Trigger retry of all FileSystemRequests here.
        // m_server->interruptHandler(0);
    }

    // Release USB transfer
    finishTransfer(message);

    // Restart read transfer
    readStart();
}
Esempio n. 22
0
void BooRedisAsync::readComplete(const boost::system::error_code &error, size_t bytesTransferred)
{
    if (!error)
    {
        std::vector<RedisMessage> result;
        BooRedisDecoder::DecodeResult res = m_decoder.decode(m_readBuffer,bytesTransferred,result);

        for (std::vector<RedisMessage>::iterator it=result.begin();it!=result.end();++it)
            onRedisMessage(*it);

        if (res != BooRedisDecoder::DecodeError)
            readStart();
        else {
            onLogMessage("Error decoding redis message. Reconnecting",LOG_LEVEL_ERR);
            onError(boost::system::error_code());
        }
    }
    else
        onError(error);
}
Esempio n. 23
0
void
TcpHandler::handleConnect(const boost::system::error_code& error)
{
    if (error) {
	doClose(error);
    } else {
	unsigned int port = Options::commandPort();
	if (port != 0) {
	    boost::asio::ip::tcp::endpoint cmdEndpoint(boost::asio::ip::tcp::v4(), port);
	    m_cmdHandler.reset(new CommandHandler(*this, cmdEndpoint));
	    m_pcMessageCallback = boost::bind(&CommandHandler::handlePcMessage,
					      m_cmdHandler, _1);
	}
	port = Options::dataPort();
	if (port != 0) {
	    boost::asio::ip::tcp::endpoint dataEndpoint(boost::asio::ip::tcp::v4(), port);
	    m_dataHandler.reset(new DataHandler(*this, dataEndpoint));
	    m_valueCallback = boost::bind(&DataHandler::handleValue, m_dataHandler, _1);
	}
	resetWatchdog();
	readStart();
    }
}
Esempio n. 24
0
Error SMSC95xxUSB::initialize()
{
    DEBUG("");

    Error r = USBDevice::initialize();
    if (r != ESUCCESS)
    {
        ERROR("failed to initialize USBDevice");
        return r;
    }
    DEBUG("setting MAC");

    // Set MAC address
    Ethernet::Address a;
    a.addr[0] = 0x00;
    a.addr[1] = 0x11;
    a.addr[2] = 0x22;
    a.addr[3] = 0x33;
    a.addr[4] = 0x44;
    a.addr[5] = 0x55;
    setMACAddress(a);

#define SMSC9512_HS_USB_PKT_SIZE 512
#define SMSC9512_DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * SMSC9512_HS_USB_PKT_SIZE)

    // Enable RX/TX bits on hardware
    write(HardwareConfig, read(HardwareConfig) | MultipleEther | BulkIn | BCE);
    write(BurstCap, SMSC9512_DEFAULT_HS_BURST_CAP_SIZE / SMSC9512_HS_USB_PKT_SIZE);
    write(MACControl, read(MACControl) | MACTransmit | MACReceive);
    write(TransmitConfig, TransmitOn);

    // Begin packet receive transfer
    readStart();

    // Done
    return ESUCCESS;
}
Esempio n. 25
0
bool USBMIDI::EPBULK_OUT_callback() {
    uint8_t buf[64];
    uint32_t len;
    readEP(EPBULK_OUT, buf, &len, 64);

    if (midi_evt != NULL) {
        for (uint32_t i=0; i<len; i+=4) {   
            uint8_t data_read;
            data_end=true;
            switch(buf[i]) {
            case 0x2:
                // Two-bytes System Common Message - undefined in USBMidi 1.0
                data_read=2;
                break;
            case 0x4:
                // SysEx start or continue
                data_end=false;
                data_read=3;
                break;
            case 0x5:
                 // Single-byte System Common Message or SysEx end with one byte
                data_read=1;
                break;
            case 0x6:
                // SysEx end with two bytes
                data_read=2;
                break;
            case 0xC:
                // Program change
                data_read=2;
                break;
            case 0xD:
                // Channel pressure
                data_read=2;
                break;      
            case 0xF:
                // Single byte
                data_read=1;
                break;    
            default:
                // Others three-bytes messages
                data_read=3;
                break;      
            } 
        
            for(uint8_t j=1;j<data_read+1;j++) {
                data[cur_data]=buf[i+j];
                cur_data++;
            }
        
            if(data_end) {
                 midi_evt(MIDIMessage(data,cur_data));
                 cur_data=0;            
            }
       }
    }

    // We reactivate the endpoint to receive next characters
    readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
    return true;
}
Esempio n. 26
0
/** reads an BLK file */
static
SCIP_RETCODE readBLKFile(
    SCIP*                 scip,               /**< SCIP data structure */
    SCIP_READER*          reader,             /**< reader data structure */
    BLKINPUT*             blkinput,           /**< BLK reading data */
    const char*           filename            /**< name of the input file */
)
{
    DEC_DECOMP *decdecomp;
    int i;
    int nconss;
    int nblocksread;
    int nvars;
    SCIP_READERDATA* readerdata;
    SCIP_CONS** conss;
    nblocksread = FALSE;

    assert(scip != NULL);
    assert(reader != NULL);
    assert(blkinput != NULL);

    if( SCIPgetStage(scip) < SCIP_STAGE_TRANSFORMED )
        SCIP_CALL( SCIPtransformProb(scip) );

    readerdata = SCIPreaderGetData(reader);
    assert(readerdata != NULL);

    readerdata->nlinkingcons = SCIPgetNConss(scip);
    readerdata->nlinkingvars = 0;
    nvars = SCIPgetNVars(scip);
    conss = SCIPgetConss(scip);
    nconss = SCIPgetNConss(scip);

    /* alloc: var -> block mapping */
    SCIP_CALL( SCIPallocMemoryArray(scip, &readerdata->varstoblock, nvars) );
    for( i = 0; i < nvars; i ++ )
    {
        readerdata->varstoblock[i] = NOVALUE;
    }

    /* alloc: linkingvar -> blocks mapping */
    SCIP_CALL( SCIPallocMemoryArray(scip, &readerdata->linkingvarsblocks, nvars) );
    SCIP_CALL( SCIPallocMemoryArray(scip, &readerdata->nlinkingvarsblocks, nvars) );
    BMSclearMemoryArray(readerdata->linkingvarsblocks, nvars);
    BMSclearMemoryArray(readerdata->nlinkingvarsblocks, nvars);

    /* cons -> block mapping */
    SCIP_CALL( SCIPhashmapCreate(&readerdata->constoblock, SCIPblkmem(scip), nconss) );
    for( i = 0; i < SCIPgetNConss(scip); i ++ )
    {
        SCIP_CALL( SCIPhashmapInsert(readerdata->constoblock, conss[i], (void*)(size_t) NOVALUE) );
    }


    /* open file */
    blkinput->file = SCIPfopen(filename, "r");
    if( blkinput->file == NULL )
    {
        SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
        SCIPprintSysError(filename);
        return SCIP_NOFILE;
    }

    /* parse the file */
    blkinput->section = BLK_START;
    while( blkinput->section != BLK_END && !hasError(blkinput) )
    {
        switch( blkinput->section )
        {
        case BLK_START:
            SCIP_CALL( readStart(scip, blkinput) );
            break;

        case BLK_PRESOLVED:
            SCIP_CALL( readPresolved(scip, blkinput) );
            if( blkinput->presolved && SCIPgetStage(scip) < SCIP_STAGE_PRESOLVED )
            {
                assert(blkinput->haspresolvesection);
                /** @bug GCG should be able to presolve the problem first */
                SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "decomposition belongs to the presolved problem, please presolve the problem first.\n");
                goto TERMINATE;
            }
            break;

        case BLK_NBLOCKS:
            SCIP_CALL( readNBlocks(scip, blkinput) );
            if( blkinput->haspresolvesection && !blkinput->presolved && SCIPgetStage(scip) >= SCIP_STAGE_PRESOLVED )
            {
                SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "decomposition belongs to the unpresolved problem, please re-read the problem and read the decomposition without presolving.\n");
                goto TERMINATE;
            }
            if( !blkinput->haspresolvesection )
            {
                SCIPwarningMessage(scip, "decomposition has no presolve section at beginning. The behaviour is undefined. See the FAQ for further information.\n");
            }
            break;

        case BLK_BLOCK:
            if( nblocksread == FALSE )
            {
                /* alloc n vars per block */
                SCIP_CALL( SCIPallocMemoryArray(scip, &readerdata->nblockvars, blkinput->nblocks) );
                SCIP_CALL( SCIPallocMemoryArray(scip, &readerdata->nblockcons, blkinput->nblocks) );
                SCIP_CALL( SCIPallocMemoryArray(scip, &readerdata->blockcons, blkinput->nblocks) );
                for( i = 0; i < blkinput->nblocks; ++i )
                {
                    readerdata->nblockvars[i] = 0;
                    readerdata->nblockcons[i] = 0;
                    SCIP_CALL( SCIPallocMemoryArray(scip, &(readerdata->blockcons[i]), nconss) ); /*lint !e866*/
                }
                nblocksread = TRUE;
            }
            SCIP_CALL( readBlock(scip, blkinput, readerdata) );
            break;

        case BLK_MASTERCONSS:
            SCIP_CALL( readMasterconss(scip, blkinput, readerdata) );
            break;

        case BLK_END: /* this is already handled in the while() loop */
        default:
            SCIPerrorMessage("invalid BLK file section <%d>\n", blkinput->section);
            return SCIP_INVALIDDATA;
        }
    }


    SCIP_CALL( DECdecompCreate(scip, &decdecomp) );

    /* fill decomp */
    SCIP_CALL( fillDecompStruct(scip, blkinput, decdecomp, readerdata) );

    /* add decomp to cons_decomp */
    SCIP_CALL( SCIPconshdlrDecompAddDecdecomp(scip, decdecomp) );

    for( i = 0; i < nvars; ++i )
    {
        assert(readerdata->linkingvarsblocks[i] != NULL || readerdata->nlinkingvarsblocks[i] == 0);
        if( readerdata->nlinkingvarsblocks[i] > 0 )
        {
            SCIPfreeMemoryArray(scip, &readerdata->linkingvarsblocks[i]);
        }
    }

TERMINATE:
    if( nblocksread )
    {
        for( i = blkinput->nblocks - 1; i >= 0; --i )
        {
            SCIPfreeMemoryArray(scip, &(readerdata->blockcons[i]));
        }
        SCIPfreeMemoryArray(scip, &readerdata->blockcons);
        SCIPfreeMemoryArray(scip, &readerdata->nblockcons);
        SCIPfreeMemoryArray(scip, &readerdata->nblockvars);
    }

    SCIPhashmapFree(&readerdata->constoblock);

    SCIPfreeMemoryArray(scip, &readerdata->nlinkingvarsblocks);
    SCIPfreeMemoryArray(scip, &readerdata->linkingvarsblocks);
    SCIPfreeMemoryArray(scip, &readerdata->varstoblock);

    /* close file */
    SCIPfclose(blkinput->file);

    return SCIP_OKAY;
}