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

Home » Public Forums » archive » read a file written in fortran
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
read a file written in fortran [message #71186] Mon, 07 June 2010 12:27 Go to next message
Thibault Garel is currently offline  Thibault Garel
Messages: 55
Registered: October 2009
Member
Hi,
I want to read with IDL an ascii file written in Fortran 90.

The file contains two types of data: double floats and "logical". For
the floats no problem but for the logical (which writes either T or F
(for true or false) in the ascii file) i get " READF: End of file
encountered" while doing:

my_float = 0.0d0
my_logical='a'

readf,11,format='(1e14.6,A1)', my_float,my_logical

Is there anything wrong in the format or in the initialization?

Thanks in advance!
Re: read a file written in fortran [message #71289 is a reply to message #71186] Wed, 09 June 2010 05:17 Go to previous messageGo to next message
Thibault Garel is currently offline  Thibault Garel
Messages: 55
Registered: October 2009
Member
OK, thanks


> bing999 wrote:
>> For information, here is how i wrote the file in fortran:
>
>> write(my_unit,'(9e14.6,L1)') a,b,c,d,e,f,g,h,i,my_logical
>
>> Then, how to read a L1 format in IDL?
>
> ; Define true/false explicitly
> FALSE = 0
> TRUE  = 1
>
> ; Read the file
> tmp = ""
> readf, your_unit, format='(9e14.6,a1)', a,b,c,d,e,f,g,h,i,tmp
>
> ; Process the logical
> case strupcase(tmp) of
>   'T': my_logical=TRUE
>   'F': my_logical=FALSE
>   ELSE: message,'invalid logical!'
> endcase
>
> ??
Re: read a file written in fortran [message #71303 is a reply to message #71186] Tue, 08 June 2010 16:33 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
bing999 wrote:
> For information, here is how i wrote the file in fortran:
>
> write(my_unit,'(9e14.6,L1)') a,b,c,d,e,f,g,h,i,my_logical
>
> Then, how to read a L1 format in IDL?

; Define true/false explicitly
FALSE = 0
TRUE = 1

; Read the file
tmp = ""
readf, your_unit, format='(9e14.6,a1)', a,b,c,d,e,f,g,h,i,tmp

; Process the logical
case strupcase(tmp) of
'T': my_logical=TRUE
'F': my_logical=FALSE
ELSE: message,'invalid logical!'
endcase


??
Re: Read a file [message #74670 is a reply to message #71186] Fri, 28 January 2011 13:14 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jan 28, 2:17 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
> Well...
>
> I need to read a file file.sav and file1.cnj, then i need restore and
> to get the structures modelo.imag, conjugado.imag. And to save in the
> new file - data.dat(line 16).
>
> I don't know how to take these structures(modelo.imag, conjugado.imag)
> and save in this file data.dat
>
> CAn you help me.??
>
> My code:http://pastebin.com/GRmNtags

Again, are file.sav and file1.cnj savefiles or text files? If they are
savefiles, they can be read with restore. If they are text files,
readf is one of the ways to read them. It does not make a lot of sense
to try to read them both as if they were savefiles and text files.
Also, it does not make much sense to open file2.cnj and never do
anything with it.

And, as mentioned before, the files should be closed, and the unit
numbers released back into the pool (both can be done with free_lun).

To tell how to make the file you want, we would have to know what kind
of variables those fields are (modelo.imag, conjugado.imag), and what
kind of output you want to make of them.

The first question could be well answered by the output of

help,modelo.imag,conjugado.imag
Re: Read a file [message #74686 is a reply to message #71186] Fri, 28 January 2011 08:17 Go to previous messageGo to next message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 28 jan, 13:26, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Jan 28, 12:50 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>> Hello,
>
>> Me again....
>
>> I'm trying read two files and to save in other file. See my code:http://pastebin.com/GRmNtags
>
>> I run a command restore, to restore the file .sav and .cnj.... and
>> then saved in 'data.dat' using 'printF'
>
>> Is this correct what I did in rows 16 to 23??
>
> Semantically, the code is correct, assuming that you have a structure
> named modelo with a field name imag, and a structure named conjugado
> with a field name imag. It is up to you to say if that is correct in
> the sense of producing the file you wanted.
>
> Though I do not see why do
>
> modelo.imag=[MODELO.imag]
> conjugado.imag=[CONJUGADO.imag]
>
> Which does not change these variables.
>
> However, there is an oddity coming before those lines: You first read
> file.sav as a text file, into a string array. Then you restore it
> (that is, read it as an IDL savefile). If it is a text file, the
> restore will fail. And if it is a savefile, the read into a string
> array, done that way, will probably read some (maybe all) of the file,
> but the contents of the string array will be the bytes of the (binary)
> savefile, interpreted as characters, which is going to be hard to make
> sense of.
>
> Also, you open file2.cnj, and never close it (never even use it). And,
> as mentioned before, closing the unit opened with /get_lun to openw
> does not release the unit number back into the pool (which a free_lun
> would do).
>
> The main question to me is: what do you want to be in the file you are
> creating? To say it another way: what should the file look like?

Well...

I need to read a file file.sav and file1.cnj, then i need restore and
to get the structures modelo.imag, conjugado.imag. And to save in the
new file - data.dat(line 16).

I don't know how to take these structures(modelo.imag, conjugado.imag)
and save in this file data.dat

CAn you help me.??

My code: http://pastebin.com/GRmNtags
Re: Read a file [message #74687 is a reply to message #71186] Fri, 28 January 2011 07:26 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jan 28, 12:50 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
> Hello,
>
> Me again....
>
> I'm trying read two files and to save in other file. See my code:http://pastebin.com/GRmNtags
>
> I run a command restore, to restore the file .sav and .cnj.... and
> then saved in 'data.dat' using 'printF'
>
> Is this correct what I did in rows 16 to 23??

Semantically, the code is correct, assuming that you have a structure
named modelo with a field name imag, and a structure named conjugado
with a field name imag. It is up to you to say if that is correct in
the sense of producing the file you wanted.

Though I do not see why do

modelo.imag=[MODELO.imag]
conjugado.imag=[CONJUGADO.imag]

Which does not change these variables.

However, there is an oddity coming before those lines: You first read
file.sav as a text file, into a string array. Then you restore it
(that is, read it as an IDL savefile). If it is a text file, the
restore will fail. And if it is a savefile, the read into a string
array, done that way, will probably read some (maybe all) of the file,
but the contents of the string array will be the bytes of the (binary)
savefile, interpreted as characters, which is going to be hard to make
sense of.

Also, you open file2.cnj, and never close it (never even use it). And,
as mentioned before, closing the unit opened with /get_lun to openw
does not release the unit number back into the pool (which a free_lun
would do).

The main question to me is: what do you want to be in the file you are
creating? To say it another way: what should the file look like?
Re: Read a file [message #74754 is a reply to message #74670] Mon, 31 January 2011 03:02 Go to previous message
Giovanna is currently offline  Giovanna
Messages: 12
Registered: January 2011
Junior Member
On 28 jan, 19:14, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Jan 28, 2:17 pm, Giovanna <giovanna01.san...@gmail.com> wrote:
>
>> Well...
>
>> I need to read a file file.sav and file1.cnj, then i need restore and
>> to get the structures modelo.imag, conjugado.imag. And to save in the
>> new file - data.dat(line 16).
>
>> I don't know how to take these structures(modelo.imag, conjugado.imag)
>> and save in this file data.dat
>
>> CAn you help me.??
>
>> My code:http://pastebin.com/GRmNtags
>
> Again, are file.sav and file1.cnj savefiles or text files? If they are
> savefiles, they can be read with restore. If they are text files,
> readf is one of the ways to read them. It does not make a lot of sense
> to try to read them both as if they were savefiles and text files.
> Also, it does not make much sense to open file2.cnj and never do
> anything with it.
>
> And, as mentioned before, the files should be closed, and the unit
> numbers released back into the pool (both can be done with free_lun).
>
> To tell how to make the file you want, we would have to know what kind
> of variables those fields are (modelo.imag, conjugado.imag), and what
> kind of output you want to make of them.
>
> The first question could be well answered by the output of
>
> help,modelo.imag,conjugado.imag

So, file.sav and file1.cnj are savefiles ...and modelo.imag:
Expression must be a structure in this context: MODELO.

Understand??

Thanks,
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Coyote Graphics Update 30 Jan 2011
Next Topic: Re: Y2 axis title orientation

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

Current Time: Wed Oct 08 13:39:43 PDT 2025

Total time taken to generate the page: 0.00671 seconds