/* Sets the edges of the viewport to the specified normalized subpage */
/* coordinates */

#include "plplot.h"

void plvasp(aspratio)
double aspratio;
{
    int level;
    double chrdef, chrht, spxmin, spxmax, spymin, spymax;
    double vpxmin, vpxmax, vpymin, vpymax;
    double xsize, ysize, nxsize, nysize;
    double lb, rb, tb, bb;

    glev(&level);
    if (level < 1) plexit("Please call plstar before calling plvasp.");

    gchr(&chrdef,&chrht);
    lb = 8.0 * chrht;
    rb = 5.0 * chrht;
    tb = 5.0 * chrht;
    bb = 5.0 * chrht;
    plgspa(&spxmin,&spxmax,&spymin,&spymax);
    xsize = spxmax - spxmin;
    ysize = spymax - spymin;
    xsize -= lb+rb;     /* adjust for labels */
    ysize -= bb+tb;
    if(aspratio*xsize > ysize) {
      nxsize = ysize/aspratio;
      nysize = ysize;
    }
    else {
      nxsize = xsize;
      nysize = xsize*aspratio;
    }
    /* center plot within page */
    vpxmin = .5*(xsize-nxsize)+lb;
    vpxmax = vpxmin + nxsize;
    vpymin = .5*(ysize-nysize)+bb;
    vpymax = vpymin + nysize;
    plsvpa(vpxmin,vpxmax,vpymin,vpymax);
}
