Loading...
Searching...
No Matches
FortranFormat Class Reference

## Public Member Functions

void | SetFormat (const String &formatString)
void | SetInputFile (IFILE &file)
void | GetNextField (String &field)
int | GetNextInteger ()
char | GetNextCharacter ()
bool | ProcessToken (String &field)
void | Flush ()

## Detailed Description

Definition at line 24 of file FortranFormat.h.

## Constructor & Destructor Documentation

## FortranFormat()

FortranFormat::FortranFormat | ( |  | ) |

Definition at line 21 of file FortranFormat.cpp.

{
inputPos = -1;
endOfPattern = false;
}

## Member Function Documentation

## Flush()

void FortranFormat::Flush | ( |  | ) |

Definition at line 356 of file FortranFormat.cpp.

{
while (!endOfPattern)
ProcessToken(buffer);
inputPos = -1;
lastBracket = 1;
lastCount = 0;
formatPos = 1;
repeatCount = 0;
bracketStack.Clear();
bracketCounter.Clear();
bracketCount.Clear();
}

## GetNextCharacter()

char FortranFormat::GetNextCharacter | ( |  | ) |

Definition at line 88 of file FortranFormat.cpp.

{
GetNextField(buffer);
return buffer[0];
}

## GetNextField()

void FortranFormat::GetNextField | ( | String & | field | ) |

Definition at line 95 of file FortranFormat.cpp.

{
while (!ProcessToken(field))
;
}

## GetNextInteger()

int FortranFormat::GetNextInteger | ( |  | ) |

Definition at line 81 of file FortranFormat.cpp.

{
GetNextField(buffer);
return buffer.AsInteger();
}

## ProcessToken()

bool FortranFormat::ProcessToken | ( | String & | field | ) |

Definition at line 101 of file FortranFormat.cpp.

{
// This flag only gets set if we encounter the final bracket or a ':'
endOfPattern = false;
// Read input from file, if appropriate
if (inputPos == -1)
{
inputLine.ReadLine(input);
inputPos = 0;
}
// First read repeat count specifier
if (repeatCount == 0)
repeatCount = GetIntegerFromFormat();
// By default, the repeat count should be 1
if (repeatCount == 0)
repeatCount = 1;
int repeatPos = formatPos;
// Check if this is a new bracketed grouping
if (format[formatPos] == '(')
{
formatPos++;
bracketStack.Push(formatPos);
bracketCounter.Push(repeatCount);
bracketCount.Push(repeatCount);
repeatCount = 0;
return false;
}
// Check if this an 'X' field
if (format[formatPos] == 'X')
{
formatPos++;
// No width specifier allowed for these fields
RejectWidth('X');
// Skip appropriate number of characters
inputPos += repeatCount;
// Reset repeat count
repeatCount = 0;
FinishField();
return false;
}
// Check if this is a '/' (vertical tab field)
if (format[formatPos] == '/')
{
formatPos++;
// No width specifier allowed for these fields
RejectWidth('/');
// Skip the appropriate number of lines
while (repeatCount--)
inputLine.ReadLine(input);
inputPos = 0;
// Separators are optional, so we might already be at the next field
if (format[formatPos] == ',' || format[formatPos] || ')')
FinishField();
return false;
}
// Check that we haven't encountered a rare, but unsupported input type
if (format[formatPos] == 'Q' || format[formatPos] == 'P' || format[formatPos] == 'B')
{
formatPos++;
int problemStart = formatPos;
while (format[formatPos] != ',' && format[formatPos] != ')' && format[formatPos] != '/')
formatPos++;
error("Unsupported pattern in FORMAT statement\n\n"
"Statement \"%s\" includes unsupporterd pattern '%s'\n",
(const char *) format,
(const char *) format.SubStr(problemStart, formatPos - problemStart));
}
if (format[formatPos] == ':')
{
formatPos++;
if (format[formatPos] == ',' || format[formatPos] || ')')
FinishField();
repeatCount = 0;
endOfPattern = true;
return false;
}
// All the other types we recognize include a width specifier
// Identify the location of the type specifier
int typeStart = formatPos;
while (CharacterFollows())
formatPos++;
int typeLen = formatPos - typeStart;
// Retrieve the field width
int width = GetIntegerFromFormat();
if (width == 0)
error("Unrecognized FORMAT statement\n\n"
"Statement \"%s\" is missing a width specifier for a field of type '%s'\n",
(const char *) format, (const char *) format.SubStr(typeStart, typeLen));
// Check for horizontal tab character
if (format[typeStart] == 'T')
{
// Move left by a specified number of characters
if (format[typeStart + 1] == 'L')
inputPos = width > inputPos ? 0 : inputPos - width;
// Move right by a specified number of characters
else if (format[typeStart + 1] == 'R')
inputPos += width;
// Or simply set the appropriate horizontal position
else
inputPos = width;
repeatCount--;
if (repeatCount)
formatPos = repeatPos;
else
FinishField();
return false;
}
// Assume that if we got here, we are looking at a data field!
field.Copy(inputLine, inputPos, width);
field.Trim();
inputPos += width;
repeatCount--;
if (repeatCount)
formatPos = repeatPos;
else
FinishField();
return true;
}

## SetFormat()

void FortranFormat::SetFormat | ( | const String & | formatString | ) |

Definition at line 34 of file FortranFormat.cpp.

{
format = formatString;
inputPos = -1;
endOfPattern = false;
repeatCount = 0;
format.Clear();
// Remove blank spaces from format statement and extract
// the first bracketed expression
int level = 0;
for (int i = 0; i < formatString.Length(); i++)
{
if (formatString[i] == ' ' || formatString[i] == '\t' ||
formatString[i] == '\n' || formatString[i] == '\r')
continue;
if (formatString[i] == '(')
level++;
if (formatString[i] == ')')
level--;
format += formatString[i];
if (level == 0) break;
}
if (format[0] != '(' || format[format.Length() - 1] != ')')
error("Invalid FORTRAN format statement\n\n"
"The statement \"%s\" is not bracketed correctly.\n",
(const char *) formatString);
lastBracket = 1;
lastCount = 0;
formatPos = 1;
repeatCount = 0;
bracketStack.Clear();
bracketCounter.Clear();
bracketCount.Clear();
}

## SetInputFile()

void FortranFormat::SetInputFile | ( | IFILE & | file | ) |

Definition at line 27 of file FortranFormat.cpp.

{
input = file;
inputPos = -1;
endOfPattern = false;
}

The documentation for this class was generated from the following files:

- general/FortranFormat.h
- general/FortranFormat.cpp