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

Home » Public Forums » archive » Unknown data type
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
Unknown data type [message #42107] Thu, 30 December 2004 05:59
julio is currently offline  julio
Messages: 31
Registered: December 2003
Member
Hello,

The files I want to read haven't any typical format. Each file has
information in the first line (like number of rows and columns), but
anything about data type�

So, I followed the tips of David. I carried out a "trial read" using�

Data_type=integer ; I assume all the files are integer
ON_IOERROR, bad
OPENR,lun, arq, /GET_lun
test = make_array(nc, nl,/integer)
READU, lun, test ; reading the file into an integer array
GOTO, Ok
bad: data_type=byte ; if the file coudn't be read into an integer
array
Ok: FREE_LUN, lun

As I told you first, I have only two possible data types: byte and
integer. So, using it, I could solve the problem.

Thanks David and others,
Julio
Re: Unknown data type [message #42115 is a reply to message #42107] Wed, 29 December 2004 05:43 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Julio wrote:

> Hello folks,
>
> I can read byte or integer images using byte or integer arrays, like:
>
> byte_image=bytarr(samples, rows) or
> integer_image=intarr(samples, rows)
>
> In both cases I must know the data type. But, when I don't know the
> data type, how can I do to read the images? Is there some way to
> verify the file format before reading into an array?
>
> Thanks for comments and happy New Yearᅵ
>
> Julio

This depends on what else you know about the data.
In your case it's only the type case which you want to determine. If you
probably knows how much lines and columns the image should have then it is
easy to calculate from the file size the length of the type you need for
reading the whole file. If you got 4byte as type it could be long or float.
Both will be able to read the whole file. You could first read it by float
and then test if float is necessary. If not read it a second time by long.

cheers
Reimar



--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
Re: Unknown data type [message #42119 is a reply to message #42107] Tue, 28 December 2004 20:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ed@schmahl.org writes:

> The first line of most image formats (at least the few that I've poked
> into) contains a code that tells you the format of the image. For
> example, a gif file may start off with GIF89, and a jpg file will have
> JFIF in the bytes 5-8. If you can figure out these codes in advance
> for each type of image you are likely to read, you can write a program
> to read the first dozen or so bytes and search for the code, then use
> that information to run the appropriate IDL routine (read_gif,
> read_jpeg, or whatever).
>
> You might even be able to learn how it's done for the 3 web-based
> formats
> (gif, jpg & png) by looking at the freely-available source code for
> Firefox or Mozilla, since these browsers (and any other competent one)
> identify the file type by reading the first several bytes.

Quite a few defined file formats have a "magic number"
that can be read to identify the file type. But, generally,
you know if you have one of these kind of files by the
file extension and you can read them directly with the
appropriate file reading program (READ_JPEG, READ_TIFF, etc.).

Most people who inquire about "how do I read this file
if I don't know what's in it" have been presented with
some kind of one-off file format written by a colleague
who divorced his wife of 25 years and ran off with the
department secretary and didn't leave very good notes
in his office drawer. For that kind of file you either
have to be incredibly clairvoyant or you have to use
some detective skills. But there no "easy way". :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Unknown data type [message #42120 is a reply to message #42107] Tue, 28 December 2004 19:29 Go to previous message
ed is currently offline  ed
Messages: 3
Registered: October 2004
Junior Member
Julio, David and others,

The first line of most image formats (at least the few that I've poked
into) contains a code that tells you the format of the image. For
example, a gif file may start off with GIF89, and a jpg file will have
JFIF in the bytes 5-8. If you can figure out these codes in advance
for each type of image you are likely to read, you can write a program
to read the first dozen or so bytes and search for the code, then use
that information to run the appropriate IDL routine (read_gif,
read_jpeg, or whatever).

You might even be able to learn how it's done for the 3 web-based
formats
(gif, jpg & png) by looking at the freely-available source code for
Firefox or Mozilla, since these browsers (and any other competent one)
identify the file type by reading the first several bytes.

Ed Schmahl
University of Maryland
Astronomy Department

David Fanning wrote:
> Julio writes:
>
>> I can read byte or integer images using byte or integer arrays,
like:
>>
>> byte_image=bytarr(samples, rows) or
>> integer_image=intarr(samples, rows)
>>
>> In both cases I must know the data type. But, when I don't know
the
>> data type, how can I do to read the images? Is there some way to
>> verify the file format before reading into an array?
>
> How can you find the New Year's party when you don't
> know the address? It's a problem. :-(
>
> Cheers,
>
> David
>
> P.S. You could do a small "trial read" and see
> if the data "made sense" the way you read it.
> What "makes sense" means is kind of up to you.
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Unknown data type [message #42129 is a reply to message #42107] Mon, 27 December 2004 19:19 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Julio writes:

> I can read byte or integer images using byte or integer arrays, like:
>
> byte_image=bytarr(samples, rows) or
> integer_image=intarr(samples, rows)
>
> In both cases I must know the data type. But, when I don't know the
> data type, how can I do to read the images? Is there some way to
> verify the file format before reading into an array?

How can you find the New Year's party when you don't
know the address? It's a problem. :-(

Cheers,

David

P.S. You could do a small "trial read" and see
if the data "made sense" the way you read it.
What "makes sense" means is kind of up to you.

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: GUI builder limitations?
Next Topic: passing objects between GUI callbacks

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

Current Time: Sat Oct 11 10:13:31 PDT 2025

Total time taken to generate the page: 0.15822 seconds