~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/graphics/Plo2d3.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------
 
2
 *    Graphic library
 
3
 *    Copyright (C) 1998-2000 Enpc/Jean-Philippe Chancelier
 
4
 *    jpc@cereve.enpc.fr 
 
5
 --------------------------------------------------------------------------*/
 
6
 
 
7
#include <string.h>
 
8
#include <stdio.h>
 
9
#include <math.h>
 
10
#include "Math.h"
 
11
#include "PloEch.h"
 
12
 
 
13
 
 
14
static void Plo2d3RealToPixel __PARAMS((integer *n1, integer *n2, double *x, double *y, integer *xm, integer *ym, char *xf));
 
15
 
 
16
/*--------------------------------------------------------------------
 
17
  C2F(plot2d3)(xf,x,y,n1,n2,style,strflag,legend,brect,aaint)
 
18
 
 
19
  used to plot only vertical bars form (x_i,0) to (x_i,y_i)
 
20
  the arguments are similar to those of plot2d 
 
21
  the only difference is that style must have positive values 
 
22
  which are considered as dash-styles 
 
23
--------------------------------------------------------------------------*/
 
24
  
 
25
int C2F(plot2d3)(xf,x,y,n1,n2,style,strflag,legend,brect,aaint,l1,l2,l3)
 
26
     double x[],y[],brect[];
 
27
     integer   *n1,*n2,style[],aaint[];
 
28
     char legend[],strflag[],xf[];
 
29
     integer l1,l2,l3;
 
30
{
 
31
  int n;
 
32
  integer *xm,*ym;
 
33
  integer j;
 
34
  /** Attention : 2*(*n2) **/
 
35
  integer nn2=2*(*n2);
 
36
  if ( CheckxfParam(xf)== 1) return(0);
 
37
 
 
38
  /** Boundaries of the frame **/
 
39
  update_frame_bounds(0,xf,x,y,n1,n2,aaint,strflag,brect);
 
40
 
 
41
  /* Storing values if using the Record driver */
 
42
  if (GetDriver()=='R') 
 
43
    StorePlot("plot2d3",xf,x,y,n1,n2,style,strflag,legend,brect,aaint);
 
44
 
 
45
  /* Allocation */
 
46
  n = (*n1)*nn2 ; 
 
47
  if ( n != 0 ) 
 
48
    {
 
49
      xm = graphic_alloc(0,n,sizeof(int));
 
50
      ym = graphic_alloc(1,n,sizeof(int));
 
51
      if ( xm == 0 || ym == 0) 
 
52
        {
 
53
          sciprint("Running out of memory \n");
 
54
          return 0;
 
55
        }      
 
56
 
 
57
      /** Real to Pixel values **/
 
58
      Plo2d3RealToPixel(n1,n2,x,y,xm,ym,xf);
 
59
      
 
60
      /** Draw Axis or only rectangle **/
 
61
    }
 
62
  axis_draw(strflag);
 
63
  if ( n != 0 ) 
 
64
    {
 
65
      /** Drawing the curves **/
 
66
      frame_clip_on();
 
67
      /** to get the default dash **/
 
68
      for ( j = 0 ; j < (*n1) ; j++)
 
69
        {
 
70
          integer lstyle,iflag=0;
 
71
          /** style must be negative **/
 
72
          lstyle = (style[j] < 0) ?  -style[j] : style[j];
 
73
          C2F(dr)("xsegs","v",&xm[2*(*n2)*j],&ym[2*(*n2)*j],&nn2
 
74
                  ,&lstyle,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
75
        }
 
76
      frame_clip_off();
 
77
      /** Drawing the Legends **/
 
78
      if ((int)strlen(strflag) >=1  && strflag[0] == '1')
 
79
        Legends(style,n1,legend);
 
80
    }
 
81
  return(0);
 
82
}
 
83
 
 
84
 
 
85
static void Plo2d3RealToPixel(n1, n2, x, y, xm, ym, xf)
 
86
     integer *n1;
 
87
     integer *n2;
 
88
     double *x;
 
89
     double *y;
 
90
     integer *xm;
 
91
     integer *ym;
 
92
     char *xf;
 
93
{
 
94
  integer i,j;
 
95
  /** Computing y-values **/
 
96
  if ((int)strlen(xf) >= 3 && xf[2]=='l')         
 
97
    {
 
98
      for ( i=0 ; i < (*n2) ; i++)
 
99
        for (j=0 ; j< (*n1) ; j++)
 
100
          {
 
101
            ym[2*i+1+2*(*n2)*j]= YScale(0);
 
102
            ym[2*i+2*(*n2)*j]= YLogScale(y[i+(*n2)*j]);
 
103
          }
 
104
    }
 
105
  else 
 
106
    {
 
107
      for ( i=0 ; i < (*n2) ; i++)
 
108
        for (j=0 ; j< (*n1) ; j++)
 
109
          {
 
110
            ym[2*i+1+2*(*n2)*j]= YScale(0);
 
111
            ym[2*i+2*(*n2)*j]= YScale(y[i+(*n2)*j]);
 
112
          }
 
113
    }
 
114
 
 
115
  /** Computing x-values **/
 
116
  switch (xf[0])
 
117
  {
 
118
  case 'e' :
 
119
   /** No X-value given by the user **/
 
120
   if ((int)strlen(xf) >= 2 && xf[1]=='l')
 
121
     for (j=0 ; j< (*n1) ; j++)
 
122
       {
 
123
         for ( i=0 ; i < (*n2) ; i++)
 
124
           {
 
125
             xm[2*i+2*(*n2)*j]= XLogScale(i+1.0);
 
126
             xm[2*i+1+2*(*n2)*j]=xm[2*i+2*(*n2)*j];
 
127
 
 
128
           }
 
129
       }
 
130
   else 
 
131
     for (j=0 ; j< (*n1) ; j++)
 
132
       {
 
133
         for ( i=0 ; i < (*n2) ; i++)
 
134
           {
 
135
             xm[2*i+2*(*n2)*j]= XScale((i+1.0));
 
136
             xm[2*i+1+2*(*n2)*j]=xm[2*i+2*(*n2)*j];
 
137
 
 
138
           }
 
139
       }
 
140
   break ;
 
141
 case 'o' :
 
142
   if ((int)strlen(xf) >= 2 && xf[1]=='l')
 
143
     for (j=0 ; j< (*n1) ; j++)
 
144
       {
 
145
         for ( i=0 ; i < (*n2) ; i++)
 
146
           {
 
147
 
 
148
             xm[2*i+2*(*n2)*j]= XLogScale(x[i]);
 
149
             xm[2*i+1+2*(*n2)*j]=xm[2*i+2*(*n2)*j];
 
150
           }
 
151
       }
 
152
   else 
 
153
     for (j=0 ; j< (*n1) ; j++)
 
154
       {
 
155
         for ( i=0 ; i < (*n2) ; i++)
 
156
           {
 
157
             xm[2*i+2*(*n2)*j]= XScale(x[i]);
 
158
             xm[2*i+1+2*(*n2)*j]=xm[2*i+2*(*n2)*j];
 
159
             
 
160
           }
 
161
       }
 
162
   break;
 
163
 case 'g' :
 
164
 default:
 
165
   if ((int)strlen(xf) >= 2 && xf[1]=='l')
 
166
     for (j=0 ; j< (*n1) ; j++)
 
167
       {
 
168
         for ( i=0 ; i < (*n2) ; i++)
 
169
           {
 
170
             xm[2*i+2*(*n2)*j]= XLogScale(x[i+(*n2)*j]);
 
171
             xm[2*i+1+2*(*n2)*j]=xm[2*i+2*(*n2)*j];
 
172
 
 
173
           }
 
174
       }
 
175
   else 
 
176
     for (j=0 ; j< (*n1) ; j++)
 
177
       {
 
178
         for ( i=0 ; i < (*n2) ; i++)
 
179
           {
 
180
             xm[2*i+2*(*n2)*j]= XScale(x[i+(*n2)*j]);
 
181
             xm[2*i+1+2*(*n2)*j]=xm[2*i+2*(*n2)*j];
 
182
           }
 
183
       }
 
184
   break;
 
185
 }
 
186
}