-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_definitions.f90
496 lines (433 loc) · 17.8 KB
/
parser_definitions.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
!------------------------------------------------------------------------------
MODULE mod_FolderNames
!------------------------------------------------------------------------------
! The meaning of 'RelativeFolderPathC' is the location of the 'Syntax/' folder
! relative to the executable.
!------------------------------------------------------------------------------
IMPLICIT NONE
CHARACTER(len=*),PARAMETER :: FolderNameForDefinitionFilesC = 'Syntax' ! to be consistent to nextnano++: folder name for keyword definition files, database, ...
CHARACTER(len=*),PARAMETER :: RelativeFolderPathC = '..' ! ..\Syntax or ../Syntax:
!CHARACTER(len=*),PARAMETER :: RelativeFolderPathC = '.' ! .\Syntax or ./Syntax
CHARACTER(len=*),PARAMETER :: RelativeFolderPathSameDirectoryC = '.' ! .\Syntax or ./Syntax:
!------------------------------------------------------------------------------
END MODULE mod_FolderNames
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
MODULE system_specific_parser
!------------------------------------------------------------------------------
IMPLICIT NONE
CHARACTER(len=30) :: OperatingSystemC ! 'windows' (default), 'mac', 'linux', 'unix'
LOGICAL :: OperatingSystem64bitL = .TRUE. ! .TRUE. if operating system is 64-bit, .FALSE. if 32-bit
TYPE :: SystemSpecific
CHARACTER(len=1) :: DirectorySeparatorCharC
CHARACTER(len=10) :: Directory_ls_C
CHARACTER(len=10) :: MakeDirC
CHARACTER(len=10) :: PrintWorkingDirC
CHARACTER(len=80) :: HomeDirC
END TYPE SystemSpecific
TYPE(SystemSpecific) :: Windows
TYPE(SystemSpecific) :: Linux
TYPE(SystemSpecific) :: CurrentSystem
LOGICAL :: ParseKeywordsInputFileL = .FALSE.
LOGICAL :: ParseKeywordsDatabaseL = .FALSE.
LOGICAL :: ParseInputFileOnlyL = .FALSE.
LOGICAL :: WriteCompactFileL = .FALSE.
LOGICAL :: SetInputFileViaCommandLineL
LOGICAL :: SetDatabaseViaCommandLineL
LOGICAL :: SetLicenseFileViaCommandLineL
LOGICAL :: SetOutputDirViaCommandLineL
LOGICAL :: SetThreadsViaCommandLineL
LOGICAL :: SetDebugLevelViaCommandLineL
!CHARACTER(len=987) :: OutputDir_defaultC = 'output' ! ==> Replace 'output' with 'InputFileName_NoDirectoryNoExtensionC'.
CHARACTER(len=50) :: OutputDir_default_IndicatorC = '<name_of_input_file>' ! ==> Replace 'output' with 'InputFileName_NoDirectoryNoExtensionC'.
CHARACTER(len=987) :: DatabaseFileName_DirectoryExtension_C = '' ! name of database file with directory and with file extension. Example: "Syntax/database_nn3.in" ==> "Syntax/database_nn3.in"
CHARACTER(len=987) :: InputFileName_DirectoryExtension_C = '' ! name of input file with directory and with file extension. Example: "input/QuantumDot.in" ==> "input/QuantumDot.in"
CHARACTER(len=987) :: InputFileName_NoDirectoryNoExtensionC = '' ! name of input file without directory and without file extension. Example: "input/QuantumDot.in" ==> "QuantumDot"
CHARACTER(len=987) :: InputFileName_NoDirectoryC = '' ! name of input file without directory. Example: "input/QuantumDot.in" ==> "QuantumDot.in"
CHARACTER(len=987) :: OutputDirC = '' ! name of global output directory, e.g. 'H:\nextnano3\output\test'
CHARACTER(len=*),PARAMETER :: DebugDirectory_defaultC = 'debug' ! default name of debug directory
CHARACTER(len=987) :: DebugDirectoryC = ''
INTEGER :: DebugLevel = 0 ! '0' = no debug information
LOGICAL :: DebugLevelL = .FALSE.
INTEGER :: NumberOfThreads = 1 ! use 1 thread by default
LOGICAL :: GenerateLogFileL = .FALSE. ! .TRUE. if .log file should be written, i.e. if screen output should be written to file.
CHARACTER(len=987) :: LogFilenameC ! name of .log file
CHARACTER(len=:),ALLOCATABLE :: NameOfExecutableC
LOGICAL :: gcc_ExecutableL = .FALSE. ! .TRUE. if the executable has been compiled with the gcc/gfortran compiler
! NEXTNANO_PathC = 'C:\Program Files (x86)\nextnano\nextnano3'
CHARACTER(len=987) :: NEXTNANO_PathC = '' ! can be changed by environment variable. The location where the nextnano software is installed.
LOGICAL :: ExecuteHTCondorL = .FALSE.
LOGICAL :: ExecutionOnHTCondorL = .FALSE. ! True, if executable is actually run on HTCondor.
!------------------------------------------------------------------------------
END MODULE system_specific_parser
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
MODULE My_Input_and_Output_Units
!------------------------------------------------------------------------------
!
!++m* parser_definitions.f90/My_Input_and_Output_Units
!
! NAME
! MODULE My_Input_and_Output_Units
!
! PURPOSE
! Subroutines to define standard input and output units.
!
! CONTAINS
! o SUBROUTINE Define_Input_and_Output_Units
!
! FILENAME
! FortranInputParser/parser_definitions.f90
!
! NOTES
!
!##
!
!------------------------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------------
! Initialize with default values but the values are overwritten later.
!----------------------------------------------------------------------
INTEGER :: my_error_unit = 0 ! The standard error reporting unit number.
INTEGER :: my_input_unit = 5 ! The standard input unit number. This is the one used by READ with an asterisk ('*') unit.
INTEGER :: my_output_unit = 6 ! The standard output unit number. This is the one used by PRINT, and by WRITE with an asterisk ('*') unit.
INTEGER,PARAMETER :: output_unit_log_file = 81 ! Note: This number must be UNIQUE. It must not be used elsewhere in the code!!!
!------------------------------------------------------------------------------
END MODULE My_Input_and_Output_Units
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
MODULE Input_and_Output_Units
!------------------------------------------------------------------------------
!
!++m* parser_definitions.f90/Input_and_Output_Units
!
! NAME
! MODULE Input_and_Output_Units
!
! PURPOSE
! Subroutines to define standard input and output units.
!
! CONTAINS
! o SUBROUTINE Define_Input_and_Output_Units
! o SUBROUTINE Redefine_Input_and_Output_Units
!
! FILENAME
! FortranInputParser/parser_definitions.f90
!
! NOTES
!
!##
!
!------------------------------------------------------------------------------
IMPLICIT NONE
CONTAINS
!------------------------------------------------------------------------------
SUBROUTINE Redefine_Input_and_Output_Units(new_error_unit,new_input_unit,new_output_unit)
!------------------------------------------------------------------------------
!
!++s* Input_and_Output_Units/Redefine_Input_and_Output_Units
!
! NAME
! FUNCTION Redefine_Input_and_Output_Units
!
! PURPOSE
! Redefines standard input and output units.
!
! USAGE
! CALL Redefine_Input_and_Output_Units(new_error_unit,new_input_unit,new_output_unit)
!
! INPUT
! o new_error_unit (optional)
! o new_input_unit (optional)
! o new_output_unit (optional)
!
! OUTPUT
! none
!
! NOTES
!
!##
!
!------------------------------------------------------------------------------
USE My_Input_and_Output_Units,ONLY: my_error_unit , &
my_input_unit , &
my_output_unit
IMPLICIT NONE
INTEGER,INTENT(in),OPTIONAL :: new_error_unit
INTEGER,INTENT(in),OPTIONAL :: new_input_unit
INTEGER,INTENT(in),OPTIONAL :: new_output_unit
!----------------------
! Take default values.
!----------------------
IF ( PRESENT(new_error_unit ) ) my_error_unit = new_error_unit
IF ( PRESENT(new_input_unit ) ) my_input_unit = new_input_unit
IF ( PRESENT(new_output_unit) ) my_output_unit = new_output_unit
!------------------------------------------------------------------------------
END SUBROUTINE Redefine_Input_and_Output_Units
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
SUBROUTINE Define_Input_and_Output_Units
!------------------------------------------------------------------------------
!
!
!++s* Input_and_Output_Units/Define_Input_and_Output_Units
!
! NAME
! FUNCTION Define_Input_and_Output_Units
!
! PURPOSE
! Defines (or redefines) standard input and output units.
!
! USAGE
! CALL Define_Input_and_Output_Units
!
! INPUT
! none
!
! OUTPUT
! none
!
! NOTES
!
!##
!
!------------------------------------------------------------------------------
USE,INTRINSIC :: ISO_FORTRAN_ENV,ONLY:error_unit,input_unit,output_unit
IMPLICIT NONE
!INTEGER,PARAMETER :: error_unit = 0 ! The standard error reporting unit number.
!INTEGER,PARAMETER :: input_unit = 5 ! The standard input unit number. This is the one used by READ with an asterisk ('*') unit.
!INTEGER,PARAMETER :: output_unit = 6 ! The standard output unit number. This is the one used by PRINT, and by WRITE with an asterisk ('*') unit.
!----------------------
! Take default values.
!----------------------
CALL Redefine_Input_and_Output_Units(error_unit,input_unit,output_unit)
!------------------------------------------------------------------------------
END SUBROUTINE Define_Input_and_Output_Units
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
END MODULE Input_and_Output_Units
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
MODULE mod_Array_of_Strings
!------------------------------------------------------------------------------
IMPLICIT NONE
TYPE :: String_in_Line
CHARACTER(len=:),ALLOCATABLE :: StringC
END TYPE String_in_Line
!------------------------------------------------------------------------------
END MODULE mod_Array_of_Strings
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
MODULE String_Utility
!------------------------------------------------------------------------------
!
!++m* parser_definitions.f90/String_Utility
!
! NAME
! MODULE String_Utility
!
! CONTAINS
! o FUNCTION StringLowerCase
! o FUNCTION StringUpperCase
! o FUNCTION Substring_is_contained_in_StringL
!
! FILENAME
! FortranInputParser/parser_definitions.f90
!
! NOTES
!
! CHECK: It would be useful to have a subroutine that compares strings and that is not case sensitive.
!
!##
!
!------------------------------------------------------------------------------
IMPLICIT NONE
CONTAINS
!------------------------------------------------------------------------------
FUNCTION StringLowerCase( Input_StringC ) RESULT( Output_StringC )
!------------------------------------------------------------------------------
!
!++f* String_Utility/StringLowerCase
!
! NAME
! FUNCTION StringLowerCase
!
! PURPOSE
! Converts a string into lower case.
!
! USAGE
! StringLowerCase(Input_StringC)
!
! INPUT
! o Input_StringC
!
! OUTPUT
! o Output_StringC
!
! NOTES
! Compare with SUBROUTINE LowCase (str1, str2) of MODULE fparser.
!
!##
!
!------------------------------------------------------------------------------
IMPLICIT NONE
CHARACTER(len=*) ,INTENT(in) :: Input_StringC
CHARACTER(LEN(Input_StringC)) :: Output_StringC ! RESULT
INTEGER :: i, n
! List of characters for case conversion
CHARACTER(len=*),PARAMETER :: LOWER_CASE = 'abcdefghijklmnopqrstuvwxyz'
CHARACTER(len=*),PARAMETER :: UPPER_CASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
!---------------------
! Copy input string .
!---------------------
Output_StringC = Input_StringC
!--------------------------------------
! Convert case character by character.
!--------------------------------------
DO i = 1, LEN(Output_StringC)
n = INDEX(UPPER_CASE, Output_StringC(i:i))
IF ( n > 0 ) Output_StringC(i:i) = LOWER_CASE(n:n)
END DO
!------------------------------------------------------------------------------
END FUNCTION StringLowerCase
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
FUNCTION StringUpperCase( Input_StringC ) RESULT( Output_StringC )
!------------------------------------------------------------------------------
!
!++f* String_Utility/StringUpperCase
!
! NAME
! FUNCTION StringUpperCase
!
! PURPOSE
! Converts a string into upper case.
!
! USAGE
! StringUpperCase(Input_StringC)
!
! INPUT
! o Input_StringC
!
! OUTPUT
! o Output_StringC
!
! NOTES
! Compare with SUBROUTINE LowCase (str1, str2) of MODULE fparser.
!
!##
!
!------------------------------------------------------------------------------
IMPLICIT NONE
CHARACTER(len=*) ,INTENT(in) :: Input_StringC
CHARACTER(LEN(Input_StringC)) :: Output_StringC ! RESULT
INTEGER :: i, n
! List of characters for case conversion
CHARACTER(len=*),PARAMETER :: LOWER_CASE = 'abcdefghijklmnopqrstuvwxyz'
CHARACTER(len=*),PARAMETER :: UPPER_CASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
!---------------------
! Copy input string .
!---------------------
Output_StringC = Input_StringC
!--------------------------------------
! Convert case character by character.
!--------------------------------------
DO i = 1, LEN(Output_StringC)
n = INDEX(LOWER_CASE, Output_StringC(i:i))
IF ( n > 0 ) Output_StringC(i:i) = UPPER_CASE(n:n)
END DO
!------------------------------------------------------------------------------
END FUNCTION StringUpperCase
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
FUNCTION Substring_is_contained_in_StringL(SubstringC,StringC) RESULT (is_containedL)
!------------------------------------------------------------------------------
!
!++f* String_Utility/Substring_is_contained_in_StringL
!
! NAME
! FUNCTION Substring_is_contained_in_StringL
!
! PURPOSE
! Checks if a substring is contained in a string.
! Blanks at the right of a string are ignored.
!
! USAGE
! Substring_is_contained_in_StringL(SubstringC,StringC)
!
! INPUT
! o SubstringC:
! o StringC:
!
! OUTPUT
! o is_containedL: .TRUE. if 'SubstringC' is contained in 'StringC'.
!
! NOTES
! Example: If substring 'GaAs' is contained in string 'AlAs GaAs InAs', the function returns .TRUE., else .FALSE.
!
!##
!
!------------------------------------------------------------------------------
IMPLICIT NONE
CHARACTER(len=*),INTENT(in) :: SubstringC
CHARACTER(len=*),INTENT(in) :: StringC
LOGICAL :: is_containedL ! RESULT
IF ( INDEX( TRIM(StringC) , TRIM(SubstringC) ) == 0 ) THEN
!------------------------------------------------------------------------------------------
! If INDEX == 0, then the substring 'SubstringC' is not contained in the string 'StringC'.
!------------------------------------------------------------------------------------------
is_containedL = .FALSE.
ELSE
is_containedL = .TRUE.
END IF
!------------------------------------------------------------------------------
END FUNCTION Substring_is_contained_in_StringL
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
END MODULE String_Utility
!------------------------------------------------------------------------------
!
!
!
!------------------------------------------------------------------------------
MODULE SpecialCharacters
!------------------------------------------------------------------------------
! Some compilers treat the backslash character '\' differently.
! o Intel Fortran compiler:
! "Treat Backslash as Normal Character in Strings:
! Treats backslash (\) as a normal graphic character, not an escape character."
! o PGI Fortran compiler:
! "Treat Backslash as Character": Yes
!-------------------------------------------------------------------------------
IMPLICIT NONE
!CHARACTER(len=*),PARAMETER :: BackSlashC = "\"
CHARACTER(len=*),PARAMETER :: BackSlashC = '\'
!CHARACTER(len=*),PARAMETER :: DoubleBackSlashC = "\\"
CHARACTER(len=*),PARAMETER :: DoubleBackSlashC = '\\'
!------------------------------------------------------------------------------
END MODULE SpecialCharacters
!------------------------------------------------------------------------------