int Save(FILE* outputfile, int geneID, int arrayID) { int row, column; if (geneID) fputs("GID\t", outputfile); fputs(_uniqID, outputfile); fputs("\tNAME\tGWEIGHT", outputfile); /* Now add headers for data columns */ for (column = 0; column < _columns; column++) { putc('\t', outputfile); fputs(_arrayname[_arrayindex[column]], outputfile); } putc('\n', outputfile); if (arrayID) { fputs("AID", outputfile); if (geneID) putc('\t',outputfile); fputs("\t\t", outputfile); for (column = 0; column < _columns; column++) { char* ID = MakeID("ARRY",_arrayindex[column]); if (!ID) return 0; putc('\t', outputfile); fputs(ID, outputfile); free(ID); } putc('\n', outputfile); } fputs("EWEIGHT", outputfile); if (geneID) putc('\t', outputfile); fputs("\t\t", outputfile); for (column = 0; column < _columns; column++) fprintf(outputfile, "\t%f", _arrayweight[_arrayindex[column]]); putc('\n', outputfile); for (row = 0; row < _rows; row++) { int index = _geneindex[row]; if (geneID) { char* ID = MakeID("GENE",index); if (!ID) return 0; fputs(ID, outputfile); free(ID); putc('\t', outputfile); } fputs(_geneuniqID[index], outputfile); putc('\t', outputfile); if (_genename[index]) fputs(_genename[index], outputfile); else fputs(_geneuniqID[index], outputfile); fprintf(outputfile, "\t%f", _geneweight[index]); for (column = 0; column < _columns; column++) { int columnindex = _arrayindex[column]; putc('\t', outputfile); if (_mask[index][columnindex]) fprintf(outputfile, "%f", _data[index][columnindex]); } putc('\n', outputfile); } return 1; }
Player::Player(ClientSession* client, const std::string& playerName, PlayerType type) { m_PlayerID = MakeID(this); m_Client = client; m_PlayerName = playerName; m_PlayerType = type; }
CMyKadID::CMyKadID(CPrivateKey* pKey) { m_PrivateKey = pKey; m_PublicKey = pKey->PublicKey(); MakeID(m_PublicKey, GetData(), GetSize()); }
Matrix newIdMatrix(void) { Matrix C; C = newMatrix(); MakeID(C); return C; }
void HouseMatrix(Matrix H,Vector v, int start, int end) { int i,j; double a; a = 2.0/xty(v,v,start,end); MakeID(H); for (i=start;i<=end;i++) for (j=start;j<=end;j++) H[i][j] -= a*v[i]*v[j]; }
bool CKadID::SetKey(CHolder<CPublicKey>& pKey, UINT eAlgorithm) { if(m_PublicKey) return m_PublicKey->GetSize() == pKey->GetSize() && memcmp(m_PublicKey->GetKey(), pKey->GetKey(), m_PublicKey->GetSize()) == 0; CUInt128 ID; MakeID(pKey, ID.GetData(), ID.GetSize(), eAlgorithm); if(CompareTo(ID) != 0) return false; m_PublicKey = pKey; return true; }
void GetImage (ULONG *Buffer, struct Image *Image) { UWORD *Temp; ULONG i; if ( *(Buffer + 1) == MakeID ('F','O','R','M') ) { Image->ImageData = NULL; Image->Width = 0; if ( *(Buffer + 3) == MakeID ('I','L','B','M') ) { Temp = (UWORD *)Buffer + 8; i = Buffer[0]; while (i) { if (*(ULONG *)Temp == MakeID ('B','M','H','D') ) { Image->Width = *(Temp + 4); Image->Height = *(Temp + 5); Image->LeftEdge = 0; Image->TopEdge = 0; Image->Depth = 1; Image->PlanePick = 1; Image->PlaneOnOff = 0; Image->NextImage = NULL; } if (*(ULONG *)Temp == MakeID ('B','O','D','Y') ) { Image->ImageData = Temp + 4; } i -= 2; Temp++; } } } }
sas_file_spectral_t sas_file_spectral_make_from_msm_file (const char * filename) { sas_file_spectral_t sp; int i; FILE * fp; ULONG id; LONG size; fp = fopen (filename, "rb"); if (!fp) return NULL; if ((!IO_Read_BE_ULONG (&id, fp)) || (id != MakeID ('S', 'M', 'S', 'F')) || (!IO_Read_BE_LONG (&size, fp)) || (size <= 0)) { fclose (fp); return NULL; } sp = sas_file_spectral_make (SAS_SAMPLING_RATE / SAS_SAMPLES, size); for (i=0; i < size; i++) { sas_file_partial_t p; p = sas_file_partial_load (fp); if (!p) { sas_file_spectral_free (sp); fclose (fp); return NULL; } sas_file_spectral_add (sp, p); } fclose (fp); sp->filename = filename; return sp; }
void LR_parser::AddBNF(const char* filename) { cfg_filepath = filename; // ask the ID name from the lex int size = lex->getRuleSize(); vmap.constSize = size-1; for (int i = 1; i< size; ++i) { vmap.InsertVt(lex->getRule(i), i); } bnfparser = new BNFParser(); State* root = bnfparser->Analysis(filename); if (root == NULL) { printf("Error State\n"); delete bnfparser; return; } // bnfparser->printTree(); bnflist = BNF::BuildAllBNF(root,vmap); bnfparser->MakePrecedence(vmap); ExtendBNF(); MakeID(); // for each state, make a ID for it }
int HierarchicalCluster(FILE* file, char metric, int transpose, char method) { int i; int ok = 0; const int nNodes = (transpose ? _columns : _rows) - 1; const double* order = (transpose==0) ? _geneorder : _arrayorder; double* weight = (transpose==0) ? _arrayweight : _geneweight; const char* keyword = (transpose==0) ? "GENE" : "ARRY"; double* nodeorder = malloc(nNodes*sizeof(double)); int* nodecounts = malloc(nNodes*sizeof(int)); char** nodeID = calloc(nNodes, sizeof(char*)); /* Perform hierarchical clustering. */ Node* tree = treecluster(_rows, _columns, _data, _mask, weight, transpose, metric, method, NULL); if (!tree || !nodeorder || !nodecounts || !nodeID) { if (tree) free(tree); if (nodeorder) free(nodeorder); if (nodecounts) free(nodecounts); if (nodeID) free(nodeID); return 0; } if (metric=='e' || metric=='b') /* Scale all distances such that they are between 0 and 1 */ { double scale = 0.0; for (i = 0; i < nNodes; i++) if (tree[i].distance > scale) scale = tree[i].distance; if (scale) for (i = 0; i < nNodes; i++) tree[i].distance /= scale; } /* Now we join nodes */ for (i = 0; i < nNodes; i++) { int min1 = tree[i].left; int min2 = tree[i].right; /* min1 and min2 are the elements that are to be joined */ double order1; double order2; int counts1; int counts2; char* ID1; char* ID2; nodeID[i] = MakeID("NODE",i+1); if (!nodeID[i]) break; if (min1 < 0) { int index1 = -min1-1; order1 = nodeorder[index1]; counts1 = nodecounts[index1]; ID1 = nodeID[index1]; tree[i].distance = max(tree[i].distance, tree[index1].distance); } else { order1 = order[min1]; counts1 = 1; ID1 = MakeID(keyword, min1); } if (min2 < 0) { int index2 = -min2-1; order2 = nodeorder[index2]; counts2 = nodecounts[index2]; ID2 = nodeID[index2]; tree[i].distance = max(tree[i].distance, tree[index2].distance); } else { order2 = order[min2]; counts2 = 1; ID2 = MakeID(keyword, min2); } if (ID1 && ID2) { fprintf(file, "%s\t%s\t%s\t", nodeID[i], ID1, ID2); fprintf(file, "%f\n", 1.0-tree[i].distance); } if (ID1 && min1>=0) free(ID1); if (ID2 && min2>=0) free(ID2); if (!ID1 || !ID2) break; nodecounts[i] = counts1 + counts2; nodeorder[i] = (counts1*order1 + counts2*order2) / (counts1 + counts2); } if (i==nNodes) /* Otherwise we encountered the break */ { /* Now set up order based on the tree structure */ const char which = (transpose==0) ? 'g' : 'a'; ok = TreeSort(which, nNodes, order, nodeorder, nodecounts, tree); } free(nodecounts); free(nodeorder); for (i = 0; i < nNodes; i++) if (nodeID[i]) free(nodeID[i]); free(nodeID); free(tree); return ok; }
/// SimpleDPX::ParseHeader // Parse the file header of a DPX file void SimpleDPX::ParseHeader(FILE *file,struct ImgSpecs &specs) { ULONG hdr; char version[9]; ULONG encryption; UWORD orientation; UWORD depth,alpha; ULONG width,height; UWORD i; struct ComponentLayout *cl; m_bLittleEndian = false; hdr = GetLong(file); if (hdr == MakeID('S','D','P','X')) { // This is big-endian. m_bLittleEndian = false; } else if (hdr == MakeID('X','P','D','S')) { m_bLittleEndian = true; } else { PostError("input file %s is not a valid DPX file",m_pcFileName); } m_ulDataOffset = GetLong(file); version[8] = 0; GetString(file,version,8); if (strcmp(version,"V1.0") && strcmp(version,"V2.0")) PostError("unsupported DPX version detected, only V1.0 and V2.0 are supported"); SkipBytes(file,8); // file size and ditto key are not really needed. // // Read sizes of data structures. m_ulGenericSize = GetLong(file); m_ulIndustrySize = GetLong(file); m_ulUserSize = GetLong(file); // // Skip over the bytes we do not care about. SkipBytes(file,100+24+100+200+200); // // Read the encyrption key. encryption = GetLong(file); if (encryption != ULONG(~0UL)) fprintf(stderr,"Warning! - DPX file %s signals encryption, output may be wrong.\n",m_pcFileName); // // Skip over the rest of the header. not needed. SkipBytes(file,104); // // Read the image orientation orientation = GetWord(file); if (orientation >= 8) PostError("unknown orientation specified in DPX file %s, must be between 0 and 7",m_pcFileName); m_bFlipX = (orientation & 1)?true:false; m_bFlipY = (orientation & 2)?true:false; m_bFlipXY = (orientation & 4)?true:false; m_usElements = GetWord(file); if (m_usElements == 0 || m_usElements > 8) PostError("number of image elements must be between 1 and 8 in DPX file %s",m_pcFileName); width = GetLong(file); height = GetLong(file); if (m_bFlipXY) { m_ulHeight = width; m_ulWidth = height; } else { m_ulWidth = width; m_ulHeight = height; } specs.ASCII = ImgSpecs::No; specs.Interleaved = (m_usElements == 1)?(ImgSpecs::Yes):(ImgSpecs::No); specs.YUVEncoded = ImgSpecs::No; // changed possibly to Yes later on. specs.Palettized = ImgSpecs::No; specs.LittleEndian = (m_bLittleEndian)?(ImgSpecs::Yes):(ImgSpecs::No); // // Image elements. All eight are always present, though only the first m_usElements contain // valid data. for(i = 0;i < 8;i++) { if (i < m_usElements) { m_Elements[i].m_ulWidth = width; m_Elements[i].m_ulHeight = height; if (ParseElementHeader(file,m_Elements + i)) specs.YUVEncoded = ImgSpecs::Yes; } else { // Skip over elements we do not need SkipBytes(file,4*5 + 1*4 + 2*2 + 4*3 + 32); } } // // The rest is junk we do not need. // // Now compute the depth of the image. depth = 0; alpha = 0; for (i = 0;i < m_usElements;i++) { depth += m_Elements[i].m_ucDepth; alpha += m_Elements[i].m_ucAlphaDepth; } CreateComponents(m_ulWidth,m_ulHeight,depth + alpha); // // Now create the planes and allocate memory. cl = m_pComponent; for(i = 0;i < m_usElements;i++) { struct ImageElement *el = m_Elements + i; struct ScanElement *sl = el->m_pScanPattern; while(sl) { struct ComponentLayout *cll; UBYTE bytesperpixel = (el->m_ucBitDepth + 7) >> 3; UBYTE subx = el->m_ucSubX; UBYTE suby = el->m_ucSubY; UWORD k = sl->m_usTargetChannel; // // If flipXY is set, then X and Y change their role, so flip them now. if (m_bFlipXY) { subx = el->m_ucSubY; suby = el->m_ucSubX; } // // LUMA and alpha is always encoded without subsampling. if (k == 0 || k == 3) { subx = suby = 1; } // // Is this an alpha component or not? if (k == MAX_UWORD) { cll = cl + el->m_ucDepth; k = el->m_ucDepth; } else { cll = cl + k; } cll->m_ucBits = m_Elements[i].m_ucBitDepth; cll->m_bSigned = m_Elements[i].m_bSigned; cll->m_bFloat = m_Elements[i].m_bFloat; cll->m_ucSubX = subx; cll->m_ucSubY = suby; cll->m_ulWidth = (m_ulWidth + subx - 1) / subx; cll->m_ulHeight = (m_ulHeight + suby - 1) / suby; cll->m_ulBytesPerPixel = bytesperpixel; cll->m_ulBytesPerRow = cll->m_ulWidth * bytesperpixel; // Check whether we have already data for this channel. If not, allocate now. // As a channel may appear multiple times in one scan pattern, make sure to // allocate only once. if (el->m_pData[k] == NULL) { el->m_pData[k] = new UBYTE[cll->m_ulWidth * bytesperpixel * cll->m_ulHeight]; cll->m_pPtr = el->m_pData[k]; sl->m_bFirst = true; } sl->m_pData = cll->m_pPtr; sl->m_pComponent = cll; sl = sl->m_pNext; } // Adjust the components. cl += el->m_ucDepth + el->m_ucAlphaDepth; } }
SensorID SampleSensorFactory::GetNextSensorID() { VaneID sensorID = MakeID( Types::SampleSensor, m_sensorIDCount ); m_sensorIDCount++; return sensorID; }
cGameCell::cGameCell( cFile& file, int num ) : m_index( num ) { queue<string> tokQueue; SetID( MakeID( c_cellSegment, num ) ); MsgDaemon()->RegObject( GetID(), this ); string tok; do { file.TokenizeNextNCLine( &tokQueue, '#' ); tok = nextTok( tokQueue ); if( tok == "CELL_START" ) { // do nothing } else if( tok == "CELL_END" ) { break; } else if( tok == "PT" ) { point3 pt; // Read in the point tok = nextTok( tokQueue ); pt.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); pt.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); pt.z = atof( tok.c_str() ); // Append it to the list m_ptList.push_back( pt ); } else if( tok == "FACE" ) { tok = nextTok( tokQueue ); int nInd = atoi( tok.c_str() ); // Create the polygon structure to fill sPolygon currPoly; currPoly.m_nVerts = nInd; /** * The next line is the indices. */ file.TokenizeNextNCLine( &tokQueue, '#' ); // Fill in the indices for( int i=0; i< nInd; i++ ) { tok = nextTok( tokQueue ); currPoly.m_vList[i].m_ind = atoi( tok.c_str() ); } // Now we can build the plane. currPoly.m_plane = plane3( m_ptList[currPoly.m_vList[0].m_ind], m_ptList[currPoly.m_vList[1].m_ind], m_ptList[currPoly.m_vList[2].m_ind] ); /** * Next line is the colors */ file.TokenizeNextNCLine( &tokQueue, '#' ); // Fill in the colors for( i=0; i< nInd; i++ ) { tok = nextTok( tokQueue ); sscanf( tok.c_str(), "%x", &currPoly.m_vList[i].m_col ); } /** * Final line is the texture info. */ file.TokenizeNextNCLine( &tokQueue, '#' ); point3 m, n, p; // First token says whether to auto generate textures // Or explicitly read them. tok = nextTok( tokQueue ); if( tok == "AUTO" ) { // Automatically generate the texture vectors p = (m_ptList[currPoly.m_vList[0].m_ind]); tok = nextTok( tokQueue ); currPoly.m_texID = atoi( tok.c_str() ); tok = nextTok( tokQueue ); float mScale = atof( tok.c_str() ); tok = nextTok( tokQueue ); float nScale = atof( tok.c_str() ); // Run tests to figure out which way the plane faces if( point3::i == currPoly.m_plane.n || -1*point3::i == currPoly.m_plane.n ) { // plane points in the +/-x direction m.Assign(0,0,1); n.Assign(0,1,0); } else if( point3::j == currPoly.m_plane.n || -1*point3::j == currPoly.m_plane.n ) { // plane points in the +/-y direction m.Assign(0,0,1); n.Assign(1,0,0); } else if( point3::k == currPoly.m_plane.n || -1*point3::k == currPoly.m_plane.n ) { // plane points in the +/-z direction m.Assign(1,0,0); n.Assign(0,1,0); } // No easy guess... just estimate using the first two points as one vector // and the cross as the other. else { m = m_ptList[currPoly.m_vList[1].m_ind] - m_ptList[currPoly.m_vList[0].m_ind]; m.Normalize(); n = m ^ currPoly.m_plane.n; } // scale the vectors by the provided scaling values. m *= mScale; n *= nScale; } else if( tok == "EXP" ) { // Explicit tex-gen. texture ID and then 9 floats (p,m,n). tok = nextTok( tokQueue ); currPoly.m_texID = atoi( tok.c_str() ); // P tok = nextTok( tokQueue ); p.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); p.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); p.z = atof( tok.c_str() ); // M tok = nextTok( tokQueue ); m.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); m.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); m.z = atof( tok.c_str() ); // N tok = nextTok( tokQueue ); n.x = atof( tok.c_str() ); tok = nextTok( tokQueue ); n.y = atof( tok.c_str() ); tok = nextTok( tokQueue ); n.z = atof( tok.c_str() ); } else throw cGameError( "Bad texture gen token" ); float mMag = m.Mag(); m /= mMag; float nMag = n.Mag(); n /= nMag; // We have the n,m,p vectors; let's generate the coordinates. for( i=0; i<nInd; i++ ) { point3 pt = m_ptList[currPoly.m_vList[i].m_ind] - p; float u = (pt * m); float v = (pt * n); currPoly.m_vList[i].m_u = u / mMag; currPoly.m_vList[i].m_v = v / nMag; } // Add the poly m_polyList.push_back( currPoly ); } else if( 0 == tok.compare( "PORTAL" ) ) { tok = nextTok( tokQueue ); int other = atoi( tok.c_str() ); tok = nextTok( tokQueue ); int nInd = atoi( tok.c_str() ); // Create the polygon structure to fill sPortal currPortal; currPortal.m_nVerts = nInd; // first # in the file is 1, here is 0 currPortal.m_other = MakeID( c_cellSegment, other - 1); // Fill in the indices for( int i=0; i< nInd; i++ ) { tok = nextTok( tokQueue ); currPortal.m_vList[i].m_ind = atoi( tok.c_str() ); } currPortal.m_plane = plane3( m_ptList[currPortal.m_vList[0].m_ind], m_ptList[currPortal.m_vList[1].m_ind], m_ptList[currPortal.m_vList[2].m_ind] ); // build the edge planes for this portal currPortal.CalcEdgePlanes( this ); // Add the poly m_portalList.push_back( currPortal ); } } while( 1 ); }