void output_repeat_legend(FILE *fp, int *startpos, int **breaks, int *numsegment, int **colorindex, char **chrname, int num) { int i, j, k, l, m, n; int base[50], point[4][2]; char c, name[100], temp[100]; char **str; double label[3]; str = (char **) ckalloc(10 * sizeof(char *)); for(i = 0; i < 10; i ++) { str[i] = (char *) ckalloc(100 * sizeof(char)); } sprintf(str[0], "Repeat ID"); sprintf(str[1], "Length"); sprintf(str[2], "Chromosome"); sprintf(str[3], "From-to"); sprintf(str[4], "Subrepeats"); sprintf(str[5], "From-to"); base[0] = 50; base[1] = 800; outputline(fp, str, 6, base, 90, 10); base[1] -= 20; for(i = 0; i < num; i ++) { for(j = 0; j < numsegment[i]; j ++) { if(j == 0) { sprintf(str[0], "R%d", i + 1); sprintf(str[1], "%d", breaks[i][numsegment[i]]); sprintf(str[2], "%s", chrname[i]); sprintf(str[3], "%d-%d", startpos[i], startpos[i] + breaks[i][numsegment[i]] - 1); } else { str[0][0] = str[1][0] = str[2][0] = str[3][0] = '\0'; } m = (colorindex[i][j] - 1) % total_color; sprintf(str[4], "s%d", colorindex[i][j]); sprintf(str[5], "%d-%d", startpos[i] + breaks[i][j], startpos[i] + breaks[i][j + 1] - 1); base[0] = 50; base[1] -= 10; outputline(fp, str, 6, base, 90, 8); if(base[1] <= 50) { base[0] = 50; base[1] = 800; showpage(fp); fprintf(fp, "%%%%Page: P%d\n", npages); npages ++; change_scale(fp, scale); } } } for(i = 0; i < 10; i ++) { free((void *) str[i]); } free((void *) str); }
// ---------------------------------------------------------------------- DIPostscriptWriter:: ~DIPostscriptWriter(void) { showpage(); if(!eps_) psfile_ << "%%Pages: " << pageNo_ << endl << "%%EOF" << endl; if ( pageSize != NULL ) delete pageSize; pageSize = NULL; if ( addvec != NULL ) delete addvec; addvec = NULL; }
// ---------------------------------------------------------------------- void DIPostscriptWriter:: newpage() { if( eps_ && pageNo_ > 1 ) return; if( pageNo_ > 1 ) showpage(); psfile_ << "%%Page: " << pageNo_ <<" " << pageNo_ << std::endl; pageNo_++; }
static int showpages(fz_context *ctx, pdf_document *doc, fz_output *out, char *pagelist) { int page, spage, epage; char *spec, *dash; int pagecount; int ret = 0; if (!doc) infousage(); pagecount = pdf_count_pages(ctx, doc); spec = fz_strsep(&pagelist, ","); while (spec && pagecount) { dash = strchr(spec, '-'); if (dash == spec) spage = epage = pagecount; else spage = epage = atoi(spec); if (dash) { if (strlen(dash) > 1) epage = atoi(dash + 1); else epage = pagecount; } if (spage > epage) page = spage, spage = epage, epage = page; spage = fz_clampi(spage, 1, pagecount); epage = fz_clampi(epage, 1, pagecount); for (page = spage; page <= epage; page++) { ret |= showpage(ctx, doc, out, page); } spec = fz_strsep(&pagelist, ","); } return ret; }
static int showpages(fz_context *ctx, pdf_document *doc, fz_output *out, const char *pagelist) { int page, spage, epage; int pagecount; int ret = 0; if (!doc) infousage(); pagecount = pdf_count_pages(ctx, doc); while ((pagelist = fz_parse_page_range(ctx, pagelist, &spage, &epage, pagecount))) { if (spage > epage) page = spage, spage = epage, epage = page; for (page = spage; page <= epage; page++) ret |= showpage(ctx, doc, out, page); } return ret; }
int main( int argc, char *argv[] ) { /* (x,y) position of edit window. x column, y line -> (0,0) at upper left on screen */ unsigned int xCursorPos = 0; unsigned int yCursorPos = 0; unsigned int curmenu = 0x1100; int i; cwsetup( argc, argv ); writestatus( 0 ); writetab( ); splashscreen( ); /* Main program loop */ do { dispstrhgc( " ", wind.col, 2, NORMALATTR ); i = pulled_down_menu( &curmenu, &xCursorPos, &yCursorPos ); if ( filename[0] != '\0' ) { switch ( i ) { case RETKEY: keymain = menu_to_key( curmenu ); break; case ESCKEY: waitkbd( wind.col + xCursorPos, wind.row + yCursorPos ); /* Show blinking cursor */ keymain = readkbd( ); /* If keypressed Get it */ break; default: keymain = i; break; } while ( keymain != ESCKEY ) { if ( ( keymain & 0xff ) >= 32 ) { keymain = changekey( keymain ); if ( insertmode ) { if ( !insert_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } else { if ( !ovrwrite_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } refreshline( xCursorPos, yCursorPos ); } else { /* Function Key */ switch ( keymain ) { case PGUPKEY: case CNTRL_R: page_up( ); break; case PGDNKEY: case CNTRL_C: page_down( ); break; case UPKEY: case CNTRL_E: cursor_up( ); break; case DNKEY: case CNTRL_X: cursor_down( yCursorPos ); break; case LEKEY: case CNTRL_S: cursor_left( &xCursorPos ); break; case 0x2301: gobeginblk( &xCursorPos ); break; case 0x2401: goendblk( &xCursorPos ); break; case RIKEY: case CNTRL_D: cursor_right( &xCursorPos, yCursorPos ); break; case CNTRL_W: scroll_up( ); break; case CNTRL_Z: scroll_down( ); break; case CHOMEKEY: top_of_page( ); break; case CPGUPKEY: topfile( &xCursorPos ); break; case CENDKEY: bottom_of_page( ); break; case CPGDNKEY: endfile( &xCursorPos ); break; case DELKEY: case CNTRL_G: delete_char( xCursorPos ); refreshline( xCursorPos, yCursorPos ); changeflag = YES; break; case CNTRL_T: delete_word( xCursorPos ); refreshline( xCursorPos, yCursorPos ); changeflag = YES; break; case CNTRL_Y: delete_line( ); changeflag = YES; break; case CNTRL_M: case RETKEY: if ( insertmode == NO ) { returnkey( &xCursorPos, yCursorPos ); } else { ret_with_ins( &xCursorPos, yCursorPos ); changeflag = YES; } break; case BSKEY: case CNTRL_H: backspace( &xCursorPos ); yCursorPos = findrow( ); refreshline( 0, yCursorPos ); changeflag = YES; break; case INSKEY: case CNTRL_V: insertmode = !insertmode; writeinsmode( ); break; case CNTRL_N: insert_ret( &xCursorPos ); break; case F10KEY: thaimode = !thaimode; writelanguage( ); break; case F1KEY: fontused = 0x00; writeattr( ); break; case F2KEY: fontused = fontused | ITALICATTR; writeattr( ); break; case F3KEY: fontused = fontused | ONELINEATTR; fontused = fontused & 0x7f; writeattr( ); break; case F4KEY: fontused = fontused | TWOLINEATTR; fontused = fontused & 0xfe; writeattr( ); break; case F5KEY: fontused = fontused | BOLDATTR; writeattr( ); break; case F6KEY: fontused = fontused | ENLARGEATTR; writeattr( ); break; case F7KEY: fontused = fontused | SUPERATTR; if ( ( fontused & SUBATTR ) == SUBATTR ) { fontused = fontused ^ SUBATTR; } writeattr( ); break; case F8KEY: fontused = fontused | SUBATTR; if ( ( fontused & SUPERATTR ) == SUPERATTR ) { fontused = fontused ^ SUPERATTR; } writeattr( ); break; case F9KEY: manualwrap( &xCursorPos, &yCursorPos ); break; case ALTM: editmacro( ); break; case TABKEY: case CNTRL_I: movetotab( &xCursorPos, yCursorPos ); break; case CNTRL_K: blockcommand( &xCursorPos ); break; case 0x1401: blkcmd( 'p', &xCursorPos ); break; case 0x6101: blkcmd( 'b', &xCursorPos ); break; case 0x6201: blkcmd( 'k', &xCursorPos ); break; case 0x6301: blkcmd( 'c', &xCursorPos ); break; case 0x6401: blkcmd( 'y', &xCursorPos ); break; case 0x6501: blkcmd( 'v', &xCursorPos ); break; case 0x6601: blkcmd( 'r', &xCursorPos ); break; case 0x6701: blkcmd( 'w', &xCursorPos ); break; case 0x6801: blkcmd( 'h', &xCursorPos ); break; case CNTRL_O: onscreen( xCursorPos, yCursorPos ); break; case 0x7101: doonscrn( 'l', xCursorPos, yCursorPos ); break; case 0x7201: doonscrn( 'r', xCursorPos, yCursorPos ); break; case 0x7301: doonscrn( 'i', xCursorPos, yCursorPos ); break; case 0x7401: doonscrn( 'n', xCursorPos, yCursorPos ); break; case 0x7501: doonscrn( 'c', xCursorPos, yCursorPos ); break; case 0x7601: doonscrn( 'p', xCursorPos, yCursorPos ); break; case 0x7701: doonscrn( 'x', xCursorPos, yCursorPos ); break; case CNTRL_Q: quick( &xCursorPos, &yCursorPos ); break; case 0x3501: deltoendline( xCursorPos, yCursorPos ); break; case 0x8111: inscntrl( CNTRL_W, xCursorPos, yCursorPos ); break; case 0x8211: inscntrl( CNTRL_S, xCursorPos, yCursorPos ); break; case 0x8311: inscntrl( CNTRL_R, xCursorPos, yCursorPos ); break; case 0x8411: inscntrl( CNTRL_B, xCursorPos, yCursorPos ); break; case 0x8511: inscntrl( CNTRL_E, xCursorPos, yCursorPos ); break; case 0x8611: inscntrl( CNTRL_T, xCursorPos, yCursorPos ); break; case 0x8711: inscntrl( CNTRL_V, xCursorPos, yCursorPos ); break; case CNTRL_P: printcntrl( xCursorPos, yCursorPos ); break; case HOMEKEY: home( &xCursorPos ); break; case ENDKEY: endline( &xCursorPos ); break; case CLEKEY: case CNTRL_A: backword( &xCursorPos ); break; case CRIKEY: case CNTRL_F: nextword( &xCursorPos, yCursorPos ); break; case CNTRL_L: if ( source[0] != '\0' ) { if ( replaceflag == NO ) { if ( searchfwd( &xCursorPos, &yCursorPos ) == NO ) { wordnotfound( ); } } else { if ( searchreplace( &xCursorPos, &yCursorPos ) == NO ) { wordnotfound( ); } } } break; case CNTRL_B: reform( ); break; case ALTP: gotopage( ); break; case CNTRL_J: case ALTL: gotoline( ); break; case 0x5101: searching( &xCursorPos, &yCursorPos ); break; case 0x5201: replacing( &xCursorPos, &yCursorPos ); break; case 0x8501: loadtoline( curline->text ); refreshline( 0, yCursorPos ); break; case CF1KEY: insertmacro( ¯o[0][0], &xCursorPos, &yCursorPos ); break; case CF2KEY: insertmacro( ¯o[1][0], &xCursorPos, &yCursorPos ); break; case CF3KEY: insertmacro( ¯o[2][0], &xCursorPos, &yCursorPos ); break; case CF4KEY: insertmacro( ¯o[3][0], &xCursorPos, &yCursorPos ); break; case CF5KEY: insertmacro( ¯o[4][0], &xCursorPos, &yCursorPos ); break; case CF6KEY: insertmacro( ¯o[5][0], &xCursorPos, &yCursorPos ); break; case CF7KEY: insertmacro( ¯o[6][0], &xCursorPos, &yCursorPos ); break; case CF8KEY: insertmacro( ¯o[7][0], &xCursorPos, &yCursorPos ); break; case CF9KEY: insertmacro( ¯o[8][0], &xCursorPos, &yCursorPos ); break; case CF10KEY: insertmacro( ¯o[9][0], &xCursorPos, &yCursorPos ); break; case AF2KEY: inscntrl( ITALICCODE, xCursorPos, yCursorPos ); break; case AF3KEY: inscntrl( ONELINECODE, xCursorPos, yCursorPos ); break; case AF4KEY: inscntrl( TWOLINECODE, xCursorPos, yCursorPos ); break; case AF5KEY: inscntrl( BOLDCODE, xCursorPos, yCursorPos ); break; case AF6KEY: inscntrl( ENLARGECODE, xCursorPos, yCursorPos ); break; case AF7KEY: inscntrl( SUPERCODE, xCursorPos, yCursorPos ); break; case AF8KEY: inscntrl( SUBCODE, xCursorPos, yCursorPos ); break; #ifdef WANT_TO_USE_GRAPH case ALTG: insertgraph( ); break; case ALTD: deletegraph( ); break; #endif case ALTX: quitprog = YES; keymain = ESCKEY; break; default: if ( ( alt_char_map( keymain ) ) != -1 ) { keymain = alt_char_map( keymain ); if ( insertmode ) { if ( !insert_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } else { if ( !ovrwrite_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } refreshline( xCursorPos, yCursorPos ); } break; } /* switch ( keymain ) */ } adjustcol( &xCursorPos ); while ( ( yCursorPos = findrow( ) ) > ( wind.width - 1 ) ) { storeline( curline ); curline = curline->previous; loadtoline( curline->text ); lineno--; } if ( !keypressed( ) ) { if ( !pagecomplete ) { showpage( ); } if ( !keypressed( ) ) { writecolno( firstcol + xCursorPos ); dispstrhgc( " ", wind.col, 2, NORMALATTR ); if ( !keypressed( ) ) { writepageline( ); } } } if ( quitprog != YES ) { waitkbd( wind.col + xCursorPos, wind.row + yCursorPos ); keymain = readkbd( ); dispkey( keymain ); } } /* while */ } else { /* if filename[0] != '\0' */ errorsound( ); } } while ( !quitprog ); if ( changeflag ) { blockmsg( 5 ); dispstrhgc( "ÂѧäÁèä´é¨Ñ´à¡çºá¿éÁ¢éÍÁÙÅ µéͧ¡ÒèѴà¡çºËÃ×ÍäÁè (Y/N)?", ( 16 + center_factor ) + 7, 5, REVERSEATTR ); keymain = 0; while ( ( keymain != 'n' ) && ( keymain != 'N' ) && ( keymain != 'y' ) && ( keymain != 'Y' ) ) { keymain = ebioskey( 0 ) & 0xff; if ( ( keymain == 'y' ) || ( keymain == 'Y' ) ) { writeblk( filename, sentinel->next, 0, sentinel->previous, MAXCOL ); } } } settext( ); return 0; }
int main (int argc, char **argv) { int n1,n2,n1tic,n2tic,nfloats,bbox[4], i1,i2,grid1,grid2,style, i3,n3,notitle2=0, n1c,n2c,n1s,n2s,i1beg,i1end,i2beg,i2end,i1c,i2c, n1dsp=0,n2dsp=0,n3dsp=0,loopdsp, nz,iz,i1step,i2step,verbose; float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip, d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi, f3,d3,f3s, xbox,ybox,wbox,hbox, x1beg,x1end,x2beg,x2end, x1min,x1max,x2min,x2max, d1num,f1num,d2num,f2num, p1beg,p1end,p2beg,p2end,matrix[6], d1s,d2s; unsigned char *cz,*czp,*sz; char *label1="",*label2="",*title="",*title2="", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *styles="seismic",*grid1s="none",*grid2s="none"; char title2s[80],c80[80]; FILE *infp=stdin; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); if (!getparfloat("d1",&d1)) d1 = 1.0; if (!getparfloat("f1",&f1)) f1 = 0.0; /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) { if (efseeko(infp,(off_t) 0,SEEK_END)!=0) err("must specify n2 if in a pipe!\n"); nfloats = (int) (eftello(infp)/((off_t) sizeof(float))); efseeko(infp,(off_t) 0,SEEK_SET); n2 = nfloats/n1; n3 = 1; } if (!getparfloat("d2",&d2)) d2 = 1.0; if (!getparfloat("f2",&f2)) f2 = 0.0; /* get parameters describing 3rd dimension sampling */ if (!getparint("n3",&n3)) { if (efseeko(infp,(off_t) 0,SEEK_END)!=0) err("must specify n3 if in a pipe!\n"); nfloats = (int) (eftello(infp)/((off_t) sizeof(float))); efseeko(infp,(off_t) 0,SEEK_SET); n3 = nfloats/n1/n2; } if (!getparfloat("d3",&d3)) d3 = 1.0; if (!getparfloat("f3",&f3)) f3 = d3; /* set up desired looping mode */ if (!getparint("loopdsp",&loopdsp)) loopdsp = 3; if (loopdsp == 3) { n1dsp = n1; n2dsp=n2; n3dsp=n3; } else if (loopdsp == 1) { n1dsp = n2; n2dsp=n3; n3dsp=n1; } else if (loopdsp == 2) { n1dsp = n1; n2dsp=n3; n3dsp=n2; } x1min = (d1>0.0)?f1:f1+(n1dsp-1)*d1; x1max = (d1<0.0)?f1:f1+(n1dsp-1)*d1; x2min = (d2>0.0)?f2:f2+(n2dsp-1)*d2; x2max = (d2<0.0)?f2:f2+(n2dsp-1)*d2; /* read binary data to be plotted */ nz = n1*n2*n3; z = ealloc1float(nz); if (fread(z,sizeof(float),nz,infp)!=nz) err("error reading input file!\n"); /* if necessary, determine clips from percentiles */ if (getparfloat("clip",&clip)) { bclip = clip; wclip = -clip; } if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) && !getparfloat("clip",&clip)) { perc = 100.0; getparfloat("perc",&perc); temp = ealloc1float(nz); for (iz=0; iz<nz; iz++) temp[iz] = z[iz]; if (!getparfloat("bclip",&bclip)) { bperc = perc; getparfloat("bperc",&bperc); iz = (nz*bperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); bclip = temp[iz]; } if (!getparfloat("wclip",&wclip)) { wperc = 100.0-perc; getparfloat("wperc",&wperc); iz = (nz*wperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); wclip = temp[iz]; } free1float(temp); } /* transpose data if needed */ if (loopdsp == 1) { temp = ealloc1float(nz); for (iz=0;iz<nz;iz++) temp[iz] = z[iz]; for (i3=0;i3<n3;i3++) { for (i2=0;i2<n2;i2++) { for(i1=0;i1<n1;i1++) { z[i2+i3*n2+i1*n2*n3] = temp[i1+i2*n1+i3*n1*n2]; } } } free1float(temp); } else if (loopdsp == 2) { temp = ealloc1float(nz); for (iz=0;iz<nz;iz++) temp[iz] = z[iz]; for (i3=0;i3<n3;i3++) { for (i2=0;i2<n2;i2++) { for(i1=0;i1<n1;i1++) { z[i1+i3*n1+i2*n1*n3] = temp[i1+i2*n1+i3*n1*n2]; } } } free1float(temp); } verbose = 1; getparint("verbose",&verbose); if (verbose) warn("bclip=%g wclip=%g",bclip,wclip); /* get scaled sampling intervals */ d1s = 1.0; getparfloat("d1s",&d1s); d2s = 1.0; getparfloat("d2s",&d2s); d1s = fabs(d1s); d1s *= d1; d2s = fabs(d2s); d2s *= d2; /* get axes parameters */ xbox = 1.0; getparfloat("xbox",&xbox); ybox = 1.5; getparfloat("ybox",&ybox); wbox = 6.0; getparfloat("wbox",&wbox); hbox = 8.0; getparfloat("hbox",&hbox); x1beg = x1min; getparfloat("x1beg",&x1beg); x1end = x1max; getparfloat("x1end",&x1end); d1num = 0.0; getparfloat("d1num",&d1num); f1num = x1min; getparfloat("f1num",&f1num); n1tic = 1; getparint("n1tic",&n1tic); getparstring("grid1",&grid1s); if (STREQ("dot",grid1s)) grid1 = DOT; else if (STREQ("dash",grid1s)) grid1 = DASH; else if (STREQ("solid",grid1s)) grid1 = SOLID; else grid1 = NONE; getparstring("label1",&label1); x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; getparfloat("x2end",&x2end); d2num = 0.0; getparfloat("d2num",&d2num); f2num = 0.0; getparfloat("f2num",&f2num); n2tic = 1; getparint("n2tic",&n2tic); getparstring("grid2",&grid2s); if (STREQ("dot",grid2s)) grid2 = DOT; else if (STREQ("dash",grid2s)) grid2 = DASH; else if (STREQ("solid",grid2s)) grid2 = SOLID; else grid2 = NONE; getparstring("label2",&label2); getparstring("labelfont",&labelfont); labelsize = 18.0; getparfloat("labelsize",&labelsize); getparstring("title",&title); if (!getparstring("title2",&title2)) notitle2=1; getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("style",&styles); if (STREQ("normal",styles)) style = NORMAL; else style = SEISMIC; /* adjust x1beg and x1end to fall on sampled values */ i1beg = NINT((x1beg-f1)/d1); i1beg = MAX(0,MIN(n1dsp-1,i1beg)); x1beg = f1+i1beg*d1; i1end = NINT((x1end-f1)/d1); i1end = MAX(0,MIN(n1dsp-1,i1end)); x1end = f1+i1end*d1; /* adjust x2beg and x2end to fall on sampled values */ i2beg = NINT((x2beg-f2)/d2); i2beg = MAX(0,MIN(n2dsp-1,i2beg)); x2beg = f2+i2beg*d2; i2end = NINT((x2end-f2)/d2); i2end = MAX(0,MIN(n2dsp-1,i2end)); x2end = f2+i2end*d2; /* allocate space for image bytes */ n1c = 1+abs(i1end-i1beg); n2c = 1+abs(i2end-i2beg); /* convert data to be imaged into unsigned characters */ zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10; zoffset = -bclip*zscale; i1step = (i1end>i1beg)?1:-1; i2step = (i2end>i2beg)?1:-1; /* determine sampling after scaling */ n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s)); d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1; n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s)); d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2; /* convert axes box parameters from inches to points */ xbox *= 72.0; ybox *= 72.0; wbox *= 72.0; hbox *= 72.0; /* set bounding box */ psAxesBBox3( xbox,ybox,wbox,hbox, labelfont,labelsize, titlefont,titlesize, style,bbox); boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ beginps(); /* loop over n3 */ for(i3=0;i3<n3dsp;i3++) { cz = ealloc1(n1c*n2c,sizeof(char)); czp = cz; for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) { for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) { zi = zoffset +z[i1+i2*n1dsp+i3*n1dsp*n2dsp]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } /* if necessary, interpolate to scaled sampling intervals */ if (n1s!=n1c || n2s!=n2c) { sz = ealloc1(n1s*n2s,sizeof(char)); intl2b(n2c,d2,0.0,n1c,d1,0.0,cz, n2s,d2s,0.0,n1s,d1s,0.0,sz); free1(cz); } else { sz = cz; } /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2; p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2; p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2; p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2; newpage("1",i3+1); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* determine image matrix */ if (style==NORMAL) { matrix[0] = 0; matrix[1] = n1s; matrix[2] = n2s; matrix[3] = 0; matrix[4] = 0; matrix[5] = 0; } else { matrix[0] = n2s; matrix[1] = 0; matrix[2] = 0; matrix[3] = -n1s; matrix[4] = 0; matrix[5] = n1s; } scale(wbox,hbox); /* draw the image (before axes so grid lines are visible) */ image(n2s,n1s,8,matrix,sz); /* restore graphics state */ grestore(); /* update title2 only if n3>1*/ strcpy(title2s,title2); if ( notitle2 == 0 ) { char *nullchar=""; f3s = f3 + i3 * d3; sprintf(c80,"= %.4g %s",f3s,nullchar); strcat(title2s,c80); } /* draw axes and title */ psAxesBox3( xbox,ybox,wbox,hbox, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, labelfont,labelsize, title,titlefont,titlesize, style, title2s); showpage(); } /* end PostScript */ endps(); return EXIT_SUCCESS; }
int main (int argc, char **argv) { int n1,n2,n3,n1s,n2s,n3s,n1c,n2c,n3c,i1,i2,i3,i1c,i2c,i3c, i1beg,i1end,i2beg,i2end,i3beg,i3end,i1step,i2step,i3step, n1tic,n2tic,n3tic,grid1,grid2,grid3,nz,iz, verbose,faces,hls,bps,style=SEISMIC,bbox[4], legend,ugrid=SOLID,lstyle=VERTLEFT,lz,lbegsup=0,lendsup=0,ln=256, lbbox[4]; float d1,d2,d3,d1s,d2s,d3s,f1,f2,f3,size1,size2,size3,xbox,ybox,angle, x1min,x1max,x2min,x2max,x3min,x3max, x1beg,x1end,x2beg,x2end,x3beg,x3end, d1num,f1num,d2num,f2num,d3num,f3num, p1beg,p1end,p2beg,p2end,p3beg,p3end, clip,bclip,wclip,perc,bperc,wperc, zscale,zoffset,zi,labelsize,titlesize, *z,*zfront,*zside,*ztop,*temp,matrix[6],colors[3][2], lwidth,lheight,lx,ly,lbeg,lend, lmin=(float)FLT_MAX,lmax=(float)-FLT_MAX, ldnum,lfnum,ld,lf=0,labmatrix[6]; unsigned char *czfront,*czside,*cztop, *szfront,*szside,*sztop,*czp, *data_legend=NULL; char *label1="",*label2="",*label3="",*title="", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *grid1s="none",*grid2s="none",*grid3s="none", *titlecolor="black",*axescolor="black",*gridcolor="black", *frontf,*sidef,*topf, *units="", *legendfont="times_roman10", *lstyles="vertleft",*lgrids="none"; FILE *infp=stdin,*frontfp,*sidefp,*topfp; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); if (!getparfloat("d1",&d1)) d1 = 1.0; if (!getparfloat("f1",&f1)) f1 = 0.0; /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) err("must specify n2!\n"); if (!getparfloat("d2",&d2)) d2 = 1.0; if (!getparfloat("f2",&f2)) f2 = 0.0; /* get parameters describing 3rd dimension sampling */ if (!getparint("n3",&n3)) err("must specify n3!\n"); if (!getparfloat("d3",&d3)) d3 = 1.0; if (!getparfloat("f3",&f3)) f3 = 0.0; /* determine input type */ if (!getparint("faces",&faces)) faces = 0; /* read color parameters */ bps = 8; hls = 0; colors[R][0] = colors[G][0] = colors[B][0] = 0.0; colors[R][1] = colors[G][1] = colors[B][1] = 1.0; if (countparval("brgb") || countparval("wrgb")) { float brgb[3],wrgb[3]; brgb[R] = brgb[G] = brgb[B] = 0.0; wrgb[R] = wrgb[G] = wrgb[B] = 1.0; getparfloat("brgb",&brgb[0]); getparfloat("wrgb",&wrgb[0]); brgb[R] = MAX(0.0,MIN(1.0,brgb[R])); wrgb[R] = MAX(0.0,MIN(1.0,wrgb[R])); brgb[G] = MAX(0.0,MIN(1.0,brgb[G])); wrgb[G] = MAX(0.0,MIN(1.0,wrgb[G])); brgb[B] = MAX(0.0,MIN(1.0,brgb[B])); wrgb[B] = MAX(0.0,MIN(1.0,wrgb[B])); colors[R][0] = brgb[R]; colors[R][1] = wrgb[R]; colors[G][0] = brgb[G]; colors[G][1] = wrgb[G]; colors[B][0] = brgb[B]; colors[B][1] = wrgb[B]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } else if (countparval("bhls") || countparval("whls")) { float bhls[3],whls[3]; hls = 1; bhls[H] = whls[H] = 0.0; bhls[L] = 0.0; whls[L] = 1.0; bhls[S] = whls[S] = 0.0; getparfloat("bhls",&bhls[0]); getparfloat("whls",&whls[0]); bhls[L] = MAX(0.0,MIN(1.0,bhls[L])); whls[L] = MAX(0.0,MIN(1.0,whls[L])); bhls[S] = MAX(0.0,MIN(1.0,bhls[S])); whls[S] = MAX(0.0,MIN(1.0,whls[S])); colors[H][0] = bhls[0]; colors[H][1] = whls[0]; colors[L][0] = bhls[1]; colors[L][1] = whls[1]; colors[S][0] = bhls[2]; colors[S][1] = whls[2]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } /* allocate space */ nz = n1*n2+n1*n3+n2*n3; z = ealloc1float(nz); zfront = z; zside = zfront+n1*n2; ztop = zside+n1*n3; /* read data */ if (getparstring("front",&frontf) && getparstring("side",&sidef) && getparstring("top",&topf)) { /* read face files */ if ((frontfp = fopen(frontf,"r")) == NULL) err("error opening front file!\n"); if (fread(zfront,sizeof(float),n1*n2,frontfp)!=n1*n2) err("error reading front file!\n"); if ((sidefp = fopen(sidef,"r")) == NULL) err("error opening side file!\n"); if (fread(zside,sizeof(float),n1*n3,sidefp)!=n1*n3) err("error reading side file!\n"); if ((topfp = fopen(topf,"r")) == NULL) err("error opening top file!\n"); if (fread(ztop,sizeof(float),n2*n3,topfp)!=n2*n3) err("error reading top file!\n"); } else if (getparstring("front",&frontf) || getparstring("side",&sidef) || getparstring("top",&topf)) { err("must specify all or none of face, side, and top!\n"); } else if (faces) { /* read faces from stdin */ if (fread(zfront,sizeof(float),n1*n2,infp)!=n1*n2) err("error reading front from input!\n"); if (fread(zside,sizeof(float),n1*n3, infp)!=n1*n3) err("error reading side from input!\n"); if (fread(ztop,sizeof(float),n2*n3, infp)!=n2*n3) err("error reading top from input!\n"); } else { /* read cube from stdin, pick off faces */ temp = ealloc1float(n1); for (i3=0; i3<n3; i3++) { for (i2=0; i2<n2; i2++) { if (fread(temp,sizeof(float),n1,infp)!=n1) err("error reading cube from input!\n"); if (i3==0) for (i1=0; i1<n1; i1++) zfront[i1+i2*n1] = temp[i1]; if (i2==n2-1) for (i1=0; i1<n1; i1++) zside[i1+i3*n1] = temp[i1]; ztop[i2+i3*n2] = temp[0]; } } free1float(temp); } /* if necessary, determine clips from percentiles */ if (getparfloat("clip",&clip)) { bclip = clip; wclip = -clip; } if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) && !getparfloat("clip",&clip)) { perc = 100.0; getparfloat("perc",&perc); temp = ealloc1float(nz); for (iz=0; iz<nz; iz++) temp[iz] = z[iz]; if (!getparfloat("bclip",&bclip)) { bperc = perc; getparfloat("bperc",&bperc); iz = (nz*bperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); bclip = temp[iz]; } if (!getparfloat("wclip",&wclip)) { wperc = 100.0-perc; getparfloat("wperc",&wperc); iz = (nz*wperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); wclip = temp[iz]; } free1float(temp); } if (!getparint("verbose",&verbose)) verbose = 1; if (verbose) warn("bclip=%g wclip=%g",bclip,wclip); /* get scaled sampling intervals */ if (!getparfloat("d1s",&d1s)) d1s = 1.0; if (!getparfloat("d2s",&d2s)) d2s = 1.0; if (!getparfloat("d3s",&d3s)) d3s = 1.0; d1s = fabs(d1s); d1s *= d1; d2s = fabs(d2s); d2s *= d2; d3s = fabs(d3s); d3s *= d3; /* get projection angle, convert to radians */ if(!getparfloat("angle",&angle)) angle = 45.0; angle = MAX(angle,0.00001); angle = MIN(angle,90.0); angle *= PI/180.0; /* get axes parameters */ if(!getparfloat("size1",&size1)) size1 = 4.0; if(!getparfloat("size2",&size2)) size2 = 4.0; if(!getparfloat("size3",&size3)) size3 = 3.0; if (!getparfloat("xbox",&xbox)) xbox = 1.5; if (!getparfloat("ybox",&ybox)) ybox = 1.5; /* compute extreme values */ x1min = (d1>0.0)?f1:f1+(n1-1)*d1; x1max = (d1<0.0)?f1:f1+(n1-1)*d1; x2min = (d2>0.0)?f2:f2+(n2-1)*d2; x2max = (d2<0.0)?f2:f2+(n2-1)*d2; x3min = (d3>0.0)?f3:f3+(n3-1)*d3; x3max = (d3<0.0)?f3:f3+(n3-1)*d3; /* get axis1 parameters */ x1beg = x1min; x1end = x1max; getparfloat("x1end",&x1end); d1num = 0.0; getparfloat("d1num",&d1num); f1num = x1min; getparfloat("f1num",&f1num); n1tic = 1; getparint("n1tic",&n1tic); getparstring("grid1",&grid1s); if (STREQ("dot",grid1s)) grid1 = DOT; else if (STREQ("dash",grid1s)) grid1 = DASH; else if (STREQ("solid",grid1s)) grid1 = SOLID; else grid1 = NONE; getparstring("label1",&label1); /* get axis2 parameters */ x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; d2num = 0.0; getparfloat("d2num",&d2num); f2num = x2min; getparfloat("f2num",&f2num); n2tic = 1; getparint("n2tic",&n2tic); getparstring("grid2",&grid2s); if (STREQ("dot",grid2s)) grid2 = DOT; else if (STREQ("dash",grid2s)) grid2 = DASH; else if (STREQ("solid",grid2s)) grid2 = SOLID; else grid2 = NONE; getparstring("label2",&label2); /* get axis3 parameters */ x3beg = x3min; x3end = x3max; getparfloat("x3end",&x3end); d3num = 0.0; getparfloat("d3num",&d3num); f3num = x3min; getparfloat("f3num",&f3num); n3tic = 1; getparint("n3tic",&n3tic); getparstring("grid3",&grid3s); if (STREQ("dot",grid3s)) grid3 = DOT; else if (STREQ("dash",grid3s)) grid3 = DASH; else if (STREQ("solid",grid3s)) grid3 = SOLID; else grid3 = NONE; getparstring("label3",&label3); /* get additional font parameters */ getparstring("labelfont",&labelfont); labelsize = 18.0; getparfloat("labelsize",&labelsize); getparstring("title",&title); getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("titlecolor",&titlecolor); getparstring("axescolor",&axescolor); getparstring("gridcolor",&gridcolor); style = SEISMIC; /* adjust x1beg and x1end to fall on sampled values */ i1beg = NINT((x1beg-f1)/d1); i1beg = MAX(0,MIN(n1,i1beg)); x1beg = f1+i1beg*d1; i1end = NINT((x1end-f1)/d1); i1end = MAX(0,MIN(n1-1,i1end)); x1end = f1+i1end*d1; /* adjust x2beg and x2end to fall on sampled values */ i2beg = NINT((x2beg-f2)/d2); i2beg = MAX(0,MIN(n2-1,i2beg)); x2beg = f2+i2beg*d2; i2end = NINT((x2end-f2)/d2); i2end = MAX(0,MIN(n2-1,i2end)); x2end = f2+i2end*d2; /* adjust x3beg and x3end to fall on sampled values */ i3beg = NINT((x3beg-f3)/d3); i3beg = MAX(0,MIN(n3-1,i3beg)); x3beg = f3+i3beg*d3; i3end = NINT((x3end-f3)/d3); i3end = MAX(0,MIN(n3-1,i3end)); x3end = f3+i3end*d3; /* allocate space for image bytes */ n1c = 1+abs(i1end-i1beg); n2c = 1+abs(i2end-i2beg); n3c = 1+abs(i3end-i3beg); czfront = ealloc1(n1c*n2c,sizeof(char)); czside = ealloc1(n1c*n3c,sizeof(char)); cztop = ealloc1(n2c*n3c,sizeof(char)); /* compute conversion constants */ zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10; zoffset = -bclip*zscale; i1step = (i1end>i1beg)?1:-1; i2step = (i2end>i2beg)?1:-1; i3step = (i3end>i3beg)?1:-1; /* convert front data to be imaged into unsigned characters */ czp = czfront; for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) { for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) { zi = zoffset+zfront[i1+i2*n1]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } /* convert side data to be imaged into unsigned characters */ czp = czside; for (i3c=0,i3=i3beg; i3c<n3c; i3c++,i3+=i3step) { for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) { zi = zoffset+zside[i1+i3*n1]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } /* convert top data to be imaged into unsigned characters */ czp = cztop; for (i3c=0,i3=i3beg; i3c<n3c; i3c++,i3+=i3step) { for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) { zi = zoffset+ztop[i2+i3*n2]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } free1float(z); /* determine sampling after scaling */ n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s)); d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1; n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s)); d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2; n3s = MAX(1,NINT(1+(n3c-1)*d3/d3s)); d3s = (n3s>1)?d3*(n3c-1)/(n3s-1):d3; /* if necessary, interpolate front to scaled sampling intervals */ if (n1s!=n1c || n2s!=n2c) { szfront = ealloc1(n1s*n2s,sizeof(char)); intl2b(n1c,d1,0.0,n2c,d2,0.0,czfront, n1s,d1s,0.0,n2s,d2s,0.0,szfront); free1(czfront); } else { szfront = czfront; } /* if necessary, interpolate side to scaled sampling intervals */ if (n1s!=n1c || n3s!=n3c) { szside = ealloc1(n1s*n3s,sizeof(char)); intl2b(n1c,d1,0.0,n3c,d3,0.0,czside, n1s,d1s,0.0,n3s,d3s,0.0,szside); free1(czside); } else { szside = czside; } /* if necessary, interpolate top to scaled sampling intervals */ if (n2s!=n2c || n3s!=n3c) { sztop = ealloc1(n2s*n3s,sizeof(char)); intl2b(n2c,d2,0.0,n3c,d3,0.0,cztop, n2s,d2s,0.0,n3s,d3s,0.0,sztop); free1(cztop); } else { sztop = cztop; } /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2; p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2; p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2; p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2; p3beg = (x3end>x3beg)?-fabs(d3s)/2:fabs(d3s)/2; p3end = (x3end>x3beg)?fabs(d3s)/2:-fabs(d3s)/2; /* get legend specs BEREND, Schoenfelder */ legend = 0; getparint("legend", &legend); /* BEREND, Schoenfelder */ getparstring("units", &units); /* BEREND, Schoenfelder */ getparstring("legendfont", &legendfont); /* BEREND, Schoenfelder */ /* Get or calc legend parameters */ /* Legend min and max: Calc from data read in */ if (legend) { for (lz=0;lz<nz;lz++) { lmin=FMIN(lmin,z[lz]); lmax=FMAX(lmax,z[lz]); } if (verbose==2) warn("lmin=%g lmax=%g",lmin,lmax); lbeg = lmin; if (getparfloat("lbeg",&lbeg)) lbegsup=1; lend = lmax; if (getparfloat("lend",&lend)) lendsup=1; /* Change wclip,bclip to be inside legend range */ wclip = FMAX(lbeg,wclip); /* [wclip,bclip] has to be in [lbeg,lend] */ bclip = FMIN(lend,bclip); if (lbegsup!=1) { /* Add white and black areas to show possible clipping */ float rangeperc=(bclip-wclip)/20.; lbeg=wclip-rangeperc; } if (lendsup!=1) { float rangeperc=(bclip-wclip)/20.; lend=bclip+rangeperc; } lfnum = lmin; getparfloat("lfnum",&lfnum); getparstring("lstyle",&lstyles); if (STREQ("vertright",lstyles)) lstyle = VERTRIGHT; else if (STREQ("horibottom",lstyles)) lstyle = HORIBOTTOM; /* legend dimensions (BEREND), Schoenfelder */ lwidth = 0.1 ;lheight = size1+sin(angle)*size3/2; if (lstyle==HORIBOTTOM) { lwidth=size2+cos(angle)*size3/1.2 ;lheight = 0.24; } getparfloat("lwidth",&lwidth); getparfloat("lheight",&lheight); lx=.8;ly = ybox+(size1+sin(angle)*size3-lheight)/2; if (lstyle==VERTRIGHT) { lx=xbox+size2+cos(angle)*size3+0.1; } else if (lstyle==HORIBOTTOM) { lx=xbox+(size2+cos(angle)*size3-lwidth)/2.0;ly = 1.0; } getparfloat("lx",&lx); getparfloat("ly",&ly); getparstring("lgrid",&lgrids); if (STREQ("dot",lgrids)) ugrid = DOT; else if (STREQ("dash",lgrids)) ugrid = DASH; else if (STREQ("solid",lgrids)) ugrid = SOLID; else ugrid = NONE; } if (legend) { /* Make legend color values */ int lll=0,lcount,perc5=13,ilbeg,ilend; /* color scale */ if (lbegsup!=1) { ln+=perc5; /* white area */ } if (lendsup!=1) { ln+=perc5; /* black area */ } data_legend = ealloc1(ln,sizeof(char)); if (lbegsup!=1) { for (lll=0;lll<perc5;lll++) data_legend[lll]=(char) 255; /* white area */ } for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount; if (lendsup!=1) { for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */ } lf=lbeg;ld=(lend-lbeg)/(ln-1); if (!(getparfloat("ldnum",&ldnum))) ldnum=0.0; /* adjust lbeg and lend to fall on sampled values */ ilbeg = NINT((lbeg-lf)/ld); ilbeg = MAX(0,MIN(ln-1,ilbeg)); lbeg = lf+ilbeg*ld; ilend = NINT((lend-lf)/ld); ilend = MAX(0,MIN(ln-1,ilend)); lend = lf+ilend*ld; /* convert legend parameters to points */ lx *= 72.0; /* Schoenfelder */ ly *= 72.0; /* Schoenfelder */ lwidth *= 72.0; /* Schoenfelder */ lheight *= 72.0; /* Schoenfelder */ } /* convert axes parameters to points */ size1 *= 72; size2 *= 72; size3 *= 72; xbox *= 72; ybox *= 72; /* set bounding box */ psAxesBBox(xbox,ybox,size2+cos(angle)*size3,size1+sin(angle)*size3, labelfont,labelsize,titlefont,titlesize,style,bbox); if (legend) { psLegendBBox( /* Space for legend Schoenfelder */ lx,ly,lwidth,lheight, labelfont,labelsize, lstyle,lbbox); /* Include space for legend Schoenfelder */ bbox[0]=MIN(bbox[0],lbbox[0]); bbox[1]=MIN(bbox[1],lbbox[1]); bbox[2]=MAX(bbox[2],lbbox[2]); bbox[3]=MAX(bbox[3],lbbox[3]); } boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ begineps(); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* begin front */ gsave(); /* transform coordinates */ translate(0,0); scale(size2,size1); /* determine image matrix */ matrix[0] = 0; matrix[1] = n2s; matrix[2] = -n1s; matrix[3] = 0; matrix[4] = n1s; matrix[5] = 0; /* draw the image */ drawimage(hls,colors,n1s,n2s,bps,matrix,szfront); /* end front */ grestore(); /* begin side */ gsave(); /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = tan(angle); matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(size2,0); concat(matrix); scale(size3*cos(angle),size1); /* determine image matrix */ matrix[0] = 0; matrix[1] = n3s; matrix[2] = -n1s; matrix[3] = 0; matrix[4] = n1s; matrix[5] = 0; /* draw the image */ drawimage(hls,colors,n1s,n3s,bps,matrix,szside); /* end side */ grestore(); /* begin top */ gsave(); /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = 0; matrix[2] = 1.0/tan(angle); matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(0,size1); concat(matrix); scale(size2,size3*sin(angle)); /* determine image matrix */ matrix[0] = n2s; matrix[1] = 0; matrix[2] = 0; matrix[3] = n3s; matrix[4] = 0; matrix[5] = 0; /* draw the image */ drawimage(hls,colors,n2s,n3s,bps,matrix,sztop); /* end top */ grestore(); if (legend) { gsave(); /* translate coordinate system by box offset */ translate(-xbox,-ybox); translate(lx,ly); scale(lwidth,lheight); if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) { labmatrix[0] = 1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); } else { labmatrix[0] = -1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; rotate(-90); drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); rotate(90); } grestore(); } /* restore graphics state */ grestore(); psCubeAxesBox(xbox,ybox,size1,size2,size3,angle, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, x3beg,x3end,p3beg,p3end, d3num,f3num,n3tic,grid3,label3, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor); /* draw axes and title for legend Schoenfelder*/ if (legend) { float lpbeg,lpend; int lntic=1; gsave(); lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/ lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/ psLegendBox( lx,ly,lwidth,lheight, lbeg,lend,lpbeg,lpend, ldnum,lf,lntic,ugrid,units, labelfont,labelsize, axescolor,gridcolor, lstyle); grestore(); } /* end PostScript */ showpage(); endeps(); return 0; }
main(int argc, char **argv) { int i, j, k, l, m, n, len_seq[100], reallen[100]; char **chrname; int *dir, **breaks, **colorindex, base[2]; char **brchrname; int *multip, *multip2, *repeat_length, num_repeat, *startpos, *numsegment; int num_ins, *insertpos, *insertlen; int global_scale; SEGMENT *segment, segment0; long int START_POS; int num_segment; int **repeats; int range[2]; int num_chro; char name[1000], temp[1000], c; char pt; FILE *fp, *fp1; if(argc < 4) { printf("Usage: makefig intv_file output_file(ps format) chrolistfile\n"); exit(-1); } chrname = alloc_name(100, 100); fp = ckopen(argv[3], "r"); num_chro = readchrolist(len_seq, chrname, reallen, fp); fclose(fp); segment = (SEGMENT *) ckalloc(20000 * sizeof(SEGMENT)); fp = ckopen(argv[1], "r"); num_segment = input_segment(segment, chrname, num_chro, fp); fclose(fp); /* Sort the segments */ qsort((void *) segment, num_segment, sizeof(SEGMENT), (void *) segcompar); /* for(i = 0; i < num_segment; i ++) { printf("aftersort segment %d %d %d\n", segment[i].pos[0], segment[i].pos[1], segment[i].eq_pos[1]); } getchar(); */ /* Compute multiplicity of each sub-repeat */ repeat_length = (int *) ckalloc(20000 * sizeof(int)); multip = (int *) ckalloc(20000 * sizeof(int)); num_repeat = 0; k = 0; for(i = 0; i < num_segment; i ++) { repeat_length[segment[i].eq_pos[0] - 1] = segment[i].length; multip[segment[i].eq_pos[0] - 1] ++; if(segment[i].eq_pos[0] > num_repeat) { num_repeat = segment[i].eq_pos[0]; } } printf("num_repeat %d\n", num_repeat); global_scale = 25; multip2 = (int *) ckalloc(num_repeat * sizeof(int)); repeats = (int **) ckalloc(num_repeat * sizeof(int *)); for(i = 0; i < num_repeat; i ++) { repeats[i] = (int *) ckalloc((1 + multip[i]) * sizeof(int)); } startpos = (int *) ckalloc(num_segment * sizeof(int)); numsegment = (int *) ckalloc(num_segment * sizeof(int)); breaks = (int **) ckalloc(num_segment * sizeof(int *)); brchrname = (char **) ckalloc(num_segment * sizeof(char *)); colorindex = (int **) ckalloc(num_segment * sizeof(int *)); for(i = 0; i < num_segment; i ++) { breaks[i] = (int *) ckalloc(num_segment * sizeof(int)); brchrname[i] = (char *) ckalloc(100 * sizeof(char)); colorindex[i] = (int *) ckalloc(num_segment * sizeof(int)); } dir = (int *) ckalloc(num_segment * sizeof(int)); k = m = 0; fp = ckopen(argv[2], "w"); prt_Header(fp, "Tang Hai-xu", "OUTPUT", "2-21-2004", 0); prt_Macro(fp); scale[0] = 0.7; scale[1] = 0.8; change_scale(fp, scale); base[0] = 50; base[1] = 850; for(i = 0; i < num_segment; i ++) { if(i == num_segment - 1 || segment[i + 1].pos[0] > segment[i].pos[1] + min_length || segment[i + 1].chro != segment[i].chro) { for(j = k; j <= i; j ++) { breaks[m][j - k + 1] += segment[j].pos[1] - segment[k].pos[0] + 1; colorindex[m][j - k] = segment[j].eq_pos[0]; dir[j - k] = segment[j].eq_pos[1]; repeats[segment[j].eq_pos[0] - 1][multip2[segment[j].eq_pos[0] - 1] ++] = m; } startpos[m] = range[0] = segment[k].pos[0]; numsegment[m] = i - k + 1; strcpy(brchrname[m], chrname[segment[i].chro]); range[1] = segment[i].pos[1]; sprintf(name, "R%d", m + 1); l = output_region(fp, base, name, chrname[segment[k].chro], range, global_scale, breaks[m], i - k + 2, colorindex[m], dir); m ++; base[0] = 50; base[1] -= 25; if(base[1] < 150) { showpage(fp); fprintf(fp, "%%%%Page: P%d\n", npages); npages ++; change_scale(fp, scale); base[0] = 50; base[1] = 850; } k = i + 1; } } showpage(fp); fprintf(fp, "%%%%Page: P%d\n", npages); npages ++; change_scale(fp, scale); fflush(fp); for(i = 0; i < num_repeat; i ++) { if(multip[i] != multip2[i]) { printf("i %d multip %d %d\n", i, multip[i], multip2[i]); exit(0); } } output_length_legend(fp); output_legend(fp, repeat_length, multip, num_repeat, repeats); showpage(fp); fprintf(fp, "%%%%Page: P%d\n", npages); npages ++; change_scale(fp, scale); output_repeat_legend(fp, startpos, breaks, numsegment, colorindex, brchrname, m); showpage(fp); page_trailer(fp); restore_scale(fp); prt_Trailer(fp, k + 1); fclose(fp); printf("%d regions output.\n", m); chrname = free_name(chrname, 100); for(i = 0; i < num_repeat; i ++) { free((void *) repeats[i]); } free((void **) repeats); free((void *) repeat_length); for(i = 0; i < num_segment; i ++) { free((void *) brchrname[i]); free((void *) breaks[i]); free((void *) colorindex[i]); } free((void *) multip); free((void *) multip2); free((void **) brchrname); free((void **) breaks); free((void **) colorindex); free((void *) startpos); free((void *) numsegment); free((void *) dir); free((void *) segment); }
void output_legend(FILE *fp, int *repeat_length, int *multip, int num_repeat, int **repeats) { int i, j, k, l, m, n; int base[50], point[4][2]; char c, name[100], temp[100]; char **str; double label[3]; str = (char **) ckalloc(10 * sizeof(char *)); for(i = 0; i < 10; i ++) { str[i] = (char *) ckalloc(100 * sizeof(char)); } sprintf(str[0], "Subrepeat ID"); sprintf(str[1], "Length"); sprintf(str[2], "Multiplicity"); sprintf(str[3], "Repeats"); sprintf(str[4], "Color coding"); base[0] = 50; base[1] = 680; outputline(fp, str, 5, base, 60, 10); for(i = 0; i < num_repeat; i ++) { if(multip[i] == 0) continue; sprintf(name, "s%d", i + 1); strcpy(str[0], name); sprintf(str[1], "%d", repeat_length[i]); sprintf(str[2], "%d", multip[i]); str[3][0] = '\0'; for(j = 0; j < min(multip[i], MIN_NUM); j ++) { sprintf(temp, "R%d ", repeats[i][j] + 1); strcat(str[3], temp); } base[0] = 50; base[1] -= 10; outputline(fp, str, 4, base, 60, 8); point[0][0] = 370; point[0][1] = base[1]; point[1][0] = 370 + length_intv(repeat_length[i]); point[1][1] = base[1]; point[2][0] = 370 + length_intv(repeat_length[i]); point[2][1] = base[1] + 5; point[3][0] = 370; point[3][1] = base[1] + 5; m = i % total_color; for(j = 0; j < 3; j ++) { label[j] = color_box[m][j]; } prt_box(fp, point, label, 0, 0, 0); base[0] = 370 + length_intv(repeat_length[i]) / 2; base[1] += 2; prt_Text(fp, name, base, 8, 0); if(base[1] <= 50 && i < num_repeat - 1) { base[0] = 50; base[1] = 800; showpage(fp); fprintf(fp, "%%%%Page: P%d\n", npages); npages ++; change_scale(fp, scale); } } for(i = 0; i < 10; i ++) { free((void *) str[i]); } free((void *) str); }
void viewer(Document *dd) { int i, fd, n, oldpage; int nxt; Menu menu, midmenu; Mouse m; Event e; Point dxy, oxy, xy0; Image *tmp; static char *fwditems[] = { "this page", "next page", "exit", 0 }; static char *miditems[] = { "orig size", "zoom in", "fit window", "rotate 90", "upside down", "", "next", "prev", "zerox", "", "reverse", "discard", "write", "", "quit", 0 }; char *s; enum { Eplumb = 4 }; Plumbmsg *pm; doc = dd; /* save global for menuhit */ ul = screen->r.min; einit(Emouse|Ekeyboard); if(doc->addpage != nil) eplumb(Eplumb, "image"); esetcursor(&reading); /* * im is a global pointer to the current image. * eventually, i think we will have a layer between * the display routines and the ps/pdf/whatever routines * to perhaps cache and handle images of different * sizes, etc. */ im = 0; page = reverse ? doc->npage-1 : 0; if(doc->fwdonly) { menu.item = fwditems; menu.gen = 0; menu.lasthit = 0; } else { menu.item = 0; menu.gen = menugen; menu.lasthit = 0; } midmenu.item = miditems; midmenu.gen = 0; midmenu.lasthit = Next; if(doc->docname != nil) setlabel(doc->docname); showpage(page, &menu); esetcursor(nil); nxt = 0; for(;;) { /* * throughout, if doc->fwdonly is set, we restrict the functionality * a fair amount. we don't care about doc->npage anymore, and * all that can be done is select the next page. */ unlockdisplay(display); i = eread(Emouse|Ekeyboard|Eplumb, &e); lockdisplay(display); switch(i){ case Ekeyboard: if(e.kbdc <= 0xFF && isdigit(e.kbdc)) { nxt = nxt*10+e.kbdc-'0'; break; } else if(e.kbdc != '\n') nxt = 0; switch(e.kbdc) { case 'r': /* reverse page order */ if(doc->fwdonly) break; reverse = !reverse; menu.lasthit = doc->npage-1-menu.lasthit; /* * the theory is that if we are reversing the * document order and are on the first or last * page then we're just starting and really want * to view the other end. maybe the if * should be dropped and this should happen always. */ if(page == 0 || page == doc->npage-1) { page = doc->npage-1-page; showpage(page, &menu); } break; case 'w': /* write bitmap of current screen */ esetcursor(&reading); s = writebitmap(); if(s) string(screen, addpt(screen->r.min, Pt(5,5)), display->black, ZP, display->defaultfont, s); esetcursor(nil); flushimage(display, 1); break; case 'd': /* remove image from working set */ if(doc->rmpage && page < doc->npage) { if(doc->rmpage(doc, page) >= 0) { if(doc->npage < 0) wexits(0); if(page >= doc->npage) page = doc->npage-1; showpage(page, &menu); } } break; case 'q': case 0x04: /* ctrl-d */ wexits(0); case 'u': if(im==nil) break; angle = (angle+180) % 360; showpage(page, &menu); break; case '-': case '\b': case Kleft: if(page > 0 && !doc->fwdonly) { --page; showpage(page, &menu); } break; case '\n': if(nxt) { nxt--; if(nxt >= 0 && nxt < doc->npage && !doc->fwdonly) showpage(page=nxt, &menu); nxt = 0; break; } goto Gotonext; case Kright: case ' ': Gotonext: if(doc->npage && ++page >= doc->npage && !doc->fwdonly) wexits(0); showpage(page, &menu); break; /* * The upper y coordinate of the image is at ul.y in screen->r. * Panning up means moving the upper left corner down. If the * upper left corner is currently visible, we need to go back a page. */ case Kup: if(screen->r.min.y <= ul.y && ul.y < screen->r.max.y){ if(page > 0 && !doc->fwdonly){ --page; showbottom = 1; showpage(page, &menu); } } else { i = Dy(screen->r)/2; if(i > 10) i -= 10; if(i+ul.y > screen->r.min.y) i = screen->r.min.y - ul.y; translate(Pt(0, i)); } break; /* * If the lower y coordinate is on the screen, we go to the next page. * The lower y coordinate is at ul.y + Dy(im->r). */ case Kdown: i = ul.y + Dy(im->r); if(screen->r.min.y <= i && i <= screen->r.max.y){ ul.y = screen->r.min.y; goto Gotonext; } else { i = -Dy(screen->r)/2; if(i < -10) i += 10; if(i+ul.y+Dy(im->r) <= screen->r.max.y) i = screen->r.max.y - Dy(im->r) - ul.y - 1; translate(Pt(0, i)); } break; default: esetcursor(&query); sleep(1000); esetcursor(nil); break; } break; case Emouse: m = e.mouse; switch(m.buttons){ case Left: oxy = m.xy; xy0 = oxy; do { dxy = subpt(m.xy, oxy); oxy = m.xy; translate(dxy); unlockdisplay(display); m = emouse(); lockdisplay(display); } while(m.buttons == Left); if(m.buttons) { dxy = subpt(xy0, oxy); translate(dxy); } break; case Middle: if(doc->npage == 0) break; unlockdisplay(display); n = emenuhit(Middle, &m, &midmenu); lockdisplay(display); if(n == -1) break; switch(n){ case Next: /* next */ if(reverse) page--; else page++; if(page < 0) { if(reverse) return; else page = 0; } if((page >= doc->npage) && !doc->fwdonly) return; showpage(page, &menu); nxt = 0; break; case Prev: /* prev */ if(reverse) page++; else page--; if(page < 0) { if(reverse) return; else page = 0; } if((page >= doc->npage) && !doc->fwdonly && !reverse) return; showpage(page, &menu); nxt = 0; break; case Zerox: /* prev */ zerox(); break; case Zin: /* zoom in */ { double delta; Rectangle r; r = egetrect(Middle, &m); if((rectclip(&r, rectaddpt(im->r, ul)) == 0) || Dx(r) == 0 || Dy(r) == 0) break; /* use the smaller side to expand */ if(Dx(r) < Dy(r)) delta = (double)Dx(im->r)/(double)Dx(r); else delta = (double)Dy(im->r)/(double)Dy(r); esetcursor(&reading); tmp = xallocimage(display, Rect(0, 0, (int)((double)Dx(im->r)*delta), (int)((double)Dy(im->r)*delta)), im->chan, 0, DBlack); if(tmp == nil) { fprint(2, "out of memory during zoom: %r\n"); wexits("memory"); } resample(im, tmp); im = tmp; delayfreeimage(tmp); esetcursor(nil); ul = screen->r.min; redraw(screen); flushimage(display, 1); break; } case Fit: /* fit */ { double delta; Rectangle r; delta = (double)Dx(screen->r)/(double)Dx(im->r); if((double)Dy(im->r)*delta > Dy(screen->r)) delta = (double)Dy(screen->r)/(double)Dy(im->r); r = Rect(0, 0, (int)((double)Dx(im->r)*delta), (int)((double)Dy(im->r)*delta)); esetcursor(&reading); tmp = xallocimage(display, r, im->chan, 0, DBlack); if(tmp == nil) { fprint(2, "out of memory during fit: %r\n"); wexits("memory"); } resample(im, tmp); im = tmp; delayfreeimage(tmp); esetcursor(nil); ul = screen->r.min; redraw(screen); flushimage(display, 1); break; } case Rot: /* rotate 90 */ angle = (angle+90) % 360; showpage(page, &menu); break; case Upside: /* upside-down */ angle = (angle+180) % 360; showpage(page, &menu); break; case Restore: /* restore */ showpage(page, &menu); break; case Reverse: /* reverse */ if(doc->fwdonly) break; reverse = !reverse; menu.lasthit = doc->npage-1-menu.lasthit; if(page == 0 || page == doc->npage-1) { page = doc->npage-1-page; showpage(page, &menu); } break; case Write: /* write */ esetcursor(&reading); s = writebitmap(); if(s) string(screen, addpt(screen->r.min, Pt(5,5)), display->black, ZP, display->defaultfont, s); esetcursor(nil); flushimage(display, 1); break; case Del: /* delete */ if(doc->rmpage && page < doc->npage) { if(doc->rmpage(doc, page) >= 0) { if(doc->npage < 0) wexits(0); if(page >= doc->npage) page = doc->npage-1; showpage(page, &menu); } } break; case Exit: /* exit */ return; case Empty1: case Empty2: case Empty3: break; }; case Right: if(doc->npage == 0) break; oldpage = page; unlockdisplay(display); n = emenuhit(RMenu, &m, &menu); lockdisplay(display); if(n == -1) break; if(doc->fwdonly) { switch(n){ case 0: /* this page */ break; case 1: /* next page */ showpage(++page, &menu); break; case 2: /* exit */ return; } break; } if(n == doc->npage) return; else page = reverse ? doc->npage-1-n : n; if(oldpage != page) showpage(page, &menu); nxt = 0; break; } break; case Eplumb: pm = e.v; if(pm->ndata <= 0){ plumbfree(pm); break; } if(plumbquit(pm)) exits(nil); if(showdata(pm)) { s = estrdup("/tmp/pageplumbXXXXXXX"); fd = opentemp(s); write(fd, pm->data, pm->ndata); /* lose fd reference on purpose; the file is open ORCLOSE */ } else if(pm->data[0] == '/') { s = estrdup(pm->data); } else { s = emalloc(strlen(pm->wdir)+1+pm->ndata+1); sprint(s, "%s/%s", pm->wdir, pm->data); cleanname(s); } if((i = doc->addpage(doc, s)) >= 0) { page = i; unhide(); showpage(page, &menu); } free(s); plumbfree(pm); break; } } }
int main (int argc, char **argv) { int n1,n2,n3,i1,i2,i3, n1tic,n2tic,n3tic,grid1,grid2,grid3,nz,iz, faces,style=SEISMIC,bbox[4], npar,nc,nplaces,ic; int labelcf, nlabelc, labelcper; float d1,d2,d3,f1,f2,f3,size1,size2,size3,xbox,ybox,angle, x1min,x1max,x2min,x2max,x3min,x3max, x1beg,x1end,x2beg,x2end,x3beg,x3end, d1num,f1num,d2num,f2num,d3num,f3num, p1beg,p1end,p2beg,p2end,p3beg,p3end, labelsize,titlesize, *z,*zfront,*zside,*ztop,*temp,matrix[6], cwidth[NCMAX],cgray[NCMAX],cdash[NCMAX], dc,fc,*x1,*x2,*x3,c[NCMAX],zmin,zmax, x1scale,x2scale,x3scale; float labelcsize,lcsize,*w,*wfront,*wside,*wtop; char *label1="",*label2="",*label3="",*title="", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *labelcfont="Helvetica-Bold",*labelccolor="black", *grid1s="none",*grid2s="none",*grid3s="none", *titlecolor="black",*axescolor="black",*gridcolor="black", *frontf,*sidef,*topf, *scolor="none",*ccolor[NCMAX]; FILE *infp=stdin,*frontfp,*sidefp,*topfp; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); if (!getparfloat("d1",&d1)) d1 = 1.0; if (!getparfloat("f1",&f1)) f1 = 0.0; x1 = ealloc1float(n1); for (i1=0; i1<n1; i1++) x1[i1] = f1+i1*d1; for (i1=1,x1min=x1max=x1[0]; i1<n1; i1++) { x1min = MIN(x1min,x1[i1]); x1max = MAX(x1max,x1[i1]); } /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) err("must specify n2!\n"); if (!getparfloat("d2",&d2)) d2 = 1.0; if (!getparfloat("f2",&f2)) f2 = 0.0; x2 = ealloc1float(n2); for (i2=0; i2<n2; i2++) x2[i2] = f2+i2*d2; for (i2=1,x2min=x2max=x2[0]; i2<n2; i2++) { x2min = MIN(x2min,x2[i2]); x2max = MAX(x2max,x2[i2]); } /* get parameters describing 3rd dimension sampling */ if (!getparint("n3",&n3)) err("must specify n3!\n"); if (n3<2)err("must have n3>=2!"); if (!getparfloat("d3",&d3)) d3 = 1.0; if (!getparfloat("f3",&f3)) f3 = 0.0; x3 = ealloc1float(n3); for (i3=0; i3<n3; i3++) x3[i3] = f3+i3*d3; for (i3=1,x3min=x3max=x3[0]; i3<n3; i3++) { x3min = MIN(x3min,x3[i3]); x3max = MAX(x3max,x3[i3]); } /* determine input type */ if (!getparint("faces",&faces)) faces = 0; /* allocate space */ nz = n1*n2+n1*n3+n2*n3; z = ealloc1float(nz); zfront = z; zside = zfront+n1*n2; ztop = zside+n1*n3; /* read data */ if (getparstring("front",&frontf) && getparstring("side",&sidef) && getparstring("top",&topf)) { /* read face files */ if ((frontfp = fopen(frontf,"r")) == NULL) err("error opening front file!\n"); if (fread(zfront,sizeof(float),n1*n2,frontfp)!=n1*n2) err("error reading front file!\n"); if ((sidefp = fopen(sidef,"r")) == NULL) err("error opening side file!\n"); if (fread(zside,sizeof(float),n1*n3,sidefp)!=n1*n3) err("error reading side file!\n"); if ((topfp = fopen(topf,"r")) == NULL) err("error opening top file!\n"); if (fread(ztop,sizeof(float),n2*n3,topfp)!=n2*n3) err("error reading top file!\n"); } else if (getparstring("front",&frontf) || getparstring("side",&sidef) || getparstring("top",&topf)) { err("must specify all or none of face, side, and top!\n"); } else if (faces) { /* read faces from stdin */ if (fread(zfront,sizeof(float),n1*n2,infp)!=n1*n2) err("error reading front from input!\n"); if (fread(zside,sizeof(float),n1*n3, infp)!=n1*n3) err("error reading side from input!\n"); if (fread(ztop,sizeof(float),n2*n3, infp)!=n2*n3) err("error reading top from input!\n"); } else { /* read cube from stdin, pick off faces */ temp = ealloc1float(n1); for (i3=0; i3<n3; i3++) { for (i2=0; i2<n2; i2++) { if (fread(temp,sizeof(float),n1,infp)!=n1) err("error reading cube from input!\n"); if (i3==0) for (i1=0; i1<n1; i1++) zfront[i1+i2*n1] = temp[i1]; if (i2==n2-1) for (i1=0; i1<n1; i1++) zside[i1+i3*n1] = temp[i1]; ztop[i2+i3*n2] = temp[0]; } } free1float(temp); } /* zero w array for contour labeling */ w = ealloc1float(nz); wfront = w; wside = wfront+n1*n2; wtop = wside+n1*n3; for(iz=0; iz<nz; iz++) w[iz] = 0.; /* determine data min and max */ for (iz=0,zmin=zmax=z[0]; iz<nz; iz++){ zmin = MIN(zmin,z[iz]); zmax = MAX(zmax,z[iz]); } /* get contouring parameters */ if ((nc=getparfloat("c",c))==0) { nc = 5; getparint("nc",&nc); dc = (zmax-zmin)/nc; getparfloat("dc",&dc); fc = zmin+dc; getparfloat("fc",&fc); for (ic=0; ic<nc; ic++) c[ic] = fc+ic*dc; } for (ic=0; ic<nc; ic++) { cwidth[ic] = 1.0; cgray[ic] = 0.0; cdash[ic] = 0.0; ccolor[ic] = scolor; } if ((npar=getparfloat("cwidth",cwidth))!=0) for (ic=npar; ic<nc; ic++) cwidth[ic] = cwidth[npar-1]; if ((npar=getparfloat("cgray",cgray))!=0) for (ic=npar; ic<nc; ic++) cgray[ic] = cgray[npar-1]; if ((npar=getparfloat("cdash",cdash))!=0) for (ic=npar; ic<nc; ic++) cdash[ic] = cdash[npar-1]; if (getparstring("ccolor",&scolor)) { int i,j; char *s; for (i=0,s=strtok(scolor,","); s!=NULL; ++i,s=strtok(NULL,",")) ccolor[i] = s; for (j=i-1; i<nc; ++i) ccolor[i] = ccolor[j]; } labelcf = 1; getparint("labelcf",&labelcf); labelcper = 1; getparint("labelcper",&labelcper); nlabelc = nc; getparint("nlabelc",&nlabelc); labelcsize = 6; getparfloat("labelcsize",&labelcsize); getparstring("labelcfont",&labelcfont); getparstring("labelccolor",&labelccolor); if (!getparint("nplaces",&nplaces)) nplaces = 6; /* get axes parameters, convert to points */ if(!getparfloat("size1",&size1)) size1 = 4.0; if(!getparfloat("size2",&size2)) size2 = 4.0; if(!getparfloat("size3",&size3)) size3 = 3.0; if (!getparfloat("xbox",&xbox)) xbox = 1.5; if (!getparfloat("ybox",&ybox)) ybox = 1.5; size1 *= 72; size2 *= 72; size3 *= 72; xbox *= 72; ybox *= 72; /* get projection angle, convert to radians */ if(!getparfloat("angle",&angle)) angle = 45.0; angle = MAX(angle,0.00001); angle = MIN(angle,90.0); angle *= PI/180.0; /* get axis1 parameters */ x1beg = x1min; x1end = x1max; getparfloat("x1end",&x1end); d1num = 0.0; getparfloat("d1num",&d1num); f1num = x1min; getparfloat("f1num",&f1num); n1tic = 1; getparint("n1tic",&n1tic); getparstring("grid1",&grid1s); if (STREQ("dot",grid1s)) grid1 = DOT; else if (STREQ("dash",grid1s)) grid1 = DASH; else if (STREQ("solid",grid1s)) grid1 = SOLID; else grid1 = NONE; getparstring("label1",&label1); /* get axis2 parameters */ x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; d2num = 0.0; getparfloat("d2num",&d2num); f2num = x2min; getparfloat("f2num",&f2num); n2tic = 1; getparint("n2tic",&n2tic); getparstring("grid2",&grid2s); if (STREQ("dot",grid2s)) grid2 = DOT; else if (STREQ("dash",grid2s)) grid2 = DASH; else if (STREQ("solid",grid2s)) grid2 = SOLID; else grid2 = NONE; getparstring("label2",&label2); /* get axis3 parameters */ x3beg = x3min; x3end = x3max; getparfloat("x3end",&x3end); d3num = 0.0; getparfloat("d3num",&d3num); f3num = x3min; getparfloat("f3num",&f3num); n3tic = 1; getparint("n3tic",&n3tic); getparstring("grid3",&grid3s); if (STREQ("dot",grid3s)) grid3 = DOT; else if (STREQ("dash",grid3s)) grid3 = DASH; else if (STREQ("solid",grid3s)) grid3 = SOLID; else grid3 = NONE; getparstring("label3",&label3); /* get additional font parameters */ getparstring("labelfont",&labelfont); labelsize = 18.0; getparfloat("labelsize",&labelsize); getparstring("title",&title); getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("titlecolor",&titlecolor); getparstring("axescolor",&axescolor); getparstring("gridcolor",&gridcolor); style = SEISMIC; /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1)/2:fabs(d1)/2; p1end = (x1end>x1beg)?fabs(d1)/2:-fabs(d1)/2; p2beg = (x2end>x2beg)?-fabs(d2)/2:fabs(d2)/2; p2end = (x2end>x2beg)?fabs(d2)/2:-fabs(d2)/2; p3beg = (x3end>x3beg)?-fabs(d3)/2:fabs(d3)/2; p3end = (x3end>x3beg)?fabs(d3)/2:-fabs(d3)/2; /* set bounding box */ psAxesBBox(xbox,ybox,size2+cos(angle)*size3,size1+sin(angle)*size3, labelfont,labelsize,titlefont,titlesize,style,bbox); boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ begineps(); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* begin top */ gsave(); /* determine x2 and x3 scale factors */ x2scale = size2/(x2end-x2beg); x3scale = size3*sin(angle)/(x3end-x3beg); /* scale x2 and x3 coordinates */ for (i2=0; i2<n2; i2++) x2[i2] *= x2scale; for (i3=0; i3<n3; i3++) x3[i3] *= x3scale; /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = 0; matrix[2] = 1/tan(angle); matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(-(f2-x2min+x2beg)*x2scale-f3*x3scale/tan(angle),size1-f3*x3scale); concat(matrix); rectclip(x2beg*x2scale,f3*x3scale,size2,size3*sin(angle)); /* draw contours */ for (ic=0; ic<nc; ic++) { setlinewidth(cwidth[ic]); if (strcmp(ccolor[ic],"none")) setcolor(ccolor[ic]); else setgray(cgray[ic]); if (cdash[ic]!=0.0) setdash(&cdash[ic],1,0.0); else setdash(&cdash[ic],0,0.0); lcsize = 0.; if (nlabelc>0) { if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1 && ic<labelcf-1+labelcper*nlabelc) { setlinewidth(cwidth[ic]); lcsize = labelcsize; } else { lcsize = 0.; setlinewidth(0.25*cwidth[ic]); } } /* no labels -> lcsize=0 to psContour */ psContour(c[ic],n2,x2,n3,x3,ztop,0,labelcfont,labelccolor,wtop,nplaces); } /* unscale x2 and x3 coordinates */ for (i2=0; i2<n2; i2++) x2[i2] /= x2scale; for (i3=0; i3<n3; i3++) x3[i3] /= x3scale; translate((f2-x2min+x2beg)*x2scale+f3*x3scale/tan(angle),-size1+f3*x3scale); /* end top */ grestore(); /* begin front */ gsave(); /* determine x1 and x2 scale factors */ x1scale = size1/(x1end-x1beg); x2scale = size2/(x2end-x2beg); /* scale x1 and x2 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] *= x1scale; for (i2=0; i2<n2; i2++) x2[i2] *= x2scale; rotate(-90); translate(-size1-f1*x1scale,-(f2-x2min+x2beg)*x2scale); rectclip(size1+f1*x1scale,(f2-x2min+x2beg)*x2scale,-size1,size2); /* draw contours */ for (ic=0; ic<nc; ic++) { setlinewidth(cwidth[ic]); if (strcmp(ccolor[ic],"none")) setcolor(ccolor[ic]); else setgray(cgray[ic]); if (cdash[ic]!=0.0) setdash(&cdash[ic],1,0.0); else setdash(&cdash[ic],0,0.0); lcsize = 0.; if (nlabelc>0) { if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1 && ic<labelcf-1+labelcper*nlabelc) { setlinewidth(cwidth[ic]); lcsize = labelcsize; } else { lcsize = 0.; setlinewidth(0.25*cwidth[ic]); } } psContour(c[ic],n1,x1,n2,x2,z,lcsize,labelcfont,labelccolor,w,nplaces); } /* unscale x1 and x2 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] /= x1scale; for (i2=0; i2<n2; i2++) x2[i2] /= x2scale; translate(size1+f1*x1scale,(f2-x2min+x2beg)*x2scale); rotate(90); /* end front */ grestore(); /* begin side */ gsave(); /* determine x1 and x3 scale factors */ x1scale = size1/(x1end-x1beg); x3scale = size3*cos(angle)/(x3end-x3beg); /* scale x1 and x3 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] *= x1scale; for (i3=0; i3<n3; i3++) x3[i3] *= x3scale; /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = tan(angle); matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(size2-f3*x3scale,size1+f1*x1scale-f3*x3scale*tan(angle)); concat(matrix); rectclip(f3*x3scale,-x1end*x1scale,size3*cos(angle),size1); rotate(-90); /* draw contours */ for (ic=0; ic<nc; ic++) { setlinewidth(cwidth[ic]); if (strcmp(ccolor[ic],"none")) setcolor(ccolor[ic]); else setgray(cgray[ic]); if (cdash[ic]!=0.0) setdash(&cdash[ic],1,0.0); else setdash(&cdash[ic],0,0.0); lcsize = 0.; if (nlabelc>0) { if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1 && ic<labelcf-1+labelcper*nlabelc) { setlinewidth(cwidth[ic]); lcsize = labelcsize; } else { lcsize = 0.; setlinewidth(0.25*cwidth[ic]); } } /* no labels -> lcsize=0 to psContour */ psContour(c[ic],n1,x1,n3,x3,zside,0,labelcfont,labelccolor,wside,nplaces); } /* unscale x1 and x3 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] /= x1scale; for (i3=0; i3<n3; i3++) x3[i3] /= x3scale; rotate(90); translate(-size2+f3*x3scale,-size1-f1*x1scale+f3*x3scale*tan(angle)); /* end side */ grestore(); /* restore graphics state */ grestore(); psCubeAxesBox(xbox,ybox,size1,size2,size3,angle, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, x3beg,x3end,p3beg,p3end, d3num,f3num,n3tic,grid3,label3, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor); /* end PostScript */ showpage(); endeps(); return 0; }
int main (int argc, char **argv) { char **text,**font,*textcolor,*boxcolor; float size,labelCD=0.0,labelCA,labelCW=0.0,labelCH,bigx,bigy,eps,eps2; float *x; int n,j,nsub; size_t nchar; /* Hook up getpars */ initargs(argc,argv); requestdoc(0); /* Get parameters */ if(!getparint("nsub",&nsub))nsub=0; if(!getparfloat("size",&size))size=30; if(!getparstring("tcolor",&textcolor))textcolor="black"; if(!getparstring("bcolor",&boxcolor))boxcolor="white"; checkpars(); eps=0.25*size; eps2=0.1*size; n=countparname("t"); if(n==0) err("must enter at least one PSTEXT text stream as parameter t"); if(n!=countparname("f")) warn("suggest specify same number of values for t and f"); text =(char **)malloc( (n+1)*sizeof(char *) ); font =(char **)malloc( (n+1)*sizeof(char *) ); x = (float *)malloc( (n+1)*sizeof(float) ); for(bigx=eps,bigy=0.,j=0;j<n;j++){ x[j]=bigx; if(!getnparstring(j+1,"t",&text[j]))text[j]="hello"; if(!getnparstring(j+1,"f",&font[j]))font[j]="Times-Bold"; labelCH = fontheight(font[j],size); labelCW = fontwidth(font[j],size); labelCA = fontascender(font[j],size); labelCD = MIN(labelCD,fontdescender(font[j],size)); nchar = strlen(text[j]); bigx+=0.5*(((double) nchar)*labelCW); bigy=MAX(bigy,labelCH+eps+0.0*labelCA); } bigx+=eps; bigx-=0.5*nsub*labelCW; /* open output eps file */ boundingbox(-eps2,-eps2,bigx+eps2,bigy+eps2); begineps(); gsave(); rectclip(0.,0.,bigx,bigy); /* fill background box with background color */ newpath(); moveto(0.,0.); lineto(bigx,0.); lineto(bigx,bigy); lineto(0.,bigy); closepath(); setcolor(boxcolor); fill(); /* write out text strings */ setcolor(textcolor); moveto(eps,eps-labelCD); for(j=0;j<n;j++) { setfont(font[j],size); show(text[j]); } /* close output stream */ grestore(); showpage(); endeps(); return EXIT_SUCCESS; }
int main (int argc, char **argv) { int n1,n2,n1tic,n2tic,nfloats,bbox[4], i1,i2,grid1,grid2,style, n1c,n2c,n1s,n2s,i1beg,i1end,i2beg,i2end,i1c,i2c, nz,iz,i1step,i2step,verbose,hls,bps, legend,ugrid=SOLID,lstyle=VERTLEFT,lz,lbegsup=0,lendsup=0,ln=256, lbbox[4], threecolor=0; /* BEREND, Schoenfelder */ int lnice; /* c liner */ float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip, d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi, xbox,ybox,width,height, x1beg,x1end,x2beg,x2end, x1min,x1max,x2min,x2max, d1num,f1num,d2num,f2num, p1beg,p1end,p2beg,p2end,matrix[6],colors[3][3], /* for 3 color mode */ d1s,d2s, lwidth,lheight,lx,ly,lbeg,lend,lmin=(float) FLT_MAX,lmax=(float) -FLT_MAX, ldnum,lfnum,ld,lf=0,labmatrix[6]; /* BEREND, Schoenfelder */ float axeswidth, ticwidth, gridwidth; unsigned char *cz,*czp,*sz,*data_legend=NULL; char *label1="",*label2="",*title="",*units="", *legendfont="times_roman10", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *styles="seismic",*grid1s="none",*grid2s="none", *titlecolor="black",*axescolor="black",*gridcolor="black", *lstyles="vertleft",*lgrids="none"; FILE *infp=stdin; float **x1curve=NULL,**x2curve=NULL,*curvewidth=NULL; int i,j,curve=0,*npair=NULL,ncurvecolor=0,ncurvewidth=0,ncurvedash=0,*curvedash=NULL; char **curvecolor=NULL,**curvefile=NULL; FILE *curvefp=NULL; cwp_Bool is_curve = cwp_false; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); d1 = 1.0; getparfloat("d1",&d1); f1 = 0.0; getparfloat("f1",&f1); x1min = (d1>0.0)?f1:f1+(n1-1)*d1; x1max = (d1<0.0)?f1:f1+(n1-1)*d1; /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) { if (efseeko(infp,(off_t) 0,SEEK_END)!=0) err("must specify n2 if in a pipe!\n"); nfloats = (int) (eftello(infp)/((off_t) sizeof(float))); efseeko(infp,(off_t) 0,SEEK_SET); n2 = nfloats/n1; } d2 = 1.0; getparfloat("d2",&d2); f2 = 0.0; getparfloat("f2",&f2); x2min = (d2>0.0)?f2:f2+(n2-1)*d2; x2max = (d2<0.0)?f2:f2+(n2-1)*d2; /* read color parameters */ if (!getparint("threecolor",&threecolor)) threecolor=1; bps = 8; hls = 0; /* color[][0] is black, color[][2] is white in 2 color mode */ colors[R][0] = colors[G][0] = colors[B][0] = 0.0; colors[R][1] = colors[G][1] = colors[B][1] = 0.5; colors[R][2] = colors[G][2] = colors[B][2] = 1.0; if (countparval("brgb") || countparval("wrgb")) { float brgb[3],grgb[3],wrgb[3]; brgb[R] = brgb[G] = brgb[B] = 0.0; wrgb[R] = wrgb[G] = wrgb[B] = 1.0; getparfloat("brgb",&brgb[0]); getparfloat("wrgb",&wrgb[0]); grgb[R] = (brgb[R] + wrgb[R])/2.; grgb[G] = (brgb[G] + wrgb[G])/2.; grgb[B] = (brgb[B] + wrgb[B])/2.; if (threecolor==1) getparfloat("grgb",&grgb[0]); brgb[R] = MAX(0.0,MIN(1.0,brgb[R])); grgb[R] = MAX(0.0,MIN(1.0,grgb[R])); wrgb[R] = MAX(0.0,MIN(1.0,wrgb[R])); brgb[G] = MAX(0.0,MIN(1.0,brgb[G])); grgb[G] = MAX(0.0,MIN(1.0,grgb[G])); wrgb[G] = MAX(0.0,MIN(1.0,wrgb[G])); brgb[B] = MAX(0.0,MIN(1.0,brgb[B])); grgb[B] = MAX(0.0,MIN(1.0,grgb[B])); wrgb[B] = MAX(0.0,MIN(1.0,wrgb[B])); colors[R][0] = brgb[R]; colors[R][1] = grgb[R]; colors[R][2] = wrgb[R]; colors[G][0] = brgb[G]; colors[G][1] = grgb[G]; colors[G][2] = wrgb[G]; colors[B][0] = brgb[B]; colors[B][1] = grgb[B]; colors[B][2] = wrgb[B]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } else if (countparval("bhls") || countparval("whls")) { float bhls[3],ghls[3],whls[3]; hls = 1; bhls[H] = ghls[H] = whls[H] = 0.0; bhls[L] = 0.0; ghls[L] = 0.5; whls[L] = 1.0; bhls[S] = ghls[S] = whls[S] = 0.0; getparfloat("bhls",&bhls[0]); getparfloat("whls",&whls[0]); ghls[H] = (bhls[H] + whls[H])/2.; ghls[L] = (bhls[L] + whls[L])/2.; ghls[S] = (bhls[S] + whls[S])/2.; if (threecolor==1) getparfloat("ghls",&ghls[0]); bhls[L] = MAX(0.0,MIN(1.0,bhls[L])); ghls[L] = MAX(0.0,MIN(1.0,ghls[L])); whls[L] = MAX(0.0,MIN(1.0,whls[L])); bhls[S] = MAX(0.0,MIN(1.0,bhls[S])); ghls[S] = MAX(0.0,MIN(1.0,ghls[S])); whls[S] = MAX(0.0,MIN(1.0,whls[S])); colors[H][0] = bhls[0]; colors[H][1] = ghls[0]; colors[H][2] = whls[0]; colors[L][0] = bhls[1]; colors[L][1] = ghls[1]; colors[L][2] = whls[1]; colors[S][0] = bhls[2]; colors[S][1] = ghls[2]; colors[S][2] = whls[2]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } /* get legend specs BEREND, Schoenfelder */ legend = 0; getparint("legend", &legend); /* BEREND, Schoenfelder */ getparstring("units", &units); /* BEREND, Schoenfelder */ getparstring("legendfont", &legendfont); /* BEREND, Schoenfelder */ /* set up curve plotting */ if ((curve=countparval("curve"))!=0) { curvefile=(char**)ealloc1(curve,sizeof(void*)); getparstringarray("curve",curvefile); if ((x1curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x1curve pointers\n"); if ((x2curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x2curve pointers\n"); npair=ealloc1int(curve); getparint("npair",npair); is_curve = cwp_true; } else { npair=(int *)NULL; curvefile=(char **)NULL; x1curve=(float **)NULL; x2curve=(float **)NULL; is_curve = cwp_false; } if (is_curve) { if ((ncurvecolor=countparval("curvecolor"))<curve) { curvecolor=(char**)ealloc1(curve,sizeof(void*)); if (!getparstringarray("curvecolor",curvecolor)) { curvecolor[0]=(char *)cwp_strdup("black\0"); ncurvecolor=1; } for (i=ncurvecolor; i<curve; i++) curvecolor[i]=(char *)cwp_strdup(curvecolor[ncurvecolor-1]); } else if (ncurvecolor) { curvecolor=(char**)ealloc1(ncurvecolor,sizeof(void*)); getparstringarray("curvecolor",curvecolor); } for (j=0; j<curve; j++) { curvefp=efopen(curvefile[j],"r"); x1curve[j]=ealloc1float(npair[j]); x2curve[j]=ealloc1float(npair[j]); for (i=0; i<npair[j]; i++) { fscanf(curvefp,"%f",&x1curve[j][i]); fscanf(curvefp,"%f",&x2curve[j][i]); } efclose(curvefp); } } /* read binary data to be plotted */ nz = n1*n2; z = ealloc1float(nz); if (fread(z,sizeof(float),nz,infp)!=nz) err("error reading input file!\n"); /* if necessary, determine clips from percentiles */ if (getparfloat("clip",&clip)) { bclip = clip; wclip = -clip; } if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) && !getparfloat("clip",&clip)) { perc = 100.0; getparfloat("perc",&perc); temp = ealloc1float(nz); for (iz=0; iz<nz; iz++) temp[iz] = z[iz]; if (!getparfloat("bclip",&bclip)) { bperc = perc; getparfloat("bperc",&bperc); iz = (nz*bperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); bclip = temp[iz]; } if (!getparfloat("wclip",&wclip)) { wperc = 100.0-perc; getparfloat("wperc",&wperc); iz = (nz*wperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); wclip = temp[iz]; } free1float(temp); } verbose = 1; getparint("verbose",&verbose); if (verbose) warn("bclip=%g wclip=%g",bclip,wclip); /* get scaled sampling intervals */ d1s = 1.0; getparfloat("d1s",&d1s); d2s = 1.0; getparfloat("d2s",&d2s); d1s = fabs(d1s); d1s *= d1; d2s = fabs(d2s); d2s *= d2; /* get axes parameters */ xbox = 1.5; getparfloat("xbox",&xbox); /* if psimage is called by ximage, it */ ybox = 1.5; getparfloat("ybox",&ybox); /* will xbox=1.166 and ybox=1.167 */ width = 6.0; getparfloat("wbox",&width); getparfloat("width",&width); height = 8.0;getparfloat("hbox",&height);getparfloat("height",&height); /* begin c liner */ lnice = 0; getparint("lnice",&lnice); if (lnice==1) { ybox = 2.2; /* lx=8 is set below, after getpar on lx ... c liner */ width = 5.4; height = 7.2; } /* end c liner */ x1beg = x1min; getparfloat("x1beg",&x1beg); x1end = x1max; getparfloat("x1end",&x1end); d1num = 0.0; getparfloat("d1num",&d1num); f1num = x1min; getparfloat("f1num",&f1num); n1tic = 1; getparint("n1tic",&n1tic); getparstring("grid1",&grid1s); if (STREQ("dot",grid1s)) grid1 = DOT; else if (STREQ("dash",grid1s)) grid1 = DASH; else if (STREQ("solid",grid1s)) grid1 = SOLID; else grid1 = NONE; getparstring("label1",&label1); x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; getparfloat("x2end",&x2end); d2num = 0.0; getparfloat("d2num",&d2num); f2num = 0.0; getparfloat("f2num",&f2num); n2tic = 1; getparint("n2tic",&n2tic); getparstring("grid2",&grid2s); if (STREQ("dot",grid2s)) grid2 = DOT; else if (STREQ("dash",grid2s)) grid2 = DASH; else if (STREQ("solid",grid2s)) grid2 = SOLID; else grid2 = NONE; getparstring("label2",&label2); getparstring("labelfont",&labelfont); labelsize = 18.0; getparfloat("labelsize",&labelsize); getparstring("title",&title); getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("titlecolor",&titlecolor); getparstring("axescolor",&axescolor); getparstring("gridcolor",&gridcolor); /* axes and tic width */ if(!getparfloat("axeswidth",&axeswidth)) axeswidth=1; if (!getparfloat("ticwidth",&ticwidth)) ticwidth=axeswidth; if(!getparfloat("gridwidth",&gridwidth)) gridwidth =axeswidth; if (is_curve) { if ((ncurvewidth=countparval("curvewidth"))<curve) { curvewidth=ealloc1float(curve); if (!getparfloat("curvewidth",curvewidth)) { curvewidth[0]=axeswidth; ncurvewidth=1; } for (i=ncurvewidth; i<curve; i++) curvewidth[i]=curvewidth[ncurvewidth-1]; } else { curvewidth=ealloc1float(ncurvewidth); getparfloat("curvewidth",curvewidth); } if ((ncurvedash=countparval("curvedash"))<curve) { curvedash=ealloc1int(curve); if (!getparint("curvedash",curvedash)) { curvedash[0]=0; ncurvedash=1; } for (i=ncurvedash; i<curve; i++) curvedash[i]=curvedash[ncurvedash-1]; } else { curvedash=ealloc1int(ncurvedash); getparint("curvedash",curvedash); } } getparstring("style",&styles); if (STREQ("normal",styles)) style = NORMAL; else style = SEISMIC; /* Get or calc legend parameters */ /* Legend min and max: Calc from data read in */ if (legend) { for (lz=0;lz<nz;lz++) { lmin=FMIN(lmin,z[lz]); lmax=FMAX(lmax,z[lz]); } if (verbose==2) warn("lmin=%g lmax=%g",lmin,lmax); } if (legend) { lbeg = lmin; if (getparfloat("lbeg",&lbeg)) lbegsup=1; lend = lmax; if (getparfloat("lend",&lend)) lendsup=1; /* Change wclip,bclip to be inside legend range */ wclip = FMAX(lbeg,wclip); /* [wclip,bclip] has to be in [lbeg,lend] */ bclip = FMIN(lend,bclip); if (lbegsup!=1) { /* Add white and black areas to show possible clipping */ float rangeperc=(bclip-wclip)/20.; lbeg=wclip-rangeperc; } if (lendsup!=1) { float rangeperc=(bclip-wclip)/20.; lend=bclip+rangeperc; } lfnum = lmin; getparfloat("lfnum",&lfnum); getparstring("lstyle",&lstyles); if (STREQ("vertright",lstyles)) lstyle = VERTRIGHT; else if (STREQ("horibottom",lstyles)) lstyle = HORIBOTTOM; /* legend dimensions (BEREND), Schoenfelder */ lwidth = 0.1 ;lheight = height/2; if (lstyle==HORIBOTTOM) { lwidth=width/1.2 ;lheight = 0.24; } getparfloat("lwidth",&lwidth); getparfloat("lheight",&lheight); lx=.8;ly = ybox+(height-lheight)/2; if (lstyle==VERTRIGHT) { lx=xbox+width+0.1; } else if (lstyle==HORIBOTTOM) { lx=xbox+(width-lwidth)/2.0;ly = 1.0; } getparfloat("lx",&lx); if (lnice==1) lx = 8; /* c liner */ getparfloat("ly",&ly); getparstring("lgrid",&lgrids); if (STREQ("dot",lgrids)) ugrid = DOT; else if (STREQ("dash",lgrids)) ugrid = DASH; else if (STREQ("solid",lgrids)) ugrid = SOLID; else ugrid = NONE; } /* adjust x1beg and x1end to fall on sampled values */ /* This will not allow to display an area greater than the data supplied */ i1beg = NINT((x1beg-f1)/d1); i1beg = MAX(0,MIN(n1-1,i1beg)); x1beg = f1+i1beg*d1; i1end = NINT((x1end-f1)/d1); i1end = MAX(0,MIN(n1-1,i1end)); x1end = f1+i1end*d1; /* adjust x2beg and x2end to fall on sampled values */ i2beg = NINT((x2beg-f2)/d2); i2beg = MAX(0,MIN(n2-1,i2beg)); x2beg = f2+i2beg*d2; i2end = NINT((x2end-f2)/d2); i2end = MAX(0,MIN(n2-1,i2end)); x2end = f2+i2end*d2; if (legend) { /* Make legend color values */ int lll=0,lcount,perc5=13,ilbeg,ilend; /* color scale */ if (lbegsup!=1) { ln+=perc5; /* white area */ } if (lendsup!=1) { ln+=perc5; /* black area */ } data_legend = ealloc1(ln,sizeof(char)); if (lbegsup!=1) { for (lll=0;lll<perc5;lll++) data_legend[lll]=(char) 255; /* white area */ } for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount; if (lendsup!=1) { for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */ } lf=lbeg;ld=(lend-lbeg)/(ln-1); if (!(getparfloat("ldnum",&ldnum))) ldnum=0.0; /* adjust lbeg and lend to fall on sampled values */ ilbeg = NINT((lbeg-lf)/ld); ilbeg = MAX(0,MIN(ln-1,ilbeg)); lbeg = lf+ilbeg*ld; ilend = NINT((lend-lf)/ld); ilend = MAX(0,MIN(ln-1,ilend)); lend = lf+ilend*ld; } /* allocate space for image bytes */ n1c = 1+abs(i1end-i1beg); n2c = 1+abs(i2end-i2beg); cz = ealloc1(n1c*n2c,sizeof(char)); /* convert data to be imaged into unsigned characters */ zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10; zoffset = -bclip*zscale; i1step = (i1end>i1beg)?1:-1; i2step = (i2end>i2beg)?1:-1; czp = cz; for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) { for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) { zi = zoffset+z[i1+i2*n1]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } free1float(z); /* determine sampling after scaling */ n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s)); d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1; n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s)); d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2; /* if necessary, interpolate to scaled sampling intervals */ if (n1s!=n1c || n2s!=n2c) { sz = ealloc1(n1s*n2s,sizeof(char)); intl2b(n2c,d2,0.0,n1c,d1,0.0,cz,n2s,d2s,0.0,n1s,d1s,0.0,sz); /* Interpol array */ free1(cz); } else { sz = cz; } /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2; p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2; p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2; p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2; /* convert axes box parameters from inches to points */ xbox *= 72.0; ybox *= 72.0; width *= 72.0; height *= 72.0; if (legend) { lx *= 72.0; /* Schoenfelder */ ly *= 72.0; /* Schoenfelder */ lwidth *= 72.0; /* Schoenfelder */ lheight *= 72.0; /* Schoenfelder */ } /* set bounding box */ psAxesBBox( xbox,ybox,width,height, labelfont,labelsize, titlefont,titlesize, style,bbox); if (legend) { psLegendBBox( /* Space for legend Schoenfelder */ lx,ly,lwidth,lheight, labelfont,labelsize, lstyle,lbbox); /* Include space for legend Schoenfelder */ bbox[0]=MIN(bbox[0],lbbox[0]); bbox[1]=MIN(bbox[1],lbbox[1]); bbox[2]=MAX(bbox[2],lbbox[2]); bbox[3]=MAX(bbox[3],lbbox[3]); } boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ begineps(); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* determine image matrix */ if (style==NORMAL) { matrix[0] = 0; matrix[1] = n1s; matrix[2] = n2s; matrix[3] = 0; matrix[4] = 0; matrix[5] = 0; } else { matrix[0] = n2s; matrix[1] = 0; matrix[2] = 0; matrix[3] = -n1s; matrix[4] = 0; matrix[5] = n1s; } scale(width,height); /* draw the image (before axes so grid lines are visible) */ drawimage(hls,colors,n2s,n1s,bps,matrix,sz); /***************************/ /* main image has been drawn, restore graphics state */ grestore(); /* *********************************/ /* draw the colorbar (before axes so grid lines are visible) Schoenfelder*/ if (legend) { gsave(); translate(lx,ly); scale(lwidth,lheight); if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) { labmatrix[0] = 1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); } else { labmatrix[0] = -1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; rotate(-90); drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); rotate(90); } grestore(); } /* draw curve */ for (i=0; i<curve; i++) { gsave(); psDrawCurve( xbox,ybox,width,height, x1beg,x1end,p1beg,p1end, x2beg,x2end,p2beg,p2end, x1curve[i],x2curve[i],npair[i], curvecolor[i],curvewidth[i],curvedash[i],style); grestore(); } gsave(); /* draw axes and title */ psAxesBox( xbox,ybox,width,height, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor, ticwidth,axeswidth,gridwidth, style); /* restore graphics state */ grestore(); /* draw axes and title for legend Schoenfelder*/ if (legend) { float lpbeg,lpend; int lntic=1; gsave(); lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/ lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/ psLegendBox( lx,ly,lwidth,lheight, lbeg,lend,lpbeg,lpend, ldnum,lf,lntic,ugrid,units, labelfont,labelsize, axescolor,gridcolor, lstyle); grestore(); } /* end PostScript */ showpage(); endeps(); if (curve) { free1int(npair); for (i=0; i<curve; i++) { free1float(x1curve[i]); free1float(x2curve[i]); } free1float(curvewidth); free1int(curvedash); free((void**)x1curve); free((void**)x2curve); free((void**)curvefile); free((void**)curvecolor); } return 0; }