#include /* Structure that describes a report header in a stn file */ struct rpthdr { char id[5]; /* Station ID */ float lat; /* Latitude of Station */ float lon; /* Longitude of Station */ float t; /* Time in grid-relative units */ int nlev; /* Number of levels following */ int flag; /* Level independent var set flag */ } hdr; main () { FILE *ifile, *ofile; /* rec wuole la dimensione */ int flag; int fascia; int fasciasav; int i; /* float val;*/ int alt; /* quota */ int temp; /* temperatura*/ float vin; /* int velocita */ float vdi; /* dir velocita */ int acc; /* accumulata */ int cc; /* copertura nuvolosa */ /* Read, write loop */ flag = 1; /* Open files */ ifile = fopen ("/home/grib/teresa/db/archivio_x_wrf/20080603.txt","r"); ofile = fopen ("/home/grib/teresa/db/archivio_x_wrf/20080603.txt.dat","wb"); if (ifile==NULL || ofile==NULL) { printf("Error opening files\n"); return; } else { printf("File opened successfully.\n"); i = 0 ; while(!feof(ifile)) { /* loop through and store the numbers into the array */ fscanf(ifile, "%i %s %g %g %i %i %g %g %i %i",&fascia,&hdr.id,&hdr.lat,&hdr.lon,&alt,&temp,&vin,&vdi,&acc,&cc); /* Time group terminator if needed */ if (flag) { fasciasav = fascia; flag = 0; } if (fasciasav!=fascia) { hdr.nlev = 0; fwrite(&hdr,sizeof(struct rpthdr), 1, ofile); } fasciasav = fascia; printf("%i,%s,%g,%g,%i,%i,%g,%g,%i,%i\n",fascia,hdr.id,hdr.lat,hdr.lon,alt,temp,vin,vdi,acc,cc); /* Write this report */ hdr.nlev = 1; hdr.flag = 1; hdr.t = 0.0; fwrite (&hdr,sizeof(struct rpthdr), 1, ofile); fwrite (&alt,sizeof(float), 1, ofile); fwrite (&temp,sizeof(float), 1, ofile); fwrite (&vin,sizeof(float), 1, ofile); fwrite (&vdi,sizeof(float), 1, ofile); fwrite (&acc,sizeof(float), 1, ofile); fwrite (&cc,sizeof(float), 1, ofile); i++; }/* while */ hdr.nlev = 0; fwrite (&hdr,sizeof(struct rpthdr), 1, ofile); } /* IF Open files */ }