1e5c89e4eSSatish Balay /* 2e5c89e4eSSatish Balay Utilites routines to add simple ASCII IO capability. 3e5c89e4eSSatish Balay */ 4c6db04a5SJed Brown #include <../src/sys/fileio/mprint.h> 579c0e996SJed Brown #include <errno.h> 6e5c89e4eSSatish Balay /* 7e5c89e4eSSatish Balay If petsc_history is on, then all Petsc*Printf() results are saved 8e5c89e4eSSatish Balay if the appropriate (usually .petschistory) file. 9e5c89e4eSSatish Balay */ 10e5c89e4eSSatish Balay extern FILE *petsc_history; 11e5c89e4eSSatish Balay /* 12e5c89e4eSSatish Balay Allows one to overwrite where standard out is sent. For example 135106ddf5SBarry Smith PETSC_STDOUT = fopen("/dev/ttyXX","w") will cause all standard out 14e5c89e4eSSatish Balay writes to go to terminal XX; assuming you have write permission there 15e5c89e4eSSatish Balay */ 16e5c89e4eSSatish Balay FILE *PETSC_STDOUT = 0; 17ae9b4142SLisandro Dalcin /* 18ae9b4142SLisandro Dalcin Allows one to overwrite where standard error is sent. For example 19ae9b4142SLisandro Dalcin PETSC_STDERR = fopen("/dev/ttyXX","w") will cause all standard error 20ae9b4142SLisandro Dalcin writes to go to terminal XX; assuming you have write permission there 21ae9b4142SLisandro Dalcin */ 22ae9b4142SLisandro Dalcin FILE *PETSC_STDERR = 0; 23b13499bfSbcordonn 24354e5084SJose Roman /* 25354e5084SJose Roman Return the maximum expected new size of the format 26354e5084SJose Roman */ 27354e5084SJose Roman #define PETSC_MAX_LENGTH_FORMAT(l) (l+l/8) 28354e5084SJose Roman 29e5c89e4eSSatish Balay #undef __FUNCT__ 30e5c89e4eSSatish Balay #define __FUNCT__ "PetscFormatConvert" 31c9a19010SBarry Smith /*@C 32c9a19010SBarry Smith PetscFormatConvert - Takes a PETSc format string and converts it to a reqular C format string 33c9a19010SBarry Smith 34c9a19010SBarry Smith Input Parameters: 35c9a19010SBarry Smith + format - the PETSc format string 36c9a19010SBarry Smith . newformat - the location to put the standard C format string values 37c9a19010SBarry Smith - size - the length of newformat 38c9a19010SBarry Smith 39eed5747fSBarry Smith Note: this exists so we can have the same code when PetscInt is either int or long long and PetscScalar is either __float128, double, or float 40c9a19010SBarry Smith 41c9a19010SBarry Smith Level: developer 42c9a19010SBarry Smith 43c9a19010SBarry Smith @*/ 447087cfbeSBarry Smith PetscErrorCode PetscFormatConvert(const char *format,char *newformat,size_t size) 45e5c89e4eSSatish Balay { 46e5c89e4eSSatish Balay PetscInt i = 0,j = 0; 47e5c89e4eSSatish Balay 48eed5747fSBarry Smith PetscFunctionBegin; 497bc47156SJose Roman while (format[i] && j < (PetscInt)size-1) { 507bc47156SJose Roman if (format[i] == '%' && format[i+1] != '%') { 517bc47156SJose Roman /* Find the letter */ 527bc47156SJose Roman for (; format[i] && format[i] <= '9'; i++) newformat[j++] = format[i]; 537bc47156SJose Roman switch (format[i]) { 547bc47156SJose Roman case 'D': 556de02169SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES) 56e5c89e4eSSatish Balay newformat[j++] = 'd'; 57e5c89e4eSSatish Balay #else 58e5c89e4eSSatish Balay newformat[j++] = 'l'; 59e5c89e4eSSatish Balay newformat[j++] = 'l'; 60e5c89e4eSSatish Balay newformat[j++] = 'd'; 61e5c89e4eSSatish Balay #endif 627bc47156SJose Roman break; 637bc47156SJose Roman case 'G': 64ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_DOUBLE) || defined(PETSC_USE_REAL_SINGLE) 65a83599f4SBarry Smith newformat[j++] = 'g'; 66ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128) 67d9822059SBarry Smith newformat[j++] = 'Q'; 6857ddf7daSJose Roman newformat[j++] = 'g'; 69a83599f4SBarry Smith #endif 707bc47156SJose Roman break; 71121a09c4SJose Roman case 'F': 72121a09c4SJose Roman #if defined(PETSC_USE_REAL_DOUBLE) || defined(PETSC_USE_REAL_SINGLE) 73121a09c4SJose Roman newformat[j++] = 'f'; 74121a09c4SJose Roman #elif defined(PETSC_USE_REAL_LONG_DOUBLE) 75121a09c4SJose Roman newformat[j++] = 'L'; 76121a09c4SJose Roman newformat[j++] = 'f'; 77121a09c4SJose Roman #elif defined(PETSC_USE_REAL___FLOAT128) 78121a09c4SJose Roman newformat[j++] = 'Q'; 79121a09c4SJose Roman newformat[j++] = 'f'; 80121a09c4SJose Roman #endif 81121a09c4SJose Roman break; 827bc47156SJose Roman default: 837bc47156SJose Roman newformat[j++] = format[i]; 847bc47156SJose Roman break; 857bc47156SJose Roman } 867bc47156SJose Roman i++; 87a297a907SKarl Rupp } else newformat[j++] = format[i++]; 88e5c89e4eSSatish Balay } 89e5c89e4eSSatish Balay newformat[j] = 0; 90eed5747fSBarry Smith PetscFunctionReturn(0); 91e5c89e4eSSatish Balay } 92e5c89e4eSSatish Balay 93e5c89e4eSSatish Balay #undef __FUNCT__ 94e5c89e4eSSatish Balay #define __FUNCT__ "PetscVSNPrintf" 95c9a19010SBarry Smith /*@C 96c9a19010SBarry Smith PetscVSNPrintf - The PETSc version of vsnprintf(). Converts a PETSc format string into a standard C format string and then puts all the 97c9a19010SBarry Smith function arguments into a string using the format statement. 98c9a19010SBarry Smith 99c9a19010SBarry Smith Input Parameters: 100c9a19010SBarry Smith + str - location to put result 101c9a19010SBarry Smith . len - the amount of space in str 102c9a19010SBarry Smith + format - the PETSc format string 103c9a19010SBarry Smith - fullLength - the amount of space in str actually used. 104c9a19010SBarry Smith 105eed5747fSBarry Smith Developer Notes: this function may be called from an error handler, if an error occurs when it is called by the error handler than likely 106eed5747fSBarry Smith a recursion will occur and possible crash. 107c9a19010SBarry Smith 108c9a19010SBarry Smith Level: developer 109c9a19010SBarry Smith 110c9a19010SBarry Smith @*/ 1117087cfbeSBarry Smith PetscErrorCode PetscVSNPrintf(char *str,size_t len,const char *format,size_t *fullLength,va_list Argp) 112e5c89e4eSSatish Balay { 113e2135aedSMatthew Knepley char *newformat; 114e2135aedSMatthew Knepley char formatbuf[8*1024]; 1151a96acb8SJed Brown size_t oldLength,length; 1161a96acb8SJed Brown int fullLengthInt; 1171a15ef5dSMatthew Knepley PetscErrorCode ierr; 118e5c89e4eSSatish Balay 119eed5747fSBarry Smith PetscFunctionBegin; 120e2135aedSMatthew Knepley ierr = PetscStrlen(format, &oldLength);CHKERRQ(ierr); 121e2135aedSMatthew Knepley if (oldLength < 8*1024) { 122e2135aedSMatthew Knepley newformat = formatbuf; 123354e5084SJose Roman oldLength = 8*1024-1; 124e2135aedSMatthew Knepley } else { 125354e5084SJose Roman oldLength = PETSC_MAX_LENGTH_FORMAT(oldLength); 126*785e854fSJed Brown ierr = PetscMalloc1(oldLength, &newformat);CHKERRQ(ierr); 127e2135aedSMatthew Knepley } 128354e5084SJose Roman PetscFormatConvert(format,newformat,oldLength); 1291a15ef5dSMatthew Knepley ierr = PetscStrlen(newformat, &length);CHKERRQ(ierr); 1302d609e63SMatthew Knepley #if 0 131a297a907SKarl Rupp if (length > len) newformat[len] = '\0'; 1322d609e63SMatthew Knepley #endif 1335a058713SBarry Smith #if defined(PETSC_HAVE_VSNPRINTF_CHAR) 13442c7c0bfSJed Brown fullLengthInt = vsnprintf(str,len,newformat,(char*)Argp); 13589b07760SSatish Balay #elif defined(PETSC_HAVE_VSNPRINTF) 13642c7c0bfSJed Brown fullLengthInt = vsnprintf(str,len,newformat,Argp); 137141c0d65SSatish Balay #elif defined(PETSC_HAVE__VSNPRINTF) 13842c7c0bfSJed Brown fullLengthInt = _vsnprintf(str,len,newformat,Argp); 139e5c89e4eSSatish Balay #else 14089b07760SSatish Balay #error "vsnprintf not found" 141e5c89e4eSSatish Balay #endif 14242c7c0bfSJed Brown if (fullLengthInt < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"vsnprintf() failed"); 1438c74ee41SBarry Smith if (fullLength) *fullLength = (size_t)fullLengthInt; 144e2135aedSMatthew Knepley if (oldLength >= 8*1024) { 145e2135aedSMatthew Knepley ierr = PetscFree(newformat);CHKERRQ(ierr); 146e2135aedSMatthew Knepley } 147eed5747fSBarry Smith PetscFunctionReturn(0); 148e5c89e4eSSatish Balay } 149e5c89e4eSSatish Balay 150e5c89e4eSSatish Balay #undef __FUNCT__ 151c9a19010SBarry Smith #define __FUNCT__ "PetscVFPrintfDefault" 152c9a19010SBarry Smith /*@C 153c9a19010SBarry Smith PetscVFPrintf - All PETSc standard out and error messages are sent through this function; so, in theory, this can 154e5c89e4eSSatish Balay can be replaced with something that does not simply write to a file. 155e5c89e4eSSatish Balay 156c9a19010SBarry Smith To use, write your own function for example, 157c9a19010SBarry Smith $PetscErrorCode mypetscvfprintf(FILE *fd,const char format[],va_list Argp) 158c9a19010SBarry Smith ${ 159c9a19010SBarry Smith $ PetscErrorCode ierr; 160c9a19010SBarry Smith $ 161c9a19010SBarry Smith $ PetscFunctionBegin; 162c9a19010SBarry Smith $ if (fd != stdout && fd != stderr) { handle regular files 163c9a19010SBarry Smith $ ierr = PetscVFPrintfDefault(fd,format,Argp);CHKERR(ierr); 164c9a19010SBarry Smith $ } else { 165c9a19010SBarry Smith $ char buff[BIG]; 166c9a19010SBarry Smith $ size_t length; 167c9a19010SBarry Smith $ ierr = PetscVSNPrintf(buff,BIG,format,&length,Argp);CHKERRQ(ierr); 168c9a19010SBarry Smith $ now send buff to whatever stream or whatever you want 169c9a19010SBarry Smith $ } 170c9a19010SBarry Smith $ PetscFunctionReturn(0); 171c9a19010SBarry Smith $} 172c9a19010SBarry Smith then before the call to PetscInitialize() do the assignment 173c9a19010SBarry Smith $ PetscVFPrintf = mypetscvfprintf; 174c9a19010SBarry Smith 175c9a19010SBarry Smith Notes: For error messages this may be called by any process, for regular standard out it is 176e5c89e4eSSatish Balay called only by process 0 of a given communicator 177e5c89e4eSSatish Balay 178eed5747fSBarry Smith Developer Notes: this could be called by an error handler, if that happens then a recursion of the error handler may occur 179eed5747fSBarry Smith and a crash 180c9a19010SBarry Smith 181c9a19010SBarry Smith Level: developer 182c9a19010SBarry Smith 183c9a19010SBarry Smith .seealso: PetscVSNPrintf(), PetscErrorPrintf() 184c9a19010SBarry Smith 185c9a19010SBarry Smith @*/ 1867087cfbeSBarry Smith PetscErrorCode PetscVFPrintfDefault(FILE *fd,const char *format,va_list Argp) 187e5c89e4eSSatish Balay { 188e2135aedSMatthew Knepley char *newformat; 189e2135aedSMatthew Knepley char formatbuf[8*1024]; 190e2135aedSMatthew Knepley size_t oldLength; 191eed5747fSBarry Smith PetscErrorCode ierr; 1921179db26SBarry Smith 193eed5747fSBarry Smith PetscFunctionBegin; 194eed5747fSBarry Smith ierr = PetscStrlen(format, &oldLength);CHKERRQ(ierr); 195e2135aedSMatthew Knepley if (oldLength < 8*1024) { 196e2135aedSMatthew Knepley newformat = formatbuf; 197354e5084SJose Roman oldLength = 8*1024-1; 198e2135aedSMatthew Knepley } else { 199354e5084SJose Roman oldLength = PETSC_MAX_LENGTH_FORMAT(oldLength); 200*785e854fSJed Brown ierr = PetscMalloc1(oldLength, &newformat);CHKERRQ(ierr); 201e2135aedSMatthew Knepley } 202eed5747fSBarry Smith ierr = PetscFormatConvert(format,newformat,oldLength);CHKERRQ(ierr); 203d8c6e182Sbcordonn 2045a058713SBarry Smith #if defined(PETSC_HAVE_VFPRINTF_CHAR) 205e5c89e4eSSatish Balay vfprintf(fd,newformat,(char*)Argp); 206e5c89e4eSSatish Balay #else 207e5c89e4eSSatish Balay vfprintf(fd,newformat,Argp); 208e5c89e4eSSatish Balay #endif 2095a058713SBarry Smith fflush(fd); 210e2135aedSMatthew Knepley if (oldLength >= 8*1024) { 211eed5747fSBarry Smith ierr = PetscFree(newformat);CHKERRQ(ierr); 212e2135aedSMatthew Knepley } 213eed5747fSBarry Smith PetscFunctionReturn(0); 214e5c89e4eSSatish Balay } 215e5c89e4eSSatish Balay 2165b5bc046SBarry Smith #undef __FUNCT__ 2175b5bc046SBarry Smith #define __FUNCT__ "PetscSNPrintf" 2185b5bc046SBarry Smith /*@C 2195b5bc046SBarry Smith PetscSNPrintf - Prints to a string of given length 2205b5bc046SBarry Smith 2215b5bc046SBarry Smith Not Collective 2225b5bc046SBarry Smith 2235b5bc046SBarry Smith Input Parameters: 2245b5bc046SBarry Smith + str - the string to print to 2255b5bc046SBarry Smith . len - the length of str 2265b5bc046SBarry Smith . format - the usual printf() format string 2275b5bc046SBarry Smith - any arguments 2285b5bc046SBarry Smith 2295b5bc046SBarry Smith Level: intermediate 2305b5bc046SBarry Smith 2315b5bc046SBarry Smith .seealso: PetscSynchronizedFlush(), PetscSynchronizedFPrintf(), PetscFPrintf(), PetscVSNPrintf(), 2325b5bc046SBarry Smith PetscPrintf(), PetscViewerASCIIPrintf(), PetscViewerASCIISynchronizedPrintf() 2335b5bc046SBarry Smith @*/ 2347087cfbeSBarry Smith PetscErrorCode PetscSNPrintf(char *str,size_t len,const char format[],...) 2355b5bc046SBarry Smith { 2365b5bc046SBarry Smith PetscErrorCode ierr; 237c9a19010SBarry Smith size_t fullLength; 2385b5bc046SBarry Smith va_list Argp; 2395b5bc046SBarry Smith 2405b5bc046SBarry Smith PetscFunctionBegin; 2415b5bc046SBarry Smith va_start(Argp,format); 2422d609e63SMatthew Knepley ierr = PetscVSNPrintf(str,len,format,&fullLength,Argp);CHKERRQ(ierr); 2435b5bc046SBarry Smith PetscFunctionReturn(0); 2445b5bc046SBarry Smith } 2455b5bc046SBarry Smith 246257d2499SJed Brown #undef __FUNCT__ 247257d2499SJed Brown #define __FUNCT__ "PetscSNPrintfCount" 248257d2499SJed Brown /*@C 249257d2499SJed Brown PetscSNPrintfCount - Prints to a string of given length, returns count 250257d2499SJed Brown 251257d2499SJed Brown Not Collective 252257d2499SJed Brown 253257d2499SJed Brown Input Parameters: 254257d2499SJed Brown + str - the string to print to 255257d2499SJed Brown . len - the length of str 256257d2499SJed Brown . format - the usual printf() format string 257257d2499SJed Brown . countused - number of characters used 258257d2499SJed Brown - any arguments 259257d2499SJed Brown 260257d2499SJed Brown Level: intermediate 261257d2499SJed Brown 262257d2499SJed Brown .seealso: PetscSynchronizedFlush(), PetscSynchronizedFPrintf(), PetscFPrintf(), PetscVSNPrintf(), 263257d2499SJed Brown PetscPrintf(), PetscViewerASCIIPrintf(), PetscViewerASCIISynchronizedPrintf(), PetscSNPrintf() 264257d2499SJed Brown @*/ 265257d2499SJed Brown PetscErrorCode PetscSNPrintfCount(char *str,size_t len,const char format[],size_t *countused,...) 266257d2499SJed Brown { 267257d2499SJed Brown PetscErrorCode ierr; 268257d2499SJed Brown va_list Argp; 269257d2499SJed Brown 270257d2499SJed Brown PetscFunctionBegin; 271257d2499SJed Brown va_start(Argp,countused); 272257d2499SJed Brown ierr = PetscVSNPrintf(str,len,format,countused,Argp);CHKERRQ(ierr); 273257d2499SJed Brown PetscFunctionReturn(0); 274257d2499SJed Brown } 275257d2499SJed Brown 276e5c89e4eSSatish Balay /* ----------------------------------------------------------------------- */ 277e5c89e4eSSatish Balay 278d30b0576SJed Brown PrintfQueue petsc_printfqueue = 0,petsc_printfqueuebase = 0; 279d30b0576SJed Brown int petsc_printfqueuelength = 0; 280e5c89e4eSSatish Balay 281e5c89e4eSSatish Balay #undef __FUNCT__ 282e5c89e4eSSatish Balay #define __FUNCT__ "PetscSynchronizedPrintf" 283e5c89e4eSSatish Balay /*@C 284e5c89e4eSSatish Balay PetscSynchronizedPrintf - Prints synchronized output from several processors. 285e5c89e4eSSatish Balay Output of the first processor is followed by that of the second, etc. 286e5c89e4eSSatish Balay 287e5c89e4eSSatish Balay Not Collective 288e5c89e4eSSatish Balay 289e5c89e4eSSatish Balay Input Parameters: 290e5c89e4eSSatish Balay + comm - the communicator 291e5c89e4eSSatish Balay - format - the usual printf() format string 292e5c89e4eSSatish Balay 293e5c89e4eSSatish Balay Level: intermediate 294e5c89e4eSSatish Balay 295e5c89e4eSSatish Balay Notes: 296e5c89e4eSSatish Balay REQUIRES a intervening call to PetscSynchronizedFlush() for the information 297e5c89e4eSSatish Balay from all the processors to be printed. 298e5c89e4eSSatish Balay 299e5c89e4eSSatish Balay Fortran Note: 300d60d70ccSBarry Smith The call sequence is PetscSynchronizedPrintf(MPI_Comm, character(*), PetscErrorCode ierr) from Fortran. 301e5c89e4eSSatish Balay That is, you can only pass a single character string from Fortran. 302e5c89e4eSSatish Balay 303e5c89e4eSSatish Balay .seealso: PetscSynchronizedFlush(), PetscSynchronizedFPrintf(), PetscFPrintf(), 304e5c89e4eSSatish Balay PetscPrintf(), PetscViewerASCIIPrintf(), PetscViewerASCIISynchronizedPrintf() 305e5c89e4eSSatish Balay @*/ 3067087cfbeSBarry Smith PetscErrorCode PetscSynchronizedPrintf(MPI_Comm comm,const char format[],...) 307e5c89e4eSSatish Balay { 308e5c89e4eSSatish Balay PetscErrorCode ierr; 309e5c89e4eSSatish Balay PetscMPIInt rank; 310e5c89e4eSSatish Balay 311e5c89e4eSSatish Balay PetscFunctionBegin; 3126180deefSBarry Smith if (comm == MPI_COMM_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Called with MPI_COMM_NULL, likely PetscObjectComm() failed"); 313e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 314e5c89e4eSSatish Balay 315e5c89e4eSSatish Balay /* First processor prints immediately to stdout */ 316e5c89e4eSSatish Balay if (!rank) { 317e5c89e4eSSatish Balay va_list Argp; 318e5c89e4eSSatish Balay va_start(Argp,format); 3191179db26SBarry Smith ierr = (*PetscVFPrintf)(PETSC_STDOUT,format,Argp);CHKERRQ(ierr); 320e5c89e4eSSatish Balay if (petsc_history) { 321cdc7d174SSatish Balay va_start(Argp,format); 3221179db26SBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 323e5c89e4eSSatish Balay } 324e5c89e4eSSatish Balay va_end(Argp); 325e5c89e4eSSatish Balay } else { /* other processors add to local queue */ 326e5c89e4eSSatish Balay va_list Argp; 327e5c89e4eSSatish Balay PrintfQueue next; 328c9a19010SBarry Smith size_t fullLength = 8191; 329e5c89e4eSSatish Balay 330e5c89e4eSSatish Balay ierr = PetscNew(struct _PrintfQueue,&next);CHKERRQ(ierr); 331a297a907SKarl Rupp if (petsc_printfqueue) { 332a297a907SKarl Rupp petsc_printfqueue->next = next; 333a297a907SKarl Rupp petsc_printfqueue = next; 334a297a907SKarl Rupp petsc_printfqueue->next = 0; 335a297a907SKarl Rupp } else petsc_printfqueuebase = petsc_printfqueue = next; 336d30b0576SJed Brown petsc_printfqueuelength++; 3372d609e63SMatthew Knepley next->size = -1; 3389ad23270SJed Brown while ((PetscInt)fullLength >= next->size) { 3392d609e63SMatthew Knepley next->size = fullLength+1; 340a297a907SKarl Rupp 341*785e854fSJed Brown ierr = PetscMalloc1(next->size, &next->string);CHKERRQ(ierr); 342e5c89e4eSSatish Balay va_start(Argp,format); 3432d609e63SMatthew Knepley ierr = PetscMemzero(next->string,next->size);CHKERRQ(ierr); 3442d609e63SMatthew Knepley ierr = PetscVSNPrintf(next->string,next->size,format, &fullLength,Argp);CHKERRQ(ierr); 345e5c89e4eSSatish Balay va_end(Argp); 346e5c89e4eSSatish Balay } 3472d609e63SMatthew Knepley } 348e5c89e4eSSatish Balay PetscFunctionReturn(0); 349e5c89e4eSSatish Balay } 350e5c89e4eSSatish Balay 351e5c89e4eSSatish Balay #undef __FUNCT__ 352e5c89e4eSSatish Balay #define __FUNCT__ "PetscSynchronizedFPrintf" 353e5c89e4eSSatish Balay /*@C 354e5c89e4eSSatish Balay PetscSynchronizedFPrintf - Prints synchronized output to the specified file from 355e5c89e4eSSatish Balay several processors. Output of the first processor is followed by that of the 356e5c89e4eSSatish Balay second, etc. 357e5c89e4eSSatish Balay 358e5c89e4eSSatish Balay Not Collective 359e5c89e4eSSatish Balay 360e5c89e4eSSatish Balay Input Parameters: 361e5c89e4eSSatish Balay + comm - the communicator 362e5c89e4eSSatish Balay . fd - the file pointer 363e5c89e4eSSatish Balay - format - the usual printf() format string 364e5c89e4eSSatish Balay 365e5c89e4eSSatish Balay Level: intermediate 366e5c89e4eSSatish Balay 367e5c89e4eSSatish Balay Notes: 368e5c89e4eSSatish Balay REQUIRES a intervening call to PetscSynchronizedFlush() for the information 369e5c89e4eSSatish Balay from all the processors to be printed. 370e5c89e4eSSatish Balay 371e5c89e4eSSatish Balay .seealso: PetscSynchronizedPrintf(), PetscSynchronizedFlush(), PetscFPrintf(), 372e5c89e4eSSatish Balay PetscFOpen(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIPrintf() 373e5c89e4eSSatish Balay 374e5c89e4eSSatish Balay @*/ 3757087cfbeSBarry Smith PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm comm,FILE *fp,const char format[],...) 376e5c89e4eSSatish Balay { 377e5c89e4eSSatish Balay PetscErrorCode ierr; 378e5c89e4eSSatish Balay PetscMPIInt rank; 379e5c89e4eSSatish Balay 380e5c89e4eSSatish Balay PetscFunctionBegin; 3816180deefSBarry Smith if (comm == MPI_COMM_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Called with MPI_COMM_NULL, likely PetscObjectComm() failed"); 382e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 383e5c89e4eSSatish Balay 384e5c89e4eSSatish Balay /* First processor prints immediately to fp */ 385e5c89e4eSSatish Balay if (!rank) { 386e5c89e4eSSatish Balay va_list Argp; 387e5c89e4eSSatish Balay va_start(Argp,format); 3881179db26SBarry Smith ierr = (*PetscVFPrintf)(fp,format,Argp);CHKERRQ(ierr); 389cdc7d174SSatish Balay if (petsc_history && (fp !=petsc_history)) { 390cdc7d174SSatish Balay va_start(Argp,format); 3911179db26SBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 392e5c89e4eSSatish Balay } 393e5c89e4eSSatish Balay va_end(Argp); 394e5c89e4eSSatish Balay } else { /* other processors add to local queue */ 395e5c89e4eSSatish Balay va_list Argp; 396e5c89e4eSSatish Balay PrintfQueue next; 397c9a19010SBarry Smith size_t fullLength = 8191; 398e5c89e4eSSatish Balay ierr = PetscNew(struct _PrintfQueue,&next);CHKERRQ(ierr); 399a297a907SKarl Rupp if (petsc_printfqueue) { 400a297a907SKarl Rupp petsc_printfqueue->next = next; 401a297a907SKarl Rupp petsc_printfqueue = next; 402a297a907SKarl Rupp petsc_printfqueue->next = 0; 403a297a907SKarl Rupp } else petsc_printfqueuebase = petsc_printfqueue = next; 404d30b0576SJed Brown petsc_printfqueuelength++; 4052d609e63SMatthew Knepley next->size = -1; 4069ad23270SJed Brown while ((PetscInt)fullLength >= next->size) { 4072d609e63SMatthew Knepley next->size = fullLength+1; 408*785e854fSJed Brown ierr = PetscMalloc1(next->size, &next->string);CHKERRQ(ierr); 409e5c89e4eSSatish Balay va_start(Argp,format); 4102d609e63SMatthew Knepley ierr = PetscMemzero(next->string,next->size);CHKERRQ(ierr); 4112d609e63SMatthew Knepley ierr = PetscVSNPrintf(next->string,next->size,format,&fullLength,Argp);CHKERRQ(ierr); 412e5c89e4eSSatish Balay va_end(Argp); 413e5c89e4eSSatish Balay } 4142d609e63SMatthew Knepley } 415e5c89e4eSSatish Balay PetscFunctionReturn(0); 416e5c89e4eSSatish Balay } 417e5c89e4eSSatish Balay 418e5c89e4eSSatish Balay #undef __FUNCT__ 419e5c89e4eSSatish Balay #define __FUNCT__ "PetscSynchronizedFlush" 4200ec8b6e3SBarry Smith /*@C 421e5c89e4eSSatish Balay PetscSynchronizedFlush - Flushes to the screen output from all processors 422e5c89e4eSSatish Balay involved in previous PetscSynchronizedPrintf() calls. 423e5c89e4eSSatish Balay 424e5c89e4eSSatish Balay Collective on MPI_Comm 425e5c89e4eSSatish Balay 426e5c89e4eSSatish Balay Input Parameters: 4270ec8b6e3SBarry Smith + comm - the communicator 4280ec8b6e3SBarry Smith - fd - the file pointer (valid on process 0 of the communicator) 429e5c89e4eSSatish Balay 430e5c89e4eSSatish Balay Level: intermediate 431e5c89e4eSSatish Balay 432e5c89e4eSSatish Balay Notes: 433e5c89e4eSSatish Balay Usage of PetscSynchronizedPrintf() and PetscSynchronizedFPrintf() with 434e5c89e4eSSatish Balay different MPI communicators REQUIRES an intervening call to PetscSynchronizedFlush(). 435e5c89e4eSSatish Balay 436e5c89e4eSSatish Balay .seealso: PetscSynchronizedPrintf(), PetscFPrintf(), PetscPrintf(), PetscViewerASCIIPrintf(), 437e5c89e4eSSatish Balay PetscViewerASCIISynchronizedPrintf() 4380ec8b6e3SBarry Smith C@*/ 4390ec8b6e3SBarry Smith PetscErrorCode PetscSynchronizedFlush(MPI_Comm comm,FILE *fd) 440e5c89e4eSSatish Balay { 441e5c89e4eSSatish Balay PetscErrorCode ierr; 44229a5cbdcSMatthew G. Knepley PetscMPIInt rank,size,tag,i,j,n = 0,dummy = 0; 4432d609e63SMatthew Knepley char *message; 444e5c89e4eSSatish Balay MPI_Status status; 445e5c89e4eSSatish Balay 446e5c89e4eSSatish Balay PetscFunctionBegin; 447e5c89e4eSSatish Balay ierr = PetscCommDuplicate(comm,&comm,&tag);CHKERRQ(ierr); 448e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 449e5c89e4eSSatish Balay ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 450e5c89e4eSSatish Balay 451e5c89e4eSSatish Balay /* First processor waits for messages from all other processors */ 452e5c89e4eSSatish Balay if (!rank) { 4530ec8b6e3SBarry Smith if (!fd) fd = PETSC_STDOUT; 454e5c89e4eSSatish Balay for (i=1; i<size; i++) { 4559f73f8ecSBarry Smith /* to prevent a flood of messages to process zero, request each message separately */ 4569f73f8ecSBarry Smith ierr = MPI_Send(&dummy,1,MPI_INT,i,tag,comm);CHKERRQ(ierr); 457e5c89e4eSSatish Balay ierr = MPI_Recv(&n,1,MPI_INT,i,tag,comm,&status);CHKERRQ(ierr); 458e5c89e4eSSatish Balay for (j=0; j<n; j++) { 45929a5cbdcSMatthew G. Knepley PetscMPIInt size = 0; 4602d609e63SMatthew Knepley 4612d609e63SMatthew Knepley ierr = MPI_Recv(&size,1,MPI_INT,i,tag,comm,&status);CHKERRQ(ierr); 462*785e854fSJed Brown ierr = PetscMalloc1(size, &message);CHKERRQ(ierr); 4632d609e63SMatthew Knepley ierr = MPI_Recv(message,size,MPI_CHAR,i,tag,comm,&status);CHKERRQ(ierr); 4643bf036e2SBarry Smith ierr = PetscFPrintf(comm,fd,"%s",message);CHKERRQ(ierr); 4652d609e63SMatthew Knepley ierr = PetscFree(message);CHKERRQ(ierr); 466e5c89e4eSSatish Balay } 467e5c89e4eSSatish Balay } 468e5c89e4eSSatish Balay } else { /* other processors send queue to processor 0 */ 469d30b0576SJed Brown PrintfQueue next = petsc_printfqueuebase,previous; 470e5c89e4eSSatish Balay 471b3ef9d35SBarry Smith ierr = MPI_Recv(&dummy,1,MPI_INT,0,tag,comm,&status);CHKERRQ(ierr); 472d30b0576SJed Brown ierr = MPI_Send(&petsc_printfqueuelength,1,MPI_INT,0,tag,comm);CHKERRQ(ierr); 473d30b0576SJed Brown for (i=0; i<petsc_printfqueuelength; i++) { 4742d609e63SMatthew Knepley ierr = MPI_Send(&next->size,1,MPI_INT,0,tag,comm);CHKERRQ(ierr); 4752d609e63SMatthew Knepley ierr = MPI_Send(next->string,next->size,MPI_CHAR,0,tag,comm);CHKERRQ(ierr); 476e5c89e4eSSatish Balay previous = next; 477e5c89e4eSSatish Balay next = next->next; 4782d609e63SMatthew Knepley ierr = PetscFree(previous->string);CHKERRQ(ierr); 479e5c89e4eSSatish Balay ierr = PetscFree(previous);CHKERRQ(ierr); 480e5c89e4eSSatish Balay } 481d30b0576SJed Brown petsc_printfqueue = 0; 482d30b0576SJed Brown petsc_printfqueuelength = 0; 483e5c89e4eSSatish Balay } 484e5c89e4eSSatish Balay ierr = PetscCommDestroy(&comm);CHKERRQ(ierr); 485e5c89e4eSSatish Balay PetscFunctionReturn(0); 486e5c89e4eSSatish Balay } 487e5c89e4eSSatish Balay 488e5c89e4eSSatish Balay /* ---------------------------------------------------------------------------------------*/ 489e5c89e4eSSatish Balay 490e5c89e4eSSatish Balay #undef __FUNCT__ 491e5c89e4eSSatish Balay #define __FUNCT__ "PetscFPrintf" 492e5c89e4eSSatish Balay /*@C 493e5c89e4eSSatish Balay PetscFPrintf - Prints to a file, only from the first 494e5c89e4eSSatish Balay processor in the communicator. 495e5c89e4eSSatish Balay 496e5c89e4eSSatish Balay Not Collective 497e5c89e4eSSatish Balay 498e5c89e4eSSatish Balay Input Parameters: 499e5c89e4eSSatish Balay + comm - the communicator 500e5c89e4eSSatish Balay . fd - the file pointer 501e5c89e4eSSatish Balay - format - the usual printf() format string 502e5c89e4eSSatish Balay 503e5c89e4eSSatish Balay Level: intermediate 504e5c89e4eSSatish Balay 505e5c89e4eSSatish Balay Fortran Note: 506e5c89e4eSSatish Balay This routine is not supported in Fortran. 507e5c89e4eSSatish Balay 508e5c89e4eSSatish Balay Concepts: printing^in parallel 509e5c89e4eSSatish Balay Concepts: printf^in parallel 510e5c89e4eSSatish Balay 511e5c89e4eSSatish Balay .seealso: PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(), 512e5c89e4eSSatish Balay PetscViewerASCIISynchronizedPrintf(), PetscSynchronizedFlush() 513e5c89e4eSSatish Balay @*/ 5147087cfbeSBarry Smith PetscErrorCode PetscFPrintf(MPI_Comm comm,FILE* fd,const char format[],...) 515e5c89e4eSSatish Balay { 516e5c89e4eSSatish Balay PetscErrorCode ierr; 517e5c89e4eSSatish Balay PetscMPIInt rank; 518e5c89e4eSSatish Balay 519e5c89e4eSSatish Balay PetscFunctionBegin; 5206180deefSBarry Smith if (comm == MPI_COMM_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Called with MPI_COMM_NULL, likely PetscObjectComm() failed"); 521e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 522e5c89e4eSSatish Balay if (!rank) { 523e5c89e4eSSatish Balay va_list Argp; 524e5c89e4eSSatish Balay va_start(Argp,format); 5251179db26SBarry Smith ierr = (*PetscVFPrintf)(fd,format,Argp);CHKERRQ(ierr); 526cdc7d174SSatish Balay if (petsc_history && (fd !=petsc_history)) { 527cdc7d174SSatish Balay va_start(Argp,format); 5281179db26SBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 529e5c89e4eSSatish Balay } 530e5c89e4eSSatish Balay va_end(Argp); 531e5c89e4eSSatish Balay } 532e5c89e4eSSatish Balay PetscFunctionReturn(0); 533e5c89e4eSSatish Balay } 534e5c89e4eSSatish Balay 535e5c89e4eSSatish Balay #undef __FUNCT__ 536e5c89e4eSSatish Balay #define __FUNCT__ "PetscPrintf" 537e5c89e4eSSatish Balay /*@C 538e5c89e4eSSatish Balay PetscPrintf - Prints to standard out, only from the first 539eed5747fSBarry Smith processor in the communicator. Calls from other processes are ignored. 540e5c89e4eSSatish Balay 541e5c89e4eSSatish Balay Not Collective 542e5c89e4eSSatish Balay 543e5c89e4eSSatish Balay Input Parameters: 544e5c89e4eSSatish Balay + comm - the communicator 545e5c89e4eSSatish Balay - format - the usual printf() format string 546e5c89e4eSSatish Balay 547e5c89e4eSSatish Balay Level: intermediate 548e5c89e4eSSatish Balay 549e5c89e4eSSatish Balay Fortran Note: 550d60d70ccSBarry Smith The call sequence is PetscPrintf(MPI_Comm, character(*), PetscErrorCode ierr) from Fortran. 551e5c89e4eSSatish Balay That is, you can only pass a single character string from Fortran. 552e5c89e4eSSatish Balay 553e5c89e4eSSatish Balay Concepts: printing^in parallel 554e5c89e4eSSatish Balay Concepts: printf^in parallel 555e5c89e4eSSatish Balay 556e5c89e4eSSatish Balay .seealso: PetscFPrintf(), PetscSynchronizedPrintf() 557e5c89e4eSSatish Balay @*/ 5587087cfbeSBarry Smith PetscErrorCode PetscPrintf(MPI_Comm comm,const char format[],...) 559e5c89e4eSSatish Balay { 560e5c89e4eSSatish Balay PetscErrorCode ierr; 561e5c89e4eSSatish Balay PetscMPIInt rank; 562e5c89e4eSSatish Balay 563e5c89e4eSSatish Balay PetscFunctionBegin; 5646180deefSBarry Smith if (comm == MPI_COMM_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Called with MPI_COMM_NULL, likely PetscObjectComm() failed"); 565e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 566e5c89e4eSSatish Balay if (!rank) { 567e5c89e4eSSatish Balay va_list Argp; 568e5c89e4eSSatish Balay va_start(Argp,format); 569eed5747fSBarry Smith ierr = (*PetscVFPrintf)(PETSC_STDOUT,format,Argp);CHKERRQ(ierr); 570e5c89e4eSSatish Balay if (petsc_history) { 571cdc7d174SSatish Balay va_start(Argp,format); 572eed5747fSBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 573e5c89e4eSSatish Balay } 574e5c89e4eSSatish Balay va_end(Argp); 575e5c89e4eSSatish Balay } 576e5c89e4eSSatish Balay PetscFunctionReturn(0); 577e5c89e4eSSatish Balay } 578e5c89e4eSSatish Balay 579e5c89e4eSSatish Balay /* ---------------------------------------------------------------------------------------*/ 580e5c89e4eSSatish Balay #undef __FUNCT__ 581e5c89e4eSSatish Balay #define __FUNCT__ "PetscHelpPrintfDefault" 582c9a19010SBarry Smith /*@C 583c9a19010SBarry Smith PetscHelpPrintf - All PETSc help messages are passing through this function. You can change how help messages are printed by 584c9a19010SBarry Smith replacinng it with something that does not simply write to a stdout. 585c9a19010SBarry Smith 586c9a19010SBarry Smith To use, write your own function for example, 587c9a19010SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....) 588c9a19010SBarry Smith ${ 589c9a19010SBarry Smith $ PetscFunctionReturn(0); 590c9a19010SBarry Smith $} 591c9a19010SBarry Smith then before the call to PetscInitialize() do the assignment 592c9a19010SBarry Smith $ PetscHelpPrintf = mypetschelpprintf; 593c9a19010SBarry Smith 594c9a19010SBarry Smith Note: the default routine used is called PetscHelpPrintfDefault(). 595c9a19010SBarry Smith 596c9a19010SBarry Smith Level: developer 597c9a19010SBarry Smith 598c9a19010SBarry Smith .seealso: PetscVSNPrintf(), PetscVFPrintf(), PetscErrorPrintf() 599c9a19010SBarry Smith @*/ 6007087cfbeSBarry Smith PetscErrorCode PetscHelpPrintfDefault(MPI_Comm comm,const char format[],...) 601e5c89e4eSSatish Balay { 602e5c89e4eSSatish Balay PetscErrorCode ierr; 603e5c89e4eSSatish Balay PetscMPIInt rank; 604e5c89e4eSSatish Balay 605e5c89e4eSSatish Balay PetscFunctionBegin; 6066180deefSBarry Smith if (comm == MPI_COMM_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Called with MPI_COMM_NULL, likely PetscObjectComm() failed"); 607e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 608e5c89e4eSSatish Balay if (!rank) { 609e5c89e4eSSatish Balay va_list Argp; 610e5c89e4eSSatish Balay va_start(Argp,format); 6111179db26SBarry Smith ierr = (*PetscVFPrintf)(PETSC_STDOUT,format,Argp);CHKERRQ(ierr); 612e5c89e4eSSatish Balay if (petsc_history) { 613cdc7d174SSatish Balay va_start(Argp,format); 6141179db26SBarry Smith ierr = (*PetscVFPrintf)(petsc_history,format,Argp);CHKERRQ(ierr); 615e5c89e4eSSatish Balay } 616e5c89e4eSSatish Balay va_end(Argp); 617e5c89e4eSSatish Balay } 618e5c89e4eSSatish Balay PetscFunctionReturn(0); 619e5c89e4eSSatish Balay } 620e5c89e4eSSatish Balay 621e5c89e4eSSatish Balay /* ---------------------------------------------------------------------------------------*/ 622e5c89e4eSSatish Balay 623e5c89e4eSSatish Balay 624e5c89e4eSSatish Balay #undef __FUNCT__ 625e5c89e4eSSatish Balay #define __FUNCT__ "PetscSynchronizedFGets" 626e5c89e4eSSatish Balay /*@C 627e5c89e4eSSatish Balay PetscSynchronizedFGets - Several processors all get the same line from a file. 628e5c89e4eSSatish Balay 629e5c89e4eSSatish Balay Collective on MPI_Comm 630e5c89e4eSSatish Balay 631e5c89e4eSSatish Balay Input Parameters: 632e5c89e4eSSatish Balay + comm - the communicator 633e5c89e4eSSatish Balay . fd - the file pointer 634e5c89e4eSSatish Balay - len - the length of the output buffer 635e5c89e4eSSatish Balay 636e5c89e4eSSatish Balay Output Parameter: 637e31d4fa4SJed Brown . string - the line read from the file, at end of file string[0] == 0 638e5c89e4eSSatish Balay 639e5c89e4eSSatish Balay Level: intermediate 640e5c89e4eSSatish Balay 641e5c89e4eSSatish Balay .seealso: PetscSynchronizedPrintf(), PetscSynchronizedFlush(), 642e5c89e4eSSatish Balay PetscFOpen(), PetscViewerASCIISynchronizedPrintf(), PetscViewerASCIIPrintf() 643e5c89e4eSSatish Balay 644e5c89e4eSSatish Balay @*/ 6457087cfbeSBarry Smith PetscErrorCode PetscSynchronizedFGets(MPI_Comm comm,FILE *fp,size_t len,char string[]) 646e5c89e4eSSatish Balay { 647e5c89e4eSSatish Balay PetscErrorCode ierr; 648e5c89e4eSSatish Balay PetscMPIInt rank; 649e5c89e4eSSatish Balay 650e5c89e4eSSatish Balay PetscFunctionBegin; 651e5c89e4eSSatish Balay ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 652e5c89e4eSSatish Balay 653e5c89e4eSSatish Balay if (!rank) { 654047b9c12SMatthew G Knepley char *ptr = fgets(string, len, fp); 655047b9c12SMatthew G Knepley 656047b9c12SMatthew G Knepley if (!ptr) { 657e31d4fa4SJed Brown string[0] = 0; 658e31d4fa4SJed Brown if (!feof(fp)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_FILE_READ, "Error reading from file: %d", errno); 659047b9c12SMatthew G Knepley } 660e5c89e4eSSatish Balay } 661e5c89e4eSSatish Balay ierr = MPI_Bcast(string,len,MPI_BYTE,0,comm);CHKERRQ(ierr); 662e5c89e4eSSatish Balay PetscFunctionReturn(0); 663e5c89e4eSSatish Balay } 664238ccf28SShri Abhyankar 665238ccf28SShri Abhyankar #if defined(PETSC_HAVE_MATLAB_ENGINE) 666c6db04a5SJed Brown #include <mex.h> 667238ccf28SShri Abhyankar #undef __FUNCT__ 668238ccf28SShri Abhyankar #define __FUNCT__ "PetscVFPrintf_Matlab" 6697087cfbeSBarry Smith PetscErrorCode PetscVFPrintf_Matlab(FILE *fd,const char format[],va_list Argp) 670238ccf28SShri Abhyankar { 671238ccf28SShri Abhyankar PetscErrorCode ierr; 672238ccf28SShri Abhyankar 673238ccf28SShri Abhyankar PetscFunctionBegin; 674238ccf28SShri Abhyankar if (fd != stdout && fd != stderr) { /* handle regular files */ 675238ccf28SShri Abhyankar ierr = PetscVFPrintfDefault(fd,format,Argp);CHKERRQ(ierr); 676238ccf28SShri Abhyankar } else { 677238ccf28SShri Abhyankar size_t len=8*1024,length; 678238ccf28SShri Abhyankar char buf[len]; 679238ccf28SShri Abhyankar 680238ccf28SShri Abhyankar ierr = PetscVSNPrintf(buf,len,format,&length,Argp);CHKERRQ(ierr); 681df413903SBarry Smith mexPrintf("%s",buf); 682238ccf28SShri Abhyankar } 683238ccf28SShri Abhyankar PetscFunctionReturn(0); 684238ccf28SShri Abhyankar } 685238ccf28SShri Abhyankar #endif 6866fc7ef2bSBarry Smith 6876fc7ef2bSBarry Smith #undef __FUNCT__ 6888c74ee41SBarry Smith #define __FUNCT__ "PetscFormatStrip" 6898c74ee41SBarry Smith /*@C 6908c74ee41SBarry Smith PetscFormatStrip - Takes a PETSc format string and removes all numerical modifiers to % operations 6918c74ee41SBarry Smith 6928c74ee41SBarry Smith Input Parameters: 6938c74ee41SBarry Smith . format - the PETSc format string 6948c74ee41SBarry Smith 6958c74ee41SBarry Smith Level: developer 6968c74ee41SBarry Smith 6978c74ee41SBarry Smith @*/ 6988c74ee41SBarry Smith PetscErrorCode PetscFormatStrip(char *format) 6998c74ee41SBarry Smith { 7008c74ee41SBarry Smith size_t loc1 = 0, loc2 = 0; 7018c74ee41SBarry Smith 7028c74ee41SBarry Smith PetscFunctionBegin; 7038c74ee41SBarry Smith while (format[loc2]) { 7048c74ee41SBarry Smith if (format[loc2] == '%') { 7058c74ee41SBarry Smith format[loc1++] = format[loc2++]; 7068c74ee41SBarry Smith while (format[loc2] && ((format[loc2] >= '0' && format[loc2] <= '9') || format[loc2] == '.')) loc2++; 7078c74ee41SBarry Smith } 7088c74ee41SBarry Smith format[loc1++] = format[loc2++]; 7098c74ee41SBarry Smith } 7108c74ee41SBarry Smith PetscFunctionReturn(0); 7118c74ee41SBarry Smith } 7128c74ee41SBarry Smith 713