computation using ascii data

Stegert stegert at IFM.UNI-HAMBURG.DE
Mon Jul 3 06:35:11 EDT 2006


Dear Suha Alsam,
1. Some notes on variables and "read" and 2. a solution to your problem
so the answer will be a bit longer - but hopefully informative:
1.
It took me some time so recognize that there are 2 kinds of variables
(I think this is not yet clearly stated in the Documentation, I think):
- "defined variables" which can be created by the "define" command.
  these can be handeled as your vars from the Grads binary (as matrix).
  (see "GADOC - Variables")
- "Script variables" which can not be used at comand line but in Scripts
only.
  these are only 'scalars' - they can not be defined and used in matrices
  (you can create arrays - further see: "GADOC - scripting lang. ->
Variables")
These two are absolutely different in handling.
GADOC address: http://grads.iges.org/grads/gadoc/gadocindex.html

The "read"-command:
reads the total line (one line at time) of your ascii file as string but
contains 2 lines
1st line: Return code (see answer by Charles Seman Jun 28)
2nd line: Your ascii string
To get it you use (in the script):
fin = read('infile.txt'); lin = sublin(fin,2)  (to get the 2nd line)
You can then get single values by subwrd(lin,n) with "n" being the n-th
value.

2. If I understand it right, you have a GrADS file with your first variable
(say "var1") with x,y,z fixed and t variable (i.e. time series) and
a second data set in an ascii file to be read in both with the same time
interval.
You can read data as described above and translate them to a defined
variable:
First, create variable:
fix x,y, and z and let t be variable ('set t 1 'tmax - with tmax number
of time steps)
'define var2 = var1 - var1'
this gives you a "var2" with the same dimensions as var1 and all values
are "0"
Then do a loop:
i = 1
while (i <= tmax)
  'set t 'i
  lin = read('asciifile.txt')
  val = sublin(lin,2)   (expecting you have only one column you can
directly use it otherwise:)
  val = subwrd(val,3)  (expecting your time series value is in the 3rd
column - else correct it)
  'set defval var2 ' val
endwhile
Now, you have the second time series on var2 and can work with that, e.g.:
'd var1 / var2' to get the relation of var1 to var2 or
'd (var1 + var2) / var1' to get the percentage change of var2 to var1 or
what you like.
(Remember first to 'set t 1 'tmax).
Is this what you want to get?
I hope this helps,
regards, Christoph

suha aslam schrieb:

>Hello grads users,
>I want to compute correlation between two parameters.
>Of which one parameter has to be calculated from a
>binary file and the second is a time series (column
>matrix) directly given as an ascii file. What is the
>method to read the ascii file and asign the
>consecutive lines (each values) as x1, x2, x3,
>.....xn. When i used the command read(file) and
>written it out (in a loop) to check whether it was
>read correctly, the output file shows 0 and the first
>value only. What could be wrong? Any idea?
>A help would be appreciated.
>Thanks,
>Suha
>
--
Christoph Stegert
Intitute  for Oceanography - (ZMK/ZMAW alliance member)
University of Hamburg, GER - Ecological Modelling Group
Bundesstr.53 20146 Hamburg - +49-40-42838-7486 - Rm 348



More information about the gradsusr mailing list