NCL Home > Documentation > Functions > String manipulation

print_table

Prints all elements from a list (to stdout).

Available in version 6.1.0 and later.

Prototype

	procedure print_table (
		alist  [1] : list,    
		format [1] : string   
	)

	return_val [*] :  string

Arguments

alist

The input list to print.

format

The format for of the (first) element of the list.

Description

This procedure prints all the elements from the list to stdout.

See Also

print_tabli write_table, write_matrix, asciiwrite, sprintf, sprinti

Examples

Example 1

 a = (/111, 222, 333, 444/)
 b = (/1.1, 2.2, 3.3/)
 c = (/"a", "b", "c"/)
 d = (/11h, 22h/)
 f = (/11l, 22l, 33l, 44l, 55l, 66l/)

 alist = [/a, b, c, d, f/]

 print_table(alist, "%d,%16.2f,%s,%d,%ld")

Output will be:

111,            1.10,a,11,11
222,            2.20,b,22,22
333,            3.30,c,  ,33
444,                , ,  ,44
   ,                , ,  ,55
   ,                , ,  ,66

Example 2

 a = (/111, 222, 333, 444/)
 b = (/1.1, 2.2, 3.3/)
 c = (/"1", "22", "333", "aaaaaa", "bbbb", "cc"/)
 d = (/11h, 22h/)
 f = (/11l, 22l, 33l, 44l, 55l, 66l/)

 alist = [/a, b, c, d, f/]

 header = (/"--------------------------------", \
            "This is a file header", \
            "--------------------------------"/)
 footer = (/"--------------------------------", \
            "This is a file footer", \
            "--------------------------------"/)

 hlist = [/header/]
 flist = [/footer/]

 print_table(hlist, "%s")
 print_table(alist, "%d%16.2f%s%d%ld")
 print_table(flist, "%s")

Output will be:

--------------------------------
This is a file header
--------------------------------
111             1.10 1      11 11
222             2.20 22     22 22
333             3.30 333       33
444                  aaaaaa    44
                     bbbb      55
                     cc        66
--------------------------------
This is a file footer
--------------------------------

Example 3

 i = ispan(1,5,1)
 j = ispan(1000,5000,1000)
 print_table([/i,j/],"low_%05i high_%05i")

Output will be:

low_00001 high_01000
low_00002 high_02000
low_00003 high_03000
low_00004 high_04000
low_00005 high_05000

Example 4:

The variable type must be appropriate for the format. If the user does not specify the width, then the function will use deault settings.

       sta  = (/"Mum", "RNC", "CNB"/)   ; type string
       Temp = (/30, 20, 25/)            ; type integer
       RH   = (/80, 900, 95/)
       WS   = (/2, 3, 4/)
       WD   = (/80, 150, 95/)
       Time = 201411050800l             ; the appended 'l' makes this a 'long' int

       print_table([/Time/], "%li")
       print_table([/"Station","Temp","RH","WS","WD"/], "%s %s %s %s %s ")
       print_table([/sta,Temp,RH,WS,WD/],"%s %i %i %i %i")

; change to float; use  :=  syntax

       Temp := (/30, 20, 25/)*1.0
       RH   := (/80, 900, 95/)*1.0
       WS   := (/2, 3, 4/)*1.0
       WD   := (/80, 150, 95/)*1.0

       print_table([/Time/], "%li")
       print_table([/"Station","Temp","RH","WS","WD"/], "%s %s %s %s %s ")
       print_table([/sta,Temp,RH,WS,WD/],"%s %f %f %f %f")

With default settings for %i the output looks like

201411050800
Station Temp RH WS WD 
Mum 30 80 2 80
RNC 20 900 3 150
CNB 25 95 4 95
With default settings for %f the output looks like

201411050800
Station Temp RH WS WD 
Mum 30.000000 80.000000 2.000000 80.000000
RNC 20.000000 900.000000 3.000000 150.000000
CNB 25.000000 95.000000 4.000000 95.000000