1*5c6c1daeSBarry Smith 2*5c6c1daeSBarry Smith #include <../src/sys/classes/viewer/impls/ascii/asciiimpl.h> /*I "petscsys.h" I*/ 3*5c6c1daeSBarry Smith #include <stdarg.h> 4*5c6c1daeSBarry Smith 5*5c6c1daeSBarry Smith #define QUEUESTRINGSIZE 8192 6*5c6c1daeSBarry Smith 7*5c6c1daeSBarry Smith #undef __FUNCT__ 8*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileClose_ASCII" 9*5c6c1daeSBarry Smith static PetscErrorCode PetscViewerFileClose_ASCII(PetscViewer viewer) 10*5c6c1daeSBarry Smith { 11*5c6c1daeSBarry Smith PetscErrorCode ierr; 12*5c6c1daeSBarry Smith PetscMPIInt rank; 13*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 14*5c6c1daeSBarry Smith int err; 15*5c6c1daeSBarry Smith 16*5c6c1daeSBarry Smith PetscFunctionBegin; 17*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);CHKERRQ(ierr); 18*5c6c1daeSBarry Smith if (!rank && vascii->fd != stderr && vascii->fd != PETSC_STDOUT) { 19*5c6c1daeSBarry Smith if (vascii->fd && vascii->closefile) { 20*5c6c1daeSBarry Smith err = fclose(vascii->fd); 21*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file"); 22*5c6c1daeSBarry Smith } 23*5c6c1daeSBarry Smith if (vascii->storecompressed) { 24*5c6c1daeSBarry Smith char par[PETSC_MAX_PATH_LEN],buf[PETSC_MAX_PATH_LEN]; 25*5c6c1daeSBarry Smith FILE *fp; 26*5c6c1daeSBarry Smith ierr = PetscStrcpy(par,"gzip ");CHKERRQ(ierr); 27*5c6c1daeSBarry Smith ierr = PetscStrcat(par,vascii->filename);CHKERRQ(ierr); 28*5c6c1daeSBarry Smith #if defined(PETSC_HAVE_POPEN) 29*5c6c1daeSBarry Smith ierr = PetscPOpen(PETSC_COMM_SELF,PETSC_NULL,par,"r",&fp);CHKERRQ(ierr); 30*5c6c1daeSBarry Smith if (fgets(buf,1024,fp)) { 31*5c6c1daeSBarry Smith SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error from compression command %s\n%s",par,buf); 32*5c6c1daeSBarry Smith } 33*5c6c1daeSBarry Smith ierr = PetscPClose(PETSC_COMM_SELF,fp,PETSC_NULL);CHKERRQ(ierr); 34*5c6c1daeSBarry Smith #else 35*5c6c1daeSBarry Smith SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"Cannot run external programs on this machine"); 36*5c6c1daeSBarry Smith #endif 37*5c6c1daeSBarry Smith } 38*5c6c1daeSBarry Smith } 39*5c6c1daeSBarry Smith ierr = PetscFree(vascii->filename);CHKERRQ(ierr); 40*5c6c1daeSBarry Smith PetscFunctionReturn(0); 41*5c6c1daeSBarry Smith } 42*5c6c1daeSBarry Smith 43*5c6c1daeSBarry Smith /* ----------------------------------------------------------------------*/ 44*5c6c1daeSBarry Smith #undef __FUNCT__ 45*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_ASCII" 46*5c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_ASCII(PetscViewer viewer) 47*5c6c1daeSBarry Smith { 48*5c6c1daeSBarry Smith PetscErrorCode ierr; 49*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 50*5c6c1daeSBarry Smith PetscViewerLink *vlink; 51*5c6c1daeSBarry Smith PetscBool flg; 52*5c6c1daeSBarry Smith 53*5c6c1daeSBarry Smith PetscFunctionBegin; 54*5c6c1daeSBarry Smith if (vascii->sviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"ASCII PetscViewer destroyed before restoring singleton or subcomm PetscViewer"); 55*5c6c1daeSBarry Smith ierr = PetscViewerFileClose_ASCII(viewer);CHKERRQ(ierr); 56*5c6c1daeSBarry Smith ierr = PetscFree(vascii);CHKERRQ(ierr); 57*5c6c1daeSBarry Smith 58*5c6c1daeSBarry Smith /* remove the viewer from the list in the MPI Communicator */ 59*5c6c1daeSBarry Smith if (Petsc_Viewer_keyval == MPI_KEYVAL_INVALID) { 60*5c6c1daeSBarry Smith ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelViewer,&Petsc_Viewer_keyval,(void*)0);CHKERRQ(ierr); 61*5c6c1daeSBarry Smith } 62*5c6c1daeSBarry Smith 63*5c6c1daeSBarry Smith ierr = MPI_Attr_get(((PetscObject)viewer)->comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg);CHKERRQ(ierr); 64*5c6c1daeSBarry Smith if (flg) { 65*5c6c1daeSBarry Smith if (vlink && vlink->viewer == viewer) { 66*5c6c1daeSBarry Smith ierr = MPI_Attr_put(((PetscObject)viewer)->comm,Petsc_Viewer_keyval,vlink->next);CHKERRQ(ierr); 67*5c6c1daeSBarry Smith ierr = PetscFree(vlink);CHKERRQ(ierr); 68*5c6c1daeSBarry Smith } else { 69*5c6c1daeSBarry Smith while (vlink && vlink->next) { 70*5c6c1daeSBarry Smith if (vlink->next->viewer == viewer) { 71*5c6c1daeSBarry Smith PetscViewerLink *nv = vlink->next; 72*5c6c1daeSBarry Smith vlink->next = vlink->next->next; 73*5c6c1daeSBarry Smith ierr = PetscFree(nv);CHKERRQ(ierr); 74*5c6c1daeSBarry Smith } 75*5c6c1daeSBarry Smith vlink = vlink->next; 76*5c6c1daeSBarry Smith } 77*5c6c1daeSBarry Smith } 78*5c6c1daeSBarry Smith } 79*5c6c1daeSBarry Smith PetscFunctionReturn(0); 80*5c6c1daeSBarry Smith } 81*5c6c1daeSBarry Smith 82*5c6c1daeSBarry Smith #undef __FUNCT__ 83*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_ASCII_Singleton" 84*5c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_ASCII_Singleton(PetscViewer viewer) 85*5c6c1daeSBarry Smith { 86*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 87*5c6c1daeSBarry Smith PetscErrorCode ierr; 88*5c6c1daeSBarry Smith PetscFunctionBegin; 89*5c6c1daeSBarry Smith ierr = PetscViewerRestoreSingleton(vascii->bviewer,&viewer);CHKERRQ(ierr); 90*5c6c1daeSBarry Smith PetscFunctionReturn(0); 91*5c6c1daeSBarry Smith } 92*5c6c1daeSBarry Smith 93*5c6c1daeSBarry Smith #undef __FUNCT__ 94*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_ASCII_Subcomm" 95*5c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_ASCII_Subcomm(PetscViewer viewer) 96*5c6c1daeSBarry Smith { 97*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 98*5c6c1daeSBarry Smith PetscErrorCode ierr; 99*5c6c1daeSBarry Smith PetscFunctionBegin; 100*5c6c1daeSBarry Smith ierr = PetscViewerRestoreSubcomm(vascii->bviewer,((PetscObject)viewer)->comm,&viewer);CHKERRQ(ierr); 101*5c6c1daeSBarry Smith PetscFunctionReturn(0); 102*5c6c1daeSBarry Smith } 103*5c6c1daeSBarry Smith 104*5c6c1daeSBarry Smith #undef __FUNCT__ 105*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFlush_ASCII_Singleton_0" 106*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFlush_ASCII_Singleton_0(PetscViewer viewer) 107*5c6c1daeSBarry Smith { 108*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 109*5c6c1daeSBarry Smith int err; 110*5c6c1daeSBarry Smith 111*5c6c1daeSBarry Smith PetscFunctionBegin; 112*5c6c1daeSBarry Smith err = fflush(vascii->fd); 113*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 114*5c6c1daeSBarry Smith PetscFunctionReturn(0); 115*5c6c1daeSBarry Smith } 116*5c6c1daeSBarry Smith 117*5c6c1daeSBarry Smith #undef __FUNCT__ 118*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFlush_ASCII" 119*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFlush_ASCII(PetscViewer viewer) 120*5c6c1daeSBarry Smith { 121*5c6c1daeSBarry Smith PetscMPIInt rank; 122*5c6c1daeSBarry Smith PetscErrorCode ierr; 123*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 124*5c6c1daeSBarry Smith int err; 125*5c6c1daeSBarry Smith 126*5c6c1daeSBarry Smith PetscFunctionBegin; 127*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);CHKERRQ(ierr); 128*5c6c1daeSBarry Smith /* fflush() fails on OSX for read-only descriptors */ 129*5c6c1daeSBarry Smith if (!rank && (vascii->mode != FILE_MODE_READ)) { 130*5c6c1daeSBarry Smith err = fflush(vascii->fd); 131*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() call failed"); 132*5c6c1daeSBarry Smith } 133*5c6c1daeSBarry Smith 134*5c6c1daeSBarry Smith if (vascii->allowsynchronized) { 135*5c6c1daeSBarry Smith /* Also flush anything printed with PetscViewerASCIISynchronizedPrintf() */ 136*5c6c1daeSBarry Smith ierr = PetscSynchronizedFlush(((PetscObject)viewer)->comm);CHKERRQ(ierr); 137*5c6c1daeSBarry Smith } 138*5c6c1daeSBarry Smith PetscFunctionReturn(0); 139*5c6c1daeSBarry Smith } 140*5c6c1daeSBarry Smith 141*5c6c1daeSBarry Smith #undef __FUNCT__ 142*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIGetPointer" 143*5c6c1daeSBarry Smith /*@C 144*5c6c1daeSBarry Smith PetscViewerASCIIGetPointer - Extracts the file pointer from an ASCII PetscViewer. 145*5c6c1daeSBarry Smith 146*5c6c1daeSBarry Smith Not Collective 147*5c6c1daeSBarry Smith 148*5c6c1daeSBarry Smith + viewer - PetscViewer context, obtained from PetscViewerASCIIOpen() 149*5c6c1daeSBarry Smith - fd - file pointer 150*5c6c1daeSBarry Smith 151*5c6c1daeSBarry Smith Level: intermediate 152*5c6c1daeSBarry Smith 153*5c6c1daeSBarry Smith Fortran Note: 154*5c6c1daeSBarry Smith This routine is not supported in Fortran. 155*5c6c1daeSBarry Smith 156*5c6c1daeSBarry Smith Concepts: PetscViewer^file pointer 157*5c6c1daeSBarry Smith Concepts: file pointer^getting from PetscViewer 158*5c6c1daeSBarry Smith 159*5c6c1daeSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerCreate(), PetscViewerASCIIPrintf(), 160*5c6c1daeSBarry Smith PetscViewerASCIISynchronizedPrintf(), PetscViewerFlush() 161*5c6c1daeSBarry Smith @*/ 162*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIGetPointer(PetscViewer viewer,FILE **fd) 163*5c6c1daeSBarry Smith { 164*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 165*5c6c1daeSBarry Smith 166*5c6c1daeSBarry Smith PetscFunctionBegin; 167*5c6c1daeSBarry Smith *fd = vascii->fd; 168*5c6c1daeSBarry Smith PetscFunctionReturn(0); 169*5c6c1daeSBarry Smith } 170*5c6c1daeSBarry Smith 171*5c6c1daeSBarry Smith EXTERN_C_BEGIN 172*5c6c1daeSBarry Smith #undef __FUNCT__ 173*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileGetMode_ASCII" 174*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileGetMode_ASCII(PetscViewer viewer, PetscFileMode *mode) 175*5c6c1daeSBarry Smith { 176*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 177*5c6c1daeSBarry Smith 178*5c6c1daeSBarry Smith PetscFunctionBegin; 179*5c6c1daeSBarry Smith *mode = vascii->mode; 180*5c6c1daeSBarry Smith PetscFunctionReturn(0); 181*5c6c1daeSBarry Smith } 182*5c6c1daeSBarry Smith EXTERN_C_END 183*5c6c1daeSBarry Smith 184*5c6c1daeSBarry Smith /*@C 185*5c6c1daeSBarry Smith PetscViewerFileSetMode - Sets the mode in which to open the file. 186*5c6c1daeSBarry Smith 187*5c6c1daeSBarry Smith Not Collective 188*5c6c1daeSBarry Smith 189*5c6c1daeSBarry Smith + viewer - viewer context, obtained from PetscViewerCreate() 190*5c6c1daeSBarry Smith - mode - The file mode 191*5c6c1daeSBarry Smith 192*5c6c1daeSBarry Smith Level: intermediate 193*5c6c1daeSBarry Smith 194*5c6c1daeSBarry Smith Fortran Note: 195*5c6c1daeSBarry Smith This routine is not supported in Fortran. 196*5c6c1daeSBarry Smith 197*5c6c1daeSBarry Smith .keywords: Viewer, file, get, pointer 198*5c6c1daeSBarry Smith 199*5c6c1daeSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen() 200*5c6c1daeSBarry Smith @*/ 201*5c6c1daeSBarry Smith 202*5c6c1daeSBarry Smith EXTERN_C_BEGIN 203*5c6c1daeSBarry Smith #undef __FUNCT__ 204*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetMode_ASCII" 205*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileSetMode_ASCII(PetscViewer viewer, PetscFileMode mode) 206*5c6c1daeSBarry Smith { 207*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 208*5c6c1daeSBarry Smith 209*5c6c1daeSBarry Smith PetscFunctionBegin; 210*5c6c1daeSBarry Smith vascii->mode = mode; 211*5c6c1daeSBarry Smith PetscFunctionReturn(0); 212*5c6c1daeSBarry Smith } 213*5c6c1daeSBarry Smith EXTERN_C_END 214*5c6c1daeSBarry Smith 215*5c6c1daeSBarry Smith /* 216*5c6c1daeSBarry Smith If petsc_history is on, then all Petsc*Printf() results are saved 217*5c6c1daeSBarry Smith if the appropriate (usually .petschistory) file. 218*5c6c1daeSBarry Smith */ 219*5c6c1daeSBarry Smith extern FILE *petsc_history; 220*5c6c1daeSBarry Smith 221*5c6c1daeSBarry Smith #undef __FUNCT__ 222*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIISetTab" 223*5c6c1daeSBarry Smith /*@ 224*5c6c1daeSBarry Smith PetscViewerASCIISetTab - Causes PetscViewer to tab in a number of times 225*5c6c1daeSBarry Smith 226*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 227*5c6c1daeSBarry Smith 228*5c6c1daeSBarry Smith Input Parameters: 229*5c6c1daeSBarry Smith + viewer - optained with PetscViewerASCIIOpen() 230*5c6c1daeSBarry Smith - tabs - number of tabs 231*5c6c1daeSBarry Smith 232*5c6c1daeSBarry Smith Level: developer 233*5c6c1daeSBarry Smith 234*5c6c1daeSBarry Smith Fortran Note: 235*5c6c1daeSBarry Smith This routine is not supported in Fortran. 236*5c6c1daeSBarry Smith 237*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 238*5c6c1daeSBarry Smith Concepts: tab^setting 239*5c6c1daeSBarry Smith 240*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), PetscViewerASCIIGetTab(), 241*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 242*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer(), PetscViewerASCIIPushTab() 243*5c6c1daeSBarry Smith @*/ 244*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIISetTab(PetscViewer viewer,PetscInt tabs) 245*5c6c1daeSBarry Smith { 246*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 247*5c6c1daeSBarry Smith PetscBool iascii; 248*5c6c1daeSBarry Smith PetscErrorCode ierr; 249*5c6c1daeSBarry Smith 250*5c6c1daeSBarry Smith PetscFunctionBegin; 251*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 252*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 253*5c6c1daeSBarry Smith if (iascii) { 254*5c6c1daeSBarry Smith ascii->tab = tabs; 255*5c6c1daeSBarry Smith } 256*5c6c1daeSBarry Smith PetscFunctionReturn(0); 257*5c6c1daeSBarry Smith } 258*5c6c1daeSBarry Smith 259*5c6c1daeSBarry Smith #undef __FUNCT__ 260*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIGetTab" 261*5c6c1daeSBarry Smith /*@ 262*5c6c1daeSBarry Smith PetscViewerASCIIGetTab - Return the number of tabs used by PetscViewer. 263*5c6c1daeSBarry Smith 264*5c6c1daeSBarry Smith Not Collective, meaningful on first processor only. 265*5c6c1daeSBarry Smith 266*5c6c1daeSBarry Smith Input Parameters: 267*5c6c1daeSBarry Smith . viewer - optained with PetscViewerASCIIOpen() 268*5c6c1daeSBarry Smith Output Parameters: 269*5c6c1daeSBarry Smith . tabs - number of tabs 270*5c6c1daeSBarry Smith 271*5c6c1daeSBarry Smith Level: developer 272*5c6c1daeSBarry Smith 273*5c6c1daeSBarry Smith Fortran Note: 274*5c6c1daeSBarry Smith This routine is not supported in Fortran. 275*5c6c1daeSBarry Smith 276*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 277*5c6c1daeSBarry Smith Concepts: tab^retrieval 278*5c6c1daeSBarry Smith 279*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), PetscViewerASCIISetTab(), 280*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 281*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer(), PetscViewerASCIIPushTab() 282*5c6c1daeSBarry Smith @*/ 283*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIGetTab(PetscViewer viewer,PetscInt *tabs) 284*5c6c1daeSBarry Smith { 285*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 286*5c6c1daeSBarry Smith PetscBool iascii; 287*5c6c1daeSBarry Smith PetscErrorCode ierr; 288*5c6c1daeSBarry Smith 289*5c6c1daeSBarry Smith PetscFunctionBegin; 290*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 291*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 292*5c6c1daeSBarry Smith if (iascii && tabs) { 293*5c6c1daeSBarry Smith *tabs = ascii->tab; 294*5c6c1daeSBarry Smith } 295*5c6c1daeSBarry Smith PetscFunctionReturn(0); 296*5c6c1daeSBarry Smith } 297*5c6c1daeSBarry Smith 298*5c6c1daeSBarry Smith #undef __FUNCT__ 299*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIAddTab" 300*5c6c1daeSBarry Smith /*@ 301*5c6c1daeSBarry Smith PetscViewerASCIIAddTab - Add to the number of times an ASCII viewer tabs before printing 302*5c6c1daeSBarry Smith 303*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 304*5c6c1daeSBarry Smith 305*5c6c1daeSBarry Smith Input Parameters: 306*5c6c1daeSBarry Smith + viewer - optained with PetscViewerASCIIOpen() 307*5c6c1daeSBarry Smith - tabs - number of tabs 308*5c6c1daeSBarry Smith 309*5c6c1daeSBarry Smith Level: developer 310*5c6c1daeSBarry Smith 311*5c6c1daeSBarry Smith Fortran Note: 312*5c6c1daeSBarry Smith This routine is not supported in Fortran. 313*5c6c1daeSBarry Smith 314*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 315*5c6c1daeSBarry Smith Concepts: tab^setting 316*5c6c1daeSBarry Smith 317*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 318*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 319*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer(), PetscViewerASCIIPushTab() 320*5c6c1daeSBarry Smith @*/ 321*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIAddTab(PetscViewer viewer,PetscInt tabs) 322*5c6c1daeSBarry Smith { 323*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 324*5c6c1daeSBarry Smith PetscBool iascii; 325*5c6c1daeSBarry Smith PetscErrorCode ierr; 326*5c6c1daeSBarry Smith 327*5c6c1daeSBarry Smith PetscFunctionBegin; 328*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 329*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 330*5c6c1daeSBarry Smith if (iascii) { 331*5c6c1daeSBarry Smith ascii->tab += tabs; 332*5c6c1daeSBarry Smith } 333*5c6c1daeSBarry Smith PetscFunctionReturn(0); 334*5c6c1daeSBarry Smith } 335*5c6c1daeSBarry Smith 336*5c6c1daeSBarry Smith #undef __FUNCT__ 337*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIISubtractTab" 338*5c6c1daeSBarry Smith /*@ 339*5c6c1daeSBarry Smith PetscViewerASCIISubtractTab - Subtracts from the number of times an ASCII viewer tabs before printing 340*5c6c1daeSBarry Smith 341*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 342*5c6c1daeSBarry Smith 343*5c6c1daeSBarry Smith Input Parameters: 344*5c6c1daeSBarry Smith + viewer - optained with PetscViewerASCIIOpen() 345*5c6c1daeSBarry Smith - tabs - number of tabs 346*5c6c1daeSBarry Smith 347*5c6c1daeSBarry Smith Level: developer 348*5c6c1daeSBarry Smith 349*5c6c1daeSBarry Smith Fortran Note: 350*5c6c1daeSBarry Smith This routine is not supported in Fortran. 351*5c6c1daeSBarry Smith 352*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 353*5c6c1daeSBarry Smith Concepts: tab^setting 354*5c6c1daeSBarry Smith 355*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 356*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 357*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer(), PetscViewerASCIIPushTab() 358*5c6c1daeSBarry Smith @*/ 359*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIISubtractTab(PetscViewer viewer,PetscInt tabs) 360*5c6c1daeSBarry Smith { 361*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 362*5c6c1daeSBarry Smith PetscBool iascii; 363*5c6c1daeSBarry Smith PetscErrorCode ierr; 364*5c6c1daeSBarry Smith 365*5c6c1daeSBarry Smith PetscFunctionBegin; 366*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 367*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 368*5c6c1daeSBarry Smith if (iascii) { 369*5c6c1daeSBarry Smith ascii->tab -= tabs; 370*5c6c1daeSBarry Smith } 371*5c6c1daeSBarry Smith PetscFunctionReturn(0); 372*5c6c1daeSBarry Smith } 373*5c6c1daeSBarry Smith 374*5c6c1daeSBarry Smith #undef __FUNCT__ 375*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIISynchronizedAllow" 376*5c6c1daeSBarry Smith /*@C 377*5c6c1daeSBarry Smith PetscViewerASCIISynchronizedAllow - Allows calls to PetscViewerASCIISynchronizedPrintf() for this viewer 378*5c6c1daeSBarry Smith 379*5c6c1daeSBarry Smith Collective on PetscViewer 380*5c6c1daeSBarry Smith 381*5c6c1daeSBarry Smith Input Parameters: 382*5c6c1daeSBarry Smith + viewer - optained with PetscViewerASCIIOpen() 383*5c6c1daeSBarry Smith - allow - PETSC_TRUE to allow the synchronized printing 384*5c6c1daeSBarry Smith 385*5c6c1daeSBarry Smith Level: intermediate 386*5c6c1daeSBarry Smith 387*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 388*5c6c1daeSBarry Smith Concepts: tab^setting 389*5c6c1daeSBarry Smith 390*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 391*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 392*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer() 393*5c6c1daeSBarry Smith @*/ 394*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIISynchronizedAllow(PetscViewer viewer,PetscBool allow) 395*5c6c1daeSBarry Smith { 396*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 397*5c6c1daeSBarry Smith PetscBool iascii; 398*5c6c1daeSBarry Smith PetscErrorCode ierr; 399*5c6c1daeSBarry Smith 400*5c6c1daeSBarry Smith PetscFunctionBegin; 401*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 402*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 403*5c6c1daeSBarry Smith if (iascii) { 404*5c6c1daeSBarry Smith ascii->allowsynchronized = allow; 405*5c6c1daeSBarry Smith } 406*5c6c1daeSBarry Smith PetscFunctionReturn(0); 407*5c6c1daeSBarry Smith } 408*5c6c1daeSBarry Smith 409*5c6c1daeSBarry Smith #undef __FUNCT__ 410*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIPushTab" 411*5c6c1daeSBarry Smith /*@ 412*5c6c1daeSBarry Smith PetscViewerASCIIPushTab - Adds one more tab to the amount that PetscViewerASCIIPrintf() 413*5c6c1daeSBarry Smith lines are tabbed. 414*5c6c1daeSBarry Smith 415*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 416*5c6c1daeSBarry Smith 417*5c6c1daeSBarry Smith Input Parameters: 418*5c6c1daeSBarry Smith . viewer - optained with PetscViewerASCIIOpen() 419*5c6c1daeSBarry Smith 420*5c6c1daeSBarry Smith Level: developer 421*5c6c1daeSBarry Smith 422*5c6c1daeSBarry Smith Fortran Note: 423*5c6c1daeSBarry Smith This routine is not supported in Fortran. 424*5c6c1daeSBarry Smith 425*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 426*5c6c1daeSBarry Smith Concepts: tab^setting 427*5c6c1daeSBarry Smith 428*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 429*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 430*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer() 431*5c6c1daeSBarry Smith @*/ 432*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIPushTab(PetscViewer viewer) 433*5c6c1daeSBarry Smith { 434*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 435*5c6c1daeSBarry Smith PetscBool iascii; 436*5c6c1daeSBarry Smith PetscErrorCode ierr; 437*5c6c1daeSBarry Smith 438*5c6c1daeSBarry Smith PetscFunctionBegin; 439*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 440*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 441*5c6c1daeSBarry Smith if (iascii) { 442*5c6c1daeSBarry Smith ascii->tab++; 443*5c6c1daeSBarry Smith } 444*5c6c1daeSBarry Smith PetscFunctionReturn(0); 445*5c6c1daeSBarry Smith } 446*5c6c1daeSBarry Smith 447*5c6c1daeSBarry Smith #undef __FUNCT__ 448*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIPopTab" 449*5c6c1daeSBarry Smith /*@ 450*5c6c1daeSBarry Smith PetscViewerASCIIPopTab - Removes one tab from the amount that PetscViewerASCIIPrintf() 451*5c6c1daeSBarry Smith lines are tabbed. 452*5c6c1daeSBarry Smith 453*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 454*5c6c1daeSBarry Smith 455*5c6c1daeSBarry Smith Input Parameters: 456*5c6c1daeSBarry Smith . viewer - optained with PetscViewerASCIIOpen() 457*5c6c1daeSBarry Smith 458*5c6c1daeSBarry Smith Level: developer 459*5c6c1daeSBarry Smith 460*5c6c1daeSBarry Smith Fortran Note: 461*5c6c1daeSBarry Smith This routine is not supported in Fortran. 462*5c6c1daeSBarry Smith 463*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 464*5c6c1daeSBarry Smith Concepts: tab^setting 465*5c6c1daeSBarry Smith 466*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 467*5c6c1daeSBarry Smith PetscViewerASCIIPushTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIOpen(), 468*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer() 469*5c6c1daeSBarry Smith @*/ 470*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIPopTab(PetscViewer viewer) 471*5c6c1daeSBarry Smith { 472*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 473*5c6c1daeSBarry Smith PetscErrorCode ierr; 474*5c6c1daeSBarry Smith PetscBool iascii; 475*5c6c1daeSBarry Smith 476*5c6c1daeSBarry Smith PetscFunctionBegin; 477*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 478*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 479*5c6c1daeSBarry Smith if (iascii) { 480*5c6c1daeSBarry Smith if (ascii->tab <= 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"More tabs popped than pushed"); 481*5c6c1daeSBarry Smith ascii->tab--; 482*5c6c1daeSBarry Smith } 483*5c6c1daeSBarry Smith PetscFunctionReturn(0); 484*5c6c1daeSBarry Smith } 485*5c6c1daeSBarry Smith 486*5c6c1daeSBarry Smith #undef __FUNCT__ 487*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIUseTabs" 488*5c6c1daeSBarry Smith /*@ 489*5c6c1daeSBarry Smith PetscViewerASCIIUseTabs - Turns on or off the use of tabs with the ASCII PetscViewer 490*5c6c1daeSBarry Smith 491*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 492*5c6c1daeSBarry Smith 493*5c6c1daeSBarry Smith Input Parameters: 494*5c6c1daeSBarry Smith + viewer - optained with PetscViewerASCIIOpen() 495*5c6c1daeSBarry Smith - flg - PETSC_TRUE or PETSC_FALSE 496*5c6c1daeSBarry Smith 497*5c6c1daeSBarry Smith Level: developer 498*5c6c1daeSBarry Smith 499*5c6c1daeSBarry Smith Fortran Note: 500*5c6c1daeSBarry Smith This routine is not supported in Fortran. 501*5c6c1daeSBarry Smith 502*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^formating 503*5c6c1daeSBarry Smith Concepts: tab^setting 504*5c6c1daeSBarry Smith 505*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 506*5c6c1daeSBarry Smith PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIPushTab(), PetscViewerASCIIOpen(), 507*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer() 508*5c6c1daeSBarry Smith @*/ 509*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIUseTabs(PetscViewer viewer,PetscBool flg) 510*5c6c1daeSBarry Smith { 511*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 512*5c6c1daeSBarry Smith PetscBool iascii; 513*5c6c1daeSBarry Smith PetscErrorCode ierr; 514*5c6c1daeSBarry Smith 515*5c6c1daeSBarry Smith PetscFunctionBegin; 516*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 517*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 518*5c6c1daeSBarry Smith if (iascii) { 519*5c6c1daeSBarry Smith if (flg) { 520*5c6c1daeSBarry Smith ascii->tab = ascii->tab_store; 521*5c6c1daeSBarry Smith } else { 522*5c6c1daeSBarry Smith ascii->tab_store = ascii->tab; 523*5c6c1daeSBarry Smith ascii->tab = 0; 524*5c6c1daeSBarry Smith } 525*5c6c1daeSBarry Smith } 526*5c6c1daeSBarry Smith PetscFunctionReturn(0); 527*5c6c1daeSBarry Smith } 528*5c6c1daeSBarry Smith 529*5c6c1daeSBarry Smith /* ----------------------------------------------------------------------- */ 530*5c6c1daeSBarry Smith 531*5c6c1daeSBarry Smith #include <../src/sys/fileio/mprint.h> /* defines the queue datastructures and variables */ 532*5c6c1daeSBarry Smith 533*5c6c1daeSBarry Smith #undef __FUNCT__ 534*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIPrintf" 535*5c6c1daeSBarry Smith /*@C 536*5c6c1daeSBarry Smith PetscViewerASCIIPrintf - Prints to a file, only from the first 537*5c6c1daeSBarry Smith processor in the PetscViewer 538*5c6c1daeSBarry Smith 539*5c6c1daeSBarry Smith Not Collective, but only first processor in set has any effect 540*5c6c1daeSBarry Smith 541*5c6c1daeSBarry Smith Input Parameters: 542*5c6c1daeSBarry Smith + viewer - optained with PetscViewerASCIIOpen() 543*5c6c1daeSBarry Smith - format - the usual printf() format string 544*5c6c1daeSBarry Smith 545*5c6c1daeSBarry Smith Level: developer 546*5c6c1daeSBarry Smith 547*5c6c1daeSBarry Smith Fortran Note: 548*5c6c1daeSBarry Smith The call sequence is PetscViewerASCIIPrintf(PetscViewer, character(*), int ierr) from Fortran. 549*5c6c1daeSBarry Smith That is, you can only pass a single character string from Fortran. 550*5c6c1daeSBarry Smith 551*5c6c1daeSBarry Smith Concepts: PetscViewerASCII^printing 552*5c6c1daeSBarry Smith Concepts: printing^to file 553*5c6c1daeSBarry Smith Concepts: printf 554*5c6c1daeSBarry Smith 555*5c6c1daeSBarry Smith .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIOpen(), 556*5c6c1daeSBarry Smith PetscViewerASCIIPushTab(), PetscViewerASCIIPopTab(), PetscViewerASCIISynchronizedPrintf(), 557*5c6c1daeSBarry Smith PetscViewerCreate(), PetscViewerDestroy(), PetscViewerSetType(), PetscViewerASCIIGetPointer(), PetscViewerASCIISynchronizedAllow() 558*5c6c1daeSBarry Smith @*/ 559*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIPrintf(PetscViewer viewer,const char format[],...) 560*5c6c1daeSBarry Smith { 561*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII*)viewer->data; 562*5c6c1daeSBarry Smith PetscMPIInt rank; 563*5c6c1daeSBarry Smith PetscInt tab; 564*5c6c1daeSBarry Smith PetscErrorCode ierr; 565*5c6c1daeSBarry Smith FILE *fd = ascii->fd; 566*5c6c1daeSBarry Smith PetscBool iascii; 567*5c6c1daeSBarry Smith int err; 568*5c6c1daeSBarry Smith 569*5c6c1daeSBarry Smith PetscFunctionBegin; 570*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 571*5c6c1daeSBarry Smith PetscValidCharPointer(format,2); 572*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 573*5c6c1daeSBarry Smith if (!iascii) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Not ASCII PetscViewer"); 574*5c6c1daeSBarry Smith 575*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);CHKERRQ(ierr); 576*5c6c1daeSBarry Smith if (!rank) { 577*5c6c1daeSBarry Smith va_list Argp; 578*5c6c1daeSBarry Smith if (ascii->bviewer) { 579*5c6c1daeSBarry Smith petsc_printfqueuefile = fd; 580*5c6c1daeSBarry Smith } 581*5c6c1daeSBarry Smith 582*5c6c1daeSBarry Smith tab = ascii->tab; 583*5c6c1daeSBarry Smith while (tab--) {ierr = PetscFPrintf(PETSC_COMM_SELF,fd," ");CHKERRQ(ierr);} 584*5c6c1daeSBarry Smith 585*5c6c1daeSBarry Smith va_start(Argp,format); 586*5c6c1daeSBarry Smith ierr = (*PetscVFPrintf)(fd,format,Argp);CHKERRQ(ierr); 587*5c6c1daeSBarry Smith err = fflush(fd); 588*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 589*5c6c1daeSBarry Smith if (petsc_history) { 590*5c6c1daeSBarry Smith va_start(Argp,format); 591*5c6c1daeSBarry Smith tab = ascii->tab; 592*5c6c1daeSBarry Smith while (tab--) {ierr = PetscFPrintf(PETSC_COMM_SELF,fd," ");CHKERRQ(ierr);} 593*5c6c1daeSBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 594*5c6c1daeSBarry Smith err = fflush(petsc_history); 595*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 596*5c6c1daeSBarry Smith } 597*5c6c1daeSBarry Smith va_end(Argp); 598*5c6c1daeSBarry Smith } 599*5c6c1daeSBarry Smith PetscFunctionReturn(0); 600*5c6c1daeSBarry Smith } 601*5c6c1daeSBarry Smith 602*5c6c1daeSBarry Smith #undef __FUNCT__ 603*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetName" 604*5c6c1daeSBarry Smith /*@C 605*5c6c1daeSBarry Smith PetscViewerFileSetName - Sets the name of the file the PetscViewer uses. 606*5c6c1daeSBarry Smith 607*5c6c1daeSBarry Smith Collective on PetscViewer 608*5c6c1daeSBarry Smith 609*5c6c1daeSBarry Smith Input Parameters: 610*5c6c1daeSBarry Smith + viewer - the PetscViewer; either ASCII or binary 611*5c6c1daeSBarry Smith - name - the name of the file it should use 612*5c6c1daeSBarry Smith 613*5c6c1daeSBarry Smith Level: advanced 614*5c6c1daeSBarry Smith 615*5c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PetscViewerDestroy(), 616*5c6c1daeSBarry Smith PetscViewerASCIIGetPointer(), PetscViewerASCIIPrintf(), PetscViewerASCIISynchronizedPrintf() 617*5c6c1daeSBarry Smith 618*5c6c1daeSBarry Smith @*/ 619*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileSetName(PetscViewer viewer,const char name[]) 620*5c6c1daeSBarry Smith { 621*5c6c1daeSBarry Smith PetscErrorCode ierr; 622*5c6c1daeSBarry Smith 623*5c6c1daeSBarry Smith PetscFunctionBegin; 624*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 625*5c6c1daeSBarry Smith PetscValidCharPointer(name,2); 626*5c6c1daeSBarry Smith ierr = PetscTryMethod(viewer,"PetscViewerFileSetName_C",(PetscViewer,const char[]),(viewer,name));CHKERRQ(ierr); 627*5c6c1daeSBarry Smith PetscFunctionReturn(0); 628*5c6c1daeSBarry Smith } 629*5c6c1daeSBarry Smith 630*5c6c1daeSBarry Smith #undef __FUNCT__ 631*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileGetName" 632*5c6c1daeSBarry Smith /*@C 633*5c6c1daeSBarry Smith PetscViewerFileGetName - Gets the name of the file the PetscViewer uses. 634*5c6c1daeSBarry Smith 635*5c6c1daeSBarry Smith Not Collective 636*5c6c1daeSBarry Smith 637*5c6c1daeSBarry Smith Input Parameter: 638*5c6c1daeSBarry Smith . viewer - the PetscViewer; either ASCII or binary 639*5c6c1daeSBarry Smith 640*5c6c1daeSBarry Smith Output Parameter: 641*5c6c1daeSBarry Smith . name - the name of the file it is using 642*5c6c1daeSBarry Smith 643*5c6c1daeSBarry Smith Level: advanced 644*5c6c1daeSBarry Smith 645*5c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PetscViewerFileSetName() 646*5c6c1daeSBarry Smith 647*5c6c1daeSBarry Smith @*/ 648*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileGetName(PetscViewer viewer,const char **name) 649*5c6c1daeSBarry Smith { 650*5c6c1daeSBarry Smith PetscErrorCode ierr; 651*5c6c1daeSBarry Smith 652*5c6c1daeSBarry Smith PetscFunctionBegin; 653*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 654*5c6c1daeSBarry Smith ierr = PetscTryMethod(viewer,"PetscViewerFileGetName_C",(PetscViewer,const char **),(viewer,name));CHKERRQ(ierr); 655*5c6c1daeSBarry Smith PetscFunctionReturn(0); 656*5c6c1daeSBarry Smith } 657*5c6c1daeSBarry Smith 658*5c6c1daeSBarry Smith EXTERN_C_BEGIN 659*5c6c1daeSBarry Smith #undef __FUNCT__ 660*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileGetName_ASCII" 661*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileGetName_ASCII(PetscViewer viewer,const char **name) 662*5c6c1daeSBarry Smith { 663*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII*)viewer->data; 664*5c6c1daeSBarry Smith 665*5c6c1daeSBarry Smith PetscFunctionBegin; 666*5c6c1daeSBarry Smith *name = vascii->filename; 667*5c6c1daeSBarry Smith PetscFunctionReturn(0); 668*5c6c1daeSBarry Smith } 669*5c6c1daeSBarry Smith EXTERN_C_END 670*5c6c1daeSBarry Smith 671*5c6c1daeSBarry Smith 672*5c6c1daeSBarry Smith EXTERN_C_BEGIN 673*5c6c1daeSBarry Smith #undef __FUNCT__ 674*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetName_ASCII" 675*5c6c1daeSBarry Smith PetscErrorCode PetscViewerFileSetName_ASCII(PetscViewer viewer,const char name[]) 676*5c6c1daeSBarry Smith { 677*5c6c1daeSBarry Smith PetscErrorCode ierr; 678*5c6c1daeSBarry Smith size_t len; 679*5c6c1daeSBarry Smith char fname[PETSC_MAX_PATH_LEN],*gz; 680*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII*)viewer->data; 681*5c6c1daeSBarry Smith PetscBool isstderr,isstdout; 682*5c6c1daeSBarry Smith PetscMPIInt rank; 683*5c6c1daeSBarry Smith 684*5c6c1daeSBarry Smith PetscFunctionBegin; 685*5c6c1daeSBarry Smith ierr = PetscViewerFileClose_ASCII(viewer);CHKERRQ(ierr); 686*5c6c1daeSBarry Smith if (!name) PetscFunctionReturn(0); 687*5c6c1daeSBarry Smith ierr = PetscStrallocpy(name,&vascii->filename);CHKERRQ(ierr); 688*5c6c1daeSBarry Smith 689*5c6c1daeSBarry Smith /* Is this file to be compressed */ 690*5c6c1daeSBarry Smith vascii->storecompressed = PETSC_FALSE; 691*5c6c1daeSBarry Smith ierr = PetscStrstr(vascii->filename,".gz",&gz);CHKERRQ(ierr); 692*5c6c1daeSBarry Smith if (gz) { 693*5c6c1daeSBarry Smith ierr = PetscStrlen(gz,&len);CHKERRQ(ierr); 694*5c6c1daeSBarry Smith if (len == 3) { 695*5c6c1daeSBarry Smith *gz = 0; 696*5c6c1daeSBarry Smith vascii->storecompressed = PETSC_TRUE; 697*5c6c1daeSBarry Smith } 698*5c6c1daeSBarry Smith } 699*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);CHKERRQ(ierr); 700*5c6c1daeSBarry Smith if (!rank) { 701*5c6c1daeSBarry Smith ierr = PetscStrcmp(name,"stderr",&isstderr);CHKERRQ(ierr); 702*5c6c1daeSBarry Smith ierr = PetscStrcmp(name,"stdout",&isstdout);CHKERRQ(ierr); 703*5c6c1daeSBarry Smith /* empty filename means stdout */ 704*5c6c1daeSBarry Smith if (name[0] == 0) isstdout = PETSC_TRUE; 705*5c6c1daeSBarry Smith if (isstderr) vascii->fd = PETSC_STDERR; 706*5c6c1daeSBarry Smith else if (isstdout) vascii->fd = PETSC_STDOUT; 707*5c6c1daeSBarry Smith else { 708*5c6c1daeSBarry Smith 709*5c6c1daeSBarry Smith 710*5c6c1daeSBarry Smith ierr = PetscFixFilename(name,fname);CHKERRQ(ierr); 711*5c6c1daeSBarry Smith switch(vascii->mode) { 712*5c6c1daeSBarry Smith case FILE_MODE_READ: 713*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"r"); 714*5c6c1daeSBarry Smith break; 715*5c6c1daeSBarry Smith case FILE_MODE_WRITE: 716*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"w"); 717*5c6c1daeSBarry Smith break; 718*5c6c1daeSBarry Smith case FILE_MODE_APPEND: 719*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"a"); 720*5c6c1daeSBarry Smith break; 721*5c6c1daeSBarry Smith case FILE_MODE_UPDATE: 722*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"r+"); 723*5c6c1daeSBarry Smith if (!vascii->fd) { 724*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"w+"); 725*5c6c1daeSBarry Smith } 726*5c6c1daeSBarry Smith break; 727*5c6c1daeSBarry Smith case FILE_MODE_APPEND_UPDATE: 728*5c6c1daeSBarry Smith /* I really want a file which is opened at the end for updating, 729*5c6c1daeSBarry Smith not a+, which opens at the beginning, but makes writes at the end. 730*5c6c1daeSBarry Smith */ 731*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"r+"); 732*5c6c1daeSBarry Smith if (!vascii->fd) { 733*5c6c1daeSBarry Smith vascii->fd = fopen(fname,"w+"); 734*5c6c1daeSBarry Smith } else { 735*5c6c1daeSBarry Smith ierr = fseek(vascii->fd, 0, SEEK_END);CHKERRQ(ierr); 736*5c6c1daeSBarry Smith } 737*5c6c1daeSBarry Smith break; 738*5c6c1daeSBarry Smith default: 739*5c6c1daeSBarry Smith SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Invalid file mode %d", vascii->mode); 740*5c6c1daeSBarry Smith } 741*5c6c1daeSBarry Smith if (!vascii->fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot open PetscViewer file: %s",fname); 742*5c6c1daeSBarry Smith } 743*5c6c1daeSBarry Smith } 744*5c6c1daeSBarry Smith #if defined(PETSC_USE_LOG) 745*5c6c1daeSBarry Smith PetscLogObjectState((PetscObject)viewer,"File: %s",name); 746*5c6c1daeSBarry Smith #endif 747*5c6c1daeSBarry Smith PetscFunctionReturn(0); 748*5c6c1daeSBarry Smith } 749*5c6c1daeSBarry Smith EXTERN_C_END 750*5c6c1daeSBarry Smith 751*5c6c1daeSBarry Smith #undef __FUNCT__ 752*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetSingleton_ASCII" 753*5c6c1daeSBarry Smith PetscErrorCode PetscViewerGetSingleton_ASCII(PetscViewer viewer,PetscViewer *outviewer) 754*5c6c1daeSBarry Smith { 755*5c6c1daeSBarry Smith PetscMPIInt rank; 756*5c6c1daeSBarry Smith PetscErrorCode ierr; 757*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data,*ovascii; 758*5c6c1daeSBarry Smith const char *name; 759*5c6c1daeSBarry Smith 760*5c6c1daeSBarry Smith PetscFunctionBegin; 761*5c6c1daeSBarry Smith if (vascii->sviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Singleton already obtained from PetscViewer and not restored"); 762*5c6c1daeSBarry Smith ierr = PetscViewerCreate(PETSC_COMM_SELF,outviewer);CHKERRQ(ierr); 763*5c6c1daeSBarry Smith ierr = PetscViewerSetType(*outviewer,PETSCVIEWERASCII);CHKERRQ(ierr); 764*5c6c1daeSBarry Smith ovascii = (PetscViewer_ASCII*)(*outviewer)->data; 765*5c6c1daeSBarry Smith ovascii->fd = vascii->fd; 766*5c6c1daeSBarry Smith ovascii->tab = vascii->tab; 767*5c6c1daeSBarry Smith 768*5c6c1daeSBarry Smith vascii->sviewer = *outviewer; 769*5c6c1daeSBarry Smith 770*5c6c1daeSBarry Smith (*outviewer)->format = viewer->format; 771*5c6c1daeSBarry Smith (*outviewer)->iformat = viewer->iformat; 772*5c6c1daeSBarry Smith 773*5c6c1daeSBarry Smith ierr = PetscObjectGetName((PetscObject)viewer,&name);CHKERRQ(ierr); 774*5c6c1daeSBarry Smith ierr = PetscObjectSetName((PetscObject)(*outviewer),name);CHKERRQ(ierr); 775*5c6c1daeSBarry Smith 776*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);CHKERRQ(ierr); 777*5c6c1daeSBarry Smith ((PetscViewer_ASCII*)((*outviewer)->data))->bviewer = viewer; 778*5c6c1daeSBarry Smith (*outviewer)->ops->destroy = PetscViewerDestroy_ASCII_Singleton; 779*5c6c1daeSBarry Smith if (rank) { 780*5c6c1daeSBarry Smith (*outviewer)->ops->flush = 0; 781*5c6c1daeSBarry Smith } else { 782*5c6c1daeSBarry Smith (*outviewer)->ops->flush = PetscViewerFlush_ASCII_Singleton_0; 783*5c6c1daeSBarry Smith } 784*5c6c1daeSBarry Smith PetscFunctionReturn(0); 785*5c6c1daeSBarry Smith } 786*5c6c1daeSBarry Smith 787*5c6c1daeSBarry Smith #undef __FUNCT__ 788*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerRestoreSingleton_ASCII" 789*5c6c1daeSBarry Smith PetscErrorCode PetscViewerRestoreSingleton_ASCII(PetscViewer viewer,PetscViewer *outviewer) 790*5c6c1daeSBarry Smith { 791*5c6c1daeSBarry Smith PetscErrorCode ierr; 792*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)(*outviewer)->data; 793*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII *)viewer->data; 794*5c6c1daeSBarry Smith 795*5c6c1daeSBarry Smith PetscFunctionBegin; 796*5c6c1daeSBarry Smith if (!ascii->sviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Singleton never obtained from PetscViewer"); 797*5c6c1daeSBarry Smith if (ascii->sviewer != *outviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"This PetscViewer did not generate singleton"); 798*5c6c1daeSBarry Smith 799*5c6c1daeSBarry Smith ascii->sviewer = 0; 800*5c6c1daeSBarry Smith vascii->fd = PETSC_STDOUT; 801*5c6c1daeSBarry Smith (*outviewer)->ops->destroy = PetscViewerDestroy_ASCII; 802*5c6c1daeSBarry Smith ierr = PetscViewerDestroy(outviewer);CHKERRQ(ierr); 803*5c6c1daeSBarry Smith ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 804*5c6c1daeSBarry Smith PetscFunctionReturn(0); 805*5c6c1daeSBarry Smith } 806*5c6c1daeSBarry Smith 807*5c6c1daeSBarry Smith #undef __FUNCT__ 808*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetSubcomm_ASCII" 809*5c6c1daeSBarry Smith PetscErrorCode PetscViewerGetSubcomm_ASCII(PetscViewer viewer,MPI_Comm subcomm,PetscViewer *outviewer) 810*5c6c1daeSBarry Smith { 811*5c6c1daeSBarry Smith PetscErrorCode ierr; 812*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data,*ovascii; 813*5c6c1daeSBarry Smith const char *name; 814*5c6c1daeSBarry Smith 815*5c6c1daeSBarry Smith PetscFunctionBegin; 816*5c6c1daeSBarry Smith if (vascii->sviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Subcomm viewer already obtained from PetscViewer and not restored"); 817*5c6c1daeSBarry Smith /* Note that we need to open vascii->filename for the subcomm: 818*5c6c1daeSBarry Smith we can't count on reusing viewer's fd since the root in comm and subcomm may differ. 819*5c6c1daeSBarry Smith Further, if the subcomm happens to be the same as comm, PetscViewerASCIIOpen() will 820*5c6c1daeSBarry Smith will return the current viewer, having increfed it. 821*5c6c1daeSBarry Smith */ 822*5c6c1daeSBarry Smith ierr = PetscViewerASCIIOpen(subcomm,vascii->filename, outviewer);CHKERRQ(ierr); 823*5c6c1daeSBarry Smith if (*outviewer == viewer) PetscFunctionReturn(0); 824*5c6c1daeSBarry Smith ovascii = (PetscViewer_ASCII*)(*outviewer)->data; 825*5c6c1daeSBarry Smith 826*5c6c1daeSBarry Smith ovascii->tab = vascii->tab; 827*5c6c1daeSBarry Smith vascii->sviewer = *outviewer; 828*5c6c1daeSBarry Smith 829*5c6c1daeSBarry Smith (*outviewer)->format = viewer->format; 830*5c6c1daeSBarry Smith (*outviewer)->iformat = viewer->iformat; 831*5c6c1daeSBarry Smith 832*5c6c1daeSBarry Smith ierr = PetscObjectGetName((PetscObject)viewer,&name);CHKERRQ(ierr); 833*5c6c1daeSBarry Smith ierr = PetscObjectSetName((PetscObject)(*outviewer),name);CHKERRQ(ierr); 834*5c6c1daeSBarry Smith 835*5c6c1daeSBarry Smith ((PetscViewer_ASCII*)((*outviewer)->data))->bviewer = viewer; 836*5c6c1daeSBarry Smith (*outviewer)->ops->destroy = PetscViewerDestroy_ASCII_Subcomm; 837*5c6c1daeSBarry Smith PetscFunctionReturn(0); 838*5c6c1daeSBarry Smith } 839*5c6c1daeSBarry Smith 840*5c6c1daeSBarry Smith #undef __FUNCT__ 841*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerRestoreSubcomm_ASCII" 842*5c6c1daeSBarry Smith PetscErrorCode PetscViewerRestoreSubcomm_ASCII(PetscViewer viewer,MPI_Comm subcomm,PetscViewer *outviewer) 843*5c6c1daeSBarry Smith { 844*5c6c1daeSBarry Smith PetscErrorCode ierr; 845*5c6c1daeSBarry Smith PetscViewer_ASCII *oascii = (PetscViewer_ASCII *)(*outviewer)->data; 846*5c6c1daeSBarry Smith PetscViewer_ASCII *ascii = (PetscViewer_ASCII *)viewer->data; 847*5c6c1daeSBarry Smith 848*5c6c1daeSBarry Smith PetscFunctionBegin; 849*5c6c1daeSBarry Smith if (!ascii->sviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Subcomm never obtained from PetscViewer"); 850*5c6c1daeSBarry Smith if (ascii->sviewer != *outviewer) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"The given PetscViewer did not generate this subcomm viewer"); 851*5c6c1daeSBarry Smith 852*5c6c1daeSBarry Smith ascii->sviewer = 0; 853*5c6c1daeSBarry Smith oascii->fd = PETSC_STDOUT; 854*5c6c1daeSBarry Smith (*outviewer)->ops->destroy = PetscViewerDestroy_ASCII; 855*5c6c1daeSBarry Smith ierr = PetscViewerDestroy(outviewer);CHKERRQ(ierr); 856*5c6c1daeSBarry Smith ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 857*5c6c1daeSBarry Smith PetscFunctionReturn(0); 858*5c6c1daeSBarry Smith } 859*5c6c1daeSBarry Smith 860*5c6c1daeSBarry Smith EXTERN_C_BEGIN 861*5c6c1daeSBarry Smith #undef __FUNCT__ 862*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate_ASCII" 863*5c6c1daeSBarry Smith PetscErrorCode PetscViewerCreate_ASCII(PetscViewer viewer) 864*5c6c1daeSBarry Smith { 865*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii; 866*5c6c1daeSBarry Smith PetscErrorCode ierr; 867*5c6c1daeSBarry Smith 868*5c6c1daeSBarry Smith PetscFunctionBegin; 869*5c6c1daeSBarry Smith ierr = PetscNewLog(viewer,PetscViewer_ASCII,&vascii);CHKERRQ(ierr); 870*5c6c1daeSBarry Smith viewer->data = (void*)vascii; 871*5c6c1daeSBarry Smith 872*5c6c1daeSBarry Smith viewer->ops->destroy = PetscViewerDestroy_ASCII; 873*5c6c1daeSBarry Smith viewer->ops->flush = PetscViewerFlush_ASCII; 874*5c6c1daeSBarry Smith viewer->ops->getsingleton = PetscViewerGetSingleton_ASCII; 875*5c6c1daeSBarry Smith viewer->ops->restoresingleton = PetscViewerRestoreSingleton_ASCII; 876*5c6c1daeSBarry Smith viewer->ops->getsubcomm = PetscViewerGetSubcomm_ASCII; 877*5c6c1daeSBarry Smith viewer->ops->restoresubcomm = PetscViewerRestoreSubcomm_ASCII; 878*5c6c1daeSBarry Smith 879*5c6c1daeSBarry Smith /* defaults to stdout unless set with PetscViewerFileSetName() */ 880*5c6c1daeSBarry Smith vascii->fd = PETSC_STDOUT; 881*5c6c1daeSBarry Smith vascii->mode = FILE_MODE_WRITE; 882*5c6c1daeSBarry Smith vascii->bviewer = 0; 883*5c6c1daeSBarry Smith vascii->sviewer = 0; 884*5c6c1daeSBarry Smith viewer->format = PETSC_VIEWER_DEFAULT; 885*5c6c1daeSBarry Smith viewer->iformat = 0; 886*5c6c1daeSBarry Smith vascii->tab = 0; 887*5c6c1daeSBarry Smith vascii->tab_store = 0; 888*5c6c1daeSBarry Smith vascii->filename = 0; 889*5c6c1daeSBarry Smith vascii->closefile = PETSC_TRUE; 890*5c6c1daeSBarry Smith 891*5c6c1daeSBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)viewer,"PetscViewerFileSetName_C","PetscViewerFileSetName_ASCII", 892*5c6c1daeSBarry Smith PetscViewerFileSetName_ASCII);CHKERRQ(ierr); 893*5c6c1daeSBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)viewer,"PetscViewerFileGetName_C","PetscViewerFileGetName_ASCII", 894*5c6c1daeSBarry Smith PetscViewerFileGetName_ASCII);CHKERRQ(ierr); 895*5c6c1daeSBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)viewer,"PetscViewerFileGetMode_C","PetscViewerFileGetMode_ASCII", 896*5c6c1daeSBarry Smith PetscViewerFileGetMode_ASCII);CHKERRQ(ierr); 897*5c6c1daeSBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)viewer,"PetscViewerFileSetMode_C","PetscViewerFileSetMode_ASCII", 898*5c6c1daeSBarry Smith PetscViewerFileSetMode_ASCII);CHKERRQ(ierr); 899*5c6c1daeSBarry Smith 900*5c6c1daeSBarry Smith PetscFunctionReturn(0); 901*5c6c1daeSBarry Smith } 902*5c6c1daeSBarry Smith EXTERN_C_END 903*5c6c1daeSBarry Smith 904*5c6c1daeSBarry Smith 905*5c6c1daeSBarry Smith #undef __FUNCT__ 906*5c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIISynchronizedPrintf" 907*5c6c1daeSBarry Smith /*@C 908*5c6c1daeSBarry Smith PetscViewerASCIISynchronizedPrintf - Prints synchronized output to the specified file from 909*5c6c1daeSBarry Smith several processors. Output of the first processor is followed by that of the 910*5c6c1daeSBarry Smith second, etc. 911*5c6c1daeSBarry Smith 912*5c6c1daeSBarry Smith Not Collective, must call collective PetscViewerFlush() to get the results out 913*5c6c1daeSBarry Smith 914*5c6c1daeSBarry Smith Input Parameters: 915*5c6c1daeSBarry Smith + viewer - the ASCII PetscViewer 916*5c6c1daeSBarry Smith - format - the usual printf() format string 917*5c6c1daeSBarry Smith 918*5c6c1daeSBarry Smith Level: intermediate 919*5c6c1daeSBarry Smith 920*5c6c1daeSBarry Smith Notes: You must have previously called PetscViewerASCIISynchronizeAllow() to allow this routine to be called. 921*5c6c1daeSBarry Smith 922*5c6c1daeSBarry Smith Fortran Note: 923*5c6c1daeSBarry Smith Can only print a single character* string 924*5c6c1daeSBarry Smith 925*5c6c1daeSBarry Smith .seealso: PetscSynchronizedPrintf(), PetscSynchronizedFlush(), PetscFPrintf(), 926*5c6c1daeSBarry Smith PetscFOpen(), PetscViewerFlush(), PetscViewerASCIIGetPointer(), PetscViewerDestroy(), PetscViewerASCIIOpen(), 927*5c6c1daeSBarry Smith PetscViewerASCIIPrintf(), PetscViewerASCIISynchronizedAllow() 928*5c6c1daeSBarry Smith 929*5c6c1daeSBarry Smith @*/ 930*5c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIISynchronizedPrintf(PetscViewer viewer,const char format[],...) 931*5c6c1daeSBarry Smith { 932*5c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII *)viewer->data; 933*5c6c1daeSBarry Smith PetscErrorCode ierr; 934*5c6c1daeSBarry Smith PetscMPIInt rank,size; 935*5c6c1daeSBarry Smith PetscInt tab = vascii->tab; 936*5c6c1daeSBarry Smith MPI_Comm comm; 937*5c6c1daeSBarry Smith FILE *fp; 938*5c6c1daeSBarry Smith PetscBool iascii; 939*5c6c1daeSBarry Smith int err; 940*5c6c1daeSBarry Smith 941*5c6c1daeSBarry Smith PetscFunctionBegin; 942*5c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 943*5c6c1daeSBarry Smith PetscValidCharPointer(format,2); 944*5c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 945*5c6c1daeSBarry Smith if (!iascii) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Not ASCII PetscViewer"); 946*5c6c1daeSBarry Smith ierr = MPI_Comm_size(((PetscObject)viewer)->comm,&size);CHKERRQ(ierr); 947*5c6c1daeSBarry Smith if (size > 1 && !vascii->allowsynchronized) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"First call PetscViewerASCIISynchronizedAllow() to allow this call"); 948*5c6c1daeSBarry Smith if (!viewer->ops->flush) PetscFunctionReturn(0); /* This viewer obtained via PetscViewerGetSubcomm_ASCII(), should not participate. */ 949*5c6c1daeSBarry Smith 950*5c6c1daeSBarry Smith comm = ((PetscObject)viewer)->comm; 951*5c6c1daeSBarry Smith fp = vascii->fd; 952*5c6c1daeSBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 953*5c6c1daeSBarry Smith 954*5c6c1daeSBarry Smith /* First processor prints immediately to fp */ 955*5c6c1daeSBarry Smith if (!rank) { 956*5c6c1daeSBarry Smith va_list Argp; 957*5c6c1daeSBarry Smith 958*5c6c1daeSBarry Smith while (tab--) {ierr = PetscFPrintf(PETSC_COMM_SELF,fp," ");CHKERRQ(ierr);} 959*5c6c1daeSBarry Smith 960*5c6c1daeSBarry Smith va_start(Argp,format); 961*5c6c1daeSBarry Smith ierr = (*PetscVFPrintf)(fp,format,Argp);CHKERRQ(ierr); 962*5c6c1daeSBarry Smith err = fflush(fp); 963*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 964*5c6c1daeSBarry Smith petsc_printfqueuefile = fp; 965*5c6c1daeSBarry Smith if (petsc_history) { 966*5c6c1daeSBarry Smith va_start(Argp,format); 967*5c6c1daeSBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 968*5c6c1daeSBarry Smith err = fflush(petsc_history); 969*5c6c1daeSBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 970*5c6c1daeSBarry Smith } 971*5c6c1daeSBarry Smith va_end(Argp); 972*5c6c1daeSBarry Smith } else { /* other processors add to local queue */ 973*5c6c1daeSBarry Smith char *string; 974*5c6c1daeSBarry Smith va_list Argp; 975*5c6c1daeSBarry Smith size_t fullLength; 976*5c6c1daeSBarry Smith PrintfQueue next; 977*5c6c1daeSBarry Smith 978*5c6c1daeSBarry Smith ierr = PetscNew(struct _PrintfQueue,&next);CHKERRQ(ierr); 979*5c6c1daeSBarry Smith if (petsc_printfqueue) {petsc_printfqueue->next = next; petsc_printfqueue = next;} 980*5c6c1daeSBarry Smith else {petsc_printfqueuebase = petsc_printfqueue = next;} 981*5c6c1daeSBarry Smith petsc_printfqueuelength++; 982*5c6c1daeSBarry Smith next->size = QUEUESTRINGSIZE; 983*5c6c1daeSBarry Smith ierr = PetscMalloc(next->size*sizeof(char), &next->string);CHKERRQ(ierr); 984*5c6c1daeSBarry Smith ierr = PetscMemzero(next->string,next->size);CHKERRQ(ierr); 985*5c6c1daeSBarry Smith string = next->string; 986*5c6c1daeSBarry Smith tab *= 2; 987*5c6c1daeSBarry Smith while (tab--) {*string++ = ' ';} 988*5c6c1daeSBarry Smith va_start(Argp,format); 989*5c6c1daeSBarry Smith ierr = PetscVSNPrintf(string,next->size-2*vascii->tab,format,&fullLength,Argp); 990*5c6c1daeSBarry Smith va_end(Argp); 991*5c6c1daeSBarry Smith } 992*5c6c1daeSBarry Smith PetscFunctionReturn(0); 993*5c6c1daeSBarry Smith } 994*5c6c1daeSBarry Smith 995*5c6c1daeSBarry Smith 996