[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: matching fields in ascii or text files.




patrick@es.ucsc.edu (Patrick McEnaney) writes:

> Folks, suggestions needed for going about the following problem:
> 
> I have columnar oceanographic data in two different data files. One is
> a txt file, the other ascii. I want to compare depth values in a
> column from one file to depth values in a column from a second file,
> then write all values associated with a specific depth in other
> columns such as temperature, conductivity, nutrients, etc, to another
> file. Should I attempt some sort of boolean expression to search
> through the two files to match values or is there a more efficient
> method that someone can suggest?

Hi Patrick--

I think what you are trying to do is match up the rows of two files
based on a shared column.  If you really need to match them exactly,
then perhaps the best route is to SORT both arrays by depth, and then
step through the lists in tandem.

  depth1 = ...
  depth2 = ...
  ds1 = sort(depth1)  &  ds2 = sort(depth2)
  j = 0L
  for i = 0, n_elements(ds1)-1 do begin  ;; Step through list 1
    while depth2(ds2(j)) LT depth1(ds1(i)) do j = j + 1  ;; Find in list 2
    ;  ... process
  endfor

You don't say whether you want to match them exactly however.  Another
really good solution is often spline interpolation.  The is especially
useful when you have two files sampled on two different time grids (or
depth grids in your case).  Then you would do,

 y2 = spl_interp(depth1, y1, spl_init(depth1, y1), depth2)

which interpolates the values of Y1, measured on the DEPTH1 grid, onto
the DEPTH2 grid.  Whew!

Craig


-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------