Search code examples
arraysoutputidl

Output 2 array values to a text file using IDL


I'm using IDL 8.3. I have two arrays called X and Y. They each contain 1001 values. I want to output their values to a text file in this format:

x1 y1
x2 y2
x3 y3
.....
x1001 y1001

I was able to print the all of the X values to a text file doing this:

openw, 1, 'outFile.txt'
printf, 1, X

And then I could print all the Y values after them (but this is not the format I want) - the text file just looked like this:

x1 x2 x3 x4
x5 x6 .. x1001
y1 y2 y3 y4
y5 y6 .. y1001

But, for some reason, I can't get printf to format the way I want it to (it doesn't let me just say printf, 1, x, y). Is there a way to do what I want with printf (http://www.exelisvis.com/docs/PRINT.html) or is there another command that would be more useful for me to look into?


Solution

  • You could do something like:

    IDL> x = findgen(10)
    IDL> y = findgen(10) * 2
    IDL> print, transpose([[x], [y]]), format='(2F)'
          0.0000000      0.0000000
          1.0000000      2.0000000
          2.0000000      4.0000000
          3.0000000      6.0000000
          4.0000000      8.0000000
          5.0000000     10.0000000
          6.0000000     12.0000000
          7.0000000     14.0000000
          8.0000000     16.0000000
          9.0000000     18.0000000