-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.F90
More file actions
67 lines (66 loc) · 2.7 KB
/
main.F90
File metadata and controls
67 lines (66 loc) · 2.7 KB
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
!> authors: Vikas Sharma, Ph. D.
! date: 2021-11-07
! update: 2021-11-07
! summary: This code reads a markdown file and extracts the fortran code
PROGRAM main
USE easifemBase
USE easifemClasses
IMPLICIT NONE
TYPE(TxtFile_) :: srcfile, mdfile
INTEGER(I4B), PARAMETER :: maxStrLen = 1024
CHARACTER(LEN=maxStrLen) :: mdfilename
CHARACTER(LEN=maxStrLen) :: srcfilename
CHARACTER(LEN=*), PARAMETER :: modname = "md2src"
CHARACTER(LEN=*), PARAMETER :: myname = "main"
TYPE(CommandLineInterface_) :: cli
INTEGER(I4B) :: error
!> main
! initializing Command Line Interface
CALL cli%initiate( &
& progname='md2src', &
& version='v23.1.0', &
& authors='Vikas Sharma, Ph.D.', &
& license='MIT', &
& description='Extract code from the markdown file and create a source file.',&
& examples=[ &
& 'md2src ', &
& 'md2src -h ', &
& 'md2src --input inputFile.md --output outFile.F90 ', &
& 'md2src -i inputFile.md -o outFile.F90 ', &
& 'md2src --version ', &
& 'md2src -v '])
CALL cli%add(switch='--input',switch_ab='-i',help='name of input markdown file',&
& required=.TRUE., act='store', error=error)
IF (error .NE. 0) &
& CALL e%raiseError(modName//"::"//myName//" - "// &
& 'cannot add value of --input from CLI')
!> handling output
CALL cli%add(switch='--output',switch_ab='-o',help='name of output source file',&
& required=.FALSE., act='store', def='default', error=error)
IF (error .NE. 0) &
& CALL e%raiseError(modName//"::"//myName//" - "// &
& 'cannot add value of --output from CLI')
CALL cli%get(switch='-i', val=mdfilename, error=error)
IF (error .NE. 0) &
& CALL e%raiseError(modName//"::"//myName//" - "// &
& 'cannot get value of --input from CLI')
CALL e%raiseInformation(modName//"::"//myName//" - "// &
& 'Parsing markdown file : '//TRIM(mdfilename))
CALL mdfile%Initiate(filename=mdfilename, STATUS="OLD", ACTION="READ")
CALL mdfile%OPEN()
CALL cli%get(switch='-o', val=srcfilename, error=error)
IF (error .NE. 0) &
& CALL e%raiseError(modName//"::"//myName//" - "// &
& 'cannot get value of --output from CLI')
IF (TRIM(srcfilename) .EQ. 'default') THEN
srcfilename = TRIM(mdfile%getFilePath())//TRIM(mdfile%getFileName())//".F90"
END IF
CALL e%raiseInformation(modName//"::"//myName//" - "// &
& 'Results will be written to file : '//TRIM(srcfilename))
CALL srcfile%Initiate(filename=srcfilename, status="REPLACE", &
& ACTION="WRITE")
CALL srcfile%OPEN()
CALL mdfile%ConvertMarkdownToSource(outfile=srcfile)
CALL mdfile%DEALLOCATE()
CALL srcfile%DEALLOCATE()
END PROGRAM main