Changeset 7 for trunk/include/ncutil.cpp
- Timestamp:
- 03/07/11 11:49:01 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ncutil.cpp
r4 r7 50 50 return(var_id); 51 51 } 52 52 53 void voncwrite(int t,int znbval,int ynbval, int xnbval, char const *var_name,int ncid,int dimids[], YREAL vect[]) 54 { //Ecrrire le volume 3D au temps t 55 //le parametre t commence de 0. 56 // ecrit la variable var_name aux points (t, 1:znbval, 1:ynbval, 1:xnbval) 57 int status; 58 59 int var_id; 60 int local_dimids[4]; 61 static size_t start[] = {0,0,0,0}; //3D+t 62 static size_t count[] = {1,1,1,1}; //3D+t 63 count[0]= (size_t) t+1; 64 count[1]= (size_t) znbval; 65 count[2]= (size_t) ynbval; 66 count[3]= (size_t) xnbval; 67 start[0]=t; //temps commence de 0; 68 69 local_dimids[0]=dimids[0]; //t 70 local_dimids[1]=dimids[1]; //z 71 local_dimids[2]=dimids[2]; //y 72 local_dimids[3]=dimids[3]; //x 73 74 //Define the netCDF variable 75 status=nc_redef(ncid); 76 if (status != NC_NOERR) 77 { 78 handle_error (status, "Erreur change to def mode NetCDF ::voncwrite"); 79 } 80 81 status=nc_def_var(ncid,var_name,NC_REAL,4,local_dimids,&var_id); 82 83 if (status != NC_NOERR) 84 { 85 printf("variable %s:",var_name); 86 handle_error (status, "Erreur define NetCDF variable ::voncwrite"); 87 } 88 nc_enddef(ncid); 89 status=nc_put_vara_real(ncid,var_id,start,count,vect); 90 if (status != NC_NOERR) 91 { 92 handle_error (status, "Erreur writing NetCDF variable ::voncwrite"); 93 } 94 } 95 53 96 void vonclire(int t,int znbval, int ynbval, int xnbval, int ncid, int varid, double vect[]) 54 97 {// lire volume 3D au temps t … … 76 119 } 77 120 121 void soncwrite(int t,int ynbval, int xnbval, char const *var_name,int ncid,int dimids[], YREAL vect[]) 122 { //Ecrrire le volume 2D au temps t 123 //le parametre t commence de 0. 124 // ecrit la variable var_name aux points (t, 1:ynbval, 1:xnbval) 125 int status; 126 127 int var_id; 128 int local_dimids[3]; 129 static size_t start[] = {0,0,0}; //2D+t 130 static size_t count[] = {1,1,1}; //2D+t 131 count[0]= (size_t) t+1; 132 count[1]= (size_t) ynbval; 133 count[2]= (size_t) xnbval; 134 start[0]=t; //temps commence de 0; 135 136 local_dimids[0]=dimids[0]; //t 137 local_dimids[1]=dimids[2]; //y 138 local_dimids[2]=dimids[3]; //x 139 140 //Define the netCDF variable 141 status=nc_redef(ncid); 142 if (status != NC_NOERR) 143 { 144 handle_error (status, "Erreur change to def mode NetCDF ::voncwrite"); 145 } 146 147 status=nc_def_var(ncid,var_name,NC_REAL,3,local_dimids,&var_id); 148 149 if (status != NC_NOERR) 150 { 151 printf("variable %s:",var_name); 152 handle_error (status, "Erreur define NetCDF variable ::voncwrite"); 153 } 154 nc_enddef(ncid); 155 status=nc_put_vara_real(ncid,var_id,start,count,vect); 156 if (status != NC_NOERR) 157 { 158 handle_error (status, "Erreur writing NetCDF variable ::voncwrite"); 159 } 160 } 161 162 78 163 void sonclire(int t,int ynbval, int xnbval, int ncid, int varid, double vect[]) 79 164 {// lire surface 2D au temps t … … 99 184 } 100 185 } 186 101 187 void sonclire(int t,int ynbval, int xnbval, int ncid, int varid, float vect[]) 102 188 {// lire surface 2D au temps t … … 123 209 } 124 210 211 void snclire(int ynbval, int xnbval, int ncid, int varid, double vect[]) 212 {// lire surface 2D 213 // (ynbval,xnbval,ncid, varid): 214 // lit la variable varid aux points (1:ynbval,1:xnbval) et 215 // renvoie un vecteur de dim ynbval*xnbval 216 217 int status; 218 static size_t start[] = { 0, 0 }; // 2D 219 static size_t count[] = { 1, 1 }; // 2D 220 count[0] =(size_t) ynbval; 221 count[1] =(size_t) xnbval; 222 223 // Read an array of values 224 status = nc_get_vara_double (ncid, varid, start, count, vect); 225 226 if (status != NC_NOERR) 227 { 228 handle_error (status, "Erreur lecture fichier NetCDF::snclire"); 229 } 230 } 231 232 void snclire(int ynbval, int xnbval, int ncid, int varid, float vect[]) 233 {// lire surface 2D 234 // (ynbval,xnbval,ncid, varid): 235 // lit la variable varid aux points (1:ynbval,1:xnbval) et 236 // renvoie un vecteur de dim ynbval*xnbval 237 238 int status; 239 static size_t start[] = { 0, 0 }; // 2D 240 static size_t count[] = { 1, 1 }; // 2D 241 count[0] =(size_t) ynbval; 242 count[1] =(size_t) xnbval; 243 244 // Read an array of values 245 status = nc_get_vara_float (ncid, varid, start, count, vect); 246 247 if (status != NC_NOERR) 248 { 249 handle_error (status, "Erreur lecture fichier NetCDF::snclire"); 250 } 251 } 252 253 void zoncwrite(int t,int znbval,char const *var_name,int ncid,int dimids[], YREAL vect[]) 254 { //Ecrrire la variable 1D au temps t 255 //le parametre t commence de 0. 256 // ecrit la variable var_name aux points (t, 1:znbval) 257 int status; 258 259 int var_id; 260 int local_dimids[2]; 261 static size_t start[] = {0,0}; //1D+t 262 static size_t count[] = {1,1}; //1D+t 263 count[0]= (size_t) t+1; 264 count[1]= (size_t) znbval; 265 266 start[0]=t; //temps commence de 0; 267 268 local_dimids[0]=dimids[0]; //t 269 local_dimids[1]=dimids[1]; //z 270 271 272 //Define the netCDF variable 273 status=nc_redef(ncid); 274 if (status != NC_NOERR) 275 { 276 handle_error (status, "Erreur change to def mode NetCDF ::voncwrite"); 277 } 278 279 status=nc_def_var(ncid,var_name,NC_REAL,2,local_dimids,&var_id); 280 281 if (status != NC_NOERR) 282 { 283 printf("variable %s:",var_name); 284 handle_error (status, "Erreur define NetCDF variable ::voncwrite"); 285 } 286 nc_enddef(ncid); 287 status=nc_put_vara_real(ncid,var_id,start,count,vect); 288 if (status != NC_NOERR) 289 { 290 handle_error (status, "Erreur writing NetCDF variable ::voncwrite"); 291 } 292 } 293 294 125 295 void zonclire(int t,int znbval, int ncid, int varid, double vect[]) 126 296 {// lire surface 1D au temps t … … 218 388 } 219 389 } 390 391 void znclire(int znbval, int ncid, int varid, double vect[]) 392 {// lire surface 1D 393 // (znbval,ncid, varid): 394 // lit la variable varid aux points (1:znbval) et 395 // renvoie un vecteur de dim znbval 396 397 int status; 398 static size_t start[] = { 0 }; //1D 399 static size_t count[] = { 1 }; // 1D 400 count[0] =(size_t) znbval; 401 402 403 // Read an array of values 404 status = nc_get_vara_double (ncid, varid, start, count, vect); 405 406 if (status != NC_NOERR) 407 { 408 handle_error (status, "Erreur lecture fichier NetCDF::zonclire"); 409 } 410 } 411 412 413 void znclire(int znbval, int ncid, int varid, float vect[]) 414 {// lire surface 1D 415 // (znbval,ncid, varid): 416 // lit la variable varid aux points (1:znbval) et 417 // renvoie un vecteur de dim znbval 418 419 int status; 420 static size_t start[] = { 0 }; //1D 421 static size_t count[] = { 1 }; // 1D 422 count[0] =(size_t) znbval; 423 424 425 // Read an array of values 426 status = nc_get_vara_float (ncid, varid, start, count, vect); 427 428 if (status != NC_NOERR) 429 { 430 handle_error (status, "Erreur lecture fichier NetCDF::zonclire"); 431 } 432 } 433 434 void sncwrite(int ynbval, int xnbval, char const *var_name,int ncid,int dimids[], YREAL vect[]) 435 { //Ecrrire le volume 2D 436 // ecrit la variable var_name aux points (1:ynbval, 1:xnbval) 437 int status; 438 439 int var_id; 440 int local_dimids[2]; 441 static size_t start[] = {0,0}; //2D 442 static size_t count[] = {1,1}; //2D 443 count[0]= (size_t) ynbval; 444 count[1]= (size_t) xnbval; 445 446 local_dimids[0]=dimids[2]; //y 447 local_dimids[1]=dimids[3]; //x 448 449 //Define the netCDF variable 450 status=nc_redef(ncid); 451 if (status != NC_NOERR) 452 { 453 handle_error (status, "Erreur change to def mode NetCDF ::voncwrite"); 454 } 455 456 status=nc_def_var(ncid,var_name,NC_REAL,2,local_dimids,&var_id); 457 458 if (status != NC_NOERR) 459 { 460 printf("variable %s:",var_name); 461 handle_error (status, "Erreur define NetCDF variable ::voncwrite"); 462 } 463 nc_enddef(ncid); 464 status=nc_put_vara_real(ncid,var_id,start,count,vect); 465 if (status != NC_NOERR) 466 { 467 handle_error (status, "Erreur writing NetCDF variable ::voncwrite"); 468 } 469 } 470 471 472 void zncwrite(int znbval,char const *var_name,int ncid,int dimids[], YREAL vect[]) 473 { //Ecrrire la variable 1D 474 // ecrit la variable var_name aux points (1:znbval) 475 int status; 476 477 int var_id; 478 int local_dimids[1]; 479 static size_t start[] = {0}; //1D 480 static size_t count[] = {1}; //1D 481 482 count[0]= (size_t) znbval; 483 484 485 local_dimids[0]=dimids[1]; //z 486 487 488 //Define the netCDF variable 489 status=nc_redef(ncid); 490 if (status != NC_NOERR) 491 { 492 handle_error (status, "Erreur change to def mode NetCDF ::voncwrite"); 493 } 494 495 status=nc_def_var(ncid,var_name,NC_REAL,1,local_dimids,&var_id); 496 497 if (status != NC_NOERR) 498 { 499 printf("variable %s:",var_name); 500 handle_error (status, "Erreur define NetCDF variable ::voncwrite"); 501 } 502 nc_enddef(ncid); 503 status=nc_put_vara_real(ncid,var_id,start,count,vect); 504 if (status != NC_NOERR) 505 { 506 handle_error (status, "Erreur writing NetCDF variable ::voncwrite"); 507 } 508 }
Note: See TracChangeset
for help on using the changeset viewer.