en:praktikum:gdl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:praktikum:gdl [2014/12/13 16:56] – Rest msteinkeen:praktikum:gdl [2016/06/16 01:31] (current) rhainich
Line 10: Line 10:
 Now enter the GDL program code line by line and the interpreter executes it right away. Now enter the GDL program code line by line and the interpreter executes it right away.
  
-However, it's more conveniant to write the program as a file. Open a text editor of your choice (kate, emacs, nedit, vi,...) and write/edit the program file (its file extension should be .pro), then save it and compile it in GDL (in contrast to other languages like Fortran or C this will not create an executable file, because IDL/GDL works differently) using the command+However, it's more convenient to write the program as a file. Open a text editor of your choice (//kate////emacs////nedit////vi//,...) and write/edit the program file (its file extension should be ''.pro''), then save it and compile it in GDL (in contrast to other languages like Fortran or C this will not create an executable file, because IDL/GDL works differently) using the command
   .compile myprog.pro   .compile myprog.pro
-Depending on the name given to the program (inside the file as first line: //pro//), e.g. +The first line of the program code gives the (internal GDL) name of the program after the key word //pro//, e.g. 
   pro prog1   pro prog1
-the compiling will make the program "prog1" available for use. Execute it by calling+After compiling the program "prog1" can be executed by calling
   prog1   prog1
 in GDL. in GDL.
- 
  
 ====== Syntax ====== ====== Syntax ======
Line 26: Line 25:
 and even and even
   PrInT, "Hello World!"   PrInT, "Hello World!"
-return the same output. However, for strings and filenames it's different, as usual.+return the same output. However, for strings and file names it's different, as usual.
  
 ==== Basics==== ==== Basics====
  
-| Calling the interpreter: gdl  | +^                          Commands 
-| Starting GDL help:    |  ?    +| Calling the interpreter:|  ''gdl''  | 
-|                          |      +| Starting GDL help:    |  ''?''    | 
-| Show all variables: help  | +| Show all variables:|  ''help''  | 
-| Compile a script: |  .compile myprogram.pro +| Compile a script: |  ''.compile myprogram.pro''  | 
-| Execute the script in gdl: |  myprogram +| Execute the script in gdl: |  ''myprogram''  | 
-| Leave gdl:          exit  | +| Leave gdl:         |  ''exit''  | 
-| First line of a script:              pro myprogram +| First line of a script:             |  ''pro myprogram''  | 
-| Last line of a script (end of the program): |  end  |+| Last line of a script (end of the program): |  ''end''  |
  
 (Note: Replace "myprogram" with useful names that describe the program.) (Note: Replace "myprogram" with useful names that describe the program.)
 +
 ==== FITS files ==== ==== FITS files ====
  
-Read the content of a fits file into the variable "image1":+Read the content of a fits file into the variable //image1//:
   image1 = readfits('filename.fits')   image1 = readfits('filename.fits')
 If the image is not in the current directory, give the full (or relative) path (i.e. '../data/filename.fits'). If the image is not in the current directory, give the full (or relative) path (i.e. '../data/filename.fits').
  
-Depending on the internal computer architecture, data consisting of more than one byte are saved in either high or low byte order. In rare cases the default byte order is different between the source system (where the fits file was created) and the reduction system. This can be seen in (seemingly) absurd values and can be noticed when viewing the image of the fits file. If that happens, convert the byte order:+Depending on the internal computer architecture, data consisting of more than one byte are saved in either high or low byte order. In rare cases the default byte order is different between the source system (where the fits file was created) and the reduction system. This can be seen in (seemingly) absurd values and can be easily noticed when viewing the image of the fits file. If that happens, convert the byte order:
   byteorder, image1   byteorder, image1
  
Line 53: Line 53:
   writefits, 'newfilename.fits', image2   writefits, 'newfilename.fits', image2
  
-Note: All FITS commands require the (freely distributed) AstroLib for GDL/IDL (which is installed for the praktikum account).+Note: All FITS commands require the (freely distributed) [[http://idlastro.gsfc.nasa.gov/homepage.html|AstroLib]] for GDL/IDL (which is installed for the praktikum account, see [[en:software:howto_gdl_install|here]] for a how-to).
  
 ==== Input/Output ==== ==== Input/Output ====
Line 61: Line 61:
   print, "Hello ", namevar   print, "Hello ", namevar
      
-Any number of values/strings/variables and be attached, separted by commas. At the end there will be a line break.+Any number of values/strings/variables can be attached, separated by commas. At the end there will be a line break.
  
 Write into a file: Write into a file:
Line 69: Line 69:
   close, handle   close, handle
  
-//handle// needs to be an arbitrary but unique integer value. Alternative:+//handle// needs to be an arbitrary but unique integer value. Alternatively use:
  
   openw,out,'filename.dat',/get_lun   openw,out,'filename.dat',/get_lun
Line 76: Line 76:
   free_lun,out   free_lun,out
  
-GDL will assign a handle then (/get_lun). The command free_lun is needed to unassign that handle again.+In this case GDL will automatically assign a //handle// (via ///get_lun//). The command //free_lun// is needed to unassign that handle again.
  
 ==== Variables and arrays ==== ==== Variables and arrays ====
  
-Indexed variables start with the index 0. The array with indices 0, 1,..., MMAX has MMAX+1 entries, thus.+Index variables start with the index 0. Thus, an array with the indices 0,1,...,MMAX has MMAX+1 entries.
  
-Dimensioning for a two dimensional array for integer numbers:+Dimensioning of a two dimensional array for integer numbers:
   variablename = intarr(MMAX+1,NMAX+1)   variablename = intarr(MMAX+1,NMAX+1)
  
-If the variable shall contain larger numbers than Integer allows ($i>2^15-1=32767$)use Long or even Long64 (32 bit or 64 bit) arrays:+In some cases lager values are required than provided by the integer type ($i>2^{15}-1=32767$). In this case use Long or even Long64 (32 bit or 64 bit) arrays:
   variablename = lonarr(MMAX+1,NMAX+1)   variablename = lonarr(MMAX+1,NMAX+1)
   variablename = lon64arr(MMAX+1,NMAX+1)   variablename = lon64arr(MMAX+1,NMAX+1)
Line 100: Line 100:
 The number of entries in an array (e.g. //variablename//) can be checked with the command The number of entries in an array (e.g. //variablename//) can be checked with the command
   size(variablename,/dimensions)   size(variablename,/dimensions)
-which returns an array itself (data type, size etc.). To obtain the numberextract the first value (index 0!) of that array:+which returns an array itself (with data type, sizeetc.). To obtain the number of entries extract the first value (index 0!) of that array:
   number = (size(variablename,/dimensions))(0)   number = (size(variablename,/dimensions))(0)
  
Line 117: Line 117:
   endif   endif
  
-See the help of GDL (type "?"for moresee e.g. the [[http://gnudatalanguage.sourceforge.net/documentation.php|Documentation page of GDL]].+Additional information can be accessed via the help of GDL (type "?"). For more see the [[http://gnudatalanguage.sourceforge.net/documentation.php|Documentation page of GDL]].
  • en/praktikum/gdl.1418489806.txt.gz
  • Last modified: 2014/12/13 16:56
  • by msteinke