A part of an automated tool chain needs some input data from a website accessible through a well-documented and working API to fetch data in "CSV" format. The output of the Invoke-WebRequest requires some further selection of the response data, since the response not only contains the desired "CSV" data but also some explanatory lines. Here's the data (exact URL to reproduce below):
Latitude (deg.): 51.654
Longitude (deg.): 6.606
A H_hor A_sun(w) H_sun(w) A_sun(s) H_sun(s)
-180.0 0.8 -180.0 0.0 -180.0 0.0
-172.5 0.8 -165.6 0.0 -172.9 0.0
-165.0 1.1 -152.1 0.0 -165.9 0.0
-157.5 1.1 -140.0 0.0 -158.9 0.0
-150.0 1.1 -129.4 0.0 -152.2 0.0
-142.5 1.5 -120.1 0.0 -145.7 0.0
-135.0 1.5 -112.0 0.0 -139.4 0.0
-127.5 1.5 -104.7 0.0 -133.3 0.0
-120.0 1.5 -98.1 0.0 -127.4 1.6
-112.5 1.5 -91.9 0.0 -121.6 5.4
-105.0 1.5 -86.1 0.0 -116.0 9.5
-97.5 1.5 -80.5 0.0 -110.5 13.8
-90.0 1.5 -74.9 0.0 -105.1 18.2
-82.5 1.5 -69.5 0.0 -99.5 22.7
-75.0 1.5 -64.0 0.0 -93.9 27.3
-67.5 1.1 -58.4 0.0 -88.1 32.0
-60.0 1.1 -52.6 0.0 -81.9 36.6
-52.5 1.1 -46.7 2.0 -75.3 41.2
-45.0 1.1 -40.6 5.2 -68.0 45.6
-37.5 1.1 -34.3 8.0 -59.9 49.8
-30.0 0.0 -27.8 10.4 -50.6 53.6
-22.5 0.4 -21.1 12.3 -40.0 56.9
-15.0 0.4 -14.1 13.7 -27.9 59.5
-7.5 0.4 -7.1 14.6 -14.4 61.2
0.0 0.0 0.0 14.9 0.0 61.8
7.5 0.0 7.1 14.6 14.4 61.2
15.0 0.0 14.1 13.7 27.9 59.5
22.5 0.0 21.1 12.3 40.0 56.9
30.0 0.4 27.8 10.4 50.6 53.6
37.5 0.0 34.3 8.0 59.9 49.8
45.0 0.0 40.6 5.2 68.0 45.6
52.5 0.0 46.7 2.0 75.3 41.2
60.0 0.0 52.6 0.0 81.9 36.6
67.5 0.0 58.4 0.0 88.1 32.0
75.0 0.0 64.0 0.0 93.9 27.3
82.5 0.4 69.5 0.0 99.5 22.7
90.0 0.4 74.9 0.0 105.1 18.2
97.5 0.0 80.5 0.0 110.5 13.8
105.0 0.8 86.1 0.0 116.0 9.5
112.5 0.8 91.9 0.0 121.6 5.4
120.0 0.8 98.1 0.0 127.4 1.6
127.5 0.8 104.7 0.0 133.3 0.0
135.0 0.4 112.0 0.0 139.4 0.0
142.5 0.4 120.1 0.0 145.7 0.0
150.0 0.8 129.4 0.0 152.2 0.0
157.5 0.8 140.0 0.0 158.9 0.0
165.0 0.8 152.1 0.0 165.9 0.0
172.5 0.8 165.6 0.0 172.9 0.0
180.0 0.8 180.0 0.0 180.0 0.0
A: Azimuth (0 = S, 90 = W, -90 = E) (degree)
H_hor: Horizon height (degree)
A_sun(w): Sun azimuth in the winter solstice (Dec 21) (0 = S, 90 = W, -90 = E) (degree)
H_sun(w): Sun height in the winter solstice (Dec 21) (degree)
A_sun(s): Sun azimuth in the summer solstice (June 21) (0 = S, 90 = W, -90 = E) (degree)
H_sun(s): Sun height in the summer solstice (June 21) (degree)
PVGIS (c) European Union, 2001-2021
I'd like to only select the lines matching '^[0-9-]' (positive and negative numbers). Essentially, selecting the following lines:
-180.0 0.8 -180.0 0.0 -180.0 0.0
-172.5 0.8 -165.6 0.0 -172.9 0.0
-165.0 1.1 -152.1 0.0 -165.9 0.0
-157.5 1.1 -140.0 0.0 -158.9 0.0
-150.0 1.1 -129.4 0.0 -152.2 0.0
-142.5 1.5 -120.1 0.0 -145.7 0.0
-135.0 1.5 -112.0 0.0 -139.4 0.0
-127.5 1.5 -104.7 0.0 -133.3 0.0
-120.0 1.5 -98.1 0.0 -127.4 1.6
-112.5 1.5 -91.9 0.0 -121.6 5.4
-105.0 1.5 -86.1 0.0 -116.0 9.5
-97.5 1.5 -80.5 0.0 -110.5 13.8
-90.0 1.5 -74.9 0.0 -105.1 18.2
-82.5 1.5 -69.5 0.0 -99.5 22.7
-75.0 1.5 -64.0 0.0 -93.9 27.3
-67.5 1.1 -58.4 0.0 -88.1 32.0
-60.0 1.1 -52.6 0.0 -81.9 36.6
-52.5 1.1 -46.7 2.0 -75.3 41.2
-45.0 1.1 -40.6 5.2 -68.0 45.6
-37.5 1.1 -34.3 8.0 -59.9 49.8
-30.0 0.0 -27.8 10.4 -50.6 53.6
-22.5 0.4 -21.1 12.3 -40.0 56.9
-15.0 0.4 -14.1 13.7 -27.9 59.5
-7.5 0.4 -7.1 14.6 -14.4 61.2
0.0 0.0 0.0 14.9 0.0 61.8
7.5 0.0 7.1 14.6 14.4 61.2
15.0 0.0 14.1 13.7 27.9 59.5
22.5 0.0 21.1 12.3 40.0 56.9
30.0 0.4 27.8 10.4 50.6 53.6
37.5 0.0 34.3 8.0 59.9 49.8
45.0 0.0 40.6 5.2 68.0 45.6
52.5 0.0 46.7 2.0 75.3 41.2
60.0 0.0 52.6 0.0 81.9 36.6
67.5 0.0 58.4 0.0 88.1 32.0
75.0 0.0 64.0 0.0 93.9 27.3
82.5 0.4 69.5 0.0 99.5 22.7
90.0 0.4 74.9 0.0 105.1 18.2
97.5 0.0 80.5 0.0 110.5 13.8
105.0 0.8 86.1 0.0 116.0 9.5
112.5 0.8 91.9 0.0 121.6 5.4
120.0 0.8 98.1 0.0 127.4 1.6
127.5 0.8 104.7 0.0 133.3 0.0
135.0 0.4 112.0 0.0 139.4 0.0
142.5 0.4 120.1 0.0 145.7 0.0
150.0 0.8 129.4 0.0 152.2 0.0
157.5 0.8 140.0 0.0 158.9 0.0
165.0 0.8 152.1 0.0 165.9 0.0
172.5 0.8 165.6 0.0 172.9 0.0
180.0 0.8 180.0 0.0 180.0 0.0
As an example, let's look at the following session explaining my confusion:
~##❯ $horizonUrl = 'https://re.jrc.ec.europa.eu/api/printhorizon?lat=51.654&lon=6.606&browser=0&outputformat=csv'
~##❯ $response = Invoke-WebRequest -Uri $horizonUrl
~##❯ $respcont = $response.Content
~##❯ $respcontstr = [String[]]$response.Content
~##❯ $respcontobj = [Object[]]$response.Content
~##❯ $respcont | Select-String -Pattern "^[0-9-]" -Raw
~##❯ $respcontstr | Select-String -Pattern "^[0-9-]" -Raw
~##❯ $respcontobj | Select-String -Pattern "^[0-9-]" -Raw
~##❯ $respcont.GetType().Name + " " + $respcont.GetType().BaseType
String System.Object
~##❯ $respcontstr.GetType().Name + " " + $respcontstr.GetType().BaseType
String[] array
~##❯ $respcontobj.GetType().Name + " " + $respcontobj.GetType().BaseType
Object[] array
---> No output on the Select-String for the variants above <---
~##❯ Invoke-WebRequest -Uri $horizonUrl -OutFile .\horizon.csv
~##❯ $gc = (Get-Content .\horizon.csv)
~##❯ $gc.GetType().Name + " " + $gc.GetType().BaseType
Object[] array
~##❯ $gc | Select-String -Pattern "^[0-9-]" -Raw
-180.0 0.8 -180.0 0.0 -180.0 0.0
-172.5 0.8 -165.6 0.0 -172.9 0.0
-165.0 1.1 -152.1 0.0 -165.9 0.0
-157.5 1.1 -140.0 0.0 -158.9 0.0
-150.0 1.1 -129.4 0.0 -152.2 0.0
-142.5 1.5 -120.1 0.0 -145.7 0.0
-135.0 1.5 -112.0 0.0 -139.4 0.0
-127.5 1.5 -104.7 0.0 -133.3 0.0
[...]
---> Piped through Get-Content, Select-String dumps the desired output <---
How come Select-String works well together with an intermediate file in piped command chain, however not when used directly, without storing the response content of the Invoke-WebRequest?
The explicit type conversion above was my meager attempt at mimicking the data structure of the output of Get-Content. All the outputs before the pipe look identical in the console (lines of strings).
What did I miss?
The Content property on the response object you get from Invoke-WebRequest is a single multi-line string. Get-Content on the other hand returns multiple single-line strings.
You can use the -split operator to split on newlines:
$respcont -split '\r?\n' |Select -Skip 4 |Select -SkipLast 9
I have a big text file which gives me solar irradiance according to latitude and longitude with a 22 year monthly average.
These data are regional averages; not point data.
Created: March 12, 2008
Lat Lon Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Ann
-90 -180 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -179 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -178 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -177 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -176 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -175 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -174 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -173 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -172 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -171 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -170 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -169 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -168 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -167 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -166 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -165 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -164 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -163 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -162 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
-90 -161 9.63 5.28 0.75 0.00 0.00 0.00 0.00 0.00 0.10 3.24 8.28 10.97 3.19
Now, I want to find monthly average for lat=-90 & long=-166. How can I call them into my workspace variable?
Also, while working in matlab, will it be better to call this whole text file when we run the code or should we copy paste the whole text file in the code to make calculations faster and space efficient.
Thank you for your help.
I'm personally a fan of the table data type. I would do something like this:
t = readtable('punit.txt','HeaderLines',2,'Delimiter',' '); % read into table
index = t.Lat == -90 & t.Lon==-166; % create a binary indicator as to whether
% each row matches the criteria
my_data = t{index, 3:14}; % extract the data into a matlab array
mean_my_data = mean(my_data, 2); % calculate mean (2 makes it along columns)
You probably already know this, but I would put this code in a file like my_script.m and then call the script from the matlab workspace with my_script.
Matthew's answer is perfectly acceptable. In fact, it's the approach I'd side with. However, if you don't have access to the table interface as it was introduced in R2013b, dlmread may be more suitable for use. Simply skip three lines and use space as the delimiter to read in that matrix into MATLAB.
Once you read in this matrix, search for all rows where the first column has -90 and the second column has -166, index into your matrix and find the mean over each column. Assuming your text file is called data.txt:
data = dlmread('data.txt', ' ', 3, 0);
ind = data(:,1) == -90 & data(:,2) == -166;
extract = data(ind,3:end);
mean_data = mean(extract, 1);
The first line of code reads in the text file as a numerical matrix and skips the first three lines. Spaces are used as the delimiter. Next, we find a Boolean vector which finds all rows where the first column is -90 and simultaneously the second column being -166. Once we find these rows, we subset into the data and extract only the third column and onwards as we don't want to include the latitude and longitude as part of the calculations.
Once we extract this data, we find the averages of each month individually using mean and to find the column-wise averages, use the second parameter with the value of 1, meaning that the averages over the first dimension or the rows is what is sought.
Try Matlab Import Data button Go to Home tab-> in the Variable section-> select Import Data.
Select your text file and get whichever row or column you want to import.
Alternatively, right click name of the file in Current Folder browser and select Import Data. --> The Import Tool opens.
it is possible to create variables also in your Matlab workspace.
It works better than copy pasting manually and less time consuming.
I have a set of data and want to plot them. However I don't know how to plot them nicely. I tried to use bar plot in Matlab and the resulted plot is not readable.
I thought to ask if there is a setting or even a new style to plot my results in a better way.
There are 15 bars for each element of x axis [1:19].
Here you can see the required data:
DAT=...
[2.476 4.142 0.000 4.302 4.302 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
6.680 8.703 2.611 6.680 6.680 3.261 0.000 3.799 6.680 0.000 0.000 0.000 0.000 0.000 0.000
7.672 6.498 7.809 7.809 7.809 6.615 5.062 7.809 7.809 3.916 5.895 7.809 2.780 5.195 2.385
27.126 17.441 11.386 0.000 0.000 17.435 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.085 0.156 0.284 0.284 0.284 0.000 0.284 0.284 0.284 0.226 0.284 0.284 0.284 0.284 0.284
10.688 12.159 10.688 10.688 10.688 10.688 10.073 5.633 10.688 0.000 0.000 6.681 0.000 0.000 0.000
11.002 11.020 11.002 11.002 11.002 11.002 11.002 9.456 11.002 5.459 2.434 3.585 3.527 2.160 0.117
2.111 2.111 2.111 2.111 2.111 2.111 2.111 0.000 0.000 2.111 2.111 0.000 0.000 0.581 0.000
9.085 9.906 9.085 1.256 9.085 9.085 9.085 7.299 0.000 9.085 0.000 0.000 0.000 0.000 0.000
3.661 3.661 3.661 3.661 3.661 3.661 3.661 0.000 0.000 1.206 0.000 0.000 0.000 0.000 0.000
3.307 3.703 3.307 2.968 3.307 3.307 3.307 0.000 0.000 3.307 0.000 0.000 0.000 0.000 0.000
4.136 4.123 4.123 4.123 4.123 4.123 4.123 4.123 0.000 4.123 4.123 0.000 3.350 0.000 0.000
2.993 3.000 2.993 2.993 2.993 2.993 0.000 1.134 0.000 2.993 0.000 0.000 1.938 0.000 0.000
1.857 1.864 1.857 1.857 1.857 1.857 1.857 1.857 0.000 1.857 1.857 0.016 1.857 0.704 0.000
3.754 3.754 3.754 3.754 3.754 3.754 3.754 0.000 0.000 3.754 3.754 0.000 0.000 0.000 0.000
2.752 2.760 2.752 2.752 2.752 2.752 2.752 2.752 0.000 2.752 2.752 2.752 2.752 2.752 0.000
3.788 5.611 3.788 3.788 3.788 3.788 3.788 3.369 0.000 3.788 3.788 0.000 3.788 0.000 0.000
0.132 0.123 0.123 0.123 0.132 0.123 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
15.465 14.081 12.468 4.808 1.787 12.858 11.067 3.644 9.317 11.846 10.631 4.233 8.394 5.094 4.225];
bar(DAT)
Try out bar3(DAT)
Output graph:
I have some text files in a folder named ff as follows. I need to delete the lines in these files based on another file aa.txt.
32bm.txt:
249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9
250 254 A K B Z 254 0E 77 -48,-2.5 -48,-0.3 4,-0.2 4,-0.3 -0.720 360.0 360.0 -93.4 135.2 38.1 11.1 8.1
252 !* 0 0 0 0, 0.0 0, 0.0 0, 0.0 0, 0.0 0.000 360.0 360.0 360.0 360.0 0.0 0.0 0.0
253 143 B R 0 0 96 0, 0.0 -2,-3.7 0, 0.0 2,-0.2 0.000 360.0 360.0 360.0 110.4 38.4 10.4 3.0
254 144 B Q B -Z 250 0E 62 -4,-0.3 -4,-0.2 -3,-0.1 2,-0.1 -0.347 360.0-157.5 -58.1 119.5 39.4 13.6 4.8
255 145 B T - 0 0 22 -6,-1.4 2,-0.3 -2,-0.2 -7,-0.2 -0.396 7.8-127.4 -91.5 173.9 36.3 15.7 5.4
2fok.txt:
1 361 X G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 X A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 X R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0
1 361 B G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 B A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 B R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0`enter code here`
aa.txt:
32bm B 143 145
2fok X 361 363
2moj B 361 367
-
-
-
For example, in the 32bm.txt, I need only the lines having B (column3) and the numbers from 143 to 145 (column2).
Desired output:
32bm.txt
253 143 B R 0 0 96 0, 0.0 -2,-3.7 0, 0.0 2,-0.2 0.000 360.0 360.0 360.0 110.4 38.4 10.4 3.0
254 144 B Q B -Z 250 0E 62 -4,-0.3 -4,-0.2 -3,-0.1 2,-0.1 -0.347 360.0-157.5 -58.1 119.5 39.4 13.6 4.8
255 145 B T - 0 0 22 -6,-1.4 2,-0.3 -2,-0.2 -7,-0.2 -0.396 7.8-127.4 -91.5 173.9 36.3 15.7 5.4
2fok.txt
1 361 X G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 X A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 X R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0
With awk you do something like this:
#!/usr/bin/awk -f
NR == FNR { # If we are in the first file
low[$1,$2]=$3 # store the low value in a map
hi[$1,$2]=$4 # store the high value in another map
next # skip the remaining commands
}
# We are not in the first file
($2 >= low[FILENAME,$3]) && ($2 <= hi[FILENAME,$3])
# The FILENAME variable holds the name of the current file
# If the number we read is within the range, do the
# default action (which is to print the current line
put the script in a file named script.awk and run like this:
$ ./script.awk aa.txt 32bm 2fok
253 143 B R 0 0 96 0, 0.0 -2,-3.7 0, 0.0 2,-0.2 0.000 360.0 360.0 360.0 110.4 38.4 10.4 3.0
254 144 B Q B -Z 250 0E 62 -4,-0.3 -4,-0.2 -3,-0.1 2,-0.1 -0.347 360.0-157.5 -58.1 119.5 39.4 13.6 4.8
255 145 B T - 0 0 22 -6,-1.4 2,-0.3 -2,-0.2 -7,-0.2 -0.396 7.8-127.4 -91.5 173.9 36.3 15.7 5.4
1 361 X G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 X A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 X R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0
Or if you prefer a one liner:
awk 'NR==FNR{low[$1,$2]=$3;hi[$1,$2]=$4;next}$2>=low[FILENAME,$3]&&$2<=hi[FILENAME,$3]' aa.txt 32bm 2fok
I want to delete the repeat data in the flowing. Then ascending order according to the first column. Could you show the detail code to solve this problem? thank you very much.
15.0 0.8 1.6 -0.0 -0.3
16.0 2.4 -0.2 0.1 -0.1
17.0 2.6 -0.6 0.2 0.2
18.0 4.6 1.0 0.3 0.1
19.0 2.3 1.4 0.9 0.2
20.0 2.4 0.9 0.5 0.4
6.0 5.8 2.5 -1.8 -1.9
7.0 4.1 4.1 -0.8 1.6
8.0 2.8 2.3 2.2 -0.5
9.0 -1.5 -1.9 1.1 0.9
10.0 0.9 0.2 0.0 0.1
9.0 -1.5 -1.9 1.1 0.9
10.0 0.9 0.2 0.0 0.1
11.0 2.3 -3.6 0.7 -0.6
12.0 -1.2 -0.4 -0.2 -0.1
13.0 -4.4 0.3 -0.3 -0.2
14.0 -0.9 0.9 -0.4 -0.4
15.0 0.8 1.6 -0.0 -0.3
From the documentation of unique, we find that the unique(B, 'rows') command will
output unique rows only
sort the output
So:
B = [...
your data here
];
C = unique(B, 'rows');
will solve both your problems: the default for sort is to sort down the first column.