HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
IncrementFilename.c File Reference

Functions for incrementing filename indices. More...

#include <stdio.h>

Go to the source code of this file.

Functions

void IncrementFilenameIndex (char *f, int len)
 
void ResetFilenameIndex (char *f, int len)
 

Detailed Description

Functions for incrementing filename indices.

Author
Debojyoti Ghosh

Definition in file IncrementFilename.c.

Function Documentation

◆ IncrementFilenameIndex()

void IncrementFilenameIndex ( char *  f,
int  len 
)

Increment the output filename of the form op_nnnnn.dat by 1, i.e., the number represented by the string nnnnn is incremented by 1.

Increment a character string representing an integer by 1. For example: "00002" -> "00003"; "3421934" -> "3421935"; "999" -> "000". The string can be of arbitrary length.

Parameters
fCharacter string representing the integer
lenLength of the string

Definition at line 46 of file IncrementFilename.c.

50 {
51  int i;
52  for (i=len-1; i>=0; i--) {
53  if (f[i] == '9') {
54  f[i] = '0';
55  if (!i) fprintf(stderr,"Warning: file increment hit max limit. Resetting to zero.\n");
56  } else {
57  f[i]++;
58  break;
59  }
60  }
61 }

◆ ResetFilenameIndex()

void ResetFilenameIndex ( char *  f,
int  len 
)

Resets the index to "0000..." of a desired length.

Parameters
fCharacter string representing the integer
lenLength of the string

Definition at line 64 of file IncrementFilename.c.

66 {
67  if (!f) return;
68  int i;
69  for (i = 0; i < len; i++) {
70  f[i] = '0';
71  }
72  return;
73 }