Ascii conversion

Valentina Radic valentina.radic at NATGEO.SU.SE
Mon Jan 23 04:45:33 EST 2006


Here is one example that may help:

A script (convert.gs) for converting binary to ASCII format. Used when the
time series from one grid point needs to be converted to ASCII in order to
be read and manipulated in some other programs (Fortran, Matlab,
):

'open filename.ctl'
'set gxout print'
'set prnopts %8.5e 1'
'set lat 61.5'                  - defines the latitude of the grid point
'set lon 7.0'                   - defines the longitude of the grid point
'set t 1 365'                   - defines the time period (365 days)
'd LSPsfc'
say result
write ('testA1.txt',result,append)
'reinit'

After running it in GrADS (run convert.gs) the time series is saved as a
column in the testA1.txt file.

Cheers,
Valentina

At 09:34 2006-01-23, you wrote:
>Hi Basit,
>
>nope, but if you use 'set gxout fwrite' and then use my little program
>'binas' which converts binary to ascii, does that help you?
>
>Program is attached. I am afraid that the whole program is in German,
>but it is not that magical.
>
>Regards,
>Heiner
>
>Basit wrote:
>>hello
>>Does anybody know grads script to get out put in ascii format instead of
>>plotting
>>
>>Regards
>>Basit
>>
>>
>>---------------------------------------------
>>This message was sent using Endymion MailMan.
>>http://www.endymion.com/products/mailman/
>
>--
>Heiner Körnich
>Dept. of Meteorology                    Tel:    +46 8 164333
>Stockholms University
>SE-106 91 Stockholm, Sweden             Email:  heiner at misu.su.se
>
>
>
>/***********************************************************\
>*  'binas' wandelt einen bin"aeren Datensatz in einen       *
>*  ASCII-Datensatz um. Der Name der unzuwandelden Datei     *
>*  wird in den Programmaufruf geschrieben.                  *
>*  (z.B. binas.exe bin.ini liefert eine bin.ini.a)          *
>*  (Heiner K"ornich,IAP K-Born, 22.7.97)                    *
>\***********************************************************/
>
>#include <stdio.h>
>#include <string.h>
>/* #include "NT_LEVELS.h" */   /* "Ubergabe von NT,M1,M2,Mi,LEVELS,NW */
>
>
>
>int main (int anzahl, char *argument[])
>{
>    int error=0,i;
>    FILE *binf, *asciif;
>    float ueber[1];
>
>    if(anzahl!=2)
>    {
>      printf("Bitte genau ein Argument eingeben!!!\n");
>      return 1;
>    }
>    binf=fopen(argument[1],"rb");
>    if(binf==0)
>    {
>       printf("Die Datei \"%s\" gibt's ja gar nicht.\n",argument[1]);
>       return 1;
>    }
>    printf("Na gut!\n");
>    asciif=fopen(strcat(argument[1],".a"),"w");
>
>    while(fread(ueber,sizeof(float),1,binf)!=0)
>    {
>       fprintf(asciif,"%E \n",ueber[0]);
>       error+=1;
>/*      if(error%5==0) fprintf(asciif,"\n");*/
>    }
>    printf("Uebertragungen: %d\n",error);
>    return 0;
>}

Valentina Radic
Department of Physical Geography and Quaternary Geology
Stockholm University, SE - 106 91 Stockholm, SWEDEN
Tel:  +46 - 8 - 16 47 67  Fax:  +46 - 8 - 16 48 18
www.glaciology.su.se



More information about the gradsusr mailing list