citeme

PURPOSE ^

CITEME Display citation requests

SYNOPSIS ^

function citeme(fname)

DESCRIPTION ^

CITEME Display citation requests
 Processes CITATION_REQUEST blocks in the first comment block of a
 function. Must be called at citeme(mfilename). 
 Citation requests are displayed only once per session, and look like
 this:

 CITATION_REQUEST:
 AUTHOR: Author Name, Author Name, Author Name, Author Name, Author Name, 
 Author Name and Author Name
 TITLE: A very long and complicated title that necessarily goes over 
 several lines
 JOURNAL: A renowned international journal that is so full of itself that 
 its name is very long
 VOL: V
 NUM: N
 YEAR: 2013
 PAGE: 1-10
 LINK: http://www.journal-website.com/dir/dir/some_strange_numbers_and_
       letters_that_goes_over_several_lines
 PDF: ftp://myserver.com/paper1.pdf
 DOI: 1234/qwre/123
 PUBMED: 12321345
 ARXIV:  0706.0001

 A CITATION_REQUEST block is terminated by an empty line. 
 The order of fields is irrelevant. All fields are optional.
 At the moment, only one CITATION_REQUEST block per file is supported.

 See also STARTUP

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function citeme(fname)
0002 %CITEME Display citation requests
0003 % Processes CITATION_REQUEST blocks in the first comment block of a
0004 % function. Must be called at citeme(mfilename).
0005 % Citation requests are displayed only once per session, and look like
0006 % this:
0007 %
0008 % CITATION_REQUEST:
0009 % AUTHOR: Author Name, Author Name, Author Name, Author Name, Author Name,
0010 % Author Name and Author Name
0011 % TITLE: A very long and complicated title that necessarily goes over
0012 % several lines
0013 % JOURNAL: A renowned international journal that is so full of itself that
0014 % its name is very long
0015 % VOL: V
0016 % NUM: N
0017 % YEAR: 2013
0018 % PAGE: 1-10
0019 % LINK: http://www.journal-website.com/dir/dir/some_strange_numbers_and_
0020 %       letters_that_goes_over_several_lines
0021 % PDF: ftp://myserver.com/paper1.pdf
0022 % DOI: 1234/qwre/123
0023 % PUBMED: 12321345
0024 % ARXIV:  0706.0001
0025 %
0026 % A CITATION_REQUEST block is terminated by an empty line.
0027 % The order of fields is irrelevant. All fields are optional.
0028 % At the moment, only one CITATION_REQUEST block per file is supported.
0029 %
0030 % See also STARTUP
0031 if ischar(fname) && strcmp(fname, 'UNIT_TEST')
0032     citeme(mfilename);
0033     return;
0034 end
0035 cm = warning('query','EIDORS:CITEME'); % one would think this is supported
0036 cf = warning('query',sprintf('EIDORS:CITEME:%s',fname));
0037 if strcmp(cm.state, 'off') || strcmp(cf.state, 'off');
0038     return
0039 end
0040 h = help(fname);
0041 s = strfind(h,'CITATION_REQUEST:');
0042 if isempty(s), return, end;
0043 T = textscan(h(s:end),'%s','delimiter','\n');
0044 T = T{1};
0045 line = 2;
0046 lastfld = [];
0047 cite = empty_cite;
0048 while line <= numel(T) && ~isempty(strtrim(T{line}))
0049     [tok rest] = strtok(T{line});
0050     if strfind(tok,':');
0051             fld = lower(tok(1:end-1));
0052             cite.(fld) = strtrim(rest);
0053             lastfld = fld;
0054     elseif ~isempty(lastfld)
0055         cite.(lastfld) = sprintf('%s %s%s', cite.(lastfld), tok, rest);
0056     else
0057         error('Error processing citation request of file %s',fname);
0058     end
0059     line = line + 1;
0060 end
0061 flds = {'link','pdf','pubmed','arxiv','doi'};
0062 for i = 1:numel(flds)
0063     cite.(flds{i})(isspace(cite.(flds{i}))) = [];
0064 end
0065 pretty_print(cite,fname);
0066  
0067 function str = pretty_print(cite, fname)
0068 str = sprintf('%s (%s) "%s"',...
0069     cite.author,cite.year,cite.title);
0070 
0071 if ~isempty(cite.link)
0072     str = sprintf('%s <a href="matlab: web %s -browser">%s</a>%s', str, cite.link, cite.journal);
0073 else
0074     str = sprintf('%s %s',str, cite.journal);
0075 end
0076 
0077 if ~isempty(cite.vol)
0078     str = sprintf('%s %s',str,cite.vol);
0079 end
0080 if ~isempty(cite.num)
0081     if ~isempty(cite.vol)
0082         str = sprintf('%s(%s)',str, cite.num);
0083     else
0084         str = sptrinf('%s %s',str, cite.num);
0085     end
0086 end
0087 if ~isempty(cite.page)
0088     str = sprintf('%s: %s',str, cite.page);
0089 end
0090 if ~isempty(cite.pdf)
0091     str = sprintf('%s <a href="matlab: web %s -browser">PDF</a>',str, cite.pdf);
0092 end
0093 if ~isempty(cite.doi)
0094     str = sprintf('%s DOI:<a href="matlab: web http://dx.doi.org/%s -browser">%s</a>',...
0095                     str, cite.doi,cite.doi);
0096 end
0097 if ~isempty(cite.pubmed)
0098     str = sprintf('%s PubMed:<a href="matlab: web http://www.ncbi.nlm.nih.gov/pubmed/%s -browser">%s</a>',...
0099                     str, cite.doi,cite.doi);
0100 end
0101 
0102 if ~isempty(cite.arxiv)
0103     str = sprintf('%s arXiv:<a href="matlab: web http://arxiv.org/abs/%s -browser">%s</a>',...
0104                     str, cite.doi,cite.doi);
0105 end
0106 
0107 str = strtrim(str);                
0108 sp = strfind(str,' ');
0109 tp1 = strfind(str,'<');
0110 tp2 = strfind(str,'>');
0111 sp = [sp length(str)];
0112 
0113 rsp = sp; % real spaces
0114 idx = false(size(sp));
0115 for i = 1:length(tp1)
0116     nidx =  rsp>tp1(i) & rsp<tp2(i);
0117     idx = idx | nidx;
0118     sp(rsp>tp1(i)) = sp(rsp>tp1(i)) - (tp2(i) + 2- tp1(i));
0119 end
0120 sp(idx) = [];
0121 rsp(idx) = [];
0122 
0123 [jnk, nl] = unique(floor(sp/82),'last');
0124 nl = rsp(nl);
0125 nl(nl==length(str)) = [];
0126 str(nl) = sprintf('\n');
0127 
0128 ws = warning('off', 'backtrace');
0129 idstr = sprintf('EIDORS:CITEME:%s',fname);
0130 stars(1:80) = '=';
0131 msg = sprintf('\n%s\nIf you use %s in a publication, please cite:\n', stars,upper(fname));
0132 warning(idstr,[msg str '\n' stars]);
0133 if 0
0134    disp('Press any key to continue...');
0135    pause
0136 else
0137    fprintf('Continuing in  ');
0138    for i = 2:-1:1
0139       fprintf('\b%d',i);
0140       pause(1);
0141    end
0142    fprintf('\b0\n');
0143 end
0144 warning(ws.state, 'backtrace');
0145 if ~strcmp(fname,'citeme')
0146     warning('off',idstr); % only show once per session
0147 end
0148 
0149 function cite = empty_cite
0150 cite.author = [];
0151 cite.year   = [];
0152 cite.journal= [];
0153 cite.title  = [];
0154 cite.vol    = [];
0155 cite.num    = [];
0156 cite.page   = [];
0157 cite.link   = [];
0158 cite.pdf    = [];
0159 cite.doi    = [];
0160 cite.pubmed = [];
0161 cite.arxiv  = [];

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005