void CEle_Power_DecomposeView::OnFileOpen() { static char BASED_CODE szFilter[] = "DataBase Files (*.mdb)|*.mdb; *.mdb|All Files (*.*)|*.*||"; CFileDialog DataRead(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs "mdb", NULL, OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT, szFilter, NULL); char DirectPath[MAX_PATH]; GetCurrentDirectory( MAX_PATH, DirectPath); if(IDOK == DataRead.DoModal()) { CString szFileName = DataRead.GetPathName(); if(szFileName.IsEmpty()) return; CEle_Power_DecomposeDoc* pDoc = GetDocument(); pDoc->SetTitle(DataRead.GetFileName()); ReadFromMDB(szFileName); } SetCurrentDirectory(DirectPath); }
/* Procedure servicing the ioctl */ long c2_ioctl (struct file *filp, unsigned int cmd, unsigned long arg) { //TODO: Locking is probably required since we don't run under BKL anymore. // Although it isn't possible to open the c2 device twice, a single // process with multiple threads might be abble to issue simultaneous // ioctls() --DI long buf; unsigned char cbuf; int err=0,ret; if (_IOC_TYPE(cmd) != C2_IOC_MAGIC) return -ENOTTY; if (_IOC_NR(cmd) > C2_IOC_MAXNR) return -ENOTTY; if (_IOC_DIR(cmd) & _IOC_READ) err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd)); else if (_IOC_DIR(cmd) & _IOC_WRITE) err = !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd)); if (err) return -EFAULT; switch(_IOC_NR(cmd)) { case _IOC_NR(C2_IOCRESET): //printk(KERN_ERR "C2_IOCRESET"); C2CK_reset(); return 0; case _IOC_NR(C2_IOCAWRITE): ret = __get_user(cbuf, (unsigned char *)arg); //printk(KERN_ERR "C2_IOCAWRITE: address=%u\n", cbuf); AddressWrite(cbuf); return ret; case _IOC_NR(C2_IOCDWRITE): ret = __get_user(buf, (long *)arg); //printk(KERN_ERR "C2_IOCDWRITE: len=%u, data=%u\n", (_IOC_SIZE(cmd)-1) & 3, buf); return DataWrite((_IOC_SIZE(cmd)-1) & 3, buf); case _IOC_NR(C2_IOCAREAD): cbuf=AddressRead(); //printk(KERN_ERR "C2_IOCAREAD: address=%u\n", cbuf); ret = __put_user(cbuf, (unsigned char *)arg); return ret; case _IOC_NR(C2_IOCDREAD): ret = DataRead((_IOC_SIZE(cmd)-1) & 3, &buf); if(ret) return ret; //printk(KERN_ERR "C2_IOCDREAD: len=%u, data=%u\n", (_IOC_SIZE(cmd)-1) & 3, buf); ret = __put_user(buf, (long *)arg); return ret; case _IOC_NR(C2_IOCQRESET): //printk(KERN_ERR "C2_IOCQRESET"); C2CK_ENA(); C2CK_low_pulse(); /* a "quick reset" is just a low pulse, less than 20us */ C2CK_DIS(); return 0; case _IOC_NR(C2_IOCIRQCHK): //printk(KERN_ERR "C2_IOCIRQCHK"); return CheckForInterrupts(); default: return -ENOTTY; } }
/*-----------------------------------------------------------------------------------------------------------------------*/ void *AcquireData(gpointer Data) //Data acquisition thread triggered by StartCallBack { gulong Curr[4],Prev[4]; gint Overflow[4]; gdouble Rate[4]; gint i,Period; FILE *Fp; struct timeval Tv; gdouble StartTime,ElapsedTime,Delta,TimeNow,TimePrev; time_t DateTime; gchar Str[120]; if (InitCamac()) { SAttention("Could not initialise CAMAC\nCheck if crate is on"); AcqOn=FALSE; pthread_exit(NULL); } if (!(Fp=fopen(RunName,"w"))) { SAttention("Could not open output file\nCheck disk full, file permissions"); AcqOn=FALSE; pthread_exit(NULL); } CamacZ(); Period=0; for (i=0;i<NScalers;++i) { Prev[i]=0; Overflow[i]=0; } gettimeofday(&Tv,NULL); StartTime=(gdouble)Tv.tv_sec+(gdouble)Tv.tv_usec*1.0e-06; TimePrev=StartTime; DateTime=time(NULL); sprintf(Str,"%s Started:%s",RunName,ctime(&DateTime)); gdk_threads_enter(); gtk_label_set_text(GTK_LABEL(S_Start),Str); gdk_threads_leave(); fprintf(Fp,"%s Started:%s",RunName,ctime(&DateTime)); fprintf(Fp," Elapsed Scaler1 Rate1 Scaler2 Rate2 Scaler3 Rate3 Scaler4 Rate4\n"); while (TRUE) { while (TRUE) { gettimeofday(&Tv,NULL); TimeNow=(gdouble)Tv.tv_sec+(gdouble)Tv.tv_usec*1.0e-06; Delta=TimeNow-TimePrev; if (Delta >= (gdouble)Interval[Period]) { TimePrev=TimeNow; break; } if (StopSignal) break; } for (i=0;i<NScalers;++i) { CamacNAF(StnNo,SubA[i],0); Curr[i]=DataRead()+Overflow[i]*SCALER_OVERFLOW; if (Curr[i]<Prev[i]) { ++Overflow[i]; Curr[i]+=SCALER_OVERFLOW; } if (Delta>0.0) Rate[i]=(Curr[i]-Prev[i])/Delta; Prev[i]=Curr[i]; } ElapsedTime=TimeNow-StartTime; if (ElapsedTime>(gdouble)Duration[0]) Period=1; if (ElapsedTime>(gdouble)(Duration[0]+Duration[1])) Period=2; sprintf(Str,"%08.2f",ElapsedTime); gdk_threads_enter(); gtk_text_insert(GTK_TEXT(S_Output),NULL,NULL,NULL,Str,-1); gdk_threads_leave(); fprintf(Fp,"%8.2f",ElapsedTime); for (i=0;i<NScalers;++i) { sprintf(Str," %010ld %010.2f",Curr[i],Rate[i]); gdk_threads_enter(); gtk_text_insert(GTK_TEXT(S_Output),NULL,NULL,NULL,Str,-1); gdk_threads_leave(); } for (i=0;i<NScalers;++i) fprintf(Fp," %10ld %10.2f",Curr[i],Rate[i]); gdk_threads_enter(); gtk_text_insert(GTK_TEXT(S_Output),NULL,NULL,NULL,"\n",-1); gdk_threads_leave(); fprintf(Fp,"\n"); if (StopSignal) break; } DateTime=time(NULL); sprintf(Str,"%s Stopped:%s",RunName,ctime(&DateTime)); gdk_threads_enter(); gtk_text_insert(GTK_TEXT(S_Output),NULL,NULL,NULL,"--------------------------------------------------------------------------------------------------------------------------------------------------------\n",-1); gtk_label_set_text(GTK_LABEL(S_Stop),Str); gdk_threads_leave(); fprintf(Fp,"%s Stopped:%s",RunName,ctime(&DateTime)); AcqOn=FALSE; FinishCamac(); fclose(Fp); pthread_exit(NULL); }
/* * Perform quality clipping on an individual contig. * This identifies low quality regions at the ends of contigs and clips them * * Note that this can produce holes, which need to be fixed by the fix_holes() * function, and can also reorder the readings. */ static int quality_clip_contig(GapIO *io, int contig, int start, int end, int qual_avg, int *old_start, int *old_end) { int rnum; int win_len = 31; /* odd num */ int i, i_end; int left, right; GReadings r; int1 *conf = NULL; int conf_alloc = 10000; /* realloced as needed */ int total; int qual_tot, win_len2; qual_tot = win_len * qual_avg; win_len2 = win_len / 2; if (NULL == (conf = (int1 *)xmalloc(conf_alloc))) return -1; /* Find start reading */ for (rnum = io_clnbr(io, contig); io_relpos(io, rnum) < start; rnum = io_rnbr(io, rnum)) ; /* * Loop through readings up to 'end' position. * The leftmost and rightmost sequences need to be treated specially * as we do not want to clip these. Doing so will change the length of the * consensus. Doing that means that we need to deal with consensus tags * (shifting, clipping and deleting them). */ for (; rnum && io_relpos(io, rnum) <= end; rnum = io_rnbr(io, rnum)) { /* Find left and right clip points */ gel_read(io, rnum, r); if (r.length < win_len) continue; /* Realloc conf if necessary */ if (r.length > conf_alloc) { int1 *conf2; conf_alloc = r.length + 100; conf2 = (int1 *)xrealloc(conf, conf_alloc); if (!conf2) { xfree(conf); return -1; } conf = conf2; } if (DataRead(io, r.confidence, conf, r.length * sizeof(*conf), sizeof(*conf))) continue; /* Clip left by quality */ if (rnum != io_clnbr(io, contig)) { total = 0; for (i = 0; i < win_len; i++) total += conf[i]; if (total > qual_tot) { i = r.start; } else { i_end = r.length - win_len2 - 1; i = win_len2 + 1; do { total += conf[i + win_len2] - conf[i - win_len2 - 1]; i++; } while (total < qual_tot && i < i_end); i--; } left = MAX(i, r.start); } else { left = r.start; } /* Clip right by quality */ if (r.position + r.sequence_length <= io_clength(io, contig)) { total = 0; for (i = 0; i < win_len; i++) total += conf[r.length - i - 1]; if (total > qual_tot) { i = r.end; } else { i = r.length - win_len2 - 2; i_end = win_len2 + 1; do { total += conf[i - win_len2] - conf[i + win_len2 + 1]; i--; } while (total < qual_tot && i > i_end); i++; } right = MIN(i, r.end); } else { right = r.end; } if (left >= r.end - 1) left = r.end - 2; if (right <= r.start + 1) right = r.start + 2; if (right < left + 2) right = left + 2; /* printf("Gel %d: L %d->%d R %d->%d\n", rnum, r.start, left, r.end, right); */ r.position += left - r.start; old_start[rnum] = r.start; old_end[rnum] = r.end; r.start = left; r.end = right; r.sequence_length = r.end - r.start - 1; gel_write(io, rnum, r); io_relpos(io, rnum) = r.position; io_length(io, rnum) = r.sense ? -r.sequence_length : r.sequence_length; } xfree(conf); return 0; }
//+------------------------------------------------------------------+ //| Main data reading function | //+------------------------------------------------------------------+ int CSourceInterface::Read(FeedData *inf) { DWORD ctm; //---- check if(inf==NULL || m_buffer==NULL) return(FALSE); inf->ticks_count=0; //---- есть синтетические инструменты? if(m_syntetics.GetTicks(inf)!=FALSE) return(TRUE); //---- is connection opened? if(m_socket==INVALID_SOCKET) { //---- try connect if(Connect(m_server,m_login,m_password)==FALSE) { _snprintf(inf->result_string,sizeof(inf->result_string)-1,"no connection %s",m_server); inf->result=FALSE; return(FALSE); } //if(Login(inf)==FALSE) return(FALSE); } //---- is login succesful? //if(m_loginflag==FALSE) //if(Login(inf)==FALSE) return(FALSE); //---- read data while(m_socket!=INVALID_SOCKET) { //---- send ping every minute ctm=GetTickCount(); if(ctm<m_lasttime) m_lasttime=ctm-1000; // проверка перехода через 49 дней if((ctm-m_lasttime)>60000) { //---- заодно загрузим базу синтетических инструментов m_syntetics.Load(); //---- m_lasttime=ctm; if(SendString("> Ping\r\n")==FALSE) { strcpy(inf->result_string,"ping failed"); ExtLogger.Out("Read: %s",inf->result_string); return(FALSE); } } //---- check data if(DataRead()==FALSE) { COPY_STR(inf->result_string,"connection lost"); ExtLogger.Out("Read: %s",inf->result_string); return(FALSE); } //---- parse while we can read strings while(DataParseLine(m_buffer,BUFFER_SIZE-1)) { //---- it is news? if(memcmp(m_buffer,"< News",6)==0) return ReadNews(inf); //---- skip service information if(m_buffer[0]=='<' || m_buffer[0]=='>') continue; //---- parse ticks if(ReadTicks(m_buffer,inf)==FALSE) return(FALSE); //---- check free space for new account if(inf->ticks_count<COUNTOF(inf->ticks)) continue; //---- break parsing break; } //---- check ticks if(inf->ticks_count>0) { //---- update syntetics m_syntetics.AddQuotes(inf); //---- return data to server return(TRUE); } //---- Sleep(10); } //---- some error return(TRUE); }
/** Process asynchronous requests */ TInt DCrashDriverChannel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2) { Kern::Printf("DCrashDriverChannel::DoRequest"); TInt err = KErrNone; switch(aReqNo) { case RKernelCrashDrv::EPrefetchAbort: { err = StartInfLoop(); if(err != KErrNone) return err; PrefetchAbort(); break; } case RKernelCrashDrv::EDataRead: { err = StartInfLoop(); if(err != KErrNone) return err; DataRead(); break; } case RKernelCrashDrv::EDataWrite: { err = StartInfLoop(); if(err != KErrNone) return err; DataWrite(); break; } case RKernelCrashDrv::EUndefInst: { err = StartInfLoop(); if(err != KErrNone) return err; UndefinedInst(); break; } case RKernelCrashDrv::EDivByZero: { err = StartInfLoop(); if(err != KErrNone) return err; DivByZero(); break; } case RKernelCrashDrv::EStackOverflow: { err = StartInfLoop(); if(err != KErrNone) return err; StackOverFlow(); break; } case RKernelCrashDrv::ETestSCMConfigInsertMethod: { //read the argmuents HBuf8* tmp = HBuf8::New(KMaxBufferSize); TInt err = Kern::ThreadDesRead(iClient, a2, *tmp, 0, 0 ); if (err != KErrNone || tmp->MaxLength() < KMaxBufferSize) { Kern::Printf("Unable to read argument or buffer too small"); // We could not read information from the user, so the a2 argument is probably wrong Kern::RequestComplete(iClient, aStatus, KErrArgument); return KErrArgument; } //run the test and gather the results TBool pass; //run test //TestConfigInsertL(pass, *tmp); //write the results back to client thread err = Kern::ThreadRawWrite(iClient, a1, (TUint8*)&pass, sizeof(TBool), iClient); if(err != KErrNone) { Kern::Printf("Unable to write data back to client"); // We could not read information from the user, so the a2 argument is probably wrong Kern::RequestComplete(iClient, aStatus, KErrArgument); return err; } //and write the buffer back... err = Kern::ThreadDesWrite(iClient, a2, *tmp, 0, 0, iClient); if(err != KErrNone) { Kern::Printf("Unable to write data back to client"); // We could not read information from the user, so the a2 argument is probably wrong Kern::RequestComplete(iClient, aStatus, KErrArgument); return err; } break; } default: { err=KErrNotSupported; break; } } return err; }
/* * Produce a quality value profile based on all sequences of a specific * chemistry. Chemistry==0 implies all sequences regardless of chemistry. * * Returns: a count of how many samples have been added into total_conf; */ int read_conf_dist(GapIO *io, int chemistry, int *total_conf) { int i, j; GReadings r; int1 conf[MAXREADLEN]; int count = 0; for (i = 1; i <= NumReadings(io); i++) { gel_read(io, i, r); if (!r.confidence) continue; if (r.length >= MAXREADLEN) continue; if (chemistry && r.chemistry != chemistry) continue; if (DataRead(io, r.confidence, conf, r.length * sizeof(int1), sizeof(int1))) continue; /* Always work on top strand data */ if (r.sense == 1) { int left, right; for (left = 0, right = r.length-1; left < right; left++, right--) { int tmp = conf[left]; conf[left] = conf[right]; conf[right] = tmp; } } /* All < conf 10 - probably not a real */ for (j = 0; j < r.length; j++) { if (conf[j] >= 10) break; } if (j == r.length) continue; /* All > conf 40 - probably not a real sequence */ for (j = 0; j < r.length; j++) { if (conf[j] < 40) break; } if (j == r.length) continue; /* All same value - probably not a real sequence */ for (j = 1; j < r.length; j++) { if (conf[j] != conf[0]) break; } if (j == r.length) continue; /* Accumulate totals and counts */ for (j = 0; j < r.length; j++) { total_conf[j] += conf[j]; } count++; } return count; }
/*! Get sample frames \param buf pointer array to channel buffers \param frames number of maximum frames to get \return frames put into buffers */ int Stream::doGet(int ch,float *const *buf,int frames,float sr) { ASSERT(ch > 0 && frames >= 0 && sr > 0); if(isOk() && !isInitializing()) { // signal thread worker pthread_cond_signal(&cond); // check/(re)allocate buffers int strch = getChannels(); if(bufs && bufch < strch) { delete[] decoded; for(int i = 0; i < bufch; ++i) src_delete(src_state[i]); delete[] src_state; delete[] bufs; bufs = NULL; } if(!bufs) { if(bufch < strch) bufch = strch; bufs = new float *[bufch]; decoded = new Fifo<float>[bufch]; src_state = new SRC_STATE *[bufch]; for(int i = 0; i < bufch; ++i) { int error; src_state[i] = src_new(SRC_ZERO_ORDER_HOLD,1,&error); if(!src_state[i]) post("src init error %i",error); } } // get frames float ratio = sr/getSamplerate(); int frneed = (int)(frames/ratio)+DECMORE; // number of frames to read from decoder fifo if(decoded[0].Size() < frneed) { // fifos are too small -> resize them (while keeping their contents) for(int i = 0; i < bufch; ++i) decoded[i].Resize(frneed,true); } // how many frames do we need to get from decoder? int frread = frneed-decoded[0].Have(); int ret = state == ST_WAIT?0:DataRead(frread); if(ret < 0) { if(debug) post("read error"); // clear output for(int c = 0; c < ch; ++c) memset(buf[c],0,frames*sizeof *buf[c]); return 0; } else { // how many channels do we really need for output? // this should be set elsewhere, because we can't change anyway!!! // (SRC_STATE for dangling channels would be incorrect) int cmin = strch; if(ch < cmin) cmin = ch; // write data to fifo for(int i = 0; i < cmin; ++i) { int wr = decoded[i].Write(ret,bufs[i]); if(wr < ret) post("fifo overflow"); } // state = ST_PROCESS; if(ratio == 1) { // no resampling necessary // hopefully all channel fifos advance uniformly..... for(int i = 0; i < cmin; ++i) { for(int got = 0; got < frames; ) { int cnt = frames-got; if(decoded[i].Have()) { got += decoded[i].Read(cnt,buf[i]+got); } else { state = ST_WAIT; if(debug) post("fifo underrun"); // Buffer underrun!! -> zero output buffer memset(buf[i]+got,0,cnt*sizeof(*buf[i])); got += cnt; } } } } else { SRC_DATA src_data; src_data.src_ratio = ratio; src_data.end_of_input = 0; // hopefully all channel fifos advance uniformly..... for(int i = 0; i < cmin; ++i) { src_set_ratio(src_state[i],ratio); for(int got = 0; got < frames; ) { src_data.data_out = buf[i]+got; src_data.output_frames = frames-got; if(decoded[i].Have()) { src_data.data_in = decoded[i].ReadPtr(); src_data.input_frames = decoded[i].ReadSamples(); int err = src_process(src_state[i],&src_data); if(err) post("src_process error %i",err); // advance buffer decoded[i].Read(src_data.input_frames_used,NULL); } else { state = ST_WAIT; if(debug) post("fifo underrun"); // Buffer underrun!! -> zero output buffer memset(src_data.data_out,0,src_data.output_frames*sizeof(*src_data.data_out)); src_data.output_frames_gen = src_data.output_frames; } got += src_data.output_frames_gen; } } } // zero remaining channels for(int c = cmin; c < ch; ++c) memset(buf[c],0,frames*sizeof *buf[c]); return ret; } } else { for(int c = 0; c < ch; ++c) memset(buf[c],0,frames*sizeof *buf[c]); return 0; } }