void V4LFrameSource::updateVideoFormat() { #ifdef USE_V4L struct v4l2_format fmt; uint32_t v4lCode = m_srcFormat.getV4LPixelFormat(); MEMCLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = m_width; fmt.fmt.pix.height = m_height; fmt.fmt.pix.pixelformat = v4lCode; fmt.fmt.pix.field = V4L2_FIELD_NONE; if (xioctl(m_fd, VIDIOC_S_FMT, &fmt) == -1) { throw IOException("Cannot set camera format parameters, invalid resolution?"); } MEMCLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; xioctl(m_fd, VIDIOC_G_FMT, &fmt); // get format information! if ((int)fmt.fmt.pix.bytesperline != PixelFormat::s_calcByteWidth(m_srcFormat, 0, m_width)) { std::cout << "Expected " << PixelFormat::s_calcByteWidth(m_srcFormat, 0, m_width) << " got " << fmt.fmt.pix.bytesperline << " for format " << m_srcFormat.toString() << std::endl; throw IOException("source format bytes/pixel mismatch"); } if (fmt.fmt.pix.pixelformat != v4lCode) { std::cerr << "source format: " << fmt.fmt.pix.pixelformat << " vs: " << m_srcFormat; throw IOException("invalid source format!"); } #endif }
void SignalException ( SLONG code, ULONG count, SLONG subcode, ULONG subcount, ...) { ULONG i; va_list ap; MSGVEC *msgvecP = new MSGVEC; // Initialize the exception codes and argument counts. MEMCLEAR (msgvecP, sizeof(MSGVEC)); msgvecP->code = code; msgvecP->count = count; msgvecP->subcode = subcode; msgvecP->subcount = subcount; // Initialize the arguments. va_start (ap, subcount); for (i = 0; i < count; i++) msgvecP->param[i] = va_arg(ap, ULONG); for (i = 0; i < subcount; i++) msgvecP->subparam[i] = va_arg(ap, ULONG); va_end (ap); // Throw the exception. throw (msgvecP); }
int V4LFrameSource::dequeueBuffer(int *bytesUsed, int64_t *usecs) { #ifdef USE_V4L struct v4l2_buffer buf; MEMCLEAR(buf); buf.index = 0; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; for (int cnt = 0; *bytesUsed == 0 && cnt < 10; cnt++) { if (xioctl(m_fd, VIDIOC_DQBUF, &buf) == -1) { switch (errno) { case EAGAIN: std::cerr << "eagain: " << buf.index << " bu: " << buf.bytesused << std::endl; sleep(1); continue; break; default: throw IOException("VIDIOC_DQBUF err: " + MMUtils::s_errToStr(errno)); } } *bytesUsed = buf.bytesused; *usecs = buf.timestamp.tv_sec * 1000000 + buf.timestamp.tv_usec; } if (*bytesUsed <= 0) { throw IOException("dequeue failed!"); } return (buf.index); #else return -1; #endif }
V4LFrameSource::V4LFrameSource() : m_isOpen(false), m_deviceName(""), m_width(-1), m_height(-1), m_exposureTime(-1), m_frameRate(-1), m_fd(-1), m_numBuffers(1), m_srcFormat(PixelFormat::FMT_YUYV422), m_tgtFormat(PixelFormat::FMT_RGB24), m_converter(), m_lastFrame(), m_framePtrMutex(), m_isRunning(false), m_threadMutex(), m_runningMutex(), m_thread(NULL) { assert(m_numBuffers < VLAB_V4L2_MAX_NUM_BUFFERS); m_converter.setDestFormat(m_tgtFormat); MEMCLEAR(m_buffer); }
STATIC void resizePricer(lprec *lp) { if(!applyPricer(lp)) return; /* Reallocate vector for new size */ lp->edgeVector = (REAL *) realloc(lp->edgeVector, (lp->sum_alloc + 1) * sizeof(*lp->edgeVector)); /* Signal that we have not yet initialized the price vector */ MEMCLEAR(lp->edgeVector, lp->sum_alloc+1); lp->edgeVector[0] = -1; }
void V4LFrameSource::mmapBuffers() { #ifdef USE_V4L struct v4l2_requestbuffers req; MEMCLEAR(req); req.count = m_numBuffers; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; if (xioctl(m_fd, VIDIOC_REQBUFS, &req) == -1) { throw IOException("V4L camera buffer request failed: " + MMUtils::s_errToStr(errno)); } if ((int)req.count < m_numBuffers) { std::cerr << "Not enough buffers! Have " << req.count << " need " << m_numBuffers << std::endl; throw IOException("Not enough buffers for v4l camera"); } for (int i = 0; i < m_numBuffers; i++) { struct v4l2_buffer buf; MEMCLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (xioctl(m_fd, VIDIOC_QUERYBUF, &buf) == -1) { throw IOException("buffer query failed: " + MMUtils::s_errToStr(errno)); } m_buffer[i].size = buf.length; m_buffer[i].ptr = (const char *)mmap (NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd, buf.m.offset); if (!m_buffer[i].ptr) { throw IOException("buffer mmap failed!"); } } #endif }
STATIC MYBOOL resizePricer(lprec *lp) { if(!applyPricer(lp)) return( TRUE ); /* Reallocate vector for new size */ if(!allocREAL(lp, &(lp->edgeVector), lp->sum_alloc+1, AUTOMATIC)) return( FALSE ); /* Signal that we have not yet initialized the price vector */ MEMCLEAR(lp->edgeVector, lp->sum_alloc+1); lp->edgeVector[0] = -1; return( TRUE ); }
void REPORT_constraintinfo(lprec *lp, char *datainfo) { int i, tally[ROWCLASS_MAX+1]; MEMCLEAR(tally, ROWCLASS_MAX+1); for(i = 1; i <= lp->rows; i++) tally[get_constr_class(lp, i)]++; if(datainfo != NULL) report(lp, NORMAL, "%s\n", datainfo); for(i = 0; i <= ROWCLASS_MAX; i++) if(tally[i] > 0) report(lp, NORMAL, "%-15s %4d\n", get_str_constr_class(lp, i), tally[i]); }
void jsi_PstateFree(jsi_Pstate *ps) { /* TODO: when do we free opcodes */ jsi_PstateClear(ps); Jsi_Free(ps->lexer); if (ps->opcodes) jsi_FreeOpcodes(ps->opcodes); if (ps->hPtr) Jsi_HashEntryDelete(ps->hPtr); Jsi_HashDelete(ps->argsTbl); Jsi_HashDelete(ps->strTbl); Jsi_HashDelete(ps->fastVarTbl); MEMCLEAR(ps); Jsi_Free(ps); }
void jsi_UserObjFree(Jsi_Interp *interp, Jsi_UserObj *uobj) { Jsi_UserObjReg *udr =uobj->reg; if (interp != uobj->interp) { Jsi_LogError("UDID bad interp"); return; } if (uobj->hPtr) Jsi_HashEntryDelete(uobj->hPtr); if (udr->freefun) { udr->freefun(interp, uobj->data); } MEMCLEAR(uobj); Jsi_Free(uobj); }
void V4LFrameSource::enqueueBuffer(int bufIdx) { #ifdef USE_V4L struct v4l2_buffer buf; MEMCLEAR(buf); buf.index = 0; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; if (xioctl(m_fd, VIDIOC_QBUF, &buf) == -1) { throw IOException("enqueing buffer failed: " + MMUtils::s_errToStr(errno)); } #endif }
boost::shared_ptr<std::queue<shared::communication::CByteBuffer> > CCamera1::encode(boost::shared_ptr<ISequenceNumberProvider> seqNumberProvider) const { RBUF rbuf; MEMCLEAR(rbuf.CAMERA1); rbuf.CAMERA1.packetlength = ENCODE_PACKET_LENGTH(CAMERA1); rbuf.CAMERA1.packettype = pTypeCamera; rbuf.CAMERA1.subtype = m_subType; rbuf.CAMERA1.seqnbr = seqNumberProvider->next(); rbuf.CAMERA1.housecode = m_houseCode; rbuf.CAMERA1.cmnd = toProtocolState(*m_camera); rbuf.CAMERA1.rssi = 0; rbuf.CAMERA1.filler = 0; return toBufferQueue(rbuf, GET_RBUF_STRUCT_SIZE(CAMERA1)); }
boost::shared_ptr<std::queue<shared::communication::CByteBuffer> > CChime::encode(boost::shared_ptr<ISequenceNumberProvider> seqNumberProvider) const { RBUF rbuf; MEMCLEAR(rbuf.CHIME); rbuf.CHIME.packetlength = ENCODE_PACKET_LENGTH(CHIME); rbuf.CHIME.packettype = pTypeChime; rbuf.CHIME.subtype = m_subType; rbuf.CHIME.seqnbr = seqNumberProvider->next(); m_subTypeManager->idToProtocol(m_id, rbuf.CHIME.id1, rbuf.CHIME.id2, rbuf.CHIME.sound); m_subTypeManager->toProtocolState(rbuf.CHIME.sound); rbuf.CHIME.rssi = 0; rbuf.CHIME.filler = 0; return toBufferQueue(rbuf, GET_RBUF_STRUCT_SIZE(CHIME)); }
void V4LFrameSource::updateCropping() { #ifdef USE_V4L // Reset the cropping struct v4l2_cropcap cropcap; MEMCLEAR(cropcap); if (xioctl(m_fd, VIDIOC_CROPCAP, &cropcap) == 0) { struct v4l2_crop crop; crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; crop.c = cropcap.defrect; /* reset to default */ if (xioctl(m_fd, VIDIOC_S_CROP, &crop) == -1) { throw IOException("Cannot reset V4L camera crop: " + MMUtils::s_errToStr(errno)); } } #endif }
void V4LFrameSource::checkCapabilities() { #ifdef USE_V4L struct v4l2_capability caps; MEMCLEAR(caps); if (xioctl(m_fd, VIDIOC_QUERYCAP, &caps) == -1) { throw IOException("Cannot query V4L camera capabilities!"); } if (!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { throw IOException("V4L device is not a capture device: " + m_deviceName); } if (!(caps.capabilities & V4L2_CAP_STREAMING)) { throw IOException("V4L device is not a streaming device: " + m_deviceName); } #endif }
STATIC MYBOOL allocREAL(lprec *lp, REAL **ptr, int size, MYBOOL clear) { if(clear == TRUE) *ptr = (REAL *) calloc(size, sizeof(**ptr)); else if(clear & AUTOMATIC) { *ptr = (REAL *) realloc(*ptr, size * sizeof(**ptr)); if(clear & TRUE) MEMCLEAR(*ptr, size); } else *ptr = (REAL *) malloc(size * sizeof(**ptr)); if(((*ptr) == NULL) && (size > 0)) { lp->report(lp, CRITICAL, "alloc of %d 'REAL' failed\n", size); lp->spx_status = NOMEMORY; return( FALSE ); } else return( TRUE ); }
boost::shared_ptr<std::queue<shared::communication::CByteBuffer> > CHomeConfort::encode(boost::shared_ptr<ISequenceNumberProvider> seqNumberProvider) const { RBUF rbuf; MEMCLEAR(rbuf.HOMECONFORT); rbuf.HOMECONFORT.packetlength = ENCODE_PACKET_LENGTH(HOMECONFORT); rbuf.HOMECONFORT.packettype = pTypeHomeConfort; rbuf.HOMECONFORT.subtype = m_subType; rbuf.HOMECONFORT.seqnbr = seqNumberProvider->next(); rbuf.HOMECONFORT.id1 = static_cast<unsigned char>((m_id & 0x070000) >> 16); rbuf.HOMECONFORT.id2 = static_cast<unsigned char>((m_id & 0xFF00) >> 8); rbuf.HOMECONFORT.id3 = static_cast<unsigned char>(m_id & 0xFF); rbuf.HOMECONFORT.housecode = m_houseCode; rbuf.HOMECONFORT.unitcode = m_unitCode; rbuf.HOMECONFORT.cmnd = toProtocolState(*m_state); rbuf.HOMECONFORT.rssi = 0; rbuf.HOMECONFORT.filler = 0; return toBufferQueue(rbuf, GET_RBUF_STRUCT_SIZE(HOMECONFORT)); }
boost::shared_ptr<std::queue<shared::communication::CByteBuffer> > CRfy::encode(boost::shared_ptr<ISequenceNumberProvider> seqNumberProvider) const { RBUF rbuf; MEMCLEAR(rbuf.RFY); rbuf.RFY.packetlength = ENCODE_PACKET_LENGTH(RFY); rbuf.RFY.packettype = pTypeRFY; rbuf.RFY.subtype = m_subType; rbuf.RFY.seqnbr = seqNumberProvider->next(); rbuf.RFY.id1 = static_cast<unsigned char>((m_id & 0xFF0000) >> 16); rbuf.RFY.id2 = static_cast<unsigned char>((m_id & 0xFF00) >> 8); rbuf.RFY.id3 = static_cast<unsigned char>(m_id & 0xFF); rbuf.RFY.unitcode = m_unitCode; rbuf.RFY.cmnd = toProtocolState(*m_state); rbuf.RFY.rfu1 = 0; rbuf.RFY.rfu2 = 0; rbuf.RFY.rfu3 = 0; rbuf.RFY.rssi = 0; rbuf.LIGHTING1.filler = 0; return toBufferQueue(rbuf, GET_RBUF_STRUCT_SIZE(RFY)); }
void LUSOL_clear(LUSOLrec *LUSOL, MYBOOL nzonly) { int len; LUSOL->nelem = 0; if(!nzonly) { /* lena arrays */ len = LUSOL->lena + LUSOL_ARRAYOFFSET; MEMCLEAR(LUSOL->a, len); MEMCLEAR(LUSOL->indc, len); MEMCLEAR(LUSOL->indr, len); /* maxm arrays */ len = LUSOL->maxm + LUSOL_ARRAYOFFSET; MEMCLEAR(LUSOL->lenr, len); MEMCLEAR(LUSOL->ip, len); MEMCLEAR(LUSOL->iqloc, len); MEMCLEAR(LUSOL->ipinv, len); MEMCLEAR(LUSOL->locr, len); #ifndef ClassicHamaxR if((LUSOL->amaxr != NULL) #ifdef AlwaysSeparateHamaxR && (LUSOL->luparm[LUSOL_IP_PIVOTTYPE] == LUSOL_PIVMOD_TRP) #endif ) MEMCLEAR(LUSOL->amaxr, len); #endif /* maxn arrays */ len = LUSOL->maxn + LUSOL_ARRAYOFFSET; MEMCLEAR(LUSOL->lenc, len); MEMCLEAR(LUSOL->iq, len); MEMCLEAR(LUSOL->iploc, len); MEMCLEAR(LUSOL->iqinv, len); MEMCLEAR(LUSOL->locc, len); MEMCLEAR(LUSOL->w, len); if(LUSOL->luparm[LUSOL_IP_PIVOTTYPE] == LUSOL_PIVMOD_TCP) { MEMCLEAR(LUSOL->Ha, len); MEMCLEAR(LUSOL->Hj, len); MEMCLEAR(LUSOL->Hk, len); } #ifndef ClassicdiagU if(LUSOL->luparm[LUSOL_IP_KEEPLU] == FALSE) { MEMCLEAR(LUSOL->diagU, len); } #endif } }
MYBOOL __WINAPI guess_basis(lprec *lp, REAL *guessvector, int *basisvector) { MYBOOL *isnz = NULL, status = FALSE; REAL *values = NULL, *violation = NULL, eps = lp->epsprimal, *value, error, upB, loB, sortorder = -1.0; int i, j, jj, n, *rownr, *colnr, *slkpos = NULL, nrows = lp->rows, ncols = lp->columns, nsum = lp->sum; int *basisnr; MATrec *mat = lp->matA; if(!mat_validate(mat)) return( status ); /* Create helper arrays, providing for multiple use of the violation array */ if(!allocREAL(lp, &values, nsum+1, TRUE) || !allocREAL(lp, &violation, nsum+1, TRUE)) goto Finish; /* Compute the values of the constraints for the given guess vector */ i = 0; n = get_nonzeros(lp); rownr = &COL_MAT_ROWNR(i); colnr = &COL_MAT_COLNR(i); value = &COL_MAT_VALUE(i); for(; i < n; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) values[*rownr] += unscaled_mat(lp, my_chsign(is_chsign(lp, *rownr), *value), *rownr, *colnr) * guessvector[*colnr]; MEMMOVE(values+nrows+1, guessvector+1, ncols); /* Initialize bound "violation" or primal non-degeneracy measures, expressed as the absolute value of the differences from the closest bound. */ for(i = 1; i <= nsum; i++) { if(i <= nrows) { loB = get_rh_lower(lp, i); upB = get_rh_upper(lp, i); } else { loB = get_lowbo(lp, i-nrows); upB = get_upbo(lp, i-nrows); } /* Free constraints/variables */ if(my_infinite(lp, loB) && my_infinite(lp, upB)) error = 0; /* Violated constraints/variable bounds */ else if(values[i]+eps < loB) error = loB-values[i]; else if(values[i]-eps > upB) error = values[i]-upB; /* Non-violated constraints/variables bounds */ else if(my_infinite(lp, upB)) error = MAX(0, values[i]-loB); else if(my_infinite(lp, loB)) error = MAX(0, upB-values[i]); else error = MIN(upB-values[i], values[i]-loB); /* MAX(upB-values[i], values[i]-loB); */ if(error != 0) violation[i] = sortorder*error; basisvector[i] = i; } /* Sort decending , meaning that variables with the largest "violations" will be designated basic. Effectively, we are performing a greedy type algorithm, but start at the "least interesting" end. */ sortByREAL(basisvector, violation, nsum, 1, FALSE); error = violation[1]; /* Used for setting the return value */ /* Let us check for obvious row singularities and try to fix these. Note that we reuse the memory allocated to the violation array. First assemble necessary basis statistics... */ slkpos = (int *) violation; n = nrows+1; MEMCLEAR(slkpos, n); isnz = (MYBOOL *) (slkpos+n+1); MEMCLEAR(isnz, n); for(i = 1; i <= nrows; i++) { j = abs(basisvector[i]); if(j <= nrows) { isnz[j] = TRUE; slkpos[j] = i; } else { j-= nrows; jj = mat->col_end[j-1]; jj = COL_MAT_ROWNR(jj); isnz[jj] = TRUE; } } for(; i <= nsum; i++) { j = abs(basisvector[i]); if(j <= nrows) slkpos[j] = i; } /* ...then set the corresponding slacks basic for row rank deficient positions */ for(j = 1; j <= nrows; j++) { if(slkpos[j] == 0) report(lp, SEVERE, "guess_basis: Internal error"); if(!isnz[j]) { isnz[j] = TRUE; i = slkpos[j]; swapINT(&basisvector[i], &basisvector[j]); basisvector[j] = abs(basisvector[j]); } } /* Adjust the non-basic indeces for the (proximal) bound state */ for(i = nrows+1, basisnr = basisvector+i; i <= nsum; i++, basisnr++) { n = *basisnr; if(n <= nrows) { values[n] -= get_rh_lower(lp, n); if(values[n] <= eps) *basisnr = -(*basisnr); } else if(values[n]-eps <= get_lowbo(lp, n-nrows)) *basisnr = -(*basisnr); } /* Lastly normalize all basic variables to be coded as lower-bounded, or effectively zero-based in the case of free variables. */ for(i = 1; i <= nrows; i++) basisvector[i] = -abs(basisvector[i]); /* Clean up and return status */ status = (MYBOOL) (error <= eps); Finish: FREE(values); FREE(violation); return( status ); }
/* ================================================================== lu7for (forward sweep) updates the LU factorization A = L*U when row iw = ip(klast) of U is eliminated by a forward sweep of stabilized row operations, leaving ip * U * iq upper triangular. The row permutation ip is updated to preserve stability and/or sparsity. The column permutation iq is not altered. kfirst is such that row ip(kfirst) is the first row involved in eliminating row iw. (Hence, kfirst marks the first nonzero in row iw in pivotal order.) If kfirst is unknown it may be input as 1. klast is such that row ip(klast) is the row being eliminated. klast is not altered. lu7for should be called only if kfirst .le. klast. If kfirst = klast, there are no nonzeros to eliminate, but the diagonal element of row ip(klast) may need to be moved to the front of the row. ------------------------------------------------------------------ On entry, locc(*) must be zero. On exit: inform = 0 if row iw has a nonzero diagonal (could be small). inform = 1 if row iw has no diagonal. inform = 7 if there is not enough storage to finish the update. On a successful exit (inform le 1), locc(*) will again be zero. ------------------------------------------------------------------ Jan 1985: Final f66 version. 09 May 1988: First f77 version. ================================================================== */ void LU7FOR(LUSOLrec *LUSOL, int KFIRST, int KLAST, int *LENL, int *LENU, int *LROW, int *INFORM, REAL *DIAG) { MYBOOL SWAPPD; int KBEGIN, IW, LENW, LW1, LW2, JFIRST, MINFRE, NFREE, L, J, KSTART, KSTOP, K, LFIRST, IV, LENV, LV1, JLAST, LV2, LV3, LV, JV, LW, LDIAG, LIMIT; REAL AMULT, LTOL, USPACE, SMALL, VJ, WJ; LTOL = LUSOL->parmlu[LUSOL_RP_UPDATEMAX_Lij]; SMALL = LUSOL->parmlu[LUSOL_RP_ZEROTOLERANCE]; USPACE = LUSOL->parmlu[LUSOL_RP_COMPSPACE_U]; KBEGIN = KFIRST; SWAPPD = FALSE; /* We come back here from below if a row interchange is performed. */ x100: IW = LUSOL->ip[KLAST]; LENW = LUSOL->lenr[IW]; if(LENW==0) goto x910; LW1 = LUSOL->locr[IW]; LW2 = (LW1+LENW)-1; JFIRST = LUSOL->iq[KBEGIN]; if(KBEGIN>=KLAST) goto x700; /* Make sure there is room at the end of the row file in case row iw is moved there and fills in completely. */ MINFRE = LUSOL->n+1; NFREE = LUSOL->lena-(*LENL)-(*LROW); if(NFREE<MINFRE) { LU1REC(LUSOL, LUSOL->m,TRUE,LROW,LUSOL->indr,LUSOL->lenr,LUSOL->locr); LW1 = LUSOL->locr[IW]; LW2 = (LW1+LENW)-1; NFREE = LUSOL->lena-(*LENL)-(*LROW); if(NFREE<MINFRE) goto x970; } /* Set markers on row iw. */ for(L = LW1; L <= LW2; L++) { J = LUSOL->indr[L]; LUSOL->locc[J] = L; } /* ================================================================== Main elimination loop. ================================================================== */ KSTART = KBEGIN; KSTOP = MIN(KLAST,LUSOL->n); for(K = KSTART; K <= KSTOP; K++) { JFIRST = LUSOL->iq[K]; LFIRST = LUSOL->locc[JFIRST]; if(LFIRST==0) goto x490; /* Row iw has its first element in column jfirst. */ WJ = LUSOL->a[LFIRST]; if(K==KLAST) goto x490; /* --------------------------------------------------------------- We are about to use the first element of row iv to eliminate the first element of row iw. However, we may wish to interchange the rows instead, to preserve stability and/or sparsity. --------------------------------------------------------------- */ IV = LUSOL->ip[K]; LENV = LUSOL->lenr[IV]; LV1 = LUSOL->locr[IV]; VJ = ZERO; if(LENV==0) goto x150; if(LUSOL->indr[LV1]!=JFIRST) goto x150; VJ = LUSOL->a[LV1]; if(SWAPPD) goto x200; if(LTOL*fabs(WJ)<fabs(VJ)) goto x200; if(LTOL*fabs(VJ)<fabs(WJ)) goto x150; if(LENV<=LENW) goto x200; /* --------------------------------------------------------------- Interchange rows iv and iw. --------------------------------------------------------------- */ x150: LUSOL->ip[KLAST] = IV; LUSOL->ip[K] = IW; KBEGIN = K; SWAPPD = TRUE; goto x600; /* --------------------------------------------------------------- Delete the eliminated element from row iw by overwriting it with the last element. --------------------------------------------------------------- */ x200: LUSOL->a[LFIRST] = LUSOL->a[LW2]; JLAST = LUSOL->indr[LW2]; LUSOL->indr[LFIRST] = JLAST; LUSOL->indr[LW2] = 0; LUSOL->locc[JLAST] = LFIRST; LUSOL->locc[JFIRST] = 0; LENW--; (*LENU)--; if(*LROW==LW2) (*LROW)--; LW2 = LW2-1; /* --------------------------------------------------------------- Form the multiplier and store it in the L file. --------------------------------------------------------------- */ if(fabs(WJ)<=SMALL) goto x490; AMULT = -WJ/VJ; L = LUSOL->lena-(*LENL); LUSOL->a[L] = AMULT; LUSOL->indr[L] = IV; LUSOL->indc[L] = IW; (*LENL)++; /* --------------------------------------------------------------- Add the appropriate multiple of row iv to row iw. We use two different inner loops. The first one is for the case where row iw is not at the end of storage. --------------------------------------------------------------- */ if(LENV==1) goto x490; LV2 = LV1+1; LV3 = (LV1+LENV)-1; if(LW2==*LROW) goto x400; /* ............................................................... This inner loop will be interrupted only if fill-in occurs enough to bump into the next row. ............................................................... */ for(LV = LV2; LV <= LV3; LV++) { JV = LUSOL->indr[LV]; LW = LUSOL->locc[JV]; if(LW>0) { /* No fill-in. */ LUSOL->a[LW] += AMULT*LUSOL->a[LV]; if(fabs(LUSOL->a[LW])<=SMALL) { /* Delete small computed element. */ LUSOL->a[LW] = LUSOL->a[LW2]; J = LUSOL->indr[LW2]; LUSOL->indr[LW] = J; LUSOL->indr[LW2] = 0; LUSOL->locc[J] = LW; LUSOL->locc[JV] = 0; (*LENU)--; LENW--; LW2--; } } else { /* Row iw doesn't have an element in column jv yet so there is a fill-in. */ if(LUSOL->indr[LW2+1]!=0) goto x360; (*LENU)++; LENW++; LW2++; LUSOL->a[LW2] = AMULT*LUSOL->a[LV]; LUSOL->indr[LW2] = JV; LUSOL->locc[JV] = LW2; } } goto x490; /* Fill-in interrupted the previous loop. Move row iw to the end of the row file. */ x360: LV2 = LV; LUSOL->locr[IW] = (*LROW)+1; #ifdef LUSOLFastMove L = LW2-LW1+1; if(L > 0) { int loci, *locp; for(loci = LW1, locp = LUSOL->indr+LW1; loci <= LW2; loci++, locp++) { (*LROW)++; LUSOL->locc[*locp] = *LROW; } LW2 = (*LROW)-L+1; MEMMOVE(LUSOL->a+LW2, LUSOL->a+LW1, L); MEMMOVE(LUSOL->indr+LW2, LUSOL->indr+LW1, L); MEMCLEAR(LUSOL->indr+LW1, L); } #else for(L = LW1; L <= LW2; L++) { (*LROW)++; LUSOL->a[*LROW] = LUSOL->a[L]; J = LUSOL->indr[L]; LUSOL->indr[L] = 0; LUSOL->indr[*LROW] = J; LUSOL->locc[J] = *LROW; } #endif LW1 = LUSOL->locr[IW]; LW2 = *LROW; /* ............................................................... Inner loop with row iw at the end of storage. ............................................................... */ x400: for(LV = LV2; LV <= LV3; LV++) { JV = LUSOL->indr[LV]; LW = LUSOL->locc[JV]; if(LW>0) { /* No fill-in. */ LUSOL->a[LW] += AMULT*LUSOL->a[LV]; if(fabs(LUSOL->a[LW])<=SMALL) { /* Delete small computed element. */ LUSOL->a[LW] = LUSOL->a[LW2]; J = LUSOL->indr[LW2]; LUSOL->indr[LW] = J; LUSOL->indr[LW2] = 0; LUSOL->locc[J] = LW; LUSOL->locc[JV] = 0; (*LENU)--; LENW--; LW2--; } } else { /* Row iw doesn't have an element in column jv yet so there is a fill-in. */ (*LENU)++; LENW++; LW2++; LUSOL->a[LW2] = AMULT*LUSOL->a[LV]; LUSOL->indr[LW2] = JV; LUSOL->locc[JV] = LW2; } } *LROW = LW2; /* The k-th element of row iw has been processed. Reset swappd before looking at the next element. */ x490: SWAPPD = FALSE; } /* ================================================================== End of main elimination loop. ================================================================== Cancel markers on row iw. */ x600: LUSOL->lenr[IW] = LENW; if(LENW==0) goto x910; for(L = LW1; L <= LW2; L++) { J = LUSOL->indr[L]; LUSOL->locc[J] = 0; } /* Move the diagonal element to the front of row iw. At this stage, lenw gt 0 and klast le n. */ x700: for(L = LW1; L <= LW2; L++) { LDIAG = L; if(LUSOL->indr[L]==JFIRST) goto x730; } goto x910; x730: *DIAG = LUSOL->a[LDIAG]; LUSOL->a[LDIAG] = LUSOL->a[LW1]; LUSOL->a[LW1] = *DIAG; LUSOL->indr[LDIAG] = LUSOL->indr[LW1]; LUSOL->indr[LW1] = JFIRST; /* If an interchange is needed, repeat from the beginning with the new row iw, knowing that the opposite interchange cannot occur. */ if(SWAPPD) goto x100; *INFORM = LUSOL_INFORM_LUSUCCESS; goto x950; /* Singular. */ x910: *DIAG = ZERO; *INFORM = LUSOL_INFORM_LUSINGULAR; /* Force a compression if the file for U is much longer than the no. of nonzeros in U (i.e. if lrow is much bigger than lenU). This should prevent memory fragmentation when there is far more memory than necessary (i.e. when lena is huge). */ x950: LIMIT = (int) (USPACE*(*LENU))+LUSOL->m+LUSOL->n+1000; if(*LROW>LIMIT) LU1REC(LUSOL, LUSOL->m,TRUE,LROW,LUSOL->indr,LUSOL->lenr,LUSOL->locr); goto x990; /* Not enough storage. */ x970: *INFORM = LUSOL_INFORM_ANEEDMEM; /* Exit. */ x990: ; }
MYBOOL crash_basis(lprec *lp) { int i; MATrec *mat = lp->matA; MYBOOL ok = TRUE; /* Initialize basis indicators */ if(lp->basis_valid) lp->var_basic[0] = FALSE; else default_basis(lp); /* Set initial partial pricing blocks */ if(lp->rowblocks != NULL) lp->rowblocks->blocknow = 1; if(lp->colblocks != NULL) lp->colblocks->blocknow = ((lp->crashmode == CRASH_NONE) || (lp->colblocks->blockcount == 1) ? 1 : 2); /* Construct a basis that is in some measure the "most feasible" */ if((lp->crashmode == CRASH_MOSTFEASIBLE) && mat_validate(mat)) { /* The logic here follows Maros */ LLrec *rowLL = NULL, *colLL = NULL; int ii, rx, cx, ix, nz; REAL wx, tx, *rowMAX = NULL, *colMAX = NULL; int *rowNZ = NULL, *colNZ = NULL, *rowWT = NULL, *colWT = NULL; REAL *value; int *rownr, *colnr; report(lp, NORMAL, "crash_basis: 'Most feasible' basis crashing selected\n"); /* Tally row and column non-zero counts */ ok = allocINT(lp, &rowNZ, lp->rows+1, TRUE) && allocINT(lp, &colNZ, lp->columns+1, TRUE) && allocREAL(lp, &rowMAX, lp->rows+1, FALSE) && allocREAL(lp, &colMAX, lp->columns+1, FALSE); if(!ok) goto Finish; nz = mat_nonzeros(mat); rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); value = &COL_MAT_VALUE(0); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) { rx = *rownr; cx = *colnr; wx = fabs(*value); rowNZ[rx]++; colNZ[cx]++; if(i == 0) { rowMAX[rx] = wx; colMAX[cx] = wx; colMAX[0] = wx; } else { SETMAX(rowMAX[rx], wx); SETMAX(colMAX[cx], wx); SETMAX(colMAX[0], wx); } } /* Reduce counts for small magnitude to preserve stability */ rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); value = &COL_MAT_VALUE(0); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) { rx = *rownr; cx = *colnr; wx = fabs(*value); #ifdef CRASH_SIMPLESCALE if(wx < CRASH_THRESHOLD * colMAX[0]) { rowNZ[rx]--; colNZ[cx]--; } #else if(wx < CRASH_THRESHOLD * rowMAX[rx]) rowNZ[rx]--; if(wx < CRASH_THRESHOLD * colMAX[cx]) colNZ[cx]--; #endif } /* Set up priority tables */ ok = allocINT(lp, &rowWT, lp->rows+1, TRUE); createLink(lp->rows, &rowLL, NULL); ok &= (rowLL != NULL); if(!ok) goto Finish; for(i = 1; i <= lp->rows; i++) { if(get_constr_type(lp, i)==EQ) ii = 3; else if(lp->upbo[i] < lp->infinite) ii = 2; else if(fabs(lp->rhs[i]) < lp->infinite) ii = 1; else ii = 0; rowWT[i] = ii; if(ii > 0) appendLink(rowLL, i); } ok = allocINT(lp, &colWT, lp->columns+1, TRUE); createLink(lp->columns, &colLL, NULL); ok &= (colLL != NULL); if(!ok) goto Finish; for(i = 1; i <= lp->columns; i++) { ix = lp->rows+i; if(is_unbounded(lp, i)) ii = 3; else if(lp->upbo[ix] >= lp->infinite) ii = 2; else if(fabs(lp->upbo[ix]-lp->lowbo[ix]) > lp->epsmachine) ii = 1; else ii = 0; colWT[i] = ii; if(ii > 0) appendLink(colLL, i); } /* Loop over all basis variables */ for(i = 1; i <= lp->rows; i++) { /* Select row */ rx = 0; wx = -lp->infinite; for(ii = firstActiveLink(rowLL); ii > 0; ii = nextActiveLink(rowLL, ii)) { tx = rowWT[ii] - CRASH_SPACER*rowNZ[ii]; if(tx > wx) { rx = ii; wx = tx; } } if(rx == 0) break; removeLink(rowLL, rx); /* Select column */ cx = 0; wx = -lp->infinite; for(ii = mat->row_end[rx-1]; ii < mat->row_end[rx]; ii++) { /* Update NZ column counts for row selected above */ tx = fabs(ROW_MAT_VALUE(ii)); ix = ROW_MAT_COLNR(ii); #ifdef CRASH_SIMPLESCALE if(tx >= CRASH_THRESHOLD * colMAX[0]) #else if(tx >= CRASH_THRESHOLD * colMAX[ix]) #endif colNZ[ix]--; if(!isActiveLink(colLL, ix) || (tx < CRASH_THRESHOLD * rowMAX[rx])) continue; /* Now do the test for best pivot */ tx = my_sign(lp->orig_obj[ix]) - my_sign(ROW_MAT_VALUE(ii)); tx = colWT[ix] + CRASH_WEIGHT*tx - CRASH_SPACER*colNZ[ix]; if(tx > wx) { cx = ix; wx = tx; } } if(cx == 0) break; removeLink(colLL, cx); /* Update row NZ counts */ ii = mat->col_end[cx-1]; rownr = &COL_MAT_ROWNR(ii); value = &COL_MAT_VALUE(ii); for(; ii < mat->col_end[cx]; ii++, rownr += matRowColStep, value += matValueStep) { wx = fabs(*value); ix = *rownr; #ifdef CRASH_SIMPLESCALE if(wx >= CRASH_THRESHOLD * colMAX[0]) #else if(wx >= CRASH_THRESHOLD * rowMAX[ix]) #endif rowNZ[ix]--; } /* Set new basis variable */ set_basisvar(lp, rx, lp->rows+cx); } /* Clean up */ Finish: FREE(rowNZ); FREE(colNZ); FREE(rowMAX); FREE(colMAX); FREE(rowWT); FREE(colWT); freeLink(&rowLL); freeLink(&colLL); } /* Construct a basis that is in some measure the "least degenerate" */ else if((lp->crashmode == CRASH_LEASTDEGENERATE) && mat_validate(mat)) { /* The logic here follows Maros */ LLrec *rowLL = NULL, *colLL = NULL; int ii, rx, cx, ix, nz, *merit = NULL; REAL *value, wx, hold, *rhs = NULL, *eta = NULL; int *rownr, *colnr; report(lp, NORMAL, "crash_basis: 'Least degenerate' basis crashing selected\n"); /* Create temporary arrays */ ok = allocINT(lp, &merit, lp->columns + 1, FALSE) && allocREAL(lp, &eta, lp->rows + 1, FALSE) && allocREAL(lp, &rhs, lp->rows + 1, FALSE); createLink(lp->columns, &colLL, NULL); createLink(lp->rows, &rowLL, NULL); ok &= (colLL != NULL) && (rowLL != NULL); if(!ok) goto FinishLD; MEMCOPY(rhs, lp->orig_rhs, lp->rows + 1); for(i = 1; i <= lp->columns; i++) appendLink(colLL, i); for(i = 1; i <= lp->rows; i++) appendLink(rowLL, i); /* Loop until we have found enough new bases */ while(colLL->count > 0) { /* Tally non-zeros matching in RHS and each active column */ nz = mat_nonzeros(mat); rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); ii = 0; MEMCLEAR(merit, lp->columns + 1); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep) { rx = *rownr; cx = *colnr; if(isActiveLink(colLL, cx) && (rhs[rx] != 0)) { merit[cx]++; ii++; } } if(ii == 0) break; /* Find maximal match; break ties with column length */ i = firstActiveLink(colLL); cx = i; for(i = nextActiveLink(colLL, i); i != 0; i = nextActiveLink(colLL, i)) { if(merit[i] >= merit[cx]) { if((merit[i] > merit[cx]) || (mat_collength(mat, i) > mat_collength(mat, cx))) cx = i; } } /* Determine the best pivot row */ i = mat->col_end[cx-1]; nz = mat->col_end[cx]; rownr = &COL_MAT_ROWNR(i); value = &COL_MAT_VALUE(i); rx = 0; wx = 0; MEMCLEAR(eta, lp->rows + 1); for(; i < nz; i++, rownr += matRowColStep, value += matValueStep) { ix = *rownr; hold = *value; eta[ix] = rhs[ix] / hold; hold = fabs(hold); if(isActiveLink(rowLL, ix) && (hold > wx)) { wx = hold; rx = ix; } } /* Set new basis variable */ if(rx > 0) { /* We have to update the rhs vector for the implied transformation in order to be able to find the new RHS non-zero pattern */ for(i = 1; i <= lp->rows; i++) rhs[i] -= wx * eta[i]; rhs[rx] = wx; /* Do the exchange */ set_basisvar(lp, rx, lp->rows+cx); removeLink(rowLL, rx); } removeLink(colLL, cx); } /* Clean up */ FinishLD: FREE(merit); FREE(rhs); freeLink(&rowLL); freeLink(&colLL); } return( ok ); }
main(int argc, char *argv[]) { CDWriter *cdwriterP; RECORDOPTIONS options; FILEHANDLE image_file; UWORD display_speed; ULONG offset, datalen, data_blkcnt; // Enable exception handling. EXCEPTION_HANDLER_START // Get the environment variables. GetEnvironmentVariables (); // Parse the command line arguments. ParseCommandLine (argc, argv); // Register the event callback function. EventRegisterCallback (ConsoleEventCallback); // Startup the ASPI manager. ASPIAdapter::StartupManager (FALSE, FALSE, TRUE); // Find a CD-R device... if (cdwriter_id_specified) { if ((cdwriterP = (CDWriter *)ASPIAdapter::FindDeviceObject ( ASPI_M_DEVTYPE_WORM, cdwriter_adapter, cdwriter_id, cdwriter_lun)) == NULL) { fprintf (stderr, "\nError: Specified device (%u:%u:%u) is not a CD-Recorder or is unknown!\n", cdwriter_adapter, cdwriter_id, cdwriter_lun); exit (1); } } else { if ((cdwriterP = (CDWriter *)ASPIAdapter::FindDeviceObject (ASPI_M_DEVTYPE_WORM)) == NULL) { fprintf (stderr, "\nError: Unable to find a known CD-Recorder device!\n"); exit (1); } } if (log_flag) { printf ("CD-Recorder device found...\n"); printf (" HA #%u - ASPI ID #%u - %-8s %-16s %-4s\n", cdwriterP->GetAdapter(), cdwriterP->GetId(), cdwriterP->GetVendorId(), cdwriterP->GetProductId(), cdwriterP->GetFirmwareLevel()); } // Prompt the user to continue? if (confirm_flag) { printf ("\n"); if (test_flag) printf ("TEST recording mode is enabled!\n"); printf ("Hit <ENTER> to begin recording (or CTRL/C to exit)..."); getchar(); } if (log_flag) printf ("\n"); // Initialize the recording options. MEMCLEAR (&options, sizeof(RECORDOPTIONS)); options.speed = record_speed; options.disc_datatype = DATATYPE_CDDA; options.close_session_flag = close_session_flag; options.multisession_flag = multisession_flag; options.test_flag = test_flag; options.underrun_protect_flag = underrun_protect_flag; options.beep_flag = beep_flag; options.eject_flag = eject_flag; options.log_flag = log_flag; // Record the image file using track-at-once recording. cdwriterP->RecordTrackAtOnce ( image_filnam, filetype, DATATYPE_CDDA, SECTOR_CDDA_BLKLEN, &options); // Success. if (log_flag) printf ("\nCD successfully recorded!\n"); // Shutdown the ASPI manager. ASPIAdapter::ShutdownManager(); // End exception handling. EXCEPTION_HANDLER_EXIT return (0); }
MYBOOL __WINAPI guess_basis(lprec *lp, REAL *guessvector, int *basisvector) { MYBOOL *isnz, status = FALSE; REAL *values = NULL, *violation = NULL, eps = lp->epsprimal, *value, error, upB, loB, sortorder = 1.0; int i, j, jj, n, *rownr, *colnr, *slkpos, nrows = lp->rows, ncols = lp->columns; MATrec *mat = lp->matA; if(!mat_validate(mat)) return( status ); /* Create helper arrays */ if(!allocREAL(lp, &values, lp->sum+1, TRUE) || !allocREAL(lp, &violation, lp->sum+1, TRUE)) goto Finish; /* Compute values of slack variables for given guess vector */ i = 0; n = get_nonzeros(lp); rownr = &COL_MAT_ROWNR(i); colnr = &COL_MAT_COLNR(i); value = &COL_MAT_VALUE(i); for(; i < n; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) values[*rownr] += unscaled_mat(lp, my_chsign(is_chsign(lp, *rownr), *value), *rownr, *colnr) * guessvector[*colnr]; MEMMOVE(values+nrows+1, guessvector+1, ncols); /* Initialize constraint bound violation measures (expressed as positive values) */ for(i = 1; i <= nrows; i++) { upB = get_rh_upper(lp, i); loB = get_rh_lower(lp, i); error = values[i] - upB; if(error > -eps) violation[i] = sortorder*MAX(0,error); else { error = loB - values[i]; if(error > -eps) violation[i] = sortorder*MAX(0,error); else if(my_infinite(lp, loB) && my_infinite(lp, upB)) ; else if(my_infinite(lp, upB)) violation[i] = sortorder*(loB - values[i]); else if(my_infinite(lp, loB)) violation[i] = sortorder*(values[i] - upB); else violation[i] = -sortorder*MAX(upB - values[i], values[i] - loB); } basisvector[i] = i; } /* Initialize user variable bound violation measures (expressed as positive values) */ for(i = 1; i <= ncols; i++) { n = nrows+i; upB = get_upbo(lp, i); loB = get_lowbo(lp, i); error = guessvector[i] - upB; if(error > -eps) violation[n] = sortorder*MAX(0,error); else { error = loB - values[n]; if(error > -eps) violation[n] = sortorder*MAX(0,error); else if(my_infinite(lp, loB) && my_infinite(lp, upB)) ; else if(my_infinite(lp, upB)) violation[n] = sortorder*(loB - values[n]); else if(my_infinite(lp, loB)) violation[n] = sortorder*(values[n] - upB); else violation[n] = -sortorder*MAX(upB - values[n], values[n] - loB); } basisvector[n] = n; } /* Sort decending by violation; this means that variables with the largest violations will be designated as basic */ sortByREAL(basisvector, violation, lp->sum, 1, FALSE); error = violation[1]; /* Adjust the non-basic indeces for the (proximal) bound state */ for(i = nrows+1, rownr = basisvector+i; i <= lp->sum; i++, rownr++) { if(*rownr <= nrows) { values[*rownr] -= lp->orig_rhs[*rownr]; if(values[*rownr] <= eps) *rownr = -(*rownr); } else if(values[i] <= get_lowbo(lp, (*rownr)-nrows)+eps) *rownr = -(*rownr); } /* Let us check for obvious row singularities and try to fix these; First assemble necessary basis statistics... */ isnz = (MYBOOL *) values; MEMCLEAR(isnz, nrows+1); slkpos = (int *) violation; MEMCLEAR(slkpos, nrows+1); for(i = 1; i <= nrows; i++) { j = abs(basisvector[i]); if(j <= nrows) { isnz[j] = TRUE; slkpos[j] = i; } else { j-= nrows; jj = mat->col_end[j-1]; isnz[COL_MAT_ROWNR(jj)] = TRUE; /* if(++jj < mat->col_end[j]) isnz[COL_MAT_ROWNR(jj)] = TRUE; */ } } for(; i <= lp->sum; i++) { j = abs(basisvector[i]); if(j <= nrows) slkpos[j] = i; } /* ...then set the corresponding slacks basic for row rank deficient positions */ for(j = 1; j <= nrows; j++) { #ifdef Paranoia if(slkpos[j] == 0) report(lp, SEVERE, "guess_basis: Internal error"); #endif if(!isnz[j]) { isnz[j] = TRUE; i = slkpos[j]; swapINT(&basisvector[i], &basisvector[j]); basisvector[j] = abs(basisvector[j]); } } /* Lastly normalize all basic variables to be coded as lower-bounded */ for(i = 1; i <= nrows; i++) basisvector[i] = -abs(basisvector[i]); /* Clean up and return status */ status = (MYBOOL) (error <= eps); Finish: FREE(values); FREE(violation); return( status ); }
main(int argc, char *argv[]) { #define SECTOR_MODE1_BLKLEN 2048 #define SECTOR_RAW_BLKLEN 2352 ULONG filelen, data_blkcnt, blk; UWORD cur_percent = 0; FILE *isofile, *rawfile; SECTORSUBHEADER subheader; // Parse the command line arguments. ParseCommandLine (argc, argv); // Allocate input and output buffers. IOBUF *inbufP = new IOBUF; IOBUF *outbufP = new IOBUF; // Open the input ISO file. if ((isofile = fopen (isofilnam, "rb")) == NULL) { fprintf (stderr, "Error opening \"%s\"\n", isofilnam); exit (1); } // Create the output RAW file. if ((rawfile = fopen (rawfilnam, "wb")) == NULL) { fprintf (stderr, "Error creating \"%s\"\n", rawfilnam); exit (1); } // Get the length of the input file and make sure that it is // a multiple of 2048 bytes. filelen = filelength (fileno (isofile)); if (filelen % SECTOR_MODE1_BLKLEN) { fprintf (stderr, "Error: Input file length is not a multiple of 2048!\n"); exit (1); } data_blkcnt = filelen / SECTOR_MODE1_BLKLEN; printf ("File contains %luMb of data (%lu blocks)\n", CDIV (filelen, 0x100000), data_blkcnt); // Calculate the I/O lengths (base this on the amount of data // that can be written from the output buffer). UWORD blocks_per_io = sizeof(outbufP->data) / SECTOR_RAW_BLKLEN; // Convert the ISO file to a RAW (2352 byte sector) file. SLONG lba = 0; ULONG blocks_written = 0; printf ("Processing...\n"); printf (" 0%% completed.\r"); for (blk = 0; blk < data_blkcnt; blk += blocks_per_io) { UWORD blocks = MIN (blocks_per_io, data_blkcnt - blk); // Read the ISO file. if (fread (inbufP->data, SECTOR_MODE1_BLKLEN, blocks, isofile) != blocks) { fprintf (stderr, "\nUnexpected error reading input file!\n"); exit (1); } // If the sector type is MODE2 FORM1, then generate a default subheader. if (sectortype == SECTORTYPE_MODE2FORM1) { MEMCLEAR (&subheader, sizeof(SECTORSUBHEADER)); subheader.submode.data_flag = TRUE; } // Convert the blocks to raw CDROM sectors. UBYTE *dataP = (UBYTE *)inbufP->data; CDSector *sectorP = (CDSector *)outbufP->data; for (UWORD b = 0; b < blocks; b++) { sectorP->Format ( sectortype, lba, &subheader, dataP, TRUE, FALSE, scramble_flag); dataP += SECTOR_MODE1_BLKLEN; sectorP++; lba++; } // Write the buffer to the output file. if (fwrite (outbufP->data, sizeof(CDSector), blocks, rawfile) != blocks) { fprintf (stderr, "\nUnexpected error writing output file!\n"); exit (1); } // Increment the number of blocks written. blocks_written += blocks; // Percent complete status change? UWORD percent = (blocks_written * 100) / data_blkcnt; if (percent > cur_percent) { printf (" %u%% completed.\r", percent); cur_percent = percent; } } printf ("Conversion completed!\n"); // Write postgap? if (postgap_flag) { printf ("Writing POSTGAP (150 blocks)..."); CDSector *sectorP = (CDSector *)outbufP->data; for (int i = 0; i < 150; i++) { sectorP->Format ( sectortype, lba++, NULL, NULL, TRUE, FALSE, scramble_flag); if (fwrite (sectorP, sizeof(CDSector), 1, rawfile) != 1) { fprintf (stderr, "\nUnexpected error writing output file!\n"); exit (1); } } printf ("\n"); } // Close the files. fclose (isofile); fclose (rawfile); // Free the I/O buffers. delete inbufP; delete outbufP; return (0); }
/* ================================================================== lu7add inserts the first nrank elements of the vector v(*) as column jadd of U. We assume that U does not yet have any entries in this column. Elements no larger than parmlu(3) are treated as zero. klast will be set so that the last row to be affected (in pivotal order) is row ip(klast). ------------------------------------------------------------------ 09 May 1988: First f77 version. ================================================================== */ void LU7ADD(LUSOLrec *LUSOL, int JADD, REAL V[], int LENL, int *LENU, int *LROW, int NRANK, int *INFORM, int *KLAST, REAL *VNORM) { REAL SMALL; int K, I, LENI, MINFRE, NFREE, LR1, LR2, L; #ifndef LUSOLFastMove int J; #endif SMALL = LUSOL->parmlu[LUSOL_RP_ZEROTOLERANCE]; *VNORM = ZERO; *KLAST = 0; for(K = 1; K <= NRANK; K++) { I = LUSOL->ip[K]; if(fabs(V[I])<=SMALL) continue; *KLAST = K; (*VNORM) += fabs(V[I]); LENI = LUSOL->lenr[I]; /* Compress row file if necessary. */ MINFRE = LENI+1; NFREE = LUSOL->lena - LENL - *LROW; if(NFREE<MINFRE) { LU1REC(LUSOL, LUSOL->m, TRUE,LROW,LUSOL->indr,LUSOL->lenr,LUSOL->locr); NFREE = LUSOL->lena - LENL - *LROW; if(NFREE<MINFRE) goto x970; } /* Move row i to the end of the row file, unless it is already there. No need to move if there is a gap already. */ if(LENI==0) LUSOL->locr[I] = (*LROW) + 1; LR1 = LUSOL->locr[I]; LR2 = (LR1+LENI)-1; if(LR2==*LROW) goto x150; if(LUSOL->indr[LR2+1]==0) goto x180; LUSOL->locr[I] = (*LROW) + 1; #ifdef LUSOLFastMove L = LR2-LR1+1; if(L > 0) { LR2 = (*LROW)+1; MEMMOVE(LUSOL->a+LR2, LUSOL->a+LR1, L); MEMMOVE(LUSOL->indr+LR2, LUSOL->indr+LR1, L); MEMCLEAR(LUSOL->indr+LR1, L); *LROW += L; } #else for(L = LR1; L <= LR2; L++) { (*LROW)++; LUSOL->a[*LROW] = LUSOL->a[L]; J = LUSOL->indr[L]; LUSOL->indr[L] = 0; LUSOL->indr[*LROW] = J; } #endif x150: LR2 = *LROW; (*LROW)++; /* Add the element of v. */ x180: LR2++; LUSOL->a[LR2] = V[I]; LUSOL->indr[LR2] = JADD; LUSOL->lenr[I] = LENI+1; (*LENU)++; } /* Normal exit. */ *INFORM = LUSOL_INFORM_LUSUCCESS; goto x990; /* Not enough storage. */ x970: *INFORM = LUSOL_INFORM_ANEEDMEM; x990: ; }