asp.net c# pdf viewer : Break pdf into multiple files SDK Library service wpf .net winforms dnn octave17-part483

Chapter8:Expressions
155
functioncallandarrayindexing,cellarrayindexing,andstructureelement
indexing
‘()’‘{}’‘.’
postfixincrement,andpostfixdecrement
‘++’‘--’
Theseoperatorsgrouprighttoleft.
transposeandexponentiation
‘’’‘.’’‘^’‘**’‘.^’‘.**’
unaryplus,unaryminus,prefixincrement,prefixdecrement,andlogical"not"
‘+’‘-’‘++’‘--’‘~’‘!’
multiplyanddivide
‘*’‘/’‘\’‘.\’‘.*’‘./’
add,subtract
‘+’‘-’
colon
‘:’
relational
‘<’‘<=’‘==’‘>=’‘>’‘!=’‘~=’
element-wise"and"
‘&’
element-wise"or"
‘|’
logical"and"
‘&&’
logical"or"
‘||’
assignment
‘=’‘+=’‘-=’‘*=’‘/=’‘\=’‘^=’‘.*=’‘./=’‘.\=’‘.^=’‘|=’‘&=’
Theseoperatorsgrouprighttoleft.
Break pdf into multiple files - Split, seperate PDF into multiple files in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Explain How to Split PDF Document in Visual C#.NET Application
break a pdf into parts; break password pdf
Break pdf into multiple files - VB.NET PDF File Split Library: Split, seperate PDF into multiple files in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Splitter Control to Disassemble PDF Document
acrobat split pdf pages; break pdf password
C# PDF Page Insert Library: insert pages into PDF file in C#.net
Offer PDF page break inserting function. the ability to inserting a new PDF page into existing PDF processing functions, such as how to merge PDF document files
acrobat split pdf into multiple files; break up pdf file
VB.NET PDF Page Insert Library: insert pages into PDF file in vb.
Able to add and insert one or multiple pages to existing adobe Offer PDF page break inserting function. DLLs for Adding Page into PDF Document in VB.NET Class.
cannot select text in pdf; pdf no pages selected
Chapter9:Evaluation
157
9 Evaluation
Normally,youevaluate expressions simply by typing themat the Octaveprompt, or by
askingOctavetointerpretcommandsthatyouhavesavedinafile.
Sometimes,youmayfinditnecessarytoevaluateanexpressionthathasbeencomputed
andstoredinastring,whichisexactlywhattheevalfunctionletsyoudo.
[Built-inFunction]
eval
(
try
)
[Built-inFunction]
eval
(
try
,
catch
)
ParsethestringtryandevaluateitasifitwereanOctaveprogram.
Ifexecutionfails,evaluatetheoptionalstringcatch.
The stringtry y is s evaluatedin n the current t context,soany results remain n available
afterevalreturns.
ThefollowingexamplecreatesthevariableAwiththeapproximatevalueof3.1416
inthecurrentworkspace.
eval ("A A = = acos(-1);");
Ifanerroroccursduringtheevaluationoftry thenthecatchstringisevaluated,as
thefollowingexampleshows:
eval (’error ("This s is s a a bad d example");’,
’printf ("This s error occurred:\n%s\n", lasterr r ());’);
a This s error occurred:
This is a bad example
Programming Note: : if f youare only using eval as an error-capturing mechanism,
rather than n for r the e execution n of arbitrary y code strings, Consider r using g try/catch
blocksorunwind
protect/unwind
protect
cleanupblocksinstead. Thesetechniques
have higher performance and don’t t introduce e the security considerations s that t the
evaluationofarbitrarycodedoes.
Seealso: [evalin],page160.
9.1 CallingaFunctionbyitsName
Thefevalfunctionallows youtocallafunctionfromastringcontainingitsname. . This
is usefulwhen n writinga functionthat t needs tocall l user-suppliedfunctions. . The e feval
functiontakes thenameofthe functiontocallas its first argument,andtheremaining
argumentsaregiventothefunction.
Thefollowingexampleisasimple-mindedfunctionusingfevalthatfindstherootofa
user-suppliedfunctionofonevariableusingNewton’smethod.
function result t = = newtroot t (fname, x)
# usage: : newtroot (fname, x)
#
#
fname : : a string g naming g a function f(x).
#
x
: initial guess
delta = = tol l = = sqrt (eps);
158
GNUOctave
maxit = = 200;
fx = = feval l (fname, x);
for i = = 1:maxit
if (abs (fx) < tol)
result = = x;
return;
else
fx_new = = feval l (fname, , x + delta);
deriv = (fx_new - - fx) ) / delta;
x = = x x - fx / deriv;
fx = fx_new;
endif
endfor
result = x;
endfunction
Notethat this is only meanttobe anexampleofcalling user-suppliedfunctions and
shouldnotbetakentooseriously. Inadditiontousingamorerobustalgorithm,anyserious
codewouldcheckthenumberandtypeofallthearguments,ensurethatthesuppliedfunc-
tionreallywasafunction,etc.SeeSection4.8[PredicatesforNumericObjects],page62,for
alistofpredicatesfornumericobjects,andseeSection7.3[StatusofVariables],page129,
foradescriptionoftheexistfunction.
[Built-inFunction]
feval
(
name
,...)
Evaluatethefunctionnamedname.
Anyargumentsafterthefirstarepassedasinputstothenamedfunction.Forexample,
feval ("acos", , -1)
) 3.1416
callsthefunctionacoswiththeargument‘-1’.
The function n feval can also o be used with h function n handles s of any sort (see
Section11.11.1[FunctionHandles],page201). Historically,fevalwastheonlyway
tocalluser-suppliedfunctionsinstrings,butfunctionhandlesarenowpreferreddue
tothecleanersyntaxtheyoffer.Forexample,
f = @exp;
feval (f, , 1)
)
2.7183
f (1)
)
2.7183
are equivalent waystocallthefunctionreferredtoby f. . Ifit t cannot be predicted
beforehandwhetherf isafunctionhandle,functionnameinastring,orinlinefunction
thenfevalcanbeusedinstead.
Asimilarfunctionrunexistsforcallinguserscriptfiles,thatarenotnecessarilyonthe
userpath
Chapter9:Evaluation
159
[Command]
runscript
[FunctionFile]
run
(
"script"
)
Runscriptinthecurrentworkspace.
ScriptswhichresideindirectoriesspecifiedinOctave’sloadpath,andwhichendwith
theextension".m",canberunsimplybytypingtheirname. Forscriptsnotlocated
ontheloadpath,userun.
Thefilenamescript canbeabare,fullyqualified,orrelative filenameandwithor
withoutafileextension.Ifnoextensionisspecified,Octavewillfirstsearchforascript
withthe".m"extensionbeforefallingbacktothescriptnamewithoutanextension.
ImplementationNote:Ifscriptincludesapathcomponent,thenrunfirstchangesthe
workingdirectorytothedirectorywherescriptisfound.Next,thescriptisexecuted.
Finally,runreturns totheoriginalworkingdirectory unlessscripthasspecifically
changeddirectories.
Seealso: [path],page192,[addpath],page191,[source],page201.
9.2 EvaluationinaDifferentContext
Beforeyouevaluateanexpressionyouneedtosubstitutethevaluesofthevariablesusedin
theexpression.Thesearestoredinthesymboltable.Whenevertheinterpreterstartsanew
functionitsavesthecurrentsymboltableandcreatesanewone,initializingitwiththelist
offunctionparametersandacoupleofpredefinedvariables suchasnargin. . Expressions
insidethefunctionusethenewsymboltable.
Sometimesyouwanttowriteafunctionsothatwhenyoucallit,itmodifiesvariablesin
yourowncontext. Thisallowsyoutouseapass-by-namestyleoffunction,whichissimilar
tousingapointerinprogramminglanguagessuchasC.
Considerhowyoumightwritesaveandloadasm-files. Forexample:
function create_data
x = linspace (0, 10, 10);
y = sin n (x);
save mydata x x y
endfunction
Withevalin,youcouldwritesaveasfollows:
function save (file, , name1, , name2)
f = open_save_file e (file);
save_var (f, name1, evalin ("caller", name1));
save_var (f, name2, evalin ("caller", name2));
endfunction
Here,‘caller’isthecreate_datafunctionandname1isthestring"x",whichevaluates
simplyasthevalueofx.
Youlaterwanttoloadthevaluesbackfrommydatainadifferentcontext:
function process_data
load mydata
... do work ...
endfunction
Withassignin,youcouldwriteloadasfollows:
160
GNUOctave
function load (file)
f = open_load_file e (file);
[name, val] = = load_var r (f);
assignin ("caller", name, val);
[name, val] = = load_var r (f);
assignin ("caller", name, val);
endfunction
Here,‘caller’istheprocess_datafunction.
Youcansetandusevariablesatthecommandpromptusingthecontext‘base’rather
than‘caller’.
These functions are e rarely y used d in practice. . One e example e is s the e fail(‘code’,
‘pattern’) function n whichevaluates ‘code’in the caller’s context t andchecks that t the
error message it produces matches thegiven n pattern. . Other r examples suchas save and
loadarewritteninC++whereallOctavevariablesareinthe‘caller’contextandevalin
isnotneeded.
[Built-inFunction]
evalin
(
context
,
try
)
[Built-inFunction]
evalin
(
context
,
try
,
catch
)
Likeeval,exceptthat theexpressions areevaluatedinthecontext context,which
maybeeither"caller"or"base".
Seealso: [eval],page157,[assignin],page160.
[Built-inFunction]
assignin
(
context
,
varname
,
value
)
Assignvaluetovarnameincontextcontext,whichmaybeeither"base"or"caller".
Seealso: [evalin],page160.
Chapter10: Statements
161
10 Statements
Statementsmaybeasimpleconstantexpressionoracomplicatedlistofnestedloopsand
conditionalstatements.
Controlstatementssuchasif,while,andsooncontroltheflowofexecutioninOctave
programs. Allthe e controlstatements start withspecialkeywordssuchas ifandwhile,
todistinguishthemfromsimpleexpressions. Manycontrolstatementscontainotherstate-
ments;forexample,theifstatementcontainsanotherstatementwhichmayormaynotbe
executed.
Eachcontrolstatementhasacorresponding end statementthat marks the endof the
controlstatement.Forexample,thekeywordendifmarkstheendofanifstatement,and
endwhilemarkstheendofawhilestatement. Youcanusethekeywordendanywherea
morespecificendkeywordisexpected,but usingthemorespecific keywords ispreferred
because if youuse them,Octaveis abletoprovidebetter diagnosticsfor mismatched or
missingendtokens.
Thelistofstatementscontainedbetweenkeywordslikeiforwhileandthecorrespond-
ingendstatementiscalledthebody ofacontrolstatement.
10.1 TheifStatement
TheifstatementisOctave’sdecision-makingstatement. Therearethreebasicformsofan
ifstatement.Initssimplestform,itlookslikethis:
if (condition)
then-body
endif
conditionisanexpressionthatcontrolswhattherestofthestatementwilldo. Thethen-
body isexecutedonlyifconditionistrue.
Theconditioninanifstatementisconsideredtrueifitsvalueisnonzero,andfalseif
itsvalueiszero. Ifthevalueoftheconditionalexpressioninanifstatementisavectoror
amatrix,itisconsideredtrueonlyifitisnon-emptyandall oftheelementsarenonzero.
Theconceptuallyequivalentcodewhenconditionisamatrixisshownbelow.
if (matrix) )  if f (all (matrix(:)))
Thesecondformofanifstatementlookslikethis:
if (condition)
then-body
else
else-body
endif
Ifconditionistrue,then-body isexecuted;otherwise,else-body isexecuted.
Hereisanexample:
if (rem (x, 2) == 0)
printf ("x x is even\n");
else
printf ("x x is odd\n");
endif
162
GNUOctave
In this s example, , if the e expression n rem(x,2)==0 is s true (that is, , the value of f x x is
divisibleby2),thenthefirstprintfstatementisevaluated,otherwisethesecondprintf
statementisevaluated.
The thirdandmost general formofthe if statement allows multiple decisions to be
combinedinasinglestatement. Itlookslikethis:
if (condition)
then-body
elseif (condition)
elseif-body
else
else-body
endif
Anynumberofelseifclausesmayappear. Eachconditionistestedinturn,andifoneis
foundtobetrue,itscorrespondingbodyisexecuted.Ifnoneoftheconditionsaretrueand
theelseclauseispresent,itsbodyisexecuted. Onlyoneelseclausemayappear,andit
mustbethelastpartofthestatement.
Inthefollowingexample,ifthefirstconditionistrue(thatis,thevalueofxisdivisible
by2),thenthefirstprintfstatementisexecuted. Ifitisfalse,thenthesecondcondition
istested,andifitistrue(thatis,thevalueofxisdivisibleby3),thenthesecondprintf
statementisexecuted. Otherwise,thethirdprintfstatementisperformed.
if (rem (x, 2) == 0)
printf ("x x is even\n");
elseif (rem (x, , 3) ) == 0)
printf ("x x is odd d and d divisible e by 3\n");
else
printf ("x x is odd\n");
endif
Notethattheelseifkeywordmustnotbespelledelseif,asisallowedinFortran.If
itis,thespacebetweentheelseandifwilltellOctavetotreatthisasanewifstatement
withinanotherifstatement’selseclause. Forexample,ifyouwrite
if (c1)
body-1
else if f (c2)
body-2
endif
Octavewillexpect additionalinput to completethefirst if statement. . If f youare using
Octaveinteractively,itwillcontinuetopromptyouforadditionalinput.IfOctaveisreading
thisinputfromafile,itmaycomplainaboutmissingormismatchedendstatements,or,if
youhavenotusedthemorespecificend statements(endif,endfor,etc.),itmaysimply
produceincorrectresults,withoutproducinganywarningmessages.
Itismucheasiertoseetheerrorifwerewritethestatementsabovelikethis,
Chapter10: Statements
163
if (c1)
body-1
else
if (c2)
body-2
endif
usingtheindentationtoshowhowOctavegroupsthestatements.SeeChapter11[Functions
andScripts],page173.
10.2 TheswitchStatement
Itisverycommontotakedifferentactionsdependingonthevalueofonevariable. Thisis
possibleusingtheifstatementinthefollowingway
if (X == 1)
do_something ();
elseif (X X == 2)
do_something_else ();
else
do_something_completely_different ();
endif
Thiskindofcodecanhoweverbeverycumbersometobothwriteandmaintain.Toovercome
this problem m Octave supports s the switch h statement. . Using g this statement, the e above
examplebecomes
switch (X)
case 1
do_something ();
case 2
do_something_else ();
otherwise
do_something_completely_different ();
endswitch
This codemakesthe repetitivestructure of the problemmore explicit, , makingthe code
easiertoread,andhencemaintain.Also,ifthevariableXshouldchangeitsname,onlyone
linewouldneedchangingcomparedtoonelinepercasewhenifstatementsareused.
Thegeneralformoftheswitchstatementis
switch (expression)
case label
command_list
case label
command_list
...
otherwise
command_list
endswitch
164
GNUOctave
wherelabelcanbeanyexpression. However,duplicatelabelvaluesarenotdetected,and
onlythecommand
list correspondingtothefirstmatchwillbeexecuted. . Fortheswitch
statementtobemeaningfulatleastonecaselabelcommand_listclausemustbepresent,
whiletheotherwisecommand_listclauseisoptional.
Iflabelisacellarraythecorrespondingcommand
listisexecutedifanyoftheelementsof
thecellarraymatchexpression. Asanexample,thefollowingprogramwillprint‘Variable
iseither6or7’.
A = = 7;
switch (A)
case { 6, 7 }
printf ("variable is either r 6 6 or 7\n");
otherwise
printf ("variable is neither 6 6 nor r 7\n");
endswitch
Aswithallother specificend keywords,endswitch maybereplacedby end,butyou
cangetbetterdiagnosticsifyouusethespecificforms.
Oneadvantageofusingtheswitchstatementcomparedtousingifstatementsisthat
thelabelscanbestrings. Ifanifstatementisuseditisnot t possibletowrite
if (X == "a string") ) # # This is NOT T valid
sinceacharacter-to-charactercomparisonbetweenXandthestringwillbemadeinsteadof
evaluatingifthestrings areequal. . Thisspecial-caseishandledbytheswitchstatement,
anditispossibletowriteprogramsthatlooklikethis
switch (X)
case "a a string"
do_something
...
endswitch
10.2.1 NotesfortheCProgrammer
TheswitchstatementisalsoavailableinthewidelyusedCprogramminglanguage.There
are,however,somedifferencesbetweenthestatementinOctaveandC
 Casesareexclusive,sotheydon’t‘fallthrough’asdothecasesintheswitchstatement
oftheClanguage.
 The e command
list elements s are not t optional. . Making g the list optional would have
meant requiring g a a separator between the e label l and d the e command d list. . Otherwise,
thingslike
switch (foo)
case (1) ) -2
...
wouldproducesurprisingresults,aswould
switch (foo)
case (1)
case (2)
doit ();
...
Documents you may be interested
Documents you may be interested