#!/bin/csh # # 'range' v2.0, June 4 1999, by R.A. Jansen # Kapteyn Astronomical Institute, University of Groningen (NL). # # This software is provided as is without any guarantee. # # C-shell script to print out one or more ranges of numbers. # Based on a script by M. Franx; rewritten 1995--1999 by R.A. Jansen. # Arguments: # -n # print every #-th number in the given range of numbers # -d # padd the numbers to the left with zeros to # digits # -p paste the numbers rather than print them one per line # -pre "pre" prefix to prepend to each number # -suf "suf" suffix to append to each number # Examples: # > range 1 - 12 --> 1 2 3 4 5 6 7 8 9 10 11 12 # > range -n 2 2 - 22 --> 2 4 6 8 10 12 14 16 18 20 22 # > range -d 3 1 - 7 --> 001 002 003 004 005 006 007 # > range -pre im -suf .fits 1 - 3 --> im1.fits im2.fits im3.fits # Note that numbers given explicitly (including the endpoints of a # range) are always echoed: # > range -n 2 1 - 7 12 18 - 25 31 --> 1 3 5 7 12 18 20 22 24 25 31 # ^ ^ ^^ ^^ ^^ ^^ if ( "" == "$1") then echo "Usage:" echo " range [-h[elp]] [-n #] [-d #] [-p] [-pre prefix] [-suf suffix] 1 - 3 4 5 ..." exit endif if ( "-h" == "$1" || "-help" == "$1" ) then echo "range v2.0, June 4 1999, by R.A. Jansen " echo "Kapteyn Astronomical Institute, University of Groningen" echo " " echo "C-shell script to print out one or more ranges of numbers." echo "Based on a script by M. Franx; rewritten 1995--1999 by R.A. Jansen." echo " " echo "Usage:" echo " range [-h[elp]] [-n #] [-d #] [-p] [-pre prefix] [-suf suffix] 1 - 3 4 5 ..." echo " " echo " -n # print every #-th number in the given range of numbers" echo " -d # padd the numbers to the left with zeros to # digits" echo " -p paste the numbers rather than print them one per line" echo " -pre "'"pre"'" prefix to prepend to each number" echo " -suf "'"suf"'" suffix to append to each number" echo " " echo "Examples:" echo " range 1 - 12 --> 1 2 3 4 5 6 7 8 9 10 11 12" echo " range -n 2 2 - 22 --> 2 4 6 8 10 12 14 16 18 20 22" echo " range -d 3 1 - 7 --> 001 002 003 004 005 006 007" echo " range -pre im -suf .fits 1 - 3 --> im1.fits im2.fits im3.fits" echo "NB: numbers given explicitly (including range limits) are always echoed:" echo " range -n 2 1 - 7 12 18 - 25 31 --> 1 3 5 7 12 18 20 22 24 25 31" echo " ^ ^ ^^ ^^ ^^ ^^" exit endif set nstep=1 set ndigits=1 set paste=0 set prefix="" set suffix="" set out="" while ( a == a) if ( "-n" == "$1" ) then set nstep=$2; shift; shift else if ( "-d" == "$1" ) then set ndigits=$2; shift; shift else if ( "-p" == "$1" ) then set paste=1; shift else if ( "-pre" == "$1" ) then set prefix="$2"; shift; shift else if ( "-suf" == "$1" ) then set suffix="$2"; shift; shift else break endif end set old=0 while ( "$1" != "" ) if ( $1 == - ) then shift @ old = $old + $nstep while ( $old < $1 ) set print=$old set n=0 set num=1 while ( $n < $ndigits ) if ( $num > $old ) set print=0$print @ num = 10 * $num @ n = $n + 1 end if ( $paste == 1 ) then set out="$out $prefix$print$suffix" else echo $prefix$print$suffix endif @ old = $old + $nstep end endif set print=$1 set old=$1 set n=0 set num=1 while ( $n < $ndigits ) if ( $num > $old ) set print=0$print @ num = 10 * $num @ n = $n + 1 end if ( $paste == 1 ) then set out="$out $prefix$print$suffix" else echo $prefix$print$suffix endif shift end if ( $paste == 1 ) echo $out