/* Advance to subpage "page", or to the next one if "page" = 0 */

#include "plplot.h"

void pladv(page)
int page;
{
      int cursub, nsubx, nsuby;
      int device, termin, graphx;

      int level;
      glev(&level);
      if (level < 1) fatal("Please call PLSTAR before calling PLADV.");
      
      gdev(&device,&termin,&graphx);
      gsub(&nsubx,&nsuby,&cursub);
      if (page > 0 && page <= nsubx*nsuby) 
        cursub = page;
      else if (page == 0) {
        if (cursub == nsubx*nsuby) {
          if (termin != 0) beepw();
          plclr();
          cursub = 1;
        }
        else
          cursub = cursub + 1;
      }
      else
        fatal("Invalid subpage number in PLADV.");

      ssub(nsubx,nsuby,cursub);
      setsub();
}

