#include /*c-style io */ #include #define infile "/web/ftp/pub/mesonet/data/sflist_all.utah" main(int argc, char *argv[]) { FILE *input; char station[3],unit[3],outfil[80]; /* input variables */ char line[240]; char stn[4],date[12],wthr[7]; float mnet,slat,slon,selv,tmpf,sknt,drct,gust,pmsl,alti,dwpf,relh,p24i; /* *** input fields *** 1st argument on command linestation = "SNH"; WBB- university; SNH sandy; SLC SALT LAKE; unit = "MKS"; MKS =m/s, etc. anything else will give english */ if ( argc != 3){ /* 3 cause 2 on command line plus program name in[0] */ printf("Error: wrong number of arguments %d\n",argc); return(0); } printf(" Stn Time Temp Sped Drct Gust\n"); /************** OPEN FILE AND GET DATA ************************/ input = fopen(infile,"r"); while ((fgets(line,sizeof(line),input)) != NULL ) { sscanf(line," %s %s %f %f %f %f %f %f %f %f %f %f %f %f %s %f" ,stn,date,&mnet,&slat,&slon,&selv,&tmpf,&sknt,&drct,&gust, &pmsl,&alti,&dwpf,&relh,wthr,&p24i); if ( strncmp(argv[1],stn,3) == 0 ) { /************ CONVERT TO MKS OR USE ENGLISH UNITS ********************** -9999. means missing */ if ( strncmp(argv[2],"MKS",3) == 0 ) { if (tmpf != -9999.)tmpf = (tmpf - 32.) * 5. / 9.; if (sknt != -9999.)sknt = sknt * .51444; if (gust != -9999.)gust = gust * .51444; } printf("%s %s %f %f %f %f \n", stn, date, tmpf, sknt, drct, gust); } } }