function[h]=sauvegrads(nomfich,matrice,posit) % SAUVEGRADS create a data file (.dat) and a definion file (.ctl) %+ % % .. _sauvegrads.m: % % ============ % sauvegrads.m % ============ % % --------------------------------------------------------- % create a data file (.dat) and a definion file (.ctl) % --------------------------------------------------------- % % SYNOPSYS % ======== % % ``SAUVEGRADS(NOMFICH,MATRICE,POSIT)`` % % DESCRIPTION % =========== % % Create a data file (:file:`.dat`) and a definion file (:file:`.ctl`). % % Those files should be used with GRADS using : % % :: % % grads$ open nomfich.ctl % % % Inputs arguments are : % % NOMFICH suffixe of the files % :file:`{nomfich}.dat` will be data file % :file:`nomfich}.ctl` will be definition file. % % MATRICE name of the 2D array to be saved % % POSIT Coordinates telling the position of MATRICE reagrding the world map. % Those coordinates [LON INCLON LAT INCLAT] are latitude and longitude % of initial point and latitude and longitude steps. All in degrees. % % Warning : MATRICE will be reversed verticaly between MATLAB and GRADS. % This is die by the fact that latitude progress upwards when in MATLAB % increasing indexes, we go downards. % % Voir aussi XGRADS % % TODO % ==== % % what about files path ? % % use h return values % % EVOLUTIONS % ========== % % $Id$ % % JMG le 10/03/94 % % - fplod 2009-01-12T16:46:41Z aedon.locean-ipsl.upmc.fr (Darwin) % % * date of day was not ok after 19991231 % % - fplod 2009-01-05T11:01:41Z aedon.locean-ipsl.upmc.fr (Darwin) % % * translation % * comment in ReST format % %- % h=[]; if nargin < 3 error('Il n''y a pas assez d''arguments.'); elseif nargin > 3 error('Il y a trop d''arguments.') end % orientation de la matrice % sans le flipud la matrice sera inverser verticalement entre grads et matlab % ce qui est normal puisque l'on utilise les coordonn??es Longitude,latitude % sous grads et en incrementant la latitude on progresse vers le haut % alors qu'avec matlab on progresse vers le bas en incrementant l'indice %matrice=flipud(matrice); mat1=fliplr(matrice); mat2=rot90(mat1); nomfichdat=[nomfich,'.dat']; nomfichctl=[nomfich,'.ctl']; fprintf(1,'creation of data file %s \n',nomfichdat); % ouverture du fichier .dat fid=fopen(nomfichdat,'w'); % ecriture de la matrice fwrite(fid,mat2,'float32'); fclose(fid); % init des variables [sxp syp]=size(posit); if (syp~=4) error('eee : incorrect syntaxe, 4 arguments must be given for POSIT'); end lon=posit(1); inclon=posit(2); lat=posit(3); inclat=posit(4); % ici on peut rajouter les test pour voir si les coordonn??es en degr??es sont bonnes if (abs(lon)>180) error('La longitude doit ??tre comprise entre -180 et 180'); elseif (abs(lat>90)) error('La latitude doit ??tre comprise entre -90 et 90') end % Init date for record date1=date; date2=[date1(1:2),upper(date1(4:6)),date1(8:11)]; % test sur les arguments [dimy dimx]=size(matrice); fprintf(1,'creation of definition file %s \n',nomfichctl); % ouverture du fichier .ctl fid=fopen(nomfichctl,'w'); % ecriture ligne par ligne du fichier texte=['DSET ^',nomfichdat,' ',10]; fwrite(fid,texte,'char'); texte=['UNDEF -2E5633 ',10]; fwrite(fid,texte,'char'); texte=['TITLE File generated by sauvegrads de MATLAB ',10]; fwrite(fid,texte,'char'); texte=['XDEF ',num2str(dimx),' LINEAR ',num2str(lon),' ',num2str(inclon),' ',10]; fwrite(fid,texte,'char'); texte=['YDEF ',num2str(dimy),' LINEAR ',num2str(lat),' ',num2str(inclat),' ',10]; fwrite(fid,texte,'char'); texte=['ZDEF ',num2str(dimx*dimy),' LINEAR 1 1 ',10]; fwrite(fid,texte,'char'); texte=['TDEF 1 LINEAR ',num2str(date2),' 1DY ',10]; fwrite(fid,texte,'char'); texte=['VARS 1 ',10]; fwrite(fid,texte,'char'); texte=[nomfich,' 0 99 ',num2str(dimx*dimy),' Matrice d''isovaleurs de MATLAB ',10]; fwrite(fid,texte,'char'); texte=['ENDVARS ',10]; fwrite(fid,texte,'char'); % fermeture du fichier fclose(fid);