1 | include(dom.inc)
2 |
3 | PROGRAM outconvert
4 |
5 | ! ==================================================================!
6 | ! !
7 | ! convertion.F : Convert PRISSMA's solution files !
8 | ! from bin to ascii and from ascii to bin !
9 | ! !
10 | ! author : D. POITOU (march 2008) !
11 | ! !
12 | ! ==================================================================!
13 |
14 | IMPLICIT NONE
15 |
16 | include 'dom_constants.h'
17 |
18 | CHARACTER*80 :: path1, path2, path3
19 | CHARACTER*80 :: gdatafile,gdatafile2,epfile,epfile2
20 | CHARACTER*80 :: gfile,srfile,hfile,qwfile,qrfile
21 | CHARACTER*80 :: gfile2,srfile2,hfile2,qwfile2,qrfile2
22 | CHARACTER*80 :: kpfile,kpfile2
23 |
24 | DOM_INT :: ntcells, ntnodes, ntfaces,ntfacesmax
25 | DOM_INT :: icell,iface,l,i,j,nfaces,convtype
26 | DOM_INT :: readkp,ios
27 | DOM_REAL :: Sr,G,H,Qw,Kp
28 | DOM_REAL :: Q_r(3)
29 |
30 | DOM_REAL, ALLOCATABLE, DIMENSION(:) :: epsil
31 |
32 | ! ------------------!
33 | ! Read choices file !
34 | ! ------------------!
35 |
36 | OPEN (FILE_CHCS , FILE='outconvert.choices', FORM='FORMATTED')
37 | READ (FILE_CHCS,*) path1 ! Path for infiles *.in
38 | READ (FILE_CHCS,*) path2 ! Path for bin outfiles *.out
39 | READ (FILE_CHCS,*) path3 ! Path for acsii outfiles *.txt
40 | READ (FILE_CHCS,*) convtype ! Choice for the convertion type
41 | CLOSE(FILE_CHCS)
42 |
43 | ! ---------------!
44 | ! Set file names !
45 | ! ---------------!
46 |
47 | gdatafile = path1(1:len_trim(path1))//'/Global.in'
48 | gdatafile2 = path3(1:len_trim(path3))//'/Global.txt'
49 | epfile = path1(1:len_trim(path1))//'/Emissivities.in'
50 | epfile2 = path3(1:len_trim(path3))//'/Emissivities.txt'
51 |
52 | gfile = path2(1:len_trim(path2))//'/G.out'
53 | srfile = path2(1:len_trim(path2))//'/Sr.out'
54 | hfile = path2(1:len_trim(path2))//'/H.out'
55 | qwfile = path2(1:len_trim(path2))//'/Qw.out'
56 | qrfile = path2(1:len_trim(path2))//'/Qr.out'
57 | kpfile = path2(1:len_trim(path2))//'/Kp.out'
58 |
59 | gfile2 = path3(1:len_trim(path3))//'/G.txt'
60 | srfile2 = path3(1:len_trim(path3))//'/Sr.txt'
61 | hfile2 = path3(1:len_trim(path3))//'/H.txt'
62 | qwfile2 = path3(1:len_trim(path3))//'/Qw.txt'
63 | qrfile2 = path3(1:len_trim(path3))//'/Qr.txt'
64 | kpfile2 = path3(1:len_trim(path3))//'/Kp.txt'
65 |
66 | ! -----------------------------------!
67 | ! Open biary/ascii Global data files !
68 | ! -----------------------------------!
69 |
70 | OPEN(FILE_GDATA, FILE=gdatafile , FORM='UNFORMATTED')
71 | OPEN(FILE_EMIS , FILE=epfile , FORM='UNFORMATTED')
72 | OPEN(FILE_GDAT2, FILE=gdatafile2, FORM='FORMATTED')
73 | OPEN(FILE_EMIS2, FILE=epfile2 , FORM='FORMATTED')
74 |
75 | ! ------------------------!
76 | ! Open biary output files !
77 | ! ------------------------!
78 |
79 | OPEN(FILE_G ,FILE=gfile ,FORM='unformatted')
80 | OPEN(FILE_Sr,FILE=srfile,FORM='unformatted')
81 | OPEN(FILE_H ,FILE=hfile ,FORM='unformatted')
82 | OPEN(FILE_Qw,FILE=qwfile,FORM='unformatted')
83 | OPEN(FILE_Qr,FILE=qrfile,FORM='unformatted')
84 |
85 | IF (convtype.eq.1) THEN
86 | readkp = 1
87 | INQUIRE(FILE=kpfile,IOSTAT=ios)
88 | IF (ios.ne.0) readkp = 0
89 | ENDIF
90 |
91 | ! ------------------------!
92 | ! Open ascii output files !
93 | ! ------------------------!
94 |
95 | OPEN(FILE_G2 ,FILE=gfile2 ,FORM='formatted')
96 | OPEN(FILE_Sr2,FILE=srfile2,FORM='formatted')
97 | OPEN(FILE_H2 ,FILE=hfile2 ,FORM='formatted')
98 | OPEN(FILE_Qw2,FILE=qwfile2,FORM='formatted')
99 | OPEN(FILE_Qr2,FILE=qrfile2,FORM='formatted')
100 |
101 | IF (convtype.eq.2) THEN
102 | readkp = 1
103 | INQUIRE(FILE=kpfile2,IOSTAT=ios)
104 | IF (ios.ne.0) readkp = 0
105 | ENDIF
106 |
107 | ! ------------------------------!
108 | ! Open Kp.out only if it exists !
109 | ! ------------------------------!
110 |
111 | IF (readkp.eq.1) THEN
112 | OPEN(FILE_Kp,FILE=kpfile,FORM='unformatted')
113 | OPEN(FILE_Kp2,FILE=kpfile2,FORM='formatted')
114 | ENDIF
115 |
116 | ! ----------------------!
117 | ! Transform Global data !
118 | ! ----------------------!
119 |
120 | IF (convtype.eq.1) THEN
121 |
122 | READ(FILE_GDATA) ntcells, ntnodes, ntfaces,ntfacesmax
123 | WRITE(FILE_GDAT2,*) ntcells, ntnodes, ntfaces,ntfacesmax
124 |
125 | ELSEIF (convtype.eq.2) THEN
126 |
127 | READ(FILE_GDAT2,*) ntcells, ntnodes, ntfaces,ntfacesmax
128 |
129 | ENDIF
130 |
131 | CLOSE(FILE_GDATA)
132 | CLOSE(FILE_GDAT2)
133 |
134 | ! -----------------!
135 | ! Allocate vectors !
136 | ! -----------------!
137 |
138 | ALLOCATE(epsil(ntfacesmax))
139 |
140 | ! ----------------------!
141 | ! Transform output data !
142 | ! ----------------------!
143 | epsil = -1.
144 |
145 | IF (convtype.eq.1) THEN
146 |
147 | DO i=1,ntcells
148 |
149 | READ(FILE_G ) icell,G
150 | READ(FILE_Sr ) icell,Sr
151 | READ(FILE_EMIS) icell,nfaces,(epsil(j),j=1,nfaces)
152 | READ(FILE_Qr ) icell,(Q_r(l),l=1,3)
153 | IF (readkp.eq.1) READ(FILE_Kp) icell,Kp
154 |
155 | WRITE(FILE_G2,* ) icell,G
156 | WRITE(FILE_Sr2,* ) icell,Sr
157 | WRITE(FILE_EMIS2,*) icell,nfaces,(epsil(j),j=1,nfaces)
158 | WRITE(FILE_Qr2,* ) icell,(Q_r(l),l=1,3)
159 | IF (readkp.eq.1) WRITE(FILE_Kp2,*) icell,Kp
160 |
161 | DO j=1,nfaces
162 |
163 | IF (epsil(j).ne.-1.) THEN
164 |
165 | READ(FILE_H ) iface,icell,H
166 | READ(FILE_Qw) iface,icell,Qw
167 |
168 | WRITE(FILE_H2,* ) iface,icell,H
169 | WRITE(FILE_Qw2,*) iface,icell,Qw
170 |
171 | ENDIF
172 |
173 | ENDDO
174 |
175 | ENDDO
176 |
177 | ELSEIF (convtype.eq.2) THEN
178 |
179 | DO i=1,ntcells
180 |
181 | READ(FILE_G2,* ) icell,G
182 | READ(FILE_Sr2,* ) icell,Sr
183 | READ(FILE_EMIS2,*) icell,nfaces,(epsil(j),j=1,nfaces)
184 | READ(FILE_Qr2,* ) icell,(Q_r(l),l=1,3)
185 | IF (readkp.eq.1) READ(FILE_Kp2,*) icell,Kp
186 |
187 | WRITE(FILE_G ) icell,G
188 | WRITE(FILE_Sr) icell,Sr
189 | WRITE(FILE_Qr) icell,(Q_r(l),l=1,3)
190 | IF (readkp.eq.1) WRITE(FILE_Kp) icell,Kp
191 |
192 | DO j=1,nfaces
193 |
194 | IF (epsil(j).ne.-1.) THEN
195 |
196 | READ(FILE_H2,* ) iface,icell,H
197 | READ(FILE_Qw2,*) iface,icell,Qw
198 |
199 | WRITE(FILE_H ) iface,icell,H
200 | WRITE(FILE_Qw ) iface,icell,Qw
201 |
202 | ENDIF
203 |
204 | ENDDO
205 |
206 | ENDDO
207 |
208 | ELSE
209 | print*, 'Error bad choice of convertion type'
210 | ENDIF
211 |
212 | ! ----------------!
213 | ! Close all files !
214 | ! ----------------!
215 |
216 | CLOSE(FILE_EMIS)
217 | CLOSE(FILE_EMIS2)
218 | CLOSE(FILE_G)
219 | CLOSE(FILE_G2)
220 | CLOSE(FILE_Sr)
221 | CLOSE(FILE_Sr2)
222 | CLOSE(FILE_Qr)
223 | CLOSE(FILE_Qr2)
224 | CLOSE(FILE_Qw)
225 | CLOSE(FILE_Qw2)
226 | CLOSE(FILE_Kp)
227 | CLOSE(FILE_Kp2)
228 |
229 | IF(convtype.eq.1) THEN
230 | print*,'Conversion bin2ascii done!'
231 | ELSEIF(convtype.eq.2) THEN
232 | print*,'Conversion ascii2bin done!'
233 | ENDIF
234 |
235 | END PROGRAM outconvert