add docs for new utility function
This commit is contained in:
@ -12,11 +12,16 @@ reduces redundant implementations and encourages consistent behavior.
|
|||||||
I/O with status check
|
I/O with status check
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
These are wrappers around the corresponding C library calls like
|
The the first two functions are wrappers around the corresponding C
|
||||||
``fgets()`` or ``fread()``. They will check if there were errors
|
library calls ``fgets()`` or ``fread()``. They will check if there
|
||||||
on reading or an unexpected end-of-file state was reached. In that
|
were errors on reading or an unexpected end-of-file state was reached.
|
||||||
case, the functions will stop the calculation with an error message,
|
In that case, the functions will stop the calculation with an error
|
||||||
indicating the name of the problematic file, if possible.
|
message, indicating the name of the problematic file, if possible.
|
||||||
|
The :cpp:func:`read_lines_from_file` function will read the requested
|
||||||
|
number of lines of a maximum length into a buffer and will return 0
|
||||||
|
if successful or 1 if not. It also guarantees that all lines are
|
||||||
|
terminated with a newline character and the entire buffer with a
|
||||||
|
NULL character.
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
|
||||||
@ -26,6 +31,9 @@ indicating the name of the problematic file, if possible.
|
|||||||
.. doxygenfunction:: sfread
|
.. doxygenfunction:: sfread
|
||||||
:project: progguide
|
:project: progguide
|
||||||
|
|
||||||
|
.. doxygenfunction:: read_lines_from_file
|
||||||
|
:project: progguide
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
|
||||||
String to number conversions with validity check
|
String to number conversions with validity check
|
||||||
|
|||||||
@ -2190,6 +2190,7 @@ nl
|
|||||||
nlayers
|
nlayers
|
||||||
nlen
|
nlen
|
||||||
Nlines
|
Nlines
|
||||||
|
nlines
|
||||||
nlo
|
nlo
|
||||||
nlocal
|
nlocal
|
||||||
Nlocal
|
Nlocal
|
||||||
|
|||||||
@ -226,7 +226,7 @@ void utils::sfread(const char *srcname, int srcline, void *s, size_t size,
|
|||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
/* read N lines and broadcast */
|
/* read N lines and broadcast */
|
||||||
int utils::read_lines_from_file(FILE *fp, int nlines, int maxline,
|
int utils::read_lines_from_file(FILE *fp, int nlines, int nmax,
|
||||||
char *buffer, int me, MPI_Comm comm)
|
char *buffer, int me, MPI_Comm comm)
|
||||||
{
|
{
|
||||||
char *ptr = buffer;
|
char *ptr = buffer;
|
||||||
@ -235,7 +235,7 @@ int utils::read_lines_from_file(FILE *fp, int nlines, int maxline,
|
|||||||
if (me == 0) {
|
if (me == 0) {
|
||||||
if (fp) {
|
if (fp) {
|
||||||
for (int i = 0; i < nlines; i++) {
|
for (int i = 0; i < nlines; i++) {
|
||||||
ptr = fgets(ptr,maxline,fp);
|
ptr = fgets(ptr,nmax,fp);
|
||||||
if (!ptr) break; // EOF?
|
if (!ptr) break; // EOF?
|
||||||
// advance ptr to end of string and append newline char if needed.
|
// advance ptr to end of string and append newline char if needed.
|
||||||
ptr += strlen(ptr);
|
ptr += strlen(ptr);
|
||||||
|
|||||||
@ -97,19 +97,19 @@ namespace LAMMPS_NS {
|
|||||||
* This function uses repeated calls to fread() to fill a buffer with
|
* This function uses repeated calls to fread() to fill a buffer with
|
||||||
* newline terminated text. If a line does not end in a newline (e.g.
|
* newline terminated text. If a line does not end in a newline (e.g.
|
||||||
* at the end of a file), it is added. The caller has to allocate an
|
* at the end of a file), it is added. The caller has to allocate an
|
||||||
* nlines by maxline sized buffer for storing the text data.
|
* nlines by nmax sized buffer for storing the text data.
|
||||||
* Reading is done by MPI rank 0 of the given communicator only, and
|
* Reading is done by MPI rank 0 of the given communicator only, and
|
||||||
* thus only MPI rank 0 needs to provide a valid file pointer.
|
* thus only MPI rank 0 needs to provide a valid file pointer.
|
||||||
*
|
*
|
||||||
* \param fp file pointer used by fread
|
* \param fp file pointer used by fread
|
||||||
* \param nlines number of lines to be read
|
* \param nlines number of lines to be read
|
||||||
* \param maxline maximum length of a single line
|
* \param nmax maximum length of a single line
|
||||||
* \param buffer buffer for storing the data.
|
* \param buffer buffer for storing the data.
|
||||||
* \param me MPI rank of calling process in MPI communicator
|
* \param me MPI rank of calling process in MPI communicator
|
||||||
* \param comm MPI communicator for broadcast
|
* \param comm MPI communicator for broadcast
|
||||||
* \return 1 if the read was short, 0 if read was succesful */
|
* \return 1 if the read was short, 0 if read was successful */
|
||||||
|
|
||||||
int read_lines_from_file(FILE *fp, int nlines, int maxline,
|
int read_lines_from_file(FILE *fp, int nlines, int nmax,
|
||||||
char *buffer, int me, MPI_Comm comm);
|
char *buffer, int me, MPI_Comm comm);
|
||||||
|
|
||||||
/** Report if a requested style is in a package or may have a typo
|
/** Report if a requested style is in a package or may have a typo
|
||||||
|
|||||||
Reference in New Issue
Block a user