tstLibraryIO.f90

./Core/io/f/tests/tstLibraryIO.f90

1 #include "ScaleDBCF/DBCF.h"
2 program main
3 
5  origen_libraryheader, &
6  origen_decaydata, &
7  origen_transitionstructure, &
8  origen_transitioncoeff
10 use datacontainer_m
11 use stringlist_m
12 use dbcf_m
13 use origen_testpaths_m
14 !
15 use nemesis_comm, only: build_types, initialize, finalize, node
16 
17 implicit none
18 
19 type(origen_library) :: lib
20 type(origen_libraryio) :: io
21 type(datacontainer) :: options
22 type(stringlist) :: errors,oerrors
23 logical :: loaded,saved
24 integer :: i
25 character(128) :: str
26 
27 call initialize
28 call build_types
29 if( node() /= 0 )call finalize
30 
31 !initialize
32 call errors % initialize()
33 call io % initialize()
34 call options % initialize()
35 
36 !load PWR library
37 call lib % initialize()
38 loaded = io % load(lib,pwrlib_filepath,options)
39 if( .not. loaded )then
40  write(*,*)"couldn't read PWR library {"//trim(pwrlib_filepath)//"}"
41  stop 0
42 else
43  saved = io % save(lib,'pwr.bof',options)
44 end if
45 call lib % destroy()
46 
47 
48 !load decay library
49 call lib % initialize()
50 loaded = io % load(lib,decaylib_filepath,options)
51 if( .not. loaded )then
52  write(*,*)"couldn't read decay library {"//trim(decaylib_filepath)//"}"
53  stop 0
54 else
55  saved = io % save(lib,'decay.bof',options)
56 end if
57 call lib % destroy()
58 
59 
60 !load non-existant library
61 loaded = io % load(lib,'DOES_NOT_EXIST',options)
62 call options % remove(oerrors,"ERROR");
63 
64 
65 !will get the following error messages (1 for each failed format, then summary):
66 ! could not open file={DOES_NOT_EXIST} for reading binary
67 ! could not open file={DOES_NOT_EXIST} for reading binary
68 ! could not open file={DOES_NOT_EXIST} for reading binary
69 ! tried to load formats: (bof|s62b|s61) and failed
70 if(oerrors%size()/=4)then
71  call errors % push_back("didn't get the right number of errors "//&
72  "when trying to load from bogus file");
73 end if
74 
75 !output the errors inside options
76 !do i=1,oerrors % size()
77 ! call oerrors % at(str,i)
78 ! write(*,*)i,". ",trim(str)
79 !end do
80 
81 !destroy options errors
82 call oerrors % destroy()
83 
84 !stop if errors found
85 if( errors%size()>0 )then
86  write(*,*)'found errors:'
87  do i=1,errors % size()
88  call errors % at(str,i)
89  write(*,*)i,". ",trim(str)
90  end do
91  stop 1
92 endif
93 
94 call options % destroy()
95 call io % destroy()
96 call errors % destroy()
97 
98 call finalize
99 
100 end program