Commit b3ccd397 authored by saeed's avatar saeed
Browse files

file update

parent 12ea0249
#include<stdio.h>
#include<stdlib.h>
char Str[32] = {'\0'};
char RStr[32] = {'\0'};
static char Str[32] = {'\0'};
static char RStr[32] = {'\0'};
static void reverse(char *s, char *t, int sign, int npadzero){
......
......@@ -12,6 +12,7 @@
int main(void){
#if 0
int year_1 = 1950;
int year_2 = 2015;
int month_1 = 1;
......@@ -34,7 +35,7 @@ int main(void){
time_t tt = t1;
printf("%u\n",(t2 - t1) / 3600);
#endif
#if 0
while (tt < t2){
info = gmtime(&tt);
......@@ -42,5 +43,11 @@ int main(void){
tt += incr;
}
#endif
time_t tnow = time(NULL);
struct tm *snow = gmtime(&tnow);;
SHOWT(snow);
return 0;
}
......@@ -57,6 +57,22 @@ extern "C" {
#include"haversin.c"
static int isfileexist(char *filename){
int result = 0;
if (filename){
FILE *file = fopen(filename,"rb");
if (file){
result = 1;
(void)fclose(file);
}
}
return result;
}
static double minval(double *ds, int *io, int *jo,float maskval){
double mins = 0.0;
......@@ -82,7 +98,14 @@ static double minval(double *ds, int *io, int *jo,float maskval){
return mins;
}
static void read_meshmask(char *filename){
static int read_meshmask(char *filename){
int result = isfileexist(filename);
if (result == 0){
printf("file %s does not exist so we exit\n",filename);
return result;
}
int ncid, ilat, ilon, imask;
char *varlat = "nav_lat", *varlon = "nav_lon", *varmask = "tmaskutil";
......@@ -96,6 +119,8 @@ static void read_meshmask(char *filename){
nc_get_var(ncid, ilon,&nlon[0]);
nc_close(ncid);
return result;
}
......@@ -314,8 +339,10 @@ int main(int argc, char *argv[]){
char string2[512] = {'\0'};
char string3[512] = {'\0'};
read_meshmask("mesh_mask.nc");
int imask = read_meshmask("mesh_mask.nc");
if (imask == 0) return 1;
int npt = 0;
while(fscanf(file,"%s %s %s",string,string1,string2) && !feof(file)) npt++;
struct Index *ind_pt = (struct Index *)malloc(sizeof(struct Index) * npt);
......
......@@ -122,6 +122,14 @@ static struct meta_extra getextrameta(float lat, float lon,struct s_time *first,
char cmin2[3] = {'\0'};
char csec2[3] = {'\0'};
char cyear3[5] = {'\0'};
char cmon3[3] = {'\0'};
char cday3[3] = {'\0'};
char chour3[3] = {'\0'};
char cmin3[3] = {'\0'};
char csec3[3] = {'\0'};
intostr_pad(first->year,cyear1,0);
intostr_pad(last->year,cyear2,0);
......@@ -190,6 +198,44 @@ static struct meta_extra getextrameta(float lat, float lon,struct s_time *first,
writetostring(result.tstart,sizeof(result.tstart),cyear1,"-",cmon1,"-",cday1,"T",chour1,":",cmin1,":",csec1,"Z",NULL);
writetostring(result.tend,sizeof(result.tend),cyear2,"-",cmon2,"-",cday2,"T",chour2,":",cmin2,":",csec2,"Z",NULL);
time_t tnow = time(NULL);
struct tm *snow = gmtime(&tnow);;
intostr_pad(snow->tm_year + 1900,cyear3,0);
if ((snow->tm_mon +1)< 10 ) {
intostr_pad((snow->tm_mon +1),cmon3,1);
}
else{
intostr_pad((snow->tm_mon +1),cmon3,0);
}
if (snow->tm_mday < 10 ) {
intostr_pad(snow->tm_mday,cday3,1);
}
else{
intostr_pad(snow->tm_mday,cday3,0);
}
if (snow->tm_hour < 10 ) {
intostr_pad(snow->tm_hour,chour3,1);
}
else{
intostr_pad(snow->tm_hour,chour3,0);
}
if (snow->tm_min < 10 ) {
intostr_pad(snow->tm_min,cmin3,1);
}
else{
intostr_pad(snow->tm_min,cmin3,0);
}
if (snow->tm_sec < 10 ) {
intostr_pad(snow->tm_sec,csec3,1);
}
else{
intostr_pad(snow->tm_sec,csec3,0);
}
writetostring(result.create,sizeof(result.create),cyear3,"-",cmon3,"-",cday3," ",chour3,":",cmin3,":",csec3,NULL);
return result;
}
......
......@@ -62,11 +62,11 @@ static void write_nc_a(char *varname[], struct Index *ind, float *val, double *v
int idt;
int idtime;
int iz;
int dimvar[] = {0,0,0,0,0};
int dimvar[] = {0,0};
float *temp = (float *)malloc(sizeof(float) * nd1 * nd3);
int *idvar = (int *)malloc(sizeof(int) * nvar);
int ilon, ilat, ipos;
int idvh, idvlat, idvlon, idvpos;
struct sc sref = formatreftime(&stimeref);
struct meta_coor meta_time[] = {
{"long_name","time",0.0,0,'s'},
......@@ -98,17 +98,13 @@ static void write_nc_a(char *varname[], struct Index *ind, float *val, double *v
dimvar[0] = idt;
dimvar[1] = iz;
dimvar[2] = ilat;
dimvar[3] = ilon;
dimvar[4] = ipos;
int idvh, idvlat, idvlon, idvpos;
nc_def_var(ncid, "TIME", NC_DOUBLE, 1, &dimvar[0], &idtime);
nc_def_var(ncid, "DEPTH", NC_FLOAT, 1, &dimvar[1], &idvh);
nc_def_var(ncid, "LATITUDE", NC_FLOAT, 1, &dimvar[2], &idvlat);
nc_def_var(ncid, "LONGITUDE", NC_FLOAT, 1, &dimvar[3], &idvlon);
nc_def_var(ncid, "POSITION_QC", NC_BYTE, 1, &dimvar[4], &idvpos);
nc_def_var(ncid, "LATITUDE", NC_FLOAT, 1, &ilat, &idvlat);
nc_def_var(ncid, "LONGITUDE", NC_FLOAT, 1, &ilon, &idvlon);
nc_def_var(ncid, "POSITION_QC", NC_BYTE, 1, &ipos, &idvpos);
add_metatocoor(ncid, idtime,meta_time,ARRLEN(meta_time));
add_metatocoor(ncid, idvh,meta_depth,ARRLEN(meta_depth));
......@@ -128,14 +124,15 @@ static void write_nc_a(char *varname[], struct Index *ind, float *val, double *v
}
struct meta_extra meta = getextrameta((ind + i)->lat,(ind + i)->lon,s_time_first,s_time_last);
if (0){
printf("latmin %s\n",meta.latmin);
printf("latmax %s\n",meta.latmax);
printf("lonmin %s\n",meta.lonmin);
printf("lonmax %s\n",meta.lonmax);
printf("tstart %s\n",meta.tstart);
printf("tend %s\n",meta.tend);
}
printf("latmin %s\n",meta.latmin);
printf("latmax %s\n",meta.latmax);
printf("lonmin %s\n",meta.lonmin);
printf("lonmax %s\n",meta.lonmax);
printf("tstart %s\n",meta.tstart);
printf("tend %s\n",meta.tend);
struct global_meta_extra glb_common_extra [] =
{{"wmo_platform_code",(ind + i)->name},
{"geospatial_lat_min",meta.latmin},
......@@ -143,7 +140,8 @@ static void write_nc_a(char *varname[], struct Index *ind, float *val, double *v
{"geospatial_lon_min",meta.lonmin},
{"geospatial_lon_max",meta.lonmax},
{"time_coverage_start",meta.tstart},
{"time_coverage_end",meta.tend}
{"time_coverage_end",meta.tend},
{"creation_date",meta.create}
};
for (int ig=0; ig < ARRLEN(glb_common_extra);++ig){
......@@ -166,6 +164,15 @@ static void write_nc_a(char *varname[], struct Index *ind, float *val, double *v
}
}
}
float latstn[] = {(ind + i)->lat};
float lonstn[] = {(ind + i)->lon};
printf("%f %f\n",(ind + i)->lat,(ind + i)->lon);
nc_put_var(ncid, idvlat,&latstn[0]);
nc_put_var(ncid, idvlon,&lonstn[0]);
signed char pos[] = {1};
nc_put_var(ncid, idvpos, &pos[0]);
size_t indext[] = {0};
for (int j=0; j < nd1;++j){
for (int k=0; k < nd3;++k){
......
Markdown is supported
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