void LoadTransform( Transformation *trans, TiXmlElement *element, int level ) { for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "scale" ) ) { Point3 s(1,1,1); ReadVector( child, s ); trans->Scale(s.x,s.y,s.z); PrintIndent(level); printf(" scale %f %f %f\n",s.x,s.y,s.z); } else if ( COMPARE( child->Value(), "rotate" ) ) { Point3 s(0,0,0); ReadVector( child, s ); s.Normalize(); float a; ReadFloat(child,a,"angle"); trans->Rotate(s,a); PrintIndent(level); printf(" rotate %f degrees around %f %f %f\n", a, s.x, s.y, s.z); } else if ( COMPARE( child->Value(), "translate" ) ) { Point3 t(0,0,0); ReadVector(child,t); trans->Translate(t); PrintIndent(level); printf(" translate %f %f %f\n",t.x,t.y,t.z); } } }
void NgramVector::Deserialize(FILE *inFile) { _length = ReadUInt64(inFile); ReadVector(inFile, _words); ReadVector(inFile, _hists); _Reindex(nextPowerOf2(_length + _length / 4)); // Build truncated view into words and hists. _wordsView.attach(_words); _histsView.attach(_hists); }
bool CMorphDictionary::Load(MorphLanguageEnum Language, const string& path) { m_Language = Language; if (!m_Flex2FlexiaModels.LoadVectorMap(path + FLEX2PARADIGMS_BIN_PATH)) return false; if (!m_Base2LemmaInfos.LoadVectorMap(path + BASE2PARADIGMS_BIN_PATH)) return false; if (!m_FlexModels.LoadVectorMap(path + PARADIGMS_BIN_PATH)) return false; if (!m_AccentModels.LoadVectorMap(path + ACCENT_MODELS_BIN_PATH)) return false; ReadVector(path + FLEXLEN_BIN_PATH, m_FlexLengthTable); if (m_FlexLengthTable.empty()) // there should be at least empty flexia in m_FlexLengthTable return false; m_Flexs.ReadShortStringHolder(path + FLEXS_BIN_PATH); m_Infos.ReadShortStringHolder(path + INFOS_BIN_PATH); m_Bases.ReadShortStringHolder(path + BASES_BIN_PATH); m_Predict.Load(path + PREDICT_BIN_PATH); LoadFrequentRoots(path); return true; }
static bool ReadSubindices(MZFile& file, std::vector<std::array<u16, 6>>& subindices) { V(ReadVector(file, subindices)); u32 size; V(file.Read(size)); V(file.Seek((64 + 2) * size)); return true; }
CVector CQuakePacket::ReadVector() { CVector vReturnMe; ReadVector(vReturnMe); return vReturnMe; }
void Int_SVQ(u32 op) { int imm = (signed short)(op&0xFFFC); int rs = _RS; int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5); u32 addr = R(rs) + imm; switch (op >> 26) { case 53: //lvl.q/lvr.q if (addr & 0x3) { _dbg_assert_msg_(CPU, 0, "Misaligned lvX.q"); } if ((op&2) == 0) { // It's an LVL float d[4]; ReadVector(d, V_Quad, vt); int offset = (addr >> 2) & 3; for (int i = 0; i < offset + 1; i++) { d[3 - i] = Memory::Read_Float(addr - i * 4); } WriteVector(d, V_Quad, vt); } else {
static bool ReadVertexData(MZFile& file, EluMesh& mesh, VertexData& data, const VertexAttributeOrder (&Order)[6]) { for (auto& Attribute : Order) { switch (Attribute) { case Pos: V(ReadVector(file, data.Positions)); break; case Nor: V(ReadVector(file, data.Normals)); break; case Tan: V(ReadVector(file, data.Tangents)); break; case Tex: V(ReadVector(file, data.TexCoords)); break; case Skip4: V(file.Seek(4)); break; case SkipVecV3: V(SkipVector<v3>(file)); break; } } return true; }
/* GetNode: read a node definition and create node */ static VQNode GetNode(Source *src, CovKind ck, short width) { char buf[MAXSTRLEN]; VQNode n; short vqidx,nid,lid,rid; Vector mean; Covariance cov; vqidx = GetVal(src,0,0,"VQ Index"); nid = GetVal(src,0,0,"Node Id"); lid = GetVal(src,0,0,"Left Id"); rid = GetVal(src,0,0,"Right Id"); mean = CreateVector(&vqHeap,width); if (!ReadVector(src, mean, FALSE)) HError(6150,"GetNode: cannot read mean vector at %s", SrcPosition(*src, buf)); switch(ck){ case NULLC: cov.var = NULL; n = CreateVQNode(vqidx,nid,lid,rid,mean,ck,cov); break; case INVDIAGC: cov.var = CreateVector(&vqHeap,width); if (!ReadVector(src, cov.var, FALSE)) HError(6150,"GetNode: cannot read variance vector at %s", SrcPosition(*src, buf)); n = CreateVQNode(vqidx,nid,lid,rid,mean,ck,cov); break; case FULLC: cov.inv = CreateTriMat(&vqHeap,width); if (!ReadTriMat(src, cov.inv, FALSE)) HError(6150,"GetNode: cannot read covariance matrix at %s", SrcPosition(*src, buf)); n = CreateVQNode(vqidx,nid,lid,rid,mean,ck,cov); break; default: n = CreateVQNode(vqidx,nid,lid,rid,mean,ck,cov); break; } return n; }
//---------------------------------------------------------------------- // Read parameters //---------------------------------------------------------------------- int CLoadCell::Read (SStream *stream, Tag tag) { int rc = TAG_IGNORED; switch (tag) { case 'name': // Name of loadout position ReadString (name, 64, stream); name[63] = 0; rc = TAG_READ; break; case 'bPos': // Offset from default center of gravity ReadVector (&bPos, stream); bPos = bPos + mveh->wgh.svh_cofg; bPos.InvertXY(); rc = TAG_READ; break; case 'load': // Default load value in pounds ReadFloat (&load, stream); rc = TAG_READ; break; case 'hiLm': // Maximum load value in pounds ReadFloat (&hiLm, stream); rc = TAG_READ; break; case 'utyp': // UI type ReadString (utyp, 64, stream); rc = TAG_READ; break; } if (rc != TAG_READ) { // Tag was not processed by this object, it is unrecognized WARNINGLOG ("CLoadCell::Read : Unrecognized tag <%s>", TagToString(tag)); } return rc; }
void TrainModel() { long long a, b; double len; InitHashTable(); ReadVector(); FILE *fo; fo = fopen(output_file, "wb"); fprintf(fo, "%lld %lld\n", num_vertices, vector_dim1 + vector_dim2); for (a = 0; a < num_vertices; a++) { fprintf(fo, "%s ", vertex[a].name); len = 0; for (b = 0; b < vector_dim1; b++) len += vec1[b + a * vector_dim1] * vec1[b + a * vector_dim1]; len = sqrt(len); for (b = 0; b < vector_dim1; b++) vec1[b + a * vector_dim1] /= len; len = 0; for (b = 0; b < vector_dim2; b++) len += vec2[b + a * vector_dim2] * vec2[b + a * vector_dim2]; len = sqrt(len); for (b = 0; b < vector_dim2; b++) vec2[b + a * vector_dim2] /= len; if (binary) { for (b = 0; b < vector_dim1; b++) fwrite(&vec1[a * vector_dim1 + b], sizeof(real), 1, fo); for (b = 0; b < vector_dim2; b++) fwrite(&vec2[a * vector_dim2 + b], sizeof(real), 1, fo); } else { for (b = 0; b < vector_dim1; b++) fprintf(fo, "%lf ", vec1[a * vector_dim1 + b]); for (b = 0; b < vector_dim2; b++) fprintf(fo, "%lf ", vec2[a * vector_dim2 + b]); } fprintf(fo, "\n"); } fclose(fo); }
static void ReadCamera(FILE *f, camera_params_t &camera) { ReadVector(f, 9, camera.R); ReadVector(f, 3, camera.t); fscanf(f, "%lf\n", &(camera.f)); }
void zreadhb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, doublecomplex **nzval, int_t **rowind, int_t **colptr) { register int_t i, numer_lines, rhscrd = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Enter zreadhb_dist()"); #endif /* Line 1 */ fgets(buf, 100, fp); /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } DumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if ( DEBUGlevel>=1 ) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); fscanf(fp, "%14c", buf); *ncol = atoi(buf); fscanf(fp, "%14c", buf); *nonz = atoi(buf); fscanf(fp, "%14c", buf); tmp = atoi(buf); if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); DumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ zallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); ParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); DumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) DumpLine(fp); /* skip RHSFMT */ #if ( DEBUGlevel>=1 ) if ( !iam ) { printf(IFMT " rows, " IFMT " nonzeros\n", *nrow, *nonz); printf("colnum " IFMT ", colsize " IFMT "\n", colnum, colsize); printf("rownum " IFMT ", rowsize " IFMT "\n", rownum, rowsize); printf("valnum " IFMT ", valsize " IFMT "\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read colptr[" IFMT "] = " IFMT "\n", *ncol, (*colptr)[*ncol]); #endif ReadVector(fp, *nonz, *rowind, rownum, rowsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read rowind[" IFMT "] = " IFMT "\n", *nonz-1, (*rowind)[*nonz-1]); #endif if ( numer_lines ) { zReadValues(fp, *nonz, *nzval, valnum, valsize); } fclose(fp); #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Exit zreadhb_dist()"); #endif }
void CFile::ReadMatrix (CFixMatrix& m) { ReadVector (m.RVec()); ReadVector (m.UVec()); ReadVector (m.FVec()); }
inline EBDB_ErrCode CBDB_BvSplitDictStore<Key, Dictionary, BvStore, BV>::ReadVectorAnd(const Key& key, TBitVector* bv) { return ReadVector(key, bv, eOp_And); }
bool CDwdsThesaurus::LoadDwdsThesaurus () { //fprintf (stderr,"0\n"); /////////////////////////////////////////// string fname = GetThesaurusPath() + string("dwds_thes_hyper.dat"); FILE* fp = fopen (fname.c_str(), "r"); if (!fp) { fprintf (stderr,"Cannot open file %s\n", fname.c_str()); return false; }; char buffer[10000]; while (fgets(buffer, 10000, fp)) { if (strlen(buffer) == 0) { fclose(fp); return false; } rtrim(buffer); if (strlen(buffer) == 0) { fclose(fp); return false; }; HyperTerms.push_back(buffer); }; fclose (fp); /////////////////////////////////////////// fname = GetThesaurusPath() + string("dwds_thes_pathes.bin"); if (access(fname.c_str(), 04) != 0) { fprintf (stderr,"Cannot open file %s\n", fname.c_str()); return false; }; //fprintf (stderr,"1\n"); ReadVector(fname, Pathes); //fprintf (stderr,"2\n"); /////////////////////////////////////////// fname = GetThesaurusPath() + string("dwds_thes_pathes.idx"); if (access(fname.c_str(), 04) != 0) { fprintf (stderr,"Cannot open file %s\n", fname.c_str()); return false; }; ReadVector(fname, PathEndIndex); /////////////////////////////////////////// fname = GetThesaurusPath() + string("dwds_thes_lemmas_pathes.dat"); if (access(fname.c_str(), 04) != 0) { fprintf (stderr,"Cannot open file %s\n", fname.c_str()); return false; }; ReadVector(fname, LeavesPathes); /////////////////////////////////////////// fname = GetThesaurusPath() + string("dwds_thes_lemmas_str.dat"); if (access(fname.c_str(), 04) != 0) { fprintf (stderr,"Cannot open file %s\n", fname.c_str()); return false; }; LeavesLemmas.ReadShortStringHolder(fname); if (LeavesLemmas.size() != LeavesPathes.size() ) { fprintf (stderr,"Bad index in thesaurus %s\n", fname.c_str()); return false; }; return true; };
void MULTIPLAY::ReadState(Uint8 * s, int slot) { //read a state //allocate function sync memory loadstates[slot].fnum = fnums[slot]; //set the number of funcs if (loadstates[slot].funcmem != NULL) //clear old func data { delete [] loadstates[slot].funcmem; loadstates[slot].funcmem = NULL; } //now, read the state int len = 0; Uint8 tempchar; len = GetFromData(s, &tempchar, sizeof(Uint8), len); if (tempchar != replay.Get_FuncStateInfo()) { if (NET_DEBUG) cout << "net: ReadState: packet is not a state" << endl; return; } len = GetFromData(s, &loadstates[slot].time, sizeof(double), len); //tplen = AddToData(tp, &GetCurState(0)->time, sizeof(double), tplen); //fwrite(&time, sizeof(double), 1, fout); len = ReadVector(loadstates[slot].chassispos, s, len); len = ReadMatrix(loadstates[slot].chassisorientation, s, len); len = ReadVector(loadstates[slot].chassisvel, s, len); len = ReadVector(loadstates[slot].chassisangvel, s, len); int i; for (i = 0; i < 4; i++) { len = GetFromData(s, &loadstates[slot].suspdisp[i], sizeof(double), len); len = GetFromData(s, &loadstates[slot].suspcompvel[i], sizeof(double), len); len = ReadVector(loadstates[slot].whlangvel[i], s, len); len = GetFromData(s, &loadstates[slot].tirespeed[i], sizeof(double), len); } len = GetFromData(s, &loadstates[slot].gear, sizeof(int), len); len = GetFromData(s, &loadstates[slot].enginespeed, sizeof(double), len); len = GetFromData(s, &loadstates[slot].clutchspeed, sizeof(double), len); len = GetFromData(s, &loadstates[slot].enginedrag, sizeof(double), len); len = GetFromData(s, &loadstates[slot].segment, sizeof(int), len); //read the function state block len = GetFromData(s, &(fnums[slot]), sizeof(int), len); loadstates[slot].funcmem = new FUNCTION_MEMORY_SYNC [fnums[slot]]; //allocate func data //len = AddToData(tp, &(fnums[0]), sizeof(int), tplen); if (MP_DEBUG) cout << "net: ReadState: " << fnums[slot] << " functions, active: "; for (i = 0; i < fnums[slot]; i++) { //fwrite(&(funcmem[i]), sizeof(struct FUNCTION_MEMORY_SYNC), 1, fout); //tplen = AddToData(tp, &(GetFuncMem(0)[i]), sizeof(struct FUNCTION_MEMORY_SYNC), tplen); len = GetFromData(s, &loadstates[slot].funcmem[i], sizeof(struct FUNCTION_MEMORY_SYNC), len); if (MP_DEBUG && loadstates[slot].funcmem[i].active) cout << GetFuncMem(slot)[i].func_name << "(" << i << ") "; } if (MP_DEBUG) cout << endl; }
void dreadhb(int *nrow, int *ncol, int *nonz, double **nzval, int **rowind, int **colptr) { register int i, numer_lines = 0, rhscrd = 0; int tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4], key[10]; FILE *fp; fp = stdin; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); #if 0 fscanf(fp, "%72c", buf); buf[72] = 0; printf("Title: %s", buf); fscanf(fp, "%8c", key); key[8] = 0; printf("Key: %s\n", key); dDumpLine(fp); #endif /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; sscanf(buf, "%d", &tmp); if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #ifdef DEBUG printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); sscanf(buf, "%d", nrow); fscanf(fp, "%14c", buf); sscanf(buf, "%d", ncol); fscanf(fp, "%14c", buf); sscanf(buf, "%d", nonz); fscanf(fp, "%14c", buf); sscanf(buf, "%d", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); dDumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) dDumpLine(fp); /* skip RHSFMT */ #ifdef DEBUG printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } fclose(fp); }
void JKG_LoadWeaponAssets ( weaponInfo_t *weaponInfo, const weaponData_t *weaponData ) { int i; char extensionlessModel[MAX_QPATH]; const weaponVisual_t *weaponVisuals = &weaponData->visuals; weaponInfo->indicatorType = weaponVisuals->indicatorType; for ( i = 0; i < 3; i++ ) { if ( weaponVisuals->groupedIndicatorShaders[i][0] ) { weaponInfo->groupedIndicators[i] = trap->R_RegisterShader (weaponVisuals->groupedIndicatorShaders[i]); } } if ( weaponVisuals->firemodeIndicatorShader[0] ) { weaponInfo->fireModeIndicator = trap->R_RegisterShader (weaponVisuals->firemodeIndicatorShader); } VectorClear (weaponInfo->gunPosition); if ( weaponVisuals->gunPosition[0] ) { ReadVector (weaponVisuals->gunPosition, weaponInfo->gunPosition); } VectorClear (weaponInfo->ironsightsPosition); if ( weaponVisuals->ironsightsPosition[0] ) { ReadVector (weaponVisuals->ironsightsPosition, weaponInfo->ironsightsPosition); } else { VectorCopy (weaponInfo->gunPosition, weaponInfo->ironsightsPosition); } weaponInfo->ironsightsFov = weaponVisuals->ironsightsFov; if ( CG_IsGhoul2Model (weaponVisuals->world_model) ) { trap->G2API_InitGhoul2Model (&weaponInfo->g2WorldModel, weaponVisuals->world_model, 0, 0, 0, 0, 0); if ( !trap->G2_HaveWeGhoul2Models (weaponInfo->g2WorldModel) ) { weaponInfo->g2WorldModel = NULL; } } memset (weaponInfo->barrelModels, NULL_HANDLE, sizeof (weaponInfo->barrelModels)); COM_StripExtension (weaponVisuals->view_model, extensionlessModel, sizeof(extensionlessModel)); for ( i = 0; i < weaponVisuals->barrelCount; i++ ) { const char *barrelModel; int len; qhandle_t barrel; if( i == 0 ) barrelModel = va("%s_barrel.md3", extensionlessModel); else barrelModel = va("%s_barrel%i.md3", extensionlessModel, i+1); len = strlen( barrelModel ); if ( (len + 1) > MAX_QPATH ) { trap->Print (S_COLOR_YELLOW "Warning: barrel model path %s is too long (%d chars). Max length is 63.\n", barrelModel, len); break; } barrel = trap->R_RegisterModel (barrelModel); if ( barrel == NULL_HANDLE ) { break; } weaponInfo->barrelModels[i] = barrel; } // Scope render if ( weaponVisuals->scopeShader[0] ) weaponInfo->scopeShader = trap->R_RegisterShader (weaponVisuals->scopeShader); // Scope toggle if ( weaponVisuals->scopeStartSound[0] ) weaponInfo->scopeStartSound = trap->S_RegisterSound (weaponVisuals->scopeStartSound); if ( weaponVisuals->scopeStopSound[0] ) weaponInfo->scopeStopSound = trap->S_RegisterSound (weaponVisuals->scopeStopSound); // Scope zoom if ( weaponVisuals->scopeLoopSound[0] ) weaponInfo->scopeLoopSound = trap->S_RegisterSound (weaponVisuals->scopeLoopSound); weaponInfo->scopeSoundLoopTime = weaponVisuals->scopeSoundLoopTime; //JKG_LoadFireModeAssets (&weaponInfo->primDrawData, &weaponData->firemodes[0], &weaponVisuals->primary); //JKG_LoadFireModeAssets (&weaponInfo->altDrawData, &weaponData->firemodes[1], &weaponVisuals->secondary); for( i = 0; i < weaponData->numFiringModes; i++ ) { JKG_LoadFireModeAssets ( &weaponInfo->drawData[i], &weaponData->firemodes[i], &weaponVisuals->visualFireModes[i] ); } }
void dreadhb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, double **nzval, int_t **rowind, int_t **colptr) { /* * -- Distributed SuperLU routine (version 1.0) -- * Lawrence Berkeley National Lab, Univ. of California Berkeley. * September 1, 1999 * * * Purpose * ======= * * Read a DOUBLE PRECISION matrix stored in Harwell-Boeing format * as described below. * * Line 1 (A72,A8) * Col. 1 - 72 Title (TITLE) * Col. 73 - 80 Key (KEY) * * Line 2 (5I14) * Col. 1 - 14 Total number of lines excluding header (TOTCRD) * Col. 15 - 28 Number of lines for pointers (PTRCRD) * Col. 29 - 42 Number of lines for row (or variable) indices (INDCRD) * Col. 43 - 56 Number of lines for numerical values (VALCRD) * Col. 57 - 70 Number of lines for right-hand sides (RHSCRD) * (including starting guesses and solution vectors * if present) * (zero indicates no right-hand side data is present) * * Line 3 (A3, 11X, 4I14) * Col. 1 - 3 Matrix type (see below) (MXTYPE) * Col. 15 - 28 Number of rows (or variables) (NROW) * Col. 29 - 42 Number of columns (or elements) (NCOL) * Col. 43 - 56 Number of row (or variable) indices (NNZERO) * (equal to number of entries for assembled matrices) * Col. 57 - 70 Number of elemental matrix entries (NELTVL) * (zero in the case of assembled matrices) * Line 4 (2A16, 2A20) * Col. 1 - 16 Format for pointers (PTRFMT) * Col. 17 - 32 Format for row (or variable) indices (INDFMT) * Col. 33 - 52 Format for numerical values of coefficient matrix (VALFMT) * Col. 53 - 72 Format for numerical values of right-hand sides (RHSFMT) * * Line 5 (A3, 11X, 2I14) Only present if there are right-hand sides present * Col. 1 Right-hand side type: * F for full storage or M for same format as matrix * Col. 2 G if a starting vector(s) (Guess) is supplied. (RHSTYP) * Col. 3 X if an exact solution vector(s) is supplied. * Col. 15 - 28 Number of right-hand sides (NRHS) * Col. 29 - 42 Number of row indices (NRHSIX) * (ignored in case of unassembled matrices) * * The three character type field on line 3 describes the matrix type. * The following table lists the permitted values for each of the three * characters. As an example of the type field, RSA denotes that the matrix * is real, symmetric, and assembled. * * First Character: * R Real matrix * C Complex matrix * P Pattern only (no numerical values supplied) * * Second Character: * S Symmetric * U Unsymmetric * H Hermitian * Z Skew symmetric * R Rectangular * * Third Character: * A Assembled * E Elemental matrices (unassembled) * */ register int_t i, numer_lines, rhscrd = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int_t sym; #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Enter dreadhb_dist()"); #endif /* Line 1 */ fgets(buf, 100, fp); /*dDumpLine(fp);*/ /*if ( !iam ) fflush(stdout);*/ /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if ( DEBUGlevel>=1 ) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); /*sscanf(buf, "%d", nrow);*/ fscanf(fp, "%14c", buf); *ncol = atoi(buf); /*sscanf(buf, "%d", ncol);*/ fscanf(fp, "%14c", buf); *nonz = atoi(buf); /*sscanf(buf, "%d", nonz);*/ fscanf(fp, "%14c", buf); tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); dDumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) dDumpLine(fp); /* skip RHSFMT */ #if ( DEBUGlevel>=1 ) if ( !iam ) { printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read colptr[%d] = %d\n", *ncol, (*colptr)[*ncol]); #endif ReadVector(fp, *nonz, *rowind, rownum, rowsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read rowind[%d] = %d\n", *nonz-1, (*rowind)[*nonz-1]); #endif if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read nzval[%d] = %e\n", *nonz-1, (*nzval)[*nonz-1]); #endif } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } /*if ( !iam ) fflush(stdout);*/ fclose(fp); #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Exit dreadhb_dist()"); #endif }
void dreadrb(int *nrow, int *ncol, int *nonz, double **nzval, int **rowind, int **colptr) { register int i, numer_lines = 0; int tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int sym; FILE *fp; fp = stdin; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); /* Line 2 */ for (i=0; i<4; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; sscanf(buf, "%d", &tmp); if (i == 3) numer_lines = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #ifdef DEBUG printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); sscanf(buf, "%d", nrow); fscanf(fp, "%14c", buf); sscanf(buf, "%d", ncol); fscanf(fp, "%14c", buf); sscanf(buf, "%d", nonz); fscanf(fp, "%14c", buf); sscanf(buf, "%d", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); dDumpLine(fp); #ifdef DEBUG printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } fclose(fp); }
void dreadrb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, double **nzval, int_t **rowind, int_t **colptr) { register int_t i, numer_lines = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int sym; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); /* Line 2 */ for (i=0; i<4; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; } DumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if (DEBUGlevel >= 1) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); fscanf(fp, "%14c", buf); *ncol = atoi(buf); fscanf(fp, "%14c", buf); *nonz = atoi(buf); fscanf(fp, "%14c", buf); tmp = atoi(buf); if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); DumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); ParseFloatFormat(buf, &valnum, &valsize); DumpLine(fp); #if (DEBUGlevel >= 1) if ( !iam ) { printf(IFMT " rows, " IFMT " nonzeros\n", *nrow, *nonz); printf("colnum " IFMT ", colsize " IFMT "\n", colnum, colsize); printf("rownum " IFMT ", rowsize " IFMT "\n", rownum, rowsize); printf("valnum " IFMT ", valsize " IFMT "\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } fclose(fp); }
SMatrix ReadSparse(char *name, char *probName) { FILE *fp; long n, m, i, j; long n_rows, tmp; long numer_lines; long colnum, colsize, rownum, rowsize; char buf[100], type[4]; SMatrix M, F; if (!name || name[0] == 0) { fp = stdin; } else { fp = fopen(name, "r"); } if (!fp) { Error("Error opening file\n"); } fscanf(fp, "%72c", buf); fscanf(fp, "%8c", probName); probName[8] = 0; DumpLine(fp); for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &tmp); if (i == 3) numer_lines = tmp; } DumpLine(fp); fscanf(fp, "%3c", type); type[3] = 0; if (!(type[0] != 'C' && type[1] == 'S' && type[2] == 'A')) { fprintf(stderr, "Wrong type: %s\n", type); exit(0); } fscanf(fp, "%11c", buf); /* pad */ fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n_rows); fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n); fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &m); fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (n_rows != n) printf("Matrix is not symmetric\n"); DumpLine(fp); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); fscanf(fp, "%20c", buf); DumpLine(fp); /* format statement */ M = NewMatrix(n, m, 0); ReadVector(fp, n+1, M.col, colnum, colsize); ReadVector(fp, m, M.row, rownum, rowsize); for (i=0; i<numer_lines; i++) /* dump numeric values */ DumpLine(fp); for (i=0; i<n; i++) ISort(M, i); for (i=0; i<=n; i++) M.startrow[i] = M.col[i]; fclose(fp); F = LowerToFull(M); maxm = 0; for (i=0; i<n; i++) if (F.col[i+1]-F.col[i] > maxm) maxm = F.col[i+1]-F.col[i]; if (F.nz) { for (j=0; j<n; j++) for (i=F.col[j]; i<F.col[j+1]; i++) F.nz[i] = Value(F.row[i], j); } FreeMatrix(M); return(F); }
void CStatistic::Load(const string& path) { ReadVector(path + HOMOWEIGHT_BIN_PATH, m_HomoWeights); ReadVector(path + WORDWEIGHT_BIN_PATH, m_WordWeights); }
int main(int argc, char *argv[]) { if (argc < 3) { printf("Invalid input parameters\n"); return 1; } int N = atoi(argv[1]); int NZ = atoi(argv[2]); char *mtxFileName = NULL; char *vecFileName = NULL; if (argc > 3 && argc < 6) { mtxFileName = argv[3]; vecFileName = argv[4]; } if ((NZ > N) || (N <= 0) || (NZ <= 0)) { printf("Incorrect arguments of main\n"); return 1; } crsMatrix A; double *x, *b, *bm; double timeM=0, timeM1=0, diff=0; if (ReadMatrix(A, mtxFileName) != 0) { GenerateRegularCRS(1, N, NZ, A); WriteMatrix(A, "mtx.txt"); } if (ReadVector(&x, N, vecFileName) != 0) { GenerateVector(2, N, &x); WriteVector(x, N, "vec.txt"); } InitializeVector(N, &b); Multiplicate(A, x, b, timeM); InitializeVector(N, &bm); SparseMKLMult(A, x, bm, timeM1); CompareVectors(b, bm, N, diff); if (diff < EPSILON) printf("OK\n"); else printf("not OK\n"); printf("%d %d\n", A.N, A.NZ); printf("%.3f %.3f\n", timeM, timeM1); FreeMatrix(A); FreeVector(&b); FreeVector(&bm); FreeVector(&x); return 0; }
void TwoFrameModel::Read(FILE *f) { fscanf(f, "%d\n", &m_num_points); fscanf(f, "%lf\n", &m_angle); fscanf(f, "%lf\n", &m_error); v3_t *points_tmp = new v3_t[m_num_points]; double *tracks_tmp = new double[m_num_points]; int *k1_tmp = new int[m_num_points]; int *k2_tmp = new int[m_num_points]; m_points = new v3_t[m_num_points]; m_tracks = new int[m_num_points]; for (int i = 0; i < m_num_points; i++) { int tr, k1, k2; fscanf(f, "%d %d %d %lf %lf %lf\n", &tr, &k1, &k2, &(Vx(points_tmp[i])), &(Vy(points_tmp[i])), &(Vz(points_tmp[i]))); tracks_tmp[i] = (double) tr; k1_tmp[i] = k1; k2_tmp[i] = k2; } bool use_tracks = true; if (tracks_tmp[0] < 0) use_tracks = false; if (use_tracks) { int *perm = new int[m_num_points]; qsort_ascending(); qsort_perm(m_num_points, tracks_tmp, perm); for (int i = 0; i < m_num_points; i++) { m_tracks[i] = iround(tracks_tmp[i]); m_points[i] = points_tmp[perm[i]]; } m_keys1 = m_keys2 = NULL; delete [] perm; } else { m_keys1 = new int[m_num_points]; m_keys2 = new int[m_num_points]; for (int i = 0; i < m_num_points; i++) { m_keys1[i] = k1_tmp[i]; m_keys2[i] = k2_tmp[i]; m_points[i] = points_tmp[i]; } m_tracks = NULL; } delete [] points_tmp; delete [] tracks_tmp; delete [] k1_tmp; delete [] k2_tmp; ReadCamera(f, m_camera0); ReadCamera(f, m_camera1); ReadVector(f, 9, m_C0); ReadVector(f, 9, m_C1); }
void LoadLight(TiXmlElement *element) { Light *light = NULL; // name const char* name = element->Attribute("name"); printf("Light ["); if ( name ) printf("%s",name); printf("]"); // type const char* type = element->Attribute("type"); if ( type ) { if ( COMPARE(type,"ambient") ) { printf(" - Ambient\n"); AmbientLight *l = new AmbientLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } } } else if ( COMPARE(type,"direct") ) { printf(" - Direct\n"); DirectLight *l = new DirectLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "direction" ) ) { Point3 v(1,1,1); ReadVector( child, v ); l->SetDirection(v); printf(" direction %f %f %f\n",v.x,v.y,v.z); } } } else if ( COMPARE(type,"point") ) { printf(" - Point\n"); PointLight *l = new PointLight(); light = l; for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) { if ( COMPARE( child->Value(), "intensity" ) ) { Color c(1,1,1); ReadColor( child, c ); l->SetIntensity(c); printf(" intensity %f %f %f\n",c.r,c.g,c.b); } else if ( COMPARE( child->Value(), "position" ) ) { Point3 v(0,0,0); ReadVector( child, v ); l->SetPosition(v); printf(" position %f %f %f\n",v.x,v.y,v.z); } } } else { printf(" - UNKNOWN\n"); } } if ( light ) { light->SetName(name); lights.push_back(light); } }
bool mcBrush::Read(mcMapParser* parser) { csString buffer; csString texture_name; if (!parser->GetTextToken(buffer)) { return false; } for(;;) { if(buffer == "}") { break; } if (buffer != "(") { parser->ReportError("Format error. Expected either \"(\" or \"}\"" ", Found\"%s\"", buffer.GetData()); return false; } //if this brush is not finished, then another plane must follow. csDVector3 v1, v2, v3; double x_off = 0; double y_off = 0; double rot_angle = 0; double x_scale = 1.0; double y_scale = 1.0; /* Read the three vectors, that define the position of the plane */ if (!ReadVector(parser, v1)) { return false; } if(!parser->GetTextToken(buffer) || buffer != ")") { return false; } if (!parser->GetTextToken(buffer) || buffer != "(") { return false; } if (!ReadVector(parser, v2)) { return false; } if(!parser->GetTextToken(buffer) || buffer != ")") { return false; } if (!parser->GetTextToken(buffer) || buffer != "(") { return false; } if (!ReadVector(parser, v3)) { return false; } if(!parser->GetTextToken(buffer) || buffer != ")") { return false; } //Get the name of the Texture if (!parser->GetTextToken(buffer)) return false; texture_name.Replace (buffer); if (!parser->GetFloatToken(x_off)) return false; if (!parser->GetFloatToken(y_off)) return false; if (!parser->GetFloatToken(rot_angle)) return false; if (!parser->GetFloatToken(x_scale)) return false; if (!parser->GetFloatToken(y_scale)) return false; if (!parser->GetTextToken(buffer)) return false; if ((buffer != "(") && (buffer != "}")) { // Looks like a Quake3 Arena Map. I don't know the meaning of these // numbers, but there are always three of them for (int i=0; i<3; i++) { bool malformed = false; bool intseen = false; const char *q = buffer.GetData(); while (*q != '\0' && isspace(*q)) { q++; } while (*q != '\0' && isdigit(*q)) { q++; intseen = true; } malformed = (*q != '\0' && !isspace(*q)); if (malformed || !intseen) { parser->ReportError("Invalid Numeric format. " "Expected int, found \"%s\"", buffer.GetData()); return false; } if (!parser->GetTextToken(buffer)) { return false; } } } m_planes.Push(mcMapTexturedPlane(v1, v2, v3, texture_name, x_off, y_off, rot_angle, x_scale, y_scale)); } return true; }
int LoadScene(const char *filename) { cout<<"Load......."; TiXmlDocument doc(filename); if ( ! doc.LoadFile() ) { printf("Failed to load the file \"%s\"\n", filename); return 0; } TiXmlElement *xml = doc.FirstChildElement("xml"); if ( ! xml ) { printf("No \"xml\" tag found.\n"); return 0; } TiXmlElement *scene = xml->FirstChildElement("scene"); if ( ! scene ) { printf("No \"scene\" tag found.\n"); return 0; } TiXmlElement *cam = xml->FirstChildElement("camera"); if ( ! cam ) { printf("No \"camera\" tag found.\n"); return 0; } nodeMtlList.clear(); rootNode.Init(); materials.DeleteAll(); lights.DeleteAll(); LoadScene( scene ); // Assign materials int numNodes = nodeMtlList.size(); for ( int i=0; i<numNodes; i++ ) { Material *mtl = materials.Find( nodeMtlList[i].mtlName ); if ( mtl ) nodeMtlList[i].node->SetMaterial(mtl); } nodeMtlList.clear(); // Load Camera camera.Init(); camera.dir += camera.pos; TiXmlElement *camChild = cam->FirstChildElement(); while ( camChild ) { if ( COMPARE( camChild->Value(), "position" ) ) ReadVector(camChild,camera.pos); else if ( COMPARE( camChild->Value(), "target" ) ) ReadVector(camChild,camera.dir); else if ( COMPARE( camChild->Value(), "up" ) ) ReadVector(camChild,camera.up); else if ( COMPARE( camChild->Value(), "fov" ) ) ReadFloat (camChild,camera.fov); else if ( COMPARE( camChild->Value(), "width" ) ) camChild->QueryIntAttribute("value", &camera.imgWidth); else if ( COMPARE( camChild->Value(), "height" ) ) camChild->QueryIntAttribute("value", &camera.imgHeight); camChild = camChild->NextSiblingElement(); } camera.dir -= camera.pos; camera.dir.Normalize(); Point3 x = camera.dir ^ camera.up; camera.up = (x ^ camera.dir).GetNormalized(); renderImage.Init( camera.imgWidth, camera.imgHeight ); return 1; }