function pubcit(CITCELL,reg_expr)
% PUBCIT(CITCELL,reg_expr)
%
% Publish citation.
% Prints on the screen and saves in html format a list
% of references formatted following the regular
% expression "reg_expr".
% CITCELL is a citation entry or a cell of citation
% entries. Each citation entry is a structure:
%
% cit.Title: title of the paper
% cit.Prename: cell of the forenames of the authors
% cit.Name: cell of the family names of the authors
% cit.Journal: Journal name
% cit.Volume: Volume number (char string)
% cit.Issue: Issue number (char string)
% cit.Page: pages array, es. [435 440]
% cit.Year: year of publication (char string)
%
% The regular expression reg_expr is a string that
% can be constructed by using the following tags:
%
% '@PI@': prename initial
% '@CP@': complete prename
% '@FN@': family name
% '@JO@': name of the journal
% '@VO@': volume
% '@IS@': issue
% '@TI@': title of the paper
% '@YE@': year
% '@PA@': first page
% '@PP@': pages, separated by '-'
%
% The references are finally saved in a html file. To
% obtain bolded or italic characters, simply insert
% the corresponding html tags in the regular expression.
% You can copy the formatted output from your browser
% and paste it into your word processor.
%
% ------------------------------------------------------
% (c) 2006 Iari-Gabriel Marino
% <iari-gabriel.marino@fis.unipr.it>
% http://www.fis.unipr.it/home/marino/
% ------------------------------------------------------
%
% Example 1:
%
% cit1.Title = 'A Matlab script for references handling';
% cit1.Prename{1} = 'Iari-Gabriel';
% cit1.Prename{2} = 'Enrico';
% cit1.Famname{1} = 'Marino';
% cit1.Famname{2} = 'Atti';
% cit1.Journal = 'Matl. Rev.';
% cit1.Volume = '100(3)';
% cit1.Issue = '5';
% cit1.Page = [1817 1845];
% cit1.Year = '2000';
% pubcit(cit1,'@PI@. @FN@, @JO@, Vol. @VO@ (@YE@).');
%
% Example 2 (follows from Example 1):
%
% cit2.Title = 'Handling references revised';
% cit2.Prename{1} = 'Iari-Gabriel';
% cit2.Famname{1} = 'Marino';
% cit2.Journal = 'J. of Matl. Res.';
% cit2.Volume = '76';
% cit2.Issue = '1';
% cit2.Page = [181 145];
% cit2.Year = '2003';
%
% CITCELL{1} = cit1;
% CITCELL{2} = cit2;
%
% pubcit(CITCELL,'@FN@, @PI@; <i>@JO@</i>, <b>@VO@</b>, @IS@ (@YE@) @PP@.')
for k=1:length(CITCELL)
if iscell(CITCELL) % is a cell of entries
cit = CITCELL{k};
else % is an entry
cit = CITCELL;
end
outstr = reg_expr;
% finds the last data referring to names
PI_pos = strfind(outstr,'@PI@');
CP_pos = strfind(outstr,'@CP@');
FN_pos = strfind(outstr,'@FN@');
CP = max([PI_pos CP_pos FN_pos]) + 4; % cut position
authors_str = auth(cit,outstr(1:CP));
outstr = [authors_str outstr(CP+2:end)];
outstr = strrep(outstr,'@TI@',cit.Title);
outstr = strrep(outstr,'@JO@',cit.Journal);
outstr = strrep(outstr,'@VO@',cit.Volume);
outstr = strrep(outstr,'@IS@',cit.Issue);
outstr = strrep(outstr,'@YE@',cit.Year);
outstr = strrep(outstr,'@PA@',num2str(cit.Page(1)));
outstr = strrep(outstr,'@PP@',[num2str(cit.Page(1)) '-' num2str(cit.Page(2))]);
disp(outstr)
str_list{k} = outstr;
end
% Saves in a html file:
html_name = 'references.html';
fid = fopen(html_name,'w');
fprintf(fid,'%s \n','<html>');
fprintf(fid,'%s \n','<head>');
fprintf(fid,'%s \n','<title>References</title>');
fprintf(fid,'%s \n','</head>');
fprintf(fid,'%s \n','<body>');
%------------------------------
for k=1:length(str_list)
fprintf(fid,'%s \n',['<p>' str_list{k} '</p>']);
end
%------------------------------
fprintf(fid,'%s \n','</body>');
fclose(fid);
close('all');
% SUBS ####################################
function out = auth(cit,str)
% Construction of the string with the names of the Authors
out = '';
for k=1:length(cit.Prename),
space_ind = strfind(cit.Prename{k},' ');
minus_ind = strfind(cit.Prename{k},'-');
if not(isempty(space_ind)),
initPrename = [cit.Prename{k}(1) '. ' cit.Prename{k}(space_ind+1)];
elseif not(isempty(minus_ind)),
initPrename = [cit.Prename{k}(1) '.-' cit.Prename{k}(minus_ind+1)];
else % nome singolo normale
initPrename = [cit.Prename{k}(1)];
end
temp = str;
temp = strrep(temp,'@PI@',initPrename);
temp = strrep(temp,'@CP@',cit.Prename{k});
temp = strrep(temp,'@FN@',cit.Famname{k});
out = [out temp ' '];
end