ascii

Mallikarjun arjunjt at CAOS.IISC.ERNET.IN
Thu Feb 3 15:09:48 EST 2005


Hello Mike,

 here is a C code that will convert ascii data to grads
readable format. Then you should open that in descriptor
file.

#include<stdio.h>
main(int argc, char *argv[])
{ FILE *fp,*np;
  float a;
  int i;
    if(argc!=3)
  {puts("Your command should be only three arguments");
          exit(1);
  }

  fp=fopen(argv[1],"r");
  np=fopen(argv[2],"wb");
  if(fp==NULL && np==NULL)
  {  puts("Invalid Path or The File Doesn't Exist\n");
     exit(1);
  }
while(!feof(fp))
{   fscanf(fp,"%f",&a);
    fwrite(&a,sizeof(float),1,np);
    //fprintf(np,"\n");
}
   fclose(fp);
   fclose(np);
   printf("The BINARY file created\n");
                 }


If there is any bug, let me know..

All the best..

--
Mallikarjuna.K
J.R.F
Centre for Atmospheric and Oceanic Sciences
Indian Institute of Science
Bangalore - 560 012



More information about the gradsusr mailing list