Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SPEC_ReadInputFile.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 ! ******************************************************************************
24 !
25 ! Purpose: Read user input, store it in the data structure and check.
26 !
27 ! Description: None.
28 !
29 ! Input:
30 ! regions Data associated with regions
31 !
32 ! Output: None.
33 !
34 ! Notes: None.
35 !
36 ! ******************************************************************************
37 !
38 ! $Id: SPEC_ReadInputFile.F90,v 1.6 2008/12/06 08:44:41 mtcampbe Exp $
39 !
40 ! Copyright: (c) 2003-2005 by the University of Illinois
41 !
42 ! ******************************************************************************
43 
44 SUBROUTINE spec_readinputfile(regions)
45 
46  USE modglobal, ONLY: t_global
47  USE moddatatypes
48  USE moddatastruct, ONLY: t_region
49  USE moderror
50  USE modparameters
51 
53 
57  IMPLICIT NONE
58 
59 ! ******************************************************************************
60 ! Definitions and declarations
61 ! ******************************************************************************
62 
63 ! ==============================================================================
64 ! Arguments
65 ! ==============================================================================
66 
67  TYPE(t_region), DIMENSION(:), POINTER :: regions
68 
69 ! ==============================================================================
70 ! Locals
71 ! ==============================================================================
72 
73  CHARACTER(CHRLEN) :: ifilename,rcsidentstring
74  CHARACTER(256) :: line
75  INTEGER :: errorflag,ipass,ireg,ispec,ispectype,nspecies
76  LOGICAL :: usedsomewhere,unusedsomewhere
77  TYPE(t_global), POINTER :: global
78 
79 ! ******************************************************************************
80 ! Start
81 ! ******************************************************************************
82 
83  rcsidentstring = '$RCSfile: SPEC_ReadInputFile.F90,v $ $Revision: 1.6 $'
84 
85  global => regions(1)%global
86 
87  CALL registerfunction(global,'SPEC_ReadInputFile',&
88  'SPEC_ReadInputFile.F90')
89 
90 ! ******************************************************************************
91 ! Read user input for species
92 ! ******************************************************************************
93 
94 ! ==============================================================================
95 ! Build file name
96 ! ==============================================================================
97 
98  CALL buildfilenameplain(global,filedest_indir,'.inp',ifilename)
99 
100 ! ==============================================================================
101 ! Look for keywords and read appropriate sections, read in two passes
102 ! ==============================================================================
103 
104  outer: DO ipass = 1,2
105  ispectype = 0
106 
107 ! ------------------------------------------------------------------------------
108 ! Open file
109 ! ------------------------------------------------------------------------------
110 
111  OPEN(if_input,file=ifilename,form='FORMATTED',status='UNKNOWN', &
112  iostat=errorflag)
113  global%error = errorflag
114  IF ( global%error /= 0 ) THEN
115  CALL errorstop(global,err_file_open,__line__,'File: '//trim(ifilename))
116  END IF ! global%error
117 
118 ! ------------------------------------------------------------------------------
119 ! In each pass, look for keywords
120 ! ------------------------------------------------------------------------------
121 
122  inner: DO
123  READ(if_input,'(A256)',iostat=errorflag) line
124 
125  IF ( errorflag > 0 ) THEN ! Error occurred
126  CALL errorstop(global,err_file_read,__line__,'File: '//trim(ifilename))
127  ELSE IF ( errorflag < 0 ) THEN ! Encountered end of file
128  EXIT inner
129  END IF ! errorFlag
130 
131 ! --- First pass: Read only SPECIES section ------------------------------------
132 
133  IF ( ipass == 1 ) THEN
134  SELECT CASE( trim(line) )
135  CASE ( '# SPECIES' )
136  CALL spec_readspecsection(regions)
137  END SELECT
138 
139 ! --- Second pass: Read only SPECIES_TYPE sections -----------------------------
140 
141  ELSE IF ( ipass == 2 ) THEN
142  SELECT CASE( trim(line) )
143  CASE ( '# SPECIES_TYPE' )
144  ispectype = ispectype + 1
145  CALL spec_readspectypesection(regions,ispectype)
146  END SELECT
147 
148 ! --- Invalid pass number (defensive coding) -----------------------------------
149 
150  ELSE
151  CALL errorstop(global,err_reached_default,__line__)
152  END IF ! iPass
153  END DO inner
154 
155 ! ------------------------------------------------------------------------------
156 ! End of pass 1: Allocate memory for species-specific input and initialize
157 ! ------------------------------------------------------------------------------
158 
159  IF ( ipass == 1 ) THEN
160  DO ireg = lbound(regions,1),ubound(regions,1)
161  nspecies = regions(ireg)%specInput%nSpecies
162 
163  IF ( nspecies > 0 ) THEN
164  ALLOCATE(regions(ireg)%specInput%specType(nspecies),stat=errorflag)
165  global%error = errorflag
166  IF ( global%error /= err_none ) THEN
167  CALL errorstop(global,err_allocate,__line__, &
168  'regions%specInput%specType')
169  END IF ! global%error
170 
171  DO ispec = 1,nspecies
172  CALL spec_initinputvaluesspectype(regions(ireg),ispec)
173  END DO ! iSpec
174  ELSE
175  nullify(regions(ireg)%specInput%specType)
176  END IF ! nSpecies
177  END DO ! iReg
178  END IF ! iPass
179 
180 ! ------------------------------------------------------------------------------
181 ! Check that have enough SPECIES_TYPE sections if species USED
182 ! ------------------------------------------------------------------------------
183 
184  IF ( ipass == 2 ) THEN
185 
186  usedsomewhere = .false.
187  unusedsomewhere = .false.
188 
189  DO ireg = lbound(regions,1),ubound(regions,1)
190  nspecies = regions(ireg)%specInput%nSpecies
191  IF ( regions(ireg)%specInput%usedFlag ) THEN
192 ! ------- if USED, then require number of sections to be consistent
193  IF ( ispectype /= nspecies ) THEN
194  CALL errorstop(global,err_spec_ntypes,__line__)
195  END IF ! iSpecType
196  IF ( nspecies == 0 ) regions(ireg)%specInput%usedFlag = .false.
197  ELSE
198 ! ------- if not USED, then no consistency check, but check nSpecies set to 0
199  IF ( nspecies /= 0 ) THEN
200  CALL errorstop(global,err_spec_ntypes,__line__)
201  END IF ! nSpecies
202  END IF ! usedFlag
203 
204  usedsomewhere = usedsomewhere .OR. &
205  regions(ireg)%specInput%usedFlag
206  unusedsomewhere = unusedsomewhere .OR. &
207  .NOT. regions(ireg)%specInput%usedFlag
208  END DO ! iReg
209 
210  IF (usedsomewhere.AND.unusedsomewhere) THEN
211  CALL errorstop( global,err_mp_allornone,__line__ )
212  END IF ! usedSomewhere.AND.unusedSomewhere
213 
214  global%specUsed = usedsomewhere
215 
216  END IF ! iPass
217 
218 ! ------------------------------------------------------------------------------
219 ! Close file
220 ! ------------------------------------------------------------------------------
221 
222  CLOSE(if_input,iostat=errorflag)
223  global%error = errorflag
224  IF ( global%error /= 0 ) THEN
225  CALL errorstop(global,err_file_close,__line__,'File: '//trim(ifilename))
226  END IF ! global%error
227  END DO outer
228 
229 ! ******************************************************************************
230 ! End
231 ! ******************************************************************************
232 
233  CALL deregisterfunction(global)
234 
235 END SUBROUTINE spec_readinputfile
236 
237 ! ******************************************************************************
238 !
239 ! RCS Revision history:
240 !
241 ! $Log: SPEC_ReadInputFile.F90,v $
242 ! Revision 1.6 2008/12/06 08:44:41 mtcampbe
243 ! Updated license.
244 !
245 ! Revision 1.5 2008/11/19 22:17:53 mtcampbe
246 ! Added Illinois Open Source License/Copyright
247 !
248 ! Revision 1.4 2005/11/10 02:38:30 haselbac
249 ! Clean-up
250 !
251 ! Revision 1.3 2004/07/28 15:29:21 jferry
252 ! created global variable for spec use
253 !
254 ! Revision 1.2 2004/06/16 20:01:29 haselbac
255 ! Added use of ModBuildFileNames, cosmetics
256 !
257 ! Revision 1.1 2003/11/25 21:08:37 haselbac
258 ! Initial revision
259 !
260 ! ******************************************************************************
261 
262 
263 
264 
265 
266 
267 
CImg< T > & line(const unsigned int y0)
Get a line.
Definition: CImg.h:18421
subroutine spec_readspectypesection(regions, iSpecType)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
subroutine spec_initinputvaluesspectype(region, iSpecType)
subroutine spec_readinputfile(regions)
subroutine buildfilenameplain(global, dest, ext, fileName)
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE form
subroutine spec_readspecsection(regions)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469