#!/usr/bin/perl
# process list of bibliographical references --> labintel
#print STDOUT "
";
# labintel type codes for each publication type:
$labtype{1}='PUB';
$labtype{2}='OUV';
$labtype{3}='OUV';
$labtype{4}='OUV';
$labtype{5}='COM';
$labtype{6}='COM';
$labtype{7}='COM';
$labtype{8}='AUT';
$labtype{9}='AUT';
$labtype{10}='ART';
$labtype{11}='AUT';
$labtype{12}='BRE';
$refnum=0;
while () {
chop;
# load fields of record
$x="";
if (($x) = /^%0\s*(.*)/) {$type=$x;}
if (($x) = /^%1\s*(.*)/) {$labintel=$x;}
if (($x) = /^%A\s*(.*)/) {@authors= (@authors, $x);}
if (($x) = /^%E\s*(.*)/) {@editors= (@editors, $x);}
if (($x) = /^%P\s*(.*)/) {$pages=$x;}
if (($x) = /^%@\s*(.*)/) {$pages=$x;} # "report number"
if (($x) = /^%D\s*(.*)/) {$date=$x;}
if (($x) = /^%T\s*(.*)/) {$title=$x;}
if (($x) = /^%B\s*(.*)/) {$book=$x;}
#if (($x) = /^%J\s*(.*)/) {$journal=$x;}
if (($x) = /^%C\s*(.*)/) {$city=$x;}
if (($x) = /^%I\s*(.*)/) {$inst=$x;}
if (($x) = /^%9\s*(.*)/) {$xxx=$x;}
if (($x) = /^%K\s*(.*)/) {$key=$x;}
if (($x) = /^%V\s*(.*)/) {$vol=$x;}
if (($x) = /^%N\s*(.*)/) {$num=$x;}
if (($x) = /^%F\s*(.*)/) {$label=$x;}
if (($x) = /^%9\s*(.*)/) {$tow=$x;} # type of work
if (($x) = /^%2\s*(.*)/) {$url=$x;}
if (($x) = /^%U\s*(.*)/) {$url=$x;}
# end of record: format and load into list
if (/^\s?$/) { # end of entry
$labintel=$labtype{$labintel};
$prefix = '';
$suffix = '';
$refnum++;
$author = join ", ", @authors;
$editor = join ", ", @editors;
# store to allow sorting by author or date
$authors[$refnum]=$author;
$dates[$refnum]=$date;
# $title = "\"". $title . "\"";
$author = $author . " ";
$date = ". " . $date . ". ";
if ($pages) {$pages = ", pp. " . $pages;}
# assemble fields according to publication type
if ($type eq 'Journal Article' | $type eq 'Magazine Article') {
if ($book) {$book = ", " . $book;}
if ($vol) {$vol = " " . $vol;}
$entry = $author . $title . $book . $date . $vol . $pages;
#print $entry, "\n";
} elsif ($type eq 'Book Section') {
if ($book) {$book = ", In: " . $book;}
if ($vol) {$vol = " " . $vol;}
if ($editor) {$editor = ", Edited by: " . $editor; }
if ($city) {$city = ", " . $city;}
if ($inst) { if ($city) {$inst = ": " . $inst;} else {$inst = ", " . $inst;} }
if ($url) {$url = " [".$url."]";}
$entry = $author . $title . $book . $editor . $city . $inst . $date . $vol . $pages ;
#print $entry, "\n";
} elsif ($type eq 'Thesis') {
if ($inst) { $inst = ", Thesis: " . $inst;}
if ($book) { $book = ", " . $book; }
if ($city) { $city = ", " . $city;}
if ($tow) {$tow = " (" . $tow . ")";}
if ($url) {$url = " [".$url."]";}
$entry = $author . $title . $inst . $book . $city . $tow . $date;
#print $entry, "\n";
} elsif ($type eq 'Conference Proceedings') {
if ($book) {$book = ", " . $book;}
if ($vol) {$vol = " " . $vol;}
if ($editor) {$editor = ", Edited by: " . $editor; }
if ($city) {$city = ", " . $city;}
if ($url) {$url = " [".$url."]";}
if ($inst) { if ($city) {$inst = ": " . $inst;} else {$inst = ", " . $inst . $url;} }
$entry = $author . $title . $book . $inst . $city . $tow . $date . $pages;
#print $entry, "\n";
} elsif ($type eq 'Edited Book') {
if ($book) {$book = " (" . $book . ")";}
if ($vol) {$vol = " " . $vol;}
if ($editor) {$editor = ", Edited by: " . $editor; }
if ($city) {$city = ", " . $city;}
if ($inst) { if ($city) {$inst = ": " . $inst;} else {$inst = ", " . $inst;} }
if ($url) {$url = " [".$url."]";}
$entry = $author . $title . $book . $vol . $editor . $city . $inst . $date . $pages ;
#print $entry, "\n";
} elsif ($type eq 'Generic') {
if ($url) {$url = " [".$url."]";}
$entry = $author . $date . $title . $book . $vol . $pages . "." . $url;
#print $entry, "\n";
} elsif ($type eq 'Report') {
if ($tow) {$tow = " (" . $tow . ")";} else {$tow = " (Technical Report)";}
if ($city) {$city = ", " . $city;}
if ($inst) { if ($city) {$inst = ": " . $inst;} else {$inst = ", " . $inst;} }
if ($url) {$url = " [".$url."]";}
$entry = $author . $title . $city . $inst . $date . $pages . $tow;
#print $entry, "\n";
} elsif ($type eq 'Patent') {
if ($tow) {$tow = " (" . $tow . ")";} else {$tow = " (Patent)";}
if ($city) {$city = ", " . $city;}
if ($inst) { if ($city) {$inst = ": " . $inst;} else {$inst = ", " . $inst;} }
if ($url) {$url = " [".$url."]";}
$entry = $author . $title . $city . $inst . $date . $pages . $tow;
#print $entry, "\n";
} else {
if ($type) {print STDERR "pub2lab says unexpected type: ", $type, "\n";}
}
$entry = $prefix . $entry . $suffix;
if ($inrecord) {
# store bibliographic entry in list
$reflist[$refnum] = "\n" . $entry . "\n";
push (@indexlist, $refnum);
}
# clear variables
$type="";
@authors=();
@editors=();
$pages="";
$date="";
$title="";
$book="";
$journal="";
$city="";
$inst="";
$xxx="";
$key="";
$vol="";
$city="";
$tow = "";
$inrecord = 0;
$url = "";
} else { $inrecord = 1;}
}
sub bydate {$dates[$b] <=> $dates[$a]}
@indexlist = sort bydate @indexlist;
foreach $i (@indexlist) {
$date = $dates[$i];
# if ($date =~ /\d+/) {
# if ($date != $lastdate) { print STDOUT " ". $date, "
\n";}
# } else {
# if (!$flag) { print STDOUT " In press
\n"; $flag = 1;}
# }
print STDOUT $reflist[$i];
$lastdate = $date;
}
#print STDOUT "
\n";