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

 CITATION_REQUEST:
 AUTHOR: Author Name
 TITLE: A 2nd paper
 JOURNAL: Jounral wth a short name
 VOL: V
 NUM: N
 YEAR: 2013
 PAGE: 1-10

 A CITATION_REQUEST block is terminated by an empty line. 
 The order of fields is irrelevant. All fields are optional.
 Multiple CITATION_REQUEST blocks are 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 % CITATION_REQUEST:
0027 % AUTHOR: Author Name
0028 % TITLE: A 2nd paper
0029 % JOURNAL: Jounral wth a short name
0030 % VOL: V
0031 % NUM: N
0032 % YEAR: 2013
0033 % PAGE: 1-10
0034 %
0035 % A CITATION_REQUEST block is terminated by an empty line.
0036 % The order of fields is irrelevant. All fields are optional.
0037 % Multiple CITATION_REQUEST blocks are supported.
0038 %
0039 % See also STARTUP
0040 if ischar(fname) && strcmp(fname, 'UNIT_TEST')
0041     citeme(mfilename);
0042     return;
0043 end
0044 cm = warning('query','EIDORS:CITEME'); % one would think this is supported
0045 cf = warning('query',sprintf('EIDORS:CITEME:%s',fname));
0046 if strcmp(cm.state, 'off') || strcmp(cf.state, 'off');
0047     return
0048 end
0049 h = help(fname);
0050 s = strfind(h,'CITATION_REQUEST:');
0051 if isempty(s), return, end;
0052 T = textscan(h(s(1):end),'%s','delimiter','\n');
0053 T = T{1};
0054 starts = 1;
0055 if numel(s) > 1
0056    starts = find(strcmp(T, 'CITATION_REQUEST:'));
0057 end
0058 empty_lines = find(cellfun(@isempty,T));
0059 if numel(empty_lines) < numel(starts)
0060    %happens if the CITATION_REQUEST runs to the end of T (no empty line)
0061    empty_lines(end+1) = numel(T);
0062 end
0063 s = s - s(1) + 1;
0064 for i = 1:numel(s)
0065    block = T(starts(i):empty_lines(find(empty_lines>starts(i), 1, 'first')));
0066    citation{i} = parse_block(block);
0067 end
0068 
0069 str = sprintf('\n%s\n',citation{:});
0070 
0071 ws = warning('off', 'backtrace');
0072 idstr = sprintf('EIDORS:CITEME:%s',fname);
0073 stars(1:80) = '=';
0074 msg = sprintf('\n%s\nIf you use %s in a publication, please cite:\n', stars,upper(fname));
0075 warning(idstr,[msg str stars]);
0076 if 0
0077    disp('Press any key to continue...');
0078    pause
0079 else
0080    fprintf('Continuing in  ');
0081    for i = 2:-1:1
0082       fprintf('\b%d',i);
0083       pause(1);
0084    end
0085    fprintf('\b0\n');
0086 end
0087 warning(ws.state, 'backtrace');
0088 if ~strcmp(fname,'citeme')
0089     warning('off',idstr); % only show once per session
0090 end
0091 
0092 function str = parse_block(T)
0093 line = 2;
0094 lastfld = [];
0095 cite = empty_cite;
0096 while line <= numel(T) && ~isempty(strtrim(T{line}))
0097     [tok rest] = strtok(T{line});
0098     if strfind(tok,':');
0099             fld = lower(tok(1:end-1));
0100             cite.(fld) = strtrim(rest);
0101             lastfld = fld;
0102     elseif ~isempty(lastfld)
0103         cite.(lastfld) = sprintf('%s %s%s', cite.(lastfld), tok, rest);
0104     else
0105         error('Error processing citation request of file %s',fname);
0106     end
0107     line = line + 1;
0108 end
0109 flds = {'link','pdf','pubmed','arxiv','doi'};
0110 for i = 1:numel(flds)
0111     cite.(flds{i})(isspace(cite.(flds{i}))) = [];
0112 end
0113 str = pretty_print(cite);
0114  
0115 function str = pretty_print(cite)
0116 str = sprintf('%s (%s) "%s"',...
0117     cite.author,cite.year,cite.title);
0118 
0119 if ~isempty(cite.link)
0120     str = sprintf('%s <a href="matlab: web %s -browser">%s</a>%s', str, cite.link, cite.journal);
0121 else
0122     str = sprintf('%s %s',str, cite.journal);
0123 end
0124 
0125 if ~isempty(cite.vol)
0126     str = sprintf('%s %s',str,cite.vol);
0127 end
0128 if ~isempty(cite.num)
0129     if ~isempty(cite.vol)
0130         str = sprintf('%s(%s)',str, cite.num);
0131     else
0132         str = sptrinf('%s %s',str, cite.num);
0133     end
0134 end
0135 if ~isempty(cite.page)
0136     str = sprintf('%s: %s',str, cite.page);
0137 end
0138 if ~isempty(cite.pdf)
0139     str = sprintf('%s <a href="matlab: web %s -browser">PDF</a>',str, cite.pdf);
0140 end
0141 if ~isempty(cite.doi)
0142     str = sprintf('%s DOI:<a href="matlab: web http://dx.doi.org/%s -browser">%s</a>',...
0143                     str, cite.doi,cite.doi);
0144 end
0145 if ~isempty(cite.pubmed)
0146     str = sprintf('%s PubMed:<a href="matlab: web http://www.ncbi.nlm.nih.gov/pubmed/%s -browser">%s</a>',...
0147                     str, cite.pubmed,cite.pubmed);
0148 end
0149 
0150 if ~isempty(cite.arxiv)
0151     str = sprintf('%s arXiv:<a href="matlab: web http://arxiv.org/abs/%s -browser">%s</a>',...
0152                     str, cite.doi,cite.doi);
0153 end
0154 
0155 str = strtrim(str);                
0156 sp = strfind(str,' ');
0157 tp1 = strfind(str,'<');
0158 tp2 = strfind(str,'>');
0159 sp = [sp length(str)];
0160 
0161 rsp = sp; % real spaces
0162 idx = false(size(sp));
0163 for i = 1:length(tp1)
0164     nidx =  rsp>tp1(i) & rsp<tp2(i);
0165     idx = idx | nidx;
0166     sp(rsp>tp1(i)) = sp(rsp>tp1(i)) - (tp2(i) + 2- tp1(i));
0167 end
0168 sp(idx) = [];
0169 rsp(idx) = [];
0170 
0171 [jnk, nl] = unique(floor(sp/82),'last');
0172 nl = rsp(nl);
0173 nl(nl==length(str)) = [];
0174 str(nl) = sprintf('\n');
0175 
0176 
0177 
0178 function cite = empty_cite
0179 cite.author = [];
0180 cite.year   = [];
0181 cite.journal= [];
0182 cite.title  = [];
0183 cite.vol    = [];
0184 cite.num    = [];
0185 cite.page   = [];
0186 cite.link   = [];
0187 cite.pdf    = [];
0188 cite.doi    = [];
0189 cite.pubmed = [];
0190 cite.arxiv  = [];

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005