1 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 2 3 #undef __FUNCT__ 4 #define __FUNCT__ "PetscDrawSetSave" 5 /*@C 6 PetscDrawSetSave - Saves images produced in a PetscDraw into a file as a Gif file using AfterImage 7 8 Collective on PetscDraw 9 10 Input Parameter: 11 + draw - the graphics context 12 . filename - name of the file, if .ext then uses name of draw object plus .ext using .ext to determine the image type, if NULL use .Gif image type 13 - movie - produce a movie of all the images 14 15 Options Database Command: 16 + -draw_save <filename> - filename could be name.ext or .ext (where .ext determines the type of graphics file to save, for example .Gif) 17 . -draw_save_movie 18 . -draw_save_final_image [optional filename] - (X windows only) saves the final image displayed in a window 19 . -draw_save_on_flush - saves an image on each flush in addition to each clear 20 - -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 21 22 Level: intermediate 23 24 Concepts: X windows^graphics 25 26 Notes: You should call this BEFORE creating your image and calling PetscDrawFlush(). 27 28 Requires that PETSc be configured with the option --with-afterimage to save the images and ffmpeg must be in your path to make the movie 29 30 The .ext formats that are supported depend on what formats AfterImage was configured with; on the Apple Mac both .Gif and .Jpeg are supported. 31 32 If X windows generates an error message about X_CreateWindow() failing then Afterimage was installed without X windows. Reinstall Afterimage using the 33 ./configure flags --x-includes=/pathtoXincludes --x-libraries=/pathtoXlibraries For example under Mac OS X Mountain Lion --x-includes=/opt/X11/include -x-libraries=/opt/X11/lib 34 35 36 .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy(), PetscDrawSetSaveFinalImage() 37 @*/ 38 PetscErrorCode PetscDrawSetSave(PetscDraw draw,const char *filename,PetscBool movie) 39 { 40 PetscErrorCode ierr; 41 char *ext; 42 43 PetscFunctionBegin; 44 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 45 ierr = PetscFree(draw->savefilename);CHKERRQ(ierr); 46 47 /* determine extension of filename */ 48 if (filename && filename[0]) { 49 ierr = PetscStrchr(filename,'.',&ext);CHKERRQ(ierr); 50 if (!ext) SETERRQ1(PetscObjectComm((PetscObject)draw),PETSC_ERR_ARG_INCOMP,"Filename %s should end with graphics extension (for example .Gif)",filename); 51 } else { 52 ext = (char *)".Gif"; 53 } 54 if (ext == filename) filename = NULL; 55 ierr = PetscStrallocpy(ext,&draw->savefilenameext);CHKERRQ(ierr); 56 57 draw->savefilemovie = movie; 58 if (filename && filename[0]) { 59 size_t l1,l2; 60 ierr = PetscStrlen(filename,&l1);CHKERRQ(ierr); 61 ierr = PetscStrlen(ext,&l2);CHKERRQ(ierr); 62 ierr = PetscMalloc1(l1-l2+1,&draw->savefilename);CHKERRQ(ierr); 63 ierr = PetscStrncpy(draw->savefilename,filename,l1-l2+1);CHKERRQ(ierr); 64 } else { 65 const char *name; 66 67 ierr = PetscObjectGetName((PetscObject)draw,&name);CHKERRQ(ierr); 68 ierr = PetscStrallocpy(name,&draw->savefilename);CHKERRQ(ierr); 69 } 70 ierr = PetscInfo2(NULL,"Will save images to file %s%s\n",draw->savefilename,draw->savefilenameext);CHKERRQ(ierr); 71 if (draw->ops->setsave) { 72 ierr = (*draw->ops->setsave)(draw,draw->savefilename);CHKERRQ(ierr); 73 } 74 PetscFunctionReturn(0); 75 } 76 77 #undef __FUNCT__ 78 #define __FUNCT__ "PetscDrawSetSaveFinalImage" 79 /*@C 80 PetscDrawSetSaveFinalImage - Saves the finale image produced in a PetscDraw into a file as a Gif file using AfterImage 81 82 Collective on PetscDraw 83 84 Input Parameter: 85 + draw - the graphics context 86 - filename - name of the file, if NULL uses name of draw object 87 88 Options Database Command: 89 . -draw_save_final_image <filename> 90 91 Level: intermediate 92 93 Concepts: X windows^graphics 94 95 Notes: You should call this BEFORE creating your image and calling PetscDrawFlush(). 96 97 Requires that PETSc be configured with the option --with-afterimage to save the images and ffmpeg must be in your path to make the movie 98 99 If X windows generates an error message about X_CreateWindow() failing then Afterimage was installed without X windows. Reinstall Afterimage using the 100 ./configure flags --x-includes=/pathtoXincludes --x-libraries=/pathtoXlibraries For example under Mac OS X Mountain Lion --x-includes=/opt/X11/include -x-libraries=/opt/X11/lib 101 102 103 .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy(), PetscDrawSetSave() 104 @*/ 105 PetscErrorCode PetscDrawSetSaveFinalImage(PetscDraw draw,const char *filename) 106 { 107 PetscErrorCode ierr; 108 109 PetscFunctionBegin; 110 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 111 ierr = PetscFree(draw->savefinalfilename);CHKERRQ(ierr); 112 113 if (filename && filename[0]) { 114 ierr = PetscStrallocpy(filename,&draw->savefinalfilename);CHKERRQ(ierr); 115 } else { 116 const char *name; 117 ierr = PetscObjectGetName((PetscObject)draw,&name);CHKERRQ(ierr); 118 ierr = PetscStrallocpy(name,&draw->savefinalfilename);CHKERRQ(ierr); 119 } 120 PetscFunctionReturn(0); 121 } 122 123 #undef __FUNCT__ 124 #define __FUNCT__ "PetscDrawSave" 125 /*@ 126 PetscDrawSave - Saves a drawn image 127 128 Collective on PetscDraw 129 130 Input Parameters: 131 . draw - the drawing context 132 133 Level: advanced 134 135 Notes: this is not normally called by the user, it is called by PetscDrawFlush() to save a sequence of images. 136 137 .seealso: PetscDrawSetSave() 138 139 @*/ 140 PetscErrorCode PetscDrawSave(PetscDraw draw) 141 { 142 PetscErrorCode ierr; 143 144 PetscFunctionBegin; 145 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 146 if (draw->ops->save) { 147 ierr = (*draw->ops->save)(draw);CHKERRQ(ierr); 148 } 149 PetscFunctionReturn(0); 150 } 151