Escolar Documentos
Profissional Documentos
Cultura Documentos
SUPERMONGO
A Beginners Primer
By Martin Altmann
17.11.2005
no um programa de adaptao,
grficos 3D possveis, mas difcil, pagar
mercadoria!
Primeiros passos....!
computerwithSupermongoinstalled!
inthehomedirectorya.smfile
My.smfile:
nameMartin
fonts
/usr/astro/sm/lib/sm/fonts.bin
help/usr/astro/sm/lib/sm/help/
history80
history_file.smhist
#+graphcap
/usr/sm/lib/lib/sm/graphcap.local
filecap/usr/astro/sm/lib/sm/filecap
+graphcap
/usr/astro/sm/lib/sm/graphcap.local
graphcap/home/maltmann/SMres/graphcap
macro/home/maltmann/SMres/macro/
#macro/usr/astro/sm/lib/sm/macro/
save_filesmongo.sav
temp_dir/tmp/
termxterm
printerpostscript
promptsadomaso>
deviceX11
file_typefits
TeX_strings1
Amorebasic.smfile
nameBenedictXVI
history80
historyfile.smhist
promptsuperpope
deviceX11
file_typefits
Tex_strings1
Primeiros passos....!
Assim, no seu xterm voc digitar "sm", e ento isso
acontece:
/vat/JP_II>sm
Ol Bento XVI, por favor me d um comando
Super papa>
SM
Um grfico simples:
Precisamos de:um arquivo de
dados, por exemplo, com duas
colunas de dados.
#xy
00
0.10.01
0.20.04
0.30.09
0.40.16
0.50.25
0.70.49
0.90.81
11
1.52.25
24
2.56.25
39
416
525
superpope>datasquare.dat
superpope>lines00#linesstarting
with#willbeignored!00means
readallreadablelines
superpope>readx1
superpope>ready2
superpope>window1111
superpope>limits05025#limitsxy
willdothesametrick!
superpope>box1200
superpope>pointsxy
superpope>connectxy
superpope>xlabelx[cm]
superpope>ylabely[m/s]#anytext
Um grfico simples :
Pronto, aqui est ela! No
exatamente elegante, mas ns somos
principiantes. Permite entender
primeiro, o que fizemos, ok???
...e ento
podemos ver
como tornar
melhor este
resultado!!
Um grfico simples e os
comandos : do arquivo que contm
datafilename:nomes
Um grfico simples e os
comandos
limites X1 X2 Y1 Y2: estados dos limites do grfico,
Asimpleplot&thecommands:
pontos xy: desenha x vs y como pontos (pequenas
Reforando o enredo
Some new commands:
expandir r1: regula o tamanho do texto e smbolos (como
aqueles que o denotar pontos em uma parcela), incluindo
os rtulos do eixo, btw. expandir 1,001 (ou qualquer
nmero diferente de 1 sm foras para usar fontes do TeX),
larguras de linha no ser afetado
pType n1 n2: permite escolher um tipo de ponto
o primeiro nmero define o nmero de lados
o segundo se o smbolo ponto ser aberta (0), esqueltico
(1), com estrela (2) ou cheio (3)
exemplo pType 6 3 significa hexgonos cheios, pType 1 1
(ou 1 pontos significa alguma coisa)
Beefinguptheplot!
ctypeexpr.:Choosesthecolour,expr.caneitherbea
numberoroneofthefollowing:default,black,white,red,
green,blue,magenta,cyan,yellow(foradvancedusers,
onecandefine&accessmorecolours)
lweight n1: altera a largura da linha, tambm
afeta os smbolos e as caixas e texto!
TIPON n1: especifica um tipo de linha
0 = slidas, 1 = pontos, 2 = trao curto, travesso 3 = 4 =
ponto - trao curto, 5 = pontos - travesso, 6 = trao curto
- trao de comprimento, 10 = linhas apagar
posio xy na trama
geralmente refere-se a coordenadas do utilizador,
tambm possvel deslocar-se para coordenadas sistema
fixo (realocar (X) (Y))
desenhar xy: desenhar uma linha da posio atual x0 y0
para xy, geralmente use primeiro mudar! ver tambm
TIPON, lweight
texto do rtulo: escrever um texto em qualquer lugar na
trama (posio previamente definida por relocate)
valor do ngulo: todos os seguintes rtulos, mscaras etc,
so rodados o valor (em ) atribudos ao ngulo (lembre-se
de mudar o ngulo para 0 depois (por exemplo, todos os
rtulos do eixo vai mais ser girado))
Somemoreusefulcommands
errorbar x y expr. n1: funciona como pontos, mas chama a
n2n3n4:defineexponentialrangeoutsideofwhich
numericallabelsaregiveninexp.form,default:
notation4444
Somemoreusefulcommands
histogramxhx:drawsahistogram(howtomake
thehistogram(hx):later,justalittlepatience)
shadehistogramn1xhx:shadesahistogramwith
lines,spacedn1apart(anglecomesinhandyhere!
Usuallyhistogramandshadehistogramareusedtogether)
andsomeothermorespecialisedcommandssuch
ascircle,spline,etc.....
Sonowweknowhowtomakeplotsofquitesomesophistication
afterallitisbettertohaveabadresultpresentedinaniceformthana
goodonepresentedsloppily(seemanycommercials).ButbeforeIpresenta
plotwithbellsandwistles......dowereallyneedtohackinallthatstuff
overandoveragaintomakeaplot?
...ofcoursenot!Macros
Amacroisafile(script)inwhichallcommands
toe.g.generateaplotarelistedsequentiallyand
areexecutedbysmintheorderofappearance.
morethanonemacromaybestoredinonefile,
certainlimitsonfilelengthapply?(haven'thitone
lately)
macrosmaybecalledfromamacro(insamefile
oranotherfile)
afterexecutionofthemacro(asinmostscript
basedprogramminglanguages)theparametersare
notdefaulted(reinitialised),i.e.smdoesnotknow
whereacommandcomesfrom,fileor<stdin>
Macros:thebasicstructure
nameofthefile:irrelevant(butuse.mac,.sm,.m
orsimilartokeepmacrofilesapartfromothers)
Donotuse+*#'$/(){[]}><,etc.,_.allowed
macroname
1stcommand
2ndcommand
3rdcommand
4thcommand
5thcommand
etc.etc.
nextmacro
1stcommand
2ndcommand
#commentedline
#commentedline
Structure:
1st line: macroname (string
which denotes this particular
macro), starting at the beginning
of the line)
All other commands must start
on the 6th (or later) character of
the line
comments with # on first
position will be echoed to
<stdout>
comments with # on later
position will not be echoed
Macros:runningthem!
superpope>macroreadst_peter.m#readingthefile
superpope>urbi_et_orbi#executingthemacro
superpope>macroreadst_peter.murbi_et_orbi
#bothcommandsinoneline;betterbecauseonlyif
#filecontainingthemacroisrereadafterany
#changes,smwillknowaboutthem!
superpope>macroreadst_peter.mpadre_hurtado
#readinganothermacrofromthesamefile
Output(on<stdout>,dependingonverbositylevel,can
beadjusted):somecommentedlines(#onpos.1),
everythingafterecho(later),print(Isaid,later!!!),
readingprogress,warnings(logofnegativenumbers,
differentnumberofelementsinvectors,errors(syntax,or
otherwise,causingthemacrotoabort!)
Andhereweare,aplotwithall
kindsofBellsandWhistles!!!
Niceplot,buthowcan
Imakeacopyofit???
orevenaPSfile?
...Noproblem!(well
almost)
MakingHardcopiesandEPSfiles
smhasasocalledgraphcapfile.Thisfiledefinestheoutput
possibilities.Itispossibletoaddanadditionalcustomised
localgraphcapfileformoreoptionsincludingcommon
bitmapformats
Basicoutputdevices:X11(screen,usuallywonb),
postscript(directlytotheprinter,onCalantrytofindout
whichonefirst),postencap(toanEPSfilerecommended
output)
Commands:
superpope>devpostencaptest.ps
superpope>macroreadst_peter.mst_peter
superpope>devx11
superpope>devpostscript#w/ofilename
superpope>....
superpope>dev:SY@::OF@:postencap...#CALAN
Lookingdeeper...andprogramming
Supermongoisapowerfulgraphicspackage
butitcandomore....
...itisalmostafullblownprogramminglanguage
withareadilyavailablegraphicaloutputno
muddlingwithgraphicslibrariesetc.!
So now we're able to make decent plots, lets look into these
additional possibilities. To use it for programming we need to
take a deeper look into how sm actually works.
First we'll look at the two data types of sm, i.e. the concept of
Variables&Vectors
Variables:areonedimensionaldatausedfor
interactionwiththeuser,loops,etc.theycanalsobe
usedforcalculations,butvectorsarebetteratthat.
definingvariables:definevarname(value)(parentheses
necessaryifvalueismorethananumber)
callingvariables(contents):$varname,e.g.echo$varname
willgivevalueon<stdout>
calculatingwith/redefiningvariables:definei($i+1)
definea2
definez(lg(z)+a**i)
definingvariablesthrough<stdin>:definea?{prompt}
defineinput_file?{hey,gimmethefreakin'file}
Variables&Vectors
Vectors:aretheprimedatatypeforcalculations.
Theyarendimensionallistsofnumbersorstrings.
definingvectors:setvector=value(orexpression)
readvec1(yes,theoldreadcommand)
setx=0,1000,1(meaning:createa
vectorthatgoesfrom0to1000withincrementsof1)
set$a=x(assignavectortothe
contentsofavariableextremelyuseful)
callingvectors:inequations:vecname,without$
outputonscreen/inafile:print{x}orprint<x>,
theprintcommandisformattable:
print+$outfile'%7.3f\n'{x}(meaning:attach
toanexistingoutputfile(+)thevectorxinthe
formatreal7digitsoverall,and3behindthepoint,
\nmeansnewline)
Variables&Vectors
Vectors:someusefulcommands
dimen(x)givesthenumberofelementsinthevector(itsdimension)
x[$i]referstothe(i+1)thelementinthevector(notethatthe
elementsstartcountingat0toN1,ifNisthedimension)
sum(x)givesthesumofallelementsinthevector,vectorneedstobe
oftyperealorinteger.
sort{xyza}sortsthefirstvector(x)fromsmalltolargevalues
andrearrangesallsubsequentvectorsaccordingtothefirstone.Upto10
vectorscanbesortedthisway.
Variables&Vectors
Vectors:calculating(4basictypesofarithmetic)
x,yarevectorsofdimensionN,phasdimension1,aisavariable
Adding:x+y=(x0+y0,x1+y1,...,xn+yn),asinvectorarithmetic
but:x+p=(x0+p,x1+p,...,xn+p)unlikev.a.
x+$a=(x0+$a,...,xn+$a)
VectorsneedtobeeitherofthesamedimensionoroneNandone1,
vectorsofdimensionN1andN2(both>1)donotmix!
Subtracting:xy=(x0y0,x1y1,...,xnyn),asinvectorarithmetic
seeAdding
Multiplying:x*y=(x0*y0,x1*y1,...,xn*yn),unlikevectorartihmetic
but:x*p,x*$aarelikev.a.,seeadding
Division:x/y=(x0/y0,x1/y1,...,xn/yn)
x/$a,x/p,seeMultiplying/Adding
Variables&Vectors
Vectors:calculating(advancedoperations)
exprChangesignABS(expr)Absolutevalue
ACOS(expr)ArccosineASIN(expr)Arcsine
ATAN(expr)ArctangentCOS(expr)Cosine
CTYPE()ReturnCTYPEsDIMEN(vector)Dimensionofavector
EXP(expr)ExponentialGAMMA(expr,expr)Incompletegammafn
INT(expr)IntegralpartLG(expr)Log_10
LN(expr)Log_eRANDOM(s_expr)Randomnumbers
SIN(expr)SineSQRT(expr)Squareroot
STRING(expr)ConverttoastringSUM(expr)Sum_iexpr_i
TAN(expr)TangentVECTOR[expr]Elementsofanarray
(expr)Raiseprecedence
Allthinkablemathematicaloperationscanbeperformedonvectors
(manyofthemonvariablestoo).Therearealsosomeoperationsfor
strings,suchasstring(x),index(x,'char')orsubstring,
Binary:
expr+exprAddexprexprSubtract
exprCONCATexprConcatenateexpr*exprMultiply
expr/exprDivideexpr**exprExponentiate
expr&exprBitwiseANDexpr|exprBitwiseOR
expr%exprModulusATAN2(expr_y,expr_x)Atan2
Variables&Vectors
Vectors:calculating(specialops&comments)
PI:ispi,i.e.3,1416....
Allarcfunctionsassumearcmeasure(rad)notdegrees(deg),degrees
havetobetransformedtoradfirst
Constructingahistogram:
yisavectorwithvaluesbetween100and100.
setx=100,100,10
sethy=histogram(y:x)sortsthevaluesofyintothebins
definedbyx
histogramxhy
etc.plottingthehistogram
Branches&loops
Branch:theifclause:
if(condition==true){dothis}(simpleifstatement)
if(condition==true){
dothis
andthat
andalsothis
}else{(i.e.ifnottrue)
dothisotherthing
andthisoneaswell
}
fullifelsestatement
Theifclauseissimilar/identicaltotheifclauseinmost
programminglanguages!
Branches&loops
Loop:thewhileloop:
while{condition==true}{dothisstuff
andalsothis
andifyoufeellikeit
alsothis
}
typicalusage:
defineN(dimen(x)
definei0
while{$i<$N}{commands
definei($i+1)!dontforget!!!
}
Againthewhileloopexistsinmostotherlanguages
Branches&loops
Loop:thedoloop:
dovariable=start,end,[increment(default=1]{do
thisstuff
andalsothis
andifyoufeellikeit
alsothis
}
Againthedoloopexistsinmostotherlanguages
thebreakcommand:exitsawhileloopprematurelyonly
workswithwhilenotwithdo
testingconditions:>,<,<=,>=,==,!=(=alonewillresult
inerrormessage)
Thefinale
I have given an overview of Supermongo that is far from complete,
but it will give you enough input to be able to do plots and to start
writing macros yourself. Now.... practise, practise, practise, soon
you'll be able to write some very sophisticated stuff. For most
commands I have shown there are more options, that you might
want to explore in time. Now it was paramount to give a
straightforward approuch focussing on the bare essentials. The most
important command for some time will be help.
So