/* Salary calculation */

Salary >>
 Level : Integer
 Quantity : Integer
 Title : String
;

/* * */

->
Arg Command_line : Array : String : String

If Command_line._ = 1 then 
 - About Script_name
 ' Script_name = Command_line.First_element.1
 ' First_element = 1
Else
 - Salary File_name ( 'R F : 
                             - Levels >R< F
                    )
                    ( A2 A1
                      Average
                      B1 B2 :
                              Say '  ' A2,
                                  '  ' A1,
                                  '- ' Average,
                                  '  ' B1,
                                  '  ' B2
                    )
 ' File_name = Command_line.Latest_element.1
 ' Latest_element = Command_line._
;

/

/* * */

Salary ->
Arg File_name : String
    R : < String > : < Array : Salary >
    F : < I|F, I|F, I|F, I|F, I|F >
+

 Total >>
  Average : Integer
  Sigma, Divider : Integer
 ;

 Total ->
 Arg Total : &Total
     Levels : Array : Salary

 Total.Average = Levels.1.Level

 Do Total.Sigma += (Levels.i.Level - Total.Average) ^ 2,
    Total.Divider ++
 Where i = 2 to Levels._

 /

+

- R >Levels< File_name,
  Total >Total< Levels

Average = Total.Average

Sigma = Sqrt (Total.Sigma / Total.Divider)

A2 <- (Average + Sigma * 2) # '     0'
A1 <- (Average + Sigma    ) # '     0'
B1 <- (Average - Sigma    ) # '     0'
B2 <- (Average - Sigma * 2) # '     0'

- F A2 A1 Average B1 B2

/

Levels ->
Arg Records : &Array : Salary
    File_name : String    

Do while Lines File_name
 If Line 
    ' Line - TextValues >Line< Raw_line
    ' Raw_line - LineIn >Raw_line< File_name then
  Records .= <
               Level    : <- S
               Quantity : <- Q
               Title    : <- T
             >
  ' S, Q, T -- Parse Line S "\t" Q "\t" T "\t" .
 ;
;

/

TextValues Levels ->
Arg S : &String, String : String

S <- String   

Do S <- S "\t\t" "\t"
While S "\t\t"

/

/* * */

About ->
Arg Script_name : String

Say 'Usage: ' Script_name ' File.tsv'

/