int Main() override { if (_argc != 2) { fprintf(stderr, "Usage: %s <header file>\n", _argv[0]); return 1; } Fast_FileInputStream fileinput(_argv[1]); Fast_BufferedInputStream input(fileinput, 32768); Fast_HTTPHeaderParser headerParser(input); const char *headerName, *headerValue; while (headerParser.ReadHeader(headerName, headerValue)) { printf("Header name: \"%s\"\n", headerName); printf("Header value: \"%s\"\n", headerValue); printf("\n"); } char buffer[1024]; size_t bytesRead = 0; ssize_t lastRead; printf("------> Remaining data in file: <------\n"); while ((lastRead = input.Read(buffer, sizeof(buffer))) > 0) { fwrite(buffer, 1, lastRead, stdout); bytesRead += lastRead; } printf("------> End of remaining data <--------\n"); printf("Total remaining data: %u bytes\n", static_cast<unsigned int>(bytesRead)); return 0; }
int main() { int tpn,i; cls_st_ewma *ewma; double x[6][50]; ewma=build(41,0.5); fileinput(x); initialize(ewma,x[0]); for(i=0;i<6;i++){ update(ewma,x[i]); predict(ewma); printf("\n"); } getchar(); }
command() { double tval; int i,echeck; int pmin,pmax,pstep; while (echeck = getstring(": ")) { if (echeck == EOF) { fileinput(EOF); } else if (in[0] == '\0') { errprint(""); } else if (startsame(in,"cycle")) { cycle(); } else if (startsame(in,"clear")) { clear(); } else if (startsame(in,"coarticulation")) { getint(&coartflag); } else if (startsame(in,"rc")) { zarrays(); cycle(); } else if (startsame(in,"wordacts")) { scr_words(printmin,printmax,3,0,"MAX"); } else if (startsame(in,"wtacts")) { scr_words(printmin,printmax,3,0,"ALL"); } else if (startsame(in,"owtacts")) { getstring("word: "); scr_words(printmin,printmax,3,0,in); } else if (startsame(in,"phonacts")) { scr_phonemes(printmin,printmax,3,0); } else if (startsame(in,"featacts")) { scr_features(); } else if (startsame(in,"sfeatacts")) { getstring("fname: "); sfeatacts(in); } else if (startsame(in,"memo")) { getstring("string: "); strcpy(memo,in); } else if (startsame(in,"expr")) { setex(); } else if (startsame(in,"fcopt")) { getint(&fcflag); } else if (startsame(in,"fpcyc")) { getint(&fpcyc); } else if (startsame(in,"finput")) { fileinput(NONSTD); } else if (startsame(in,"inoise")) { getval(&inoise); } else if (startsame(in,"inspecs")) { getstring("File name (- = stdin): "); inspecs(in); } else if (startsame(in,"infeatures")) { getstring("File name: "); infeats(in); } /* NOT PRESENTLY OPERATIVE -- JLM 10-5-82 else if (startsame(in,"wsubset")) { wordsubset(); } */ else if (startsame(in,"test")) { getstring("test string: "); strcpy(memo,in); test(in); } else if (startsame(in,"topdown")) { topdown(); } else if (startsame(in,"output")) { setout(); } else if (startsame(in,"ofile")) { getstring("give filename (or - for none): "); setoutfile(in); } else if (in[0] == '?') { help(); } else if (startsame(in,"help")) { help(); } else if (startsame(in,"lexicon")) { getlex(); } else if (startsame(in,"params")) { getpars(); } else if (startsame(in,"quit")) { quit(); } else if (startsame(in,"decay")) { getdouble(decay,NLEVS,levlabs); } else if (startsame(in,"alpha")) { getdouble(alpha,NPARAMS,conlabs); } else if (startsame(in,"gamma")) { getdouble(ga,NLEVS,levlabs); } else if (startsame(in,"grace")) { getint(&grace); } else if (startsame(in,"rest")) { tval = rest[W]; getdouble(rest,NLEVS,levlabs); if (tval != rest[W]) { initialize(); } } else if (startsame(in,"fweight")) { getdouble(fweight,NCONTINS,contname); } else if (startsame(in,"pthresh")) { getdouble(pthresh,NLEVS,levlabs); } else if (startsame(in,"ngraph")) { newgraph(pmin,ng_max,pstep); } else if (startsame(in,"ngmax")) { getint(&ng_max); } else if (startsame(in,"ngwscale")) { getval(&ng_wscale); } else if (startsame(in,"ngsscale")) { getval(&ng_sscale); } else if (startsame(in,"ngpscale")) { getval(&ng_pscale); } else if (startsame(in,"nreps")) { getint(&nreps); } else if (startsame(in,"pfreq")) { getint(&printfreq); } else if (startsame(in,"rarate")) { getval(&rarate); } else if (startsame(in,"sumpr")) { scr_sum(pmin,pmax,pstep); } else if (startsame(in,"sinspec")) { sinspec(); } else if (startsame(in,"sfeatures")) { getstring("Filename: "); sfeatures(in); } else if (startsame(in,"dinspec")) { dinspec(); } else if (startsame(in,"sumopt")) { getint(&sumflag); } else if (startsame(in,"pmin")) { getint(&pmin); } else if (startsame(in,"pmax")) { getint(&pmax); } else if (startsame(in,"pstep")) { getint(&pstep); } else if (startsame(in,"min")) { getval(&min); } else if (startsame(in,"max")) { getval(&max); } else if (startsame(in,"windowcent")) { getval(&windowcent); } else if (startsame(in,"wbase")) { getval(&wbase); } else if (startsame(in,"wgraph")) { wgraph(pmin,ng_max,pstep); } else if (startsame(in,"wchange")) { getval(&wchange); } else if (startsame(in,"wgain")) { getval(&wgain); } else if (startsame(in,"wramp")) { getval(&wramp); } else if (startsame(in,"imax")) { getval(&imax); } else if (startsame(in,"sscale")) { getval(&sscale); } else if (startsame(in,"nsscale")) { getval(&nsscale); } else if (startsame(in,"freqscale")) { tval = fscale; getval(&fscale); if (tval != fscale) { initialize(); } } else if (startsame(in,"abort")) { abort(); /* to get a core dump for sdb */ } else { errprint("Unrecognized request: For help type ?."); if (infp != stdin) fileinput(STD); } wait(0); } }
bool initializeFluidGiantFluctuations(){ double v0, k; double vx, vy, vz; int fx, fy, fz; double dc; vx = 0.; vy = 0.; vz = 0.; dc = soretCoefficient * gradTemperature * ly; if((massSpecies0==0)||(massSpecies1==0)||(diffusion==0)){ cout << "(massSpecies0==0)||(massSpecies1==0)||(diffusion==0)" << endl; return 0; } if(loadFluid==0){ for(int j=0;j<ncells;j++){ int i; fx = j % mx; fy = (j % (my*mx)) / mx; fz = j / (mx*my); //go to index tanking into account ghost cells fx++; fy++; fz++; i = fx + fy*mxt + fz*mxt*myt; cDensity[i] = densfluid; if(gradTemperature==0) { c[i] = concentration; } else{ c[i] = concentration * dc * exp(-dc*(fy-0.5)/double(my))/(1-exp(-dc)); //The next line fixed the init bias for //<c>=0.018, h=0.1, mx=128, my=32, gradT=174. c[i] += -4.4797e-7 + 1.1985e-6 * ((fy-0.5)*0.1/double(my)) + 6.8284e-4 * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) - 1.6661e-2 * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) + 0.16417 * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) - 0.6038 * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)) * ((fy-0.5)*0.1/double(my)); //c[i] += -4.918e-7 + 1.2248e-5*((fy-0.5)/double(my)*0.1) // + 7.8826e-6 * ((fy-0.5)/double(my)*0.1)*((fy-0.5)/double(my)*0.1) // - 5.8778e-4 * ((fy-0.5)/double(my)*0.1)*((fy-0.5)/double(my)*0.1)*((fy-0.5)/double(my)*0.1); //c[i] = concentration; } //cMass[i] = cDensity[i] * cVolume; //c[i].pressure = pressure(c[i].density); switch(initfluid){ case 0: //****************************************** //Fluido con velocidad cero //****************************************** cvx[i] = vx0; cvy[i] = vy0; cvz[i] = vz0; break; case 1: //!************************************************* //! Fluido en equilibrio a T != 0 //!************************************************* cvx[i] = sqrt(temperature/(cDensity[i]*cVolume))*gauss(); cvy[i] = sqrt(temperature/(cDensity[i]*cVolume))*gauss(); cvz[i] = sqrt(temperature/(cDensity[i]*cVolume))*gauss(); if(fy!=(myt-2)){ vx += cvx[i]; vy += cvy[i]; vz += cvz[i]; } else{ vx += cvx[i]; vz += cvz[i]; } break; case 2: //!************************************************* //! Onda transversal y temperatura 0 //! vx = v0 sin(kz)exp(-nuk**2t) //!************************************************* v0 = 2.04; k = 2*pi/lz; cvx[i] = v0*sin(k*crz[i]); cvy[i] = 0.; cvz[i] = 0.; break; case 3: //!************************************************* //! Onda longitudinal y temperatura 0 //! vz = v0 sin(kz)cos(c_t k t)exp(-gamma_t k**2 t //! c_t = velocidad del sonido //! gamma_t = absorción isoterma del sonido //!************************************************* v0 = 0.0204; k = 2*pi/lz; cvx[i] = 0.; cvy[i] = 0.; cvz[i] = v0 * sin(k*crz[i]); break; case 4: //c[0].density = 1.2; //c[0].mass = c[0].density * c[0].volume; cvx[i] = 0.00000001; cvy[i] = 0.; cvz[i] = 0.; //vx += cvx[i]; //vy += cvy[i]; //vz += cvz[i]; /*c[555].v[0] = 2.; c[555].v[1] = 2.; c[555].v[2] = 2.; c[0] .v[0] = -2.; c[0] .v[1] = -2.; c[0] .v[2] = -2.;*/ //c[0].v[0] = 10.; break; default: for(int i=0;i<ncells;i++){ cvx[i] = 0; cvy[i] = 0; cvz[i] = 0; } break; } //c[i].p[0] = c[i].v[0] * c[i].mass; //c[i].p[1] = c[i].v[1] * c[i].mass; //c[i].p[2] = c[i].v[2] * c[i].mass; } if(initfluid == 1){ vx = vx/double(ncells); vy = vy/double((ncells-mx*mz)); vz = vz/double(ncells); for(int j=0;j<ncells;j++){ int i; fx = j % mx; fy = (j % (my*my)) / mx; fz = j / (mx*my); //go to index tanking into account ghost cells fx++; fy++; fz++; i = fx + fy*mxt + fz*mxt*myt; if(fy!=(myt-2)){ cvx[i] = cvx[i] - vx + vx0; cvy[i] = cvy[i] - vy + vy0; cvz[i] = cvz[i] - vz + vz0; } else{ cvx[i] = cvx[i] - vx + vx0; cvz[i] = cvz[i] - vz + vz0; } } vx=0;vy=0;vz=0; for(int j=0;j<ncells;j++){ int i; fx = j % mx; fy = (j % (my*my)) / mx; fz = j / (mx*my); //go to index tanking into account ghost cells fx++; fy++; fz++; i = fx + fy*mxt + fz*mxt*myt; if(fy!=(myt-2)){ vx += cvx[i]; vy += cvy[i]; vz += cvz[i]; } else{ vx += cvx[i]; vz += cvz[i]; } } cout << "KKKK " << vx << " " << vy << " " << vz << endl; } } else { ifstream fileinput(loadFluidFile.c_str()); string word; getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); fileinput >> word >> densfluid; fileinput >> word >> word >> pressurea0 >> pressurea1 >> pressurea2; getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); cout << word << endl; for(int i=0;i<ncells;i++) { fileinput >> cDensity[i]; fileinput >> cvx[i] >> cvy[i] >> cvz[i]; //c[i].mass = c[i].density * c[i].volume; //cout << i << " " << c[i].density << endl; } fileinput.close(); } return 1; }
bool initializeFluidBinaryMixtureWall(){ double v0, k; double vx, vy, vz; int fx, fy, fz; vx = 0.; vy = 0.; vz = 0.; if((massSpecies0==0)||(massSpecies1==0)||(diffusion==0)){ cout << "(massSpecies0==0)||(massSpecies1==0)||(diffusion==0)" << endl; return 0; } if(loadFluid==0){ for(int j=0;j<ncells;j++){ int i; fx = j % mx; fy = (j % (my*mx)) / mx; fz = j / (mx*my); //go to index tanking into account ghost cells fx++; fy++; fz++; i = fx + fy*mxt + fz*mxt*myt; cDensity[i] = densfluid; //c[i] = concentration; c[i] = cWall0 + ((cWall1-cWall0)/double(my)) * (fy-0.5); //cMass[i] = cDensity[i] * cVolume; //c[i].pressure = pressure(c[i].density); switch(initfluid){ case 0: //****************************************** //Fluido con velocidad cero //****************************************** cvx[i] = vx0; cvy[i] = vy0; cvz[i] = vz0; break; case 1: //!************************************************* //! Fluido en equilibrio a T != 0 //!************************************************* cvx[i] = sqrt(temperature/(cDensity[i]*cVolume))*gauss(); cvy[i] = sqrt(temperature/(cDensity[i]*cVolume))*gauss(); cvz[i] = sqrt(temperature/(cDensity[i]*cVolume))*gauss(); if(fy!=(myt-2)){ vx += cvx[i]; vy += cvy[i]; vz += cvz[i]; } else{ vx += cvx[i]; vz += cvz[i]; } break; case 2: //!************************************************* //! Onda transversal y temperatura 0 //! vx = v0 sin(kz)exp(-nuk**2t) //!************************************************* v0 = 2.04; k = 2*pi/lz; cvx[i] = v0*sin(k*crz[i]); cvy[i] = 0.; cvz[i] = 0.; break; case 3: //!************************************************* //! Onda longitudinal y temperatura 0 //! vz = v0 sin(kz)cos(c_t k t)exp(-gamma_t k**2 t //! c_t = velocidad del sonido //! gamma_t = absorción isoterma del sonido //!************************************************* v0 = 0.0204; k = 2*pi/lz; cvx[i] = 0.; cvy[i] = 0.; cvz[i] = v0 * sin(k*crz[i]); break; case 4: //c[0].density = 1.2; //c[0].mass = c[0].density * c[0].volume; cvx[i] = 0.00000001; cvy[i] = 0.; cvz[i] = 0.; //vx += cvx[i]; //vy += cvy[i]; //vz += cvz[i]; /*c[555].v[0] = 2.; c[555].v[1] = 2.; c[555].v[2] = 2.; c[0] .v[0] = -2.; c[0] .v[1] = -2.; c[0] .v[2] = -2.;*/ //c[0].v[0] = 10.; break; default: for(int i=0;i<ncells;i++){ cvx[i] = 0; cvy[i] = 0; cvz[i] = 0; } break; } //c[i].p[0] = c[i].v[0] * c[i].mass; //c[i].p[1] = c[i].v[1] * c[i].mass; //c[i].p[2] = c[i].v[2] * c[i].mass; } if(initfluid == 1){ vx = vx/double(ncells); vy = vy/double((ncells-mx*mz)); vz = vz/double(ncells); for(int j=0;j<ncells;j++){ int i; fx = j % mx; fy = (j % (my*my)) / mx; fz = j / (mx*my); //go to index tanking into account ghost cells fx++; fy++; fz++; i = fx + fy*mxt + fz*mxt*myt; if(fy!=(myt-2)){ cvx[i] = cvx[i] - vx + vx0; cvy[i] = cvy[i] - vy + vy0; cvz[i] = cvz[i] - vz + vz0; } else{ cvx[i] = cvx[i] - vx + vx0; cvz[i] = cvz[i] - vz + vz0; } } vx=0;vy=0;vz=0; for(int j=0;j<ncells;j++){ int i; fx = j % mx; fy = (j % (my*my)) / mx; fz = j / (mx*my); //go to index tanking into account ghost cells fx++; fy++; fz++; i = fx + fy*mxt + fz*mxt*myt; if(fy!=(myt-2)){ vx += cvx[i]; vy += cvy[i]; vz += cvz[i]; } else{ vx += cvx[i]; vz += cvz[i]; } } cout << "KKKK " << vx << " " << vy << " " << vz << endl; } } else { ifstream fileinput(loadFluidFile.c_str()); string word; getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); fileinput >> word >> densfluid; fileinput >> word >> word >> pressurea0 >> pressurea1 >> pressurea2; getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); getline(fileinput,word); cout << word << endl; for(int i=0;i<ncells;i++) { fileinput >> cDensity[i]; fileinput >> cvx[i] >> cvy[i] >> cvz[i]; //c[i].mass = c[i].density * c[i].volume; //cout << i << " " << c[i].density << endl; } fileinput.close(); } return 1; }
command() { float tval; int i,echeck; int pmin,pmax,pstep; char tbuf[20]; while (echeck = getstring(": ")) { if (echeck == EOF) { fileinput(STD); } else if (startsame(in,"cycle")) { cycle(); } else if (startsame(in,"coarticulation")) { ttyprint("coarticulation %s: change? ",(coartflag ? "ON":"OFF")); fscanf(infp,"%s",in); if(in[0] == 'n') continue; coartflag = 1 - coartflag; } else if (startsame(in,"rc")) { printf("reset and cycle\n"); zarrays(); cycle(); } else if (startsame(in,"wordacts")) { printwords(printmin,printmax,3,stdout); if (outfile) printwords(printmin,printmax,3,outfile); } else if (startsame(in,"wtacts")) { printwt(printmin,printmax,3,stdout); if (outfile) printwt(printmin,printmax,3,outfile); } else if (startsame(in,"owtacts")) { getstring("word: "); strcpy(tbuf,in); printonewt(tbuf,printmin,printmax,3,stdout); if (outfile) printonewt(tbuf,printmin,printmax,3,outfile); } else if (startsame(in,"phonacts")) { printphonemes(printmin,printmax,3,stdout); if (outfile) printphonemes(printmin,printmax,3,outfile); } else if (startsame(in,"featacts")) { printf("feature activations - give min,max,step: "); scanf("%d %d %d",&pmin,&pmax,&pstep); printfeatures(pmin,pmax,pstep,stdout); if (outfile) printfeatures(pmin,pmax,pstep,outfile); } else if (startsame(in,"expression")) { setex(); } else if (startsame(in,"fileinput")) { fileinput(NONSTD); } else if (startsame(in,"inspecs")) { ttyprint("File name (- = stdin): "); fscanf(infp,"%s",in); inspecs(in); } else if (startsame(in,"infeatures")) { ttyprint("File name: "); fscanf(infp,"%s",in); infeats(in); } /* NOT PRESENTLY OPERATIVE -- JLM 10-5-82 else if (startsame(in,"wsubset")) { wordsubset(); } */ else if (startsame(in,"test")) { getstring("test string: "); test(in); } else if (startsame(in,"topdown")) { topdown(); } else if (startsame(in,"output")) { setout(); } else if (startsame(in,"ofile")) { getstring("give filename (or - for none): "); setoutfile(in); } else if (in[0] == '!') { system(&in[1]); } else if (in[0] == '?') { help(); } else if (startsame(in,"help")) { help(); } else if (startsame(in,"lexicon")) { getlex(); } else if (startsame(in,"parameters")) { getpars(); } else if (startsame(in,"quit")) { quit(); } else if (startsame(in,"decay")) { ttyprint ("decay values:\n"); getfloat(decay,NLEVS,"F","P","W"); } else if (startsame(in,"alpha")) { ttyprint ("alpha values:\n"); getfloat(alpha,NPARAMS, "IF","FF","FP","PP","PW","WW","WP","PF","PFC"); } else if (startsame(in,"gamma")) { ttyprint ("gamma values:\n"); getfloat(ga,NLEVS,"F","P","W"); } else if (startsame(in,"grace")) { ttyprint ("grace %s: change? ",(grace ? "ON" : "OFF")); fscanf(infp,"%s",in); if (in[0] == 'n') continue; grace = 1 - grace; } else if (startsame(in,"rest")) { tval = rest[W]; ttyprint ("rest values:\n"); getfloat(rest,NLEVS,"F","P","W"); if (tval != rest[W]) { initialize(); } } else if (startsame(in,"fweight")) { ttyprint ("fweight values:\n"); getfloat(fweight,NCONTINS, "POW","PIT","VOI","ABT","DIF","ACU","CON","LWS", "MDS", "HIS","FT1","FT2","FT3","FT4","FT5","FT6"); } else if (startsame(in,"pthresh")) { ttyprint ("pthresh values:\n"); getfloat(pthresh,NLEVS,"F","P","W"); } else if (startsame(in,"nreps")) { ttyprint ("%d nreps: change? ",nreps); fscanf(infp,"%s",in); if (in[0] == 'n') continue; sscanf(in,"%d",&nreps); } else if (startsame(in,"pfreq")) { ttyprint ("%d pfreq: change? ",printfreq); fscanf(infp,"%s",in); if (in[0] == 'n') continue; sscanf(in,"%d",&printfreq); } else if (startsame(in,"summarypr")) { ttyprint("give min, max, and step: "); fscanf(infp,"%d %d %d",&pmin,&pmax,&pstep); summarypr(pmin,pmax,pstep,stdout); if (outfile) summarypr(pmin,pmax,pstep,outfile); } else if (startsame(in,"spointers")) { qsort(wordptr,nwptrs,sizeof(struct word *),ecomp); } else if (startsame(in,"sinspec")) { sinspec(); } else if (startsame(in,"sfeatures")) { ttyprint("file name: "); fscanf(infp,"%s",in); sfeatures(in); } else if (startsame(in,"dinspec")) { dinspec(); } else if (startsame(in,"acoustinput")) { ttyprint("give min, max, and step: "); fscanf(infp,"%d %d %d",&pmin,&pmax,&pstep); acoustinput(pmin,pmax,pstep,stdout); if (outfile) acoustinput(pmin,pmax,pstep,outfile); } else if (startsame(in,"sumopt")) { ttyprint ("summaryprint %s: change? ",(sumflag ? "ON" : "OFF")); fscanf(infp,"%s",in); if (in[0] == 'n') continue; sumflag = 1 - sumflag; } else if (startsame(in,"echooutput")) { ttyprint ("echooutput %s: change? ",(echoflag ? "ON" : "OFF")); fscanf(infp,"%s",in); if (in[0] == 'n') continue; echoflag = 1 - echoflag; } else if (startsame(in,"min")) { ttyprint ("min = "); getval(&min); } else if (startsame(in,"max")) { ttyprint ("max = "); getval(&max); } else if (startsame(in,"windowcent")) { ttyprint ("windowcent = "); getval(&windowcent); } else if (startsame(in,"wbase")) { ttyprint ("wbase = "); getval(&wbase); } else if (startsame(in,"wchange")) { ttyprint ("wchange = "); getval(&wchange); } else if (startsame(in,"wgain")) { ttyprint ("wgain = "); getval(&wgain); } else if (startsame(in,"wramp")) { ttyprint ("wramp = "); getval(&wramp); } else if (startsame(in,"imax")) { ttyprint ("imax = "); getval(&imax); } else if (startsame(in,"freqscale")) { ttyprint ("freqscale = "); tval = fscale; getval(&fscale); if (tval != fscale) { initialize(); } } else if (startsame(in,"abort")) { abort(); /* to get a core dump for sdb */ } else { printf("Unrecognized request: For help type ?.\n"); if (infp != stdin) fileinput(STD); } wait(0); } }