void main(int argc, string argv[]) { string type, name; initparam(argv, defv); type = getparam("type"); name = getparam("name"); printf("type_length(\"%s\") = %d\n", type, type_length(type)); printf("type_name(\"%s\") = %s\n", type, type_name(type)); printf("type_base(\"%s\") = %s\n", type, type_base(type)); printf("type_fmt(\"%s\", TRUE) = %s\n", type, type_fmt(type, TRUE)); printf("type_fmt(\"%s\", FALSE) = %s\n", type, type_fmt(type, FALSE)); printf("name_type(\"%s\") = %s\n", name, name_type(name)); }
void nemo_main() { int seed; rmin = -0.5 * getdparam("size"); rmax = -rmin; nbody = getiparam("nbody"); sigma = getdparam("sigma"); seed = init_xrandom(getparam("seed")); zerocm = getbparam("zerocm"); mkcube(); writegalaxy(getparam("out"), getparam("headline")); free(btab); }
void readgsp(void) { stream istr; istr = stropen(getparam("gsp"), "r"); get_history(istr); gsp = ggsp = get_gsprof(istr); strclose(istr); if (! strnull(getparam("grav"))) { istr = stropen(getparam("grav"), "r"); get_history(istr); ggsp = get_gsprof(istr); strclose(istr); } }
void writemodel(void) { stream ostr; real tsnap = 0.0; string outfields[] = { PosTag, VelTag, MassTag, PhiTag, AuxTag, NULL }; if (! strnull(getparam("out"))) { if (strnull(getparam("auxvar"))) outfields[3] = NULL; ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tsnap, outfields); strclose(ostr); } }
nemo_main() { stream instr; real inv_rscale, e_pot, e_kin, tsnap; string times; Body *btab = NULL, *bp; int i, nbody, bits, nrscale, nvscale; real tmporb, tmpran, e_orb, e_ran; times = getparam("times"); instr = stropen(getparam("in"), "r"); get_history(instr); for (;;) { if (!get_tag_ok(instr, SnapShotTag)) break; /* done with work in loop */ get_snap(instr, &btab, &nbody, &tsnap, &bits); if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) { continue; /* just skip */ } if ((bits & TimeBit) == 0) tsnap = 0.0; else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ)) continue; /* now skip this snapshot */ dprintf (1,"Snapshot time=%f\n",tsnap); if ((bits & PotentialBit)) { e_pot = e_kin = e_orb = 0.0; for (bp = btab; bp < btab+nbody; bp++) { e_pot += Mass(bp) * Phi(bp); split_e (Mass(bp), Pos(bp), Vel(bp), &tmporb, &tmpran); e_kin += tmporb + tmpran; e_orb += tmporb; } } else error("snapstab: Potentials required\n"); e_kin *= 0.5; /* proper factor 0.5 */ e_pot *= 0.5; /* double count */ e_orb *= 0.5; if (e_pot > 0.0) error("positive total potential energy???"); if (e_kin < 0.0) error("negative total kinetic energy???"); printf("t= %g E=T+U: %g %g %g 2T+U= %g t_OP= %g\n", tsnap,e_pot+e_kin,e_kin,e_pot,2*e_kin+e_pot,e_orb/ABS(e_pot)); } }
void writeview(void) { static stream viewstr = NULL; real aspect, tempmat[4][4]; int i, j, k; if (viewstr == NULL) { viewstr = stropen(getparam("viewfile"), "w"); put_history(viewstr); } aspect = ((float) wscreen) / ((float) hscreen); for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { tempmat[i][j] = 0.0; for (k = 0; k < 4; k++) tempmat[i][j] += viewmat[i][k] * projmat[k][j]; } put_set(viewstr, "SnapView"); put_data(viewstr, "Time", RealType, &tnow, 0); put_data(viewstr, "Aspect", RealType, &aspect, 0); put_data(viewstr, "ViewMatrix", FloatType, tempmat, 4, 4, 0); put_data(viewstr, "MouseValues", FloatType, mouseval, NVALUES, 2, 0); put_tes(viewstr, "SnapView"); fflush(viewstr); }
int nemo_main() { int sock, mode = 0, direction = 0, port = getiparam("port"), buffer_size = getiparam("bufsize"); string rhost = NULL; bool Qreport = getbparam("report"); if (hasvalue("host_sender")) { mode = CONNECT; direction = RECEIVE; rhost = getparam("host_sender"); } else { mode = LISTEN; direction = SEND; } switch (mode) { case LISTEN: sock = do_listen(port, rhost); break; case CONNECT: sock = do_connect(port, rhost); break; default: error("bad mode"); break; } switch (direction) { case SEND: do_transfer(STDIN_FILENO, sock, buffer_size, FALSE, port); break; case RECEIVE: do_transfer(sock, STDOUT_FILENO, buffer_size, Qreport, port); break; default: error("bad direction"); break; } return 0; }
restorestate(string file) { stream str; string program, version; str = stropen(file, "r"); /* open state input file */ program = get_string(str, "program"); version = get_string(str, "version"); if (! streq(program, getargv0()) || /* check program, version */ ! streq(version, getparam("VERSION"))) printf("warning: state file may be outdated\n\n"); headline = get_string(str, "headline"); /* read control parameters */ get_data(str, "freq", RealType, &freq, 0); get_data(str, "tol", RealType, &tol, 0); get_data(str, "eps", RealType, &eps, 0); get_data(str, "fcells", RealType, &fcells, 0); options = get_string(str, "options"); get_data(str, "tstop", RealType, &tstop, 0); get_data(str, "freqout", RealType, &freqout, 0); get_data(str, "minor_freqout", RealType, &minor_freqout, 0); get_data(str, "tnow", RealType, &tnow, 0); /* read state variables */ get_data(str, "tout", RealType, &tout, 0); get_data(str, "minor_tout", RealType, &minor_tout, 0); get_data(str, "nstep", IntType, &nstep, 0); get_data(str, "rmin", RealType, rmin, NDIM, 0); get_data(str, "rsize", RealType, &rsize, 0); get_data(str, "nbody", IntType, &nbody, 0); bodytab = (bodyptr) allocate(nbody * sizeof(body)); if (bodytab == NULL) error("restorestate: not enuf memory\n"); get_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0); strclose(str); }
nemo_main () { setparams(); outstr = stropen(getparam("out"),"w"); cube_create(outstr); strclose(outstr); }
static void override_base_param(struct obs_x264 *obsx264, const char *param, char **preset, char **profile, char **tune) { char *name; const char *val; if (getparam(param, &name, &val)) { if (astrcmpi(name, "preset") == 0) { const char *valid_name = validate(obsx264, val, "preset", x264_preset_names); if (valid_name) { bfree(*preset); *preset = bstrdup(val); } } else if (astrcmpi(name, "profile") == 0) { const char *valid_name = validate(obsx264, val, "profile", x264_profile_names); if (valid_name) { bfree(*profile); *profile = bstrdup(val); } } else if (astrcmpi(name, "tune") == 0) { const char *valid_name = validate(obsx264, val, "tune", x264_tune_names); if (valid_name) { bfree(*tune); *tune = bstrdup(val); } } bfree(name); } }
char * getcgivar(char *cgistring, char *param) { register int i; char *result = NULL; char cgiinput[BUFFER_LEN]; static char result2[BUFFER_LEN]; char *nvpair; strcpy(cgiinput, cgistring); /** Change all plusses back to spaces **/ for (i = 0; cgiinput[i]; i++) if (cgiinput[i] == '+') cgiinput[i] = ' '; nvpair = strtok(cgiinput, "&"); while (nvpair) { char *test = getparam(nvpair); if (!vcSTRCASECMP(test, param)) { result = getvalue(nvpair); free((void *) test); break; } free((void *) test); nvpair = strtok(NULL, "&"); } unescape_url(result); strcpy(result2, result); free((void *) result); return (result2); }
int main(int argc, string argv[]) { stream outstr; int nmodel; real tzero = 0.0; initparam(argv, defv); layout_body(bodyfields, Precision, NDIM); nbody = getiparam("nbody"); nmodel = getiparam("nmodel"); if (nbody < 1 || nmodel < 1) error("%s: absurd value for nbody or nmodel\n", getprog()); btab = (bodyptr) allocate(nbody * SizeofBody); init_random(getiparam("seed")); outstr = stropen(getparam("out"), "w"); put_history(outstr); while (--nmodel >= 0) { plummodel(getdparam("mfrac")); if (getbparam("besort")) qsort(btab, nbody, SizeofBody, berank); if (getbparam("zerocm")) snapcenter(btab, nbody, MassField.offset); put_snap(outstr, &btab, &nbody, &tzero, bodyfields); fflush(outstr); } return (0); }
nemo_main() { real frame[N][N]; image f1; imageptr fp1, fp2; /* or image *fp1 */ stream instr,outstr; if (strcmp(getparam("mode"),"w")==0) { /* write test */ printf ("WRITING test (mode=w) foo.dat\n"); outstr = stropen ("foo.dat","w"); f1.frame = &frame[0][0]; /* compiler complained when = frame used ???? */ /* would be same as fp2->frame = ... */ fp1 = &f1; /* to initialize structures, we need pointer to them */ ini_matrix (&fp1,N,N); /* ini_matrix MUST have pointer to pointer to image */ fp2 = NULL; /* This is to check dynamic allocation of whole thing */ ini_matrix (&fp2,N,N); write_image (outstr,fp2); write_image (outstr,&f1); /* or fp1 */ strclose(outstr); exit(0); } else { printf ("READING test (mode<>w) foo.dat\n"); fp2=NULL; /* read test */ instr = stropen ("foo.dat","r"); while (read_image(instr,&fp2)) { printf ("Read image\n"); printf ("with MapValue(5,5)=%f\n",MapValue(fp2,5,5)); } strclose(instr); } }
writesnap(int n) { int cs = CSCode(Cartesian, NDIM, 2); static bool first = TRUE; if (n==0) return; if (first) { if (! streq(headline, "")) set_headline(headline); outstr = stropen(getparam("out"), "w"); put_history(outstr); first = FALSE; } put_set(outstr, SnapShotTag); put_set(outstr, ParametersTag); put_data(outstr, NobjTag, IntType, &n, 0); put_tes(outstr, ParametersTag); put_set(outstr, ParticlesTag); put_data(outstr, CoordSystemTag, IntType, &cs, 0); put_data(outstr, MassTag, RealType, pmass, n, 0); put_data(outstr, PhaseSpaceTag, RealType, pphase[0][0], n, 2, NDIM, 0); put_tes(outstr, ParticlesTag); put_tes(outstr, SnapShotTag); ntot += n; }
int pthread_getschedparam(pthread_t tid, int *policy, struct sched_param *param) { ulwp_t *ulwp; id_t cid; int error = 0; if ((ulwp = find_lwp(tid)) == NULL) { error = ESRCH; } else { cid = getparam(P_LWPID, ulwp->ul_lwpid, policy, param); if (cid == -1) { error = errno; } else if (*policy == ulwp->ul_policy && cid == ulwp->ul_cid && (*policy == SCHED_FIFO || *policy == SCHED_RR)) { /* * Return the defined priority, not the effective * priority from priority ceiling mutexes. */ param->sched_priority = ulwp->ul_pri; } else { if (*policy == SCHED_FIFO || *policy == SCHED_RR) ulwp->ul_rtclassid = cid; ulwp->ul_cid = cid; ulwp->ul_pri = param->sched_priority; membar_producer(); ulwp->ul_policy = *policy; } ulwp_unlock(ulwp, curthread->ul_uberdata); } return (error); }
int main(int argc, string argv[]) { string prog, itags[MaxBodyFields]; stream xstr; int nprof, nbody, nsamp; real *prof1, *prof2, rrange[2], tnow; bodyptr btab = NULL; initparam(argv, defv); layout_body(fields, Precision, NDIM); prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char))); xstr = execmap(prog); get_history(xstr); nprof = getiparam("nprof"); prof1 = (real *) allocate((2 + nprof) * sizeof(real)); prof2 = (real *) allocate((2 + nprof) * sizeof(real)); setrange(rrange, getparam("rrange")); nsamp = 0; while (get_snap(xstr, &btab, &nbody, &tnow, itags, FALSE)) { setprofile(prof1, prof2, nprof, rrange, btab, nbody); nsamp++; } if (unlink(prog) != 0) error("%s: can't unlink %s\n", getargv0(), prog); if (nsamp == 0) error("%s: no data in input\n", getargv0()); listdensity(prof1, prof2, nprof, rrange, nsamp); return (0); }
FITS *rawopen(string name, string status, int naxis, int *nsize) { FITS *f; int i,ndim,bitpix; f = (FITS *) allocate(sizeof(FITS)); if (streq(status,"old")){ /* handle an old file */ f->fd = stropen(name,"r"); ndim = nemoinpi(getparam("naxis"),nsize,naxis); if (ndim < 1) error("naxis= returns %d from parser",ndim); f->naxis = ndim; for (i=ndim; i<naxis; i++) nsize[i] = 1; for (i=0; i<ndim; i++) f->axes[i] = nsize[i]; for (i=ndim; i<MAXNAX; i++) f->axes[i] = 1; bitpix = getiparam("bitpix"); fit_setbitpix(bitpix); if (bitpix==8) f->type = TYPE_8INT; else if (bitpix==16) f->type = TYPE_16INT; else if (bitpix==32) f->type = TYPE_32INT; else if (bitpix==-32) f->type = TYPE_FLOAT; else error("Invalid bitpix: %d",bitpix); f->bytepix = ABS(bitpix)/8; f->status = STATUS_OLD; f->bscale = getdparam("bscale"); f->bzero = getdparam("bzero"); f->offset = getiparam("offset"); f->skip = f->offset; f->ncards = 0; } else error("Cannot rawopen %s as \"%s\"\n",name,status); fit_setblocksize( getiparam("blocksize") * getiparam("blocking") ); return f; }
void nemo_main () { setparams(); /* set par's in globals */ instr = stropen (infile, "r"); read_image (instr,&iptr); /* set some global paramters */ nx = Nx(iptr); ny = Ny(iptr); nz = Nz(iptr); xmin = Xmin(iptr); ymin = Ymin(iptr); zmin = Zmin(iptr); dx = Dx(iptr); dy = Dy(iptr); dz = Dz(iptr); if(hasvalue("gauss")) make_gauss_beam(getparam("dir")); outstr = stropen (outfile,"w"); if (hasvalue("wiener")) wiener(); else smooth_it(); write_image (outstr,iptr); strclose(instr); strclose(outstr); }
int main(int argc, string argv[]) { real rrange[2]; gsprof *gsp; stream ostr; initparam(argv, defv); setrange(rrange, getparam("rrange")); gsp = plumgsp(getdparam("mtot"), getdparam("a"), getiparam("npoint"), rrange[0], rrange[1]); ostr = stropen(getparam("out"), "w"); put_history(ostr); put_gsprof(ostr, gsp); strclose(ostr); return (0); }
int restorestate(string file) { stream str; string program, version; str = stropen(file, "r"); /* open state input file */ program = get_string(str, "program"); version = get_string(str, "version"); if (! streq(version, getparam("VERSION"))) printf("warning: state file may be outdated\n\n"); headline = get_string(str, "headline"); /* read control parameters */ get_data(str, "freq", RealType, &freq, 0); get_data(str, "mode", IntType, &mode, 0); get_data(str, "eps1", RealType, &eps1, 0); get_data(str, "eps2", RealType, &eps2, 0); options = get_string(str, "options"); get_data(str, "tstop", RealType, &tstop, 0); get_data(str, "minor_freqout", RealType, &minor_freqout, 0); get_data(str, "freqout", RealType, &freqout, 0); get_data(str, "tnow", RealType, &tnow, 0); /* read system state */ get_data(str, "minor_tout", RealType, &minor_tout, 0); get_data(str, "tout", RealType, &tout, 0); get_data(str, "nbody", IntType, &nbody, 0); bodytab = (Body *) allocate(nbody * sizeof(body)); get_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0); get_data(str, "qfld", AnyType, &qfld, sizeof(qfld), 0); strclose(str); }
int lua_engine::l_ioport_write(lua_State *L) { ioport_field *field = static_cast<ioport_field *>(getparam(L, 1, tname_ioport)); luaL_argcheck(L, lua_isnumber(L, 2), 2, "value expected"); field->set_value(lua_tointeger(L, 2)); return 0; }
int savestate(string file) { stream str; str = stropen(file, "a"); /* open state output file */ fseek(str, 0L, 0); /* rewind stream to origin */ put_string(str, "program", getargv0()); put_string(str, "version", getparam("VERSION")); put_string(str, "headline", headline); /* save control parameters */ put_data(str, "freq", RealType, &freq, 0); put_data(str, "mode", IntType, &mode, 0); put_data(str, "eps1", RealType, &eps1, 0); put_data(str, "eps2", RealType, &eps2, 0); put_string(str, "options", options); put_data(str, "tstop", RealType, &tstop, 0); put_data(str, "minor_freqout", RealType, &minor_freqout, 0); put_data(str, "freqout", RealType, &freqout, 0); put_data(str, "tnow", RealType, &tnow, 0); /* save state variables */ put_data(str, "minor_tout", RealType, &minor_tout, 0); put_data(str, "tout", RealType, &tout, 0); put_data(str, "nbody", IntType, &nbody, 0); put_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0); put_data(str, "qfld", AnyType, &qfld, sizeof(qfld), 0); strclose(str); }
nemo_main() { setparams(); read_data(); if (scanopt(method,"line")) { do_line(); } else if (scanopt(method,"ellipse")) { do_ellipse(); } else if (scanopt(method,"imageshift")) { do_imageshift(); } else if (scanopt(method,"plane")) { do_plane(); } else if (scanopt(method,"gauss1d")) { do_gauss1d(); } else if (scanopt(method,"gauss2d")) { do_gauss2d(); } else if (scanopt(method,"poly")) { do_poly(); } else if (scanopt(method,"area")) { do_area(); } else if (scanopt(method,"peak")) { do_peak(); } else if (scanopt(method,"zero")) { do_zero(); } else if (scanopt(method,"fourier")) { do_fourier(); } else error("fit=%s invalid; try [line,ellipse,imageshift,plane,gauss1d,gauss2d,poly,area,peak,zero,fourier]", getparam("fit")); if (outstr) strclose(outstr); }
setcolors() { stream cstr; int ncolors; real red[MAXCOL], green[MAXCOL], blue[MAXCOL]; char line[256]; if (hasvalue("color_table")) { cstr = stropen(getparam("color_table"), "r"); if(qsf(cstr)) { get_data(cstr, "ncolors", IntType, &ncolors, 0); get_data(cstr, "red", RealType, red, ncolors, 0); get_data(cstr, "green", RealType, green, ncolors, 0); get_data(cstr, "blue", RealType, blue, ncolors, 0); plpalette(red, green, blue, ncolors); } else { rewind(cstr); ncolors = 0; while (fgets(line,256,cstr)) { sscanf(line,"%g %g %g",&red[ncolors], &green[ncolors], &blue[ncolors]); ncolors++; } plpalette(red, green, blue, ncolors); } strclose(cstr); dprintf(0,"New colortable with %d entries\n",ncolors); } }
void nemo_main() { stream outstr; int nx, ny, nz; int ix, iy, iz; imageptr optr=NULL; /* pointer to image, needs to be NULL to force new */ real tmp, sum = 0.0; outstr = stropen(getparam("out"), "w"); nx = getiparam("nx"); ny = getiparam("ny"); nz = getiparam("nz"); dprintf(0,"Creating image cube (size : %d x %d x %d)\n",nx,ny,nz); create_cube(&optr,nx,ny,nz); for (iz=0; iz<nz; iz++) { for (iy=0; iy<ny; iy++) { for (ix=0; ix<nx/2; ix++) { CubeValue(optr,ix,iy,iz) = 0.0; } } } write_image(outstr, optr); }
nemo_main() { imageptr iptr=NULL, optr=NULL; string *filename; stream instr, outstr; int i, j, i0, j0, nfiles; int nx, ny, nx1, ny1, ix, iy, n; nx = hasvalue("nx") ? getiparam("nx") : 0; ny = hasvalue("ny") ? getiparam("ny") : 0; filename = burststring(getparam("in")," ,\n"); nfiles = xstrlen(filename,sizeof(string))-1; if (nx==0 && ny==0) error("Need at least one of nx= or ny="); else if (nx==0) { nx = nfiles/ny; dprintf(0,"nx=%d ny=%d nfiles=%d\n",nx,ny,nfiles); if (nfiles % ny) error("nfiles=%d/ny=%d does not divide evenly",nfiles,ny); } else if (ny==0) { ny = nfiles/nx; dprintf(0,"nx=%d ny=%d nfiles=%d\n",nx,ny,nfiles); if (nfiles % nx) error("nfiles=%d/nx=%d does not divide evenly",nfiles,nx); } for (iy=0, n=0; iy<ny; iy++) { for (ix=0; ix<nx; ix++, n++) { instr = stropen (filename[n],"r"); read_image (instr,&iptr); /* read image */ strclose(instr); /* close image file */ if (n==0) { nx1 = Nx(iptr); ny1 = Ny(iptr); create_image(&optr,nx*nx1,ny*ny1); } i0 = ix*nx1; j0 = iy*ny1; for (j=0; j<ny1; j++) for (i=0; i<nx1; i++) MapValue(optr,i+i0,j+j0) = MapValue(iptr,i,j); i++; } } outstr = stropen(getparam("out"),"w"); write_image(outstr,optr); strclose(outstr); }
void nemo_main(void) { stream instr, outstr; real tsnap; string times; Body *btab = NULL, *bp; float mass, pos[NDIM], vel[NDIM], t; int j, nbody, bits; instr = stropen(getparam("in"), "r"); /* open input file */ outstr = stropen(getparam("out"), "w"); /* open output file */ times = getparam("times"); get_history(instr); /* read history */ for(;;) { /* repeating until first or all times are read */ get_history(instr); if (!get_tag_ok(instr, SnapShotTag)) break; /* done with work */ get_snap(instr, &btab, &nbody, &tsnap, &bits); if (!streq(times,"all") && !within(tsnap,times,0.0001)) continue; /* skip work on this snapshot */ if ( (bits & PhaseSpaceBit) == 0) continue; /* skip work, only diagnostics here */ dprintf(0,"Converting time=%f to RV format",tsnap); fwrite(&nbody,sizeof(int),1,outstr); for (bp = btab; bp < btab+nbody; bp++) { mass = Mass(bp); fwrite(&mass,sizeof(float),1,outstr); } t = tsnap; fwrite(&t,sizeof(float),1,outstr); for (bp = btab; bp < btab+nbody; bp++) { for(j = 0; j < NDIM; j++) { pos[j] = Pos(bp)[j]; vel[j] = Vel(bp)[j]; } fwrite(pos,sizeof(float),NDIM,outstr); fwrite(vel,sizeof(float),NDIM,outstr); } } strclose(instr); strclose(outstr); }
void readgsp(void) { stream istr; istr = stropen(getparam("gsp"), "r"); get_history(istr); spheroid = gsp_read(istr); }
long getlparam(string name) { string val; for (val = ""; *val == '\0'; ) val = getparam(name); return (atol(val)); }
nemo_main() { anisorad = getdparam("anisorad"); mcutoff = getdparam("mcutoff"); ntab = MXTB; plummer(); writemodel(getparam("out")); }