IRAF Logo
  • Package and Task Reference
    • dataio: Data format conversion package (RFITS, etc.)
    • images: General image processing package
    • language: The command language itself
      • intro: A brief introduction to IRAF
      • expressions: Standard expression syntax in IRAF tasks
      • break: Break out of a loop
      • case: One setting of a switch
      • commands: A discussion of the syntax of IRAF commands
      • cursors: Graphics and image display cursors
      • declarations: Parameter/variable declarations
      • default: The default clause of a switch
      • else: Else clause of IF statement
      • for: C-style for loop construct
      • if: If statement
      • goto: Goto statement
      • logging: Discussion of CL logging
      • next: Start next iteration of a loop
      • parameters: Discussion of parameter attributes
      • procedure: Start a procedure script
      • return: Return from script with an optional value
      • switch: Multiway branch construct
      • while: While loop
      • access: Test if a file exists
      • back: Return to the previous directory (after a chdir)
      • beep: Send a beep to the terminal
      • bye: Exit a task or package
      • cache: Cache parameter files, or print the current cache list
      • cd: Change directory
      • chdir: Change directory
      • cl: Execute commands from the standard input
      • clbye: A cl followed by a bye (used to save file descriptors)
      • clear: Clear the terminal screen
      • defpac: Test if a package is defined
      • defpar: Test if a parameter is defined
      • deftask: Test if a task is defined
      • defvar: Test if an environment variable is defined
      • dparam: Dump a pset as a series of task.param=value assignments
      • edit: Edit a text file
      • ehistory: Edit history file to re-execute commands
      • envget: Get the string value of an environment variable
      • eparam: Edit parameters of a task
      • error: Print error code and message and abort
      • flprcache: Flush the process cache
      • fprint: Print a line into a parameter
      • fscan: Scan a list
      • fscanf: Formatted read from a file, or another parameter
      • gflush: Flush any buffered graphics output
      • hidetask: Make a task invisible to the user
      • history: Display commands previously executed
      • imaccess: Test if an image exists
      • jobs: Display status of background jobs
      • keep: Make recent set, task, etc. declarations permanent
      • kill: Kill a background job
      • logout: Log out of the CL
      • lparam: List the parameters of a task
      • mathfcns: Mathematical routines
      • mktemp: Make a temporary (unique) file name
      • osfn: Return the host system equivalent of an IRAF filename
      • package: Define a new package, or print the current package names
      • prcache: Show process cache, or lock a process into the cache
      • print: Print a line on the standard output
      • printf: Formatted print to the standard output
      • putlog: Put a message to the logfile
      • radix: Encode a number in the specified radix
      • redefine: Redefine a task
      • reset: Reset the value of an environment variable
      • scan: Scan the standard input
      • scanf: Formatted read from the standard input
      • service: Service a query from a background job
      • set: Set an environment variable
      • show: Show an environment variable
      • sleep: Hibernate for a specified time
      • strings: String manipulation routines
      • stty: Set/show terminal characteristics
      • task: Define a new task
      • time: Print the current time
      • unlearn: Restore the default parameters for a task or package
      • update: Update a task’s parameters (flush to disk)
      • wait: Wait for all background jobs to complete
      • whereis: locate all occurences of a task in the package list
      • which: locate a task in the package list
    • lists: List processing package
    • obsolete: Obsolete tasks
    • noao: The NOAO optical astronomy packages
    • plot: Plot package
    • proto: Prototype or interim tasks
    • softools: Software tools package
    • system: System utilities package
    • utilities: Miscellaneous utilities package
  • External packages
  • SPP Reference Manual
  • CL Programmer’s Manual
  • IRAF Standards and Conventions
  • Standard Nomenclature
  • Site Manager’s Guide
  • IRAF Release Notes
  • Additional IRAF documentation
  • PyRAF tutorial
IRAF
  • Package and Task Reference
  • language: The command language itself
  • print: Print a line on the standard output

print: Print a line on the standard output

Package: language

Usage

print  expr [expr ...]
fprint param expr [expr ...]
printf format [arg ...]

Parameters

expr
Any expression, the string value of which is to be printed.
param
The fprint call will deposit the output string in the value field of this parameter.
format
A C-like format specification string containing plain characters, which are simply copied into the output string, and conversion specifications, each of which causes conversion and printing of zero or more args.
arg
Any expression, variable, parameter value or constant to be used in the format string's conversion specifications. One arg is required for each conversion specification.

Description

The print and fprint commands format a line of text and write it to either the standard output or in the case of fprint, the p_value field of the named parameter. The output is free format although spaces may be specifically inserted (as quoted string constants) to make the output easier to read. One space is automatically inserted after each numeric argument; this can be defeated by coercing the argument to a string with the str intrinsic function. A newline is automatically output at the end of the output line. I/O redirection may be used with print or printf to write to a file or through a pipe to another task.

The printf command allows more control over the output format and can convert arguments for printing as another type. The format string contains plain text characters and format specifications as well as escape sequences for printing tabs, newlines, etc. Unlike the other two commands, spaces and newlines must be explicitly given in the format string.

A format specification has the form "%[W][.D]Cn", where W is the field width, D is the number of decimal places or the number of digits of precision, C is the format code, and N is radix character for format code "r" only. The W and D fields are optional. The format codes C are as follows:

b    boolean (YES or NO)
c    single character (c or '\c' or '\0nnn')
d    decimal integer
e    exponential format (D specifies the precision)
f    fixed format (D specifies the number of decimal places)
g    general format (D specifies the precision)
h    hms format (hh:mm:ss.ss, D = no. decimal places)
m    minutes, seconds (or hours, minutes) (mm:ss.ss)
o    octal integer
rN   convert integer in any radix N
s    string (D field specifies max chars to print)
t    advance To column given as field W
u    unsigned decimal integer
w    output the number of spaces given by field W
x    hexadecimal integer
z    complex format (r,r) (D = precision)

Conventions for W (field width) specification:

W =  n      right justify in field of N characters, blank fill
    -n      left justify in field of N characters, blank fill
    0n      zero fill at left (only if right justified)
absent, 0   use as much space as needed (D field sets precision)

Escape sequences (e.g. "\n" for newline):

     formfeed
\n      newline (crlf)
\r      carriage return
\t      tab
\"      string delimiter character
\'      character constant delimiter character
\\      backslash character
\nnn    octal value of character

Compute mode (a parenthesized argument list) is recommended for this task to avoid surprises.

Examples

1. Print the name of the current terminal.

cl> print ("terminal = ", envget ("terminal"))

2. Output a blank line on the standard output, e.g., in a script.

print ("")

3. Format a command and send it to the host system. In this example, "fname" is a string valued parameter.

cl> print ("!ls -l ", fname) | cl

4. Write to a file.

for (x=1.;  x < 1E5;  x *= 10)
    print ("the sqrt of ", x, "is ", sqrt(x), >> "output")

5. Print a formatted string.

cl> printf ("pi = %.6f\n", 2*atan2(1.0,0.0))
pi = 3.141593
cl> printf ("RA = %h  DEC = %m\nExptime = %8.2f\n",ra,dec,etime)
RA = 18:32:33.5 DEC = 23:45.2   Exptime =     1.57

6. Print to a parameter. Note that fprint allows you to create a formatted string, whereas the scan() example requires a struct parameter.

cl> x = 3.14159
cl> fprint (s1, "pi = ", x)
cl> = s1
pi = 3.14159

or

cl> printf ("pi = %g\n", x) | scan (line)

Bugs

The fprint task is not very useful since the same thing can be accomplished by string concatenation and assignment.

See also

scan, scanf, fscan, fscanf, strings

Previous Next

© Copyright 1986 Association of Universities for Research in Astronomy Inc..

Built with Sphinx using a theme provided by Read the Docs.