int zap_restore(int laddr) { register struct line *p1, *p2; int status = OK, i; if(nladdrs == 2) return(ERROR5); curln = laddr; for(p1 = purge_ptr->next, i = npurge_lns; i ; --i, p1 = p1->next) { strcpy(rbuff, (p2 = getptr(curln))->textp); zchar_change(curin, strlen(rbuff), p1->textp, strlen(p1->textp), curln); if(curln == 0) { /* Add after last line */ curln = lastln; status = addline(rbuff, 0, 0); } else status = replace(curln, rbuff, p2->textp); if(status != OK) break; curln = nextln(curln); /* Set to zero after last line */ } curln = laddr; return(status); }
void weaktestinfo::run() { auto weakptr=strongref.weaken(); std::cout << "Weak reference acquired" << std::endl << std::flush; weaktest_go=true; { std::unique_lock<std::mutex> lock_test_mutex(mutex); std::cout << "Lock acquired in the thread, signaling parent" << std::endl << std::flush; cond.notify_one(); cond.wait(lock_test_mutex); std::cout << "Acquiring strong reference..." << std::endl << std::flush; } testptr strongref=weakptr.getptr(); std::cout << "Acquired strong reference: " << (strongref.null() ? "no":"yes") << std::endl << std::flush; }
void bx_param_string_c::text_print(FILE *fp) { char *value = getptr(); int opts = options; if (opts & RAW_BYTES) { char buffer[1024]; buffer[0] = 0; char sep_string[2]; sep_string[0] = separator; sep_string[1] = 0; for (int i=0; i<maxsize; i++) { char eachbyte[16]; sprintf(eachbyte, "%s%02x", (i>0)?sep_string : "", (unsigned int)0xff&val[i]); strncat(buffer, eachbyte, sizeof(eachbyte)); } if (strlen(buffer) > sizeof(buffer)-4) { assert(0); // raw byte print buffer is probably overflowing. increase the max or make it dynamic } value = buffer; } if (get_format()) { fprintf(fp, get_format(), value); } else { if (get_label()) { fprintf(fp, "%s: %s", get_label(), value); } else { fprintf(fp, "%s: %s", get_name(), value); } } }
void print_instr_pipe(s_instr *instr, FILE *fd) { s_instr_pipe *instr_pipe = NULL; if (instr == NULL || instr->instr == NULL) return; instr_pipe = instr->instr; fprintf(fd, "itm%p [label=\"|\" "AST_STYLE_PIPE"]\n", getptr(instr)); fprintf(fd, "itm%p -> itm%p\n", getptr(instr), getptr(instr_pipe->list_instr)); print_list_instr(instr_pipe->list_instr, fd); }
// Get metadata about file f. int filestat(struct file *f, struct stat *st) { uchar cksum; struct buf *bp; int i; if(f->type == FD_INODE){ ilock(f->ip); stati(f->ip, st); cksum = getcksum(f->ip->addrs[0]); for(i = 1; i < NDIRECT; i++){ cksum = cksum ^ getcksum(f->ip->addrs[i]); } bp = bread(f->ip->dev, getptr(f->ip->addrs[NDIRECT])); uint *a; a = (uint*)bp->data; for(i = 0; i < 512/sizeof(uint); i++){ cksum = cksum ^ getcksum(a[i]); } st->checksum = cksum; iunlock(f->ip); return 0; } return -1; }
Variant Dictionary::get_valid(const Variant& p_key) const { const Variant *v = getptr(p_key); if (!v) return Variant(); return *v; }
// branches from the position of the symbol; arguments accompany this symbol. void cross(Elem *s) { Lit l; l.x.i = lookupf(s->x.x.s); l.type = FUN; s->x = l; s->up = s->next; s->next = getptr(s,funs[s->x.x.i].ins); }
void print_instr_func(s_instr *instr, FILE *fd) { s_instr_func *instr_func = NULL; if (instr == NULL || instr->instr == NULL) return; instr_func = instr->instr; fprintf(fd, "itm%p [label=\"Function %s\" "AST_STYLE_FUNCTION"]\n", getptr(instr), instr_func->name); fprintf(fd, "itm%p -> itm%p\n", getptr(instr), getptr(instr_func->list_instr)); print_list_instr(instr_func->list_instr, fd); }
void AGOSEngine_PN::getObjectName(char *v, uint16 x) { if (x & 0x8000) { x &= ~0x8000; if (x > getptr(51)) error("getObjectName: Object %d out of range", x); uncomstr(v, ftext(getlong(27), x * _dataBase[47])); } else { assert(x < 30); strcpy(v, objectNames[x]); } }
int AGOSEngine_PN::findentry() { int stepmt; int curObj = 0; uint32 ofs = _quickptr[11]; int c1, c2; c1 = varval(); c2 = varval(); stepmt = _quickshort[4]; while (curObj < _quickshort[6]) { if (((c1 == 255) || (c1 == getptr(ofs))) && (c2 == getptr(ofs + 2))) { _variableArray[23] = curObj; return 1; } curObj++; ofs += stepmt; } return 0; }
int AGOSEngine_PN::varval() { int a; int b; a = readfromline(); if (a < 247) { return a; } switch (a) { case 249: b = readfromline(); return (int)(b + 256 * readfromline()); break; case 250: return readfromline(); case 251: return (int)_variableArray[varval()]; case 252: b = varval(); return (int)_dataBase[_quickptr[0] + b * _quickshort[0] + varval()]; case 254: b = varval(); return (int)_dataBase[_quickptr[3] + b * _quickshort[2] + varval()]; case 247: b = varval(); return (int)getptr(_quickptr[11] + (b * _quickshort[4]) + (2 * varval())); case 248: b = varval(); return (int)getptr(_quickptr[12] + (b * _quickshort[5]) + (2 * varval())); case 253: b = varval(); return bitextract((int32)_quickptr[1] + b * _quickshort[1], varval()); case 255: b = varval(); return bitextract((int32)_quickptr[4] + b * _quickshort[3], varval()); default: error("VARVAL : Illegal code %d encountered", a); } }
void sequence::debug2 () { span *sptr; printf("**********************\n"); for(sptr = head; sptr; sptr = sptr->next) { //char *buffer = (char *)buffer_list[sptr->buffer]->buffer; char *buffer = (char *)getptr(sptr); printf("[%d] [%4d %4d] %.*s\n", sptr->id, sptr->offset, sptr->length, sptr->length, buffer); } printf("-------------------------\n"); for(sptr = tail; sptr; sptr = sptr->prev) { //char *buffer = (char *)buffer_list[sptr->buffer]->buffer; char *buffer = (char *)getptr(sptr); printf("[%d] [%4d %4d] %.*s\n", sptr->id, sptr->offset, sptr->length, sptr->length, buffer + sptr->offset); } printf("**********************\n"); for(sptr = head; sptr; sptr = sptr->next) { //char *buffer = (char *)buffer_list[sptr->buffer]->buffer; char *buffer = (char *)getptr(sptr); printf("%.*s", sptr->length, buffer + sptr->offset); } printf("\nsequence length = %d chars\n", sequence_length); printf("\n\n"); }
// 获得变量的值. llvm::Value* VariableDimAST::getval(ASTContext ctx) { llvm::IRBuilder<> builder(ctx.block); return builder.CreateLoad(getptr(ctx)); #ifdef WIN32 printf("%s\n", __FUNCTION__); #else printf("%s\n", __func__); #endif exit(1); }
int AGOSEngine_PN::findset() { int curObj = _fnst; int c1, c2, c3, c4; int stepmt = _quickshort[4]; uint32 ofs = _quickptr[11] + stepmt * curObj; c1 = varval(); c2 = varval(); c3 = varval(); c4 = varval(); while (curObj < _quickshort[6]) { if (((c1 ==255) || (c1 == getptr(ofs))) && ((c2 == 255) || (c2 == getptr(ofs + 2))) && ((c3 == 255) || (c3 == getptr(ofs + 4))) && ((c4 == 255) || (c4 == getptr(ofs + 6)))) { _variableArray[23] = curObj; _fnst = curObj + 1; return 1; } curObj++; ofs += stepmt; } return 0; }
int main(int argc, char **argv) { int a, b; int (*f)(int, int); if(argc != 2 || argv[1][1]) bad_input("arglen"); a = 3; b = 2; f = getptr(argv[1][0]); printf("%d %c %d = %d\n", a, argv[1][0], b, f(a, b)); return 0; }
void sequence::debug1 () { span *sptr; for(sptr = head; sptr; sptr = sptr->next) { //char *buffer = (char *)buffer_list[sptr->buffer]->viewlist[0].buffer; //printf("%.*s", sptr->length, buffer + sptr->offset); char *buffer = (char *)getptr(sptr); printf("%.*s", sptr->length, buffer); } printf("\n"); }
int prnt(int from, int to) { register int laddr; char raw = 0; if(from <= 0) return( ERROR5 ); raw = *(lp + -1) == 'P'; for(laddr = from ; laddr <= to ; ++laddr) prnt_screen(getptr(laddr)->textp, raw); curln = to; return( OK ); }
llvm::Value* ArgumentDimAST::getval(ASTContext ctx) { debug("ArgumentDimAST:: geting val %s of argument\n", this->name.c_str()); if(modified_stackvar){ // have local copy now llvm::IRBuilder<> builder(ctx.block); return builder.CreateLoad(getptr(ctx)); } // geting value from argument llvm::Function::arg_iterator arg_it =ctx.llvmfunc->arg_begin(); for(;arg_it != ctx.llvmfunc->arg_end(); arg_it++){ if(arg_it->getName() == this->name) return arg_it; } debug("bug here %s \n",__FUNCTION__); exit(1); }
int bx_param_string_c::text_ask(FILE *fpin, FILE *fpout) { fprintf(fpout, "\n"); int status; const char *prompt = get_ask_format(); if (prompt == NULL) { if (options & SELECT_FOLDER_DLG) { fprintf(fpout, "%s\n\n", get_label()); prompt = "Enter a path to an existing folder or press enter to cancel\n"; } else { // default prompt, if they didn't set an ask format string text_print(fpout); fprintf(fpout, "\n"); prompt = "Enter a new value, '?' for help, or press return for no change.\n"; } } while (1) { char buffer[1024]; status = ask_string(prompt, getptr(), buffer); if (status == -2) { fprintf(fpout, "\n%s\n", get_description()); continue; } if (status < 0) return status; int opts = options; char buffer2[1024]; strcpy(buffer2, buffer); if (status == 1 && opts & RAW_BYTES) { // copy raw hex into buffer status = parse_raw_bytes(buffer, buffer2, maxsize, separator); if (status < 0) { fprintf(fpout, "Illegal raw byte format. I expected something like 3A%c03%c12%c...\n", separator, separator, separator); continue; } } if (!equals(buffer)) set(buffer); return 0; } }
bool AGOSEngine_PN::ifObjectAt(uint16 a, uint16 b) { if (getFeatures() & GF_DEMO) return false; return b == getptr(_quickptr[11] + a * _quickshort[4] + 2); }
bool AGOSEngine_PN::ifObjectHere(uint16 a) { if (getFeatures() & GF_DEMO) return false; return _variableArray[39] == getptr(_quickptr[11] + a * _quickshort[4] + 2); }
void GUIStateNode::accept(GUIVisitor& guiVisitor) { guiVisitor.visit(getptr()); Node::accept(guiVisitor); }
// pop for all necessary functions. void parse(void) { for(long i=mn;i<esz;i++) { switch(exprs[i].op) { case PW: push_int(exprs[i].q.i); break; case PF: push_flt(exprs[i].q.f); break; case PC: push_chr(exprs[i].q.c); break; case PL: push_lng(exprs[i].q.l); break; case MALLOCI: nstkptr(); stk->x.ia = malloc(exprs[i].q.i*I); break; case MALLOCF: nstkptr(); stk->x.fa = malloc(exprs[i].q.i*F); break; case MALLOCC: nstkptr(); stk->x.ca = malloc(exprs[i].q.i*B); break; case MALLOCL: nstkptr(); stk->x.la = malloc(exprs[i].q.i*L); break; case REALL: { void *x = getptr(stk->x); x = realloc(x,exprs[i].q.i); break; } case FREE: free(getptr(stk->x)); pop(); break; case OUT_S: out_s(stk->x.i,stk->prev->x); pop(); pop(); break; case JMP_S: { i=lbls[0].l[stk->x.i]-1; pop(); break; } case JMP: { i=lbls[0].l[exprs[i].q.i]-1; break; } // it's correct case POP: pop(); break; case IN: push_chr(getchar()); break; case REFI: { int q = (stk->x.ia)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.i = q; break; } case REFF: { double q = (stk->x.fa)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.f = q; break; } case REFC: { char q = (stk->x.ca)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.c = q; break; } case REFL: { long q = (stk->x.la)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.l = q; break; } case CALL_S: { Ref *r = malloc(sizeof(Ref)); r->r = i; if(refs) { r->prev = refs; } refs = r; i=lbls[0].l[stk->x.i]-1; pop(); break; } case CALL: { Ref *r = malloc(sizeof(Ref)); r->r = i; if(refs) { r->prev = refs; } refs = r; i=lbls[0].l[exprs[i].q.i]-1; break; } case RETURN: { Ref *r; r = refs; i = r->r; refs = refs->prev; free(r); break; } case MOVI: { (stk->x.ia)[stk->prev->x.i] = stk->prev->prev->x.i; pop(); pop(); pop(); break; } case MOVF: { (stk->x.fa)[stk->prev->x.i] = stk->prev->prev->x.f; pop(); pop(); pop(); break; } case SWAP: { stk->prev->prev = stk; stk = stk->prev; break; } case SREF: { Stk *e = stkref(stk->x.i); pop(); nstkptr(); *(stk) = *(e); break; } case ARITH: { arith(stk->x.i,stk->prev->x.i); break; } case LINK: { nstkptr(); stk->x.v = dlopen(exprs[i].q.ca,RTLD_LAZY); break; } case LFUN: { void *z; z = dlsym(stk->prev->x.v,exprs[i].q.ca); push_f(z,exprs[i].q.ca,stk->x.i); pop(); break; } case LCALL: { exec_ffun(exprs[i].q.ca); break; } case IMPORT: { char *in; in = malloc((strlen(exprs[i].q.ca)+4)*sizeof(char)); strcpy(in,exprs[i].q.ca); strcat(in,".uo"); FILE *u; u = fopen(in,"rb"); lbls = realloc(lbls,(++lsz)*sizeof(Modu)); lbls[lsz-1].sz = 0; read_prgm(u,md++); fclose(u); break; /* simply allocate the next lblarr */ } case OJMP: { // pop module, then word i = lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; pop(); pop(); break; } case OCALL: { Ref *r; r = malloc(sizeof(Ref)); r->r = i; if(refs) { r->prev = refs; } refs = r; i=lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; pop(); pop(); break; } case NS: { if(!stk) { nstkptr(); stk->x.i = 1; } else { nstkptr(); stk->x.i = 0; } break; } case OJEZ: { if(!stk->prev->prev->x.i) { i = lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; } pop(); pop(); pop(); break; } case OJNZ: { if(stk->prev->prev->x.i) { i = lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; } pop(); pop(); pop(); break; } case TERM: exit(0); break; default: printf("what"); exit(0); } } }
void AGOSEngine_PN::plocd(int n, int m) { if (n > getptr(53)) error("Location out of range"); ptext(ftext(getlong(21), n * _dataBase[48] + m)); }
void AGOSEngine_PN::pobjd(int n, int m) { if (n > getptr(51)) error("Object out of range"); ptext(ftext(getlong(27), n * _dataBase[47] + m)); }
static PyObject * bloboverlaps (PyObject *self, PyObject *args, PyObject *keywds) { PyArrayObject *b1=NULL,*b2=NULL; /* in */ PyArrayObject *r1=NULL, *r2=NULL; /* in/out */ int i,j,s,f, verbose ; /* loop vars, flag */ int p1,p2,n1,n2; /* peak num and npeaks in each */ int *link , percent, safelyneed, must_do_relabel; int ipk, jpk, npk; int *intp, *T; double *res1, *res2; static char *kwlist[] = { "blob1", "n1", "res1", "blob2", "n2", "res2", "verbose", NULL}; /* b nr b nr */ if(!PyArg_ParseTupleAndKeywords(args,keywds, "O!iO!O!iO!|i",kwlist, &PyArray_Type, &b1, /* blobs 1 */ &n1, /* npeaks 1 */ &PyArray_Type, &r1, /* results 1 */ &PyArray_Type, &b2, /* blobs 2 */ &n2, /* npeaks 2 */ &PyArray_Type, &r2, /*results 2 */ &verbose)) /* optional verbosity */ return NULL; if(verbose!=0)printf("Welcome to bloboverlaps\n"); /* Check array is two dimensional and int - results from connectedpixels above */ if(b1->nd != 2 && b1->descr->type_num != PyArray_INT){ PyErr_SetString(PyExc_ValueError, "Blob1 array must be 2d and integer, first arg problem"); return NULL; } if(b2->nd != 2 && b2->descr->type_num != PyArray_INT){ PyErr_SetString(PyExc_ValueError, "Blob2 array must be 2d and integer, second arg problem"); return NULL; } if (b1->strides[0] != b2->strides[0] || b1->strides[1] != b2->strides[1] || b1->dimensions[0] != b2->dimensions[0] || b1->dimensions[1] != b2->dimensions[1] ){ PyErr_SetString(PyExc_ValueError, "Blob1 and Blob2 array be similar (dims & strides)"); return NULL; } /* check results args */ if (r1->dimensions[0] < n1 || r1->dimensions[1] != NPROPERTY || r2->dimensions[0] < n2 || r2->dimensions[1] != NPROPERTY || r1->descr->type_num != PyArray_DOUBLE || r2->descr->type_num != PyArray_DOUBLE ){ PyErr_SetString(PyExc_ValueError, "Results arrays look corrupt\n"); return NULL; } Py_BEGIN_ALLOW_THREADS res1 = (double *)r1->data; res2 = (double *)r2->data; /* Decide on fast/slow loop - inner versus outer */ if(b1->strides[0] > b1->strides[1]) { f=1; s=0;} else { f=0; s=1; } if (verbose!=0){ printf("Fast index is %d, slow index is %d, ",f,s); printf("strides[0]=%d, strides[1]=%d\n",b1->strides[0],b2->strides[1]); } /* Initialise a disjoint set in link * image 2 has peak[i]=i ; i=1->n2 * image 1 has peak[i]=i+n1+1 ; i=1->n1 * 0, 1, 2, 3, n2 * 4, 5, 6, 7, 8, 9, n1 need 0, 4 == n1+n2+3 * link to hold 0->n1-1 ; n1->n2+n2-1 */ safelyneed=n1+n2+3; link = (int *)malloc(safelyneed*sizeof(int)); for(i=0;i<safelyneed;i++){ link[i]=i; } /* first image */ /* flag the start of image number 2 */ link[n2+1]=-99999; /* ==n2=0 Should never be touched by anyone */ /* results lists of pairs of numbers */ if(verbose!=0){ printf("Scanning image, n1=%d n2=%d\n",n1,n2); } percent = b1->dimensions[s] / 100.; for( i = 0 ; i <= (b1->dimensions[s]-1) ; i++ ){ /* i,j is looping along the indices of the data array */ for( j = 0 ; j <= (b1->dimensions[f]-1) ; j++ ){ p1 = * (int *) getptr(b1,f,s,i,j); if ( p1 == 0 ){ continue; } p2 = * (int *) getptr(b2,f,s,i,j); if ( p2 == 0 ){ continue; } /* Link contains the peak that this peak is */ if(link[p2] < 0 || link[p1+n2+1]<0){ printf("Whoops p1=%d p2=%d p2+n1=%d link[p1]=%d link[p2+n1]=%d\n", p1,p2,p2+n1,link[p1],link[p2+n1+1]); return NULL; } if(verbose>2)printf("p1 %d p2 %d\n",p1,p2); dset_makeunion(link, p2, p1+n2+1); /* printf("link[60]=%d ",link[60]); */ if(verbose>2)printf("link[p2=%d]=%d link[p1+n2=%d]=%d\n", p2,link[p2],p2+n1+1,link[p1+n2+1]); } /* j */ } /* i */ if(verbose)printf("Finished scanning blob images\n"); must_do_relabel = 1; /* Just do it always */ for(i=1; i < safelyneed; i++){ if(link[i] != i && i != n2+1){ j = dset_find(i, link); if(verbose>1){ printf("\ni= %d link[i]= %d j= %d n1= %d n2=%d \n",i,link[i],j, n1,n2); } if(i > n2+1 && j<n2+1){ /* linking between images */ jpk = j-1; ipk = i-n2-2; if(jpk<0 || jpk>r2->dimensions[0])printf("bounds jpk %d",jpk); if(ipk<0 || ipk>r1->dimensions[0])printf("bounds ipk %d",ipk); if(verbose>2)printf("mx_o,f,s 1 %f %d %d %f %d %d ", res2[NPROPERTY*jpk+mx_I_o], (int)res2[NPROPERTY*jpk+mx_I_f], (int)res2[NPROPERTY*jpk+mx_I_s], res1[NPROPERTY*ipk+mx_I_o], (int)res1[NPROPERTY*ipk+mx_I_f], (int)res1[NPROPERTY*ipk+mx_I_s] ); merge( &res2[NPROPERTY*jpk], &res1[NPROPERTY*ipk] ); if(verbose>2)printf("after 1 %f %d %d %f %d %d\n", res2[NPROPERTY*jpk+mx_I_o], (int)res2[NPROPERTY*jpk+mx_I_f], (int)res2[NPROPERTY*jpk+mx_I_s], res1[NPROPERTY*ipk+mx_I_o], (int)res1[NPROPERTY*ipk+mx_I_f], (int)res1[NPROPERTY*ipk+mx_I_s] ); if(verbose>2)printf("merged ipk %d jpk %d between images\n",ipk,jpk); continue; } if(i > n2+1 && j>n2+1){ /* linking on same image */ jpk = j-n2-2; ipk = i-n2-2; if(jpk<0 || jpk>r1->dimensions[0])printf("bounds jpk %d",jpk); if(ipk<0 || ipk>r1->dimensions[0])printf("bounds ipk %d",ipk); if(verbose>2)printf("mx_o,f,s 2 %f %d %d %f %d %d ", res1[NPROPERTY*jpk+mx_I_o], (int)res1[NPROPERTY*jpk+mx_I_f], (int)res1[NPROPERTY*jpk+mx_I_s], res1[NPROPERTY*ipk+mx_I_o], (int)res1[NPROPERTY*ipk+mx_I_f], (int)res1[NPROPERTY*ipk+mx_I_s] ); merge( &res1[NPROPERTY*jpk], &res1[NPROPERTY*ipk] ); if(verbose>2)printf("after 2 %f %d %d %f %d %d\n", res1[NPROPERTY*jpk+mx_I_o], (int)res1[NPROPERTY*jpk+mx_I_f], (int)res1[NPROPERTY*jpk+mx_I_s], res1[NPROPERTY*ipk+mx_I_o], (int)res1[NPROPERTY*ipk+mx_I_f], (int)res1[NPROPERTY*ipk+mx_I_s] ); if(verbose>2)printf("merged ipk %d jpk %d on same image\n",ipk,jpk); continue; } if(i < n2+1 && j < n2+1){ /* linking on same image */ jpk = j-1; ipk = i-1; if(jpk<0 || jpk>r2->dimensions[0])printf("bounds jpk %d",jpk); if(ipk<0 || ipk>r2->dimensions[0])printf("bounds ipk %d",ipk); if(verbose>2)printf("ms_o,f,s 3 %f %d %d %f %d %d ", res2[NPROPERTY*jpk+mx_I_o], (int)res2[NPROPERTY*jpk+mx_I_f], (int)res2[NPROPERTY*jpk+mx_I_s], res2[NPROPERTY*ipk+mx_I_o], (int)res2[NPROPERTY*ipk+mx_I_f], (int)res2[NPROPERTY*ipk+mx_I_s] ); merge( &res2[NPROPERTY*jpk], &res2[NPROPERTY*ipk] ); if(verbose>2)printf("after 3 %f %d %d %f %d %d\n", res2[NPROPERTY*jpk+mx_I_o], (int)res2[NPROPERTY*jpk+mx_I_f], (int)res2[NPROPERTY*jpk+mx_I_s], res2[NPROPERTY*ipk+mx_I_o], (int)res2[NPROPERTY*ipk+mx_I_f], (int)res2[NPROPERTY*ipk+mx_I_s] ); must_do_relabel = 1; if(verbose>2)printf("merged check ipk %d jpk on same II %d\n",ipk,jpk); continue; } printf("bad logic in bloboverlaps\n"); return NULL; } } npk = n2; if((must_do_relabel=1)){ /* just always do it */ /* This is the case where two spots on the current image become linked by * by a spot overlap on the previous one * * The labels are now wrong, in fact there is a single peak in 3D and * two peaks in 2D * * Thanks to Stine West from Riso for finding this subtle bug */ /* First, work out the new labels */ /* Now make each T[i] contain the unique ascending integer for the set */ T=NULL; if(verbose!=0)printf("Now I want to malloc T=%p at "\ "size np=%d and sizeof(int)=%d\n", (void *) T ,n2 ,sizeof(int)); if( ( T=(int *) ( malloc( (n2+3)*sizeof(int) ) ) ) == NULL){ printf("Memory allocation error in bloboverlaps\n"); return 0; } npk = 0; for( i=1 ; i<n2+1 ; i++){ if(link[i] == i ){ npk++; T[i]=npk; } else { /* check */ j = dset_find(i,link); /* j is the lower one, fill in as T[i] = npk previously */ T[i] = T[j]; if(verbose)printf("T[i] = T[%d] = T[j] = T[%d] = %d\n",i,j,T[i]); if(j>=i && verbose){ printf("Oh dear - there was a problem compressing"\ " the disjoint set, j=%d, i=%d \n",j,i); } /* if(T[j]!=j && verbose!=0){ printf("Oh dear - the disjoint set is squiff,"\ "T[j]=%d, link[j]=%d,j=%d, n2+1\n",T[j],link[j],j); }*/ } if(verbose>10){ printf("i=%d T[i]=%d\n",i,T[i] ); } } /* Compress the set */ if (verbose) printf("Done compressing set in b.o.\n"); /* Update the res2 array too * * We will move the bad ones to the end by using * link and T, I hope * */ for( i=1 ; i<n2+1 ; i++){ /* dest = T[i]; */ /* src = link[i]; */ if (link[i] == T[i]) continue; if (T[i] < link[i] ) { /* copy and zero out */ for (j=0 ; j < NPROPERTY ; j++ ){ res2[NPROPERTY*(T[i]-1) + j] = res2[NPROPERTY*(link[i]-1) + j] ; res2[NPROPERTY*(link[i]-1) + j] = 0; } if(verbose) printf("np i %d j %d %f \n",T[i],link[i],res2[NPROPERTY*T[i] + 1]); } else { printf("Bad logic in bloboverlaps \n"); } } if (verbose) printf("Copied results in b.o.\n"); /* Relabel the image */ for( i = 0 ; i <= (b1->dimensions[s]-1) ; i++ ){ for( j = 0 ; j <= (b1->dimensions[f]-1) ; j++ ){ intp = (int *) getptr(b2,f,s,i,j); if ( *intp == 0 ) continue; ipk = T[*intp]; if (ipk > 0 && ipk <= n2) *intp = ipk; else { printf("bad logic on image relabelling, ipk=%d, n2=%d\n",ipk,n2); return NULL; } } } /* for loops over image */ if (verbose) printf("Relabeled in b.o.\n"); free(T); if (verbose) printf("freed in b.o.\n"); } /* relabeling */ if(verbose!=0){ printf("\n"); for(i=0;i<n1+n2;i++){ if(i!=link[i] && link[i]>0){ printf("Link found!! %d %d\n",i,link[i]); } } } free(link); if(verbose)printf("returning from bloboverlaps\n"); /* * Py_INCREF(Py_None);0 * return Py_None; * * Should return the new number of peaks in the results array * */ Py_END_ALLOW_THREADS return Py_BuildValue("i", npk); }
static PyObject * blobproperties (PyObject *self, PyObject *args, PyObject *keywds) { PyArrayObject *dataarray=NULL,*blobarray=NULL; /* in (not modified) */ PyArrayObject *results=NULL; static char *kwlist[] = { "data", "blob", "npeaks", "omega", "verbose", NULL}; double *res; double fval; double omega=0; int np=0,verbose=0,type,f,s,peak,bad; int i,j, percent; npy_intp safelyneed[3]; if(!PyArg_ParseTupleAndKeywords(args,keywds, "O!O!i|di",kwlist, &PyArray_Type, &dataarray, /* array args - data */ &PyArray_Type, &blobarray, /* blobs */ &np, /* Number of peaks to treat */ &omega, /* omega angle - put 0 if unknown */ &verbose)) /* optional verbosity */ return NULL; if(verbose)printf("omega = %f",omega); /* Check array is two dimensional */ if(dataarray->nd != 2){ PyErr_SetString(PyExc_ValueError, "data array must be 2d, first arg problem"); return NULL; } if(verbose!=0)printf("Welcome to blobproperties\n"); /* Check array is two dimensional and int - results from connectedpixels above */ if(blobarray->nd != 2 && blobarray->descr->type_num != PyArray_INT){ PyErr_SetString(PyExc_ValueError, "Blob array must be 2d and integer, second arg problem"); return NULL; } type=dataarray->descr->type_num; /* Decide on fast/slow loop - inner versus outer */ if(blobarray->strides[0] > blobarray->strides[1]) { f=1; s=0;} else { f=0; s=1; } if (verbose!=0){ printf("Fast index is %d, slow index is %d, ",f,s); printf("strides[0]=%d, strides[1]=%d\n", dataarray->strides[0], dataarray->strides[1]); } /* results arrays */ safelyneed[0]=np; safelyneed[1]=NPROPERTY; results = (PyArrayObject *) PyArray_SimpleNew(2, safelyneed, PyArray_DOUBLE); if( results == NULL){ PyErr_SetString(PyExc_ValueError, "Malloc failed fo results"); return NULL; } Py_BEGIN_ALLOW_THREADS if(verbose>0)printf("malloc'ed the results\n"); res = (double*)results->data; /* Initialise the results */ for ( i=0 ; i<safelyneed[0] ; i++) { for ( j=0 ; j<NPROPERTY; j++){ res[i*NPROPERTY+j]=0.; } /* Set min to max +1 and vice versa */ res[i*NPROPERTY+bb_mn_f]=blobarray->dimensions[f]+1; res[i*NPROPERTY+bb_mn_s]=blobarray->dimensions[s]+1; res[i*NPROPERTY+bb_mx_f]=-1; res[i*NPROPERTY+bb_mx_s]=-1; /* All pixels have the same omega in this frame */ res[i*NPROPERTY+bb_mx_o]=omega; res[i*NPROPERTY+bb_mn_o]=omega; } if(verbose!=0)printf("Got some space to put the results in\n"); percent=(blobarray->dimensions[s]-1)/80.0; if(percent < 1)percent=1; bad = 0; if(verbose!=0)printf("Scanning image\n"); /* i,j is looping along the indices data array */ for( i = 0 ; i <= (blobarray->dimensions[s]-1) ; i++ ){ if(verbose!=0 && (i%percent == 0) )printf("."); for( j = 0 ; j <= (blobarray->dimensions[f]-1) ; j++ ){ peak = *(int *) getptr(blobarray,f,s,i,j); if( peak > 0 && peak <=np ) { fval = getval(getptr(dataarray,f,s,i,j),type); /* printf("i,j,f,s,fval,peak %d %d %d %d %f %d\n",i,j,f,s,fval,peak); */ add_pixel( &res[NPROPERTY*(peak-1)] ,i , j ,fval , omega); } else{ if(peak!=0){ bad++; if(verbose!=0 && bad<10){ printf("Found %d in your blob image at i=%d, j=%d\n",peak,i,j);} /* Only complain 10 times - otherwise piles of crap go to screen */ } } } /* j */ } /* i */ if(verbose){ printf("\nFound %d bad pixels in the blob image\n",bad); } Py_END_ALLOW_THREADS return Py_BuildValue("O", PyArray_Return(results) ); }
static PyObject * connectedpixels (PyObject *self, PyObject *args, PyObject *keywds) { PyArrayObject *dataarray=NULL, *results=NULL; /* in (not modified) and out (modified) */ int i, j, /* looping over pixels */ k, /* used in looping neighouring pixels */ *curr, /* current blob assignment in loop */ l, f, s, /* fast and slow directions in image */ np, /* number of pixels */ ival; int *T, *S; /* for the disjoint set copy */ int verbose=0,type; /* whether to print stuff and the type of the input array */ int percent,npover; /* for the progress indicator in verbose mode */ static char *kwlist[] = { "data", "results", "threshold", "verbose", NULL}; clock_t tv1,tv1point5,tv2,tv3,tv4; /* for timing */ double time; double val; /* data, flood and dark values */ float threshold; if(!PyArg_ParseTupleAndKeywords(args,keywds, "O!O!f|i",kwlist, &PyArray_Type, &dataarray, /* array args */ &PyArray_Type, &results, /* array args */ &threshold, &verbose)) /* threshold and optional verbosity */ return NULL; if(verbose!=0){ printf("\n\nHello there from connected pixels,"\ "you wanted the verbose output...\n"); } tv1=clock(); /* Check array is two dimensional */ if(dataarray->nd != 2){ PyErr_SetString(PyExc_ValueError, "Array must be 2D!"); return NULL; } /* Save type for getval */ type = dataarray->descr->type_num; if(verbose!=0)ptype(type); if(verbose!=0)printf("Thresholding at level %f\n",threshold); /* Check results argument */ if(results->nd != 2){ PyErr_SetString(PyExc_ValueError, "Array must be 2d, second arg problem"); return NULL; } if( results->dimensions[0] != dataarray->dimensions[0] || results->dimensions[1] != dataarray->dimensions[1] ){ PyErr_SetString(PyExc_ValueError, "Arrays must have same shape"); return NULL; } /* Default number before reallocation, rather large * FIXME - can we pass this in and out? */ Py_BEGIN_ALLOW_THREADS S = dset_initialise(16384); if(verbose != 0)printf("Initialised the disjoint set\n"); npover = 0; /* number of pixels over threshold */ /* Decide on fast/slow loop - inner versus outer */ if(dataarray->strides[0] > dataarray->strides[1]) { f=1; s=0;} else { f=0; s=1; } if (verbose!=0){ printf("Fast index is %d, slow index is %d, ",f,s); printf("strides[0]=%d, strides[1]=%d\n", dataarray->strides[0], dataarray->strides[1]); } percent=(results->dimensions[s]-1)/80.0; if(percent < 1)percent=1; tv1point5=clock(); if(verbose!=0){ time=(tv1point5-tv1)/CLOCKS_PER_SEC; printf("Ready to scan image, setup took %g and "\ "clock is only good to ~0.015 seconds\n",time); } if(verbose!=0)printf("Scanning image\n"); /* === Mainloop === */ for( i = 0 ; i < (results->dimensions[s]) ; i++ ){ /* i = slow */ if(verbose!=0 && (i%percent == 0) )printf("."); for( j = 0 ; j < (results->dimensions[f]) ; j++ ){ /* j = fast*/ /* Set result for this pixel to zero - Not needed here? */ curr = (int *) getptr(results,f,s,i,j); *curr = 0; val = getval( getptr(dataarray,f,s,i,j), type); /* printf("curr %d val=%f",*curr,val); */ if( val > threshold) { npover++; k = 0; l = 0; /* peak needs to be assigned */ /* i-1, j-1, assign same index */ if(i!=0 && j!=0) if( (k = *(int *)(getptr(results,f,s,i-1,j-1))) > 0) { *curr = k ; l = k; } /* i-1,j */ if(i != 0) if( (k = *(int *)(getptr(results,f,s,i-1,j))) > 0) { if(l==0){ *curr = k; l = k; /* l holds the assignment of the current pixel */ } else { if(l != k)dset_makeunion(S,k,l); } } /* i-1, j+1 */ if(i!=0 && j!=(results->dimensions[f]-1)) if( (k = *(int *)(getptr(results,f,s,i-1,j+1))) > 0) { if(l==0){ *curr = k; l = k; /* l holds the assignment of the current pixel */ } else { if(l != k)dset_makeunion(S,k,l); } } /* i, j-1 */ if(j!=0) if( (k = *(int *)(getptr(results,f,s,i,j-1))) > 0) { if(l==0){ *curr = k; l = k; /* l holds the assignment of the current pixel */ } else { if(l != k)dset_makeunion(S,k,l); } } if(l == 0){ /* pixel has no neighbours thus far */ S = dset_new(&S); *curr = S[S[0]-1]; } } /* active pixel */ else { /* inactive pixel - zero in results */ *curr = 0; } } /* j */ } /* i */ /* ===== End of loop over data assigning in disjoint set == */ tv2=clock(); if(verbose!=0){ printf("\nFinished scanning image, now make unique list and sums\n"); printf("Number of pixels over threshold was : %d\n",npover); time=(tv2-tv1)/CLOCKS_PER_SEC; printf("That took %f seconds and %f in total being aware "\ "that the clock is only good to ~0.015 seconds\n", 1.*(tv2-tv1point5)/CLOCKS_PER_SEC,time*1.); } /* First, count independent peaks */ /* count peaks */ np = S[S[0]-1]; /* Now make each T[i] contain the unique ascending integer for the set */ T=NULL; if(verbose!=0)printf("Now I want to malloc T=%p at "\ "size np=%d and sizeof(int)=%d\n", (void *) T ,np ,sizeof(int)); if( ( T=(int *) ( malloc( (np+3)*sizeof(int) ) ) ) == NULL){ printf("Memory allocation error in connected pixels\n"); return 0; } if(verbose!=0)printf("Now T should be allocated, it is at %p\n",(void*)T); np = 0; for( i=1 ; i<S[S[0]-1]+1 ; i++){ if(S[i] == i ){ np++; T[i]=np; } else{ /* check */ j=dset_find(i,S); T[i]=T[j]; if(j>=i && verbose){ printf("Oh dear - there was a problem compressing"\ " the disjoint set, j=%d, i=%d \n",j,i); } if(S[j]!=j && verbose!=0){ printf("Oh dear - the disjoint set is squiff,"\ "S[j]=%d,j=%d\n",S[j],j); } } } if(verbose!=0)printf("\n"); tv3=clock(); if(verbose!=0){ printf("Compressing list, time=%g, total time=%g\n", 1.*(tv3-tv2)/CLOCKS_PER_SEC,1.*(tv3-tv1)/CLOCKS_PER_SEC); } if(verbose)printf("Found %d peaks\nNow assigning unique identifiers\n",np); /* Now loop through the results image again, assigning the corrected numbers to each pixel, and collecting the properties ??? */ for( i = 0 ; i < (results->dimensions[s]) ; i++ ){ for( j = 0 ; j < (results->dimensions[f]) ; j++ ){ curr = (int*)getptr(results,f,s,i,j); ival = *curr; if( ival > 0){ if(T[ival]==0){ printf("Something buggered up, ival=%d, T[ival]=%d, "\ "dset_find(ival,S)=%d\n", ival,T[ival],dset_find(ival,S)); free(S); exit(2); return NULL; } *curr = T[ival]; } } } Py_END_ALLOW_THREADS if(verbose!=0)printf("Freeing S=%p and T=%p\n",(void*)S,(void*)T); free(S); free(T); if(verbose!=0){ printf("Freed S=%p and T=%p\n",(void*)S,(void*)T); printf("Finished assigning unique values and tidied up, now returning"); tv4=clock(); time=(tv4-tv3)/CLOCKS_PER_SEC; printf("\nThat took %g seconds, being aware that the clock is "\ "only good to ~0.015 seconds\n",1.*time); printf("The total time in this routine was about %f\n", 1.*(tv4-tv1)/CLOCKS_PER_SEC); } return Py_BuildValue("i", np);/* why the plus one?? */ }
static PyObject * roisum (PyObject *self, PyObject *args, PyObject *keywds) { PyArrayObject *dat=NULL; /* in (not modified) */ int i,j,f,s,np; int xl,xh,yl,yh; int verbose=0,type; /* whether to print stuff and the type of the input array */ static char *kwlist[] = {"data","xl","xh","yl","yh","verbose", NULL}; double sum; if(!PyArg_ParseTupleAndKeywords(args,keywds, "O!iiii|i",kwlist, &PyArray_Type, &dat, /* array arg */ &xl,&xh,&yl,&yh, &verbose)) /* optional verbosity */ return NULL; if(verbose!=0){ printf("\n\nHello there from roisum, you wanted the verbose output...\n"); } /* Check array is two dimensional and Ushort */ if(dat->nd != 2 ){ PyErr_SetString(PyExc_ValueError, "Data array must be 2d,first arg problem"); return NULL; } type=dat->descr->type_num; if(verbose!=0)ptype(type); /* Decide on fast/slow loop - inner versus outer */ if(dat->strides[0] > dat->strides[1]) { f=1; s=0;} else { f=0; s=1; } if (verbose!=0){ printf("Fast index is %d, slow index is %d, ",f,s); printf("strides[0]=%d, strides[1]=%d\n", dat->strides[0], dat->strides[1]); } /* Check ROI is sane */ if(xl > xh || yl > yh || yl < 0 || xl < 0 || xh >dat->dimensions[s] || yh >dat->dimensions[f]){ PyErr_SetString(PyExc_ValueError, "Problem with your ROI"); return NULL; } if(verbose!=0)printf("Summing ROI\n"); sum=0.; np=0; for( i = xl ; i < xh ; i++ ){ /* i,j is looping along the indices data array */ for( j = yl ; j < yh ; j++ ){ sum+=getval( getptr(dat,f,s,i,j),type); np++; if(verbose>2){ printf("%d %d %f\n", i,j, getval(getptr(dat,f,s,i,j), type)); } } } if(verbose!=0){ printf("Sum %f np %d\n",sum,np); } return Py_BuildValue("d", sum/np); }
/* * This routine will update the in-house information using the data * read from license file. */ void update_lic_info(lic_data_t *data, bool daemon) { void *p, *p1; struct timespec abstime; double exptime; char *prod; char *maj = NULL; lic_type type = 0; lic_inst_type inst_type = 0; clock_gettime(CLOCK_REALTIME, &abstime); /* * If we couldn't read license details due to internall error, say * insufficient memory, let us not fail or decide license status. * Instead, read the license details again as soon as possible. */ ld_state = data->fld_state; if (daemon && (data->fld_state == LS_INTERNAL_ERR)) { ld_valid = true; adjust_chk_prd(-1); if (is_btree_loaded()) { ext_cbs->zs_lic_cb((ld_valid == true) ? 1 : 0); } return; } /* * Only if license is valid or expired, let us check whether the license * is for ZS. Else, let us mark the license as invalid and fail the * application. */ if ((ld_state == LS_VALID) || (ld_state == LS_EXPIRED)) { // We always expect license type and product to be set. p = getptr(data, LDI_LIC_TYPE); plat_assert(p); if (p) { type = getas(p, lic_type); } else { ld_state = LS_INVALID; goto print; } p = getptr(data, LDI_INST_TYPE); plat_assert(p); if (p) { inst_type = getas(p, lic_inst_type); } else { ld_state = LS_INVALID; goto print; } p = getptr(data, LDI_PROD_NAME); plat_assert(p); if (p) { prod = getasstr(p); p1 = getptr(data, LDI_PROD_MAJ); if (p1) { maj = getasstr(p1); } /* * If product matches, check whether the version * matches. If both, then this is a valid license. */ if ( (!strcmp(prod, ZS_PRODUCT_NAME)) || (!strcmp(prod, "Flash Data Fabric")) ) { #ifdef ZS_REVISION if (p1) { if (strncmp(p1, "all", strlen(p1))) { char *tmp; if (!zs_version) { zs_version = malloc(strlen(ZS_REVISION) + 1); } if (zs_version) { bzero(zs_version, strlen(ZS_REVISION) + 1); strncpy(zs_version, ZS_REVISION, strlen(ZS_REVISION)); tmp = strstr(zs_version, "."); if (tmp) { int len = tmp - zs_version; if (len) { if (strncmp(zs_version, maj, len)){ ld_state = LS_VER_MISMATCH; } } else { if (strncmp(zs_version, maj, strlen(zs_version))){ ld_state = LS_VER_MISMATCH; } } } } else { plat_log_msg(160256, LOG_CAT, LOG_WARN, "Internal error, skipped version check"); } } } else { ld_state = LS_PROD_MISMATCH; } #endif } else { ld_state = LS_PROD_MISMATCH; } } else { ld_state = LS_INVALID; } //If license is valid, update ld_vtime with current time. if (ld_state == LS_VALID) { ld_vtime = abstime.tv_sec; } } /* * Print any info/warning messages based on status of license. */ print: ld_cktime = abstime.tv_sec; if (ld_state == LS_VALID) { // Print any warning, if we are near to expiry. check_validity_left(data, inst_type, type, daemon); } else if (ld_state == LS_EXPIRED) { // If license has expired, then it has to be periodic. plat_assert(type != LPT_PERPETUAL); if (daemon) { plat_log_msg(160155, LOG_CAT, LOG_WARN, "License has expired. Renew the license."); } p = getptr(data, LDI_DIFF_TO); plat_assert(p); if (p) { exptime = getas(p, double); plat_assert(exptime < 0); exptime = -exptime; //Get the grce period of license file supports //Print warning & find period we need to make next check p = getptr(data, LDI_GRACE_PRD); if (p) { check_time_left(exptime, getas(p, double), daemon); } else { check_time_left(exptime, ZS_EXP_GPRD, daemon); } } } else {