User Tools

Site Tools


internal:administration:idl

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
internal:administration:idl [2025/11/27 11:40] – [idl path] janinternal:administration:idl [2026/04/28 08:26] (current) – [interpolation] jan
Line 285: Line 285:
   IF x eq 4 THEN BEGIN   IF x eq 4 THEN BEGIN
     print, 'x equals 4' $     print, 'x equals 4' $
-  END ELSE BEGIN+  ENDIF ELSE BEGIN
     print, 'x is not 4'     print, 'x is not 4'
-  END+  ENDELSE
  
-for safety you may extend the END statements with blocked statement i.e. ENDIF or ENDELSE+to keep track of your blocks you may extend the END statements with the statement the block started with, i.e. ENDIF for the block started afer an 'IF' or ENDELSE or ENDCASE, ENDWHILE, etc. 
 +The interpreter tells you then if a ENDxxx statement does not fit.
  
-you may nest i.e. build structures like IF ... THEN ... ELSE IF ... THEN ... +You may nest i.e. build structures like IF ... THEN ... ELSE IF ... THEN ...\\ 
-or use the CASE statement.+ 
 + 
 +Alternatively you use the CASE statement:
  
   CASE x of   CASE x of
-     1: begin +     1: <> 
-       ... +    22: BEGIN
-        end +
-    22: begin+
         ...         ...
-        end +        END 
-    ELSE: begin+    ELSE: BEGIN
           ...           ...
-          end+          END
   ENDCASE   ENDCASE
  
Line 311: Line 312:
      x eq 1: begin      x eq 1: begin
        ...        ...
-        end+        END
     (x eq 22) OR (x eq 23): begin     (x eq 22) OR (x eq 23): begin
         ...         ...
-        end+        END
     ELSE: begin     ELSE: begin
           ...           ...
Line 335: Line 336:
   FOR i = 0,5 DO BEGIN   FOR i = 0,5 DO BEGIN
     PRINT, i     PRINT, i
-    END+    ENDFOR
      
   i = 0   i = 0
Line 341: Line 342:
     i = i+1     i = i+1
     PRINT, i     PRINT, i
-    END+    ENDWHILE
      
   i = 1   i = 1
Line 347: Line 348:
     i = i + 1      i = i + 1 
     PRINT, i     PRINT, i
-  END UNTIL i gt 5+  ENDREP UNTIL i gt 5
  
 to make coding a bit safer you may append the name of the loop command to the END statement, i.e. to make coding a bit safer you may append the name of the loop command to the END statement, i.e.
Line 354: Line 355:
   ENDREP    ENDREP 
  
-a PROCEDURE is a subroutine that may take parameters and change them. Its definition is started with the word PRO and ends with END statement+a PROCEDURE is a subroutine that may take parameters and change them. Its definition is started with the word PRO and ends with an END statement
  
   PRO my_proc, text_str, x_value=x_value   PRO my_proc, text_str, x_value=x_value
Line 625: Line 626:
   * As matrix operations are faster than for-loops this may speed up your code a lot ...   * As matrix operations are faster than for-loops this may speed up your code a lot ...
  
 +  * Alternatively one may use **rebin** , but note that rebin uses bilinear interpolation (sample=0) or nearest neigbor (sample=1) and accordingly might be a bit slower 
 +
 +  x = fltarr(Nx)
 +  y = fltarr(Ny)
 +  xx = rebin( x, Nx, Ny, sample=1 )
 +  yy = transpose(rebin( y, Ny, Nx ))
 +
 +  
 ==== procedure names ==== ==== procedure names ====
  
Line 814: Line 823:
   ss[0] = 'wind speed'   ss[0] = 'wind speed'
   ss[1] = 'm/s'   ss[1] = 'm/s'
 +
 +An array of strings can be also be splitted element by element, but only from Idl version 8. onwards. 
 +The result will be a  [[https://www.nv5geospatialsoftware.com/docs/list.html|LIST-Object]] , which might be converted to an array by using its method [[https://www.nv5geospatialsoftware.com/docs/list.html#ToArrayMethod|List::toArray()]] (note the brackets!).
 +
 +  s = [ 'a=b', 'c=d', 'e=f' ]
 +  sL = STRSPLIT( s, '=', /ex, count=N )
 +  sA = (STRSPLIT( s, '=', /ex, count=N )).toArray(  ) ; equal to sA = sL.toArray()
 +
 +Result %%sL%% will be a %%LIST%% object with N elements, and every entry of sL an array of strings with elements accorrding to the result fo strsplit.
 +Parameter %%N%% will be an array with the number of splits that could be made per element.
 +The conversion %%sL.toArray()%% works only if every entry in sL has the same number of elements.
 +The %%sA%% array would allow you to search for certain values in the array by using the where functions - eg:
 +
 +  ia = where( sA[*,0] eq 'a', Na )
 +
 +But you could also try to use the %%WHERE%% method of the %%LIST%% object ...
 +
  
  
Line 820: Line 846:
  
  
-filenames can be separated into path and name by +filenames can be separated into path and name with 
-  file_dirname( <path to file> ) +  f_dn = file_dirname( <path to file> ) 
-  file_basename( <path to file> )+  f_bn = file_basename( <path to file> ) 
 + 
 +where the dirname will have no '/' charcater. 
 + 
 +You may use strsplit to strip or get the 'filename extension' - the part of the filename after the last dot: 
 +  f_ext = (STRSPLIT( f_bn, '.', /ex, count=N ))[N-1] 
 +  f_bnx = STRJOIN((STRSPLIT( f_bn, '.', /ex, count=N ))[0:N-2],'.'
  
 ==== formatted output ==== ==== formatted output ====
Line 1768: Line 1801:
     xrange = [ 0.5 * hour, 2*1e6 ], $     xrange = [ 0.5 * hour, 2*1e6 ], $
     /xlog, $     /xlog, $
-    xticks = N_ticks-1, $  ; holy IDL - why do you need things like this ?+    xticks = N_ticks-1, $  ; xticks is the number of //intervals// not ticks!,  holy IDL - why do you need things like this ?
     xtickname = x_tiknams, $     xtickname = x_tiknams, $
     xtickv    = x_tikvals, $     xtickv    = x_tikvals, $
Line 3070: Line 3103:
   extrm_lev_max = +(machar()).xmax   extrm_lev_max = +(machar()).xmax
      
-See function [[https://www.harrisgeospatial.com/docs/machar.html|function machar]].+See function [[https://www.nv5geospatialsoftware.com/docs/MACHAR.html|function machar]].
  
  
Line 3086: Line 3119:
     /overplot     /overplot
  
-Keyword c_annotations is used here toprovide a format - this is usually not necessary.+Keyword c_annotations is used here to provide a format - this is usually not necessary.
 You can define also different thicknesses, colors etc. with the other %%c_...%% key words of %%contour%%  You can define also different thicknesses, colors etc. with the other %%c_...%% key words of %%contour%% 
 see [[http://www.physics.nyu.edu/grierlab/idl_html_help/C40.html#wp908085| help for contour]]. see [[http://www.physics.nyu.edu/grierlab/idl_html_help/C40.html#wp908085| help for contour]].
  
 +=== line patterns ===
 +
 +contour can draw hatch patterns - but note: the pattern is not transparent.
 +
 +  contour, z, x, y, $
 +    levels = levels, $
 +    c_orientation = [ 0 , 22, 45, 90, ... ] , $ ; orientation of the lines in degrees
 +    c_spacing = [ 1, 0.5, 0.25, ... ] ; spacing between lines in cm
 +    
 +
 +=== Path of contour lines ===
 +
 +contour can provide the pathes of the contour lines:
 +
 +  contour, z, x, y, $
 +    levels = levels, $ 
 +    path_info = path_info, $ ; info about the provided pathes (see below). If you provide here a variable contour will not draw.
 +    path_xy = path_xy, $ ; variable for coordinates: fltarr(2,N_tot)
 +    /path_data_coords, $ ; want to have data coordinates in data_xy instead of normalized coo's.
 +    /path_double, $ ; you need double if eg x is time as julian day
 +    /closed, $ ; close pathes along outline of the plotting area when isolines leave it.
 +    /overplot ; avoid contour to rescale the axes - if you already had a plot or contour plot you want to reuse
 +
 +path_info is an array of CONTOUR_PATH_STRUCTURE. The number of elelemtns gives the number of sub pathes.
 +Elements %%offset%% and %%N%% give the starting index and length of every isoline in path_xy.
 +
 +You can then use the pathes in poly_fill to do transparent hatch patterns: 
 +
 +  for i = 0, n_elements(path_info)-1 do begin
 +    ii = path_info[i].offset + lindgen(path_info[i].N)
 +    polyfill, path_xy[0,ii], path_xy[1,ii], /line_fill, spacing=0.7, orientation=i*5, noclip=0
 +  endfor ; i
 +
 +You could also use polyfill to put a byte pattern or wrap an image between the isolines ...
 +
 +  c = 255
 +  pattern = [ $
 +      [ 0, 0, 0, 0, 0, 0, 0 ], $
 +      [ 0, 0, 0, c, 0, 0, 0 ], $
 +      [ 0, 0, c, c, c, 0, 0 ], $
 +      [ 0, c, c, c, c, c, 0 ], $
 +      [ 0, 0, c, c, c, 0, 0 ], $
 +      [ 0, 0, 0, c, 0, 0, 0 ], $
 +      [ 0, 0, 0, 0, 0, 0, 0 ]  $
 +    ]
 +  for i = 0, n_elements(path_info)-1 do begin
 +    ii = path_info[i].offset + lindgen(path_info[i].N)
 +    polyfill, path_xy[0,ii], path_xy[1,ii], pattern=pattern, transparent=c-1, noclip=0, color='ff00ff'x
 +  endfor ; i
 +
 +But i do not understand how the transparent thing works - in this example it does not work. And if i understood it right i need to provide IMAGE_COORD, 
 +see  NV5 help for [[https://www.nv5geospatialsoftware.com/docs/POLYFILL_Procedure.html#dg_routines_3604229493_877795|POLYFILL]].
  
 === color bar === === color bar ===
  
-You can use contour also to make a **color bar**:+You may want to have a color bar setting the colorshading in relation to values. 
 +You can use contour to make a **color bar**:
  
 A **horizontal** color bar at the bottom A **horizontal** color bar at the bottom
Line 3765: Line 3851:
 If you want to interpolate only over certain dimensions they must be the last ones. You may use transpose to rearrange. Lets assume you have an array depending on x, y and time, i.e. z=fltarr(Nx,Ny,Nt) and you want to interpolate to certain x and y coordinates you can do this as follows: If you want to interpolate only over certain dimensions they must be the last ones. You may use transpose to rearrange. Lets assume you have an array depending on x, y and time, i.e. z=fltarr(Nx,Ny,Nt) and you want to interpolate to certain x and y coordinates you can do this as follows:
  
-  z_ipol = transpose( interpolate( transpose(z_org,[2,0,1]) , ix_ipol , iy_ipol , /grid  ), [1,2,0] )+  z_ipol = transpose( interpolate( transpose(z_org,[2,0,1]) , ix_ipol , iy_ipol , /grid, MISSING=!VALUES.f_nan  ), [1,2,0] )
  
 +The /GRID flag allow to use different sizes for ix_ipol and iy_ipol and the MISSING keyword sets values of z_ipol outside the ranges of z_org to the missing value (no extrapolation).
  
  
internal/administration/idl.1764243609.txt.gz · Last modified: by jan