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