Esempio n. 1
0
//***************************************************************************
static void ReadMaterial(header_t *chunkmat,material_t *material)
{
	header_t	*chunk=chunkmat+1;
	uint		size=chunkmat->len,pos=0;

	while(pos<size)
	{

	  switch(chunk->id)
	  {
	    case C_MATNAME: strcpy(material->name,(char*)(chunk+1)); break;
	    case C_AMBIENT: ReadRGB(chunk,&material->ambient); break;
	    case C_SPECULAR: ReadRGB(chunk,&material->specular); break;
	    case C_DIFFUSE: ReadRGB(chunk,&material->diffuse); break;
	    case C_TWOSIDED: material->twosided=1; break;
	    case C_WIRED: material->wired=1; break;
	    case C_TEXTMAP: ReadMap(chunk,&material->textmappath); break;
	    case C_REFLMAP: ReadMap(chunk,&material->reflmappath); break;
	    case C_BUMPMAP: ReadMap(chunk,&material->bumpmappath); break;
	    case C_TRANSMAP: ReadMap(chunk,&material->transpmappath); break;
	  }

	  pos+=chunk->len;
	  chunk=(header_t*)((uint)chunk+chunk->len);
	}

}
Esempio n. 2
0
static void ProcessCommandLine(int argc, char *argv[])
{
	int i;
	
	if(argc == 1)
	{
		PrintUsage();
		exit(EXIT_SUCCESS);
	}

	for(i = 1; i < argc && argv[i][0] == '-'; i++)
	{
		if(!strcmp(argv[i], "-o"))
		{
			i++;
			outputfilename = argv[i];
		}
		else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose"))
		{
			verbose = true;
		}
		else
			Error("Unknown option \"%s\"\n", argv[i]);
	}

	// eventually this could loop through all source files
	// the higher level construct would be of a "bsp model"
	// allowing multiple bsp models to be packed into a single file?
	ReadMap(argv[i]);

	ProcessModel();
}
Esempio n. 3
0
bool 
Game::Initialise()
{



	

	const int width = tileSize * 21;
	const int height = tileSize * 16;

	m_pBackBuffer = new BackBuffer();
	if (!m_pBackBuffer->Initialise(width, height))
	{
		LogManager::GetInstance().Log("BackBuffer Init Fail!");
		return (false);
	}

	m_pInputHandler = new InputHandler();
	if (!m_pInputHandler->Initialise())
	{
		LogManager::GetInstance().Log("InputHandler Init Fail!");
		return (false);
	}

	
	//Create background
	Sprite* backG = m_pBackBuffer->CreateSprite("assets\\background.png");

	bg = new Background();
	bg->Initialise(backG);
	bg->SetPositionX(0.0f);
	bg->SetPositionY(0.0f);


	
	// Load the player sprite
	right = m_pBackBuffer->CreateSprite("assets\\Player.png");
	left = m_pBackBuffer->CreateSprite("assets\\PlayerRight.png");

	//Create the player sprite and set the position
	m_pPlayer = new Player();
	m_pPlayer->Initialise(right);
	m_pPlayer->SetPositionX(tileSize);
	m_pPlayer->SetPositionY(tileSize * 14);
	m_pPlayer->SetVerticalVelocity(2.0f);

	//create map from file
	ReadMap();
	
	

	


	m_lastTime = SDL_GetTicks();
	m_lag = 0.0f;

	return (true);
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int mergeMarker = 7;
    if(argc == 5)
    {
        mergeMarker = atoi(argv[4]);
        argc--;
    }

    if(argc != 4 || !mergeMarker)
    {
        printf("Improper invocation.\n");
        Usage();
        return 1;
    }

    Map *ancestor, *current, *merge, *output;

    printf("Reading ancestor map...\n");
    ancestor = ReadMap(argv[1]);
    if(!ancestor)
      return 1;

    printf("Reading current map...\n");
    current = ReadMap(argv[2]);
    if(!current)
      return 1;

    printf("Reading merging map...\n");
    merge = ReadMap(argv[3]);
    if(!merge)
      return 1;

    printf("Merging maps...\n");
    output = MergeMaps(ancestor, current, merge);
    if(!output)
    {
        printf("Error during merge; aborting.\n");
        return 1;
    }

    printf("Writing merged map...\n");
    if(WriteMap(output, argv[2]))
      return 0;
    else
      return 1;
}
Esempio n. 5
0
void ProcessSystemObjects()
{
	int i;

	MODULEMAPBLOCK* mmbptr= &AvpCompiledMaps[0];
	STRATEGYBLOCK* sbptr;

	/* PC Loading.
		 1 LoadRif File 
		 			a sets up precompiled shapes
					b	sets up other loaded shapes
					c sets maps ans SBs for loaded maps
					
		 2 
	*/	


	#if TestRiffLoaders
	ReadMap(Map);							 /* for chunck loader*/
	ReadModuleMapList(mmbptr);
	#else
	#if SupportModules
	ReadModuleMapList(mmbptr);
	#endif /*SupportModules*/
	ReadMap(Map);	
	#endif

	/*HACK HACK*/

	sbptr = AttachNewStratBlock((MODULE*)NULL,
															(MODULEMAPBLOCK*)&Player_and_Camera_Type8[0],
															Player);
	AssignRunTimeBehaviours(sbptr);

	#if SupportModules

	Global_ModulePtr = MainSceneArray;
	PreprocessAllModules();
	i = GetModuleVisArrays();
	if(i == No) textprint("GetModuleVisArrays() failed\n");


	/*WaitForReturn();*/

	#endif
}
Esempio n. 6
0
enum ActionMenu StageMain(int *stageState, char *mapName)
{
    static int bgm = - 1;
    static char name[MAX_PATH];
    
    switch (*stageState) {
    case 0:
        map = ReadMap(mapName);
#if !MAP_EDIT_MODE
        GetBgmName(name, mapName);
        bgm = LoadSound(name);
#endif        
        *stageState = 1;
        break;

    case 1:
        {
            InitMap(map);
            CreateObject(map);
            DrawMain = StageDraw;
            LoopSound(bgm);
            *stageState = 2;
        }
        break;

    case 2:
            MoveMap(map);
            MoveEnemy(map);
            MoveItem(map);
            MoveBomb(map);
            MoveEnemy(map);
            MovePlayer(map);
            if (IsPlayerDie()) {
                SoundPlay(res.sound_die);
                life--;
                if (life < 0) {
                    FreeStage(map, stageState, bgm);
                    return MENU_GAMEOVER;
                }
                *stageState = 1;
            }
            if (IsPlayerClear()) {
                FreeStage(map, stageState, bgm);
                return MENU_CLEAR;
            }
            break;
    }
    return MENU_STAGE;
}
Esempio n. 7
0
void initRendering(char** argv)
{
	glClearColor(0.678431, 0.847059, 0.901961, 1.0);
	glShadeModel(GL_SMOOTH);

	glEnable(GL_DEPTH_TEST);
	ReadMap("hole.01.db");
	
	ImportObj temp;
	ImportObj Tee = getTeeBuffer();
	load_obj("BallSmall.obj", temp.Vertices, temp.Indices, glm::vec3(0, 0.08, 0));
	temp.CalculateNormals();
	GolfBall = Ball(temp, Tee.Coordinate, getTiles()[getTeeBuffer().TileID - 1]);
	//The starting tile is the tile of the Tee

	setShaders();
}
Esempio n. 8
0
void IntegrateNewEnvironment()
{
	int i;
	MODULEMAPBLOCK* mmbptr= &AvpCompiledMaps[0];

	// elements we need form processsystemobjects

	ReadMap(Map);							 /* for chunck loader*/
	ReadModuleMapList(mmbptr);

	Global_ModulePtr = MainSceneArray;
	PreprocessAllModules();
	i = GetModuleVisArrays();
	if(i == No) textprint("GetModuleVisArrays() failed\n");

 
	// elements from start game for AI

	InitObjectVisibilities();
	InitPheromoneSystem();
	BuildFarModuleLocs();
	InitHive();

	AssignAllSBNames();

	/* KJL 20:54:55 05/15/97 - setup player vision (alien wideangle, etc) */
	SetupVision();

	UnloadRifFile();//deletes environment File_Chunk since it is no longer needed

	/* Patrick: 26/6/97
	Load our sounds for the new env */	
	LoadSounds("PLAYER");

	/* remove resident loaded 'fast' files */
	ffcloseall();

	ResetFrameCounter();
}
Esempio n. 9
0
Mesh* Load3ds(string URL, Entity* parent_ent){
  int Size;
  //Local OldDir:String
  unsigned char Red, Green, Blue;
  //unsigned char Percent;
  //Local Pixmap:TPixmap
  Stream = File::ReadResourceFile(URL);
  if (Stream == 0) return 0;

  //Size = Stream.Size()
  fseek(Stream->pFile, 0, SEEK_END); // seek to end of file
  Size = ftell(Stream->pFile); // get current file pointer
  fseek(Stream->pFile, 0, SEEK_SET);

  // Read Main-Chunk
  ReadChunk();
  if (ChunkID != M3D_3DS_MAIN || ChunkSize != Size) {
    Stream->CloseFile();
    //Print "No 3DS File"
    return 0;
  }
  // Find 3DEditor-Chunk
  while (Stream->Eof()==0){
    ReadChunk();
    if (ChunkID == M3D_3DS_3DEDITOR){
      break;
    }else{
      SkipChunk();
    }
  }

  //OldDir = CurrentDir()
  //If String(URL) <> "" Then ChangeDir(ExtractDir(String(URL)))
  mesh = Mesh::CreateMesh();
  while (Stream->Eof()==0){
    ReadChunk();
    switch (ChunkID){
    case M3D_3DS_OBJECTBLOCK:
      ReadCString(); // ' ObjectName
      break;
    case M3D_3DS_BrushBLOCK:
      ReadBrushBlock();
      break;
    case M3D_3DS_TRIMESH:
      ReadTriMesh();
      break;
    case M3D_3DS_VERTEXLIST:
      ReadVertexList();
      break;
    case M3D_3DS_FACELIST:
      ReadFaceList();
      break;
    case M3D_3DS_FACEMATLIST:
      ReadFaceMatList();
      break;
    case M3D_3DS_TEXCOORDS:
      ReadTexCoords();
      break;
    case M3D_3DS_BrushNAME:
      //Loader.Brush = CreateBrush()
      brush->name = ReadCString();
      break;
    case M3D_3DS_BrushAMBIENT:
      //ReadChunk();
      //ReadRGB(ChunkID, Red, Green, Blue);
      //brush->SetAmbientColor(Red, Green, Blue);
      break;
    case M3D_3DS_BrushDIFFUSE:
      ReadChunk();
      ReadRGB(ChunkID, Red, Green, Blue);
      brush->BrushColor(Red, Green, Blue);
      break;
    case M3D_3DS_BrushSPECULAR:
      //'Loader.ReadChunk()
      //'Loader.ReadRGB(Loader.ChunkID, Red, Green, Blue)
      //'Loader.Brush.SetSpecularColor(Red, Green, Blue)
      break;
    case M3D_3DS_BrushSHININESS:
      //'Loader.ReadChunk()
      //'Percent = Loader.ReadPercent(Loader.ChunkID)
      //'Loader.Brush.BrushShininess(Percent)
      break;
    case M3D_3DS_MAPFILENAME:
      LoadMap();
      break;
    case M3D_3DS_MAPVSCALE:
      texture->v_scale = Stream->ReadFloat();
      break;
    case M3D_3DS_MAPUSCALE:
      texture->u_scale = Stream->ReadFloat();
      break;
    case M3D_3DS_MAPUOFFSET:
      texture->u_pos = Stream->ReadFloat();
      break;
    case M3D_3DS_MAPVOFFSET:
      texture->v_pos = Stream->ReadFloat();
      break;
    case M3D_3DS_MAPROTATION:
      texture->angle = Stream->ReadFloat();
      break;
    default:
      if ((ChunkID == M3D_3DS_TEXTUREMAP1) || (ChunkID == M3D_3DS_TEXTUREMAP2)) {
        ReadMap(ChunkID);
      }else{
        SkipChunk();
      }
    }
  }
  Stream->CloseFile();

  if (surface!=0){
    MovedTris.sort();
    int CheckSurface=0;
    for(list<int>::const_reverse_iterator it = MovedTris.rbegin(); it != MovedTris.rend(); it++){
      surface->RemoveTri(*it);
      CheckSurface=1;
    }
    MovedTris.clear();

    if (surface->no_tris==0 && CheckSurface !=0) {
      delete surface;
      mesh->surf_list.remove(surface);
      mesh->no_surfs=mesh->no_surfs-1;
    }
  }


//    ChangeDir(OldDir)
//    Loader.Surface.UpdateVertices()
//    Loader.Surface.UpdateTriangles()
  mesh->UpdateNormals();
  /*Loader.Mesh.UpdateBuffer()
  Print Loader.Surface.Tris.Length
  Print Loader.Surface.no_verts
  'Loader.Mesh.FlipMesh()*/

  mesh->class_name="Mesh";
  mesh->AddParent(*parent_ent);
  Entity::entity_list.push_back(mesh);
  if(mesh->parent!=0){
    mesh->mat.Overwrite(mesh->parent->mat);
    mesh->UpdateMat();
  }else{
    mesh->UpdateMat(true);
  }
  return mesh;
}
void RASCATFiniteGammaPhyloProcess::ReadPB(int argc, char* argv[])	{

	string name = "";

	int burnin = -1;
	int every = 1;
	int until = -1;
	int ppred = 0;
	// 1 : plain ppred (outputs simulated data)
	// 2 : diversity statistic
	// 3 : compositional statistic
	int cv = 0;
	int sitelogl = 0;
	int map = 0;
	int rates = 0;
	string testdatafile = "";
	int rateprior = 0;
	int profileprior = 0;
	int rootprior = 1;
	int savetrees = 0;

	int ancstatepostprobs = 0;

	try	{

		if (argc == 1)	{
			throw(0);
		}

		int i = 1;
		while (i < argc)	{
			string s = argv[i];

			if (s == "-div")	{
				ppred = 2;
			}
			else if (s == "-comp")	{
				ppred = 3;
			}
            else if (s == "-siteconvprob")   {
                ppred = 4;
            }
            else if (s == "-sitecomp")   {
                ppred = 5;
            }
			else if (s == "-ppred")	{
				ppred = 1;
			}
			else if (s == "-allppred")	{
				ppred = -1;
			}
			else if (s == "-ppredrate")	{
				i++;
				string tmp = argv[i];
				if (tmp == "prior")	{
					rateprior = 1;
				}
				else if ((tmp == "posterior") || (tmp == "post"))	{
					rateprior = 0;
				}
				else	{
					cerr << "error after ppredrate: should be prior or posterior\n";
					throw(0);
				}
			}
			else if (s == "-ppredprofile")	{
				i++;
				string tmp = argv[i];
				if (tmp == "prior")	{
					profileprior = 1;
				}
				else if ((tmp == "posterior") || (tmp == "post"))	{
					profileprior = 0;
				}
				else	{
					cerr << "error after ppredprofile: should be prior or posterior\n";
					throw(0);
				}
			}
			else if (s == "-ppredroot")	{
				i++;
				string tmp = argv[i];
				if (tmp == "prior")	{
					rootprior = 1;
				}
				else if ((tmp == "posterior") || (tmp == "post"))	{
					rootprior = 0;
				}
				else	{
					cerr << "error after ppredroot: should be prior or posterior\n";
					throw(0);
				}
			}
			else if (s == "-savetrees")	{
				savetrees = 1;
			}

			else if (s == "-anc")	{
				ancstatepostprobs = 1;
			}
			else if (s == "-sitelogl")	{
				sitelogl = 1;
			}
			else if (s == "-r")	{
				rates = 1;
			}
			else if (s == "-map")	{
				map = 1;
			}
			else if (s == "-cv")	{
				cv = 1;
				i++;
				testdatafile = argv[i];
			}
			else if ( (s == "-x") || (s == "-extract") )	{
				i++;
				if (i == argc) throw(0);
				burnin = atoi(argv[i]);
				i++;
				if (i == argc) throw(0);
				s = argv[i];
				if (IsInt(s))	{
					every = atoi(argv[i]);
					i++;
					if (i == argc) throw(0);
					string tmp = argv[i];
					if (IsInt(tmp))	{
						until = atoi(argv[i]);
					}
					else	{
						i--;
					}
				}
				else {
					i--;
				}
			}
			else	{
				if (i != (argc -1))	{
					throw(0);
				}
				name = argv[i];
			}
			i++;
		}
	}
	catch(...)	{
		cerr << "error in command\n";
		cerr << '\n';
		exit(1);
	}

	if (until == -1)	{
		until = GetSize();
	}
	if (burnin == -1)	{
		burnin = GetSize() / 5;
	}

	if ((GetNprocs() == 1) && (ppred || cv || sitelogl))	{
		cerr << "error : should run readpb_mpi in mpi mode, with at least 2 processes\n";
		MPI_Finalize();
		exit(1);
	}

	if (cv)	{
		ReadCV(testdatafile,name,burnin,every,until);
	}
	else if (ancstatepostprobs)	{
		ReadAncestral(name,burnin,every,until);
	}
	else if (sitelogl)	{
		ReadSiteLogL(name,burnin,every,until);
	}
	else if (rates)	{
		ReadSiteRates(name,burnin,every,until);
	}
	else if (ppred == -1)	{
		AllPostPred(name,burnin,every,until,rateprior,profileprior,rootprior);
	}
	else if (ppred)	{
		PostPred(ppred,name,burnin,every,until,rateprior,profileprior,rootprior,savetrees);
	}
	else if (map)	{
		ReadMap(name,burnin,every,until);
	}
	else	{
		Read(name,burnin,every,until);
	}
}
Esempio n. 11
0
int main(int argc, char**argv)
{
	FILE *fIn;
	TFile *fOut;
	struct pre_event_struct *event;
	struct event_struct *Evt;
	struct event_struct *EvtOld;
	int GEvtCnt;
	int i, j, irc;
	long long tbegin, tsum;
	int EvWin;
	time_t systime;
	int Cnt[20];
	const char *CntName[20] = {"Events read", "Time defined", "In diff time cut", "In energy cuts", "Global events", "Global events+2", "Global events+3", 
		"Veto", "Full selection", "", "", "", "", "", "", "", "", "", "", ""};

	Evt = NULL;
	event = NULL;
	fIn = NULL;
	fOut = NULL;
	tsum = 0;
	memset(Cnt, 0, sizeof(Cnt));
	memset(Hist.obj, 0, sizeof(Hist));

	if (ReadMap("danss_map.txt")) return 10;

//		Initializing files and memory
	if (argc < 2) {
		printf("Usage: ./danal2 file.rdat ...\n");
		return 20;
	}

	printf("%d files requested\n", argc - 1);
	fOut = OpenRootFile(argv[1]);
	if (!fOut->IsOpen()) {
		printf("Can not open output root file for %s\n", argv[1]);
		goto fin;
	}

	Evt = (struct event_struct *) malloc(EESIZE);
	EvtOld = (struct event_struct *) malloc(EESIZE);
	event = (struct pre_event_struct *) malloc(ESIZE);
	if (!event || !Evt || !EvtOld) {
		printf("Allocation failure: %m\n");
		goto fin;
	}
//		Book histogramms and trees
	BookHist();
		
	for (j=1; j<argc; j++) {
		GEvtCnt = 0;
		fIn = fopen(argv[j], "rb");
		if (!fIn) {
			printf("Can not open input file %s: %m\n", argv[j]);
			continue;
		}
		EvtOld->gtime = -125000000;
		tbegin = -1;
		EvWin = 0;
		for(;!feof(fIn);) {
			irc = fread(event, sizeof(int), 1, fIn);
			if (irc != 1) break;
			if (event->len > ESIZE || event->len < sizeof(struct pre_event_struct)) {
				printf("Odd block size: %d\n", event->len);
				break;
			}
			irc = fread(&event->systime, event->len - sizeof(int), 1, fIn);
			if (irc != 1) {
				printf("Unexpected EOF - %m\n");
				break;
			}
			systime = event->systime;
			if (tbegin < 0) {
				printf("File %s. Start: %s", argv[j], ctime(&systime));
				tbegin = event->gtime;
			}
			Cnt[0]++;
			memset(Evt, 0, sizeof(struct event_struct));
			Evt->t = FindEventTime(event);
			if (Evt->t < 0) continue;
			Cnt[1]++;
			FilterAndCopy(Evt, event);
			CalculateEventParameters(Evt);
			Hist.h.hT[0]->Fill((Evt->gtime - EvtOld->gtime) / FREQ);
			Hist.h.hEN[0]->Fill(Evt->ns, Evt->es);
			Hist.h.hESEP[0]->Fill(Evt->es, Evt->ep);
			FillXYZ(Evt, 0);
			Hist.h.hV->Fill(Evt->ev);
			Hist.h.mXZ[0]->Fill(Evt->x, Evt->z);
			Hist.h.mYZ[0]->Fill(99-Evt->y, Evt->z);
			if (Evt->ev >= VETOEMIN || Evt->nv >= VETONMIN) {
				Cnt[7]++;
				continue;
			}
			if (Evt->gtime - EvtOld->gtime <= MAXTDIFF * FREQ) {
				Cnt[2]++;
				if (Evt->ep > E2MIN && Evt->es > E2MIN) {
					Cnt[3]++;
					switch (EvWin) {
					case 0:
						Hist.h.hT[1]->Fill((Evt->gtime - EvtOld->gtime) / FREQ);
						Hist.h.hEN[1]->Fill(EvtOld->ns, EvtOld->es);
						Hist.h.hESEP[1]->Fill(EvtOld->es, EvtOld->ep);
						Hist.h.mXZ[1]->Fill(EvtOld->x, EvtOld->z);
						Hist.h.mYZ[1]->Fill(99-EvtOld->y, EvtOld->z);
						FillXYZ(EvtOld, 1);
						Hist.h.hEN[2]->Fill(Evt->ns, Evt->es);
						Hist.h.hESEP[2]->Fill(Evt->es, Evt->ep);
						FillXYZ(Evt, 2);
						Hist.h.mXZ[2]->Fill(Evt->x, Evt->z);
						Hist.h.mYZ[2]->Fill(99-Evt->y, Evt->z);
						FillN(event, Evt->t, 0);
						FillR(Evt, EvtOld);
						Hist.h.hE->Fill(EvtOld->ee);
						Hist.h.hNG->Fill(EvtOld->ng);
						Hist.h.hNC->Fill(EvtOld->nc);
						FillEMaxN(Evt);
						Cnt[4]++;
						GEvtCnt++;
						if (FinalSelection(Evt, EvtOld)) {
							Hist.h.hEE->Fill(EvtOld->ee);
							Hist.h.hNE->Fill(Evt->en);
							Hist.h.hNR->Fill(Evt->rn);
							Cnt[8]++;
						}
						break;
					case 1:
						Hist.h.hT[2]->Fill((Evt->gtime - EvtOld->gtime) / FREQ);
						Hist.h.hEN[3]->Fill(Evt->ns, Evt->es);
						Hist.h.hESEP[3]->Fill(Evt->es, Evt->ep);
						FillXYZ(Evt, 3);
						Hist.h.mXZ[3]->Fill(Evt->x, Evt->z);
						Hist.h.mYZ[3]->Fill(99-Evt->y, Evt->z);
						FillN(event, Evt->t, 1);
						Cnt[5]++;
						break;
					case 2:
						Hist.h.hT[3]->Fill((Evt->gtime - EvtOld->gtime) / FREQ);
						Hist.h.hEN[4]->Fill(Evt->ns, Evt->es);
						Hist.h.hESEP[4]->Fill(Evt->es, Evt->ep);
						FillXYZ(Evt, 4);
						Hist.h.mXZ[4]->Fill(Evt->x, Evt->z);
						Hist.h.mYZ[4]->Fill(99-Evt->y, Evt->z);
						FillN(event, Evt->t, 2);
						Cnt[6]++;
						break;
					}
					EvWin++;
				}
			} else {
				TryAsPositron(Evt);
				if (Evt->ep > E1MIN && Evt->es > E1MIN && Evt->ee > E1MIN) memcpy(EvtOld, Evt, EESIZE);
				Hist.h.hM->Fill(1.0 * EvWin);
				EvWin = 0;
			}
		}
		printf("%d events. End: %s", GEvtCnt, ctime(&systime));
		tsum += event->gtime - tbegin;
		fclose(fIn);
	}
	printf("Total time %f s.\n", tsum / (FREQ*1000000.0));
	printf("Counters:\n");
	for (i = 0; i < sizeof(Cnt)/sizeof(Cnt[0]); i++) if (Cnt[i]) printf("%50s: %10d\n", CntName[i], Cnt[i]);
	for (i = 0; i< sizeof(Hist) / sizeof(Hist.obj[0]); i++) if (Hist.obj[i]) {
		Hist.obj[i]->Write();
		delete Hist.obj[i];
	}
fin:
	if (event) free(event);
	if (Evt) free(Evt);
	if (EvtOld) free(EvtOld);
	if (fOut && fOut->IsOpen()) {
		fOut->Close();
		delete fOut;
	}

	return 0;
}
Esempio n. 12
0
void L3DS::ReadMaterial(const LChunk &parent)
{
    // variables
    LChunk chunk;
    LChunk child;
    char str[30];
    LMaterial mat;
    short sh;

    GotoChunk(parent);

    chunk = ReadChunk();
    while (chunk.end <= parent.end)
    {
        switch (chunk.id)
        {
        case MAT_NAME:
            ReadASCIIZ(str, 30);
            mat.SetName(str);
            break;
        case MAT_AMBIENT:
            child = ReadChunk();
            mat.SetAmbientColor(ReadColor(child));
            break;
        case MAT_DIFFUSE:
            child = ReadChunk();
            mat.SetDiffuseColor(ReadColor(child));
            break;
        case MAT_SPECULAR:
            child = ReadChunk();
            mat.SetSpecularColor(ReadColor(child));
            break;
        case MAT_SHININESS:
            child = ReadChunk();
            mat.SetShininess(ReadPercentage(child));
            break;
        case MAT_TRANSPARENCY:
            child = ReadChunk();
            mat.SetTransparency(ReadPercentage(child));
            break;
        case MAT_SHADING:
            sh = ReadShort();
            switch (sh)
            {
            case 0:
                mat.SetShadingType(sWireframe);
                break;
            case 1:
                mat.SetShadingType(sFlat);
                break;
            case 2:
                mat.SetShadingType(sGouraud);
                break;
            case 3:
                mat.SetShadingType(sPhong);
                break;
            case 4:
                mat.SetShadingType(sMetal);
                break;
            }
            break;
        case MAT_WIRE:
            mat.SetShadingType(sWireframe);
            break;
        case MAT_TEXMAP:
            ReadMap(chunk, mat.GetTextureMap1());
            break;
        case MAT_TEX2MAP:
            ReadMap(chunk, mat.GetTextureMap2());
            break;
        case MAT_OPACMAP:
            ReadMap(chunk, mat.GetOpacityMap());
            break;
        case MAT_BUMPMAP:
            ReadMap(chunk, mat.GetBumpMap());
            break;
        case MAT_SPECMAP:
            ReadMap(chunk, mat.GetSpecularMap());
            break;
        case MAT_REFLMAP:
            // AMZ not really a bugfix but it seems to work!
#if 1
            ReadMap(chunk, mat.GetReflectionMap());
#else
            child = ReadChunk();
            mat.GetReflectionMap().strength = ReadPercentage(child);
            SkipChunk(child);
            child = ReadChunk();
            if (child.id != MAT_MAPNAME)
            {
                fprintf(stderr, "L3DS::ReadMaterial - error, expected chunk not found");
                return;
            }
            ReadASCIIZ(str, 30);
            if (strcmp(str, "") == 0)
                strcpy(mat.GetReflectionMap().mapName, "auto");
#endif
            break;
        }

        SkipChunk(chunk);
        chunk = ReadChunk();
    }
    m_materials.push_back(mat);
    m_materials[m_materials.size()-1].SetID(uint(m_materials.size())-1);
}
Esempio n. 13
0
int main(int argc, char *argv[]) {

	int client_len = sizeof(client_addr);
	int ns;
	int x, y;

	ReadMap("house.dat");

	pthread_mutex_lock(&mapMutex);
	for(y = 0; y < HOUSE_HEIGHT; y++) {
		for(x = 0; x < HOUSE_WIDTH; x++) {
			if(map[y][x].type == TYPE_KID) {
				child.x = x;
				child.y = y;
			}
		}
	}
	pthread_mutex_unlock(&mapMutex);

	pthread_mutex_lock(&houseMutex);
	houseObject.active = 0;
	houseObject.locked = 0;
	houseObject.level[0] = 70;
	houseObject.level[1] = 0;
	pthread_mutex_unlock(&houseMutex);

	childBlock.type = TYPE_FLOOR;
	childBlock.active = 0;
	childBlock.locked = 0;
	childBlock.level[0] = 0;
	childBlock.level[1] = 0;

	signal(SIGQUIT, Terminate);
	signal(SIGINT, Terminate);
	signal(SIGTERM, Terminate);

	if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		printf("%s: error: could not create socket\n", argv[0]);
		exit(1);
	}

	if(bind(sd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
		printf("%s: error: could not bind\n", argv[0]);
		exit(1);
	}

	if(listen(sd, MAX_CLIENTS) == -1) {
		printf("%s: error: listen()\n", argv[0]);
		exit(1);
	}

	for(x = 0; x < MAX_CLIENTS; x++) {
		client[x].ns = -1;
	}

	if(pthread_create(&htid, NULL, HouseThread, NULL)) {
		printf("%s: error: could not create thread\n", argv[0]);
	}

	printf("Press ^C to exit\n");

	for(;;) {
		ns = accept(sd, (struct sockaddr*)&client_addr, &client_len);
		pthread_mutex_lock(&clientMutex);
		for(x = 0; x < MAX_CLIENTS; x++) {
			if(client[x].ns < 0) {
				break;
			}
		}
		if(client[x].ns >= 0) {
			break;
		}
		client[x].ns = ns;
		pthread_mutex_unlock(&clientMutex);

		if(pthread_create(&client[x].tid, NULL, TalkThread, &client[x])) {
			printf("%s: error: could not create thread\n", argv[0]);
		}
	}

	close(sd);

	printf("%s: error: too many clients\n", argv[0]);

	return 0;
}
Esempio n. 14
0
/// Make wxPdfDocument font metrics file based on AFM file
bool
MakeFont::MakeFontAFM(const wxString& fontFileName, const wxString& afmFileName,
                      const wxString& encoding, const wxString& type, const wxString& patch)
{
  bool valid = false;
  wxString fontType = type;
  wxFileName fileName(fontFileName);
  // Find font type
  if (fontFileName.Length() > 0)
  {
    wxString ext = fileName.GetExt();
    if (ext == wxT("ttf"))
    {
      fontType = wxT("TrueType");
    }
    else if (ext == wxT("pfb"))
    {
      fontType = wxT("Type1");
    }
    else
    {
      wxLogMessage(wxT("Warning: Unrecognized font file extension (") + ext + wxT("), ") + fontType + wxT(" font assumed."));
    }
  }

  bool embeddingAllowed = true;
  bool subsettingAllowed = true;
  if (fontFileName.Length() > 0)
  {
    int cffOffset, cffLength;
    if (fontType == wxT("TrueType"))
    {
      CheckTTF(fontFileName, embeddingAllowed, subsettingAllowed, cffOffset, cffLength);
    }
  }

  wxPdfFontData* afmFont;
  if (fontType == wxT("TrueType"))
  {
    afmFont = new wxPdfFontDataTrueType();
  }
  else
  {
    afmFont = new wxPdfFontDataType1();
  }
  // Initialize font description
  wxPdfFontDescription fd;
  fd.SetAscent(1000);
  fd.SetDescent(-200);
  fd.SetItalicAngle(0);
  fd.SetStemV(70);
  fd.SetMissingWidth(600);
  fd.SetUnderlinePosition(-100);
  fd.SetUnderlineThickness(50);
  
  bool hasCapHeight = false;
  bool hasXCapHeight = false;
  bool hasXHeight = false;
  bool hasFontBBox = false;
  bool hasStemV = false;
  bool hasMissingWidth = false;
  int flags = 0;

  CTGMap cc2gn;
  CTGMap cc2gnPatch;
  if (encoding.Length() > 0)
  {
    afmFont->SetEncoding(encoding);
    valid = ReadMap(encoding, cc2gn);
    if (!valid)
    {
      delete afmFont;
      return false;
    }
    if (patch.Length() > 0)
    {
      valid = ReadMap(patch, cc2gnPatch);
      if (valid)
      {
        CTGMap::iterator patchIter;
        for (patchIter = cc2gnPatch.begin(); patchIter != cc2gnPatch.end(); patchIter++)
        {
          cc2gn[patchIter->first] = patchIter->second;
        }
      }
      else
      {
        wxLogMessage(wxT("Warning: Unable to read patch file '") + patch + wxT("'."));
      }
    }
  }

  // Read a font metric file
  wxFileInputStream afmFile(afmFileName);
  if (!afmFile.Ok())
  {
    wxLogMessage(wxT("Error: Unable to read AFM file '") + afmFileName + wxT("'."));
    delete afmFont;
    return false;
  }
  wxTextInputStream text(afmFile);

  FixGlyphMap fix;

  fix[wxT("Edot")] = wxT("Edotaccent");
  fix[wxT("edot")] = wxT("edotaccent");
  fix[wxT("Idot")] = wxT("Idotaccent");
  fix[wxT("Zdot")] = wxT("Zdotaccent");
  fix[wxT("zdot")] = wxT("zdotaccent");
  fix[wxT("Odblacute")] = wxT("Ohungarumlaut");
  fix[wxT("odblacute")] = wxT("ohungarumlaut");
  fix[wxT("Udblacute")] = wxT("Uhungarumlaut");
  fix[wxT("udblacute")] = wxT("uhungarumlaut");
  fix[wxT("Gcedilla")] = wxT("Gcommaaccent");
  fix[wxT("gcedilla")] = wxT("gcommaaccent");
  fix[wxT("Kcedilla")] = wxT("Kcommaaccent");
  fix[wxT("kcedilla")] = wxT("kcommaaccent");
  fix[wxT("Lcedilla")] = wxT("Lcommaaccent");
  fix[wxT("lcedilla")] = wxT("lcommaaccent");
  fix[wxT("Ncedilla")] = wxT("Ncommaaccent");
  fix[wxT("ncedilla")] = wxT("ncommaaccent");
  fix[wxT("Rcedilla")] = wxT("Rcommaaccent");
  fix[wxT("rcedilla")] = wxT("rcommaaccent");
  fix[wxT("Scedilla")] = wxT("Scommaaccent");
  fix[wxT("scedilla")] = wxT("scommaaccent");
  fix[wxT("Tcedilla")] = wxT("Tcommaaccent");
  fix[wxT("tcedilla")] = wxT("tcommaaccent");
  fix[wxT("Dslash")] = wxT("Dcroat");
  fix[wxT("dslash")] = wxT("dcroat");
  fix[wxT("Dmacron")] = wxT("Dcroat");
  fix[wxT("dmacron")] = wxT("dcroat");
  fix[wxT("combininggraveaccent")] = wxT("gravecomb");
  fix[wxT("combininghookabove")] = wxT("hookabovecomb");
  fix[wxT("combiningtildeaccent")] = wxT("tildecomb");
  fix[wxT("combiningacuteaccent")] = wxT("acutecomb");
  fix[wxT("combiningdotbelow")] = wxT("dotbelowcomb");
  fix[wxT("dongsign")] = wxT("dong");

  // Read the AFM font metric file
  wxPdfGlyphWidthMap* widths = new wxPdfGlyphWidthMap();
  wxPdfChar2GlyphMap* glyphs = new wxPdfChar2GlyphMap();
  long cc;
  if (!cc2gn.empty())
  {
    for (cc = 0; cc <= 255; cc++)
    {
      (*widths)[cc] = 0xFFFF;
      (*glyphs)[cc] = 0;
    }
  }

  wxString line;
  wxString charcode, glyphname;
  wxString code, param, dummy, glyph;
  wxString token, tokenBoxHeight;
  long nParam, incWidth = -1, incGlyph = 0;
  long width, boxHeight, glyphNumber;
  wxString weight;
  bool hasGlyphNumbers = false;
  while (!afmFile.Eof())
  {
    line = text.ReadLine();
    line.Trim();

    wxStringTokenizer tkz(line, wxT(" "));
    int count = (int) tkz.CountTokens();
    if (count < 2) continue;
    code  = tkz.GetNextToken(); // 0
    param = tkz.GetNextToken(); // 1
    if (code == wxT("C"))
    {
      width = -1;
      glyphNumber = 0;
      boxHeight = 0;
      tokenBoxHeight = wxEmptyString;
      // Character metrics
      param.ToLong(&cc);
      dummy = tkz.GetNextToken(); // 2
      while (tkz.HasMoreTokens())
      {
        token = tkz.GetNextToken();
        if (token == wxT("WX")) // Character width
        {
          param = tkz.GetNextToken(); // Width
          param.ToLong(&width);
          dummy = tkz.GetNextToken(); // Semicolon
        }
        else if (token == wxT("N")) // Glyph name
        {
          glyphname = tkz.GetNextToken(); // Glyph name
          dummy = tkz.GetNextToken(); // Semicolon
        }
        else if (token == wxT("G")) // Glyph number
        {
          hasGlyphNumbers = true;
          param = tkz.GetNextToken(); // Number
          param.ToLong(&glyphNumber);
          dummy = tkz.GetNextToken(); // Semicolon
        }
        else if (token == wxT("B")) // Character bounding box
        {
          dummy = tkz.GetNextToken(); // x left
          dummy = tkz.GetNextToken(); // y bottom
          dummy = tkz.GetNextToken(); // x right
          tokenBoxHeight = tkz.GetNextToken(); // y top
          tokenBoxHeight.ToLong(&boxHeight);
          dummy = tkz.GetNextToken(); // Semicolon
        }
        else
        {
          while (tkz.HasMoreTokens() && tkz.GetNextToken() != wxT(";"));
        }
      }

      if (glyphname.Right(4) == wxT("20AC"))
      {
        glyphname = wxT("Euro");
      }
      if (glyphname == wxT("increment"))
      {
        incWidth = width;
        if (hasGlyphNumbers)
        {
          incGlyph = glyphNumber;
        }
      }
      if (fix.find(glyphname) != fix.end())
      {
        //Fix incorrect glyph name
        for (int i = 0; i <= 255; i++)
        {
          if (cc2gn[i] == fix[glyphname])
          {
            cc2gn[i] = glyphname;
          }
        }
      }
      if (cc2gn.empty())
      {
        // Symbolic font: use built-in encoding
        (*widths)[cc] = width;
        if (hasGlyphNumbers)
        {
          (*glyphs)[cc] = glyphNumber;
        }
        if (!hasCapHeight && !hasXCapHeight && cc == 'X' && tokenBoxHeight != wxEmptyString)
        {
          hasXCapHeight = true;
          fd.SetCapHeight(boxHeight);
        }
        if (!hasXHeight && cc == 'x' && tokenBoxHeight != wxEmptyString)
        {
          hasXHeight = true;
          fd.SetXHeight(boxHeight);
        }
      }
      else
      {
        // Search glyphname in cc2gn
        bool found = false;
        for (int i = 0; i <= 255; i++)
        {
          if (cc2gn[i] == glyphname)
          {
            found = true;
            (*widths)[i] = width;
            if (hasGlyphNumbers)
            {
              (*glyphs)[i] = glyphNumber;
            }
          }
        }
        if (!found)
        {
          wxLogMessage(wxT("Warning: character '") + glyphname + wxT("' is undefined."));
        }
        if (!hasCapHeight && !hasXCapHeight && glyphname == wxT("X") && tokenBoxHeight != wxEmptyString)
        {
          hasXCapHeight = true;
          fd.SetCapHeight(boxHeight);
        }
        if (!hasXHeight && glyphname == wxT("x") && tokenBoxHeight != wxEmptyString)
        {
          hasXHeight = true;
          fd.SetXHeight(boxHeight);
        }
      }
      if (!hasMissingWidth && glyphname == wxT(".notdef"))
      {
        hasMissingWidth = true;
        fd.SetMissingWidth(width);
      }
    }
    else if (code == wxT("FontName"))
    {
      afmFont->SetName(param);
    }
    else if (code == wxT("Weight"))
    {
      wxString weight = param.Lower();
      if (!hasStemV && (weight == wxT("black") || weight == wxT("bold")))
      {
        fd.SetStemV(120);
      }
    }
    else if (code == wxT("ItalicAngle"))
    {
      double italic;
      param.ToDouble(&italic);
      int italicAngle = int(italic);
      fd.SetItalicAngle(italicAngle);
      if (italicAngle > 0)
      {
        flags += 1 << 6;
      }
    }
    else if (code == wxT("Ascender"))
    {
      long ascent;
      param.ToLong(&ascent);
      fd.SetAscent(ascent);
    }
    else if (code == wxT("Descender"))
    {
      param.ToLong(&nParam);
      fd.SetDescent(nParam);
    }
    else if (code == wxT("UnderlineThickness"))
    {
      param.ToLong(&nParam);
      fd.SetUnderlineThickness(nParam);
    }
    else if (code == wxT("UnderlinePosition"))
    {
      param.ToLong(&nParam);
      fd.SetUnderlinePosition(nParam);
    }
    else if (code == wxT("IsFixedPitch"))
    {
      if (param == wxT("true"))
      {
        flags += 1 << 0;
      }
    }
    else if (code == wxT("FontBBox"))
    {
      hasFontBBox = true;
      wxString bbox2 = tkz.GetNextToken();
      wxString bbox3 = tkz.GetNextToken();
      wxString bbox4 = tkz.GetNextToken();
      wxString bBox = wxT("[") + param + wxT(" ") + bbox2 + wxT(" ") + bbox3 + wxT(" ") + bbox4 + wxT("]");
      fd.SetFontBBox(bBox);
    }
    else if (code == wxT("CapHeight"))
    {
      hasCapHeight = true;
      long capHeight;
      param.ToLong(&capHeight);
      fd.SetCapHeight(capHeight);
    }
    else if (code == wxT("StdVW"))
    {
      hasStemV = true;
      long stemV;
      param.ToLong(&stemV);
      fd.SetStemV(stemV);
    }
  }

  for (cc = 0; cc <= 255; cc++)
  {
    if ((*widths)[cc] == 0xFFFF)
    {
      if (cc2gn[cc] == wxT("Delta") && incWidth >= 0)
      {
        (*widths)[cc] = incWidth;
        if (hasGlyphNumbers)
        {
          (*glyphs)[cc] = incGlyph;
        }
      }
      else
      {
        (*widths)[cc] = fd.GetMissingWidth();
        if (hasGlyphNumbers)
        {
          (*glyphs)[cc] = 0;
        }
        wxLogMessage(wxT("Warning: character '") + cc2gn[cc] + wxT("' is missing."));
      }
    }
  }

  wxString diffs;
  if (encoding.Length() > 0)
  {
    // Build differences from reference encoding
    CTGMap cc2gnRef;
    valid = ReadMap(wxT("cp1252"), cc2gnRef);
    diffs = wxT("");
    int last = 0;
    for (int i = 32; i <= 255; i++)
    {
      if (cc2gn[i] != cc2gnRef[i])
      {
        if (i != last+1)
        {
          diffs += wxString::Format(wxT("%d "), i);
        }
        last = i;
        diffs = diffs + wxT("/") + cc2gn[i] + wxT(" ");
      }
    }
  }
  afmFont->SetDiffs(diffs);  
  
  if (cc2gn.empty())
  {
    flags += 1 << 2;
  }
  else
  {
    flags += 1 << 5;
  }
  fd.SetFlags(flags);
  if (!hasCapHeight && !hasXCapHeight)
  {
    fd.SetCapHeight(fd.GetAscent());
  }
  if (!hasFontBBox)
  {
    wxString fbb = wxString::Format(wxT("[0 %d 1000 %d]"), fd.GetDescent()-100, fd.GetAscent()+100);
    fd.SetFontBBox(fbb);
  }

  afmFont->SetGlyphWidthMap(widths);
  afmFont->SetChar2GlyphMap(glyphs);

  afmFont->SetDescription(fd);

  wxString baseName = fileName.GetName();
  if (embeddingAllowed)
  {
    if (fontType == wxT("TrueType"))
    {
      wxFileInputStream ttfFile(fontFileName);
      if (!ttfFile.Ok())
      {
        wxLogMessage(wxT("Error: Unable to read font file '") + fontFileName + wxT("'."));
        delete afmFont;
        return false;
      }
      size_t len = ttfFile.GetLength();
      wxFileOutputStream outFontFile(baseName + wxT(".z"));
      wxZlibOutputStream zOutFontFile(outFontFile);
      zOutFontFile.Write(ttfFile);
      zOutFontFile.Close();
      afmFont->SetFontFile(baseName + wxT(".z"));
      afmFont->SetSize1(len);
      wxLogMessage(wxT("Font file compressed (") + baseName + wxT(".z)."));
    }
    else
    {
      wxFileInputStream pfbFile(fontFileName);
      if (!pfbFile.Ok())
      {
        wxLogMessage(wxT("Error: Unable to read font file '") + fontFileName + wxT("'."));
        delete afmFont;
        return false;
      }
      size_t len = pfbFile.GetLength();
      // Find first two sections and discard third one
      unsigned char* buffer = new unsigned char[len];
      unsigned char* buf1 = buffer;
      unsigned char* buf2;
      pfbFile.Read(buffer, len);
      unsigned char first = buffer[0];
      if (first == 128)
      {
        // Strip first binary header
        buf1 += 6;
        len -= 6;
      }
      int* f = makeFail("eexec",5);
      int size1 = (int) findString((char*) buf1, len, "eexec", 5, f);
      delete [] f;

      int size2 = -1;
      if (size1 >= 0)
      {
        size1 += 6;
        unsigned char second = buf1[size1];
        buf2 = buf1 + size1;
        len -= size1;
        if (first == 128 && second == 128)
        {
          // Strip second binary header
          buf2 += 6;
          len -= 6;
        }
        f = makeFail("00000000",8);
        size2 = (int) findString((char*) buf2, len, "00000000", 8, f);
        delete [] f;
        if (size2 >= 0)
        {
          wxFileOutputStream outFontFile(baseName + wxT(".z"));
          wxZlibOutputStream zOutFontFile(outFontFile);
          zOutFontFile.Write(buf1, size1);
          zOutFontFile.Write(buf2, size2);
          afmFont->SetFontFile(baseName + wxT(".z"));
          afmFont->SetSize1(size1);
          afmFont->SetSize2(size2);
        }
      }
      delete [] buffer;
      if (size1 < 0 || size2 < 0)
      {
        wxLogMessage(wxT("Warning: Font file does not seem to be valid Type1, font embedding not possible."));
      }
    }
  }
  else
  {
    if (fontFileName.Length() > 0)
    {
      wxLogMessage(wxT("Warning: Font license does not allow embedding."));
    }
    else
    {
      wxLogMessage(wxT("Warning: Font file name missing, font embedding not possible."));
    }
  }

  // Create XML file
  CreateFontMetricsFile(baseName + wxT(".xml"), *afmFont, hasGlyphNumbers);
  wxLogMessage(wxT("Font definition file generated (") + baseName + wxT(".xml)."));

  //delete widths;
  delete afmFont;
  return true;
}
void CodonMutSelSBDPPhyloProcess::ReadPB(int argc, char* argv[])	{

	string name = "";

	int burnin = 0;
	int every = 1;
	int until = -1;
	int ppred = 0;
	// 1 : plain ppred (outputs simulated data)
	// 2 : diversity statistic
	// 3 : compositional statistic

	int sel = 0;
	int map = 0;

	try	{

		if (argc == 1)	{
			throw(0);
		}

		int i = 1;
		while (i < argc)	{
			string s = argv[i];
			if (s == "-sel")	{
				sel = 1;
			}
			else if (s == "-map")	{
				map = 1;
			}
			//else if (s == "-ppred")	{
			//	ppred = 1;
			//}
			else if ( (s == "-x") || (s == "-extract") )	{
				i++;
				if (i == argc) throw(0);
				burnin = atoi(argv[i]);
				i++;
				if (i == argc) throw(0);
				s = argv[i];
				if (IsInt(s))	{
					every = atoi(argv[i]);
					i++;
					if (i == argc) throw(0);
					string tmp = argv[i];
					if (IsInt(tmp))	{
						until = atoi(argv[i]);
					}
					else	{
						i--;
					}
				}
				else {
					i--;
				}
			}
			else	{
				if (i != (argc -1))	{
					throw(0);
				}
				name = argv[i];
			}
			i++;
		}
	}
	catch(...)	{
		cerr << "error in command\n";
		cerr << '\n';
		exit(1);
	}

	if (until == -1)	{
		until = GetSize();
	}

	if (map)	{
		ReadMap(name,burnin,every,until);
	}
	else	{
		Read(name,burnin,every,until);
	}
}
void AACodonMutSelSBDPPhyloProcess::ReadPB(int argc, char* argv[])	{

	string name = "";

	int burnin = 0;
	int every = 1;
	int until = -1;
	int ppred = 0;
	// 1 : plain ppred (outputs simulated data)
	// 2 : diversity statistic
	// 3 : compositional statistic

	int cv = 0;
	int sel = 0;
	int map = 0;
	int mapstats = 0;
	string testdatafile = "";

	int rateprior = 0;
	int profileprior = 0;
	int rootprior = 1;

	int ss = 0;
	int om = 0;

	try	{

		if (argc == 1)	{
			throw(0);
		}

		int i = 1;
		while (i < argc)	{
			string s = argv[i];
			if (s == "-sel")	{
				sel = 1;
			}
			else if (s == "-map")	{
				map = 1;
			}
			else if (s == "-mapstats")	{
				mapstats = 1;
			}
			else if (s == "-cv")	{
				cv = 1;
				i++;
				testdatafile = argv[i];
			}
			else if (s == "-ppred")	{
				ppred = 1;
			}
			else if (s == "-ppredrate")	{
				i++;
				string tmp = argv[i];
				if (tmp == "prior")	{
					rateprior = 1;
				}
				else if ((tmp == "posterior") || (tmp == "post"))	{
					rateprior = 0;
				}
				else	{
					cerr << "error after ppredrate: should be prior or posterior\n";
					throw(0);
				}
			}
			else if (s == "-ppredprofile")	{
				i++;
				string tmp = argv[i];
				if (tmp == "prior")	{
					profileprior = 1;
				}
				else if ((tmp == "posterior") || (tmp == "post"))	{
					profileprior = 0;
				}
				else	{
					cerr << "error after ppredprofile: should be prior or posterior\n";
					throw(0);
				}
			}
			else if (s == "-ppredroot")	{
				i++;
				string tmp = argv[i];
				if (tmp == "prior")	{
					rootprior = 1;
				}
				else if ((tmp == "posterior") || (tmp == "post"))	{
					rootprior = 0;
				}
				else	{
					cerr << "error after ppredroot: should be prior or posterior\n";
					throw(0);
				}
			}
			else if (s == "-div")	{
				ppred = 2;
			}
			else if (s == "-ss")	{
				ss = 1;
			}
			else if (s == "-om")	{
				om = 1;
			}
			else if ( (s == "-x") || (s == "-extract") )	{
				i++;
				if (i == argc) throw(0);
				burnin = atoi(argv[i]);
				i++;
				if (i == argc) throw(0);
				s = argv[i];
				if (IsInt(s))	{
					every = atoi(argv[i]);
					i++;
					if (i == argc) throw(0);
					string tmp = argv[i];
					if (IsInt(tmp))	{
						until = atoi(argv[i]);
					}
					else	{
						i--;
					}
				}
				else {
					i--;
				}
			}
			else	{
				if (i != (argc -1))	{
					throw(0);
				}
				name = argv[i];
			}
			i++;
		}
	}
	catch(...)	{
		cerr << "error in command\n";
		cerr << '\n';
		exit(1);
	}

	if (until == -1)	{
		until = GetSize();
	}

	if (map)	{
		ReadMap(name,burnin,every,until);
	}
	else if (cv)	{
		ReadCV(testdatafile,name,burnin,every,until,1,codetype);
	}
	//if (sel)	{
	//	ReadSDistributions(name,burnin,every,until);
	//}
	else if (ss)	{
		ReadSiteProfiles(name,burnin,every,until);
	}
	else if (om)	{
		ReadPredictedOmega(name,burnin,every,until);
	}
	else if (mapstats)	{
		ReadMapStats(name,burnin,every,until);
	}
	else if (ppred)	{
		PostPred(ppred,name,burnin,every,until,rateprior,profileprior,rootprior);
	}
	else	{
		Read(name,burnin,every,until);
	}
}