Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
avalanche
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Community
avalanche
Commits
be0c0ec4
Commit
be0c0ec4
authored
2 years ago
by
Matti Rauter
Browse files
Options
Downloads
Patches
Plain Diff
Removed regex from gistools. Fixes issue
#5
parent
8f0055e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/avalanche/gistools/gridfile.C
+29
-24
29 additions, 24 deletions
src/avalanche/gistools/gridfile.C
with
29 additions
and
24 deletions
src/avalanche/gistools/gridfile.C
+
29
−
24
View file @
be0c0ec4
...
@@ -34,7 +34,7 @@ Author
...
@@ -34,7 +34,7 @@ Author
#include
<sstream>
#include
<sstream>
#include
<limits>
#include
<limits>
#include
<cmath>
#include
<cmath>
#include
<regex>
//
#include <regex>
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
...
@@ -139,11 +139,11 @@ int gridfile::read(std::string filename)
...
@@ -139,11 +139,11 @@ int gridfile::read(std::string filename)
std
::
ifstream
pFile
(
filename
);
std
::
ifstream
pFile
(
filename
);
if
(
!
pFile
.
is_open
())
if
(
!
pFile
.
is_open
())
{
{
if
(
debug
)
log
()
<<
"Cannot open file
\"
"
<<
filename
<<
"
\"
"
<<
std
::
endl
;
return
0
;
return
0
;
}
}
std
::
string
line
;
std
::
string
line
;
std
::
smatch
match
;
bool
readheader
=
true
;
bool
readheader
=
true
;
...
@@ -152,54 +152,59 @@ int gridfile::read(std::string filename)
...
@@ -152,54 +152,59 @@ int gridfile::read(std::string filename)
{
{
std
::
getline
(
pFile
,
line
);
std
::
getline
(
pFile
,
line
);
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"^ncols
\\
s*(
\\
S*)$"
))
)
if
(
line
.
find
(
"ncols"
)
!=
std
::
string
::
npos
)
{
{
this
->
ncols_
=
std
::
stod
(
match
[
1
]
);
this
->
ncols_
=
std
::
stod
(
line
.
substr
(
5
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"^nrows
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"nrows"
)
!=
std
::
string
::
npos
)
{
{
this
->
nrows_
=
std
::
stod
(
match
[
1
]
);
this
->
nrows_
=
std
::
stod
(
line
.
substr
(
5
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"
^
xllcorner
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"xllcorner
"
)
!=
std
::
string
::
npos
)
{
{
offsetFromCornerToCenter
=
true
;
offsetFromCornerToCenter
=
true
;
this
->
xllcenter_
=
std
::
stod
(
match
[
1
]
);
this
->
xllcenter_
=
std
::
stod
(
line
.
substr
(
9
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"
^
xllcenter
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"xllcenter
"
)
!=
std
::
string
::
npos
)
{
{
this
->
xllcenter_
=
std
::
stod
(
match
[
1
]
);
this
->
xllcenter_
=
std
::
stod
(
line
.
substr
(
9
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"
^
yllcorner
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"yllcorner
"
)
!=
std
::
string
::
npos
)
{
{
offsetFromCornerToCenter
=
true
;
offsetFromCornerToCenter
=
true
;
this
->
yllcenter_
=
std
::
stod
(
match
[
1
]
);
this
->
yllcenter_
=
std
::
stod
(
line
.
substr
(
9
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"
^
yllcenter
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"yllcenter
"
)
!=
std
::
string
::
npos
)
{
{
this
->
yllcenter_
=
std
::
stod
(
match
[
1
]
);
this
->
yllcenter_
=
std
::
stod
(
line
.
substr
(
9
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"
^
cellsize
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"cellsize
"
)
!=
std
::
string
::
npos
)
{
{
this
->
dx_
=
std
::
stod
(
match
[
1
]
);
this
->
dx_
=
std
::
stod
(
line
.
substr
(
9
)
);
this
->
dy_
=
std
::
stod
(
match
[
1
]
);
this
->
dy_
=
std
::
stod
(
line
.
substr
(
9
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"^dx
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"dx"
)
!=
std
::
string
::
npos
)
{
{
this
->
dx_
=
std
::
stod
(
match
[
1
]
);
this
->
dx_
=
std
::
stod
(
line
.
substr
(
2
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"^dy
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"dy"
)
!=
std
::
string
::
npos
)
{
{
this
->
dy_
=
std
::
stod
(
match
[
1
]
);
this
->
dy_
=
std
::
stod
(
line
.
substr
(
2
)
);
}
}
else
if
(
std
::
regex_match
(
line
,
match
,
std
::
regex
(
"
^
NODATA_value
\\
s*(
\\
S*)$"
))
)
else
if
(
line
.
find
(
"NODATA_value
"
)
!=
std
::
string
::
npos
)
{
{
this
->
NODATA_value_
=
std
::
stod
(
match
[
1
]
);
this
->
NODATA_value_
=
std
::
stod
(
line
.
substr
(
12
)
);
readheader
=
false
;
readheader
=
false
;
}
}
else
{
if
(
debug
)
log
()
<<
"Skipping line "
<<
line
<<
std
::
endl
;
}
}
}
if
(
this
->
ncols_
<
1
||
this
->
nrows_
<
1
)
if
(
this
->
ncols_
<
1
||
this
->
nrows_
<
1
)
{
{
if
(
debug
)
log
()
<<
"Number of columns ("
<<
this
->
ncols_
<<
") or number of rows ("
<<
this
->
nrows_
<<
") invalid."
<<
std
::
endl
;
return
0
;
return
0
;
}
}
...
@@ -218,7 +223,6 @@ int gridfile::read(std::string filename)
...
@@ -218,7 +223,6 @@ int gridfile::read(std::string filename)
unsigned
int
i
=
0
,
j
=
0
;
unsigned
int
i
=
0
,
j
=
0
;
std
::
regex
e
(
"(
\\
S+)"
);
while
(
!
pFile
.
eof
()
&&
i
<
this
->
nrows_
)
while
(
!
pFile
.
eof
()
&&
i
<
this
->
nrows_
)
{
{
if
(
debug
)
log
()
<<
"Reading line "
<<
i
<<
"/"
<<
this
->
nrows_
<<
std
::
endl
;
if
(
debug
)
log
()
<<
"Reading line "
<<
i
<<
"/"
<<
this
->
nrows_
<<
std
::
endl
;
...
@@ -226,6 +230,7 @@ int gridfile::read(std::string filename)
...
@@ -226,6 +230,7 @@ int gridfile::read(std::string filename)
std
::
getline
(
pFile
,
line
);
std
::
getline
(
pFile
,
line
);
j
=
0
;
j
=
0
;
#if 0
#if 0
std::regex e("(\\S+)");
// The following part is very flexible but slow
// The following part is very flexible but slow
while (std::regex_search (line, match, e) and j < this->ncols) {
while (std::regex_search (line, match, e) and j < this->ncols) {
try
try
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment