en:praktikum:gdl

Differences

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

Link to this comparison view

Next revision
Previous revision
en:praktikum:gdl [2014/12/13 01:39] – created, Part 1 msteinkeen:praktikum:gdl [2016/06/16 01:31] (current) rhainich
Line 1: Line 1:
-FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)// 
  
 ====== GDL (IDL) for beginners ====== ====== GDL (IDL) for beginners ======
Line 11: 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 27: 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:    |  ''?''    | 
-| Anzeigen aller Variablen:|  help  | +Show all variables:|  ''help''  | 
-Kompilieren eines eigenen Scripts: |  .compile meinprogramm.pro  | +Compile a script: |  ''.compile myprogram.pro''  | 
-Ausführen des Scripts in gdl: |  meinprogramm  | +Execute the script in gdl: |  ''myprogram''  | 
-Beenden von GDL:          exit  | +Leave gdl:         |  ''exit''  | 
-Erste Zeile:              pro meinprogramm  | +First line of a script:             |  ''pro myprogram''  | 
-Letzte Zeile (Ende des Programms): |  end  |+Last line of a script (end of the program): |  ''end''  |
  
-==== FITS-Dateien ====+(Note: Replace "myprogram" with useful names that describe the program.)
  
-Einlesen eines Fits-Files in eine Variable:  +==== FITS files ====
-  bild1 readfi ts(' filename.fi ts'+
-Liegt das Bild nicht im aktuellen Verzeichnis muss man hier den ganzen (relativen) Pfad vor dem Dateinamen angeben.+
  
-Je nach interner Rechnerarchitektur werden Daten, die mehr als ein Byte umfassen entweder in High- oder Lowbyteordnung abgespeichert. In seltenen Faellen kann es passieren, dass die Standardordnung zwischen Quellsystem und Auswertesystem nicht identisch ist, was sich in (scheinbar) unsinnigen Werten ausdrückt und sich leicht mit einem Blick auf das Bild der FITS-Datei ermitteln laesst. In solchen Faellen muss die Byteordnung konvertiert werden mittels:  +Read the content of a fits file into the variable //image1//: 
-  byteorder, bild1 +  image1 = readfits('filename.fits'
-   +If the image is not in the current directorygive the full (or relative) path (i.e. '../data/filename.fits').
-Abspeichern eines Arrays (hier //bild2//) als FITS-Datei+
-  writefi ts, 'neuer filename. fits', bild2+
  
-Beachte: Alle FITS-Befehle benoetigen die (frei verfügbareAstrolib fuer GDL/IDL.+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 createdand the reduction systemThis 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
  
-==== Ein- und Ausgabe ====+Save an array (e.g. //image2//) as fits file: 
 +  writefits, 'newfilename.fits', image2
  
-Schreiben auf die Konsole+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).
  
-  print, "Hallo ", namevar+==== Input/Output ==== 
 + 
 +If the variable //namevar// has a content (e.g. namevar='world'), create output by writing: 
 + 
 +  print, "Hello ", namevar
      
-Mittels Komma getrennt koennen beliebig viele weitere Werte oder Variablen angehaengt werdenEs erfolgt an Ende ein Zeilenumbruch.+Any number of values/strings/variables can be attached, separated by commasAt the end there will be a line break.
  
-Schreiben in eine Datei:+Write into a file:
  
-  openw, handle, 'dateiname.dat' +  openw, handle, 'filename.dat' 
-  printf,handle,i,variable1,"Beispieltext",variable2+  printf,handle,i,variable1,"some text",variable2
   close, handle   close, handle
  
-//handle// muss dabei ein beliebiger, aber eindeutiger Integerwert sein.+//handle// needs to be an arbitrary but unique integer valueAlternatively use:
  
-==== Variablen und Felder ====+  openw,out,'filename.dat',/get_lun 
 +  printf,out,i,variable1,"some text",variable2 
 +  close,out 
 +  free_lun,out
  
-Indizierte Variablen beginnen mit dem Index 0Ein Array mit den Eintraegen 0, 1,... bis MMAX hat somit MMAX + 1 Eintraege +In this case GDL will automatically assign a //handle// (via ///get_lun//)The command //free_lun// is needed to unassign that handle again.
-   +
-Dimensionierung eines zweidimensionalen Arrays fuer Integer-Zahlen durch: +
-  variablenname = intarr(MMAX+1,NMAX+1)+
  
-In machen Faellen werden groessere Zahlenwerte benoetigt, als der Datentyp Integer hergibt, in diesem Fall kann +==== Variables and arrays ====
-  variablenname lonarr(MMAX+1,NMAX+1) +
-verwendet werden. +
  
-Fuer Fliesskommazahlen (Float) lautet der Befehl +Index variables start with the index 0. Thus, an array with the indices 0,1,...,MMAX has MMAX+1 entries.
-  variablenname = fltarr(MMAX+1,NMAX+1)+
  
-Die Anzahl der Eintraege eines Arrays (hier //arrayvar//) kann ueber den Befehl +Dimensioning of a two dimensional array for integer numbers: 
-  size(arrayvar,/dimensions) +  variablename intarr(MMAX+1,NMAX+1)
-ermittelt werden. Allerdings liefert ''size'' wiederum ein Array mit Informationen, von denen nur ein Wert die Anzahl der Eintraege ist. Um diesen direkt zu ermitteln, sollte der Befehl ergaenzt werden zu +
-  anz = (size(arrayvar,/dimensions))(0)+
  
 +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 = lon64arr(MMAX+1,NMAX+1)
 +  
 +For floating point numbers (Float) use
 +  variablename = fltarr(MMAX+1,NMAX+1)
  
-==== Kontrollstrukturen ====+For double-precision numbers (Double) use 
 +  variablename dblarr(MMAX+1,NMAX+1) 
 +   
 +For strings use 
 +  variablename strarr(MMAX+1,NMAX+1) 
 +   
 +The number of entries in an array (e.g. //variablename//) can be checked with the command 
 +  size(variablename,/dimensions) 
 +which returns an array itself (with data type, size, etc.). To obtain the number of entries extract the first value (index 0!) of that array: 
 +  number (size(variablename,/dimensions))(0)
  
-Schleifen-Syntax:+==== Control structures ==== 
 + 
 +Loop syntax:
  
   for j=n1,n2 do begin   for j=n1,n2 do begin
Line 99: Line 111:
   endfor   endfor
  
 +Conditional syntax: 
 +
 +  if a gt b then begin
 +    ...
 +  endif
  
 +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.1418434764.txt.gz
  • Last modified: 2014/12/13 01:39
  • by msteinke