Commit 0945614c authored by saeed's avatar saeed
Browse files

some modification

parent 1b8f4045
#!/bin/bash #!/bin/bash
iobs=1
isvg=1
issh=1 issh=1
iobs=0
isvg=0
if [ $issh -eq 1 ];then if [ $issh -eq 1 ];then
......
...@@ -164,7 +164,7 @@ int main(int argc,char *argv[]) ...@@ -164,7 +164,7 @@ int main(int argc,char *argv[])
} }
#if sort #if sort
sortfull(atime,adata,icom); sortfull(atime,adata,icom);
#endif #endif
......
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
#define LF (64) #define LF (64)
typedef struct Data{
int *icontent;
float *fcontent;
}Data;
long int numLines(FILE *FS){ long int numLines(FILE *FS){
long int nl = 0L; long int nl = 0L;
int c = 0; int c = 0;
...@@ -43,19 +49,7 @@ int Strcmp(char *sa, char *sb){ ...@@ -43,19 +49,7 @@ int Strcmp(char *sa, char *sb){
} }
} }
int main(int argc, char *argv[]){ int Readsshcsv(char *filename, char *station, int idbeg, int idend, Data *sshdata){
if (argc != 5){
printf("Usage %s filename stationame startdate(YYYYMMDDHH) enddate(YYYYMMDDHH)\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; FILE *FS = NULL;
FS = fopen(filename,"r"); FS = fopen(filename,"r");
...@@ -117,14 +111,14 @@ int main(int argc, char *argv[]){ ...@@ -117,14 +111,14 @@ int main(int argc, char *argv[]){
nl = 0; nl = 0;
int nit = 0; int nit = 0;
int ifld = 0; int ifld = 0;
int *icontent = NULL; sshdata->icontent = NULL;
float *fcontent = NULL; sshdata->fcontent = NULL;
int ic = 0; int ic = 0;
for (int i=0; i < nfl; ++i){ for (int i=0; i < nfl; ++i){
if (Strcmp(cfl[i],station)){ if (Strcmp(cfl[i],station)){
ic = i; ic = i;
icontent = malloc(sizeof(int) *(nline -1)); sshdata->icontent = malloc(sizeof(int) *(nline -1));
fcontent = malloc(sizeof(float) *(nline -1)); sshdata->fcontent = malloc(sizeof(float) *(nline -1));
while ((cc=fgetc(FS)) != EOF){ while ((cc=fgetc(FS)) != EOF){
if (cc != ','){ if (cc != ','){
if(cc=='\n'){ if(cc=='\n'){
...@@ -139,8 +133,8 @@ int main(int argc, char *argv[]){ ...@@ -139,8 +133,8 @@ int main(int argc, char *argv[]){
} }
} }
else{ else{
if (ifld == 0) icontent[nl] = atoi(ifield); if (ifld == 0) sshdata->icontent[nl] = atoi(ifield);
if (ic == ifld )fcontent[nl] = atof(field); if (ic == ifld )sshdata->fcontent[nl] = atof(field);
ifld += 1; ifld += 1;
ne=0; ne=0;
} }
...@@ -148,29 +142,29 @@ int main(int argc, char *argv[]){ ...@@ -148,29 +142,29 @@ int main(int argc, char *argv[]){
} }
} }
if (icontent == NULL || fcontent == NULL){ if (sshdata->icontent == NULL || sshdata->fcontent == NULL){
printf("something went wrong. Perhaps the station %s is not in the csv file %s\n",station,filename); printf("something went wrong. Perhaps the station %s is not in the csv file %s\n",station,filename);
return 1;
fclose(FS); fclose(FS);
return 1;
} }
fclose(FS); fclose(FS);
int ii = 0; int ii = 0;
int ia = -1, ib = -1; int ia = -1, ib = -1;
for(int i=0; i < (nline-1);++i){ for(int i=0; i < (nline-1);++i){
if (icontent[i] == 0 ){ if (sshdata->icontent[i] == 0 ){
ii = i; ii = i;
break; break;
} }
} }
for(int i=0; i < (ii+1);++i){ for(int i=0; i < (ii+1);++i){
if (icontent[i] == idbeg){ if (sshdata->icontent[i] == idbeg){
ia = i; ia = i;
break; break;
} }
} }
for(int i=0; i < (ii+1);++i){ for(int i=0; i < (ii+1);++i){
if (icontent[i] == idend){ if (sshdata->icontent[i] == idend){
ib = i; ib = i;
break; break;
} }
...@@ -184,12 +178,35 @@ int main(int argc, char *argv[]){ ...@@ -184,12 +178,35 @@ int main(int argc, char *argv[]){
return 1; return 1;
} }
for (int i=ia; i <= ib;++i){ for (int i=ia; i <= ib;++i){
printf("%d\t%f\n",icontent[i],fcontent[i]); printf("%d\t%f\n",sshdata->icontent[i],sshdata->fcontent[i]);
} }
free(cfl); free(cfl);
free(icontent);
free(fcontent); return 0;
}
int main(int argc, char *argv[]){
if (argc != 5){
printf("Usage %s filename stationame startdate(YYYYMMDDHH) enddate(YYYYMMDDHH)\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);
Data sshdata = {NULL, NULL};
Readsshcsv(filename, station, idbeg, idend, &sshdata);
free(sshdata.icontent);
free(sshdata.fcontent);
return 0; return 0;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment