From David.Steele@usask.ca Fri Jul 12 08:22:14 1996 Path: tribune.usask.ca!decwrl!news.PBI.net!news.mathworks.com!fu-berlin.de!news.th-darmstadt.de!news From: hahn@hrz.th-darmstadt.de (Norbert Hahn) Newsgroups: comp.lang.idl-pvwave Subject: Re: ASSOC function Date: Fri, 12 Jul 1996 12:56:27 GMT Organization: Technische Hochschule Darmstadt Lines: 75 Message-ID: <4s5hip$1885@rs18.hrz.th-darmstadt.de> References: <31E56C0D.571F@hawk.igs.net> NNTP-Posting-Host: pc03.hrz.th-darmstadt.de X-Newsreader: Forte Free Agent 1.0.82 Godelieve Deblonde & Ivan L'Heureux wrote: >Hello, >I have written a binary file using fortran code: [snip] >Some of the numbers are read in correctly, but some strange numbers appear >also. I have also added the keyword f77_unformatted but it still did not work. Well, you had the right thoughts, but the place was wrong: Writing a file sequentially with unformatted i/o causes the Fortran run time system to add the record length both before and after the data. Altho not required by the Fortran standard, this is usefull for the BACKSPACE function for *variable* length records. When you read such a file *sequentially* in IDL you must add the keyword f77_unformatted, as you did. So, this was the right part of your thoughts. Using the ASSOC function causes IDL to randomly access data in *fixed* records. As the records are assumed to be fixed, the record length is not expected, neither by IDL nor by Fortran. To make ASSOC work you must write the Fortran records as direct access records! The Fortran run time system does not add anything when writing DA records. So IDL and Fortran is pretty compatible. >On a HP, I have managed to read the binary file using a direct access mode for >the fortran open statement. This does not work on an SGI machine though. I don't know why this workedd on a HP system, but I assume that you got both the data and the record lenght words as data because all your records have the same length. To be on the save side I would always use the same technique for writing and reading: If you are going to read the data by using IDL's ASSOC function, thus by direct access, I recommend to write the data as a direct access file from Fortran. >Has anybody out there tried this before? I am quite sure that somebody >must have run into this problem. Yes, everybody can fall into this pit on every Unix system: This may be different on other operating systems! > I don't think that RSI will be of much help >answering this question, they don't have a fortran compiler on an SGI! So they >told me. It's not the lack of a Fortran compiler but the lack of clear thoughts in the IDL user's manual. Chapter 17 describes the difference between Unformatted i/o and Formatted i/o but simply ignores differences between Sequentiel i/o and Direct Access i/o. And XDR is not mentioned as an additional format!! Things can get even more complicated when you write a file with IDL and plan to read it in Fortran: Once a file is open for output IDL allows you to write the same file formatted and unformatted: OpenW, 27, 'test.dat' WriteU, 27, !DPI PrintF, 27, 2*!pi, format='(F10.6)' Close, 27 This example works quite well, but you cannot read this file with a Fortran program without doing some tricks: When opening a file in Fortran you must specify to read it either formatted or unformatted! >Thanks, >Godelieve Hope this helps Norbert