// ExgLibDisconnect Err FlickrDisconnect(UInt16 libRefnum, ExgSocketType *exgSocket, Err err) { DMSG("FlickrDisconnect() enter; err: "); DNUM(err); DENDL; FlickrDbOpen dbOpen; FlickrSocketContext* context = (FlickrSocketContext*)exgSocket->socketRef; if (NULL == context) { DMSG("FlickrDisconnect() context is NULL"); DENDL; if (errNone == err) err = exgErrUnknown; goto Finish; } if (errNone != err) goto Finish; err = FlickrUploadImage(*context, exgSocket); if (errNone == err && !context->prefs.dontShowUploadCompletedForm) err = FlickrShowUploadCompleted(*context); Finish: if (NULL != context && NULL != context->progress) { DMSG("PrgUpdateDialog() called"); DENDL; PrvUpdateProgress(*context, err); err = PrvProcessEvents(*context, 0); } delete context; exgSocket->socketRef = NULL; DMSG("FlickrDisconnect() exit; error: ");DNUM(err);DENDL return err; }
/************************************************************************** * Precentiles at given steps */ void HandleStepPercentiles(NUMSTAT *nsPO, DOUB *rvalsPD, int num, FILE *outPF) { int p,last; DOUB pD,jD; if(BAD_DOUB(nsPO->prsd)) { return; } HAND_NFILE(outPF); /*** * Limit step */ LIMIT_NUM(nsPO->prsd, 100.0/DNUM(num), 100.0); fprintf(outPF,"%s# Percentile steps of %4.2f (min to max)\n", nsPO->echo, nsPO->prsd); if(nsPO->do_sl) { fprintf(outPF,"%sPercentiles",nsPO->prls); } /*** * Start at min == 0 percentile */ jD = DNUM(num) * nsPO->prsd / 100.0; pD = 0.0; p = last = 0; while(p < num) { ReportSingPercentile(nsPO, p, rvalsPD[p], num, outPF); pD += jD; last = p; p = ROUND(pD); } /*** * If not already reported, max == last percentile */ if( (p != last) && (p <= num) ) { p = num - 1; ReportSingPercentile(nsPO, p, rvalsPD[p], num, outPF); } if(nsPO->do_sl) { fprintf(outPF,"\n"); } return; }
static void FlickrSocketInspect(const ExgSocketType* exgSocket) { DMSG("FlickrSocketInspect() length: "); DNUM(exgSocket->length); DENDL; DMSG("FlickrSocketInspect() count: "); DNUM(exgSocket->count); DENDL; if (NULL != exgSocket->name) { DMSG("FlickrSocketInspect() name: "); DMSG(exgSocket->name); DENDL; } if (NULL != exgSocket->type) { DMSG("FlickrSocketInspect() type: "); DMSG(exgSocket->type); DENDL; } if (NULL != exgSocket->description) { DMSG("FlickrSocketInspect() description: "); DMSG(exgSocket->description); DENDL; } }
static Boolean FlickrErrCallback(PrgCallbackData* data) { DMSG("FlickrErrCallback(): enter; error: "); DNUM(data->error); DENDL; assert(errNone != data->error); const char* text = NULL; switch (data->error) { case memErrNotEnoughSpace: case exgMemError: text = "Not enough memory to complete operation."; break; case flickrErrHttpUnsupportedResponse: text = "Server returned malformed response."; break; case flickrErrUploadInvalidLogin: text = "Invalid flickr.com login. Please verify your email and password."; break; case flickrErrUploadFileTypeNotRecognized: text = "Server rejected this file type."; break; case flickrErrUploadExceededUploadLimit: text = "Exceeded flickr.com upload limit."; break; case flickrErrUploadFileSizeZero: case flickrErrUploadGeneralFailure: case flickrErrUploadNoPhoto: case flickrErrUploadUnknown: text = "Unable to complete operation: unknown flickr.com error."; break; case exgErrUserCancel: text = "Cancelled by user."; break; default: if (data->error >= netErrorClass && data->error < netErrorClass + 0x100) text = "Unable to complete operation: network error."; else text = "Unable to complete operation: unknown error."; } char buffer[32] = {chrNull}; if (data->showDetails) StrPrintF(buffer, "\nError: %hu", data->error); PrvFillBuffer(data->textP, data->textLen, text, buffer); DMSG("FlickrErrCallback(): exit"); DENDL; return true; }
// ExgLibSend UInt32 FlickrSend(UInt16 libRefNum, ExgSocketType *exgSocket, const void *bufP, UInt32 bufLen, Err *errP) { DMSG("FlickrSend() enter");DENDL; *errP = errNone; FlickrDbOpen dbOpen; FlickrSocketContext* context = (FlickrSocketContext*)exgSocket->socketRef; if (NULL == context) { DMSG("FlickrSend() context is NULL"); DENDL; *errP = exgErrUnknown; goto Finish; } DMSG("FlickrSend() bufLen: "); DNUM(bufLen); DENDL; *errP = FlickrAppendImageData(*context, bufP, bufLen); if (stageReadingImageData != context->stage) context->stage = stageReadingImageData; Finish: if (NULL != context && NULL != context->progress) { DMSG("PrgUpdateDialog() called"); DENDL; PrvUpdateProgress(*context, *errP); *errP = PrvProcessEvents(*context, 0); } if (errNone != *errP) { delete context; exgSocket->socketRef = NULL; } DMSG("FlickrSend() exit; error: ");DNUM(*errP);DENDL return bufLen; }
/************************************************************************** * Fill valsPD with rank values from sorted SCOREC */ int FillScorecRankArrayI(SCOREC *scPO,int n,DOUB *valsPD) { int i,j,tie; DOUB pvD,vD; i = 0; while(i<n) { tie = 1; pvD = scPO[i].sc; while( (scPO[i+tie].sc == pvD) && ((i+tie)<n) ) { tie++; } vD = DNUM(i) + DNUM(tie)/2.0 + 0.5; for(j=0;j<tie;j++) { valsPD[scPO[i+j].id] = vD; } i += tie; } return(TRUE); }
/*************************************************************************** * Fill line with symbols to plot histogram * bval = bin count * ncum = cumulative bin count * max = max bin (i.e. mode) * win = win = windows size (i.e. char width) */ void FillHisPlotLine(int bval, int ncum, int max, int win, char *bufS) { int i,j,n,m,clip; if(ncum > 0) { n = ROUND( DNUM(ncum)/DNUM(max) * DNUM(win) ); m = ROUND( DNUM(bval)/DNUM(max) * DNUM(win) ); } else { n = m = ROUND( DNUM(bval)/DNUM(max) * DNUM(win) ); } /*** * If bar would be bigger than window size, clip */ clip = (n>win) ? TRUE : FALSE; LIMIT_NUM(n,0,win); j = 0; if(bval>0) { bufS[j] = '|'; } else { bufS[j] = ' '; } j++; for(i=0;i<n;i++) { if( (clip) && ( (i == (n-3)) || (i== (n-5)) ) ) { bufS[j] = '/'; } else if( (clip) && (i == (n-4)) ) { bufS[j] = ' '; } else if(i>=m) { bufS[j] = '.'; } else { bufS[j] = 'X'; } j++; } bufS[j] = '\0'; }
/************************************************************************** * Precentiles given as a comma-sep list */ void HandleListPercentiles(NUMSTAT *nsPO, DOUB *rvalsPD, int num, FILE *outPF) { char *cPC; int p; DOUB pD,prsD; HAND_NFILE(outPF); /*** * Read list of comma-delimited percentiles */ ReplaceChars(',',nsPO->prls,' ',nsPO->prls); fprintf(outPF,"%s# Percentiles: %s\n", nsPO->echo, nsPO->prls); if(nsPO->do_sl) { fprintf(outPF,"%sPercentiles",nsPO->echo); } cPC = nsPO->prls; PASS_BLANK(cPC); while(ISLINE(*cPC)) { prsD = BAD_D; sscanf(cPC,"%lf",&prsD); if(BAD_DOUB(prsD)) { PROBLINE; printf("Bad percentile list format\n"); printf("|%s|\n",nsPO->prls); printf("Here: %s\n",cPC); return; } if( (prsD<0.0) || (prsD>100.0) ) { PROBLINE; printf("Bad percentile value listed\n"); printf("|%s|\n",nsPO->prls); printf("Bad: %f\n",prsD); return; } pD = DNUM(nsPO->num) * prsD / 100.0; p = ROUND(pD); LIMIT_NUM(p, 0, (num - 1)); ReportSingPercentile(nsPO, p, rvalsPD[p], num, outPF); NEXT_WORD(cPC); } if(nsPO->do_sl) { fprintf(outPF,"\n"); } return; }
/*************************************************************************** * Limits precision of val based on table settings and sets via pointer * new value */ int SetTableValPrecisionI(TABLE *tabPO, DOUB valD, DOUB *newPD) { DOUB intD,fracD; DB_TAB_LO DB_PrI(">> SetTableValPrecisionI val=%1.12f\n",valD); VALIDATE(tabPO,TABLE_ID); DB_TAB_LO DB_PrI("+ prenum=%d prefac=%1.12f\n",tabPO->prenum,tabPO->prefac); /*** * Only mess with the fractional part */ fracD = modf(valD,&intD); fracD = DNUM( ROUND(fracD * tabPO->prefac) ) / tabPO->prefac; *newPD = intD + fracD; DB_TAB_LO DB_PrI("<< SetTableValPrecisionI new=%1.12f TRUE\n",*newPD); return(TRUE); }
/************************************************************************* * Figure out discrete bin and start values */ int GetDiscreteBinStartI(DOUB binD, DOUB *binPD, DOUB loD, DOUB *loPD) { DOUB mD; MakeDiscreteValI(binD,&binD); mD = DNUM( INT(loD / binD) ) * binD; if(mD > loD) { mD -= binD; } loD = mD; if(binPD) { *binPD = binD; } if(loPD) { *loPD = loD; } return(TRUE); }
static MemHandle StrCopyToHandle(const char* text, Int16 len = -1) { if (-1 == len) len = StrLen(text); MemHandle handle = MemHandleNew(len + 1); if (NULL == handle) { DMSG("StrCopyToHandle(): MemHandleNew() failed; size: "); DNUM(len + 1); DENDL; return NULL; } char* p = (char*)MemHandleLock(handle); if (NULL == p) { MemHandleFree(handle); return NULL; } MemMove(p, text, sizeof(char) * len); p[len] = chrNull; MemPtrUnlock(p); return handle; }
int NumstatHandleHistI(NUMSTAT *nsPO) { int i,n,ncum,nun,nov,nmax,m1,m2; DOUB stD,enD,modeD; HISTOGRAM *hisPO; /*** * If not specified, set binning and bounds to auto values */ if(BAD_DOUB(nsPO->h_bin)) { nsPO->h_bin = nsPO->h_abin; } if(BAD_DOUB(nsPO->h_lo)) { nsPO->h_lo = nsPO->h_alo; } if(BAD_DOUB(nsPO->h_hi)) { nsPO->h_hi = nsPO->h_ahi; } NumlistToHistogramI(nsPO->vals, nsPO->h_bin, nsPO->h_lo, nsPO->h_hi, &hisPO); /*** * Get max total value or max his bin to normalize * Also under and over counts */ if(nsPO->do_ploti) { NumlistSumI(hisPO->bins, -1, -1, &modeD); nmax = INT(modeD); } else { NumlistStatsI(hisPO->bins, -1, -1, NULL,&modeD,NULL,NULL); nmax = INT(modeD); } GetHistogramUnOvCountsI(hisPO, &nun, &nov); if(nsPO->do_hends) { nmax = MAX_NUM(nmax ,nun); nmax = MAX_NUM(nmax ,nov); } /*** * Check if one bin dominates and truncate back if allowed */ if( (! nsPO->do_hntb) && (hisPO->n > 1) ) { GetHistogramMaxTwoBinsI(hisPO, &m1, &m2); if ( DNUM(m1) > (DNUM(m2) * nsPO->htb_xfold) ) { nmax = ROUND( DNUM(m2) * nsPO->htb_xfold ); } } /*** * Dump histogram values; Under, body, Over */ NumstatHistHeader(nsPO, hisPO, nsPO->out); ncum = nun; if(nsPO->do_hends && (nun > 0)) { HistogramValuesForBinI(hisPO,-1,NULL,NULL,&enD); NumPrecisionI(enD, NULL,NULL,NULL, nsPO->h_pfmt); OneHistLineNumsOut(nsPO, nun, enD, "<", ncum); OneHistLinePlotOut(nsPO, nun, ncum, nmax); fprintf(nsPO->out,"\n"); } HistogramAutoFormatStringI(hisPO, nsPO->h_pfmt); for(i=0; i < hisPO->n; i++) { HistogramValuesForBinI(hisPO,i,&n,&stD,&enD); ncum += n; OneHistLineNumsOut(nsPO, n, stD, NULL, ncum); OneHistLinePlotOut(nsPO, n, ncum, nmax); fprintf(nsPO->out,"\n"); } if(nsPO->do_hends && (nov > 0)) { HistogramValuesForBinI(hisPO,hisPO->n,NULL,&stD,NULL); NumPrecisionI(stD, NULL,NULL,NULL, nsPO->h_pfmt); ncum += nov; OneHistLineNumsOut(nsPO, nov, stD, ">", ncum); OneHistLinePlotOut(nsPO, nov, ncum, nmax); fprintf(nsPO->out,"\n"); } CHECK_HISTOGRAM(hisPO); return(TRUE); }
/************************************************************************** * Quantil-ize table columns */ int QuantileTableColsI(TABLE *tabPO, int parts, int mask, int verbose) { int c,r,nr,nc,quant,qi,lastb; DOUB vD,qvalD,bvalD,jumpD; SCOREC *cvalsPO; char cnameS[NSIZE],vformS[DEF_BS]; VALIDATE(tabPO,TABLE_ID); nr = GetTableRowsI(tabPO,mask); nc = GetTableColsI(tabPO,mask); GetTablePrintformI(tabPO,vformS,NULL,NULL,NULL,NULL); /*** * Cannot split into more parts than rows * Alloc sorting structure for n-rows */ LIMIT_NUM(parts,0,nr); if(parts < 2) { return(TRUE); } if(!(cvalsPO = CreateScorecsPO(nr))) { PROBLINE; printf("Failed to allocate temp struct for %d rows (QuantileTableColsI)\n",nr); return(FALSE); } /*** * Jump for each quantile; Tell story for whole set; */ jumpD = DNUM(nr) / DNUM(parts); if(verbose) { printf("# QuanTab splitting %d rows into %d parts (%0.3f)\n",nr,parts,jumpD); } lastb = INT(DNUM(nr) * DNUM(parts-1) / DNUM(parts)) + 1; /*** * Each column */ for(c=0;c<nc;c++) { if( (mask) && (!tabPO->cmask[c]) ) { continue; } GetTableColLabI(tabPO,c,cnameS,-1); /*** * Copy values into structure then sort */ for(r=0;r<nr;r++) { GetTableValI(tabPO,r,c,&vD); cvalsPO[r].sc = vD; } SortScorecVals(cvalsPO,nr,1); /*** * Initialize; "bins" are at least jump wide, but can be wider if ties */ quant = 1; bvalD = jumpD; qi = INT(bvalD) - 1; BOG_CHECK(qi >= nr); qvalD = cvalsPO[qi].sc; /* printf("first bval=%f qi=%d qval=%f\n",bvalD,qi,qvalD); */ if(verbose) { printf("# QuanTab col_%02d %s quant %d ind %d val <= ",c,cnameS,quant,qi); printf(vformS,qvalD); printf("\n"); } /*** * Now replace records with quantiles * ... Not clear correct partitioning (sham?); No "little" last bin * ... Calc (logic?) for moving to next bin also a mess (sham?) */ for(r=0;r<nr;r++) { /*if( (cvalsPO[r].sc > qvalD) ){ */ if( (cvalsPO[r].sc > qvalD) && (r<=lastb) ){ quant++; bvalD = (DNUM(r) > bvalD) ? DNUM(r) : bvalD; bvalD += jumpD; qi = INT(bvalD) - 1; LIMIT_NUM(qi,0,(nr-1)); qvalD = cvalsPO[qi].sc; /* printf("quant=%d r=%d bval=%f qi=%d qval=%f\n",quant,r,bvalD,qi,qvalD); */ if(verbose) { printf("# QuanTab col_%02d %s quant %d ind %d val <= ",c,cnameS,quant,qi); printf(vformS,qvalD); printf("\n"); } } GetTableValI(tabPO,cvalsPO[r].id,c,&vD); vD = DNUM(quant); /* SetTableValI(tabPO,cvalsPO[r].id,c,qvalD); */ SetTableValI(tabPO,cvalsPO[r].id,c,vD); } } CHECK_SCOREC(cvalsPO); return(TRUE); }
/************************************************************************** * Calculate Tm with PNA algorithm; */ DOUB CalcPNATmI(TM_PARS *tmPO,char *seqS,int len) { int i,n_pyr; DOUB tmD,hD,sD,hsumD,ssumD; DB_DNA_TM DB_PrI(">> CalcPNATmI\n"); /*** * Tally sequence pairs and pyridines */ hsumD = ssumD = 0.0; n_pyr = 0; for(i=0;i<(len-1);i++) { /*** * Entropy / enthalpy terms */ hD = sD = 0.0; switch(seqS[i]) { case 'A': case 'a': switch(seqS[i+1]) { case 'A': case 'a': hD = -8400; sD = -23.6; break; case 'C': case 'c': hD = -8600; sD = -23.0; break; case 'G': case 'g': hD = -6100; sD = -16.1; break; case 'T': case 't': hD = -6500; sD = -18.8; break; } break; case 'C': n_pyr++; switch(seqS[i+1]) { case 'A': case 'a': hD = -7400; sD = -19.3; break; case 'C': case 'c': hD = -6700; sD = -15.6; break; case 'G': case 'g': hD = -10100; sD = -25.5; break; case 'T': case 't': hD = -6100; sD = -16.1; break; } break; case 'G': switch(seqS[i+1]) { case 'A': case 'a': hD = -7700; sD = -20.3; break; case 'C': case 'c': hD = -11100; sD = -28.4; break; case 'G': case 'g': hD = -6700; sD = -15.6; break; case 'T': case 't': hD = -8600; sD = -23.0; break; } break; case 'T': n_pyr++; switch(seqS[i+1]) { case 'A': case 'a': hD = -6300; sD = -18.5; break; case 'C': case 'c': hD = -7700; sD = -20.3; break; case 'G': case 'g': hD = -7400; sD = -19.3; break; case 'T': case 't': hD = -8400; sD = -23.6; break; } break; } hsumD += hD; ssumD += sD; } if( (seqS[len-1]=='C') || (seqS[len-1]=='c') || (seqS[len-1]=='T') || (seqS[len-1]=='t') ) { n_pyr++; } DB_DNA_TM DB_PrI("+ H=%f S=%f npyr=%d\n",hsumD,ssumD,n_pyr); /*** * Calculate Tm */ tmD = hsumD / (ssumD + 1.987 * log(tmPO->conc/4.0)) - 273.15; tmD *= PNA_TM_SC_D; tmD += PNA_TM_CON_D; tmD += (PNA_TM_PYR_D * (DNUM(n_pyr)/DNUM(len))); tmD += (PNA_TM_LEN_D * DNUM(len)); DB_DNA_TM DB_PrI("<< CalcPNATmI %f\n",tmD); return(tmD); }
/************************************************************************* * Find stats for between-value differences */ int NumlistDifStatsI(NUMLIST *nlPO, DOUB *minPD, DOUB *maxPD, DOUB *avPD) { int len,i,nd; DOUB v1D,v2D, delD, minD, maxD, avD; NUMLIST *newPO; VALIDATE(nlPO,NUMLIST_ID); len = GetNumlistLengthI(nlPO); if(len<2) { PROBLINE; printf("No dif stats for array with %d elements!\n",len); return(FALSE); } /*** * Duplicate so we can sort without messing up given order */ if(!(newPO = DuplicateNumlistPO(nlPO,-1))) { PROBLINE; printf("Failed to duplicate numbers for dif stats\n"); return(FALSE); } SortNumlistI(newPO, SORT_ASCEND); /*** * Init, then party through rest of list looking at difs */ minD = TOO_BIG_D; maxD = avD = 0.0; GetNumlistIntDoubI(newPO,0,NULL,&v1D); nd = 0; for(i=1;i<len;i++) { GetNumlistIntDoubI(newPO,i,NULL,&v2D); delD = v2D - v1D; if(v2D != v1D) { nd++; if(delD < minD) { minD = delD; } if(delD > maxD) { maxD = delD; } } avD += delD; v1D = v2D; } /*** * Special case where all the same, so no difs ever evaluated * Set min and max to 0; Av = any value = last one (v2) */ if(nd < 1) { minD = maxD = 0.0; avD = v2D; } if(minPD) { *minPD = minD; } if(maxPD) { *maxPD = maxD; } if(avPD) { if(nd > 0) { avD = avD / DNUM(len); } *avPD = avD; } CHECK_NUMLIST(newPO); return(len); }
/*************************************************************************** * Pick "natural" histogram bin based on minium spacing between values, * truncated to max wanted bins * The maximum number of bins is specified by max * If dhis is true, discrete-bounded histogram bins are chosen * Sets starting bin value via lowPD * Sets bin size value via binPD * Returns number of different values */ int NaturalHistBinI(DOUB *valsPD, int num, int max, int dhis, DOUB *lowPD, DOUB *binPD) { int i,n; DOUB pD,minD,maxD,binD,nminD; SCOREC *scPO; DB_STAT DB_PrI(">> NaturalHistBinI, num=%d, max=%d, dhis=%d\n",num,max,dhis); /*** * Init */ if(lowPD) { *lowPD = BAD_D; } if(binPD) { *binPD = BAD_D; } if( (num<1) || (!(scPO=CreateScorecsPO(num))) ) { DB_STAT DB_PrI("<< NaturalHistBinI FALSE\n"); return(FALSE); } /*** * Fill values then sort if needed */ minD = TOO_BIG_R; maxD = -TOO_BIG_R; for(i=0;i<num;i++) { minD = MIN_NUM(valsPD[i], minD); maxD = MAX_NUM(valsPD[i], maxD); scPO[i].sc = valsPD[i]; } /*** * Find min between-value spacing */ if( minD == maxD ) { binD = 1.0; } else { SortScorecVals(scPO,num,SORT_ASCEND); binD = maxD - minD; pD = scPO[0].sc; for(i=1; i<num; i++) { /*** * If current != previous, bin = save min diff */ if(scPO[i].sc != pD) { binD = MIN_NUM(binD, (scPO[i].sc - pD) ); pD = scPO[i].sc; } } } CHECK_SCOREC(scPO); DB_STAT DB_PrI("+ min=%f max=%f bin=%f\n",minD,maxD,binD); /*** * Shrink if too many bins */ n = INT( (maxD-minD)/binD); if(max>0) { while(n>max) { binD = binD * 2.0; n = n/2; } } /*** * Discrete values */ if(dhis) { MakeDiscreteValI(binD,&binD); nminD = DNUM( INT(minD/binD) ) * binD; if(nminD > minD) { nminD -= binD; } minD = nminD; } DB_STAT DB_PrI("+ min=%f bin=%f\n",minD,binD); if(lowPD) { *lowPD = minD; } if(binPD) { *binPD = binD; } DB_STAT DB_PrI("<< NaturalHistBinI %d\n",n); return(n); }
/************************************************************************** * Pick "natural" histogram bin */ int NumlistNaturalHistBinI(NUMLIST *nlPO, int max_bin, int dhis, DOUB *binPD, DOUB *lowPD, DOUB *hiPD) { int n; DOUB binD,minD,maxD,min_difD; DB_STAT DB_PrI(">> NumlistNaturalHistBinI max=%d, dhis=%d\n",max_bin,dhis); VALIDATE(nlPO,NUMLIST_ID); /* n = GetNumlistLengthI(nlPO); if(n<2) { return(FALSE); } */ if(!NumlistStatsI(nlPO,-1,-1, &minD, &maxD, NULL, NULL)) { DB_STAT DB_PrI("<< NumlistNaturalHistBinI Stats failed FALSE\n"); return(FALSE); } if(!NumlistDifStatsI(nlPO, &min_difD, NULL, NULL)) { DB_STAT DB_PrI("<< NumlistNaturalHistBinI DifStats failed FALSE\n"); return(FALSE); } /*** * Flat = one bin, else min diff */ if( minD == maxD ) { binD = 1.0; } else { binD = min_difD; } DB_STAT DB_PrI("+ min=%f max=%f min_dif=%f bin=%f\n",minD,maxD,min_difD,binD); /*** * Shrink if too many bins */ n = INT( (maxD-minD)/binD); DB_STAT DB_PrI("+ n=%d ... ",n); if(max_bin>0) { while(n > max_bin) { binD = binD * 2.0; n = n/2; } } DB_STAT DB_PrI("n=%d bin=%f\n",n,binD); /*** * Discrete values? */ if(dhis) { DB_STAT DB_PrI("+ calling to make bin and min discrete\n"); GetDiscreteBinStartI(binD, &binD, minD, &minD); } n = INT( (maxD-minD)/binD); maxD = minD + DNUM(n) * binD; DB_STAT DB_PrI("+ n=%d bin=%f min=%f max=%f\n",n,binD,minD,maxD); if(binPD) { *binPD = binD; } if(lowPD) { *lowPD = minD; } if(hiPD) { *hiPD = maxD; } DB_STAT DB_PrI("<< NumlistNaturalHistBinI %d\n",n); return(n); }
// ExgLibPut Err FlickrPut(UInt16 libRefnum, ExgSocketType* exgSocket) { DMSG("FlickrPut() enter"); DENDL; FlickrDbOpen dbOpen; assert(exgSocket->libraryRef == libRefnum); FlickrSocketContext* context = NULL; const char* extension = NULL; const char* mimeType = NULL; const char* name = NULL; Err err = FlickrDetectExtensionAndType(exgSocket, extension, mimeType, name); if (errNone != err) { FlickrAlert(unsupportedFormatAlert); goto Finish; } DMSG("FlickrPut() using extension: "); DMSG(extension); DMSG(" and type: "); DMSG(mimeType); DENDL; if (NULL != exgSocket->socketRef) { DMSG("FlickrPut(): socketRef is not NULL!");DENDL; context = (FlickrSocketContext*)exgSocket->socketRef; if (FlickrSocketContext::magicValue != context->magic) { DMSG("FlickrPut(): socketRef probably is not context, magic value mismatch"); DENDL; exgSocket->socketRef = NULL; } else { err = FlickrUploadImage(*context, exgSocket); if (errNone != err) goto Finish; err = context->Reset(); if (errNone != err) goto Finish; } } if (NULL == exgSocket->socketRef) { context = new FlickrSocketContext(libRefnum); if (NULL == context) { DMSG("FlickrPut(): not enough memory to create FlickrSocketContext");DENDL; FlickrAlert(notEnoughMemoryAlert); err = exgMemError; goto Finish; } err = context->Init(); if (errNone != err) { // TODO: inspect error and display appropriate alert goto Finish; } exgSocket->socketRef = (UInt32)context; MemPtrSetOwner(context, 0); } bool hasCredentials; err = FlickrVerifyUserCredentials(hasCredentials, context->prefs); if (errNone != err) goto Finish; if (!hasCredentials) { DMSG("FlickrVerifyUserCredentials() returned false"); DENDL; err = FlickrGetUserCredentials(context->prefs); if (errNone != err) goto Finish; } DMSG("FlickrPut() user credentials obtained succesfully; email: "); DMSG(context->prefs.email); DMSG("; password: "******"PrgUpdateDialog() called"); DENDL; PrvUpdateProgress(*context, err); err = PrvProcessEvents(*context, 0); } if (errNone != err) { delete context; exgSocket->socketRef = NULL; } DMSG("FlickrPut() exit; error: ");DNUM(err);DENDL return err; }
/************************************************************************** * Rank correlation coefficient * ALLOCATES AND FREES TEMP ARRAYS HERE */ DOUB RankCorD(void *aPO, void *bPO, int n, int ct) { int i, *iPI,*jPI; REAL *iPR,*jPR; DOUB rD,*iPD,*jPD; DOUB *rank1PD,*rank2PD; SCOREC *sc1PO, *sc2PO; DB_STAT DB_PrI(">> RankCorD, n=%d, ct=%d\n",n,ct); /*** * Attempt to allocate arrays */ sc1PO = CreateScorecsPO(n); sc2PO = CreateScorecsPO(n); rank1PD = (DOUB *)ALLOC(n,sizeof(DOUB)); rank2PD = (DOUB *)ALLOC(n,sizeof(DOUB)); if( (!sc1PO) || (!sc1PO) || (!rank1PD) || (!rank2PD) ) { printf("Problem allocating temp space for rank correlations!\n"); CHECK_FREE(sc1PO); CHECK_FREE(sc2PO); CHECK_FREE(rank1PD); CHECK_FREE(rank2PD); return(-TOO_BIG_R); } /*** * Copy values from passed arrays SCORECs for sorting */ switch(ct) { case IS_INT: iPI = (int *)aPO; jPI = (int *)bPO; for(i=0;i<n;i++) { sc1PO[i].sc = DNUM(iPI[i]); sc2PO[i].sc = DNUM(jPI[i]); } break; case IS_REAL: iPR = (REAL *)aPO; jPR = (REAL *)bPO; for(i=0;i<n;i++) { sc1PO[i].sc = DNUM(iPR[i]); sc2PO[i].sc = DNUM(jPR[i]); } break; case IS_DOUB: iPD = (DOUB *)aPO; jPD = (DOUB *)bPO; for(i=0;i<n;i++) { sc1PO[i].sc = iPD[i]; sc2PO[i].sc = jPD[i]; } break; default: CHECK_FREE(sc1PO); CHECK_FREE(sc2PO); CHECK_FREE(rank1PD); CHECK_FREE(rank2PD); printf("Bogus ct code=%d\n",ct); ERR("RankCorD","Bogus ct code"); return(-TOO_BIG_R); } /*** * Sort arrays and get rank arrays */ SortScorecVals(sc1PO,n,SORT_ASCEND); SortScorecVals(sc2PO,n,SORT_ASCEND); FillScorecRankArrayI(sc1PO,n,rank1PD); FillScorecRankArrayI(sc2PO,n,rank2PD); /*** * Now get normal coorelation on rank arrays */ rD = PearsonsCorD(rank1PD,rank2PD,n,IS_DOUB); /*** * Clean up and bail */ CHECK_FREE(sc1PO); CHECK_FREE(sc2PO); CHECK_FREE(rank1PD); CHECK_FREE(rank2PD); return(rD); }
// ExgLibControl Err FlickrControl(UInt16 libRefNum, UInt16 op, void *valueP, UInt16 *valueLenP) { DMSG("FlickrControl() enter, op: ");DNUM(op);DMSG("; *valueLenP: ");DNUM(*valueLenP);DENDL FlickrDbOpen dbOpen; FlickrGlobalsPtr globals(libRefNum); switch (op) { case exgLibCtlGetTitle: { DMSG("FlickrControl(): exgLibCtlGetTitle\n"); if (NULL == valueLenP) return exgErrBadParam; UInt16 len = StrLen(FlickrTitle); if (0 == *valueLenP || NULL == valueP) { *valueLenP = len; return errNone; } if (*valueLenP - 1 < len) { StrNCopy((char*)valueP, FlickrTitle, *valueLenP - 1); ((char*)valueP)[*valueLenP - 1] = chrNull; } else { StrCopy((char*)valueP, FlickrTitle); *valueLenP = len + 1; } return errNone; } case exgLibCtlGetVersion: { DMSG("FlickrControl(): exgLibCtlGetVersion\n"); if (NULL == valueP || NULL == valueLenP || *valueLenP < 2) return exgErrBadParam; UInt16* ver = (UInt16*)valueP; *ver = exgLibAPIVersion; *valueLenP = 2; return errNone; } case exgLibCtlGetPreview: DMSG("FlickrControl(): exgLibCtlGetPreview\n"); return exgErrNotSupported; case flickrCtlLibraryVersion: { DMSG("FlickrControl(): flickrCtlLibraryVersion\n"); if (NULL == valueP || NULL == valueLenP || *valueLenP < 2) return exgErrBadParam; UInt16* ver = (UInt16*)valueP; *ver = FlickrVersion; *valueLenP = 2; return errNone; } case flickrCtlInitializePrefs: { DMSG("FlickrControl(): flickrCtlInitializePrefs\n"); FlickrPrefs* prefs = new FlickrPrefs; if (NULL == prefs) return memErrNotEnoughSpace; MemSet(prefs, sizeof(*prefs), 0); UInt16 size = sizeof(*prefs); Int16 ver = PrefGetAppPreferences(FlickrCreatorID, flickrPrefsResourceID, prefs, &size, true); if (noPreferenceFound != ver) goto Finish; PrvPrepareDescriptionText(*prefs); PrvPrepareTags(*prefs); FlickrSavePrefs(*prefs); Finish: delete prefs; return errNone; } } return exgErrNotSupported; }
/************************************************************************** * Pearson's correlation coefficient */ DOUB PearsonsCorD(void *aPO, void *bPO, int n, int ct) { int i, *iPI,*jPI; REAL *iPR,*jPR; DOUB rD; DOUB *iPD,*jPD,syyD,sxyD,sxxD,axD,ayD,xtD,ytD; DB_STAT DB_PrI(">> PearsonsCorD, n=%d, ct=%d\n",n,ct); /*** * Get array averages */ ArrayStatsI(aPO, ct, 0, n, NULL, NULL, &axD, NULL); ArrayStatsI(bPO, ct, 0, n, NULL, NULL, &ayD, NULL); DB_STAT DB_PrI("+ x %f, y %f\n",axD,ayD); /*** * Tally difference sums */ syyD = sxyD = sxxD = 0.0; switch(ct) { case IS_INT: iPI = (int *)aPO; jPI = (int *)bPO; for(i=0; i<n; i++) { xtD = DNUM(iPI[i]) - axD; ytD = DNUM(jPI[i]) - ayD; sxxD += (xtD * xtD); syyD += (ytD * ytD); sxyD += (xtD * ytD); } break; case IS_REAL: iPR = (REAL *)aPO; jPR = (REAL *)bPO; for(i=0; i<n; i++) { xtD = DNUM(iPR[i]) - axD; ytD = DNUM(jPR[i]) - ayD; sxxD += (xtD * xtD); syyD += (ytD * ytD); sxyD += (xtD * ytD); } break; case IS_DOUB: iPD = (DOUB *)aPO; jPD = (DOUB *)bPO; for(i=0; i<n; i++) { xtD = iPD[i] - axD; ytD = jPD[i] - ayD; sxxD += (xtD * xtD); syyD += (ytD * ytD); sxyD += (xtD * ytD); } break; default: printf("Bogus ct code=%d\n",ct); ERR("PearsonsCorD","Bogus ct code"); return(-TOO_BIG_R); } DB_STAT DB_PrI("+ sx %f, sy %f, sxy\n",sxxD,syyD,sxyD); rD = DNUM(sxyD / (sqrt(sxxD*syyD) + PEARSON_TINY) ); DB_STAT DB_PrI("<< PearsonsCorD %f\n",rD); return(rD); }
int NumlistMutInfoI(NUMLIST *nums1PO, NUMLIST *nums2PO, int maxb, DOUB *minfPD, int *nb1PI, int *nb2PI) { int i,r,c,n,nrow,ncol,dis_bin; DOUB vD, bin1D, bin2D, st1D, st2D, en1D, en2D, infoD; HISTOGRAM *his1PO, *his2PO; TABLE *tabPO; DB_MINF DB_PrI(">> NumlistMutInfoI maxb=%d\n",maxb); VALIDATE(nums1PO,NUMLIST_ID); VALIDATE(nums2PO,NUMLIST_ID); if( !NumlistSameLenI(nums1PO,nums2PO) ) { DB_MINF DB_PrI("<< NumlistMutInfoI not same len FALSE\n"); return(FALSE); } n = GetNumlistLengthI(nums1PO); DB_MINF DB_PrI("+ number lists %d long\n",n); /*** * Get histograms from number lists */ dis_bin = FALSE; NumlistNaturalHistBinI(nums1PO, maxb, dis_bin, &bin1D, &st1D, &en1D); NumlistNaturalHistBinI(nums2PO, maxb, dis_bin, &bin2D, &st2D, &en2D); DB_MINF DB_PrI("+ Hist1 bin=%f st=%f en=%f\n",bin1D,st1D,en1D); DB_MINF DB_PrI("+ Hist2 bin=%f st=%f en=%f\n",bin2D,st2D,en2D); his1PO = his2PO = NULL; NumlistToHistogramI(nums1PO, bin1D, st1D, en1D, &his1PO); NumlistToHistogramI(nums2PO, bin2D, st2D, en2D, &his2PO); if( (!his1PO) || (!his2PO) ) { CHECK_HISTOGRAM(his1PO); CHECK_HISTOGRAM(his2PO); DB_MINF DB_PrI("<< NumlistMutInfoI nums to histograms %p %p FALSE\n",his1PO,his2PO); return(FALSE); } nrow = GetHistogramNumBinsI(his1PO); ncol = GetHistogramNumBinsI(his2PO); DB_MINF DB_PrI("+ histogram bins nrow=%d ncol=%d\n",nrow,ncol); if( (nrow < 2) || (ncol < 2) ) { CHECK_HISTOGRAM(his1PO); CHECK_HISTOGRAM(his2PO); DB_MINF DB_PrI("<< NumlistMutInfoI not enough bins FALSE\n"); return(FALSE); } /*** * Allocate space */ tabPO = CreateTablePO(nrow, ncol); if( !tabPO ) { CHECK_HISTOGRAM(his1PO); CHECK_HISTOGRAM(his2PO); DB_MINF DB_PrI("<< NumlistMutInfoI failed table space FALSE\n"); return(FALSE); } /*** * Fill joint probabilities from pairwise screen of input data */ for(i=0;i<n;i++) { GetNumlistIntDoubI(nums1PO,i,NULL,&vD); HistogramBinForValueI(his1PO, vD, &r, NULL,NULL); GetNumlistIntDoubI(nums2PO,i,NULL,&vD); HistogramBinForValueI(his2PO, vD, &c, NULL,NULL); GetTableValI(tabPO,r,c,&vD); vD += 1.0; SetTableValI(tabPO,r,c,vD); } DB_MINF { printf("\n xxxxxxxxxxxxxxxxxxxxxx\n"); DumpNumlist(his1PO->bins,-1,-1, NULL, NULL); DumpNumlist(his2PO->bins,-1,-1, NULL, NULL); AutoTableOutFormattingI(tabPO,TRUE,TRUE); DumpTable(tabPO,TRUE,FALSE,NULL); } /*** * Now the info */ infoD = 0.0; for(r=0;r<nrow;r++) { GetNumlistIntDoubI(his1PO->bins,r,NULL,&bin1D); bin1D = bin1D / DNUM(n); for(c=0;c<ncol;c++) { GetTableValI(tabPO,r,c,&vD); if(vD == 0.0) { continue; } vD = vD / DNUM(n); GetNumlistIntDoubI(his2PO->bins,c,NULL,&bin2D); bin2D = bin2D / DNUM(n); /* printf("[%d][%d]\tbin1=%f\tbin2=%f\tv=%f",r,c,bin1D,bin2D,vD); */ vD = vD * LOG_2(vD / (bin1D * bin2D)); infoD += vD; /* printf("\tV=%f\tinfo=%f\n",vD,infoD); */ SetTableValI(tabPO,r,c,vD); } } DB_MINF { AutoTableOutFormattingI(tabPO,TRUE,TRUE); DumpTable(tabPO,TRUE,FALSE,NULL); } DB_MINF DB_PrI("+ info = %f\n",infoD); /*** * Set values and clean up */ if(nb1PI) { *nb1PI = nrow; } if(nb2PI) { *nb2PI = ncol; } if(minfPD) { *minfPD = infoD; } CHECK_TABLE(tabPO); CHECK_HISTOGRAM(his1PO); CHECK_HISTOGRAM(his2PO); DB_MINF DB_PrI("<< NumlistMutInfoI TRUE\n"); return(TRUE); }