\section{PRINTF Formated Output Function (C-Style)}

\subsection{Usage}

Prints values to the output.  The general syntax for its use is
\begin{verbatim}
  printf(format,a1,a2,...)
\end{verbatim}
Here \verb|format| is the format string, which is a string that
controls the format of the output.  The values of the variables
\verb|a_i| are substituted into the output as required.  It is
an error if there are not enough variables to satisfy the format
string.  Note that this \verb|printf| command is not vectorized!  Each
variable must be a scalar.

\subsection{Format of the format string}


The  format  string  is a character string, beginning and ending in its
initial shift state, if any.  The format string is composed of zero  or
more   directives:  ordinary  characters  (not  %),  which  are  copied
unchanged to the output stream; and conversion specifications, each  of
which results in fetching zero or more subsequent arguments.  Each 
conversion specification is introduced by the character %, and ends with a
conversion  specifier.  In between there may be (in this order) zero or
more flags, an optional minimum field width, and an optional precision.

The  arguments must correspond properly (after type promotion) with the
conversion specifier, and are used in the order given.

\subsection{The flag characters}

The character \verb|%| is followed by zero or more of the following flags:
\begin{itemize}
\item  \verb|\#|   The  value  should be converted to an ``alternate form''.  For \verb|o| conversions, the first character of the output  string  is  made  zero (by prefixing a \verb|0| if it was not zero already).  For \verb|x| and \verb|X| conversions, a nonzero result has the string \verb|'0x'| (or \verb|'0X'| for  \verb|X|  conversions) prepended to it.  For \verb|a, A, e, E, f, F, g,| and \verb|G|  conversions, the result will always  contain  a  decimal  point,  even  if  no digits follow it (normally, a decimal point appears  in the results of those conversions only if  a  digit  follows).  For \verb|g| and \verb|G| conversions, trailing zeros are not removed from the  result as they would otherwise be.  For other  conversions,  the  result is undefined.

\item  \verb|0|   The value should be zero padded.  For \verb|d, i, o, u, x, X, a, A, e, E, f, F, g,| and \verb|G| conversions, the converted value is padded  on the  left  with  zeros rather than blanks.  If the \verb|0| and \verb|-| flags  both appear, the \verb|0| flag is ignored.  If  a  precision  is  given  with  a numeric conversion \verb|(d, i, o, u, x, and X)|, the \verb|0| flag is  ignored.  For other conversions, the behavior is undefined.

\item  \verb|-|   The converted value is to be left adjusted on the  field  boundary.  (The default is right justification.) Except for \verb|n| conversions, the converted value is padded on the right  with  blanks, rather than on the left with blanks or zeros.  A \verb|-| overrides a \verb|0| if both are given.

\item  \verb|' '| (a space) A blank should be left before a  positive  number  (or empty string) produced by a signed conversion.

\item  \verb|+| A  sign  (\verb|+| or \verb|-|) always be placed before a number produced by a signed conversion.  By default a sign is used only for  negative numbers. A \verb|+| overrides a space if both are used.

\end{itemize}
\subsection{The field width}

An  optional decimal digit string (with nonzero first digit) specifying a 
minimum field width.  If the converted  value  has  fewer  characters than 
the  field  width,  it will be padded with spaces on the left (or right, 
if the left-adjustment flag has been given).  A  negative  field width is 
taken as a \verb|'-'| flag followed by a positive field  width. In no case does 
a non-existent or small field width cause truncation of a field; if the 
result of a conversion is wider than the  field  width, the field is 
expanded to contain the conversion result.

\subsection{The precision}


An  optional  precision,  in the form of a period (\verb|'.'|)  followed by an optional decimal digit string.  If the precision is given as just \verb|'.'|, or the precision is negative, the precision is  taken  to  be zero.   This  gives the minimum number of digits to appear for \verb|d, i, o, u, x|, and \verb|X| conversions, the number of digits to appear after the radix character  for  \verb|a, A, e, E, f|, and \verb|F| conversions, the maximum number of significant digits for \verb|g| and \verb|G| conversions, or the  maximum  number  of  characters to be printed from a string for s conversions.

\subsection{The conversion specifier}


A character that specifies the type of conversion to be  applied.   The
conversion specifiers and their meanings are:
\begin{itemize}
\item  \verb|d,i|   The  int  argument is converted to signed decimal notation.  The  precision, if any, gives the minimum number of digits that  must   appear;  if  the  converted  value  requires fewer digits, it is    padded on the left with zeros. The default precision is \verb|1|.  When \verb|0|  is printed with an explicit precision \verb|0|, the output is empty.

\item  \verb|o,u,x,X|   The unsigned int argument is converted to  unsigned  octal  (\verb|o|),  unsigned  decimal  (\verb|u|),  or unsigned hexadecimal (\verb|x| and \verb|X|) notation.  The letters \verb|abcdef| are used for \verb|x| conversions;  the  letters \verb|ABCDEF| are used for \verb|X| conversions.  The precision, if any,  gives the minimum number of digits that must appear; if the converted  value  requires  fewer  digits, it is padded on the left  with zeros. The default precision is \verb|1|.  When \verb|0| is printed  with  an explicit precision \verb|0|, the output is empty.

\item  \verb|e,E|    The  double  argument  is  rounded  and  converted  in the style  \verb|[-]d.ddde dd| where there is one digit before  the  decimal-point  character and the number of digits after it is equal to the precision; if the precision is missing, it is taken as  \verb|6|;  if  the    precision  is  zero,  no  decimal-point character appears.  An \verb|E|  conversion uses the letter \verb|E| (rather than \verb|e|)  to  introduce  the  exponent.   The exponent always contains at least two digits; if  the value is zero, the exponent is \verb|00|.

\item  \verb|f,F|   The double argument is rounded and converted to decimal notation  in  the  style  \verb|[-]ddd.ddd|, where the number of digits after the decimal-point character is equal to the precision specification.  If  the precision is missing, it is taken as \verb|6|; if the precision  is explicitly zero, no decimal-point character  appears.   If  a   decimal point appears, at least one digit appears before it.

\item  \verb|g,G|   The double argument is converted in style \verb|f| or \verb|e| (or \verb|F| or \verb|E|  for  \verb|G|  conversions).  The precision specifies the number of significant digits.  If the precision is missing, \verb|6| digits  are  given;  if  the  precision is zero, it is treated as \verb|1|.  Style e is used   if the exponent from its conversion is less than \verb|-4|  or  greater than or equal to the precision.  Trailing zeros are removed from  the fractional part of the result; a decimal point appears  only  if it is followed by at least one digit.

\item  \verb|c| The int argument is  converted  to  an  unsigned  char, and  the resulting character is written.

\item  \verb|s| The string argument is printed.

\item  \verb|%|   A \verb|'%'| is written. No argument is converted. The complete conversion specification is \verb|'%%'|.

\end{itemize}
\subsection{Example}

Here are some examples of the use of \verb|printf| with various arguments.  First we print out an integer and double value.
\begin{verbatim}
--> printf('intvalue is %d, floatvalue is %f\n',3,1.53);
intvalue is 3, floatvalue is 1.530000

\end{verbatim}
Next, we print out a string value.
\begin{verbatim}
--> printf('string value is %s\n','hello');
string value is hello

\end{verbatim}
Now, we print out an integer using 12 digits, zeros up front.
\begin{verbatim}
--> printf('integer padded is %012d\n',32);
integer padded is 000000000032

\end{verbatim}
Print out a double precision value with a sign, a total of 18 characters (zero prepended if necessary), a decimal point, and 12 digit precision.
\begin{verbatim}
--> printf('float value is %+018.12f\n',pi);
float value is +0003.141592653590

\end{verbatim}
