Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
saeed
SSHC
Commits
bf2ba525
Commit
bf2ba525
authored
Mar 15, 2018
by
saeed
Browse files
sshval now read both time and data at the same time
parent
569c9ebb
Changes
1
Hide whitespace changes
Inline
Side-by-side
sshval.c
View file @
bf2ba525
#include<stdio.h>
#include<stdlib.h>
#include"svg.h"
#include<math.h>
#include"svgplot.h"
#define LF 2
56
#define LF
3
2
long
int
numLines
(
FILE
*
FS
){
long
int
nl
=
0L
;
int
c
=
0
;
while
((
c
=
getc
(
FS
))
!=
EOF
){
while
((
c
=
f
getc
(
FS
))
!=
EOF
){
if
(
c
==
'\n'
){
nl
+=
1
;
}
...
...
@@ -46,13 +46,17 @@ int Strcmp(char *sa, char *sb){
int
main
(
int
argc
,
char
*
argv
[]){
if
(
argc
!=
3
){
if
(
argc
!=
5
){
printf
(
"Usage %s filename (stationame)
\n
"
,
argv
[
0
]);
return
1
;
}
char
*
filename
=
argv
[
1
];
char
*
station
=
argv
[
2
];
char
*
datebeg
=
argv
[
3
];
char
*
datend
=
argv
[
4
];
int
idbeg
=
atoi
(
datebeg
);
int
idend
=
atoi
(
datend
);
FILE
*
FS
=
NULL
;
FS
=
fopen
(
filename
,
"r"
);
...
...
@@ -60,14 +64,16 @@ int main(int argc, char *argv[]){
printf
(
"error in opening the file %s
\n
"
,
filename
);
return
1
;
}
long
int
nline
=
numLines
(
FS
);
char
cc
=
' '
;
char
field
[
LF
]
=
""
;
char
ifield
[
LF
]
=
""
;
int
ne
=
0
;
int
nfl
=
0
;
int
nl
=
0
;
//Here we calculate the number of the field from the header
//Here we calculate the number of the field from the
CSV
header
while
((
cc
=
fgetc
(
FS
))
!=
EOF
){
if
(
cc
!=
','
){
if
(
cc
==
'\n'
){
...
...
@@ -79,12 +85,10 @@ int main(int argc, char *argv[]){
nfl
+=
1
;
}
}
printf
(
"number of fields is %d
\n
"
,
nfl
);
//printf("number of fields is %d \n", nfl);
rewind
(
FS
);
char
**
cfl
=
malloc
(
sizeof
(
char
*
)
*
nfl
);
char
**
cfl
=
malloc
(
sizeof
(
char
*
)
*
nfl
);
// each field is a array of character array
nfl
=
0
;
nl
=
0
;
...
...
@@ -115,63 +119,89 @@ int main(int argc, char *argv[]){
//now we read date time;
ne
=
0
;
int
ifld
=
0
;
nl
=
0
;
int
nit
=
0
;
int
ifld
=
0
;
int
*
icontent
=
NULL
;
float
*
fcontent
=
NULL
;
int
ic
=
0
;
for
(
int
i
=
0
;
i
<
nfl
;
++
i
){
if
(
Strcmp
(
cfl
[
i
],
station
)){
ic
=
i
;
if
(
ic
==
0
){
icontent
=
malloc
(
sizeof
(
int
)
*
(
nline
-
1
));
}
if
(
ic
>
0
)
{
fcontent
=
malloc
(
sizeof
(
float
)
*
(
nline
-
1
));
}
printf
(
"%d
\t
%s
\n
"
,
i
,
cfl
[
i
]);
icontent
=
malloc
(
sizeof
(
int
)
*
(
nline
-
1
));
fcontent
=
malloc
(
sizeof
(
float
)
*
(
nline
-
1
));
while
((
cc
=
fgetc
(
FS
))
!=
EOF
){
if
(
cc
!=
','
){
if
(
cc
==
'\n'
){
ne
=
0
;
nit
=
0
;
nl
+=
1
;
ifld
=
0
;
}
else
{
if
(
ic
==
ifld
)
{
field
[
ne
]
=
cc
;
ne
+=
1
;}
if
(
ic
==
ifld
)
{
field
[
ne
]
=
cc
;
ne
+=
1
;}
if
(
ifld
==
0
)
{
ifield
[
nit
]
=
cc
;
nit
+=
1
;}
}
}
else
{
if
(
ic
==
ifld
)
{
if
(
ic
==
0
)
icontent
[
nl
]
=
atoi
(
field
);
if
(
ic
>
0
)
fcontent
[
nl
]
=
atof
(
field
);
}
if
(
ifld
==
0
)
icontent
[
nl
]
=
atoi
(
ifield
);
if
(
ic
==
ifld
)
fcontent
[
nl
]
=
atof
(
field
);
ifld
+=
1
;
ne
=
0
;
}
}
}
}
if
(
icontent
==
NULL
&&
ic
==
0
)
printf
(
"something wrong happend. perhaps the station %s is not in the csv file %s
\n
"
,
station
,
filename
);
if
(
fcontent
==
NULL
&&
ic
>
0
)
printf
(
"something wrong happend. perhaps the station %s is not in the csv file %s
\n
"
,
station
,
filename
);
if
(
icontent
==
NULL
||
fcontent
==
NULL
){
printf
(
"something went wrong. Perhaps the station %s is not in the csv file %s
\n
"
,
station
,
filename
);
return
1
;
fclose
(
FS
);
}
fclose
(
FS
);
int
ii
=
0
;
int
ia
=
0
,
ib
=
0
;
for
(
ii
=
0
;
ii
<
(
nline
-
1
);
++
ii
){
if
(
icontent
[
ii
]
==
0
)
break
;
}
for
(
ia
=
0
;
ia
<
(
ii
+
1
);
++
ia
){
if
(
icontent
[
ia
]
==
idbeg
)
break
;
}
for
(
int
i
=
0
;
i
<
(
nline
-
1
);
++
i
){
if
(
icontent
!=
NULL
&&
ic
==
0
&&
icontent
[
i
]
!=
0
)
printf
(
"%d
\n
"
,
icontent
[
i
]);
if
(
fcontent
!=
NULL
&&
ic
>
0
)
printf
(
"%f
\n
"
,
fcontent
[
i
]);
for
(
ib
=
0
;
ib
<
(
ii
+
1
);
++
ib
){
if
(
icontent
[
ib
]
==
idend
)
break
;
}
printf
(
"%d
\t
%ld
\t
%d
\t
%d
\n
"
,
ii
,(
nline
-
1
),
ia
,
ib
);
if
(
fcontent
!=
NULL
&&
ic
>
0
){
create_svg
(
fcontent
,
nline
);
for
(
int
i
=
ia
;
i
<=
ib
;
++
i
){
printf
(
"%d
\t
%f
\n
"
,
icontent
[
i
],
fcontent
[
i
]);
}
free
(
cfl
);
float
rmax
=
sfmax
(
fcontent
,
ii
+
1
);
float
rmin
=
sfmin
(
fcontent
,
ii
+
1
);
//printf("%f\t%f\n",rmin,rmax);
svgmeta
svgm
;
if
(
icontent
!=
NULL
)
free
(
icontent
);
if
(
fcontent
!=
NULL
)
free
(
fcontent
);
FILE
*
filsvg
=
svg_init
(
900
,
600
,
0
.
0
,(
float
)(
ii
+
1
),
rmin
,
rmax
,
"ssh.html"
,
&
svgm
);
float
*
xax
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
(
ii
+
1
));
for
(
int
i
=
0
;
i
<
(
ii
+
1
);
++
i
)
xax
[
i
]
=
(
float
)(
i
);
if
(
filsvg
!=
NULL
){
svg_add
(
filsvg
,
xax
,
fcontent
,(
ii
+
1
),
&
svgm
);
svg_close
(
filsvg
);
}
free
(
cfl
);
free
(
icontent
);
free
(
fcontent
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment