This factor will vanish for even values of n.
Only do even values, multiply by (1-(-1)^n)/2.0. Repeat this instruction with the actual FourierĬoefficients for the triangle wave. Was just to show that the calculation works. The Fourier coefficients for the triangle wave.
(See previous problems Wave-1 and Wave-2 for detailsĬomputer Stations in TH 123 for details.) This will tell IDL to byte-swap the data when reading from the binary file.Computer system, starting the desktop, and changing to a subdirectory for this OpenW, Ilun, FileName, /Get_Lun, Swap_Endian=Little_Endian() OpenR, Ilun, FileName, /Get_Lun, Swap_Endian=Little_Endian() Or if you are using IDL's OPENR and OPENW functions directly: Get_LUN, /F77_Unformatted, /Write, Swap_Endian=Little_Endian() Get_LUN, /F77_Unformatted, Swap_Endian=Little_Endian() If you are using GAMAP's OPEN_FILE command, then be sure to use the SWAP_ENDIAN keyword as follows:
For example, you may be trying to read a GEOS-Chem binary punch file (which is Big Endian) from IDL on a PC or Linux cluster machine (which is Little Endian).įortunately, there is a simple way to read binary files of the opposite endian in IDL. What's wrong?Ĭhances are that you are reading a binary file that was created on a machine with the opposite endian from the machine that you are using. I used to be able to read a binary file in IDL but now I can't. It is pretty safe to say that most of the newer machines being built today are Little Endian. Machines with RISC chipsets tend to be Big Endian.Machines with Intel or AMD chipsets tend to be Little Endian.Then print, "I'm using IDL on a little-endian machine." $Įlse print, "I'm using IDL on a big-endian machine." The LITTLE_ENDIAN function that ships with the GAMAP package returns 1 if you are on a Little Endian machine, and returns 0 if you are on a Big Endian machine: How do I know which type of machine I am using? All binary punch files are Big Endian by default. The GEOS-Chem binary punch file format is an example of unformatted binary files. If you save data from a Big Endian machine and try to read it back into a Little Endian machine, then the bytes will be in wrong order and the data you will be interpreted as gibberish. When an IDL or Fortran program saves data to an unformatted file, it is saving the bytes directly from memory without any further data processing. However, if you are trying to read or write binary unformatted data, then the endian ordering becomes important.
Normally, you would not be concerned whether the computer you are using uses Big Endian or a Little Endian byte ordering. Little Endian may be found here: Why does it matter? Reverse of a car's odometer: digit order is "ones", "tens", "hundreds", "thousands", "ten-thousands"Ī good discussion about Big Endian vs.A Little Endian machine orders the bytes (in ascending order) from right to left.Think of a car's odometer: digit order is "ten-thousands", "thousands", "hundreds", "tens", "ones".A Big Endian machine orders the bytes (in descending order) from left to right.There are two ways that the bytes can be ordered: from right to left, or from left to right. (A byte consists of 8 bits and can be used to represent 256 distinct values.)įor all of these number types (except BYTE), you need more than one byte to create integer or floating point numbers in IDL and Fortran. Normally each number type is composed of one or more bytes. The terms "Big Endian" and "Little Endian" refer to the way that computers order bytes internally. 4 I used to be able to read a binary file in IDL but now I can't.3 How do I know which type of machine I am using?.