0

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?

deedsy
  • 57
  • 2
  • 11

2 Answers2

2

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
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • thanks - this method worked great. Another option I found is to download the 'niceprint.pro' and 'niceprintf.pro' procedures (free). Then once you have your arrays, simply open a text file for writing `openw,1,'arrays.txt'` and then `niceprintf,1,x,y` will print the x and y arrays side by side in arrays.txt. Then close the text file `close,1` - without the close command, things sometimes get messed up I've found – deedsy Aug 08 '14 at 21:29
0

You can also use the writecol procedure for this: http://www.staff.science.uu.nl/~rutte101/rridl/misclib/writecol.pro

One more suggestion is to use the get_lun keyword with all open calls: it is better to let IDL manage the logical unit numbers, than having to do it yourself. (http://www.exelisvis.com/docs/OPEN.html#O_828691053_889739)

VBB
  • 1,305
  • 7
  • 17