Commit 15ff76ce authored by saeed's avatar saeed
Browse files

m

parent ad9619b9
......@@ -14,15 +14,15 @@ do_precise=0
do_only_monthy=1
use_report_file=0
report_type_filename="report_type_list"
list_report=(16001 16005)
list_report=(16001)
PRECISE_ODB_DIR="/scratch/ms/se/smdk/scratchdir/"
OUTPUT_DIR="/home/ms/se/smdk/odb_panel/OUTPUT"
path_cycle="/home/ms/se/smdk/odb_panel/bin/"
startdate="2017-01-01"
enddate="2017-01-02"
time_cycle="00,12"
enddate="2017-01-20"
time_cycle="21"
if [ ${use_report_file} -eq 1 ];then
......@@ -36,8 +36,8 @@ fi
checkmonthly=`ismonthly ${startdate} ${enddate}`
if [ ${do_only_monthy} -eq 1 -a ${checkmonthly} -eq 0 ];then
echo "we chose the monthly data retrieval from mars"
echo "please adjust the startdate ${startdate} or enddate ${enddate}"
echo "you chose the monthly data retrieval from mars"
echo "please adjust the startdate ${startdate} or enddate ${enddate} so that they have the same month and the same year"
exit
fi
......@@ -76,17 +76,29 @@ if [ ${do_era5} -eq 1 ];then
done
if [ ${lexist} -eq 0 ];then
echo "we are extracting odb for repportype ${vr}"
echo "==========================================="
echo "we are extracting odb for repportype ${vr} for a period ${startdate_out} ${enddate_out}"
echo "==========================================="
sed -e "s/<reptype>/${vr}/g" -e "s/<time_cycle>/${time_cycle_out}/g" -e "s/<startdate_out>/${startdate_out}/g" -e "s/<enddate_out>/${enddate_out}/g" -e "s/<startdate>/${startdate}/g" -e "s/<enddate>/${enddate}/g" request_odb_temp_era5 > request_odb_temp
mars request_odb_temp
do_filter ${fin}
if [ ! -f ${fin} ];then
echo "something went wrong in creating odb file ${fin} so we quit check your mars request"
fi
do_filter ${fin} &>/dev/null
if [ $? -ne 0 ];then
echo "some thing went wrong in odb filtering on file ${fin} so we quit"
echo "it is very likely that you have a problem with time_cycle ${time_cycle_out} so maybe you can change the cycle"
rm -f ${fin} 2>/dev/null
exit
fi
rm -f ${fin} 2>/dev/null
nc=`echo ${time_cycle} | awk -F',' '{print NF}'`
for nf in `seq 1 ${nc}`;do
vb=`echo ${time_cycle} | cut -d, -f${nf}`
${path_cycle}/era5_cycle.exe ${fout} ${vb}
fout_cycle=`output_name_cycle ${fout} ${vb}`
echo "fout_cycle ${fout_cycle}"
#echo "fout_cycle ${fout_cycle}"
mv ${fout_cycle} ${OUTPUT_DIR} 2>/dev/null
done
rm -f ${fout}
......
......@@ -112,7 +112,7 @@ static int *uniq_line(struct Line *ar, int nx, int *nout){
}
if (j == i || i == 0){
nc++;
printf("nc is %d \n",nc);
//printf("nc is %d \n",nc);
}
}
*nout = nc;
......@@ -130,12 +130,12 @@ static int *uniq_line(struct Line *ar, int nx, int *nout){
}
}
if (j == i || i == 0){
printf("%d %d\n",nt,ar[i].date);
//printf("%d %d\n",nt,ar[i].date);
result[nt] = ar[i].date;
nt++;
}
}
printf("nt %d \n",nt);
//printf("nt %d \n",nt);
}
return result;
}
......@@ -267,8 +267,8 @@ static void process(char *filename, char * ccycle){
//here we sort cont
int *undate = uniq_line(cont, nl,&nu);
printf("%d nu is \n",nu);
for (int i=0; i < nu ;++i)printf("%d\n",undate[i]);
//printf("%d nu is \n",nu);
//for (int i=0; i < nu ;++i)printf("%d\n",undate[i]);
int first = 0, last = 0;
find(".txt", cbase, &first, &last);
char cout1[512] = {'\0'};
......@@ -286,7 +286,7 @@ static void process(char *filename, char * ccycle){
concat(cout2, ccycle, cout3, LEN(cout3));
concat(cout3, "_thin.txt", cout4, LEN(cout4));
concat(cout3, ".txt", cout5, LEN(cout5));
printf("creating file %s \n",cout4);
//printf("creating file %s \n",cout4);
printf("creating file %s \n",cout5);
FILE *fout_vis = fopen(cout5,"w");
float sumg = 0;
......@@ -302,7 +302,7 @@ static void process(char *filename, char * ccycle){
fclose(fout_vis);
free(cont);
free(undate);
printf("here\n");
//printf("here\n");
}
}
......
#include<stdio.h>
#include<stdlib.h>
#define LEN(a) (sizeof(a) / sizeof(a[0]))
struct range{
float lat1, lat2, lon1, lon2;
};
static char cbase[1024] = {'\0'};
static void getbase(char *path){
char *sl = path;
char *t = path;
if (t){
while (*t != '\0'){
if (*t == '/'){
sl = t;
}
t++;
}
}
int i = 0;
if (*sl == '/'){
for (char *c = sl +1;*c; ++c){
*(cbase+i) = *c;
i++;
}
}
else{
for (char *c = sl;*c; ++c){
*(cbase+i) = *c;
i++;
}
}
*(cbase+i) = '\0';
}
static int *uniq(int *ar, int nx){
int j = 0;
int nc = 0;
int *result = NULL;
for (int i=0; i < nx;++i){
for (j=0; j < i;++j){
if (ar[j] == ar[i])break;
}
if (j == i) nc++;
}
j = 0;
if (nc > 0){
result = (int *)malloc(sizeof(int) *nc);
int nt = 0;
for (int i=0; i < nx;++i){
for (j=0; j < i;++j){
if (ar[j] == ar[i])break;
}
if (j == i) result[nt++] = ar[i];
}
}
}
static int isendofline(char c){
int result = ((c == '\n') || (c == '\r')) ? 1 : 0;
return result;
}
struct Line{
int date;
int time;
float lat;
float lon;
float obsvalue;
int varno;
int codetype;
float count;
};
struct file_content{
char **date;
float *obscount;
};
static void skipline(FILE *file, int nl){
if (file){
int nn = 0;
char c = ' ';
while(( c = fgetc(file)) != EOF){
if (isendofline(c) ) nn++;
if (nn == nl) break;
}
}
}
static int *uniq_line(struct Line *ar, int nx, int *nout){
int j = 0;
int nc = 0;
int *result = NULL;
for (int i=0; i < nx;++i){
for (j=i-1; j < i;++j){
if (i == 0 ){
break;
}
else if (ar[j].date == ar[i].date){
break;
}
}
if (j == i || i == 0){
nc++;
printf("nc is %d \n",nc);
}
}
*nout = nc;
j = 0;
if (nc > 0){
result = (int *)malloc(sizeof(int) *nc);
int nt = 0;
for (int i=0; i < nx;++i){
for (j=(i-1); j < i ;++j){
if (i == 0 ){
break;
}
else if (ar[j].date == ar[i].date){
break;
}
}
if (j == i || i == 0){
printf("%d %d\n",nt,ar[i].date);
result[nt] = ar[i].date;
nt++;
}
}
printf("nt %d \n",nt);
}
return result;
}
static long int numberoflines(FILE *file){
long int result = 0L;
if (file){
char c = ' ';
while((c = fgetc(file)) != EOF){
if (isendofline(c) ) result++;
}
}
return result;
}
static int getLen(char *str){
int result = 0;
if (str){
while(*str != '\0'){
result++;
str++;
}
}
return result;
}
static void concat(char *str1, char *str2, char *str3, int N){
char *result =str3;
int ns = getLen(str1) + getLen(str2) + 1;
if (ns < N){
while(*str1 != '\0'){
*result = *str1;
result++;
str1++;
}
while(*str2 != '\0'){
*result = *str2;
result++;
str2++;
}
*result = '\0';
}
}
static int find(char *reg, char *str, int *first, int *last){
int lnr = getLen(reg);
int lns = getLen(str);
if ( lnr == 0 || lns == 0) return -1;
if (lnr > lns) return -1;
int i = 0;
int ncount = 0;
int k = 0;
int result = -1;
int ip = 0;
for (int j=0; j < lns; ++j){
i = 0;
if (str[j] == reg[i]){
*first = j;
k = j+1;
ip = i + 1;
ncount = 1;
while(str[k] == reg[ip]){
++k;
++ip;
++ncount;
}
if (ncount == lnr){
result = j;
*last = (k-1);
break;
}
else{
}
}
}
return result;
}
static int isinrange(float lon, float lat, struct range range){
int result = 0;
if (lon >= range.lon1 && lon <= range.lon2 && lat >= range.lat1 && lat<= range.lat2 ) result = 1;
return result;
}
static void process(char *filename){
struct range range = {20.292, 75.3466,-58.105, 74.1046};
if (filename){
FILE *file = fopen(filename,"r");
getbase(filename);
if (file){
//skipline(file,1);
long int nl = numberoflines(file);
printf("number of line is %ld\n",nl);
rewind(file);
//skipline(file,1);
struct Line Line = {0};
struct Line *cont = (struct Line *)malloc(sizeof(struct Line) * nl);
for (long int i =0L; i < nl;++i){
fscanf(file,"%d%d%f%f%d%d%f",&Line.date,&Line.time,&Line.lat,&Line.lon,&Line.varno,&Line.codetype,&Line.count);
printf("%d %d %f %f %f %d %d %f\n",Line.date,Line.time,Line.lat,Line.lon,Line.obsvalue,Line.varno,Line.codetype,Line.count);
cont[i].date = Line.date;
cont[i].time = Line.time;
cont[i].lat = Line.lat;
cont[i].lon = Line.lon;
cont[i].obsvalue = Line.obsvalue;
cont[i].varno = Line.varno;
cont[i].codetype = Line.codetype;
cont[i].count = Line.count;
}
fclose(file);
int nu = 0;
//here we sort cont
int *undate = uniq_line(cont, nl,&nu);
printf("%d nu is \n",nu);
for (int i=0; i < nu ;++i)printf("undate %d\n",undate[i]);
int first = 0, last = 0;
find(".txt", cbase, &first, &last);
char cout1[512] = {'\0'};
int ns = 0;
for (int i=0; i < first;++i){
cout1[i] = cbase[i];
ns++;
}
cout1[ns] = '\0';
char cout2[512] = {'\0'};
concat(cout1, "_thin.txt", cout2, LEN(cout2));
printf("creating file %s \n",cout2);
FILE *fout = fopen(cout2,"w");
float sumg = 0;
for (int i=0; i < nu ;++i){
float sum = 0.0;
for (long int j =0L; j < nl;++j){
//printf("%d \n",isinrange(cont[j].lon,cont[j].lat,range));
if (cont[j].date == undate[i] && isinrange(cont[j].lon,cont[j].lat,range)) sum += cont[j].count;
}
fprintf(fout,"%d %f \n",undate[i],sum);
sumg += sum;
}
fclose(fout);
free(cont);
free(undate);
printf("here\n");
}
}
}
int main(int argc, char *argv[]){
if (argc == 2){
process(argv[1]);
}
else{
printf("Usage %s odb_file.txt\n",argv[0]);
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#define LEN(a) (sizeof(a) / sizeof(a[0]))
static char cbase[1024] = {'\0'};
static void getbase(char *path){
char *sl = path;
char *t = path;
if (t){
while (*t != '\0'){
if (*t == '/'){
sl = t;
}
t++;
}
}
int i = 0;
if (*sl == '/'){
for (char *c = sl +1;*c; ++c){
*(cbase+i) = *c;
i++;
}
}
else{
for (char *c = sl;*c; ++c){
*(cbase+i) = *c;
i++;
}
}
*(cbase+i) = '\0';
}
static int *uniq(int *ar, int nx){
int j = 0;
int nc = 0;
int *result = NULL;
for (int i=0; i < nx;++i){
for (j=0; j < i;++j){
if (ar[j] == ar[i])break;
}
if (j == i) nc++;
}
j = 0;
if (nc > 0){
result = (int *)malloc(sizeof(int) *nc);
int nt = 0;
for (int i=0; i < nx;++i){
for (j=0; j < i;++j){
if (ar[j] == ar[i])break;
}
if (j == i) result[nt++] = ar[i];
}
}
}
static int isendofline(char c){
int result = ((c == '\n') || (c == '\r')) ? 1 : 0;
return result;
}
struct Line{
int date;
int time;
float lat;
float lon;
float obsvalue;
int varno;
int codetype;
float count;
};
struct file_content{
char **date;
float *obscount;
};
static void skipline(FILE *file, int nl){
if (file){
int nn = 0;
char c = ' ';
while(( c = fgetc(file)) != EOF){
if (isendofline(c) ) nn++;
if (nn == nl) break;
}
}
}
static int *uniq_line(struct Line *ar, int nx, int *nout){
int j = 0;
int nc = 0;
int *result = NULL;
for (int i=0; i < nx;++i){
for (j=i-1; j < i;++j){
if (i == 0 ){
break;
}
else if (ar[j].date == ar[i].date){
break;
}
}
if (j == i || i == 0){
nc++;
printf("nc is %d \n",nc);
}
}
*nout = nc;
j = 0;
if (nc > 0){
result = (int *)malloc(sizeof(int) *nc);
int nt = 0;
for (int i=0; i < nx;++i){
for (j=(i-1); j < i ;++j){
if (i == 0 ){
break;
}
else if (ar[j].date == ar[i].date){
break;
}
}
if (j == i || i == 0){
printf("%d %d\n",nt,ar[i].date);
result[nt] = ar[i].date;
nt++;
}
}
printf("nt %d \n",nt);
}
return result;
}
static long int numberoflines(FILE *file){
long int result = 0L;
if (file){
char c = ' ';
while((c = fgetc(file)) != EOF){
if (isendofline(c) ) result++;
}
}
return result;
}
static int getLen(char *str){
int result = 0;
if (str){
while(*str != '\0'){
result++;
str++;
}
}
return result;
}
static void concat(char *str1, char *str2, char *str3, int N){
char *result =str3;
int ns = getLen(str1) + getLen(str2) + 1;
if (ns < N){
while(*str1 != '\0'){
*result = *str1;
result++;
str1++;
}