/************************************************************************ * dat2cm reads a file in gmtplus-dat format and convert to the NAVO * * NGA, NOAA, SIO common format * ************************************************************************/ /************************************************************************ * Creator: David T. Sandwell (Scripps Institution of Oceanography) * * Date : 09286/06 * ************************************************************************/ /************************************************************************ * Modification History: * * Date : * * * ************************************************************************/ #include #include #include #include main(int argc, char **argv) { char line[512]; char data[14][11]; char time_data[20]; double lat,lon; int time,depth,pred; int id,iflag,nrec,sigh,sigd,sigdi; if(argc < 4){ fprintf(stderr,"usage: %s sig_h sig_d source_id < file.dat > file.cm\n\n",argv[0]); fprintf(stderr," sig_h - horizontal uncertainty (m) (0 no estimate)\n"); fprintf(stderr," sig_d - depth uncertainty (m) (-1 no estimate)\n"); fprintf(stderr," source_id unique ID number for each file\n\n"); exit(-1); } /* parse the command line */ sigh=atoi(argv[1]); sigdi=atoi(argv[2]); id=atoi(argv[3]); /* skip the first two lines of the file */ fgets(line,512,stdin); fgets(line,512,stdin); /* read all the data */ nrec=0; while (fgets(line,512,stdin)) { sscanf (line, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s", time_data, data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13]); /* extract the depth data only. skip ver NaN */ if(strcmp(data[8],"NaN") != 0) { sscanf(time_data, "%d", &time); sscanf(data[1], "%lf", &lat); sscanf(data[2], "%lf", &lon); pred=9999.; if(strcmp(data[5],"NaN") != 0) sscanf(data[5], "%d", &pred); sscanf(data[8], "%d", &depth); sscanf(data[13], "%d", &iflag); nrec++; /* prepare the data for output */ if(lon > 180.) lon = lon-360.; sigd=sigdi; if(iflag & 256) sigd=9999.; printf("%d %.5f %.5f %d %d %d %d %d \n",time,lon,lat,depth,sigh,sigd,id,pred); } } }