15c6c1daeSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscviewer.h" I*/ 35c6c1daeSBarry Smith 45c6c1daeSBarry Smith PetscClassId PETSC_VIEWER_CLASSID; 55c6c1daeSBarry Smith 65c6c1daeSBarry Smith static PetscBool PetscViewerPackageInitialized = PETSC_FALSE; 75c6c1daeSBarry Smith #undef __FUNCT__ 85c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFinalizePackage" 95c6c1daeSBarry Smith /*@C 105c6c1daeSBarry Smith PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 115c6c1daeSBarry Smith called from PetscFinalize(). 125c6c1daeSBarry Smith 135c6c1daeSBarry Smith Level: developer 145c6c1daeSBarry Smith 155c6c1daeSBarry Smith .keywords: Petsc, destroy, package, mathematica 165c6c1daeSBarry Smith .seealso: PetscFinalize() 175c6c1daeSBarry Smith @*/ 185c6c1daeSBarry Smith PetscErrorCode PetscViewerFinalizePackage(void) 195c6c1daeSBarry Smith { 2037e93019SBarry Smith PetscErrorCode ierr; 2137e93019SBarry Smith 225c6c1daeSBarry Smith PetscFunctionBegin; 2337e93019SBarry Smith ierr = PetscFunctionListDestroy(&PetscViewerList);CHKERRQ(ierr); 245c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_FALSE; 250f51fdf8SToby Isaac PetscViewerRegisterAllCalled = PETSC_FALSE; 265c6c1daeSBarry Smith PetscFunctionReturn(0); 275c6c1daeSBarry Smith } 285c6c1daeSBarry Smith 295c6c1daeSBarry Smith #undef __FUNCT__ 305c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerInitializePackage" 315c6c1daeSBarry Smith /*@C 325c6c1daeSBarry Smith PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package. 335c6c1daeSBarry Smith 345c6c1daeSBarry Smith Level: developer 355c6c1daeSBarry Smith 365c6c1daeSBarry Smith .keywords: Petsc, initialize, package 375c6c1daeSBarry Smith .seealso: PetscInitialize() 385c6c1daeSBarry Smith @*/ 39607a6623SBarry Smith PetscErrorCode PetscViewerInitializePackage(void) 405c6c1daeSBarry Smith { 415c6c1daeSBarry Smith char logList[256]; 425c6c1daeSBarry Smith char *className; 435c6c1daeSBarry Smith PetscBool opt; 445c6c1daeSBarry Smith PetscErrorCode ierr; 455c6c1daeSBarry Smith 465c6c1daeSBarry Smith PetscFunctionBegin; 475c6c1daeSBarry Smith if (PetscViewerPackageInitialized) PetscFunctionReturn(0); 485c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_TRUE; 495c6c1daeSBarry Smith /* Register Classes */ 505c6c1daeSBarry Smith ierr = PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);CHKERRQ(ierr); 515c6c1daeSBarry Smith 525c6c1daeSBarry Smith /* Register Constructors */ 53607a6623SBarry Smith ierr = PetscViewerRegisterAll();CHKERRQ(ierr); 545c6c1daeSBarry Smith 555c6c1daeSBarry Smith /* Process info exclusions */ 56c5929fdfSBarry Smith ierr = PetscOptionsGetString(NULL,NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 575c6c1daeSBarry Smith if (opt) { 585c6c1daeSBarry Smith ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr); 595c6c1daeSBarry Smith if (className) { 605c6c1daeSBarry Smith ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr); 615c6c1daeSBarry Smith } 625c6c1daeSBarry Smith } 635c6c1daeSBarry Smith /* Process summary exclusions */ 64c5929fdfSBarry Smith ierr = PetscOptionsGetString(NULL,NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 655c6c1daeSBarry Smith if (opt) { 665c6c1daeSBarry Smith ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr); 675c6c1daeSBarry Smith if (className) { 685c6c1daeSBarry Smith ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr); 695c6c1daeSBarry Smith } 705c6c1daeSBarry Smith } 715c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 72607a6623SBarry Smith ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 735c6c1daeSBarry Smith #endif 745c6c1daeSBarry Smith ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr); 755c6c1daeSBarry Smith PetscFunctionReturn(0); 765c6c1daeSBarry Smith } 775c6c1daeSBarry Smith 785c6c1daeSBarry Smith #undef __FUNCT__ 795c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy" 805c6c1daeSBarry Smith /*@ 815c6c1daeSBarry Smith PetscViewerDestroy - Destroys a PetscViewer. 825c6c1daeSBarry Smith 835c6c1daeSBarry Smith Collective on PetscViewer 845c6c1daeSBarry Smith 855c6c1daeSBarry Smith Input Parameters: 865c6c1daeSBarry Smith . viewer - the PetscViewer to be destroyed. 875c6c1daeSBarry Smith 885c6c1daeSBarry Smith Level: beginner 895c6c1daeSBarry Smith 905c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 915c6c1daeSBarry Smith 925c6c1daeSBarry Smith @*/ 935c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 945c6c1daeSBarry Smith { 955c6c1daeSBarry Smith PetscErrorCode ierr; 965c6c1daeSBarry Smith 975c6c1daeSBarry Smith PetscFunctionBegin; 985c6c1daeSBarry Smith if (!*viewer) PetscFunctionReturn(0); 995c6c1daeSBarry Smith PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 1005c6c1daeSBarry Smith 1015c6c1daeSBarry Smith ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr); 1025c6c1daeSBarry Smith if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; PetscFunctionReturn(0);} 1035c6c1daeSBarry Smith 104e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*viewer);CHKERRQ(ierr); 1055c6c1daeSBarry Smith if ((*viewer)->ops->destroy) { 1065c6c1daeSBarry Smith ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr); 1075c6c1daeSBarry Smith } 1085c6c1daeSBarry Smith ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr); 1095c6c1daeSBarry Smith PetscFunctionReturn(0); 1105c6c1daeSBarry Smith } 1115c6c1daeSBarry Smith 1125c6c1daeSBarry Smith #undef __FUNCT__ 113*fe01d993SBarry Smith #define __FUNCT__ "PetscViewerAndFormatDestroy" 114*fe01d993SBarry Smith /*@C 115*fe01d993SBarry Smith PetscViewerAndFormatDestroy - Destroys a PetscViewerAndFormat struct. 116*fe01d993SBarry Smith 117*fe01d993SBarry Smith Collective on PetscViewer 118*fe01d993SBarry Smith 119*fe01d993SBarry Smith Input Parameters: 120*fe01d993SBarry Smith . viewer - the PetscViewerAndFormat to be destroyed. 121*fe01d993SBarry Smith 122*fe01d993SBarry Smith Level: beginner 123*fe01d993SBarry Smith 124*fe01d993SBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 125*fe01d993SBarry Smith 126*fe01d993SBarry Smith @*/ 127*fe01d993SBarry Smith PetscErrorCode PetscViewerAndFormatDestroy(PetscViewerAndFormat **vf) 128*fe01d993SBarry Smith { 129*fe01d993SBarry Smith PetscErrorCode ierr; 130*fe01d993SBarry Smith 131*fe01d993SBarry Smith PetscFunctionBegin; 132*fe01d993SBarry Smith ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr); 133*fe01d993SBarry Smith ierr = PetscFree(*vf);CHKERRQ(ierr); 134*fe01d993SBarry Smith PetscFunctionReturn(0); 135*fe01d993SBarry Smith } 136*fe01d993SBarry Smith 137*fe01d993SBarry Smith #undef __FUNCT__ 1385c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetType" 1395c6c1daeSBarry Smith /*@C 1405c6c1daeSBarry Smith PetscViewerGetType - Returns the type of a PetscViewer. 1415c6c1daeSBarry Smith 1425c6c1daeSBarry Smith Not Collective 1435c6c1daeSBarry Smith 1445c6c1daeSBarry Smith Input Parameter: 1455c6c1daeSBarry Smith . viewer - the PetscViewer 1465c6c1daeSBarry Smith 1475c6c1daeSBarry Smith Output Parameter: 1485c6c1daeSBarry Smith . type - PetscViewer type (see below) 1495c6c1daeSBarry Smith 1505c6c1daeSBarry Smith Available Types Include: 1515c6c1daeSBarry Smith . PETSCVIEWERSOCKET - Socket PetscViewer 1525c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1535c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1545c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 1555c6c1daeSBarry Smith . PETSCVIEWERDRAW - drawing PetscViewer 1565c6c1daeSBarry Smith 1575c6c1daeSBarry Smith Level: intermediate 1585c6c1daeSBarry Smith 1595c6c1daeSBarry Smith Note: 1605c6c1daeSBarry Smith See include/petscviewer.h for a complete list of PetscViewers. 1615c6c1daeSBarry Smith 1625c6c1daeSBarry Smith PetscViewerType is actually a string 1635c6c1daeSBarry Smith 1645c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 1655c6c1daeSBarry Smith 1665c6c1daeSBarry Smith @*/ 1675c6c1daeSBarry Smith PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 1685c6c1daeSBarry Smith { 1695c6c1daeSBarry Smith PetscFunctionBegin; 1705c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 1715c6c1daeSBarry Smith PetscValidPointer(type,2); 1725c6c1daeSBarry Smith *type = ((PetscObject)viewer)->type_name; 1735c6c1daeSBarry Smith PetscFunctionReturn(0); 1745c6c1daeSBarry Smith } 1755c6c1daeSBarry Smith 1765c6c1daeSBarry Smith #undef __FUNCT__ 1775c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetOptionsPrefix" 1785c6c1daeSBarry Smith /*@C 1795c6c1daeSBarry Smith PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 1805c6c1daeSBarry Smith PetscViewer options in the database. 1815c6c1daeSBarry Smith 1825c6c1daeSBarry Smith Logically Collective on PetscViewer 1835c6c1daeSBarry Smith 1845c6c1daeSBarry Smith Input Parameter: 1855c6c1daeSBarry Smith + viewer - the PetscViewer context 1865c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 1875c6c1daeSBarry Smith 1885c6c1daeSBarry Smith Notes: 1895c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1905c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 1915c6c1daeSBarry Smith 1925c6c1daeSBarry Smith Level: advanced 1935c6c1daeSBarry Smith 1945c6c1daeSBarry Smith .keywords: PetscViewer, set, options, prefix, database 1955c6c1daeSBarry Smith 1965c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions() 1975c6c1daeSBarry Smith @*/ 1985c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 1995c6c1daeSBarry Smith { 2005c6c1daeSBarry Smith PetscErrorCode ierr; 2015c6c1daeSBarry Smith 2025c6c1daeSBarry Smith PetscFunctionBegin; 2035c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2045c6c1daeSBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2055c6c1daeSBarry Smith PetscFunctionReturn(0); 2065c6c1daeSBarry Smith } 2075c6c1daeSBarry Smith 2085c6c1daeSBarry Smith #undef __FUNCT__ 2095c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerAppendOptionsPrefix" 2105c6c1daeSBarry Smith /*@C 2115c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 2125c6c1daeSBarry Smith PetscViewer options in the database. 2135c6c1daeSBarry Smith 2145c6c1daeSBarry Smith Logically Collective on PetscViewer 2155c6c1daeSBarry Smith 2165c6c1daeSBarry Smith Input Parameters: 2175c6c1daeSBarry Smith + viewer - the PetscViewer context 2185c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2195c6c1daeSBarry Smith 2205c6c1daeSBarry Smith Notes: 2215c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2225c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2235c6c1daeSBarry Smith 2245c6c1daeSBarry Smith Level: advanced 2255c6c1daeSBarry Smith 2265c6c1daeSBarry Smith .keywords: PetscViewer, append, options, prefix, database 2275c6c1daeSBarry Smith 2285c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2295c6c1daeSBarry Smith @*/ 2305c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2315c6c1daeSBarry Smith { 2325c6c1daeSBarry Smith PetscErrorCode ierr; 2335c6c1daeSBarry Smith 2345c6c1daeSBarry Smith PetscFunctionBegin; 2355c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2365c6c1daeSBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2375c6c1daeSBarry Smith PetscFunctionReturn(0); 2385c6c1daeSBarry Smith } 2395c6c1daeSBarry Smith 2405c6c1daeSBarry Smith #undef __FUNCT__ 2415c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetOptionsPrefix" 2425c6c1daeSBarry Smith /*@C 2435c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2445c6c1daeSBarry Smith PetscViewer options in the database. 2455c6c1daeSBarry Smith 2465c6c1daeSBarry Smith Not Collective 2475c6c1daeSBarry Smith 2485c6c1daeSBarry Smith Input Parameter: 2495c6c1daeSBarry Smith . viewer - the PetscViewer context 2505c6c1daeSBarry Smith 2515c6c1daeSBarry Smith Output Parameter: 2525c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2535c6c1daeSBarry Smith 2545c6c1daeSBarry Smith Notes: On the fortran side, the user should pass in a string 'prefix' of 2555c6c1daeSBarry Smith sufficient length to hold the prefix. 2565c6c1daeSBarry Smith 2575c6c1daeSBarry Smith Level: advanced 2585c6c1daeSBarry Smith 2595c6c1daeSBarry Smith .keywords: PetscViewer, get, options, prefix, database 2605c6c1daeSBarry Smith 2615c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 2625c6c1daeSBarry Smith @*/ 2635c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 2645c6c1daeSBarry Smith { 2655c6c1daeSBarry Smith PetscErrorCode ierr; 2665c6c1daeSBarry Smith 2675c6c1daeSBarry Smith PetscFunctionBegin; 2685c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2695c6c1daeSBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2705c6c1daeSBarry Smith PetscFunctionReturn(0); 2715c6c1daeSBarry Smith } 2725c6c1daeSBarry Smith 2735c6c1daeSBarry Smith #undef __FUNCT__ 2745c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetUp" 2755c6c1daeSBarry Smith /*@ 2765c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 2775c6c1daeSBarry Smith 2785c6c1daeSBarry Smith Collective on PetscViewer 2795c6c1daeSBarry Smith 2805c6c1daeSBarry Smith Input Parameters: 2815c6c1daeSBarry Smith . viewer - the PetscViewer context 2825c6c1daeSBarry Smith 2835c6c1daeSBarry Smith Notes: 2845c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 2855c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 2865c6c1daeSBarry Smith 2875c6c1daeSBarry Smith Level: advanced 2885c6c1daeSBarry Smith 2895c6c1daeSBarry Smith .keywords: PetscViewer, setup 2905c6c1daeSBarry Smith 2915c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 2925c6c1daeSBarry Smith @*/ 2935c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 2945c6c1daeSBarry Smith { 295c98fd787SBarry Smith PetscErrorCode ierr; 296c98fd787SBarry Smith 2975c6c1daeSBarry Smith PetscFunctionBegin; 2985c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 299c98fd787SBarry Smith if (viewer->setupcalled) PetscFunctionReturn(0); 300c98fd787SBarry Smith if (viewer->ops->setup) { 301c98fd787SBarry Smith ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr); 302c98fd787SBarry Smith } 303c98fd787SBarry Smith viewer->setupcalled = PETSC_TRUE; 3045c6c1daeSBarry Smith PetscFunctionReturn(0); 3055c6c1daeSBarry Smith } 3065c6c1daeSBarry Smith 3075c6c1daeSBarry Smith #undef __FUNCT__ 3085c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerView" 3095c6c1daeSBarry Smith /*@C 3105c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 3115c6c1daeSBarry Smith 3125c6c1daeSBarry Smith Collective on PetscViewer 3135c6c1daeSBarry Smith 3145c6c1daeSBarry Smith Input Parameters: 3155c6c1daeSBarry Smith + v - the viewer 3165c6c1daeSBarry Smith - viewer - visualization context 3175c6c1daeSBarry Smith 3185c6c1daeSBarry Smith Notes: 3195c6c1daeSBarry Smith The available visualization contexts include 3205c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 3215c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 3225c6c1daeSBarry Smith output where only the first processor opens 3235c6c1daeSBarry Smith the file. All other processors send their 3245c6c1daeSBarry Smith data to the first processor to print. 3255c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 3265c6c1daeSBarry Smith 3275c6c1daeSBarry Smith Level: beginner 3285c6c1daeSBarry Smith 3296a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 3305c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 3315c6c1daeSBarry Smith @*/ 3325c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3335c6c1daeSBarry Smith { 3345c6c1daeSBarry Smith PetscErrorCode ierr; 3355c6c1daeSBarry Smith PetscBool iascii; 3365c6c1daeSBarry Smith PetscViewerFormat format; 337e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 338536b137fSBarry Smith PetscBool issaws; 3390076e027SBarry Smith #endif 3405c6c1daeSBarry Smith 3415c6c1daeSBarry Smith PetscFunctionBegin; 3425c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3435c6c1daeSBarry Smith PetscValidType(v,1); 3445c6c1daeSBarry Smith if (!viewer) { 345ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 3465c6c1daeSBarry Smith } 3475c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3485c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3495c6c1daeSBarry Smith 3505c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 351e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 352536b137fSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr); 3530076e027SBarry Smith #endif 3545c6c1daeSBarry Smith if (iascii) { 3555c6c1daeSBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 356dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr); 35798c3331eSBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 3582f234a98SBarry Smith if (v->format) { 3592f234a98SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 3602f234a98SBarry Smith } 3615c6c1daeSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 3622bf49c77SBarry Smith if (v->ops->view) { 3632bf49c77SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 3645c6c1daeSBarry Smith } 3655c6c1daeSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 3665c6c1daeSBarry Smith } 367e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 368536b137fSBarry Smith } else if (issaws) { 3690076e027SBarry Smith if (!((PetscObject)v)->amsmem) { 370e04113cfSBarry Smith ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr); 3710076e027SBarry Smith if (v->ops->view) { 3720076e027SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 3730076e027SBarry Smith } 3740076e027SBarry Smith } 3750076e027SBarry Smith #endif 3765c6c1daeSBarry Smith } 3775c6c1daeSBarry Smith PetscFunctionReturn(0); 3785c6c1daeSBarry Smith } 3791d641e7bSMichael Lange 3801d641e7bSMichael Lange #undef __FUNCT__ 3811d641e7bSMichael Lange #define __FUNCT__ "PetscViewerRead" 3821d641e7bSMichael Lange /*@C 3831d641e7bSMichael Lange PetscViewerRead - Reads data from a PetscViewer 3841d641e7bSMichael Lange 3851d641e7bSMichael Lange Collective on MPI_Comm 3861d641e7bSMichael Lange 3871d641e7bSMichael Lange Input Parameters: 3881d641e7bSMichael Lange + viewer - The viewer 3891d641e7bSMichael Lange . data - Location to write the data 390060da220SMatthew G. Knepley . num - Number of items of data to read 3911d641e7bSMichael Lange - datatype - Type of data to read 3921d641e7bSMichael Lange 393f8e4bde8SMatthew G. Knepley Output Parameters: 394060da220SMatthew G. Knepley . count - number of items of data actually read, or NULL 395f8e4bde8SMatthew G. Knepley 3961d641e7bSMichael Lange Level: beginner 3971d641e7bSMichael Lange 3981d641e7bSMichael Lange Concepts: binary files, ascii files 3991d641e7bSMichael Lange 4006a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), 4011d641e7bSMichael Lange VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(), 4021d641e7bSMichael Lange PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer 4031d641e7bSMichael Lange @*/ 404060da220SMatthew G. Knepley PetscErrorCode PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype) 4051d641e7bSMichael Lange { 4061d641e7bSMichael Lange PetscErrorCode ierr; 4071d641e7bSMichael Lange 4081d641e7bSMichael Lange PetscFunctionBegin; 4091d641e7bSMichael Lange PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4101d641e7bSMichael Lange if (dtype == PETSC_STRING) { 411060da220SMatthew G. Knepley PetscInt c, i = 0, cnt; 4121d641e7bSMichael Lange char *s = (char *)data; 413060da220SMatthew G. Knepley for (c = 0; c < num; c++) { 4141d641e7bSMichael Lange /* Skip leading whitespaces */ 415060da220SMatthew G. Knepley do {ierr = (*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;} 416eb2700f0SMichael Lange while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r'); 4171d641e7bSMichael Lange i++; 4181d641e7bSMichael Lange /* Read strings one char at a time */ 419060da220SMatthew G. Knepley do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;} 420eb2700f0SMichael Lange while (s[i-1]!='\n' && s[i-1]!='\t' && s[i-1]!=' ' && s[i-1]!='\0' && s[i-1]!='\v' && s[i-1]!='\f' && s[i-1]!='\r'); 4211d641e7bSMichael Lange /* Terminate final string */ 422060da220SMatthew G. Knepley if (c == num-1) s[i-1] = '\0'; 4231d641e7bSMichael Lange } 424060da220SMatthew G. Knepley if (count) *count = c; 425060da220SMatthew G. Knepley else if (c < num) SETERRQ2(PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %D < %D strings", c, num); 4261d641e7bSMichael Lange } else { 427060da220SMatthew G. Knepley ierr = (*viewer->ops->read)(viewer, data, num, count, dtype);CHKERRQ(ierr); 4281d641e7bSMichael Lange } 4291d641e7bSMichael Lange PetscFunctionReturn(0); 4301d641e7bSMichael Lange } 431