00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "plplotP.h"
00028
00029
00030
00031 #define PEN 4
00032
00033 typedef struct {
00034 PLFLT xmin, xmax, ymin, ymax, xjump, xlen;
00035 PLFLT wxmin, wxmax, wymin, wymax;
00036 char *xspec, *yspec, *labx, *laby, *labtop;
00037 PLINT y_ascl, acc, colbox, collab;
00038 PLFLT xlpos, ylpos;
00039 PLFLT *x[PEN], *y[PEN];
00040 PLINT npts[PEN], nptsmax[PEN];
00041 PLINT colline[PEN], styline[PEN];
00042 char *legline[PEN];
00043 } PLStrip;
00044
00045 static int sid;
00046 #define MAX_STRIPC 1000
00047 static PLStrip *strip[MAX_STRIPC];
00048 static PLStrip *stripc;
00049
00050
00051
00052 static void
00053 plstrip_gen(PLStrip *strip);
00054
00055
00056
00057 static void
00058 plstrip_legend(PLStrip *strip, int flag);
00059
00060
00061
00062
00063
00064
00065
00066 void
00067 c_plstripc( PLINT *id, const char *xspec, const char *yspec,
00068 PLFLT xmin, PLFLT xmax, PLFLT xjump, PLFLT ymin, PLFLT ymax,
00069 PLFLT xlpos, PLFLT ylpos,
00070 PLINT y_ascl, PLINT acc,
00071 PLINT colbox, PLINT collab,
00072 PLINT *colline, PLINT *styline, const char *legline[],
00073 const char *labx, const char *laby, const char *labtop )
00074 {
00075 int i;
00076
00077
00078
00079 for (i = 0; i < MAX_STRIPC; i++)
00080 if (strip[i] == NULL)
00081 break;
00082
00083 if (i == MAX_STRIPC) {
00084 plabort("plstripc: Cannot create new strip chart");
00085 *id = -1;
00086 return;
00087 }
00088 else {
00089 sid = *id = i;
00090 strip[sid] = (PLStrip *) calloc(1, (size_t) sizeof(PLStrip));
00091 if (strip[sid] == NULL) {
00092 plabort("plstripc: Out of memory.");
00093 *id = -1;
00094 return;
00095 }
00096 }
00097
00098
00099
00100 stripc = strip[sid];
00101
00102 for (i=0; i<PEN; i++) {
00103 stripc->npts[i] = 0;
00104 stripc->nptsmax[i] = 100;
00105 stripc->colline[i] = colline[i];
00106 stripc->styline[i] = styline[i];
00107 stripc->legline[i] = plstrdup(legline[i]);
00108 stripc->x[i] = (PLFLT *) malloc((size_t) sizeof(PLFLT) * stripc->nptsmax[i]);;
00109 stripc->y[i] = (PLFLT *) malloc((size_t) sizeof(PLFLT) * stripc->nptsmax[i]);;
00110 if (stripc->x[i] == NULL || stripc->y[i] == NULL) {
00111 plabort("plstripc: Out of memory.");
00112 plstripd(sid);
00113 *id = -1;
00114 return;
00115 }
00116 }
00117
00118 stripc->xlpos = xlpos;
00119 stripc->ylpos = ylpos;
00120 stripc->xmin = xmin;
00121 stripc->xmax = xmax;
00122 stripc->ymin = ymin;
00123 stripc->ymax = ymax;
00124 stripc->xjump = xjump;
00125 stripc->xlen = xmax - xmin;
00126 stripc->y_ascl = y_ascl;
00127 stripc->acc = acc;
00128 stripc->xspec = plstrdup(xspec);
00129 stripc->yspec = plstrdup(yspec);
00130 stripc->labx = plstrdup(labx);
00131 stripc->laby = plstrdup(laby);
00132 stripc->labtop = plstrdup(labtop);
00133 stripc->colbox = colbox;
00134 stripc->collab = collab;
00135
00136
00137
00138 plstrip_gen(stripc);
00139 plstrip_legend(stripc,1);
00140 }
00141
00142 static void plstrip_legend(PLStrip *stripc, int first)
00143 {
00144 int i;
00145 PLFLT sc, dy;
00146
00147
00148
00149 plgchr(&sc, &dy);
00150 sc = dy = dy/100;
00151 plwind(-0.01, 1.01, -0.01, 1.01);
00152 for (i=0; i<PEN; i++) {
00153 if (stripc->npts[i] || first) {
00154 plcol(stripc->colline[i]); pllsty(stripc->styline[i]);
00155 pljoin(stripc->xlpos, stripc->ylpos - sc, stripc->xlpos + 0.1, stripc->ylpos - sc);
00156 plcol(stripc->collab);
00157 plptex(stripc->xlpos + 0.11, stripc->ylpos - sc, 0., 0., 0, stripc->legline[i]);sc += dy;
00158 }
00159 }
00160 plwind(stripc->xmin, stripc->xmax, stripc->ymin, stripc->ymax);
00161 plflush();
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171 static void plstrip_gen( PLStrip *strip )
00172 {
00173 int i;
00174
00175
00176
00177 plvpor(0,1,0,1);
00178 plwind(0,1,0,1);
00179 plcol(0);plpsty(0);
00180 plclear();
00181 plvsta();
00182
00183
00184 strip->wxmin=strip->xmin; strip->wxmax=strip->xmax;
00185 strip->wymin=strip->ymin; strip->wymax=strip->ymax;
00186
00187 plwind(strip->xmin, strip->xmax, strip->ymin, strip->ymax);
00188
00189 pllsty(1);
00190 plcol(strip->colbox);
00191 plbox(strip->xspec, 0.0, 0, strip->yspec, 0.0, 0);
00192
00193 plcol(strip->collab);
00194 pllab(strip->labx, strip->laby, strip->labtop);
00195
00196 for (i=0; i<PEN; i++) {
00197 if (strip->npts[i] > 0) {
00198 plcol(strip->colline[i]);pllsty(strip->styline[i]);
00199 plline(strip->npts[i], strip->x[i], strip->y[i]);
00200 }
00201 }
00202
00203 plstrip_legend(strip,0);
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 void c_plstripa( PLINT id, PLINT p, PLFLT x, PLFLT y )
00214 {
00215 int j, yasc=0, istart;
00216
00217 if (p >= PEN) {
00218 plabort("Non existent pen");
00219 return;
00220 }
00221
00222 if ((id < 0) || (id >= MAX_STRIPC) ||
00223 ((stripc = strip[id]) == NULL)) {
00224 plabort("Non existent stripchart");
00225 return;
00226 }
00227
00228
00229
00230 if (++stripc->npts[p] > stripc->nptsmax[p]) {
00231 stripc->nptsmax[p] += 32;
00232 stripc->x[p] = (PLFLT *) realloc((void *) stripc->x[p], sizeof(PLFLT)*stripc->nptsmax[p]);
00233 stripc->y[p] = (PLFLT *) realloc((void *) stripc->y[p], sizeof(PLFLT)*stripc->nptsmax[p]);
00234 if (stripc->x[p] == NULL || stripc->y[p] == NULL) {
00235 plabort("plstripc: Out of memory.");
00236 plstripd(id);
00237 return;
00238 }
00239 }
00240
00241 stripc->x[p][stripc->npts[p]-1] = x;
00242 stripc->y[p][stripc->npts[p]-1] = y;
00243
00244 stripc->xmax = x;
00245
00246 if (stripc->y_ascl == 1 && (y > stripc->ymax || y < stripc->ymin))
00247 yasc=1;
00248
00249 if (y > stripc->ymax)
00250 stripc->ymax = stripc->ymin + 1.1*(y - stripc->ymin);
00251 if (y < stripc->ymin)
00252 stripc->ymin = stripc->ymax - 1.1*(stripc->ymax - y);
00253
00254
00255
00256 if (stripc->xmax - stripc->xmin < stripc->xlen) {
00257 if( yasc == 0) {
00258
00259
00260 plvsta();
00261 plwind(stripc->wxmin, stripc->wxmax, stripc->wymin, stripc->wymax);
00262 plcol(stripc->colline[p]); pllsty(stripc->styline[p]);
00263 if ((stripc->npts[p]-2) < 0)
00264 plP_movwor(stripc->x[p][stripc->npts[p]-1], stripc->y[p][stripc->npts[p]-1]);
00265 else
00266 plP_movwor(stripc->x[p][stripc->npts[p]-2], stripc->y[p][stripc->npts[p]-2]);
00267 plP_drawor(stripc->x[p][stripc->npts[p]-1], stripc->y[p][stripc->npts[p]-1]);
00268 plflush();
00269 }
00270 else {
00271 stripc->xmax = stripc->xmin + stripc->xlen;
00272 plstrip_gen(stripc);
00273 }
00274 }
00275 else {
00276
00277 if (stripc->acc == 0) {
00278 for (j=0; j<PEN; j++) {
00279 if (stripc->npts[j] > 0) {
00280 istart = 0;
00281 while (stripc->x[j][istart] < stripc->xmin + stripc->xlen*stripc->xjump)
00282 istart++;
00283
00284 stripc->npts[j] = stripc->npts[j] - istart;
00285 memcpy( &stripc->x[j][0], &stripc->x[j][istart], (stripc->npts[j])*sizeof(PLFLT));
00286 memcpy( &stripc->y[j][0], &stripc->y[j][istart], (stripc->npts[j])*sizeof(PLFLT));
00287 }
00288 }
00289 } else
00290 stripc->xlen = stripc->xlen * (1 + stripc->xjump);
00291
00292 stripc->xmin = stripc->x[p][0];
00293 stripc->xmax = stripc->xmax + stripc->xlen*stripc->xjump;
00294
00295 plstrip_gen(stripc);
00296 }
00297 }
00298
00299
00300
00301
00302
00303
00304
00305 void c_plstripd( PLINT id )
00306 {
00307 int i;
00308
00309 if ((id < 0) || (id >= MAX_STRIPC) ||
00310 ((stripc = strip[id]) == NULL)) {
00311 plabort("Non existent stripchart");
00312 return;
00313 }
00314
00315 for (i=0; i<PEN; i++) {
00316 if (stripc->npts[i]) {
00317 free((void *) stripc->x[i]);
00318 free((void *) stripc->y[i]);
00319 free(stripc->legline[i]);
00320 }
00321 }
00322
00323 free(stripc->xspec);
00324 free(stripc->yspec);
00325 free(stripc->labx);
00326 free(stripc->laby);
00327 free(stripc->labtop);
00328 free((void *) stripc);
00329 strip[id] = NULL;
00330 }