module parse_traceur_file_mod implicit none contains subroutine get_nq_from_traceur_file(nq) ! get the number of tracers from "traceur.def" file use mod_phys_lmdz_para, only : is_master, bcast implicit none integer,intent(out) :: nq ! number of tracers if (is_master) then ! only the master needs do this open(42,file="traceur.def") ! first line of traceur.def is # of tracers read(42,*) nq close(42) endif ! of is_master ! share the information with all cores call bcast(nq) end subroutine get_nq_from_traceur_file subroutine get_names_from_traceur_file(nq,noms,nqparents,nqchildren) use mod_phys_lmdz_para, only : is_master, bcast implicit none integer,intent(in) :: nq ! number of tracers character(len=*),intent(out) :: noms(nq) ! names of the tracers integer,intent(out) :: nqparents ! number of tracers that are "parents" integer,intent(out) :: nqchildren(nq) ! number of children the tracer has integer :: idummy character(len=150) :: line character(len=50) :: parent(nq) ! to store the name of a parent of a tracer integer :: i,j integer :: first_blank if (is_master) then ! only the master needs do this open(42,file="traceur.def") ! first line of traceur.def is # of tracers (already known) read(42,*) idummy ! each line of traceur.def starts with name of tracer, possibly followed ! by name of parent nqparents=0 parent(:)="" do i=1,nq read(42,'(a)') line ! look for index of fist space in line first_blank=index(line," ") read(line(1:first_blank-1),'(a)')noms(i) if (len_trim(line)==len_trim(noms(i))) then ! the line only contained the name of the tracer; it is a parent nqparents=nqparents+1 else ! it is a child, parse the rest of the line for its parents name read(line(first_blank+1:),'(a)')parent(i) endif enddo ! now look for the number of children each parent has: do i=1,nq nqchildren(i)=0 do j=1,nq if (noms(i)==parent(j)) then nqchildren(i)=nqchildren(i)+1 endif enddo enddo endif ! of is_master ! share the information with all cores do i=1,nq call bcast(noms(i)) enddo call bcast(nqparents) call bcast(nqchildren) end subroutine get_names_from_traceur_file end module parse_traceur_file_mod