Commits

BarryFSmith committed 8b7fcac

add -draw_save_single_file to recycle same file for saved images

Comments (0)

Files changed (3)

include/petsc-private/drawimpl.h

   PetscInt        savefilecount;
   PetscBool       savefilemovie;
   PetscBool       saveonflush;       /* save a new image for every PetscDrawFlush() called */
+  PetscBool       savesinglefile;
   void            *data;
 };
 

src/sys/classes/draw/impls/x/xinit.c

 #define __FUNCT__ "PetscDrawSave_X"
 PetscErrorCode PetscDrawSave_X(PetscDraw draw)
 {
-  PetscDraw_X             *drawx = (PetscDraw_X*)draw->data;
-  XImage                  *image;
-  ASImage                 *asimage;
-  struct  ASVisual        *asv;
-  char                    filename[PETSC_MAX_PATH_LEN];
-  PetscErrorCode          ierr;
-  PetscMPIInt             rank;
-  int                     depth;
+  PetscDraw_X      *drawx = (PetscDraw_X*)draw->data;
+  XImage           *image;
+  ASImage          *asimage;
+  struct  ASVisual *asv;
+  char             filename[PETSC_MAX_PATH_LEN];
+  PetscErrorCode   ierr;
+  PetscMPIInt      rank;
+  int              depth;
 
   PetscFunctionBegin;
   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr);
   image   = XGetImage(drawx->disp, drawx->drw ? drawx->drw : drawx->win, 0, 0, drawx->w, drawx->h, AllPlanes, ZPixmap);
   if (!image) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_PLIB,"Cannot XGetImage()");\
   asimage = picture_ximage2asimage (asv,image,0,0);if (!asimage) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_PLIB,"Cannot create AfterImage ASImage");
-  ierr    = PetscSNPrintf(filename,PETSC_MAX_PATH_LEN,"%s/%s_%d.Gif",draw->savefilename,draw->savefilename,draw->savefilecount++);CHKERRQ(ierr);
+  if (draw->savesinglefile) {
+    ierr    = PetscSNPrintf(filename,PETSC_MAX_PATH_LEN,"%s/%s.Gif",draw->savefilename,draw->savefilename);CHKERRQ(ierr);
+  } else {
+    ierr    = PetscSNPrintf(filename,PETSC_MAX_PATH_LEN,"%s/%s_%d.Gif",draw->savefilename,draw->savefilename,draw->savefilecount++);CHKERRQ(ierr);
+  }
   ASImage2file(asimage, 0, filename,ASIT_Gif,0);
 
   XDestroyImage(image);

src/sys/classes/draw/interface/drawreg.c

 .   -draw_pause <pause amount> -- -1 indicates wait for mouse input, -2 indicates pause when window is to be destroyed
 .   -draw_save [optional filename] - (X windows only) saves each image before it is cleared to a file
 .   -draw_save_movie - converts image files to a movie  at the end of the run. See PetscDrawSetSave()
--   -draw_save_on_flush - saves an image on each flush in addition to each clear
+.   -draw_save_on_flush - saves an image on each flush in addition to each clear
+-   -draw_save_single_file - saves each new image in the same file, normally each new image is saved in a new file with filename_%d
 
    Level: intermediate
 
     char      filename[PETSC_MAX_PATH_LEN];
     PetscBool save,movie = PETSC_FALSE;
     ierr = PetscOptionsBool("-draw_save_movie","Make a movie from the images saved (X Windows only)","PetscDrawSetSave",movie,&movie,NULL);CHKERRQ(ierr);
+    ierr = PetscOptionsBool("-draw_save_single_file","Each new image replaces previous image in file","PetscDrawSetSave",draw->savesinglefile,&draw->savesinglefile,NULL);CHKERRQ(ierr);
     ierr = PetscOptionsString("-draw_save","Save graphics to file (X Windows only)","PetscDrawSetSave",filename,filename,PETSC_MAX_PATH_LEN,&save);CHKERRQ(ierr);
     if (save) {
       ierr = PetscDrawSetSave(draw,filename,movie);CHKERRQ(ierr);