All I have is this
Tc=air temperature in degrees Celsius
Tdc=dewpoint temperature in degrees Celsius
(1) Es=6.11*10.0** (7.5*Tc/ (237.7+Tc))
(2) E=6.11*10.0** (7.5*Tdc/ (237.7+Tdc))
(3) Relative Humidity (RH) in percent = (E/Es)*100
In fact ( froma CSV file ) I need to grab a value from Column9 and one from Col 10 use those values to calculate Relative Humidity(%) and put the result at the end of the record/ line. This needs to be repeated till the end of the csv file.Any help appreciated
cheers
From stackoverflow
-
Put the following code in
calc_rh.pl:#!/usr/bin/perl while (<>) { chomp; @f = map { /^\"(.*)\"$/ ? $1 : $_ } split /,/; # Strips double quotes if present ($Tc, $Tdc) = @f[8, 9]; # Assuming Tc in column 9, Tdc in column 10 $Es=6.11*10.0** (7.5*$Tc/ (237.7+$Tc)); $E=6.11*10.0** (7.5*$Tdc/ (237.7+$Tdc)); $RH = sprintf "%.2f", $E/$Es*100; # Or use e.g. "%.4f" for 4 digits after d.p. print join(",", map { "\"$_\"" } @f, $RH), "\n"; }Run with:
perl calc_rh.pl < infile.csv > outfile.csvNOTE: The code above will break if any of your columns contain a comma. It's possible to fix this using downloadable modules, but I get the feeling you just need a quick script.
Also, if you're running in Linux, you may need to run:
perl ./calc_rh.pl < infile.csv > outfile.csvinstead.
-
Guru....thanks mate I think its working ...
cheers
0 comments:
Post a Comment