Changeset 151 for altifloat/src


Ignore:
Timestamp:
07/02/15 10:08:35 (9 years ago)
Author:
jbrlod
Message:

load and interp wind data

Location:
altifloat/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • altifloat/src/floater.h

    r147 r151  
    11#define UPDATE_BCK 
     2 
     3#include <netcdf.h> 
    24 
    35//constantes 
     
    2123YREAL umod[nlon][nlat][jptfl]; 
    2224YREAL vmod[nlon][nlat][jptfl]; 
     25YREAL uwind[nlon][nlat][jptfl]; 
     26YREAL vwind[nlon][nlat][jptfl]; 
    2327 
    2428//Background 
     
    4751#endif 
    4852#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" 
    4959 
    5060//Options du run incr士ental 
     
    6171void run_inc(int argv, char *argc[]); 
    6272void div_init(); 
     73void init_wind(char fname[],int iter0,int *ptime0); 
    6374 
    6475void appli_start(int argc, char *argv[]){ 
     
    195206 
    196207} 
     208 
     209void 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 
     237void 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 
    197336 
    198337void read_mask(int argv, char *argc[]) { 
     
    446585      fprintf(fid,"%d %d %f %f\n",it,j,piret[it][j],pjret[it][j]); 
    447586         
     587                                              
     588  fclose(fid); 
     589 
     590} 
     591 
     592 
     593void save_output_wind (int argc, char *argv[]) { 
     594  //Function used only for test 
     595FILE *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        } 
    448607                                              
    449608  fclose(fid); 
  • altifloat/src/floater_delta.d

    r150 r151  
    8282modul u       space S_euler       noward    output 1 tempo //noward veut dire pas de calcul 
    8383modul v       space S_euler       noward    output 1 tempo 
     84modul uwind   space S_euler       noward    output 1 tempo 
     85modul vwind   space S_euler       noward    output 1 tempo 
    8486modul locate  space S_eulerlocate input  2  output 1 tempo 
    8587modul mask    space S_euler       noward    output 1 
     
    280282insert_fct multirun 
    281283insert_fct arg save_output_uv 
     284insert_fct arg save_output_wind 
    282285insert_fct arg save_output_rfloat 
    283286insert_fct arg read_bck 
Note: See TracChangeset for help on using the changeset viewer.