static void TestSequence2(const sChar *desc,sArrayRange<FakeVertex> &seq) { static const sInt nAttempts = 3; sStaticArray<FakeVertex> arr(seq.GetCount()); sPrintF(L"%-12s ",desc); for(sInt i=0; i<sCOUNTOF(sortFuncs2); i++) { // report minimum runtime over nAttempts runs sInt minTime = 0x7fffffff; for(sInt j=0; j<nAttempts; j++) { arr.Clear(); sCopyMem(arr.AddMany(seq.GetCount()),&seq[0],seq.GetCount()*sizeof(FakeVertex)); ThrashCache(); sU64 start = sGetTimeUS(); sortFuncs2[i](arr); minTime = sMin(minTime,(sInt) (sGetTimeUS() - start)); // verify that the sorted sequence is nondecreasing for(sInt i=1; i<arr.GetCount(); i++) sVERIFY(!(arr[i] < arr[i-1])); } sPrintF(L"%10d ",minTime); } sPrint(L"\n"); }
static void TestSequence1(const sChar *desc,sArrayRange<sInt> &seq) { static const sInt nAttempts = 3; sStaticArray<sInt> arr(seq.GetCount()); sPrintF(L"%-12s ",desc); for(sInt i=0; i<sCOUNTOF(sortFuncs1); i++) { // report minimum runtime over nAttempts runs sInt minTime = 0x7fffffff; for(sInt j=0; j<nAttempts; j++) { arr.Clear(); sCopyMem(arr.AddMany(seq.GetCount()),&seq[0],seq.GetCount()*sizeof(sInt)); ThrashCache(); sU64 start = sGetTimeUS(); sortFuncs1[i](arr); minTime = sMin(minTime,(sInt) (sGetTimeUS() - start)); } VerifySorted(&arr[0],arr.GetCount()); sPrintF(L"%10d ",minTime); } sPrint(L"\n"); }
static void TestForEach() { KVPair x[nTestInts]; KVList lx[nTestInts]; sDList<KVList,&KVList::Node> keysOrig; InitKVTest(x); for(sInt i=0; i<nTestInts; i++) { lx[i].Key = x[i].Key; lx[i].Value = x[i].Value; keysOrig.AddTail(&lx[i]); } sInsertionSort(sReverse(sAll(x)),sMemberGreater(&KVPair::Key)); sPrint(L"Iteration using sFOREACH:\n"); KVPair *pair; sFOREACH(sAll(x),pair) sPrintF(L"%s ",pair->Value); sPrint(L"\n"); KVList *lpair; sFOREACH(sReverse(sAll(keysOrig)),lpair) sPrintF(L"%s ",lpair->Value); sPrint(L"\n"); sPrint(L"Primes smaller than 100:\n"); const sInt *pr; sFOREACH(PrimesSmallerThan(100),pr) sPrintF(L"%2d ",*pr); sPrint(L"\n"); }
static void TestReverseRange() { KVPair x[nTestInts]; KVList lx[nTestInts]; sDList<KVList,&KVList::Node> keysOrig; InitKVTest(x); for(sInt i=0; i<nTestInts; i++) { lx[i].Key = x[i].Key; lx[i].Value = x[i].Value; keysOrig.AddTail(&lx[i]); } sPrintF(L"Reverse range test:\n"); sInsertionSort(sReverse(sAll(x)),sMemberGreater(&KVPair::Key)); PrintKV(x); PrintKVRange(sAll(x)); PrintKVRange(sReverse(sAll(x))); sPrintF(L"List range test:\n"); PrintKVRange(sAll(keysOrig)); PrintKVRange(sReverse(sAll(keysOrig))); }
static void PrintSortHeader() { sPrintF(L"%12s ",L""); // space for sequence type for(sInt i=0; i<sCOUNTOF(sortFuncs1); i++) sPrintF(L"%10s ",sortFuncNames[i]); sPrint(L"\n"); }
void ServerThread(sThread *t,void *user) { sMiniFTPServer server(12345); sPrintF(L"Starting server, Ctrl+C to exit.\n"); server.SetRequestHandler(RequestHandler); server.Run(t); }
void Altona2::Main() { sPrint ("print umlaut a, umlaut o, umlaut u and euro in different ways.\n"); sDPrint ("print umlaut a, umlaut o, umlaut u and euro in different ways.\n"); // if this fails, printf does not produce unicode sPrintF("from %%c with hex literals <%c%c%c%c>\n",0x00e4,0x00f6,0x00fc,0x20ac); sDPrintF("from %%c with hex literals <%c%c%c%c>\n",0x00e4,0x00f6,0x00fc,0x20ac); // if the euro fails, then the source is in ansi // if all fails, we have a signed / unsigned problem sPrintF("from %%c with char literals <%c%c%c%c>\n",'ה','צ','�','€'); sDPrintF("from %%c with char literals <%c%c%c%c>\n",'ה','צ','�','€'); // if this fails, then the compiler is not set to utf8 sPrint ("from proper escape codes: <\u00e4\u00f6\u00fc\u20ac>\n"); sDPrint ("from proper escape codes: <\u00e4\u00f6\u00fc\u20ac>\n"); // if this fails, then the source is not in utf8 // sPrint ("from string literal: <הצ�€>\n"); // sDPrint ("from string literal: <הצ�€>\n"); }
void sMain() { sGetMemHandler(sAMF_HEAP)->MakeThreadSafe(); // WTF?! { sThread serve(ServerThread); sCatchCtrlC(); while(!sGotCtrlC()) sSleep(100); } sPrintF(L"Server quit.\n"); }
static void TestPredicates() { KVPair x[nTestInts]; KVPair *y[nTestInts]; sPrintF(L"Ref member predicate test (mainly a compile test):\n"); InitKVTest(x); sInsertionSort(sAll(x),sMemberLess(&KVPair::Key)); PrintKV(x); InitKVTest(x); sHeapSort(sAll(x),sMemberGreater(&KVPair::Key)); PrintKV(x); sPrintF(L"Ptr member predicate test (mainly a compile test):\n"); InitKVTest(x); InitKVIndir(y,x); sInsertionSort(sAll(y),sMemPtrGreater(&KVPair::Key)); PrintKVIndir(y); InitKVIndir(y,x); sHeapSort(sAll(y),sMemPtrLess(&KVPair::Key)); PrintKVIndir(y); }
sBool sShaderCompile(sCompileResult &result, sInt stype, sInt dtype, const sChar *source, sInt len, sInt flags /*=0*/, const sChar *name/*=0*/) { for(sInt i=0;i<CompilerCount;i++) { if((ShaderCompiler[i].SrcType&(sSTF_PLATFORM|sSTF_PROFILE)) == (stype&(sSTF_PLATFORM|sSTF_PROFILE)) && (ShaderCompiler[i].DstType&(sSTF_PLATFORM|sSTF_PROFILE)) == (dtype&(sSTF_PLATFORM|sSTF_PROFILE))) { sChar8 *buffer = new sChar8[len]; sCopyString(buffer,source,len); if(!name) name = L"main"; sChar8 name8[64]; sCopyString(name8,name,64); sBool check = (*ShaderCompiler[i].Func)(result,stype,dtype,flags,buffer,len,name8); sDeleteArray(buffer); return check; } } sPrintF(L"no shader compiler found for 0x%08x -> 0x%08x\n",stype,dtype); return sFALSE; }
void sMain() { Document Doc; sString<sMAXPATH> path; const sChar *proj; sString<sMAXPATH> configbuffer; sString<sMAXPATH> projbuffer; // command line parameters Doc.WriteFlag = !(sGetShellSwitch(L"p")||sGetShellSwitch(L"-pretend")); Doc.CheckLicenseFlag = sGetShellSwitch(L"l")||sGetShellSwitch(L"-license"); Doc.TestFlag = sGetShellSwitch(L"t")||sGetShellSwitch(L"-test"); Doc.DebugFlag = sGetShellSwitch(L"d")||sGetShellSwitch(L"-debug"); Doc.BriefFlag = !(sGetShellSwitch(L"v")||sGetShellSwitch(L"-verbose")); Doc.CreateNewFiles = sGetShellSwitch(L"c")||sGetShellSwitch(L"-create"); if(sGetShellParameter(L"r",0)) path.PrintF(L"%p",sGetShellParameter(L"r",0)); // this converts '\\' to '/' else path.PrintF(L"%p",sCONFIG_CODEROOT); const sChar *depPattern = sGetShellParameter(L"D",0); projbuffer = path; projbuffer.AddPath(sCONFIG_MP_TEMPLATES); proj = projbuffer; Doc.RootPath.RootPath[OmniPath::PT_SYSTEM] = path; Doc.RootPath.RootPath[OmniPath::PT_SOLUTION] = path; // was sCONFIG_CODEROOT_WINDOWS, which was sCONFIG_CODEROOT, but doesn't work -r param SetTildeExpand(Doc.RootPath.RootPath[OmniPath::PT_MAKEFILE],path); configbuffer = path; configbuffer.AddPath(sCONFIG_CONFIGFILE); Doc.ConfigFile.Scan(configbuffer); Doc.ConfigFile.DPrint(); if(sCmpString(Doc.ConfigFile.VSVersion,L"2008")>=0) { Doc.VS_Version = 9; Doc.VS_ProjectVersion = 9; Doc.VS_SolutionVersion = 10; } if(sCmpString(Doc.ConfigFile.VSVersion,L"2010")>=0) { Doc.VS_ProjExtension = L".vcxproj"; Doc.VS_Version = 10; Doc.VS_ProjectVersion = 10; Doc.VS_SolutionVersion = 11; } if(sCmpString(Doc.ConfigFile.VSVersion,L"2012")>=0) { Doc.VS_ProjExtension = L".vcxproj"; Doc.VS_Version = 11; Doc.VS_ProjectVersion = 10; Doc.VS_SolutionVersion = 11; } Doc.IntermediatePath.RootPath[OmniPath::PT_SYSTEM] = Doc.ConfigFile.IntermediateRoot; Doc.IntermediatePath.RootPath[OmniPath::PT_SOLUTION] = Doc.ConfigFile.IntermediateRoot; SetTildeExpand(Doc.IntermediatePath.RootPath[OmniPath::PT_MAKEFILE],Doc.ConfigFile.IntermediateRoot); Doc.OutputPath.RootPath[OmniPath::PT_SYSTEM] = Doc.ConfigFile.OutputRoot; Doc.OutputPath.RootPath[OmniPath::PT_SOLUTION] = Doc.ConfigFile.OutputRoot; SetTildeExpand(Doc.OutputPath.RootPath[OmniPath::PT_MAKEFILE],Doc.ConfigFile.OutputRoot); Doc.VSPlatformMask = 0; if(Doc.ConfigFile.Solution & sSLN_WIN32) Doc.VSPlatformMask |= sVSPLAT_WIN32; if(Doc.ConfigFile.Solution & sSLN_WIN64) Doc.VSPlatformMask |= sVSPLAT_WIN64; Doc.ConfMakefile = Document::MF_NONE; if(Doc.ConfigFile.Makefile==sMAKE_MINGW) Doc.ConfMakefile = Document::MF_MINGW; if(Doc.ConfigFile.Makefile==sMAKE_LINUX) Doc.ConfMakefile = Document::MF_LINUX; sPrintF(L"makeproject v%d.%d\n",VERSION,REVISION); if(sGetShellSwitch(L"vs")) { sPrint(L"the '-vs' option is obsolete. please use 'altona_config.hpp'\n"); } else if(sGetShellSwitch(L"h")||sGetShellSwitch(L"-help")) { sPrint(L"makeproject [options]\n"); sPrint(L"-r path root (default c:/svn2)\n"); sPrint(L"-h --help print this text\n"); sPrint(L"-p --pretend don't write destination files\n"); sPrint(L"-t --test write to .vsproj.txt\n"); sPrint(L"-d --debug output parser tree\n"); sPrint(L"-v --verbose more output\n"); sPrint(L"-l --license check and fix license header in all sources\n"); sPrint(L"-c --create create new files.\n"); sPrint(L"-D pattern write dependency graph of matching solutions.\n"); } else if(path) { if(Doc.ParseGlobal(proj)) { sPrintF(L"Scan for projects...\n"); if (Doc.ScanForSolutions(&Doc.RootPath)) { if(Doc.WriteFlag) sPrintF(L"Write Projects...\n"); Doc.WriteProjectsAndSolutions(); if(depPattern) { sPrintF(L"Write dependency graphs....\n"); Doc.WriteDependencyGraphs(depPattern); } sPrintF(L"%d Configurations.\n",Doc.GetConfigCount()); Doc.Cleanup(); } } } }
void Altona2::Main() { sPrintF("makeproject (altona2) v%d.%d\n",VERSION,REVISION); Document *Doc = new Document; // cmd line sString<64> buildname; sString<64> platformname; sInt platformset = 0; sInt buildset = 0; sInt pauseonerror = 0; int WriteMpx = 0; sCommandlineParser cmd; const sChar *platform = "win32"; const sChar *build = "vs2012"; if(sConfigPlatform == sConfigPlatformWin) { platform = "win32"; build = "vs2012"; Doc->RootPath = "c:/source/altona2"; } if(sConfigPlatform == sConfigPlatformLinux) { platform = "linux"; build = "make"; Doc->RootPath = "/home/chaos/svn3"; } if(sConfigPlatform == sConfigPlatformOSX) { platform = "osx"; build = "xcode4"; Doc->RootPath = "c:/svn3/altona2/"; } if(sConfigPlatform == sConfigPlatformIOS) { platform = "ios"; build = "xcode4"; Doc->RootPath = "c:/svn3/altona2/"; } if(sConfigPlatform == sConfigPlatformAndroid) { platform = "android"; build = "android"; Doc->RootPath = "c:/svn3/altona2/"; } int X86 = 0; Doc->X64 = 1; Doc->Manifest = 0; Doc->TargetProject = ""; cmd.AddHelp("?"); cmd.AddFile("r",Doc->RootPath,0,"root path (c:/svn3)"); cmd.AddFile("tr",Doc->TargetRootPath,0,"root path as seen from the target"); cmd.AddSwitch("c",Doc->CreateNewFiles,"create new files"); cmd.AddSwitch("cs",Doc->SvnNewFiles,"create new files and add to svn"); cmd.AddSwitch("forceinfo",Doc->ForceInfo,"force writing of additional files like info.plist"); cmd.AddSwitch("p",Doc->Pretend,"pretend"); cmd.AddString("build",buildname,&buildset,"one of: vs2013 vs2012 vs2010 vs2008 make xcode4 ndk"); cmd.AddString("platform",platformname,&platformset,"one of: win32 linux osx ios android"); cmd.AddSwitch("x64",Doc->X64,"add x64 projects to vs2012/13 (default)"); cmd.AddSwitch("x86",X86,"do not generate x64 projects for vs2012/13"); cmd.AddSwitch("pause",pauseonerror,"pause on error"); cmd.AddSwitch("mpx",WriteMpx,"write *.mpx.txt files"); cmd.AddSwitch("manifest",Doc->Manifest,"creates an AndroidManifest.xml (if not already exists)"); cmd.AddSwitch("nocygwinpath",Doc->CygwinPath,"Replace dos path c:\\ to /cygrdrive/. (default false) .only on Windows and build=ndk, platform=android."); cmd.AddFile("tp",Doc->TargetProject,0,"target project (only that project will be build/rebuild)"); if(!cmd.Parse()) { sSetExitCode(1); return; } if(Doc->X64 && X86) { sPrint("you may not specify -x64 and -x86 at the same time.\n"); sSetExitCode(1); return; } if(X86) Doc->X64 = 0; if(Doc->SvnNewFiles) Doc->CreateNewFiles = 1; if(Doc->TargetRootPath.IsEmpty()) Doc->TargetRootPath = Doc->RootPath; // process configuration file sBool ok = Doc->ScanConfig(); // figure out platform if(ok) { // figure out native platform if(platformset) platform = platformname; if(buildset) build = buildname; Doc->Platform = Doc->Platforms.Find([=](mPlatform *p){return p->Name==platform;}); if(Doc->Platform==0) { sPrintF("platform %s not found\n",platform); sPrintF("known platforms are:\n"); for(auto p : Doc->Platforms) sPrintF(" %s\n",p->Name); ok = 0; } Doc->OutputKind = OK_Error; if (sCmpStringI(build, "vs2013") == 0) Doc->OutputKind = OK_VS2013; else if (sCmpStringI(build, "vs2012") == 0) Doc->OutputKind = OK_VS2012; else if(sCmpStringI(build,"vs2010")==0) Doc->OutputKind = OK_VS2010; else if(sCmpStringI(build,"vs2008")==0) Doc->OutputKind = OK_VS2008; else if(sCmpStringI(build,"make")==0) Doc->OutputKind = OK_Make; else if(sCmpStringI(build,"xcode4")==0) Doc->OutputKind = OK_XCode4; else if(sCmpStringI(build,"ndk")==0) Doc->OutputKind = OK_NDK; if((Doc->OutputKind != OK_VS2012 && Doc->OutputKind != OK_VS2013) && Doc->X64) { Doc->X64 = 0; } if(Doc->OutputKind==OK_Error) { sPrintF("build system %s not found\n",build); sPrint("supported build systems:\n"); sPrint(" vs2013\n"); sPrint(" vs2012\n"); sPrint(" vs2010\n"); sPrint(" vs2008\n"); sPrint(" make\n"); sPrint(" xcode4\n"); sPrint(" ndk\n"); ok = 0; } } // scan mp files and make dependencies if(ok) ok = Doc->ScanMP(); if(ok) ok = Doc->FindDepends(); // output project files if(ok) { switch (Doc->OutputKind) { case OK_VS2013: case OK_VS2012: ok = Doc->OutputVS2012(); break; case OK_VS2010: ok = Doc->OutputVS2010(); break; case OK_VS2008: ok = Doc->OutputVS2008(); break; case OK_Make: ok = Doc->OutputMake(); break; case OK_XCode4: ok = Doc->OutputXCode4(); break; case OK_NDK: ok = Doc->OutputNDK(); break; default: ok = 0; break; } } // create new files (if requested) if(ok && Doc->CreateNewFiles) Doc->Create(); // some more outputs if(ok && WriteMpx) Doc->OutputMpx(); // done if(!ok) { sSetExitCode(1); if(pauseonerror) { sPrint("fail. press any key to continue\n"); sWaitForKey(); } else { sPrint("fail\n"); } } else { sPrint("success\n"); sPrintF("projects found: %d\n",Doc->Solutions.GetCount()); sPrintF("platforms found: %d\n",Doc->Platforms.GetCount()); sInt n = 0; for(auto p : Doc->Platforms) n += p->Configs.GetCount(); sPrintF("configurations found: %d (%d in %s)\n",n,Doc->Platform->Configs.GetCount(),Doc->Platform->Name); } delete Doc; }
void sCheck(const sChar *file,sInt line) { sPrintF(L"%s(%d) failed!\n",file,line); sDPrintF(L"%s(%d) failed!\n",file,line); ErrorCount++; }
void sCheckModule(const sChar *mod) { sPrintF(L"Testing %s...\n",mod); }
static void PrintKVRange(Range r) { while(!r.IsEmpty()) sPrintF(L"%s ",sPopHead(r).Value); sPrintF(L"\n"); }
static void PrintKVIndir(KVPair * const *arr) { for(sInt i=0; i<nTestInts; i++) sPrintF(L"%s%c",arr[i]->Value,(i==nTestInts-1) ? '\n' : ' '); }
int plotCellWave(int argc, char *argv[]) { Overture::start(argc,argv); // initialize Overture cout << "Type: `plotCellWave fileName [file.cmd]' to read the show file called fileName \n"; cout << " and optionally start reading a command file \n"; aString nameOfShowFile, commandFileName; nameOfShowFile=""; if( argc > 1 ) { nameOfShowFile=argv[1]; int l=nameOfShowFile.length()-1; if( l>2 && nameOfShowFile(l-3,l)==".cmd" ) { commandFileName=nameOfShowFile; nameOfShowFile=""; } else if( argc>2 ) commandFileName=argv[2]; } bool done=FALSE; // create a Graphics Interface GenericGraphicsInterface & ps = *Overture::getGraphicsInterface("CellWave visualization",TRUE); GraphicsParameters psp; // create an object that is used to pass parameters aString movieFileName; // By default start saving the command file called "plotStuff.cmd" aString logFile="out_plotCellWave.cmd"; ps.saveCommandFile(logFile); cout << "User commands are being saved in the file `" << (const char *)logFile << "'\n"; // read from a command file if given if( commandFileName!="" ) ps.readCommandFile(commandFileName); checkArrays("plotStuff: before loop"); aString *sequenceName = NULL; // this loop is used to look at more than one file while( !done ) { // cout << ">> Enter the name of the show file:" << endl; // cin >> nameOfShowFile; if( nameOfShowFile=="" ) ps.inputString(nameOfShowFile,">> Enter the name of the show file:"); ShowFileReader showFileReader(nameOfShowFile); int numberOfFrames=showFileReader.getNumberOfFrames(); int numberOfSolutions = max(1,numberOfFrames); int numberOfComponents; int numberOfSequences=showFileReader.getNumberOfSequences(); if( numberOfSequences>0 ) { delete [] sequenceName; sequenceName = new aString[numberOfSequences]; showFileReader.getSequenceNames(sequenceName,numberOfSequences); } CompositeGrid cg; // set up a function for contour plotting: Range all; realCompositeGridFunction u; char buff[120]; aString answer,answer2; aString menu0[]= { "!plotStuff", "contour", "line plot", "probe plot", "stream lines", "grid", ">sequence", "<next", "previous", ">choose a component", "<>choose a solution", "<next component", "previous component", "derived types", "movie", "movie and save", ">plot bounds", "set plot bounds", "use default plot bounds", "<check mappings with grid", "erase", "redraw", "open a new file", "file output", "help", "exit", "" }; aString help[]= { "contour : plot contours (surfaces)", "line plot : plot line cut across solution field", "probe plot : plot timehistory of field at probe locations", "stream lines : draw stream lines", "grid : plot the grid", "sequence : plot a sequence that has been saved in the show file", "next : plot the next solution of all items on the screen", "previous : plot the previous solution of all items on the screen" , "choose a component : plot a different component of all items on the screen", "choose a solution : plot a different solution of all items on the screen", "next component : plot the next component of all items on the screen", "previous component : plot the previous component of all items on the screen", "derived types : define new quantities such as vorticity, derivatives etc.", "movie : plot the next `n' solutions", "movie and save : plot the next `n' solutions and save each as a postscript file", "set plot bounds : specify fixed bounds for plotting. Useful for movies.", "use default plot bounds : let plotStuff determine the plotting bounds", "check mappings with grid : call the checkMapping routine", "erase : erase everything", "redraw : force a redraw (useful to call from command files)", "open a new file : open a new show file to read", "file output : output solutions to a file (ascii)", "help", "exit", "" }; int plotOptions = 0; bool plotNewFunction = FALSE; bool plotNewComponent= FALSE; bool movieMode=FALSE; int numberOfMovieFrames=numberOfFrames; int solutionNumber=1; int component = 0; int numberOfHeaderComments; const aString *headerComment; // This array holds the comments that should go in the plot showFileReader.getASolution(solutionNumber,cg,u); headerComment=showFileReader.getHeaderComments(numberOfHeaderComments); numberOfComponents=u.getComponentDimension(0); const int numberOfComponents0=numberOfComponents; // this next class knows how to form derived quantities such as vorticity, derivatives etc. DerivedFunctions derivedFunctions(showFileReader); // create the real menu by adding in the component names, these will appear as a // cascaded menu int chooseAComponentMenuItem; // menu[chooseAComponentMenuItem]=">choose a component" int chooseASolutionMenuItem; int numberOfSolutionMenuItems=0; int chooseASequenceMenuItem; int numberOfSequenceMenuItems=0; const int maxMenuSolutions=25; // cascade solution menu if there are more than this many solutions const int maximumNumberOfSolutionsInTheMenu=400; // stride through the solutions if there are more // than this many solutions. int solutionIncrement=1; // Here is the stride. const int maxMenuSequences=25; // cascade sequence menu if there are more than this many sequences const int maximumNumberOfSequencesInTheMenu=400; // stride through the sequences if there are more // than this many sequences. int sequenceIncrement=1; // Here is the stride. aString *menu=NULL; buildMainMenu( menu0, menu, u, sequenceName, numberOfSolutions, numberOfComponents, numberOfSequences, chooseAComponentMenuItem, chooseASolutionMenuItem, numberOfSolutionMenuItems, chooseASequenceMenuItem, numberOfSequenceMenuItems, maxMenuSolutions, maximumNumberOfSolutionsInTheMenu, solutionIncrement, maxMenuSequences, maximumNumberOfSequencesInTheMenu, sequenceIncrement ); psp.set(GI_TOP_LABEL,headerComment[0]); // set title psp.set(GI_TOP_LABEL_SUB_1,headerComment[1]); psp.set(GI_TOP_LABEL_SUB_2,headerComment[2]); if( cg.numberOfDimensions()==1 ) psp.set(GI_COLOUR_LINE_CONTOURS,TRUE); // set default prompt ps.appendToTheDefaultPrompt("plotCellWave>"); int menuItem=-1; for( int it=0; ; it++) { checkArrays("plotCellWave: in for(;;)"); if( it==0 && numberOfFrames<=0 ) answer="grid"; else menuItem=ps.getMenuItem(menu,answer); if( answer=="grid" ) { PlotIt::plot(ps, cg, psp); // plot the composite grid if( psp.getObjectWasPlotted() ) plotOptions |= 1; if( false ) { for( int grid=0; grid<cg.numberOfComponentGrids(); grid++ ) cg[grid].displayComputedGeometry(); } } else if( answer=="contour" ) { PlotIt::contour(ps, u, psp); // contour/surface plots if( psp.getObjectWasPlotted() & 1 ) plotOptions |= 2; if( psp.getObjectWasPlotted() & 2 ) // grid was also plotted plotOptions |= 1; } else if( answer=="line plot" ) { printf(" -- ERROR: line plot not available yet. --\n"); int oldPBGG = ps.getPlotTheBackgroundGrid(); int oldKAR = ps.getKeepAspectRatio(); const GridCollection & gc = *(u.gridCollection); RealArray xBound(2,3); PlotIt::getPlotBounds(gc,psp,xBound); // plot solution on lines that cut the 2D grid //contourCuts(gi, uGCF,psp ); PlotIt::contourCuts(ps, u, psp ); // Restore plotbackgroundgrid and keepAspectRatio after this call ps.setPlotTheBackgroundGrid(oldPBGG); psp.keepAspectRatio=oldKAR; ps.setKeepAspectRatio(psp.keepAspectRatio); // the boundingbox is messed up (set for 1D) after this call ps.setGlobalBound(xBound); // erase the labels and replot them ps.eraseLabels(psp); // replot the 3D object //plotObject = TRUE; //plotContours = TRUE; //PlotIt::contour(ps, u, psp); // contour/surface plots //if( psp.getObjectWasPlotted() & 1 ) // plotOptions |= 2; //if( psp.getObjectWasPlotted() & 2 ) // grid was also plotted // plotOptions |= 1; } else if( answer=="probe plot" ) { printf(" -- ERROR: probe plot not available yet. --\n"); // PlotIt::contour(ps, u, psp); // contour/surface plots //if( psp.getObjectWasPlotted() & 1 ) // plotOptions |= 2; //if( psp.getObjectWasPlotted() & 2 ) // grid was also plotted // plotOptions |= 1; } else if( answer=="stream lines" ) { PlotIt::streamLines(ps, u, psp); // streamlines if( psp.getObjectWasPlotted() ) plotOptions |= 4; } else if( answer=="derived types" ) { if( numberOfComponents>0 ) { aString *componentNames = new aString [numberOfComponents]; for( int n=0; n<numberOfComponents; n++ ) componentNames[n]=u.getName(n); derivedFunctions.update(ps,numberOfComponents,componentNames); delete [] componentNames; derivedFunctions.getASolution(solutionNumber,cg,u); numberOfComponents=numberOfComponents0+derivedFunctions.numberOfDerivedTypes(); buildMainMenu( menu0, menu, u, sequenceName, numberOfSolutions, numberOfComponents, numberOfSequences, chooseAComponentMenuItem, chooseASolutionMenuItem, numberOfSolutionMenuItems, chooseASequenceMenuItem, numberOfSequenceMenuItems, maxMenuSolutions, maximumNumberOfSolutionsInTheMenu, solutionIncrement, maxMenuSequences, maximumNumberOfSequencesInTheMenu, sequenceIncrement ); } else { printf("ERROR: no components are available\n"); } } else if( menuItem > chooseASequenceMenuItem && menuItem <= chooseASequenceMenuItem+numberOfSequenceMenuItems ) { // plot a sequence int sequenceNumber=menuItem-chooseASequenceMenuItem; if( numberOfSequences>maxMenuSequences ) { // adjust the sequence number when there are many sequences since we add in extra menu items // into the list. int extra = 1+ sequenceNumber/maxMenuSequences; extra=1+ (sequenceNumber-extra)/maxMenuSequences; sequenceNumber-=extra; // printf("menuItem-chooseASequenceMenuItem=%i, extra=%i sequenceNumber=%i\n", // menuItem-chooseASequenceMenuItem,extra,sequenceNumber); } sequenceNumber=(sequenceNumber-1)*sequenceIncrement; assert( sequenceNumber>=0 && sequenceNumber<numberOfSequences ); aString name; realArray time,value; const int maxComponentName1=25, maxComponentName2=1; aString componentName1[maxComponentName1], componentName2[maxComponentName2]; showFileReader.getSequence(sequenceNumber,name,time,value, componentName1,maxComponentName1, componentName2,maxComponentName2); // printf("sequence %i: name=%s\n",sequenceNumber,(const char*)name); // display(value,"value"); ps.erase(); psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,FALSE); psp.set(GI_TOP_LABEL_SUB_1,""); psp.set(GI_TOP_LABEL_SUB_2,""); Range all; PlotIt::plot(ps, time, value(all,all,value.getBase(2)), name, "t", componentName1, psp); psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,TRUE); ps.erase(); } else if( answer=="next" ) { solutionNumber = (solutionNumber % numberOfSolutions) +1; plotNewFunction=TRUE; } else if( answer=="previous" ) { solutionNumber = ((solutionNumber-2+numberOfSolutions) % numberOfSolutions) +1; plotNewFunction=TRUE; } else if( answer=="next component" ) { component= (component+1) % numberOfComponents; plotNewComponent=TRUE; } else if( answer=="previous component" ) { component= (component-1+numberOfComponents) % numberOfComponents; plotNewComponent=TRUE; } else if( menuItem > chooseAComponentMenuItem && menuItem <= chooseAComponentMenuItem+numberOfComponents ) { component=menuItem-chooseAComponentMenuItem-1 + u.getComponentBase(0); plotNewComponent=TRUE; // cout << "chose component number=" << component << endl; } else if( answer=="choose a component" ) { // *** not used *** Make a menu with the component names. If there are no names then use the component numbers aString *menu2 = new aString[numberOfComponents+1]; for( int i=0; i<numberOfComponents; i++ ) { menu2[i]=u.getName(u.getComponentBase(0)+i); if( menu2[i] == "" || menu2[i]==" " ) menu2[i]=sPrintF(buff,"component%i",u.getComponentBase(0)+i); } menu2[numberOfComponents]=""; // null string terminates the menu component = ps.getMenuItem(menu2,answer2); component+=u.getComponentBase(0); delete [] menu2; plotNewComponent=TRUE; } else if( menuItem > chooseASolutionMenuItem && menuItem <= chooseASolutionMenuItem+numberOfSolutionMenuItems ) { solutionNumber=menuItem-chooseASolutionMenuItem; if( numberOfSolutions>maxMenuSolutions ) { // adjust the solution number when there are many solutions since we add in extra menu items // into the list. int extra = 1+ solutionNumber/maxMenuSolutions; extra=1+ (solutionNumber-extra)/maxMenuSolutions; solutionNumber-=extra; // printf("menuItem-chooseASolutionMenuItem=%i, extra=%i solutionNumber=%i\n", // menuItem-chooseASolutionMenuItem,extra,solutionNumber); } solutionNumber=(solutionNumber-1)*solutionIncrement+1; plotNewFunction=TRUE; } else if( answer=="choose a solution" ) { // ***** not used **** Make a menu with the solution Names aString *menu2 = new aString[numberOfFrames+1]; for( int i=0; i<numberOfFrames; i++ ) menu2[i]=sPrintF(buff,"solution%i",i); menu2[numberOfFrames]=""; // null string terminates the menu solutionNumber = ps.getMenuItem(menu2,answer2)+1; delete [] menu2; plotNewFunction=TRUE; } else if( answer=="movie" || answer=="movie and save" ) { movieMode=TRUE; numberOfMovieFrames=numberOfFrames; ps.inputString(answer2,sPrintF(buff,"Enter the number of frames (total=%i)",numberOfFrames)); if( answer2 !="" && answer2!=" ") { sScanF(answer2,"%i",&numberOfMovieFrames); printf("number of frames = %i \n",numberOfMovieFrames); } if( answer=="movie and save" ) { ps.inputString(answer2,"Enter basic name for the ppm files (default=plot)"); if( answer2 !="" && answer2!=" ") movieFileName=answer2; else movieFileName="plot"; ps.outputString(sPrintF(buff,"pictures will be named %s0.ppm, %s1.ppm, ...", (const char*)movieFileName,(const char*)movieFileName)); } } else if( answer=="set plot bounds" ) { RealArray xBound(2,3); xBound=0.; xBound(1,Range(0,2))=1.; if( cg.numberOfDimensions()==2 ) ps.inputString(answer2,sPrintF(buff,"Enter bounds xa,xb, ya,yb ")); else ps.inputString(answer2,sPrintF(buff,"Enter bounds xa,xb, ya,yb, za,zb ")); if( answer2!="" ) sScanF(answer2,"%e %e %e %e %e %e",&xBound(0,0),&xBound(1,0),&xBound(0,1),&xBound(1,1), &xBound(0,2),&xBound(1,2)); ps.resetGlobalBound(ps.getCurrentWindow()); ps.setGlobalBound(xBound); psp.set(GI_PLOT_BOUNDS,xBound); // set plot bounds psp.set(GI_USE_PLOT_BOUNDS,TRUE); // use the region defined by the plot bounds } else if( answer=="use default plot bounds" ) { psp.set(GI_USE_PLOT_BOUNDS,FALSE); // use the region defined by the plot bounds } else if( answer=="check mappings with grid" ) { for( int grid=0; grid<cg.numberOfComponentGrids(); grid++ ) { if( cg[grid].mapping().mapPointer==NULL ) { cout << "ERROR: This grid has no mappings! \n"; break; } cg[grid].mapping().checkMapping(); } } else if( answer=="erase" ) { ps.erase(); plotOptions=0; } else if( answer=="redraw" ) { // force a redraw -- add to command files to force the drawing of the screen ps.redraw(TRUE); } else if( answer=="open a new file" ) { nameOfShowFile=""; // do this so we prompt for a new name break; } else if( answer=="file output" ) { fileOutput(ps, u); } else if( answer=="exit" ) { done=TRUE; break; } else if( answer=="help" ) { for( int i=0; help[i]!=""; i++ ) ps.outputString(help[i]); } else { cout << "unknown response, answer=[" << answer << "]\n"; ps.stopReadingCommandFile(); } if( movieMode ) { // ************** Movie Mode ******************* psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,TRUE); for( int frame=1; frame<=numberOfMovieFrames; frame++ ) { if( answer=="movie and save" ) { // save a ppm file psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::ppm); ps.outputString(sPrintF(buff,"Saving file %s%i.ppm",(const char*)movieFileName,frame-1)); ps.hardCopy( sPrintF(buff, "%s%i.ppm",(const char*)movieFileName,frame-1),psp); psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::postScript); } solutionNumber = (solutionNumber+numberOfSolutions) % numberOfSolutions +1; // showFileReader.getASolution(solutionNumber,cg,u); derivedFunctions.getASolution(solutionNumber,cg,u); headerComment=showFileReader.getHeaderComments(numberOfHeaderComments); numberOfComponents=u.getComponentDimension(0); psp.set(GI_TOP_LABEL,headerComment[0]); // set title psp.set(GI_TOP_LABEL_SUB_1,headerComment[1]); psp.set(GI_TOP_LABEL_SUB_2,headerComment[2]); ps.erase(); if( plotOptions & 1 ) PlotIt::plot(ps, cg, psp ); if( plotOptions & 2 ) PlotIt::contour(ps, u, psp ); if( plotOptions & 4 ) PlotIt::streamLines(ps, u, psp ); ps.redraw(TRUE); // ***** } if( answer=="movie and save" ) { // save a ppm file psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::ppm); ps.outputString(sPrintF(buff,"Saving file %s%i.ppm",(const char*)movieFileName,numberOfMovieFrames)); ps.hardCopy( sPrintF(buff, "%s%i.ppm",(const char*)movieFileName,numberOfMovieFrames),psp); psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::postScript); } psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,FALSE); movieMode=FALSE; } else if( plotNewFunction || plotNewComponent ) { if( plotNewFunction ) { // showFileReader.getASolution(solutionNumber,cg,u); derivedFunctions.getASolution(solutionNumber,cg,u); headerComment=showFileReader.getHeaderComments(numberOfHeaderComments); numberOfComponents=u.getComponentDimension(0); psp.set(GI_TOP_LABEL,headerComment[0]); // set title psp.set(GI_TOP_LABEL_SUB_1,headerComment[1]); psp.set(GI_TOP_LABEL_SUB_2,headerComment[2]); plotNewFunction=FALSE; } if( plotNewComponent ) { psp.set(GI_COMPONENT_FOR_CONTOURS,component); plotNewComponent=FALSE; } psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,TRUE); ps.erase(); if( plotOptions & 1 ) PlotIt::plot(ps, cg, psp ); if( plotOptions & 2 ) PlotIt::contour(ps, u, psp ); if( plotOptions & 4 ) PlotIt::streamLines(ps, u, psp ); psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,FALSE); } } // end for(;;) delete [] menu; ps.unAppendTheDefaultPrompt(); // reset defaultPrompt if( true ) { for( int grid=0; grid<cg.numberOfComponentGrids(); grid++ ) cg[grid].displayComputedGeometry(); } } // end while not done delete [] sequenceName; Overture::finish(); return 0; }
static int buildMainMenu( aString *menu0, aString *&menu, RealGridCollectionFunction & u, aString *sequenceName, const int & numberOfSolutions, const int & numberOfComponents, const int & numberOfSequences, int & chooseAComponentMenuItem, int & chooseASolutionMenuItem, int & numberOfSolutionMenuItems, int & chooseASequenceMenuItem, int & numberOfSequenceMenuItems, const int & maxMenuSolutions, const int & maximumNumberOfSolutionsInTheMenu, int & solutionIncrement, const int & maxMenuSequences, const int & maximumNumberOfSequencesInTheMenu, int & sequenceIncrement ) { // create the real menu by adding in the component names, these will appear as a // cascaded menu char buff[120]; chooseAComponentMenuItem=0; // menu[chooseAComponentMenuItem]=">choose a component" chooseASolutionMenuItem=0; numberOfSolutionMenuItems=0; chooseASequenceMenuItem=0; numberOfSequenceMenuItems=0; int numberOfMenuItems0=0; while( menu0[numberOfMenuItems0]!="" ) { numberOfMenuItems0++; } numberOfMenuItems0++; // const int maxMenuSolutions=25; // cascade solution menu if there are more than this many solutions // const int maximumNumberOfSolutionsInTheMenu=400; // stride through the solutions if there are more // than this many solutions. // int solutionIncrement=1; // Here is the stride. // const int maxMenuSequences=25; // cascade sequence menu if there are more than this many sequences // const int maximumNumberOfSequencesInTheMenu=400; // stride through the sequences if there are more // than this many sequences. // int sequenceIncrement=1; // Here is the stride. delete [] menu; menu = new aString [numberOfMenuItems0+numberOfComponents+numberOfSolutions +numberOfSolutions/maxMenuSolutions +numberOfSequences+numberOfSequences/maxMenuSequences +2]; int i=-1; for( int i0=0; i0<numberOfMenuItems0 ; i0++ ) { menu[++i]=menu0[i0]; if( menu[i]==">choose a component" ) { chooseAComponentMenuItem=i; for( int j=0; j<numberOfComponents; j++ ) { menu[++i]=u.getName(u.getComponentBase(0)+j); if( menu[i] == "" || menu[i]==" " ) menu[i]=sPrintF(buff,"component%i",u.getComponentBase(0)+j); } } else if( menu[i]=="<>choose a solution" ) { // make menu items that display all the solutions. If there many solutions then we cascade the solutions // into groups, each group has maxMenuSolutions entries chooseASolutionMenuItem=i; solutionIncrement=1; if( numberOfSolutions>maximumNumberOfSolutionsInTheMenu ) solutionIncrement=(numberOfSolutions+maximumNumberOfSolutionsInTheMenu-1)/maximumNumberOfSolutionsInTheMenu; int k=0; for( int j=0; j<numberOfSolutions; j+=solutionIncrement ) { if( numberOfSolutions>maxMenuSolutions && ( k % maxMenuSolutions==0) ) { if( j==0 ) menu[++i]=sPrintF(buff,">solutions %i to %i",j,j+maxMenuSolutions*solutionIncrement-1); else menu[++i]=sPrintF(buff,"<>solutions %i to %i",j, min(j+maxMenuSolutions*solutionIncrement-1,numberOfSolutions-1)); } menu[++i]=sPrintF(buff,"solution%i",j); k++; } if( numberOfSolutions>maxMenuSolutions ) menu[++i]="< "; numberOfSolutionMenuItems=i-chooseASolutionMenuItem; } else if( menu[i]==">sequence" ) { // make menu items that display all the sequences. If there many sequences then we cascade them into groups. chooseASequenceMenuItem=i; sequenceIncrement=1; if( numberOfSequences>maximumNumberOfSequencesInTheMenu ) sequenceIncrement=(numberOfSequences+maximumNumberOfSequencesInTheMenu-1)/maximumNumberOfSequencesInTheMenu; int k=0; for( int j=0; j<numberOfSequences; j+=sequenceIncrement ) { if( numberOfSequences>maxMenuSequences && ( k % maxMenuSequences==0) ) { if( j==0 ) menu[++i]=sPrintF(buff,">sequences %i to %i",j,j+maxMenuSequences*sequenceIncrement-1); else menu[++i]=sPrintF(buff,"<>sequences %i to %i",j, min(j+maxMenuSequences*sequenceIncrement-1,numberOfSequences-1)); } menu[++i]=sequenceName[j]; k++; } if( numberOfSequences>maxMenuSequences ) menu[++i]="< "; numberOfSequenceMenuItems=i-chooseASequenceMenuItem; } } return 0; }
void sMain() { sCommandlineParser cmd; sPrintF("asc2 v%d.%d\n",AppVersion,AppRevision); sString<sMaxPath> infile,objfile,cppfile,platformstring,dumpfile,headerfile; sInt dump=0; sInt isobjfile=0; sInt iscppfile=0; sInt platform=0; cmd.AddHelp("?"); cmd.AddFile("!i",infile,0,"input file (xxx.asc.txt)"); cmd.AddFile("!h",headerfile,0,"header file (xxx.hpp)"); cmd.AddFile("o",objfile,&isobjfile,"output object file (final_null_shell_win32/xxx.o)"); cmd.AddFile("cpp",cppfile,&iscppfile,"output cpp file (xxx.cpp)"); cmd.AddString("!p",platformstring,0,"platform: dx9 dx11 blank gl2 gles"); cmd.AddFile("d",dumpfile,&dump,"dump debug info into file"); if(!cmd.Parse()) { sSetExitCode(1); return; } if(isobjfile+iscppfile!=1) { sPrint("you must specify either the -cpp option or the -o options,\nnot both or none\n"); sSetExitCode(1); return; } sBool ok = 1; platform = 0; if(platformstring=="dx9") platform = sConfigRenderDX9; if(platformstring=="dx11") platform = sConfigRenderDX11; if(platformstring=="gl2") platform = sConfigRenderGL2; if(platformstring=="gles2") platform = sConfigRenderGLES2; if(platformstring=="null") platform = sConfigRenderNull; if(platform==0) { sPrintF("unknown platform %s\n",platformstring); sSetExitCode(1); return; } AltonaShaderLanguage::Document *doc = new AltonaShaderLanguage::Document; if(!doc->Parse(infile,platform,dump)) ok = 0; if(ok) { sSaveTextAnsi(headerfile,doc->GetHpp(),1); if(isobjfile) { // save output sString<sMaxPath> asmfile; asmfile.PrintF("%s.asm",objfile); sSaveTextAnsi(asmfile,doc->GetAsm(),0); sInt plat = sConfigPlatform; sBool bit64 = sConfig64Bit; if(sConfigRender==sConfigRenderGLES2) { plat = sConfigPlatformIOS; bit64 = 0; } if(!sAssemble(asmfile,objfile,plat,bit64)) { sPrint("yasm failed\n"); ok = 0; } } if(iscppfile) { sSaveTextAnsi(cppfile,doc->GetCpp(),0); } } if(dump) sSaveTextAnsi(dumpfile,doc->GetDump(),1); delete doc; if(ok) { sPrint("ok\n"); } else { sPrint("failed\n"); sSetExitCode(1); } }