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()
70 END TYPE reference_p_type
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)
131 SUBROUTINE add_reference(key, authors, title, source, volume, pages, year, doi, citation_key)
132 INTEGER,
INTENT(OUT) :: key
133 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(IN) :: authors
134 CHARACTER(LEN=*),
INTENT(IN) :: title, source
135 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: volume, pages
136 INTEGER,
INTENT(IN) :: year
137 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: doi, citation_key
140 CHARACTER(LEN=default_string_length) :: author, citation_key_, key_a, key_b
141 INTEGER :: i, ires, match, mylen, periodloc
143 IF (
nbib + 1 > max_reference) cpabort(
"increase max_reference")
147 ALLOCATE (thebib(key)%ref)
150 ALLOCATE (thebib(key)%ref%authors(
SIZE(authors)))
151 DO i = 1,
SIZE(authors)
153 thebib(key)%ref%authors(i) = authors(i)
157 thebib(key)%ref%title = trim(title)
158 thebib(key)%ref%source = trim(source)
159 thebib(key)%ref%year = year
162 IF (
PRESENT(volume))
THEN
163 thebib(key)%ref%volume = trim(volume)
165 IF (
PRESENT(pages))
THEN
166 thebib(key)%ref%pages = trim(pages)
168 IF (
PRESENT(doi))
THEN
169 thebib(key)%ref%doi = trim(doi)
172 IF (
PRESENT(citation_key))
THEN
173 citation_key_ = citation_key
174 cpassert(len_trim(citation_key_) > 4)
178 periodloc = index(author,
'.', back=.true.)
179 IF (periodloc > 0) author = author(periodloc + 1:)
180 cpassert(len_trim(author) > 0)
181 WRITE (citation_key_,
'(A,I4)') trim(author), year
184 mylen = len_trim(citation_key_)
187 IF (index(
"0123456789thequickbrownfoxjumpsoverthelazydogTHEQUICKBROWNFOXJUMPSOVERTHELAZYDOG", &
188 citation_key_(i:i)) /= 0)
THEN
190 tmp = citation_key_(i:i)
191 citation_key_(ires:ires) = tmp
194 citation_key_(ires + 1:) =
""
195 cpassert(len_trim(citation_key_) > 4)
199 mylen = len_trim(citation_key_)
200 key_a = citation_key_(1:mylen)
204 key_b = thebib(i)%ref%citation_key(1:mylen)
206 IF (key_a == key_b) match = match + 1
209 IF (
PRESENT(citation_key))
THEN
210 cpabort(
"explicit citation key already exists")
212 citation_key_ = citation_key_(1:mylen)//char(ichar(
'a') + match)
217 thebib(key)%ref%citation_key = citation_key_
230 DEALLOCATE (thebib(i)%ref)
242 INTEGER,
INTENT(IN) :: unit
245 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: irank, ival
253 ival(i) = -thebib(i)%ref%year
258 IF (thebib(irank(i))%ref%is_cited)
THEN
259 CALL print_reference_journal(key=irank(i), unit=unit)
260 WRITE (unit,
'(A)')
""
274 SUBROUTINE print_reference_journal(key, unit)
275 INTEGER,
INTENT(IN) :: key, unit
277 CHARACTER(LEN=:),
ALLOCATABLE :: text
278 CHARACTER(LEN=default_string_length) :: year_str
282 text = thebib(key)%ref%authors(1)
283 DO iauthor = 2,
SIZE(thebib(key)%ref%authors)
284 text = trim(text)//
", "//thebib(key)%ref%authors(iauthor)
286 CALL write_long_text(trim(text)//
".", unit)
289 text = thebib(key)%ref%source
290 IF (
ALLOCATED(thebib(key)%ref%volume))
THEN
291 text = text//
" "//thebib(key)%ref%volume
293 IF (
ALLOCATED(thebib(key)%ref%pages))
THEN
294 text = trim(text)//
", "//thebib(key)%ref%pages
296 IF (thebib(key)%ref%year > 0)
THEN
298 text = trim(text)//
" ("//trim(year_str)//
")"
300 CALL write_long_text(trim(text)//
".", unit)
303 CALL write_long_text(thebib(key)%ref%title//
".", unit)
306 IF (
ALLOCATED(thebib(key)%ref%doi))
THEN
307 WRITE (unit,
'(T2,A)')
"https://doi.org/"//trim(thebib(key)%ref%doi)
310 END SUBROUTINE print_reference_journal
318 INTEGER,
INTENT(IN) :: unit
323 WRITE (unit,
'(T2,A)')
'<REFERENCE key="'//trim(thebib(i)%ref%citation_key)//
'">'
326 DO j = 1,
SIZE(thebib(i)%ref%authors)
327 WRITE (unit,
'(T3,A)')
'<AUTHOR>'//trim(thebib(i)%ref%authors(j))//
'</AUTHOR>'
331 WRITE (unit,
'(T3,A)')
'<TITLE>'//thebib(i)%ref%title//
'</TITLE>'
332 WRITE (unit,
'(T3,A)')
'<SOURCE>'//thebib(i)%ref%source//
'</SOURCE>'
335 IF (
ALLOCATED(thebib(i)%ref%doi)) &
337 IF (
ALLOCATED(thebib(i)%ref%volume)) &
338 WRITE (unit,
'(T3,A)')
'<VOLUME>'//thebib(i)%ref%volume//
'</VOLUME>'
339 IF (
ALLOCATED(thebib(i)%ref%pages)) &
340 WRITE (unit,
'(T3,A)')
'<PAGES>'//thebib(i)%ref%pages//
'</PAGES>'
341 IF (thebib(i)%ref%year > 0) &
342 WRITE (unit,
'(T3,A,I4.4,A)')
'<YEAR>', thebib(i)%ref%year,
'</YEAR>'
343 WRITE (unit,
'(T2,A)')
'</REFERENCE>'
354 INTEGER,
INTENT(IN) :: key
355 CHARACTER(LEN=default_string_length) :: res
357 res = thebib(key)%ref%citation_key
367 SUBROUTINE write_long_text(text, unit)
368 CHARACTER(LEN=*),
INTENT(IN) :: text
369 INTEGER,
INTENT(IN) :: unit
374 DO WHILE (b < len(text))
375 b = next_linebreak(text, pos=a, rowlen=78)
376 WRITE (unit,
'(T2,A)') text(a:b)
379 END SUBROUTINE write_long_text
389 FUNCTION next_linebreak(text, pos, rowlen)
RESULT(ibreak)
390 CHARACTER(LEN=*),
INTENT(IN) :: text
391 INTEGER,
INTENT(IN) :: pos, rowlen
397 IF (n - pos <= rowlen)
THEN
400 i = index(text(pos + 1:pos + 1 + rowlen),
" ", back=.true.)
402 ibreak = pos + rowlen - 1
407 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
subroutine, public add_reference(key, authors, title, source, volume, pages, year, doi, citation_key)
add a reference to the bibliography
pure character(len=default_string_length) function, public get_citation_key(key)
...
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