source: altifloat/include/ncutil.cpp @ 99

Last change on this file since 99 was 84, checked in by leila_ocean, 11 years ago

initial import

File size: 19.8 KB
Line 
1#include "../include/ncutil.h"//netcdf
2
3//--------------------- fonction d'erreur -------------------------------------
4using namespace std;
5
6inline void     handle_error (int status, char *txt)
7{
8        if (status != NC_NOERR)
9        { printf ("netcdf error: %s: netcdf statut: ", txt);
10        cout << nc_strerror (status) << endl;
11        exit (-1);
12        }
13}
14
15int Ouvre_nc_add(char const *var_file)
16{
17  // Ouvre un fichier ncf existant pour ajouter des variables
18  int var_file_id;
19  int status = nc_open(var_file, NC_WRITE, &var_file_id);
20  if (status != NC_NOERR) {
21  char file_error[100];
22    sprintf(file_error,"open %s",var_file);
23    handle_error (status, file_error);
24  }
25  return(var_file_id);
26}
27int Ouvre_nc_write(char const *var_file)
28{
29  ///* ouvre un fichier nc pour écriture et renvoie son id var_file_id
30  int var_file_id;
31  int status = nc_create(var_file, NC_CLOBBER, &var_file_id);
32  if (status != NC_NOERR) {
33  char file_error[100];
34    sprintf(file_error,"open %s",var_file);
35    handle_error (status, file_error);
36  }
37  return(var_file_id);
38}
39
40int Ouvre_nc(char const *var_file ) 
41{
42///* Ouvre un fichier nc et renvoie son id var_file_id
43  int var_file_id;
44  int status = nc_open (var_file, NC_NOWRITE | NC_SHARE,&var_file_id);
45  if (status != NC_NOERR){
46    char file_error[100];
47    sprintf(file_error,"open %s",var_file);
48    handle_error (status, file_error);
49  }
50  return(var_file_id);
51}
52
53int Var_id(int  var_file_id,char* varn) //initial traceurs actifs
54{// avoir l id d un variable a partir de l id var_file_id
55  int var_id;
56  int status = nc_inq_varid (var_file_id,varn,&var_id);
57  if (status != NC_NOERR){
58    char var_id_error[100];
59    sprintf(var_id_error,"%s_id error",varn);
60    handle_error (status, var_id_error);
61  }
62  return(var_id);
63}
64
65void twrite(int t, char *var_name,int ncid,int tid,int var)
66{
67  //Ecrire un scalaire au temps t
68  //le parametre t commence de 0.
69  // ecrit la variable var_name au point (t)
70  int status;
71
72  int var_id;
73  static size_t start[] = {0}; //3D+t
74  static size_t count[] = {1}; //3D+t
75  count[0]= (size_t) t+1;
76  start[0]=t; //temps commence de 0;
77
78  //Define the netCDF variable
79  status=nc_redef(ncid);
80if (status != NC_NOERR)
81    {
82      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
83    }
84 
85 status=nc_def_var(ncid,var_name,NC_INT,1,&tid,&var_id);
86 
87  if (status != NC_NOERR)
88    {
89      printf("variable %s:",var_name);
90      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
91    }
92 nc_enddef(ncid);
93  status=nc_put_vara_int(ncid,var_id,start,count,&var);
94 if (status != NC_NOERR)
95    {
96      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
97    }
98}
99
100void twrite(int t, char *var_name,int ncid,int tid,float var)
101{
102  //Ecrire un scalaire au temps t
103  //le parametre t commence de 0.
104  // ecrit la variable var_name au point (t)
105  int status;
106
107  int var_id;
108  static size_t start[] = {0}; //3D+t
109  static size_t count[] = {1}; //3D+t
110  count[0]= (size_t) t+1;
111  start[0]=t; //temps commence de 0;
112
113  //Define the netCDF variable
114  status=nc_redef(ncid);
115if (status != NC_NOERR)
116    {
117      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
118    }
119 
120 status=nc_def_var(ncid,var_name,NC_FLOAT,1,&tid,&var_id);
121 
122  if (status != NC_NOERR)
123    {
124      printf("variable %s:",var_name);
125      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
126    }
127 nc_enddef(ncid);
128  status=nc_put_vara_float(ncid,var_id,start,count,&var);
129 if (status != NC_NOERR)
130    {
131      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
132    }
133}
134
135void twrite(int t, char *var_name,int ncid,int tid,double var)
136{
137  //Ecrire un scalaire au temps t
138  //le parametre t commence de 0.
139  // ecrit la variable var_name au point (t)
140  int status;
141
142  int var_id;
143  static size_t start[] = {0}; //3D+t
144  static size_t count[] = {1}; //3D+t
145  count[0]= (size_t) t+1;
146  start[0]=t; //temps commence de 0;
147
148  //Define the netCDF variable
149  status=nc_redef(ncid);
150if (status != NC_NOERR)
151    {
152      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
153    }
154 
155 status=nc_def_var(ncid,var_name,NC_DOUBLE,1,&tid,&var_id);
156 
157  if (status != NC_NOERR)
158    {
159      printf("variable %s:",var_name);
160      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
161    }
162 nc_enddef(ncid);
163  status=nc_put_vara_double(ncid,var_id,start,count,&var);
164 if (status != NC_NOERR)
165    {
166      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
167    }
168}
169
170
171void voncwrite(int t,int znbval,int ynbval, int xnbval, char const *var_name,int ncid,int dimids[], YREAL vect[])
172{ //Ecrrire le volume 3D au temps t
173  //le parametre t commence de 0.
174  // ecrit la variable var_name aux points (t, 1:znbval, 1:ynbval, 1:xnbval)
175  int status;
176
177  int var_id;
178  int local_dimids[4];
179  static size_t start[] = {0,0,0,0}; //3D+t
180  static size_t count[] = {1,1,1,1}; //3D+t
181  count[0]= (size_t) t+1;
182  count[1]= (size_t) znbval;
183  count[2]= (size_t) ynbval;
184  count[3]= (size_t) xnbval;
185  start[0]=t; //temps commence de 0;
186
187  local_dimids[0]=dimids[0]; //t
188  local_dimids[1]=dimids[1]; //z
189  local_dimids[2]=dimids[2]; //y
190  local_dimids[3]=dimids[3]; //x
191
192  //Define the netCDF variable
193  status=nc_redef(ncid);
194if (status != NC_NOERR)
195    {
196      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
197    }
198 
199 status=nc_def_var(ncid,var_name,NC_REAL,4,local_dimids,&var_id);
200 
201  if (status != NC_NOERR)
202    {
203      printf("variable %s:",var_name);
204      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
205    }
206 nc_enddef(ncid);
207  status=nc_put_vara_real(ncid,var_id,start,count,vect);
208 if (status != NC_NOERR)
209    {
210      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
211    }
212}
213
214void vonclire(int t,int znbval, int ynbval, int xnbval, int ncid, int varid, double vect[])
215{// lire volume 3D au temps t
216  // le parametre t commence de 0 et pas de 1
217  // (t,znbval,ynbval,xnbval,ncid, varid):
218  // lit la variable varid aux points (t,1:znbval,1:ynbval,1:xnbval) et
219  // renvoie un vecteur de dim znbval*ynbval*xnbval
220 
221  int           status;
222  static size_t   start[] = { 0, 0, 0, 0 };  // 3D+t
223  static size_t   count[] = { 1, 1, 1, 1 }; // 3D+t
224  count[0] =(size_t)  t+1;
225  count[1] =(size_t)  znbval;
226  count[2] =(size_t)  ynbval;
227  count[3] =(size_t)  xnbval;
228  start[0] = (size_t) t;   // temps commence de 0:
229 
230  // Read an array of values
231  status = nc_get_vara_double (ncid, varid, start, count, vect);
232 
233 if (status != NC_NOERR)
234    {
235      handle_error (status, "Erreur lecture fichier NetCDF::vonclire");
236    }
237}
238
239void soncwrite(int t,int ynbval, int xnbval, char const *var_name,int ncid,int dimids[], YREAL vect[])
240{ //Ecrrire le volume 2D au temps t
241  //le parametre t commence de 0.
242  // ecrit la variable var_name aux points (t, 1:ynbval, 1:xnbval)
243  int status;
244
245  int var_id;
246  int local_dimids[3];
247  static size_t start[] = {0,0,0}; //2D+t
248  static size_t count[] = {1,1,1}; //2D+t
249  count[0]= (size_t) t+1;
250  count[1]= (size_t) ynbval;
251  count[2]= (size_t) xnbval;
252  start[0]=t; //temps commence de 0;
253
254  local_dimids[0]=dimids[0]; //t
255  local_dimids[1]=dimids[2]; //y
256  local_dimids[2]=dimids[3]; //x
257
258  //Define the netCDF variable
259  status=nc_redef(ncid);
260if (status != NC_NOERR)
261    {
262      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
263    }
264 
265 status=nc_def_var(ncid,var_name,NC_REAL,3,local_dimids,&var_id);
266 
267  if (status != NC_NOERR)
268    {
269      printf("variable %s:",var_name);
270      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
271    }
272 nc_enddef(ncid);
273  status=nc_put_vara_real(ncid,var_id,start,count,vect);
274 if (status != NC_NOERR)
275    {
276      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
277    }
278}
279
280
281void sonclire(int t,int ynbval, int xnbval, int ncid, int varid, double vect[])
282{// lire surface 2D au temps t
283  // le parametre t commence de 0 et pas de 1
284  // (t,ynbval,xnbval,ncid, varid):
285  // lit la variable varid aux points (t,1:ynbval,1:xnbval) et
286  // renvoie un vecteur de dim ynbval*xnbval
287 
288  int           status;
289  static size_t   start[] = { 0, 0, 0 };  // 2D+t
290  static size_t   count[] = { 1, 1, 1 }; // 2D+t
291  count[0] =(size_t)  t+1;
292  count[1] =(size_t)  ynbval;
293  count[2] =(size_t)  xnbval;
294  start[0] = (size_t) t;   // temps commence de 0:
295 
296  // Read an array of values
297  status = nc_get_vara_double (ncid, varid, start, count, vect);
298 
299 if (status != NC_NOERR)
300    {
301      handle_error (status, "Erreur lecture fichier NetCDF::sonclire");
302    }
303}
304
305void sonclire(int t,int ynbval, int xnbval, int ncid, int varid, float vect[])
306{// lire surface 2D au temps t
307  // le parametre t commence de 0 et pas de 1
308  // (t,ynbval,xnbval,ncid, varid):
309  // lit la variable varid aux points (t,1:ynbval,1:xnbval) et
310  // renvoie un vecteur de dim ynbval*xnbval
311 
312  int           status;
313  static size_t   start[] = { 0, 0, 0 };  // 2D+t
314  static size_t   count[] = { 1, 1, 1 }; // 2D+t
315  count[0] =(size_t)  t+1;
316  count[1] =(size_t)  ynbval;
317  count[2] =(size_t)  xnbval;
318  start[0] = (size_t) t;   // temps commence de 0:
319 
320  // Read an array of values
321  status = nc_get_vara_float (ncid, varid, start, count, vect);
322 
323 if (status != NC_NOERR)
324    {
325      handle_error (status, "Erreur lecture fichier NetCDF::sonclire");
326    }
327}
328
329void snclire(int ynbval, int xnbval, int ncid, int varid, double vect[])
330{// lire surface 2D
331  // (ynbval,xnbval,ncid, varid):
332  // lit la variable varid aux points (1:ynbval,1:xnbval) et
333  // renvoie un vecteur de dim ynbval*xnbval
334 
335  int           status;
336  static size_t   start[] = { 0, 0 };  // 2D
337  static size_t   count[] = { 1, 1 }; // 2D
338  count[0] =(size_t)  ynbval;
339  count[1] =(size_t)  xnbval;
340 
341  // Read an array of values
342  status = nc_get_vara_double (ncid, varid, start, count, vect);
343 
344 if (status != NC_NOERR)
345    {
346      handle_error (status, "Erreur lecture fichier NetCDF::snclire");
347    }
348}
349
350void snclire(int ynbval, int xnbval, int ncid, int varid, float vect[])
351{// lire surface 2D
352  // (ynbval,xnbval,ncid, varid):
353  // lit la variable varid aux points (1:ynbval,1:xnbval) et
354  // renvoie un vecteur de dim ynbval*xnbval
355 
356  int           status;
357  static size_t   start[] = { 0, 0 };  // 2D
358  static size_t   count[] = { 1, 1 }; // 2D
359  count[0] =(size_t)  ynbval;
360  count[1] =(size_t)  xnbval;
361 
362  // Read an array of values
363  status = nc_get_vara_float (ncid, varid, start, count, vect);
364 
365 if (status != NC_NOERR)
366    {
367      handle_error (status, "Erreur lecture fichier NetCDF::snclire");
368    }
369}
370
371void zoncwrite(int t,int znbval,char const *var_name,int ncid,int dimids[], YREAL vect[])
372{ //Ecrrire la variable 1D au temps t
373  //le parametre t commence de 0.
374  // ecrit la variable var_name aux points (t, 1:znbval)
375  int status;
376
377  int var_id;
378  int local_dimids[2];
379  static size_t start[] = {0,0}; //1D+t
380  static size_t count[] = {1,1}; //1D+t
381  count[0]= (size_t) t+1;
382  count[1]= (size_t) znbval;
383 
384  start[0]=t; //temps commence de 0;
385
386  local_dimids[0]=dimids[0]; //t
387  local_dimids[1]=dimids[1]; //z
388 
389
390  //Define the netCDF variable
391  status=nc_redef(ncid);
392if (status != NC_NOERR)
393    {
394      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
395    }
396 
397 status=nc_def_var(ncid,var_name,NC_REAL,2,local_dimids,&var_id);
398 
399  if (status != NC_NOERR)
400    {
401      printf("variable %s:",var_name);
402      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
403    }
404 nc_enddef(ncid);
405  status=nc_put_vara_real(ncid,var_id,start,count,vect);
406 if (status != NC_NOERR)
407    {
408      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
409    }
410}
411
412
413void zonclire(int t,int znbval, int ncid, int varid, double vect[])
414{// lire surface 1D au temps t
415  // le parametre t commence de 0 et pas de 1
416  // (t,znbval,ncid, varid):
417  // lit la variable varid aux points (t,1:znbval) et
418  // renvoie un vecteur de dim znbval
419 
420  int           status;
421  static size_t   start[] = { 0, 0 };  // t+1D
422  static size_t   count[] = { 1, 1 }; // t+1D
423  count[0] =(size_t)  t+1;
424  count[1] =(size_t)  znbval;
425  start[0] = (size_t) t;   // temps commence de 0:
426 
427  // Read an array of values
428  status = nc_get_vara_double (ncid, varid, start, count, vect);
429 
430 if (status != NC_NOERR)
431    {
432      handle_error (status, "Erreur lecture fichier NetCDF::zonclire");
433    }
434}
435
436
437void vonclire(int t,int znbval, int ynbval, int xnbval, int ncid, int varid, int vect[])
438{// lire volume 3D au temps t
439  // le parametre t commence de 0 et pas de 1
440  // (t,znbval,ynbval,xnbval,ncid, varid):
441  // lit la variable varid aux points (t,1:znbval,1:ynbval,1:xnbval) et
442  // renvoie un vecteur de dim znbval*ynbval*xnbval
443 
444  int           status;
445  static size_t   start[] = { 0, 0, 0, 0 };  // 3D+t
446  static size_t   count[] = { 1, 1, 1, 1 }; // 3D+t
447  count[0] =(size_t)  t+1;
448  count[1] =(size_t)  znbval;
449  count[2] =(size_t)  ynbval;
450  count[3] =(size_t)  xnbval;
451  start[0] = (size_t) t;   // temps commence de 0:
452 
453  // Read an array of values
454  status = nc_get_vara_int (ncid, varid, start, count, vect);
455 
456 if (status != NC_NOERR)
457    {
458      handle_error (status, "Erreur lecture fichier NetCDF::vonclire");
459    }
460}
461
462void sonclire(int t,int ynbval, int xnbval, int ncid, int varid, int vect[])
463{// lire surface 2D au temps t
464  // le parametre t commence de 0 et pas de 1
465  // (t,ynbval,xnbval,ncid, varid):
466  // lit la variable varid aux points (t,1:ynbval,1:xnbval) et
467  // renvoie un vecteur de dim ynbval*xnbval
468 
469  int           status;
470  static size_t   start[] = { 0, 0, 0 };  // 2D+t
471  static size_t   count[] = { 1, 1, 1 }; // 2D+t
472  count[0] =(size_t)  t+1;
473  count[1] =(size_t)  ynbval;
474  count[2] =(size_t)  xnbval;
475  start[0] = (size_t) t;   // temps commence de 0:
476 
477  // Read an array of values
478  status = nc_get_vara_int (ncid, varid, start, count, vect);
479 
480 if (status != NC_NOERR)
481    {
482      handle_error (status, "Erreur lecture fichier NetCDF::sonclire");
483    }
484}
485
486void zonclire(int t,int znbval, int ncid, int varid, int vect[])
487{// lire surface 1D au temps t
488  // le parametre t commence de 0 et pas de 1
489  // (t,znbval,ncid, varid):
490  // lit la variable varid aux points (t,1:znbval) et
491  // renvoie un vecteur de dim znbval
492 
493  int           status;
494  static size_t   start[] = { 0, 0 };  // t+1D
495  static size_t   count[] = { 1, 1 }; // t+1D
496  count[0] =(size_t)  t+1;
497  count[1] =(size_t)  znbval;
498  start[0] = (size_t) t;   // temps commence de 0:
499 
500  // Read an array of values
501  status = nc_get_vara_int (ncid, varid, start, count, vect);
502 
503 if (status != NC_NOERR)
504    {
505      handle_error (status, "Erreur lecture fichier NetCDF::zonclire");
506    }
507}
508
509void znclire(int znbval, int ncid, int varid, double vect[])
510{// lire surface 1D
511  // (znbval,ncid, varid):
512  // lit la variable varid aux points (1:znbval) et
513  // renvoie un vecteur de dim znbval
514 
515  int           status;
516  static size_t   start[] = { 0 };  //1D
517  static size_t   count[] = { 1 }; // 1D
518  count[0] =(size_t)  znbval;
519 
520 
521  // Read an array of values
522  status = nc_get_vara_double (ncid, varid, start, count, vect);
523 
524 if (status != NC_NOERR)
525    {
526      handle_error (status, "Erreur lecture fichier NetCDF::zonclire");
527    }
528}
529
530
531void znclire(int znbval, int ncid, int varid, float vect[])
532{// lire surface 1D
533  // (znbval,ncid, varid):
534  // lit la variable varid aux points (1:znbval) et
535  // renvoie un vecteur de dim znbval
536 
537  int           status;
538  static size_t   start[] = { 0 };  //1D
539  static size_t   count[] = { 1 }; // 1D
540  count[0] =(size_t)  znbval;
541 
542 
543  // Read an array of values
544  status = nc_get_vara_float (ncid, varid, start, count, vect);
545 
546 if (status != NC_NOERR)
547    {
548      handle_error (status, "Erreur lecture fichier NetCDF::zonclire");
549    }
550}
551
552void scalarlire (int ncid,int varid, int *var) {
553  int status;
554  status=nc_get_var_int (ncid,varid,var);
555  if (status != NC_NOERR)
556    {
557      handle_error (status, "Erreur lecture fichier NetCDF::scalarlire");
558    }
559}
560
561void scalarlire (int ncid,int varid, float *var) {
562  int status;
563  status=nc_get_var_float (ncid,varid,var);
564  if (status != NC_NOERR)
565    {
566      handle_error (status, "Erreur lecture fichier NetCDF::scalarlire");
567    }
568}
569
570void scalarlire (int ncid,int varid, double *var) {
571  int status;
572  status=nc_get_var_double (ncid,varid,var);
573  if (status != NC_NOERR)
574    {
575      handle_error (status, "Erreur lecture fichier NetCDF::scalarlire");
576    }
577}
578
579void scalarwrite (int ncid,char const *var_name,int var) {
580  int status;
581  int var_id;
582  status=nc_redef(ncid);
583  if (status != NC_NOERR)
584    {
585      handle_error (status, "Erreur change to def mode NetCDF ::scalarwrite");
586    }
587 
588  status=nc_def_var(ncid,var_name,NC_INT,0,NULL,&var_id);
589 
590  if (status != NC_NOERR)
591    {
592      printf("variable %s:",var_name);
593      handle_error (status, "Erreur define NetCDF variable ::scalarwrite");
594    }
595  nc_enddef(ncid);
596  status=nc_put_var_int(ncid,var_id,&var);
597  if (status != NC_NOERR)
598    {
599      handle_error (status, "Erreur writing NetCDF variable ::scalarwrite");
600    }
601}
602void scalarwrite (int ncid,char const *var_name,float var) {
603  int status;
604  int var_id;
605  status=nc_redef(ncid);
606  if (status != NC_NOERR)
607    {
608      handle_error (status, "Erreur change to def mode NetCDF ::scalarwrite");
609    }
610 
611  status=nc_def_var(ncid,var_name,NC_FLOAT,0,NULL,&var_id);
612 
613  if (status != NC_NOERR)
614    {
615      printf("variable %s:",var_name);
616      handle_error (status, "Erreur define NetCDF variable ::scalarwrite");
617    }
618  nc_enddef(ncid);
619  status=nc_put_var_float(ncid,var_id,&var);
620  if (status != NC_NOERR)
621    {
622      handle_error (status, "Erreur writing NetCDF variable ::scalarwrite");
623    }
624}
625void scalarwrite (int ncid,char const *var_name,double var) {
626  int status;
627  int var_id;
628  status=nc_redef(ncid);
629  if (status != NC_NOERR)
630    {
631      handle_error (status, "Erreur change to def mode NetCDF ::scalarwrite");
632    }
633 
634  status=nc_def_var(ncid,var_name,NC_DOUBLE,0,NULL,&var_id);
635 
636  if (status != NC_NOERR)
637    {
638      printf("variable %s:",var_name);
639      handle_error (status, "Erreur define NetCDF variable ::scalarwrite");
640    }
641  nc_enddef(ncid);
642  status=nc_put_var_double(ncid,var_id,&var);
643  if (status != NC_NOERR)
644    {
645      handle_error (status, "Erreur writing NetCDF variable ::scalarwrite");
646    }
647}
648
649void sncwrite(int ynbval, int xnbval, char const *var_name,int ncid,int dimids[], YREAL vect[])
650{ //Ecrrire le volume 2D
651  // ecrit la variable var_name aux points (1:ynbval, 1:xnbval)
652  int status;
653
654  int var_id;
655  int local_dimids[2];
656  static size_t start[] = {0,0}; //2D
657  static size_t count[] = {1,1}; //2D
658  count[0]= (size_t) ynbval;
659  count[1]= (size_t) xnbval;
660 
661  local_dimids[0]=dimids[2]; //y
662  local_dimids[1]=dimids[3]; //x
663
664  //Define the netCDF variable
665  status=nc_redef(ncid);
666if (status != NC_NOERR)
667    {
668      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
669    }
670 
671 status=nc_def_var(ncid,var_name,NC_REAL,2,local_dimids,&var_id);
672 
673  if (status != NC_NOERR)
674    {
675      printf("variable %s:",var_name);
676      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
677    }
678 nc_enddef(ncid);
679  status=nc_put_vara_real(ncid,var_id,start,count,vect);
680 if (status != NC_NOERR)
681    {
682      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
683    }
684}
685
686
687void zncwrite(int znbval,char const *var_name,int ncid,int dimids[], YREAL vect[])
688{ //Ecrrire la variable 1D
689  // ecrit la variable var_name aux points (1:znbval)
690  int status;
691
692  int var_id;
693  int local_dimids[1];
694  static size_t start[] = {0}; //1D
695  static size_t count[] = {1}; //1D
696
697  count[0]= (size_t) znbval;
698 
699
700  local_dimids[0]=dimids[1]; //z
701 
702
703  //Define the netCDF variable
704  status=nc_redef(ncid);
705if (status != NC_NOERR)
706    {
707      handle_error (status, "Erreur change to def mode NetCDF ::voncwrite");
708    }
709 
710 status=nc_def_var(ncid,var_name,NC_REAL,1,local_dimids,&var_id);
711 
712  if (status != NC_NOERR)
713    {
714      printf("variable %s:",var_name);
715      handle_error (status, "Erreur define NetCDF variable ::voncwrite");
716    }
717 nc_enddef(ncid);
718  status=nc_put_vara_real(ncid,var_id,start,count,vect);
719 if (status != NC_NOERR)
720    {
721      handle_error (status, "Erreur writing NetCDF variable ::voncwrite");
722    }
723}
Note: See TracBrowser for help on using the repository browser.