32#include "../base/base_uses.f90"
47 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'reference_manager'
50 INTEGER,
PARAMETER :: max_reference = 1024
54 CHARACTER(LEN=default_string_length),
DIMENSION(:),
ALLOCATABLE :: authors
55 CHARACTER(LEN=:),
ALLOCATABLE :: title
56 CHARACTER(LEN=:),
ALLOCATABLE :: source
57 CHARACTER(LEN=:),
ALLOCATABLE :: volume
58 CHARACTER(LEN=:),
ALLOCATABLE :: pages
60 CHARACTER(LEN=:),
ALLOCATABLE :: doi
62 LOGICAL :: is_cited = .false.
64 CHARACTER(LEN=default_string_length) :: citation_key =
""
65 END TYPE reference_type
69 TYPE(reference_type),
POINTER :: ref => null()
74 TYPE(reference_p_type),
DIMENSION(max_reference) :: thebib
85 INTEGER,
INTENT(IN) :: key
87 IF (key < 1 .OR. key > max_reference) cpabort(
"citation key out of range")
90 thebib(key)%ref%is_cited = .true.
107 IF (thebib(i)%ref%is_cited) t = 1
109 thebib(i)%ref%is_cited = (t == 1)
130 SUBROUTINE add_reference(key, authors, title, source, volume, pages, year, doi)
131 INTEGER,
INTENT(OUT) :: key
132 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(IN) :: authors
133 CHARACTER(LEN=*),
INTENT(IN) :: title, source
134 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: volume, pages
135 INTEGER,
INTENT(IN) :: year
136 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: doi
139 CHARACTER(LEN=default_string_length) :: author, citation_key, key_a, key_b
140 INTEGER :: i, ires, match, mylen, periodloc
142 IF (
nbib + 1 > max_reference) cpabort(
"increase max_reference")
146 ALLOCATE (thebib(key)%ref)
149 ALLOCATE (thebib(key)%ref%authors(
SIZE(authors)))
150 DO i = 1,
SIZE(authors)
152 thebib(key)%ref%authors(i) = authors(i)
156 thebib(key)%ref%title = trim(title)
157 thebib(key)%ref%source = trim(source)
158 thebib(key)%ref%year = year
161 IF (
PRESENT(volume))
THEN
162 thebib(key)%ref%volume = trim(volume)
164 IF (
PRESENT(pages))
THEN
165 thebib(key)%ref%pages = trim(pages)
167 IF (
PRESENT(doi))
THEN
168 thebib(key)%ref%doi = trim(doi)
173 periodloc = index(author,
'.', back=.true.)
174 IF (periodloc > 0) author = author(periodloc + 1:)
175 cpassert(len_trim(author) > 0)
176 WRITE (citation_key,
'(A,I4)') trim(author), year
179 mylen = len_trim(citation_key)
182 IF (index(
"0123456789thequickbrownfoxjumpsoverthelazydogTHEQUICKBROWNFOXJUMPSOVERTHELAZYDOG", citation_key(i:i)) .NE. 0)
THEN
184 tmp = citation_key(i:i)
185 citation_key(ires:ires) = tmp
188 citation_key(ires + 1:) =
""
189 cpassert(len_trim(citation_key) > 4)
192 mylen = len_trim(citation_key)
193 key_a = citation_key(1:mylen)
197 key_b = thebib(i)%ref%citation_key(1:mylen)
199 IF (key_a == key_b) match = match + 1
201 IF (match > 0) citation_key = citation_key(1:mylen)//char(ichar(
'a') + match)
204 thebib(key)%ref%citation_key = citation_key
217 DEALLOCATE (thebib(i)%ref)
229 INTEGER,
INTENT(IN) :: unit
232 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: irank, ival
240 ival(i) = -thebib(i)%ref%year
245 IF (thebib(irank(i))%ref%is_cited)
THEN
246 CALL print_reference_journal(key=irank(i), unit=unit)
247 WRITE (unit,
'(A)')
""
261 SUBROUTINE print_reference_journal(key, unit)
262 INTEGER,
INTENT(IN) :: key, unit
264 CHARACTER(LEN=:),
ALLOCATABLE :: text
265 CHARACTER(LEN=default_string_length) :: year_str
269 text = thebib(key)%ref%authors(1)
270 DO iauthor = 2,
SIZE(thebib(key)%ref%authors)
271 text = trim(text)//
", "//thebib(key)%ref%authors(iauthor)
273 CALL write_long_text(trim(text)//
".", unit)
276 text = thebib(key)%ref%source
277 IF (
ALLOCATED(thebib(key)%ref%volume))
THEN
278 text = text//
" "//thebib(key)%ref%volume
280 IF (
ALLOCATED(thebib(key)%ref%pages))
THEN
281 text = trim(text)//
", "//thebib(key)%ref%pages
283 IF (thebib(key)%ref%year > 0)
THEN
285 text = trim(text)//
" ("//trim(year_str)//
")"
287 CALL write_long_text(trim(text)//
".", unit)
290 CALL write_long_text(thebib(key)%ref%title//
".", unit)
293 IF (
ALLOCATED(thebib(key)%ref%doi))
THEN
294 WRITE (unit,
'(T2,A)')
"https://doi.org/"//trim(thebib(key)%ref%doi)
297 END SUBROUTINE print_reference_journal
305 INTEGER,
INTENT(IN) :: unit
310 WRITE (unit,
'(T2,A)')
'<REFERENCE key="'//trim(thebib(i)%ref%citation_key)//
'">'
313 DO j = 1,
SIZE(thebib(i)%ref%authors)
314 WRITE (unit,
'(T3,A)')
'<AUTHOR>'//trim(thebib(i)%ref%authors(j))//
'</AUTHOR>'
318 WRITE (unit,
'(T3,A)')
'<TITLE>'//thebib(i)%ref%title//
'</TITLE>'
319 WRITE (unit,
'(T3,A)')
'<SOURCE>'//thebib(i)%ref%source//
'</SOURCE>'
322 IF (
ALLOCATED(thebib(i)%ref%doi)) &
324 IF (
ALLOCATED(thebib(i)%ref%volume)) &
325 WRITE (unit,
'(T3,A)')
'<VOLUME>'//thebib(i)%ref%volume//
'</VOLUME>'
326 IF (
ALLOCATED(thebib(i)%ref%pages)) &
327 WRITE (unit,
'(T3,A)')
'<PAGES>'//thebib(i)%ref%pages//
'</PAGES>'
328 IF (thebib(i)%ref%year > 0) &
329 WRITE (unit,
'(T3,A,I4.4,A)')
'<YEAR>', thebib(i)%ref%year,
'</YEAR>'
330 WRITE (unit,
'(T2,A)')
'</REFERENCE>'
341 INTEGER,
INTENT(IN) :: key
342 CHARACTER(LEN=default_string_length) :: res
344 res = thebib(key)%ref%citation_key
354 SUBROUTINE write_long_text(text, unit)
355 CHARACTER(LEN=*),
INTENT(IN) :: text
356 INTEGER,
INTENT(IN) :: unit
361 DO WHILE (b < len(text))
362 b = next_linebreak(text, pos=a, rowlen=78)
363 WRITE (unit,
'(T2,A)') text(a:b)
366 END SUBROUTINE write_long_text
376 FUNCTION next_linebreak(text, pos, rowlen)
RESULT(ibreak)
377 CHARACTER(LEN=*),
INTENT(IN) :: text
378 INTEGER,
INTENT(IN) :: pos, rowlen
384 IF (n - pos <= rowlen)
THEN
387 i = index(text(pos + 1:pos + 1 + rowlen),
" ", back=.true.)
389 ibreak = pos + rowlen - 1
394 END FUNCTION next_linebreak
Defines the basic variable types.
integer, parameter, public default_string_length
Interface to the message passing library MPI.
provides a uniform framework to add references to CP2K cite and output these
pure character(len=default_string_length) function, public get_citation_key(key)
...
subroutine, public add_reference(key, authors, title, source, volume, pages, year, doi)
add a reference to the bibliography
subroutine, public remove_all_references()
deallocate the bibliography
subroutine, public collect_citations_from_ranks(para_env)
Checks for each reference if any mpi-rank has marked it for citation.
subroutine, public cite_reference(key)
marks a given reference as cited.
subroutine, public print_cited_references(unit)
printout of all cited references in the journal format sorted by publication year
subroutine, public export_references_as_xml(unit)
Exports all references as XML.
Utilities for string manipulations.
subroutine, public integer_to_string(inumber, string)
Converts an integer number to a string. The WRITE statement will return an error message,...
character(len=2 *len(inp_string)) function, public substitute_special_xml_tokens(inp_string)
Substitutes the five predefined XML entities: &, <, >, ', and ".
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
All kind of helpful little routines.
stores all the informations relevant to an mpi environment