/* read_3dot.c Tina Suen 9-12-05 12-21-05 Example program to read 3.* files. - A line of data in the 3.* file consists of: ID ID of ship/buoy year year month month day day hour hour lat latitude that observation corresponds to lon longitude that observation corresponds to u zonal wind speed v meridional wind speed ta air temperature qa specific humidity sst sea surface temperature taux zonal surface stress tauy meridional surface stress shf sensible heat flux lhf latent heat flux press sea level pressure sd swell direction wh wave height All values at 10m except press, sst, sd, and wh. */ #include #include #include #include #include #include typedef struct { char ID[8]; int year; int month; int day; float hour; float lat, lon; float vars[12]; } DATA; int main() { //char InFile[] = "/Net/scratch1/winde/newwinds/3.moored2002"; //char InFile[] = "/Net/scratch1/winde/newwinds/3.drifting2002"; char InFile[] = "/Net/scratch1/winde/newwinds/3.VOS2002"; DATA buf[200]; int input; ssize_t nread; input = open(InFile, O_RDONLY); if ( !input ) { printf( "Can't open file\n" ); exit(1); } // Try to read 200 observations at a time. Actual num read is nread. while ( (nread = read( input, &buf, sizeof(DATA)*200 )) > 0 ) { int obs_read = nread / sizeof(DATA); int obs; // Loop through nread obs for ( obs = 0; obs < obs_read; ++obs ) { // access to each obs here // ex: printf( "%s %d %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", buf[obs].ID, buf[obs].year, buf[obs].month, buf[obs].day, buf[obs].hour, buf[obs].lat, buf[obs].lon, buf[obs].vars[0], buf[obs].vars[1], buf[obs].vars[2], buf[obs].vars[3], buf[obs].vars[4], buf[obs].vars[5], buf[obs].vars[6], buf[obs].vars[7], buf[obs].vars[8], buf[obs].vars[9], buf[obs].vars[10], buf[obs].vars[11] ); } } return 0; }