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

Home » Public Forums » archive » Re: Reading and saving a file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Reading and saving a file [message #74611] Thu, 27 January 2011 07:28 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paolo writes:

> Basically you want to use openw to get a file unit:
>
> openw, Unit, 'data.dat', /GET_LUN
>
> then printf to write the contents
>
> mydata=[1,2,3]
>
> printf,unit,mydata
>
> close,unit

Well, use FREE_LUN, instead of CLOSE. CLOSE won't
free the logical unit number to be used over again
when it is obtained this way. FREE_LUN will both
close the file *and* free the logical unit number.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Reading and saving a file [message #74612 is a reply to message #74611] Thu, 27 January 2011 07:25 Go to previous messageGo to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Jan 27, 7:32 am, Giovanna <giovanna01.san...@gmail.com> wrote:
> On 26 jan, 18:42, Paolo <pgri...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On Jan 26, 1:19 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>> On 26 jan, 13:37, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>>>> > On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> > > So, i'm reading a file, i need to extract data and save into another
>>>> > > file, but is coming with strange characters.
>>>> > > In what format I save so they do not come up with these strange
>>>> > > characters and that JAVA can also read??
>
>>>> > Where do you see the problem? In IDL, from what was read? In the file
>>>> > written by IDL? Which characters are creating the problem?
>
>>>> > Generally speaking, any text files made in IDL should be easy to read
>>>> > in Java, since IDL only natively does ASCII strings, and Java natively
>>>> > uses Unicode.
>
>>>> I'm reading this file for example:http://pastebin.com/ctHZC8wvand
>>>> when i save characters appear. See:http://pastebin.com/HsQse0uy
>
>>>> My code:http://pastebin.com/eiAVywr1
>
>>>> Thanks
>
>>> Hi all,
>
>>> I'm reading a file, i need to extract data and save into another
>>> file, but is coming with strange characters.
>>> I'm reading this file for example:http://pastebin.com/ZLgMjrH3and
>>> when i save characters appear. See:http://pastebin.com/NbwKhqAw
>
>>> My code:http://pastebin.com/kShggiSa
>
>>> I need to save in a format that is then recognized by JAVA.
>
>>> Understood?
>
>> The solution is not to use the "save" function.
>> Use "printf" to write the contents to the new
>> file.
>
>> Ciao,
>> Paolo
>
> How do i use the printF? So: printF, file, 'teste1.dat'
>
> ??

Basically you want to use openw to get a file unit:

openw, Unit, 'data.dat', /GET_LUN

then printf to write the contents

mydata=[1,2,3]

printf,unit,mydata

close,unit


Ciao,
Paolo
Re: Reading and saving a file [message #74615 is a reply to message #74612] Thu, 27 January 2011 04:32 Go to previous messageGo to next message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 26 jan, 18:42, Paolo <pgri...@gmail.com> wrote:
> On Jan 26, 1:19 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>
>
>
>
>> On 26 jan, 13:37, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>> On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>>>> On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> > So, i'm reading a file, i need to extract data and save into another
>>>> > file, but is coming with strange characters.
>>>> > In what format I save so they do not come up with these strange
>>>> > characters and that JAVA can also read??
>
>>>> Where do you see the problem? In IDL, from what was read? In the file
>>>> written by IDL? Which characters are creating the problem?
>
>>>> Generally speaking, any text files made in IDL should be easy to read
>>>> in Java, since IDL only natively does ASCII strings, and Java natively
>>>> uses Unicode.
>
>>> I'm reading this file for example:http://pastebin.com/ctHZC8wvand
>>> when i save characters appear. See:http://pastebin.com/HsQse0uy
>
>>> My code:http://pastebin.com/eiAVywr1
>
>>> Thanks
>
>> Hi all,
>
>> I'm reading a file, i need to extract data and save into another
>> file, but is coming with strange characters.
>> I'm reading this file for example:http://pastebin.com/ZLgMjrH3and
>> when i save characters appear. See:http://pastebin.com/NbwKhqAw
>
>> My code:http://pastebin.com/kShggiSa
>
>> I need to save in a format that is then recognized by JAVA.
>
>> Understood?
>
> The solution is not to use the "save" function.
> Use "printf" to write the contents to the new
> file.
>
> Ciao,
> Paolo

How do i use the printF? So: printF, file, 'teste1.dat'

??
Re: Reading and saving a file [message #74626 is a reply to message #74615] Wed, 26 January 2011 12:42 Go to previous messageGo to next message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Jan 26, 1:19 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
> On 26 jan, 13:37, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>>> On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> So, i'm reading a file, i need to extract data and save into another
>>>> file, but is coming with strange characters.
>>>> In what format I save so they do not come up with these strange
>>>> characters and that JAVA can also read??
>
>>> Where do you see the problem? In IDL, from what was read? In the file
>>> written by IDL? Which characters are creating the problem?
>
>>> Generally speaking, any text files made in IDL should be easy to read
>>> in Java, since IDL only natively does ASCII strings, and Java natively
>>> uses Unicode.
>
>> I'm reading this file for example:http://pastebin.com/ctHZC8wvand
>> when i save characters appear. See:http://pastebin.com/HsQse0uy
>
>> My code:http://pastebin.com/eiAVywr1
>
>> Thanks
>
> Hi all,
>
> I'm reading a file, i need to extract data and save into another
> file, but is coming with strange characters.
> I'm reading this file for example:http://pastebin.com/ZLgMjrH3and
> when i save characters appear. See:http://pastebin.com/NbwKhqAw
>
> My code:http://pastebin.com/kShggiSa
>
> I need to save in a format that is then recognized by JAVA.
>
> Understood?

The solution is not to use the "save" function.
Use "printf" to write the contents to the new
file.


Ciao,
Paolo
Re: Reading and saving a file [message #74629 is a reply to message #74626] Wed, 26 January 2011 10:44 Go to previous messageGo to next message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jan 26, 1:19 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
> On 26 jan, 13:37, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>>> On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> So, i'm reading a file, i need to extract data and save into another
>>>> file, but is coming with strange characters.
>>>> In what format I save so they do not come up with these strange
>>>> characters and that JAVA can also read??
>
>>> Where do you see the problem? In IDL, from what was read? In the file
>>> written by IDL? Which characters are creating the problem?
>
>>> Generally speaking, any text files made in IDL should be easy to read
>>> in Java, since IDL only natively does ASCII strings, and Java natively
>>> uses Unicode.
>
>> I'm reading this file for example:http://pastebin.com/ctHZC8wvand
>> when i save characters appear. See:http://pastebin.com/HsQse0uy
>
>> My code:http://pastebin.com/eiAVywr1
>
>> Thanks
>
> Hi all,
>
> I'm reading a file, i need to extract data and save into another
> file, but is coming with strange characters.
> I'm reading this file for example:http://pastebin.com/ZLgMjrH3and
> when i save characters appear. See:http://pastebin.com/NbwKhqAw
>
> My code:http://pastebin.com/kShggiSa
>
> I need to save in a format that is then recognized by JAVA.
>
> Understood?

So, you're saying that when you restore your saved 'teste1.dat', and
type print, file you get those characters? Could it be possible that
your original file has control characters hidden? Try opening it with
a plain old text editor to see if there are hidden characters.
Re: Reading and saving a file [message #74630 is a reply to message #74629] Wed, 26 January 2011 10:19 Go to previous messageGo to next message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 26 jan, 13:37, Giovanna <giovanna01.san...@gmail.com> wrote:
> On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>> On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>> So, i'm reading a file, i need to extract data and save into another
>>> file, but is coming with strange characters.
>>> In what format I save so they do not come up with these strange
>>> characters and that JAVA can also read??
>
>> Where do you see the problem? In IDL, from what was read? In the file
>> written by IDL? Which characters are creating the problem?
>
>> Generally speaking, any text files made in IDL should be easy to read
>> in Java, since IDL only natively does ASCII strings, and Java natively
>> uses Unicode.
>
> I'm reading this file for example:http://pastebin.com/ctHZC8wvand
> when i save characters appear. See:http://pastebin.com/HsQse0uy
>
> My code:http://pastebin.com/eiAVywr1
>
> Thanks


Hi all,

I'm reading a file, i need to extract data and save into another
file, but is coming with strange characters.
I'm reading this file for example: http://pastebin.com/ZLgMjrH3 and
when i save characters appear. See: http://pastebin.com/NbwKhqAw

My code: http://pastebin.com/kShggiSa

I need to save in a format that is then recognized by JAVA.

Understood?
Re: Reading and saving a file [message #74637 is a reply to message #74630] Wed, 26 January 2011 07:37 Go to previous messageGo to next message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>> So, i'm reading a file, i need to extract data and save into another
>> file, but is coming with strange characters.
>> In what format I save so they do not come up with these strange
>> characters and that JAVA can also read??
>
> Where do you see the problem? In IDL, from what was read? In the file
> written by IDL? Which characters are creating the problem?
>
> Generally speaking, any text files made in IDL should be easy to read
> in Java, since IDL only natively does ASCII strings, and Java natively
> uses Unicode.

I'm reading this file for example: http://pastebin.com/ctHZC8wv and
when i save characters appear. See: http://pastebin.com/HsQse0uy

My code: http://pastebin.com/eiAVywr1

Thanks
Re: Reading and saving a file [message #74638 is a reply to message #74637] Wed, 26 January 2011 07:31 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paulo Penteado writes:

> Where do you see the problem? In IDL, from what was read? In the file
> written by IDL? Which characters are creating the problem?
>
> Generally speaking, any text files made in IDL should be easy to read
> in Java, since IDL only natively does ASCII strings, and Java natively
> uses Unicode.

Well, she "saved" the file in an IDL save file. That
will probably create some problems for JAVA. :-)

I think the real problem is that the user is
confusing the notion of "file" with "variables
in the file". You don't have to "save" this file.
It's already saved. You're reading it!!

If it is variables you want to save, you are going
to have to do something else completely. Maybe just
read a book on general programming principles.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Reading and saving a file [message #74640 is a reply to message #74638] Wed, 26 January 2011 07:22 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
> So, i'm reading a file, i need to extract data and save into another
> file, but is coming with strange characters.
> In what format I save so they do not come up with these strange
> characters and that JAVA can also read??

Where do you see the problem? In IDL, from what was read? In the file
written by IDL? Which characters are creating the problem?

Generally speaking, any text files made in IDL should be easy to read
in Java, since IDL only natively does ASCII strings, and Java natively
uses Unicode.
Re: Reading and saving a file [message #74643 is a reply to message #74640] Wed, 26 January 2011 06:48 Go to previous messageGo to next message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 26 jan, 11:52, Gray <grayliketheco...@gmail.com> wrote:
> On Jan 26, 8:25 am, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>> Hi all,
>
>> I need to read and save a file using IDL, but my code is reading and
>> saving only the first line. Please, see my code:
>
>> PRO READ_FILE
>> OpenR, lun, 'C:\Documents and Settings\Web\IDLWorkspace\Projeto_Estudo
>> \dados.dat', /Get_lun
>> file = ''
>> ReadF, lun, file
>> SAVE, FILENAME=('C:\Documents and Settings\Web\IDLWorkspace
>> \Projeto_Estudo\teste1.dat')
>
>> ;print,file
>> END
>
> It reads in the first line because "file" is a string, and not a
> string array.  If you want the whole thing you need:
>
> file = strarr(file_lines(...))
> readf, lun, file


So, i'm reading a file, i need to extract data and save into another
file, but is coming with strange characters.
In what format I save so they do not come up with these strange
characters and that JAVA can also read??

Thanks
Re: Reading and saving a file [message #74645 is a reply to message #74643] Wed, 26 January 2011 05:52 Go to previous messageGo to next message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jan 26, 8:25 am, Giovanna <giovanna01.san...@gmail.com> wrote:
> Hi all,
>
> I need to read and save a file using IDL, but my code is reading and
> saving only the first line. Please, see my code:
>
> PRO READ_FILE
> OpenR, lun, 'C:\Documents and Settings\Web\IDLWorkspace\Projeto_Estudo
> \dados.dat', /Get_lun
> file = ''
> ReadF, lun, file
> SAVE, FILENAME=('C:\Documents and Settings\Web\IDLWorkspace
> \Projeto_Estudo\teste1.dat')
>
> ;print,file
> END

It reads in the first line because "file" is a string, and not a
string array. If you want the whole thing you need:

file = strarr(file_lines(...))
readf, lun, file
Re: Reading and saving a file [message #74707 is a reply to message #74612] Thu, 27 January 2011 08:24 Go to previous message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 27 jan, 13:25, Paolo <pgri...@gmail.com> wrote:
> On Jan 27, 7:32 am, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>
>
>
>
>> On 26 jan, 18:42, Paolo <pgri...@gmail.com> wrote:
>
>>> On Jan 26, 1:19 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> On 26 jan, 13:37, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> > On 26 jan, 13:22, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>>>> > > On Jan 26, 12:48 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>>>> > > > So, i'm reading a file, i need to extract data and save into another
>>>> > > > file, but is coming with strange characters.
>>>> > > > In what format I save so they do not come up with these strange
>>>> > > > characters and that JAVA can also read??
>
>>>> > > Where do you see the problem? In IDL, from what was read? In the file
>>>> > > written by IDL? Which characters are creating the problem?
>
>>>> > > Generally speaking, any text files made in IDL should be easy to read
>>>> > > in Java, since IDL only natively does ASCII strings, and Java natively
>>>> > > uses Unicode.
>
>>>> > I'm reading this file for example:http://pastebin.com/ctHZC8wvand
>>>> > when i save characters appear. See:http://pastebin.com/HsQse0uy
>
>>>> > My code:http://pastebin.com/eiAVywr1
>
>>>> > Thanks
>
>>>> Hi all,
>
>>>> I'm reading a file, i need to extract data and save into another
>>>> file, but is coming with strange characters.
>>>> I'm reading this file for example:http://pastebin.com/ZLgMjrH3and
>>>> when i save characters appear. See:http://pastebin.com/NbwKhqAw
>
>>>> My code:http://pastebin.com/kShggiSa
>
>>>> I need to save in a format that is then recognized by JAVA.
>
>>>> Understood?
>
>>> The solution is not to use the "save" function.
>>> Use "printf" to write the contents to the new
>>> file.
>
>>> Ciao,
>>> Paolo
>
>> How do i use the printF? So: printF, file, 'teste1.dat'
>
>> ??
>
> Basically you want to use openw to get a file unit:
>
> openw, Unit, 'data.dat', /GET_LUN
>
> then printf to write the contents
>
> mydata=[1,2,3]
>
> printf,unit,mydata
>
> close,unit
>
> Ciao,
> Paolo


Hi,

This error is occurring when running:

Error -
OPENR: All available logical units are currently in use.
% Execution halted at: READ_FILE 3 read_file.pro
% $MAIN$

This error is occurring this line: OpenR, lun, 'dados.dat', /Get_lun

What could be??

Thanks
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: configuration file to go along with a virtual machine program
Next Topic: MATRIX LOGARITHM (and EXPONENTIAL)

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

Current Time: Wed Oct 08 13:36:27 PDT 2025

Total time taken to generate the page: 0.00646 seconds