comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: formatting array output?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: formatting array output? [message #33848 is a reply to message #33844] Fri, 31 January 2003 08:12 Go to previous messageGo to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Murat Maga <maga@mail.utexas.edu> writes:



> Kenneth Bowman wrote:
>>
>> In article <3E394CDD.8F9B0C65@mail.utexas.edu>,
>> Murat Maga <maga@mail.utexas.edu> wrote:
>>
>>> Hi All,
>>> I have an integer array (2000x1000) which I would like to write in file
>>> in the typical matrix convention. I think IDL breaks the line at 80th
>>> column and everything starts to look quite messy.
>>> To format an array output, do I use the print/printf, or are there any
>>> other tricks good to know?
>>> Best,
>>> Murat
>>
>> Use a portable binary format like netcdf or hdf. You aren't really
>> planning to read the file, are you?
>>
>> id = NCDF_OPEN('newfile')
>> d1 = NCDF_DIMDEF(id, 'dim1', 2000)
>> d2 = NCDF_DIMDEF(id, 'dim2', 1000)
>> vid = NCDF_VARDEF(id, 'matrix', [d1, d2], /LONG)
>> NCDF_CONTROL, id, /ENDEF
>> NCDF_VARPUT, id, 'matrix', matrix
>> NCDF_CLOSE, id
>>
>> Ken Bowman

> Thanks for the answers everybody. Yes I do need to use an ASCII format,
> HDF is not an option for me. I also need to parse the file manually -at
> least partially-, that is the other reason.

> printf, 2, '$(2000F)'
> command is actually all i need. But I have one other silly question,
> what if the size of the array is parametric? I tried to put the variable
> name but that didnt work. Just for the record, I come from neither C nor
> fortran school. No programming skills, unfortunately. I measure bones
> :-)
> Best,
> Murat

The simplest way to do that in IDL is to create the format string on the fly,
e.g.

format = '$(' + strtrim(n,2) + 'F)'
printf, 2, format=format, ...

You can use the SIZE function to determine what N should be, e.g.

sz = size(array)
format = '$(' + strtrim(sz[1],2) + 'F)'
printf, 2, format=format, array

William Thompson
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: last array index subscript
Next Topic: Re: Alpha Blending inside of Widgets / Graphic Objects in Widgets

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 17:08:41 PDT 2025

Total time taken to generate the page: 1.27875 seconds