USING: accessors arrays ascii assocs calendar calendar.format
classes.tuple combinators command-line continuations csv
formatting grouping http.client io io.encodings.ascii io.files
-io.styles kernel math math.extras math.parser namespaces regexp
-sequences sorting.human splitting strings urls wrap.strings ;
+io.styles kernel math math.extras math.functions math.parser
+namespaces regexp sequences sorting.human splitting strings urls
+wrap.strings ;
IN: metar
[ parse-direction ] dip {
{ [ "KT" ?tail ] [ "knots" ] }
{ [ "MPS" ?tail ] [ "meters per second" ] }
+ [ "knots" ]
} cond [ "G" split1 ] dip '[ _ parse-speed ] bi@
[ "%s at %s with gusts to %s " sprintf ]
[ "%s at %s" sprintf ] if*
[ @ [ 65 wrap-string write ] when* ] with-cell
] with-row ; inline
+: calc-humidity ( report -- humidity/f )
+ [ dew-point>> ] [ temperature>> ] bi 2dup and [
+ [ " " split1 drop string>number ] bi@
+ [ [ 17.625 * ] [ 243.04 + ] bi / e^ ] bi@ / 100 *
+ round "%d%%" sprintf
+ ] [ 2drop f ] if ;
+
: metar-report. ( report -- )
standard-table-style [
{
[ "Temperature" [ temperature>> ] row. ]
[ "Dew point" [ dew-point>> ] row. ]
[ "Altimeter" [ altimeter>> ] row. ]
+ [ "Humidity" [ calc-humidity ] row. ]
[ "Remarks" [ remarks>> ] row. ]
[ "Raw Text" [ raw>> ] row. ]
} cleave