Changeset 151 for altifloat/src
- Timestamp:
- 07/02/15 10:08:35 (9 years ago)
- Location:
- altifloat/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
altifloat/src/floater.h
r147 r151 1 1 #define UPDATE_BCK 2 3 #include <netcdf.h> 2 4 3 5 //constantes … … 21 23 YREAL umod[nlon][nlat][jptfl]; 22 24 YREAL vmod[nlon][nlat][jptfl]; 25 YREAL uwind[nlon][nlat][jptfl]; 26 YREAL vwind[nlon][nlat][jptfl]; 23 27 24 28 //Background … … 47 51 #endif 48 52 #endif 53 54 #define ERR(e) {fprintf(stderr,"Error: %s\n", nc_strerror(e)); exit(EXIT_FAILURE);} 55 #define LONDIM "lon_interp" 56 #define LATDIM "lat_interp" 57 #define UVAR "u10_f" 58 #define VVAR "v10_f" 49 59 50 60 //Options du run incr士ental … … 61 71 void run_inc(int argv, char *argc[]); 62 72 void div_init(); 73 void init_wind(char fname[],int iter0,int *ptime0); 63 74 64 75 void appli_start(int argc, char *argv[]){ … … 195 206 196 207 } 208 209 void load_wind(int argv, char *argc[]) { 210 /* load_wind windname iter0 time0 211 load a wind netcdfile ( from ERAI) 212 time0 is the time of the first iteration considered in the file 213 (by default time0 is time(0) field in the netcdf file) 214 iter0 is the timestep corresponding to time0. 215 (by default iter0 is 0) 216 */ 217 if ((argv<2) | (argv >4)) { 218 fprintf(stderr,"(load_wind): wrong number of arguments\n"); 219 return; 220 } 221 222 //time0 is a pointer to pass the NULL address in case time0 is 223 //not specified in the call of the function 224 int *time0=NULL; 225 226 int iter0=0; 227 char fname[50]; 228 sprintf(fname,argc[1]); 229 if (argv > 2) { 230 iter0 = atoi(argc[2]); 231 if (argv > 3) 232 *time0 = atoi(argc[3]); 233 } 234 init_wind(fname,iter0,time0); 235 } 236 237 void init_wind(char fname[],int iter0,int *ptime0) { 238 int ncid,retval; 239 int dlatid,dlonid,dtimeid; 240 int latid,lonid,timeid,u10id,v10id; 241 size_t Nlon,Nlat,Ntime; 242 if ((retval = nc_open(fname,NC_NOWRITE, &ncid))) 243 ERR(retval); 244 if ((retval = nc_inq_dimid(ncid,LONDIM,&dlonid))) 245 ERR(retval); 246 if ((retval = nc_inq_dimid(ncid,LATDIM,&dlatid))) 247 ERR(retval); 248 if ((retval = nc_inq_dimid(ncid,"time",&dtimeid))) 249 ERR(retval); 250 if ((retval = nc_inq_dimlen(ncid,dlonid,&Nlon))) 251 ERR(retval); 252 if ((retval = nc_inq_dimlen(ncid,dlatid,&Nlat))) 253 ERR(retval); 254 if ((retval = nc_inq_dimlen(ncid,dtimeid,&Ntime))) 255 ERR(retval); 256 257 if ((Nlon != nlon) | (Nlat != nlat)) { 258 fprintf(stderr, 259 "(init_wind) Wrong dimension (nlat=%d,nlon=%d) for the wind_field %s\n", 260 (int)Nlat, (int)Nlon, fname); 261 } 262 if ((retval = nc_inq_varid(ncid,LATDIM,&latid))) 263 ERR(retval); 264 if ((retval = nc_inq_varid(ncid,LONDIM,&lonid))) 265 ERR(retval); 266 if ((retval = nc_inq_varid(ncid,"time",&timeid))) 267 ERR(retval); 268 if ((retval = nc_inq_varid(ncid,UVAR,&u10id))) 269 ERR(retval); 270 if ((retval = nc_inq_varid(ncid,VVAR,&v10id))) 271 ERR(retval); 272 273 int time[Ntime]; 274 float u10[Ntime][nlat][nlon]; 275 float v10[Ntime][nlat][nlon]; 276 277 if ((retval = nc_get_var_int(ncid,timeid,&time[0]))) 278 ERR(retval); 279 280 if ((retval = nc_get_var_float(ncid,u10id,&u10[0][0][0]))) 281 ERR(retval); 282 283 if ((retval = nc_get_var_float(ncid,v10id,&v10[0][0][0]))) 284 ERR(retval); 285 286 //Load time dimensions 287 if (ptime0 == NULL) 288 { 289 ptime0 = (int *)malloc(sizeof(int)); 290 *ptime0 = time[0]; 291 } 292 293 //Copy arrays 294 int nt=0; 295 int realtime=*ptime0; //time value from time (in hour) 296 int timeindex=iter0; //time index for uwind and vwind 297 int it; 298 YREAL alpha; //interp coefficient 299 for (it=0;it<(int)Ntime-1;it++) { 300 301 // ionterp whil relatime is between 2 step time 302 while (time[it]<=realtime && time[it+1]>realtime) { 303 304 305 if (timeindex >= jptfl) { 306 fprintf(stderr,"(init_wind) Warning: time values in %s don't fill the jptfl\n",fname); 307 return; 308 } 309 alpha = ((double)realtime - time[it])/(time[it+1]-time[it]); 310 for (int ilon=0;ilon<nlon;ilon++) 311 for (int ilat=0;ilat<nlat;ilat++) { 312 uwind[ilon][ilat][timeindex] = (1-alpha)*u10[it][ilat][ilon] + alpha*u10[it+1][ilat][ilon]; 313 vwind[ilon][ilat][timeindex] = (1-alpha)*v10[it][ilat][ilon] + alpha*v10[it+1][ilat][ilon]; 314 315 } 316 //To avoid cumulative rounding mistake, realtime is calculate with : 317 nt++; 318 realtime = *ptime0 + nt*(double)rdtflo/3600; 319 timeindex ++; 320 321 } //while time[it]<=realtime 322 } //for it 323 if (time[it]==realtime && timeindex < jptfl ) //last step time 324 { 325 for (int ilon=0;ilon<nlon;ilon++) 326 for (int ilat=0;ilat<nlat;ilat++) { 327 uwind[ilon][ilat][timeindex] = u10[it][ilat][ilon] ; 328 vwind[ilon][ilat][timeindex] = v10[it][ilat][ilon] ; 329 330 } 331 } 332 333 } 334 335 197 336 198 337 void read_mask(int argv, char *argc[]) { … … 446 585 fprintf(fid,"%d %d %f %f\n",it,j,piret[it][j],pjret[it][j]); 447 586 587 588 fclose(fid); 589 590 } 591 592 593 void save_output_wind (int argc, char *argv[]) { 594 //Function used only for test 595 FILE *fid; 596 fid=fopen(argv[1],"w"); 597 if (fid==NULL) { 598 printf("\nfailed to open %s",argv[1]); 599 exit(3); 600 } 601 int j,k,it; 602 for (it=0;it<jptfl;it++) 603 for (j=0;j<nlon;j++) 604 for (k=0;k<nlat;k++) { 605 fprintf(fid,"%d %d %d %f %f\n",it,j,k,uwind[j][k][it],vwind[j][k][it]); 606 } 448 607 449 608 fclose(fid); -
altifloat/src/floater_delta.d
r150 r151 82 82 modul u space S_euler noward output 1 tempo //noward veut dire pas de calcul 83 83 modul v space S_euler noward output 1 tempo 84 modul uwind space S_euler noward output 1 tempo 85 modul vwind space S_euler noward output 1 tempo 84 86 modul locate space S_eulerlocate input 2 output 1 tempo 85 87 modul mask space S_euler noward output 1 … … 280 282 insert_fct multirun 281 283 insert_fct arg save_output_uv 284 insert_fct arg save_output_wind 282 285 insert_fct arg save_output_rfloat 283 286 insert_fct arg read_bck
Note: See TracChangeset
for help on using the changeset viewer.