; docformat = 'rst' ;+ ; Batch file containing all the code intended to be typed at the command line ; from the "Programming" chapter. ;- ; Introduction print, findgen(10), $ format='(F0.2)' ; Looping constructs for i = 0, 9 do print, i for i = 0, 9, 2 do print, i for i = 9, 0, -1 do j = i print, j, i for i = 0, 40000 do j = i ; this line causes a syntax error for i = 0L, 40000 do j = i print, j ; for i = 0, 1, 0.1 do j = 1 ; this line is an infinite loop for i = 0.0, 1, 0.1 do j = i print, j print, j, format='(F20.15)' for i = 0, 10 do j = i / 10.0 print, j arr = 2. * findgen(5) foreach f, arr do print, f foreach f, arr, i do print, i, f i = 0 while ++i lt 10 do print, i i = 0 repeat print, i until ++i ge 10 ; Truth and conditionals _width = n_elements(width) eq 0L ? 1000L : width ; Routines print, 0 y = sin(findgen(360) * !dtor) a = 5 mg_by_reference_test, a print, a arr = fltarr(3) mg_by_reference_test, arr print, arr mg_by_reference_test, arr[0] print, arr[0] mg_param_test, 1, [0, 1, 2], /keyword print, keyword_set(0) print, keyword_set(1) print, keyword_set(2) print, keyword_set([0, 1, 2]) print, keyword_set([0]) x = findgen(360) * !dtor mg_window_plot, x, sin(x), xstyle=1, xsize=600, ysize=300 mg_dirinfo, count=nfiles, current_directory=currentDir print, nfiles print, currentDir mg_exactplot, x, sin(x), xstyle=4, color='0000FF'x mg_exactplot, x, sin(x), xsize=300 ; this line causes a syntax error ; Error handling section help, mg_long('5.0', error=error), error help, mg_long('not numeric', error=error), error mg_unknown_routine ; this line causes a syntax error help, !error_state, /structures ; Debugging ; Main-level programs .run mg_readplot plot, plotData[1, *] oplot, plotData[2, *] .run mg_long help, mg_long('5.0', error=error) ; Batch file @mg_batch_example help, a for i = 0, 9 do begin & j = i^2 & print, j & endfor ; compile_opt !warn.parens = 1 help, 0 compile_opt defint32 help, 0 help, 0S !warn.obs_routines = 1 .run mg_obsolete_routine a = findgen(10) print, a[-1] print, a[[-1, 0, 2, 9, 10]] compile_opt strictarrsubs print, a[[-1, 0, 2, 9, 10]] for i = 0, 4 do print, strtrim(i, 2) + ': ' + (i ? 'True' : 'False') for i = 0., 4. do print, strtrim(i, 2) + ': ' + (i ? 'True' : 'False') print, '' ? 'True' : 'False' print, 'Any non-null string' ? 'True' : 'False' compile_opt logical_predicate for i = 0, 4 do print, strtrim(i, 2) + ': ' + (i ? 'True' : 'False') print, ~2 ; Distribution of IDL code end