Actual source code: lg.c
petsc-3.3-p7 2013-05-11
2: #include <../src/sys/draw/utils/lgimpl.h>
6: /*@
7: PetscDrawLGAddPoint - Adds another point to each of the line graphs.
8: The new point must have an X coordinate larger than the old points.
10: Not Collective, but ignored by all processors except processor 0 in PetscDrawLG
12: Input Parameters:
13: + lg - the LineGraph data structure
14: - x, y - the points to two vectors containing the new x and y
15: point for each curve.
17: Level: intermediate
19: Concepts: line graph^adding points
21: .seealso: PetscDrawLGAddPoints()
22: @*/
23: PetscErrorCode PetscDrawLGAddPoint(PetscDrawLG lg,PetscReal *x,PetscReal *y)
24: {
26: int i;
29: if (lg && ((PetscObject)lg)->classid == PETSC_DRAW_CLASSID) return(0);
32: if (lg->loc+lg->dim >= lg->len) { /* allocate more space */
33: PetscReal *tmpx,*tmpy;
34: PetscMalloc2(lg->len+lg->dim*CHUNCKSIZE,PetscReal,&tmpx,lg->len+lg->dim*CHUNCKSIZE,PetscReal,&tmpy);
35: PetscLogObjectMemory(lg,2*lg->dim*CHUNCKSIZE*sizeof(PetscReal));
36: PetscMemcpy(tmpx,lg->x,lg->len*sizeof(PetscReal));
37: PetscMemcpy(tmpy,lg->y,lg->len*sizeof(PetscReal));
38: PetscFree2(lg->x,lg->y);
39: lg->x = tmpx;
40: lg->y = tmpy;
41: lg->len += lg->dim*CHUNCKSIZE;
42: }
43: for (i=0; i<lg->dim; i++) {
44: if (x[i] > lg->xmax) lg->xmax = x[i];
45: if (x[i] < lg->xmin) lg->xmin = x[i];
46: if (y[i] > lg->ymax) lg->ymax = y[i];
47: if (y[i] < lg->ymin) lg->ymin = y[i];
49: lg->x[lg->loc] = x[i];
50: lg->y[lg->loc++] = y[i];
51: }
52: lg->nopts++;
53: return(0);
54: }
58: /*@C
59: PetscDrawLGAddPoints - Adds several points to each of the line graphs.
60: The new points must have an X coordinate larger than the old points.
62: Not Collective, but ignored by all processors except processor 0 in PetscDrawLG
64: Input Parameters:
65: + lg - the LineGraph data structure
66: . xx,yy - points to two arrays of pointers that point to arrays
67: containing the new x and y points for each curve.
68: - n - number of points being added
70: Level: intermediate
73: Concepts: line graph^adding points
75: .seealso: PetscDrawLGAddPoint()
76: @*/
77: PetscErrorCode PetscDrawLGAddPoints(PetscDrawLG lg,int n,PetscReal **xx,PetscReal **yy)
78: {
80: int i,j,k;
81: PetscReal *x,*y;
84: if (lg && ((PetscObject)lg)->classid == PETSC_DRAW_CLASSID) return(0);
86: if (lg->loc+n*lg->dim >= lg->len) { /* allocate more space */
87: PetscReal *tmpx,*tmpy;
88: int chunk = CHUNCKSIZE;
90: if (n > chunk) chunk = n;
91: PetscMalloc2(lg->len+lg->dim*chunk,PetscReal,&tmpx,lg->len+lg->dim*chunk,PetscReal,&tmpy);
92: PetscLogObjectMemory(lg,2*lg->dim*chunk*sizeof(PetscReal));
93: PetscMemcpy(tmpx,lg->x,lg->len*sizeof(PetscReal));
94: PetscMemcpy(tmpy,lg->y,lg->len*sizeof(PetscReal));
95: PetscFree2(lg->x,lg->y);
96: lg->x = tmpx;
97: lg->y = tmpy;
98: lg->len += lg->dim*chunk;
99: }
100: for (j=0; j<lg->dim; j++) {
101: x = xx[j]; y = yy[j];
102: k = lg->loc + j;
103: for (i=0; i<n; i++) {
104: if (x[i] > lg->xmax) lg->xmax = x[i];
105: if (x[i] < lg->xmin) lg->xmin = x[i];
106: if (y[i] > lg->ymax) lg->ymax = y[i];
107: if (y[i] < lg->ymin) lg->ymin = y[i];
109: lg->x[k] = x[i];
110: lg->y[k] = y[i];
111: k += lg->dim;
112: }
113: }
114: lg->loc += n*lg->dim;
115: lg->nopts += n;
116: return(0);
117: }
119:
122: /*@
123: PetscDrawLGSetLimits - Sets the axis limits for a line graph. If more
124: points are added after this call, the limits will be adjusted to
125: include those additional points.
127: Not Collective, but ignored by all processors except processor 0 in PetscDrawLG
129: Input Parameters:
130: + xlg - the line graph context
131: - x_min,x_max,y_min,y_max - the limits
133: Level: intermediate
135: Concepts: line graph^setting axis
137: @*/
138: PetscErrorCode PetscDrawLGSetLimits(PetscDrawLG lg,PetscReal x_min,PetscReal x_max,PetscReal y_min,PetscReal y_max)
139: {
141: if (lg && ((PetscObject)lg)->classid == PETSC_DRAW_CLASSID) return(0);
143: (lg)->xmin = x_min;
144: (lg)->xmax = x_max;
145: (lg)->ymin = y_min;
146: (lg)->ymax = y_max;
147: return(0);
148: }
149: