source: branches/fitshead-branch/Utils/cpgwedg_log.c @ 1441

Last change on this file since 1441 was 3, checked in by Matthew Whiting, 18 years ago

This is the first full import of all working code to
the Duchamp repository.
Made three directories at top level:

branches/ tags/ trunk/

and trunk/ has the full set of code:
ATrous/ Cubes/ Detection/ InputComplete? InputExample? README Utils/ docs/ mainDuchamp.cc param.cc param.hh

File size: 4.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <ctype.h>
5#include <cpgplot.h>
6#include <math.h>
7#define WDGPIX 100
8void cpgwedglog(const char* side, float disp, float width, float fg, float bg, const char *label)
9{
10  /**
11   *  cpgwedglog
12   *     A C-code version of PGWEDG that writes the scale of the wedge in logarithmic
13   *     coordinates. All parameters are exactly as for cpgwedg.
14   */
15 
16  float wxa,wxb,wya,wyb, xa,xb,ya,yb; // Temporary window coord storage.
17  float vxa,vxb,vya,vyb;              // Viewport coords of wedge.
18  float oldch, newch;                 // Original and anotation character heights.
19  float ndcsiz;                       // Size of unit character height (NDC units).
20  int horiz;                          // Logical: True (=1) if wedge plotted horizontally.
21  int image;                          // Logical: Use PGIMAG (T=1) or PGGRAY (F=0).
22
23  int nside,i;                        // nside = symbolic version of side.
24  const int bot=1,top=2,lft=3,rgt=4;
25  float wedwid, wdginc, vwidth, vdisp, xch, ych, labwid, fg1, bg1;
26  float txtfrc=0.6;                       // Set the fraction of WIDTH used for anotation.
27  float txtsep=2.2;                       // Char separation between numbers and LABEL.
28  float wdgarr[WDGPIX];                   // Array to draw wedge in.
29  float tr[6] = {0.0,1.0,0.0,0.0,0.0,1.0};
30
31/*   if(pgnoto("pgwedg")) return; */
32
33  /* Get a numeric version of SIDE. */
34  if(tolower(side[0])=='b'){
35    nside = bot;
36    horiz = 1;
37  }
38  else if(tolower(side[0]=='t')){
39    nside = top;
40    horiz = 1;
41  }
42  else if(tolower(side[0]=='l')){
43    nside = lft;
44    horiz = 0;
45  }
46  else if(tolower(side[0]=='r')){
47    nside = rgt;
48    horiz = 0;
49  }
50  //   else gwarn("Invalid \"SIDE\" argument in PGWEDG.");
51  else fprintf(stdout,"%PGPLOT, Invalid \"SIDE\" argument in CPGWEDGLOG.");
52
53  /* Determine which routine to use. */
54  if(strlen(side)<2) image = 0;
55  else if(tolower(side[1])=='i') image = 1;
56  else if(tolower(side[1])=='g') image = 0;
57  else fprintf(stdout,"%PGPLOT, Invalid \"SIDE\" argument in CPGWEDGLOG.");
58
59  cpgbbuf();
60
61  /* Store the current world and viewport coords and the character height. */
62  cpgqwin(&wxa, &wxb, &wya, &wyb);
63  cpgqvp(0, &xa, &xb, &ya, &yb);
64  cpgqch(&oldch);
65
66  /* Determine the unit character height in NDC coords. */
67  cpgsch(1.0);
68  cpgqcs(0, &xch, &ych);
69  if(horiz == 1)  ndcsiz = ych;
70  else ndcsiz = xch;
71
72  /* Convert 'WIDTH' and 'DISP' into viewport units. */
73  vwidth = width * ndcsiz * oldch;
74  vdisp  = disp * ndcsiz * oldch;
75
76  /* Determine the number of character heights required under the wedge. */
77  labwid = txtsep;
78  if(strcmp(label," ")!=0) labwid = labwid + 1.0;
79 
80  /* Determine and set the character height required to fit the wedge
81     anotation text within the area allowed for it. */
82  newch = txtfrc*vwidth / (labwid*ndcsiz);
83  cpgsch(newch);
84
85  /* Determine the width of the wedge part of the plot minus the anotation.
86     (NDC units). */
87  wedwid = vwidth * (1.0-txtfrc);
88
89  /* Use these to determine viewport coordinates for the wedge + annotation. */
90  vxa = xa;
91  vxb = xb;
92  vya = ya;
93  vyb = yb;
94  if(nside==bot){
95    vyb = ya - vdisp;
96    vya = vyb - wedwid;
97  }
98  else if(nside==top) {
99    vya = yb + vdisp;
100    vyb = vya + wedwid;
101  }
102  else if(nside==lft) {
103    vxb = xa - vdisp;
104    vxa = vxb - wedwid;
105  }
106  else if(nside==rgt) {
107    vxa = xb + vdisp;
108    vxb = vxa + wedwid;
109  }
110
111  /* Set the viewport for the wedge. */
112  cpgsvp(vxa, vxb, vya, vyb);
113
114  /* Swap FG/BG if necessary to get axis direction right. */
115/*   fg1 = max(fg,bg); */
116/*   bg1 = min(fg,bg); */
117  if(fg>bg) {
118    fg1 = fg;
119    bg1 = bg;
120  }
121  else {
122    fg1 = bg;
123    bg1 = fg;
124  }
125
126
127  /* Create a dummy wedge array to be plotted. */
128  wdginc = (fg1-bg1)/(WDGPIX-1);
129  for(i=0;i<WDGPIX;i++)  wdgarr[i] = bg1 + (i-1) * wdginc;
130
131  /* Draw the wedge then change the world coordinates for labelling. */
132  if (horiz==1) {
133    cpgswin(1.0, (float)WDGPIX, 0.9, 1.1);
134    if (image==1) cpgimag(wdgarr, WDGPIX,1, 1,WDGPIX, 1,1, fg,bg, tr);
135    else          cpggray(wdgarr, WDGPIX,1, 1,WDGPIX, 1,1, fg,bg, tr);
136    cpgswin(bg1,fg1,0.0,1.0);
137  }
138  else{
139    cpgswin(0.9, 1.1, 1.0, (float)WDGPIX);
140    if (image==1) cpgimag(wdgarr, 1,WDGPIX, 1,1, 1,WDGPIX, fg,bg, tr);
141    else          cpggray(wdgarr, 1,WDGPIX, 1,1, 1,WDGPIX, fg,bg, tr);
142    cpgswin(0.0, 1.0, bg1, fg1);
143  }
144
145  /* Draw a labelled frame around the wedge -- using a logarithmic scale! */
146  if(nside==bot)  cpgbox("BCNSTL",0.0,0,"BC",0.0,0);
147  else if(nside==top) cpgbox("BCMSTL",0.0,0,"BC",0.0,0);
148  else if(nside==lft) cpgbox("BC",0.0,0,"BCNSTL",0.0,0);
149  else if(nside==rgt) cpgbox("BC",0.0,0,"BCMSTL",0.0,0);
150
151  /* Write the units label. */
152  if((strcmp(label," ")!=0)) cpgmtxt(side,txtsep,1.0,1.0,label);
153
154  /* Reset the original viewport and world coordinates. */
155  cpgsvp(xa,xb,ya,yb);
156  cpgswin(wxa,wxb,wya,wyb);
157  cpgsch(oldch);
158  cpgebuf();
159
160}
Note: See TracBrowser for help on using the repository browser.