%%% $Id: jkthesis.bst,v 1.5 2002/07/12 05:49:13 jochen Exp $
%%%
%%% Copyright (C) 1999--2001 Jochen K�pper
%%%
%%% This is file `abbrev', containing all journal abbreviations we use.
%%% It tries to be consistent with general merlin abbrevs, so don't use
%%% the merlin names differently.
%%%
%%% Due to some limitations in the automatic generation of
%%% abbrev.bib from this file, do not insert blank lines !
%%% Do not split macros accross multiple lines !
%%% Keep the exact format of all these entries !
%%% (Only comments or macro-Lines are allowed.)
MACRO {aa} {"Astron.\ \& Astrophys."}
MACRO {acr} {"Acc.\ Chem.\ Res."}
MACRO {acmcs} {"ACM Comput.\ Surv."}
MACRO {acta} {"Acta Inf."}
MACRO {actacryst} {"Acta Cryst."}
MACRO {actaphys} {"Acta Phys."}
MACRO {advp} {"Adv.\ Phys."}
MACRO {ajp} {"Amer.\ J.\ Phys."}
MACRO {ajm} {"Amer.\ J.\ Math."}
MACRO {amsci} {"Amer.\ Sci."}
MACRO {anofd} {"Ann.\ Fluid Dyn."}
MACRO {am} {"Ann.\ Math."}
MACRO {ap} {"Ann.\ Phys.\ (NY)"}
MACRO {adp} {"Ann.\ Phys.\ (Leipzig)"}
MACRO {ao} {"Appl.\ Opt."}
MACRO {apa} {"Appl.\ Phys.\ A"}
MACRO {apb} {"Appl.\ Phys.\ B"}
MACRO {apl} {"Appl.\ Phys.\ Lett."}
MACRO {app} {"Astroparticle Phys."}
MACRO {apj} {"Astrophys.\ J."}
MACRO {baps} {"Bull.\ Amer.\ Phys.\ Soc."}
MACRO {bunsen} {"Ber.\ Bunsenges.\ Phys.\ Chem."}
MACRO {biochem} {"Biochem."}
MACRO {chember} {"Chem.\ Ber."}
MACRO {biopol} {"Biopol."}
MACRO {canjp} {"Can.\ J.\ Phys."}
MACRO {cacm} {"Commun.\ ACM"}
MACRO {cmp} {"Comm.\ Math.\ Phys."}
MACRO {cp} {"Chem.\ Phys."}
MACRO {cpam} {"Commun.\ Pure Appl.\ Math."}
MACRO {cppcf} {"Comm.\ Plasma Phys.\ \& Controlled Fusion"}
MACRO {cpc} {"Comp.\ Phys.\ Comm."}
MACRO {cpl} {"Chem.\ Phys.\ Lett."}
MACRO {cqg} {"Class.\ Quant.\ Grav."}
MACRO {cra} {"C.\ R.\ Acad.\ Sci.\ A"}
MACRO {ddj} {"Dr.\ Dobbs Journal"}
MACRO {fed} {"Fusion Eng.\ \& Design"}
MACRO {ft} {"Fusion Tech."}
MACRO {grg} {"Gen.\ Relativ.\ Gravit."}
MACRO {ibmjrd} {"IBM J.\ Res.\ Dev."}
MACRO {ibmsj} {"IBM Syst.\ J."}
MACRO {ieeens} {"IEEE Trans.\ Nucl.\ Sci."}
MACRO {ieeeps} {"IEEE Trans.\ Plasma Sci."}
MACRO {ieeese} {"IEEE Trans.\ Softw.\ Eng."}
MACRO {ieeetc} {"IEEE Trans.\ Comput."}
MACRO {ieeetcad} {"IEEE Trans.\ Comput.-Aided Design Integrated Circuits"}
MACRO {ijimw} {"Interntl.\ J.\ Infrared \& Millimeter Waves"}
MACRO {indjpap} {"Indian J.\ Pure Appl.\ Phys."}
MACRO {ip} {"Infrared Phys."}
MACRO {ipl} {"Inf.\ Process.\ Lett."}
MACRO {irp} {"Infrared Phys."}
MACRO {jacm} {"J.\ ACM"}
MACRO {jacs} {"J.\ Am.\ Chem.\ Soc."}
MACRO {jap} {"J.\ Appl.\ Phys."}
MACRO {jasa} {"J.\ Acoust.\ Soc.\ America"}
MACRO {jcedu} {"J.\ Chem.\ Educ."}
MACRO {jchp} {"J.\ Chem.\ Phys."}
MACRO {jcp} {"J.\ Comp.\ Phys."}
MACRO {jcs} {"J.\ Chem.\ Soc."}
MACRO {jcss} {"J.~Comput.\ Syst.\ Sci."}
MACRO {jetp} {"Sov.\ Phys.--JETP"}
MACRO {jfe} {"J.\ Fusion Energy"}
MACRO {jfm} {"J.\ Fluid Mech."}
MACRO {jmolspec} {"J.\ Mol.\ Spec."}
MACRO {jmolstruct} {"J.\ Mol.\ Struct."}
MACRO {jmp} {"J.\ Math.\ Phys."}
MACRO {jne} {"J.\ Nucl.\ Energy"}
MACRO {jnm} {"J.\ Nucl.\ Mat."}
MACRO {jpc} {"J.\ Phys.\ Chem."}
MACRO {jpca} {"J.\ Phys.\ Chem.\ A"}
MACRO {jpcb} {"J.\ Phys.\ Chem.\ B"}
MACRO {jpp} {"J.\ Plasma Phys."}
MACRO {jpsj} {"J.\ Phys.\ Soc.\ Japan"}
MACRO {jsi} {"J.\ Sci.\ Instrum."}
MACRO {jvst} {"J.\ Vac.\ Sci.\ \& Tech."}
MACRO {laserchem} {"Laser Chem."}
MACRO {molphys} {"Mol.\ Phys."}
MACRO {nat} {"Nature"}
MACRO {nature} {"Nature"}
MACRO {nedf} {"Nucl.\ Eng.\ \& Design/Fusion"}
MACRO {nf} {"Nucl.\ Fusion"}
MACRO {nim} {"Nucl.\ Inst.\ \& Meth."}
MACRO {nimpr} {"Nucl.\ Inst.\ \& Meth.\ in Phys.\ Res."}
MACRO {np} {"Nucl.\ Phys."}
MACRO {npb} {"Nucl.\ Phys.\ B"}
MACRO {nt/f} {"Nucl.\ Tech./Fusion"}
MACRO {inc} {"Nuovo Cimento"}
MACRO {nc} {"Nuovo Cimento"}
MACRO {optcom} {"Opt.\ Commun."}
MACRO {optspec} {"Optics {a}nd Spectroscopy"}
MACRO {orgmassspec} {"Org.\ Mass Spectrom."}
MACRO {pccp} {"Phys.\ Chem.\ Chem.\ Phys."}
MACRO {perkin} {"J.\ Chem.\ Soc.\ Perkin Trans."}
MACRO {pf} {"Phys.\ Fluids"}
MACRO {pfa} {"Phys.\ Fluids A: Fluid Dyn."}
MACRO {pfb} {"Phys.\ Fluids B: Plasma Phys."}
MACRO {photochembio} {"Photochem.\ Photobiol."}
MACRO {pl} {"Phys.\ Lett."}
MACRO {pla} {"Phys.\ Lett.\ A"}
MACRO {plb} {"Phys.\ Lett.\ B"}
MACRO {prep} {"Phys.\ Rep."}
MACRO {pnas} {"Proc.\ Nat.\ Acad.\ Sci.\ USA"}
MACRO {pp} {"Plasma Phys."}
MACRO {ppcf} {"Plasma Phys.\ \& Controlled Fusion"}
MACRO {phitrsl} {"Philos.\ Trans.\ Roy.\ Soc.\ London"}
MACRO {prl} {"Phys.\ Rev.\ Lett."}
MACRO {pr} {"Phys.\ Rev."}
MACRO {pra} {"Phys.\ Rev.\ A"}
MACRO {prb} {"Phys.\ Rev.\ B"}
MACRO {prc} {"Phys.\ Rev.\ C"}
MACRO {prd} {"Phys.\ Rev.\ D"}
MACRO {pre} {"Phys.\ Rev.\ E"}
MACRO {ps} {"Phys.\ Scripta"}
MACRO {procrsl} {"Proc.\ Roy.\ Soc.\ London"}
MACRO {rmp} {"Rev.\ Mod.\ Phys."}
MACRO {rsi} {"Rev.\ Sci.\ Inst."}
MACRO {sam} {"Stud.\ Appl.\ Math."}
MACRO {sciam} {"Sci.\ Am."}
MACRO {science} {"Science"}
MACRO {scp} {"Sci.\ Comput.\ Programming"}
MACRO {sicomp} {"SIAM J.\ Comput."}
MACRO {sjpp} {"Sov.\ J.\ Plasma Phys."}
MACRO {spd} {"Sov.\ Phys.--Doklady"}
MACRO {specacta} {"Spectrochim.\ Acta"}
MACRO {sptp} {"Sov.\ Phys.-Tech.\ Phys."}
MACRO {spu} {"Sov.\ Phys.-Uspeki"}
MACRO {tocs} {"ACM Trans.\ Comput.\ Syst."}
MACRO {tods} {"ACM Trans.\ Database Syst."}
MACRO {tog} {"ACM Trans.\ Gr."}
MACRO {toms} {"ACM Trans.\ Math.\ Softw."}
MACRO {toois} {"ACM Trans.\ Office Inf.\ Syst."}
MACRO {toplas} {"ACM Trans.\ Prog.\ Lang.\ Syst."}
MACRO {tcs} {"Theoretical Comput.\ Sci."}
MACRO {znat} {"Z.\ Naturforsch."}
MACRO {znata} {"Z.\ Naturforsch.\ A"}
MACRO {znatb} {"Z.\ Naturforsch.\ B"}
MACRO {zp} {"Zeitschr.\ f.\ Phys."}
MACRO {zpa} {"Zeitschr.\ f.\ Phys.\ A"}
MACRO {zpb} {"Zeitschr.\ f.\ Phys.\ B"}
MACRO {zpc} {"Zeitschr.\ f.\ Phys.\ C"}
MACRO {zpch} {"Zeitschr.\ f.\ Phys.\ Chem."}
MACRO {zpd} {"Zeitschr.\ f.\ Phys.\ D"}

%%% -------------------------------------------
%%% *** Jochen's privater Bibliography Style ***
%%% -------------------------------------------
%%%
%%% This is file `jkthesis.bst', generated with the docstrip utility.
%%% and heavily modified to match my taste, Jochen.
%%%
%%% Copyright (C) 1999,2000 Jochen K�pper
%%%
%%
%% The original source files were:
%%
%% merlin.mbs
%% german.mbs
%% physjour.mbs
%% merlin.mbs
 %-------------------------------------------------------------------
 % The original source file contains the following version information:
 % \ProvidesFile{merlin.mbs}[1998/02/25 3.85a (PWD)]
 %
 % NOTICE:
 % This file may be used for non-profit purposes.
 % It may not be distributed in exchange for money,
 %   other than distribution costs.
 %
 % The author provides it `as is' and does not guarantee it in any way.
 %
 % Copyright (C) 1994-98 Patrick W. Daly
 %-------------------------------------------------------------------
 %   For use with BibTeX version 0.99a or later
 %-------------------------------------------------------------------
 % This bibliography style file is intended for texts in
 %   GERMAN
 % This is a numerical citation style, and as such is standard LaTeX.
 % It requires no extra package to interface to the main text.
 % The form of the \bibitem entries is
 %   \bibitem{key}...
 % Usage of \cite is as follows:
 %   \cite{key} ==>>          [#]
 %   \cite[chap. 2]{key} ==>> [#, chap. 2]
 % where # is a number determined by the ordering in the reference list.
 % The order in the reference list is alphabetical by authors.
 %---------------------------------------------------------------------


ENTRY
  { address
    author
    booktitle
    chapter
    edition
    editor
    howpublished
    institution
    journal
    key
    month
    note
    number
    organization
    pages
    publisher
    school
    series
    title
    type
    volume
    year
  }
  {}
  { label }

INTEGERS { output.state before.all mid.sentence after.sentence after.block }

FUNCTION {init.state.consts}
{ #0 'before.all :=
  #1 'mid.sentence :=
  #2 'after.sentence :=
  #3 'after.block :=
}

STRINGS { s t }

FUNCTION {output.nonnull}
{ 's :=
  output.state mid.sentence =
    { ", " * write$ }
    { output.state after.block =
        { add.period$ write$
          newline$
          "\newblock " write$
        }
        { output.state before.all =
            'write$
            { add.period$ " " * write$ }
          if$
        }
      if$
      mid.sentence 'output.state :=
    }
  if$
  s
}

FUNCTION {output.null}
{ 's :=
  write$
  s
}

FUNCTION {output}
{ duplicate$ empty$
    'pop$
    'output.nonnull
  if$
}

FUNCTION {output.check}
{ 't :=
  duplicate$ empty$
    { pop$ "empty " t * " in " * cite$ * warning$ }
    'output.nonnull
  if$
}

FUNCTION {output.null.check}
{ 't :=
  duplicate$ empty$
    { pop$ "empty " t * " in " * cite$ * warning$ }
    'output.null
  if$
}
 
FUNCTION {fin.entry}
{ add.period$
  write$
  newline$
}

FUNCTION {new.block}
{ output.state before.all =
    'skip$
    { after.block 'output.state := }
  if$
}

FUNCTION {new.sentence}
{ output.state after.block =
    'skip$
    { output.state before.all =
        'skip$
        { after.sentence 'output.state := }
      if$
    }
  if$
}

FUNCTION {add.blank}
{  " " * before.all 'output.state :=
}

FUNCTION {date.block}
{
  new.block
}

FUNCTION {not}
{   { #0 }
    { #1 }
  if$
}

FUNCTION {and}
{   'skip$
    { pop$ #0 }
  if$
}

FUNCTION {or}
{   { pop$ #1 }
    'skip$
  if$
}

FUNCTION {new.block.checka}
{ empty$
    'skip$
    'new.block
  if$
}

FUNCTION {new.block.checkb}
{ empty$
  swap$ empty$
  and
    'skip$
    'new.block
  if$
}

FUNCTION {new.sentence.checka}
{ empty$
    'skip$
    'new.sentence
  if$
}

FUNCTION {new.sentence.checkb}
{ empty$
  swap$ empty$
  and
    'skip$
    'new.sentence
  if$
}

FUNCTION {field.or.null}
{ duplicate$ empty$
    { pop$ "" }
    'skip$
  if$
}

FUNCTION {emphasize}
{ duplicate$ empty$
    { pop$ "" }
    { "\emph{" swap$ * "}" * }
  if$
}

FUNCTION {bolden}
{ duplicate$ empty$
    { pop$ "" }
    { "\textbf{" swap$ * "}" * }
  if$
}

FUNCTION {capitalize}
{ "u" change.case$ "t" change.case$ }

FUNCTION {space.word}
{ " " swap$ * " " * }



% Here are the language-specific definitions for explicit words.
% Each function has a name bbl.xxx where xxx is the English word.
%-------------------------------------------------------------------
% The original source file contains the following version information:
% \ProvidesFile{german.mbs}[1995/11/02 1.5 (PWD)]
% Copyright (C) 1994, 1995 Patrick W. Daly
%-------------------------------------------------------------------

FUNCTION {bbl.and}
{ "und"}

FUNCTION {bbl.editors}
{ "Herausgeber" }

FUNCTION {bbl.editor}
{ "Herausgeber" }

FUNCTION {bbl.edby}
{ "herausgegeben von" }

FUNCTION {bbl.edition}
{ "Auf\/lage" }

FUNCTION {bbl.volume}
{ "Band" }

FUNCTION {bbl.of}
{ "von" }

FUNCTION {bbl.number}
{ "Nummer" }

FUNCTION {bbl.nr}
{ "Nr." }

FUNCTION {bbl.in}
{ "in" }

FUNCTION {bbl.pages}
{ "Seiten" }

FUNCTION {bbl.page}
{ "Seite" }

FUNCTION {bbl.chapter}
{ "Kapitel" }

FUNCTION {bbl.techrep}
{ "{Technischer Bericht}" }

FUNCTION {bbl.mthesis}
{ "Diplomarbeit" }

FUNCTION {bbl.phdthesis}
{ "Dissertation" }

FUNCTION {bbl.first}
{ "Erste" }

FUNCTION {bbl.second}
{ "Zweite" }

FUNCTION {bbl.third}
{ "Dritte" }

FUNCTION {bbl.fourth}
{ "Vierte" }

FUNCTION {bbl.fifth}
{ "F\^^b{u}nfte" }

FUNCTION {bbl.th}
{ "." }

% months

MACRO {jan} {"Januar"}
MACRO {feb} {"Februar"}
MACRO {mar} {"M\^^b{a}rz"}
MACRO {apr} {"April"}
MACRO {may} {"Mai"}
MACRO {jun} {"Juni"}
MACRO {jul} {"Juli"}
MACRO {aug} {"August"}
MACRO {sep} {"September"}
MACRO {oct} {"Oktober"}
MACRO {nov} {"November"}
MACRO {dec} {"Dezember"}



% output routines

INTEGERS { nameptr namesleft numnames }

FUNCTION {format.names}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{f{.}{.~}}{vv~}{ll}{, jj}" format.name$
    't :=
      nameptr #1 >
        {
          namesleft #1 >
            { ", " * t * }
            {
              s nameptr "{ll}" format.name$ duplicate$ "others" =
                { 't := }
                { pop$ }
              if$
              t "others" =
                {
                  " et~al. " *
                }
                { bbl.and space.word * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {format.names.ed}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{f.~}{vv~}{ll}{, jj}"
      format.name$
      't :=
      nameptr #1 >
        {
          namesleft #1 >
            { ", " * t * }
            {
              s nameptr "{ll}" format.name$ duplicate$ "others" =
                { 't := }
                { pop$ }
              if$
              t "others" =
                {
                  " et~al." *
                }
                { bbl.and space.word * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {format.authors}
{ author empty$
    { "" }
    { author format.names }
  if$
}

FUNCTION {format.editors}
{ editor empty$
    { "" }
    { editor format.names
      editor num.names$ #1 >
        { ", " * bbl.editors * }
        { ", " * bbl.editor * }
      if$
    }
  if$
}

FUNCTION {format.in.editors}
{ editor empty$
    { "" }
    { editor format.names.ed
    }
  if$
}

FUNCTION {format.note}
{ note empty$
    { "" }
    { note #1 #1 substring$
      duplicate$ "{" =
        'skip$
        { output.state mid.sentence =
          { "l" }
          { "u" }
        if$
        change.case$
        }
      if$
      note #2 global.max$ substring$ *
    }
  if$
}

FUNCTION {format.title}
{ title empty$
    { "" }
    { title
      emphasize
    }
  if$
}

FUNCTION {output.bibitem}
{ newline$
  "\bibitem{" write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}

FUNCTION {if.digit}
{ duplicate$ "0" =
  swap$ duplicate$ "1" =
  swap$ duplicate$ "2" =
  swap$ duplicate$ "3" =
  swap$ duplicate$ "4" =
  swap$ duplicate$ "5" =
  swap$ duplicate$ "6" =
  swap$ duplicate$ "7" =
  swap$ duplicate$ "8" =
  swap$ "9" = or or or or or or or or or
}
FUNCTION {n.separate}
{ 't :=
  ""
  #0 'numnames :=
  { t empty$ not }
  { t #-1 #1 substring$ if.digit
      { numnames #1 + 'numnames := }
      { #0 'numnames := }
    if$
    t #-1 #1 substring$ swap$ *
    t #-2 global.max$ substring$ 't :=
    numnames #5 =
      { duplicate$ #1 #2 substring$ swap$
        #3 global.max$ substring$
        "\," swap$ * *
      }
      'skip$
    if$
  }
  while$
}
FUNCTION {n.dashify}
{
  n.separate
  't :=
  ""
    { t empty$ not }
    { t #1 #1 substring$ "-" =
        { t #1 #2 substring$ "--" = not
            { "--" *
              t #2 global.max$ substring$ 't :=
            }
            {   { t #1 #1 substring$ "-" = }
                { "-" *
                  t #2 global.max$ substring$ 't :=
                }
              while$
            }
          if$
        }
        { t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}

FUNCTION {word.in}
{ bbl.in capitalize
  " " * }

FUNCTION {format.date}
{ year empty$
    { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$
          month
        }
      if$
    }
    { month empty$
        'year
        { month " " * year * }
      if$
    }
  if$
  duplicate$ empty$
    'skip$
    {
      before.all 'output.state :=
    " (" swap$ * ")" *
    }
  if$
}

FUNCTION{format.year}
{ year duplicate$ empty$
    { "empty year in " cite$ * warning$ pop$ "" }
    { "(" swap$ * ")" * }
  if$
}

FUNCTION {format.bookdate}
{ year empty$
    { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$
          month
        }
      if$
    }
    { month empty$
        'year
        { month " " * year * }
      if$
    }
  if$
  duplicate$ empty$
    'skip$
    {
      before.all 'output.state :=
    ", " swap$ * "" *
    }
  if$
}

FUNCTION {format.btitle}
{ title emphasize
}

FUNCTION {tie.or.space.connect}
{ duplicate$ text.length$ #3 <
    { "~" }
    { " " }
  if$
  swap$ * *
}

FUNCTION {either.or.check}
{ empty$
    'pop$
    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  if$
}

FUNCTION {format.bvolume}
{ volume empty$
    { "" }
    { bbl.volume volume tie.or.space.connect
      series empty$
        'skip$
        { bbl.of space.word * series emphasize * }
      if$
      "volume and number" number either.or.check
    }
  if$
}

FUNCTION {format.number.series}
{ volume empty$
    { number empty$
        { series field.or.null }
        { output.state mid.sentence =
            { bbl.number }
            { bbl.number capitalize }
          if$
          number tie.or.space.connect
          series empty$
            { "there's a number but no series in " cite$ * warning$ }
            { bbl.in space.word * series * }
          if$
        }
      if$
    }
    { "" }
  if$
}

FUNCTION {is.num}
{ chr.to.int$
  duplicate$ "0" chr.to.int$ < not
  swap$ "9" chr.to.int$ > not and
}

FUNCTION {extract.num}
{ duplicate$ 't :=
  "" 's :=
  { t empty$ not }
  { t #1 #1 substring$
    t #2 global.max$ substring$ 't :=
    duplicate$ is.num
      { s swap$ * 's := }
      { pop$ "" 't := }
    if$
  }
  while$
  s empty$
    'skip$
    { pop$ s }
  if$
}

FUNCTION {convert.edition}
{ edition extract.num "l" change.case$ 's :=
  s "first" = s "1" = or
    { bbl.first 't := }
    { s "second" = s "2" = or
        { bbl.second 't := }
        { s "third" = s "3" = or
            { bbl.third 't := }
            { s "fourth" = s "4" = or
                { bbl.fourth 't := }
                { s "fifth" = s "5" = or
                    { bbl.fifth 't := }
                    { s #1 #1 substring$ is.num
                        { s bbl.th * 't := }
                        { edition 't := }
                      if$
                    }
                  if$
                }
              if$
            }
          if$
        }
      if$
    }
  if$
  t
}

FUNCTION {format.edition.long}
{ edition empty$
    { "" }
    { output.state mid.sentence =
        { convert.edition "l" change.case$ " " * bbl.edition * }
        { convert.edition "t" change.case$ " " * bbl.edition * }
      if$
    }
  if$
}

FUNCTION {format.edition}
{ edition empty$
    { "" }
    { output.state mid.sentence =
        { edition extract.num "l" change.case$ ". " * bbl.edition * }
        { edition extract.num "t" change.case$ ". " * bbl.edition * }
      if$
    }
  if$
}

INTEGERS { multiresult }

FUNCTION {multi.page.check}
{ 't :=
  #0 'multiresult :=
    { multiresult not
      t empty$ not
      and
    }
    { t #1 #1 substring$
      duplicate$ "-" =
      swap$ duplicate$ "," =
      swap$ "+" =
      or or
        { #1 'multiresult := }
        { t #2 global.max$ substring$ 't := }
      if$
    }
  while$
  multiresult
}

FUNCTION {format.pages}
{ pages empty$
    { "" }
    { pages multi.page.check
        { bbl.pages pages n.dashify tie.or.space.connect }
        { bbl.page pages tie.or.space.connect }
      if$
    }
  if$
}

FUNCTION {format.commapages}
{ ", " output.null
  pages empty$
    { "" }
    { pages multi.page.check
        { bbl.pages pages n.dashify tie.or.space.connect }
        { bbl.page pages tie.or.space.connect }
      if$
    }
  if$
}

FUNCTION {first.page}
{ 't :=
  ""
    {  t empty$ not t #1 #1 substring$ "-" = not and }
    { t #1 #1 substring$ *
      t #2 global.max$ substring$ 't :=
    }
  while$
}

FUNCTION {format.journal.pages}
{ pages empty$
    'skip$
    { duplicate$ empty$
        { pop$ format.pages }
        {
          ", " *
          pages first.page *
        }
      if$
    }
  if$
}

FUNCTION {format.vol.num.pages}
{ " " output.null volume field.or.null
  bolden
  " " output.null format.year *
  format.journal.pages
}

FUNCTION {format.chapter.pages}
{ chapter empty$
    'format.pages
    { type empty$
        { bbl.chapter }
        { type "l" change.case$ }
      if$
      chapter tie.or.space.connect
      pages empty$
        'skip$
        { ", " * format.pages * }
      if$
    }
  if$
}

FUNCTION {format.comma.chapter.pages}
{ ", " output.null
  chapter empty$
    'format.pages
    { type empty$
        { bbl.chapter }
        { type "l" change.case$ }
      if$
      chapter tie.or.space.connect
      pages empty$
        'skip$
        { ", " * format.pages * }
      if$
    }
  if$
}

FUNCTION {format.in.ed.booktitle}
{ booktitle empty$
    { "" }
    { editor empty$
        { word.in booktitle emphasize * }
        { word.in booktitle emphasize *
          ", " *
          bbl.edby
          * " " *
          format.in.editors *
        }
      if$
    }
  if$
}

FUNCTION {empty.misc.check}
{ author empty$ title empty$ howpublished empty$
  month empty$ year empty$ note empty$
  and and and and and
  key empty$ not and
    { "all relevant fields are empty in " cite$ * warning$ }
    'skip$
  if$
}

FUNCTION {format.thesis.type}
{ type empty$
    'skip$
    { pop$
      type "t" change.case$
    }
  if$
}

FUNCTION {format.tr.number}
{ type empty$
    { bbl.techrep }
    'type
  if$
  number empty$
    { "t" change.case$ }
    { number tie.or.space.connect }
  if$
}

FUNCTION {format.article.crossref}
{
  key empty$
    { journal empty$
        { "need key or journal for " cite$ * " to crossref " * crossref *
          warning$
          ""
        }
        { word.in journal emphasize * }
      if$
    }
    { word.in key * " " *}
  if$
  " \cite{" * crossref * "}" *
}

FUNCTION {format.crossref.editor}
{ editor #1 "{vv~}{ll}" format.name$
  editor num.names$ duplicate$
  #2 >
    { pop$
      " et~al." *
    }
    { #2 <
        'skip$
        { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
            {
              " et~al." *
            }
            { bbl.and space.word * editor #2 "{vv~}{ll}" format.name$
              * }
          if$
        }
      if$
    }
  if$
}

FUNCTION {format.book.crossref}
{ volume empty$
    { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
      word.in
    }
    { bbl.volume capitalize
      volume tie.or.space.connect
      bbl.of space.word *
    }
  if$
  editor empty$
  editor field.or.null author field.or.null =
  or
    { key empty$
        { series empty$
            { "need editor, key, or series for " cite$ * " to crossref " *
              crossref * warning$
              "" *
            }
            { series emphasize * }
          if$
        }
        { key * }
      if$
    }
    { format.crossref.editor * }
  if$
  " \cite{" * crossref * "}" *
}

FUNCTION {format.incoll.inproc.crossref}
{
  editor empty$
  editor field.or.null author field.or.null =
  or
    { key empty$
        { booktitle empty$
            { "need editor, key, or booktitle for " cite$ * " to crossref " *
              crossref * warning$
              ""
            }
            { word.in booktitle emphasize * }
          if$
        }
        { word.in key * " " *}
      if$
    }
    { word.in format.crossref.editor * " " *}
  if$
  " \cite{" * crossref * "}" *
}

FUNCTION {format.publisher}
{ publisher empty$
    { "empty publisher in " cite$ * warning$ }
    'skip$
  if$
  ""
  address empty$ publisher empty$ and
    'skip$
    {
      publisher empty$
        { address empty$
          'skip$
          { address * }
          if$
        }
        { publisher *
          address empty$
            'skip$
            { ", " * address * }
          if$
        }
      if$
    }
  if$
  output
}

FUNCTION {article}
{ output.bibitem
  format.authors "author" output.null.check ", " output.null
  new.block
  crossref missing$
    { journal
      emphasize
      "journal" output.null.check " " output.null
      format.vol.num.pages output
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
  new.block
  format.note output
  fin.entry
}

FUNCTION {book}
{ output.bibitem
  author empty$
    { format.editors "author and editor" output.check
    }
    { format.authors output.null ": " output.null
      crossref missing$
        { "author and editor" editor either.or.check }
        'skip$
      if$
    }
  if$
  new.block
  format.btitle "title" output.check
  crossref missing$
    { format.bvolume output
      new.block
      format.number.series output
      format.edition output
      new.sentence
      format.publisher
    }
    {
      new.block
      format.book.crossref output.nonnull
    }
  if$
  format.bookdate "year" output.check
  new.block
  format.note output
  fin.entry
}

FUNCTION {booklet}
{ output.bibitem
  format.authors output
  new.block
  format.title "title" output.check
  new.block
  howpublished output
  address output
  format.date output
  new.block
  format.note output
  fin.entry
}

FUNCTION {inbook}
{ output.bibitem
  author empty$
    { format.editors "author and editor" output.check
    }
    { format.authors output.nonnull
      crossref missing$
        { "author and editor" editor either.or.check }
        'skip$
      if$
    }
  if$
  new.block
  format.btitle "title" output.check
  crossref missing$
    {
      format.bvolume output
      new.block
      format.number.series output
      format.edition output
      new.sentence
      format.publisher
    }
    {
      new.block
      format.book.crossref output.nonnull
    }
  if$
  format.bookdate "year" output.check
  new.block
  format.chapter.pages "pages" output.check
  new.block
  format.note output
  fin.entry
}

FUNCTION {incollection}
{ output.bibitem
  format.authors "author" output.check
  new.block
  crossref missing$
    { format.in.ed.booktitle "booktitle" output.check
      format.bvolume output
      format.number.series output
      format.edition output
      new.sentence
      format.publisher
    }
    { format.incoll.inproc.crossref output.nonnull
    }
  if$
  format.date "year" output.check
  format.commapages "pages" output.null.check
  new.block
  format.note output
  fin.entry
}

FUNCTION {inproceedings}
{ output.bibitem
  format.authors output.null ": " output.null
  new.block
  format.title "title" output.check
  new.block
  crossref missing$
    { format.btitle "title" output.check
      format.in.ed.booktitle "booktitle" output.check
      format.bvolume output
      format.number.series output.null "." output.null
      new.sentence
      publisher empty$
        { organization output
          address output
        }
        { organization output
          format.publisher
        }
      if$
    }
    { format.incoll.inproc.crossref output.nonnull
      format.pages output
    }
  if$
  format.date "year" output.check
  date.block
  pages missing$
    {
    }
    {  add.blank
       format.pages "pages" output.check
       new.block
    }
  if$
  format.note output
  fin.entry
}

FUNCTION {conference} { inproceedings }

FUNCTION {manual}
{ output.bibitem
  author empty$
    { organization empty$
        'skip$
        { organization output.nonnull
          address output
        }
      if$
    }
    { format.authors output.nonnull }
  if$
  new.block
  format.btitle "title" output.check
  author empty$
    { organization empty$
    {
          address new.block.checka
          address output
        }
        'skip$
      if$
    }
    {
      organization address new.block.checkb
      organization output
      address output
    }
  if$
  format.edition output
  format.date output
  new.block
  format.note output
  fin.entry
}

FUNCTION {mastersthesis}
{ output.bibitem
  format.authors "author" output.check ":" output.null
  add.blank
  title empty$
    { }
    { new.block
      format.btitle "title" output.check
      new.block
    }
  if$
  address output
  school "school" output.check
  bbl.mthesis format.thesis.type output.nonnull
  format.bookdate "year" output.check
  new.block
  format.note output
  fin.entry
}

FUNCTION {misc}
{ output.bibitem
  format.authors output
  title howpublished new.block.checkb
  format.title output
  howpublished new.block.checka
  howpublished output
  format.bookdate "year" output.check
  new.block
  format.note output
  fin.entry
  empty.misc.check
}

FUNCTION {phdthesis}
{ output.bibitem
  format.authors output.null ": " output.null
  title empty$
    { }
    { new.block
      format.btitle "title" output.check
      new.block
    }
  if$
  address output
  school "school" output.check
  bbl.phdthesis format.thesis.type output.nonnull
  format.bookdate "year" output.check
  new.block
  format.note output
  fin.entry
}

FUNCTION {proceedings}
{ output.bibitem
  editor empty$
    { organization output }
    { format.editors output.nonnull }
  if$
  new.block
  format.btitle "title" output.check
  format.bvolume output
  format.number.series output
  address empty$
    { editor empty$
        { publisher new.sentence.checka }
        { organization publisher new.sentence.checkb
          organization output
        }
      if$
      publisher output
      format.date "year" output.check
    }
    { address output.nonnull
      format.date "year" output.check
      new.sentence
      editor empty$
        'skip$
        { organization output }
      if$
      publisher output
    }
  if$
  new.block
  format.note output
  fin.entry
}

FUNCTION {techreport}
{ output.bibitem
  format.authors "author" output.check
  new.block
  format.title "title" output.check
  new.block
  format.tr.number output.nonnull
  institution "institution" output.check
  address output
  format.bookdate "year" output.check
  new.block
  format.note output
  fin.entry
}

FUNCTION {unpublished}
{ output.bibitem
  format.authors "author" output.check
  new.block
  format.title "title" output.check
  format.date output
  new.block
  format.note "note" output.check
  fin.entry
}

FUNCTION {default.type} { misc }

READ

FUNCTION {sortify}
{ purify$
  "l" change.case$
}

INTEGERS { len }

FUNCTION {chop.word}
{ 's :=
  'len :=
  s #1 len substring$ =
    { s len #1 + global.max$ substring$ }
    's
  if$
}

FUNCTION {sort.format.names}
{ 's :=
  #1 'nameptr :=
  ""
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{ll{ }}{  f{ }}{  jj{ }}"
      format.name$ 't :=
      nameptr #1 >
        {
          "   "  *
          namesleft #1 = t "others" = and
            { "zzzzz" * }
            { t sortify * }
          if$
        }
        { t sortify * }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {sort.format.title}
{ 't :=
  "A " #2
    "An " #3
      "The " #4 t chop.word
    chop.word
  chop.word
  sortify
  #1 global.max$ substring$
}

FUNCTION {author.sort}
{ author empty$
    { key empty$
        { "to sort, need author or key in " cite$ * warning$
          ""
        }
        { key sortify }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {author.editor.sort}
{ author empty$
    { editor empty$
        { key empty$
            { "to sort, need author, editor, or key in " cite$ * warning$
              ""
            }
            { key sortify }
          if$
        }
        { editor sort.format.names }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {author.organization.sort}
{ author empty$
    { organization empty$
        { key empty$
            { "to sort, need author, organization, or key in " cite$ * warning$
              ""
            }
            { key sortify }
          if$
        }
        { "The " #4 organization chop.word sortify }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {editor.organization.sort}
{ editor empty$
    { organization empty$
        { key empty$
            { "to sort, need editor, organization, or key in " cite$ * warning$
              ""
            }
            { key sortify }
          if$
        }
        { "The " #4 organization chop.word sortify }
      if$
    }
    { editor sort.format.names }
  if$
}

FUNCTION {presort}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
        'editor.organization.sort
        { type$ "manual" =
            'author.organization.sort
            'author.sort
          if$
        }
      if$
    }
  if$
  "    "
  *
  year field.or.null sortify
  *
  "    "
  *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}

ITERATE {presort}

SORT

STRINGS { longest.label }

INTEGERS { number.label longest.label.width }

FUNCTION {initialize.longest.label}
{ "" 'longest.label :=
  #1 'number.label :=
  #0 'longest.label.width :=
}

FUNCTION {longest.label.pass}
{ number.label int.to.str$ 'label :=
  number.label #1 + 'number.label :=
  label width$ longest.label.width >
    { label 'longest.label :=
      label width$ 'longest.label.width :=
    }
    'skip$
  if$
}

EXECUTE {initialize.longest.label}

ITERATE {longest.label.pass}

FUNCTION {begin.bib}
{ preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  "\begin{thebibliography}{"  longest.label  * "}" *
  write$ newline$
}

EXECUTE {begin.bib}

EXECUTE {init.state.consts}

ITERATE {call.type$}

FUNCTION {end.bib}
{ newline$
  "\end{thebibliography}" write$ newline$
}

EXECUTE {end.bib}