source: trunk/src/sauvegrads.m @ 71

Last change on this file since 71 was 71, checked in by pinsard, 14 years ago

add man troff output of manuals and some light modification in sources due to docutils upgrade (0.6); warning : new troubles with target

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1function[h]=sauvegrads(nomfich,matrice,posit)
2% SAUVEGRADS create a data file (.dat) and  and a definion file (.ctl)
3
4%+
5% module
6% ======
7%
8% create a data file (.dat) and  and a definion file (.ctl)
9%
10% SYNOPSYS
11% ========
12%
13% ``SAUVEGRADS(NOMFICH,MATRICE,POSIT)``
14%
15% DESCRIPTION
16% ===========
17%
18% Create a data file (.dat) and  and a definion file (.ctl).
19%
20% Those files should be used with GRADS using :
21%
22% ::
23%
24%   grads$ open nomfich.ctl
25%
26%
27% Inputs arguments are :
28%
29% NOMFICH  suffixe of the files
30%          *nomfich*\ ``.dat`` will be data file
31%          *nomfich*\ ``.ctl`` will be definition file.
32%
33% MATRICE name of the 2D array to be saved
34%
35% POSIT    Coordinates telling the position of MATRICE reagrding the world map.
36%          Those coordinates [LON INCLON LAT INCLAT] are latitude and longitude
37%          of initial point and latitude and longitude steps. All in degrees.
38%
39% Warning : MATRICE will be reversed verticaly between MATLAB and GRADS.
40% This is die by the fact that latitude progress upwards when in MATLAB
41% increasing indexes, we go downards.
42%
43% Voir aussi XGRADS
44%
45% TODO
46% ====
47%
48% what about files path ?
49%
50% use h return values
51%
52%
53% EVOLUTIONS
54% ==========
55%
56% $Id$
57%
58% JMG le 10/03/94
59%
60% - fplod 2009-01-12T16:46:41Z aedon.locean-ipsl.upmc.fr (Darwin)
61%
62%   * date of day was not ok after 19991231
63%
64% - fplod 2009-01-05T11:01:41Z aedon.locean-ipsl.upmc.fr (Darwin)
65%
66%   * translation
67%   * comment in ReST format
68%
69%-
70%
71h=[];
72if nargin < 3
73        error('Il n''y a pas assez d''arguments.');
74elseif nargin > 3
75        error('Il y a trop d''arguments.')
76end
77
78% orientation de la matrice
79% sans le flipud la matrice sera inverser verticalement entre grads et matlab
80% ce qui est normal puisque l'on utilise les coordonn??es Longitude,latitude
81% sous grads et en incrementant la latitude on progresse vers le haut
82% alors qu'avec matlab on progresse vers le bas en incrementant l'indice
83%matrice=flipud(matrice);
84mat1=fliplr(matrice);
85mat2=rot90(mat1);
86nomfichdat=[nomfich,'.dat'];
87nomfichctl=[nomfich,'.ctl'];
88
89fprintf(1,'creation of data file %s \n',nomfichdat);
90% ouverture du fichier .dat
91fid=fopen(nomfichdat,'w');
92% ecriture de la matrice
93fwrite(fid,mat2,'float32');
94fclose(fid);
95
96% init des variables
97[sxp syp]=size(posit);
98if (syp~=4)
99  error('eee : incorrect syntaxe, 4 arguments must be given for POSIT');
100end
101lon=posit(1);
102inclon=posit(2);
103lat=posit(3);
104inclat=posit(4);
105% ici on peut rajouter les test pour voir si les coordonn??es en degr??es sont bonnes
106if (abs(lon)>180)
107  error('La longitude doit ??tre comprise entre -180 et 180');
108elseif (abs(lat>90))
109  error('La latitude doit ??tre comprise entre -90 et 90')
110end
111
112% Init date for record
113date1=date;
114date2=[date1(1:2),upper(date1(4:6)),date1(8:11)];
115% test sur les arguments
116[dimy dimx]=size(matrice);
117
118fprintf(1,'creation of definition file %s \n',nomfichctl);
119% ouverture du fichier .ctl
120fid=fopen(nomfichctl,'w');
121
122% ecriture ligne par ligne du fichier
123texte=['DSET ^',nomfichdat,' ',10];
124fwrite(fid,texte,'char');
125texte=['UNDEF -2E5633 ',10];
126fwrite(fid,texte,'char');
127texte=['TITLE File generated by sauvegrads de MATLAB ',10];
128fwrite(fid,texte,'char');
129texte=['XDEF ',num2str(dimx),' LINEAR ',num2str(lon),'  ',num2str(inclon),' ',10];
130fwrite(fid,texte,'char');
131texte=['YDEF ',num2str(dimy),' LINEAR ',num2str(lat),'  ',num2str(inclat),' ',10];
132fwrite(fid,texte,'char');
133texte=['ZDEF ',num2str(dimx*dimy),' LINEAR  1  1 ',10];
134fwrite(fid,texte,'char');
135texte=['TDEF 1 LINEAR ',num2str(date2),' 1DY ',10];
136fwrite(fid,texte,'char');
137texte=['VARS 1 ',10];
138fwrite(fid,texte,'char');
139texte=[nomfich,'      0   99  ',num2str(dimx*dimy),'   Matrice d''isovaleurs de MATLAB ',10];
140fwrite(fid,texte,'char');
141texte=['ENDVARS ',10];
142fwrite(fid,texte,'char');
143
144% fermeture du fichier
145fclose(fid);
Note: See TracBrowser for help on using the repository browser.