/* mat2cps.c */ #include #include #include #define BOOLEAN char #define FALSE 0 #define VERS 1.3 main(argc,argv) int argc; char *argv[]; { FILE *fd_inp; FILE *fd_out; char name[20]; int type, imagf; double *inpr, *inpi; /* matrix real and imaginary: imaginary not used */ /****** double sqrt(); UNDEFINED _sqrt... ******/ int M, N, MN; /* size of original matrix */ int m, n, mn; int msd, lsd; /* least most significant digits to output in hex */ unsigned char inp_file[256]; /* char *filename gives 4 characters/byte */ unsigned char out_file[256]; /* HELP MESSAGE */ if (argc < 2) { /* give help when only program name given (no args) */ fprintf(stderr,"%s: convert matlab matrix to eps\n", argv[0]); fprintf(stderr,"version %f Steve Mann; 1990\n",VERS); fprintf(stderr,"---------------------------------------------------"); fprintf(stderr,"----------------------------\n"); fprintf(stderr,"%s deleteme.mat chirplet_growler.eps ",argv[0]); fprintf(stderr,"converts deleteme.mat to eps file\n"); fprintf(stderr,"%s deleteme.mat | lpr -Pps ",argv[0]); fprintf(stderr,"stdout (without creating a file)\n"); fprintf(stderr,"---------------------------------------------------"); fprintf(stderr,"----------------------------\n"); exit(0); } strcpy(inp_file, argv[1]); /* for now input file is always first */ fd_inp = fopen(inp_file,"rb"); if (fd_inp==NULL) {perror(argv[0]); exit(-1);} /* read in input matrix */ if (loadmat(fd_inp, &type, name, &M, &N, &imagf, &inpr, &inpi)) { printf("\nRead error when calling loadmat\n"); } fclose(fd_inp); fprintf(stderr,"%s: input matrix has been read in\n",argv[0]); /* output stream may be stdout or file */ if (argc < 3) { /* only one extra command line arg given */ fd_out = stdout; fprintf(stderr,"%s : output is stdout\n",argv[0]); } else { /* output is a file */ strcpy(out_file, argv[argc-1]); /* last argument is outfile */ fprintf(stderr,"%s ; output file = %s\n", argv[0], out_file); fd_out = fopen(out_file, "w"); if (fd_out==NULL) {perror(argv[0]); exit(-1);} } /* write out PostScript header */ fprintf(fd_out, "%%!PS-Adobe-2.0 EPSF-1.2\n"); fprintf(fd_out, "%%%%Copyright (c) 1991 by SwimWhere SoftWear\n"); fprintf(fd_out, "%%%%Creator: mat2eps_tf.c version 1.3, Steve Mann\n"); fprintf(fd_out, "%%%%Title: time-freq image\n"); fprintf(fd_out, "%%%%Pages: 1\n"); fprintf(fd_out, "%%%%BoundingBox: 100 90 495 504\n"); fprintf(fd_out, "%%%%EndComments\n"); fprintf(fd_out, "\n"); fprintf(fd_out, "%% tf_eps dictionary\n"); fprintf(fd_out, "/tfeps 20 dict begin\n"); fprintf(fd_out, "%% definition operators\n"); fprintf(fd_out, "/bdef {bind def} bind def\n"); fprintf(fd_out, "/xdef {exch def} bdef\n"); fprintf(fd_out, "%% page state control\n"); fprintf(fd_out, "/pgsv () def\n"); fprintf(fd_out, "/bpage {/pgsv save def} bdef\n"); fprintf(fd_out, "/epage {pgsv restore} bdef\n"); fprintf(fd_out, "/picstr %d string def\n",M); fprintf(fd_out, "/imagefile\n"); if (M!=N) fprintf(stderr,"%s ; still not sure which is M and which is N\n",argv[0]); fprintf(fd_out, "{ %d %d 8 [%d 0 0 %d 0 0]\n",M,N,M,N); fprintf(fd_out, " {currentfile picstr readhexstring pop} image} def\n"); fprintf(fd_out, "/xrightshow %% stk: string\n"); fprintf(fd_out, "{dup stringwidth pop\n"); fprintf(fd_out, "neg 0 rmoveto %% move left\n"); fprintf(fd_out, "show} def\n"); fprintf(fd_out, "/xcentershow %% stk: string\n"); fprintf(fd_out, "{dup stringwidth pop\n"); fprintf(fd_out, "2 div %% half width\n"); fprintf(fd_out, "neg 0 rmoveto %% move left\n"); fprintf(fd_out, "show} def\n"); fprintf(fd_out, "currentdict end def %% dictionary\n"); fprintf(fd_out, "%%%%EndProlog\n"); fprintf(fd_out, "\n"); fprintf(fd_out, "%%%%Page: 1 1\n"); fprintf(fd_out, "tfeps begin\n"); fprintf(fd_out, "bpage\n"); fprintf(fd_out, "gsave\n"); fprintf(fd_out, "360 360 scale\n"); fprintf(fd_out, "0.35 0.35 translate\n"); fprintf(fd_out, "/Times-Roman findfont\n"); fprintf(fd_out, "0.05 scalefont\n"); fprintf(fd_out, "setfont\n"); fprintf(fd_out, "0.5 1.1 moveto\n"); fprintf(fd_out, "(delete this title Title TITLE or change 504 to 534) xcentershow\n"); fprintf(fd_out, "%% image data\n"); fprintf(fd_out, "imagefile\n"); fprintf(stderr,"%s ; written out first part of header\n", argv[0]); MN = M*N; for (mn=0; mn

AltStyle によって変換されたページ (->オリジナル) /