/* @(#)bdf2ps.c 17.1.1.1 (ES0-DMD) 01/25/02 18:00:46 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, MA 02139, USA. Correspondence concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .COPYRIGHT (c) 1997 European Southern Observatory .LANGUAGE C .IDENT bdf2ps.c .AUTHOR Preben J. Grosbol [ESO/IPG] .KEYWORDS MIDAS bdf format, PostScript, conversion .PURPOSE Convert MIDAS bdf files to PostScript format .ENVIRON UNIX, MIDAS .VERSION 1.0 1992-Jun-23 : Creation, PJG .VERSION 1.1 1992-Oct-05 : Better LUT's, PJG .VERSION 1.2 1993-Apr-14 : LUT tables and true color, PJG .VERSION 1.3 1993-Jul-01 : add frame size and origin, PJG .VERSION 1.4 1993-Nov-12 : Correct error + add options, PJG .VERSION 1.5 1993-Nov-25 : Separate X/Y scales, PJG .VERSION 1.6 1994-Mar-18 : Correct error in scaling, PJG .VERSION 1.7 1994-May-03 : Add option for frame box, PJG .VERSION 1.8 1994-May-19 : Explicit check of SC error returns, PJG .VERSION 1.9 1994-Oct-09 : Write usage on wrong option, PJG .VERSION 1.91 1997-Feb-18 : Explicit cast in SCFMAP/GET, PJG .VERSION 1.95 1997-May-15 : Initiate pointers to NULL, PJG .VERSION 2.00 1998-Feb-27 : Use 'strtok' and add line/arc draw, PJG .VERSION 2.10 1998-Mar-03 : Correct algorithm for neg. step size, PJG ------------------------------------------------------------------------*/ #include /* Standard Library definitions */ #include /* Standard I/O definitions */ #include /* Standard Mathmatical library */ #include /* Standard string definitions */ #include /* Time library */ #include /* MIDAS OS-definitions */ #include /* MIDAS definitions */ #include /* Data formats */ #include /* FITS definitions */ #include /* FITS Table definitions */ #define MXPARM 32 /* Max. no. of parameters */ #define MXNAME 64 /* Max size of name string */ #define MXLINE 128 /* Max. size of print line */ #define MXITF 256 /* Max size of LUT/ITT tables */ #define PSPAGE "A4P" /* Default page format */ #define PSFONT "Helvetica" /* Standard PS font used */ #define PSNAME "psimage.ps" /* Default name for output file */ typedef struct { char *name; /* Name of page format */ double xsize; /* Total size of page in X (cm) */ double ysize; /* Total size of page in Y (cm) */ double xmar; /* Page margin in X (cm) */ double ymar; /* Page margin in Y (cm) */ double angle; /* Angle of page ref. Portait */ } PAGE; static PAGE page[] = { {"A4P", 21.00, 29.73, 1.0, 1.0, 0.0}, {"A4L", 21.00, 29.73, 1.0, 1.0, 90.0}, {"A3P", 29.73, 42.00, 1.0, 1.0, 0.0}, {"A3L", 29.73, 42.00, 1.0, 1.0, 90.0}, {"S4P", 21.00, 29.73, 2.0, 3.0, 0.0}, {"S4L", 21.00, 29.73, 2.0, 3.0, 90.0}, {(char *) 0, 0.0, 0.0, 0.0, 0.0, 0.0} }; /* Definition of parameter list */ static char *plist[] = {"i+:Input file", "o+:Output file", "l+:File list", "p+:Page format", "r+:Resolution per cm", "c+:Color LUT table", "s+:Xscale,Yscale", "z+:Z-cut levels (low,high)", "w-:Wedge", "b-:Background color", "n-:Negative", "e-:Exponential scale", "a-:Autoscale", "f-:Frame", "E-:Encapsulated PostScript", "N-:No Identifier", "v-:Verbose", (char *) 0}; static char usage[] = "Usage: bdf2ps [-i bdf-file] [-o ps-file] [-l list-file] [-p page-format]\n\t\ [-r resolution] [-c LUT] [-s xscale,yscale] [-z lcut,hcut] [-wbneafENv]"; int main(argc,argv) int argc; /* parameter count */ char **argv; /* pointers to parameters */ { unsigned char *data, *px[3]; char c, *pc, *pl, *pfmt, *pfl, *pin, *pon, *text; char pg[4], iname[MXNAME]; char *pval[MXPARM], line[MXLINE], ident[MXLINE]; char *gvparm(), *getenv(); int vmode, amode, bmode, wmode, nmode, fmode; int nx, ny, mx, my, na, np, nxs, nys, nxe, nye; int n, i, ip, iva, err, n1, n2, cmode, image, lok; int msize, idf, ioff, idt, nr, ng, nb, gcmode; int inull, lfsize, ipl, ixcen, iycen, ilc, ihc; int *pbl, *pgl, *prl, npix[3], kunit[4]; int itt[MXITF], blut[MXITF], glut[MXITF], rlut[MXITF]; int dcparm(), pscolor(), psdraw(); float *buf, *pf, val, cuts[4]; double cl, ch, gcl, gch, gxscale, gyscale, xscale, yscale; double ww, res[2], fac, xw, yw, pi, lcut, hcut; double xorg, yorg, xsize, ysize, xend, yend, xcen, ycen; double start[3], step[3], xstr, ystr, xo, xs, yo, ys; double red, blue, green; struct tm tms; PAGE *pp; FILE *pfd; SCSPRO("-1"); /* initiate MIDAS environment */ na = 1; iva = 0; SCECNT("PUT", &na, &iva, &iva); /* disable SC errors */ if (dcparm(argc,argv,plist,pval)) { /* decode parameter list */ fprintf(stdout,"%s\n",usage); SCSEPI(); } pin = gvparm('i',plist,pval); pfl = gvparm('l',plist,pval); if ((pin && pfl) || !(pin || pfl)) { /* If no file list/name */ fprintf(stderr,"Error: either file name OR list MUST be given!\n"); SCSEPI(); } if (pfl) { pfd = fopen(pfl,"r"); if (!pfd) { fprintf(stderr,"Error: cannot open list file >%s<\n",pfl); SCSEPI(); } pin = (char *) 0; } else pfd = NULL; pfmt = (pc=gvparm('p',plist,pval)) ? pc : PSPAGE; /* Page format */ for (n=0; n<4; n++) { c = (*pfmt) ? *pfmt : PSPAGE[n]; pg[n] = ('a'<=c && c<='z') ? c+'A'-'a' : c; if (*pfmt) pfmt++; } for (pp=page; pp->name && strcmp(pp->name,pg); pp++); if (!(pp->name)) { fprintf(stderr,"Error: Unknown page format!\n"); SCSEPI(); } lfsize = 8; if (gvparm('e',plist,pval) != (char *) 0) { /* ramp or log ITT */ fac = 255.0/log(256.0); for (n=0; n%s<\n",pc); i = MXITF-1; switch (*pc) { case '0' : /* default LUT no. 0 */ n1 = 0; n2 = 32; for (n=n1; n%sxsize,pp->ysize, /* open PS output file */ pp->xmar,pp->ymar,pp->angle,res)) { fprintf(stderr,"Error: cannot open PostScript output file\n"); SCSEPI(); } psmode(bmode, 0.0, 0.0, 1.0); /* set background color */ ww = 0.2; if (!(gvparm('E',plist,pval))) { if (oshdate(ident,&tms)) ident[0] = '\0'; sprintf(line,"ESO-MIDAS; %s",ident); pslabel(0.0,0.0,PSFONT,5,line); } while (pin || (pfd && fgets(line,MXLINE,pfd))) { /* go through files */ cl = gcl; ch = gch; xscale = gxscale; yscale = gyscale; xorg = 0.0; yorg = 1.0; if (pp->angle == 0.0) { xsize = pp->xsize - 2*(pp->xmar) - xorg - 2.0*ww; ysize = pp->ysize - 2*(pp->ymar) - yorg; } else { xsize = pp->ysize - 2*(pp->ymar) - xorg - 2.0*ww; ysize = pp->xsize - 2*(pp->xmar) - yorg; } ixcen = iycen = 0; /* no x/y-center given */ xcen = ycen = 0.0; ilc = ihc = 0; lcut = 0.0; hcut = 1.0; if (!pin) { /* decode file list */ if (vmode) fprintf(stdout,"File line >%s",line); lok = 0; image = 0; pl = strtok(line, " \t:\n"); if (!pl || *pl=='#' || *pl=='!') continue; /* comment line */ switch (*pl) { case 'I' : case 'i' : if (!(pl=strtok(NULL, " \t:"))) break; pc = strcpy(iname,pl); /* get file name */ pin = iname; if (!(pl=strtok(NULL, " \n\t,"))) break; xorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; yorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; xscale = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; yscale = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; xsize = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; ysize = atof(pl); ixcen = ((pl=strtok(NULL, " \n\t,")) != 0); if (ixcen) xcen = atof(pl); iycen = ((pl=strtok(NULL, " \n\t,")) != 0); if (iycen) ycen = atof(pl); ilc = ((pl=strtok(NULL, " \n\t,")) != 0); if (ilc) lcut = atof(pl); ihc = ((pl=strtok(NULL, " \n\t,")) != 0); if (ihc) hcut = atof(pl); if (vmode) { fprintf(stdout,"File >%s< %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f\n" ,pin,xorg,yorg,xscale,yscale,xsize,ysize); fprintf(stdout," %7.1f %7.1f %7.1f %7.1f\n" ,xcen,ycen,lcut,hcut); } lok = 1; image = 1; break; case 'T' : /* write text */ case 't' : if (!(pl=strtok(NULL, "\n"))) break; while (*pl && (*pl==' ' || *pl=='\t')) pl++; if (*pl=='"') c = '"', pl++; else c = ' '; text = pl; while (*pl && *pl!=c) pl++; *pl++ = '\0'; if (!(pl=strtok(pl, " \n\t,"))) break; xorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; yorg = atof(pl); i = (pl=strtok(NULL, " \n\t,")) ? atol(pl) : 5; red = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; green = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; gcmode = (pl==0) ? 0 : 1; blue = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; pscolor(gcmode,red,green,blue); if (vmode) { fprintf(stdout,"Text >%s< %7.1f %7.1f, %d\n",text,xorg,yorg,i); } pslabel(xorg,yorg,PSFONT,i,text); lok = 1; break; case 'L' : /* draw line */ case 'l' : if (!(pl=strtok(NULL, " \n\t,"))) break; xorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; yorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; xsize = atof(pl); ysize = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; xscale = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.1; red = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; green = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; gcmode = (pl==0) ? 0 : 1; blue = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; pscolor(gcmode,red,green,blue); if (vmode) { fprintf(stdout,"Line %7.1f %7.1f,%7.1f %7.1f, %7.2f\n", xorg,yorg,xsize,ysize,xscale); } psdraw(0,xorg,yorg,xscale,xsize,ysize,0.0,0.0); lok = 1; break; case 'C' : /* draw circle */ case 'c' : if (!(pl=strtok(NULL, " \n\t,"))) break; xorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; yorg = atof(pl); if (!(pl=strtok(NULL, " \n\t,"))) break; xsize = atof(pl); xscale = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; yscale = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 360.0; ysize = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.1; red = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; green = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; gcmode = (pl==0) ? 0 : 1; blue = (pl=strtok(NULL, " \n\t,")) ? atof(pl) : 0.0; pscolor(gcmode,red,green,blue); if (vmode) { fprintf(stdout,"Circle %7.1f %7.1f,%7.1f %7.1f, %7.2f %7.2f\n", xorg,yorg,ysize,xsize,xscale,yscale); } psdraw(1,xorg,yorg,ysize,xsize,xscale,yscale,0.0); lok = 1; break; default : fprintf(stderr,"Warning: Unknown line type in input list file\n"); fprintf(stderr," >%32.32s<\n",line); } if (!lok) { fprintf(stderr,"Error: wrong parameters in line\n"); fclose(pfd); SCSEPI(); } if (!image) continue; } if (vmode) fprintf(stdout,"Open image frame >%s<\n",pin); err = SCFOPN(pin, D_R4_FORMAT, 0, F_IMA_TYPE, &idf); if (err != ERR_NORMAL) { /* check if frame exists */ fprintf(stderr,"Warning: Image file >%s< not found\n", pin); pin = (char *) 0; continue; } err = SCDRDI(idf, "NAXIS", 1, 1, &iva, &na, kunit, &inull); if (na<2 || 3