nemo_main() { int i, j, k, naxes[3], handle, naxis; real *data; char fmt[20]; strcpy(fmt, getparam("fmt")); strcat(fmt, " "); if (hasvalue("in")) { xyopen(&handle,getparam("in"),"r",3,naxes); dprintf(0,"Image size: %d * %d * %d\n",naxes[0],naxes[1],naxes[2]); data = (real *) allocate(sizeof(real)*naxes[0]); for(k=0; k<naxes[2];k++) { xysetpl(handle,1,&k); printf("plane: %d\n",k); for(j=naxes[1]-1;j>=0; j--) { xyread(handle,j,data); printf("%d:",j); for (i=0; i<naxes[0]; i++) printf(fmt,data[i]); printf("\n"); } } xyclose(handle); } else if (hasvalue("out")) { naxis = nemoinpi(getparam("size"),naxes,3); if (naxis<1) error("Bad format n=%s\n",getparam("size")); for (i=naxis; i<3; i++) naxes[i] = 1; xyopen(&handle,getparam("out"),"w",naxis,naxes); data = (real *) allocate(sizeof(real)*naxes[0]); for(k=0; k<naxes[2];k++) { xysetpl(handle,1,&k); for(j=0; j<naxes[1]; j++) { for (i=0; i<naxes[0]; i++) data[i] = i+10*j+100*k; xywrite(handle,j,data); } } xyclose(handle); } else warning("Either in= or out= needs to used"); }
extern int xycpt(xycpt_opt_t opt) { fill_stack_t* xy = xyread(opt.file.input, opt); int err = 0; if (!xy) { btrace("failed to read data from %s", (opt.file.input ? opt.file.input : "<stdin>")); err++; } else { cpt_t* cpt = cpt_new(); if (cpt == NULL) { btrace("failed to get new cpt strcture"); err++; } else { cpt->model = model_rgb; cpt->fg.type = cpt->bg.type = cpt->nan.type = fill_colour; cpt->bg.u.colour.rgb = opt.bg; cpt->fg.u.colour.rgb = opt.fg; cpt->nan.u.colour.rgb = opt.nan; if (opt.file.input) cpt->name = cptname(opt.file.input, "*"); if (xycpt_convert(xy, cpt, opt) != 0) { btrace("failed to convert data"); err++; } else { if (opt.verbose) { int n = cpt_nseg(cpt); printf("converted to %i segment rgb-spline\n", n); } if (cpt_write(opt.file.output, cpt) != 0) { btrace("failed to write palette to %s", (opt.file.output ? opt.file.output : "<stdout>")); err++; } } cpt_destroy(cpt); } fill_stack_destroy(xy); } return err; }