# This awk script is supposed to take and extract the data # from each line in an ASCII FLEX output file of wind data ... # input format is "MM/DD/YYYY|DATA0|DATA1|... " format # where: # DATAx is paired wind direction/wind speed data at hour "x" (0-23) # output format is "YYYY MM DD wd0 ws0 wd1 ws1 ... wd23 ws23" format # where: # "wsx" is wind speed in (m/2) at hour "x" (0-23) # "wdx" is wind direction (degrees) at hour "x" (0-23) # missing hourly data is output as -1 for both wind speed and direction # variable definitions: # DATA[1] is month # DATA[2] is day # DATA[3] is year # DATA[4-27] is paired wind direction/wind speed data for hours (0-23) BEGIN { FS = "[/|]" OFS = "\t" } { N = split($0, DATA, "[/|]") # print "N is", N, DATA[0], DATA[1], DATA[2], DATA[3], DATA[4] # Notify us if we don't have 24 hours of data # Note that each input line ends with the "|" delimiter # So nawk thinks there is a 28th field, which is blank if (N != 28) { printf("Data invalid, should have 27 fields but have %d\n",N) printf("N is: %d, %s \n", N, DATA[N]) } # print the Year, Month, Day printf("%.4s %.2s %.2s ", DATA[3], DATA[1], DATA[2]) # print the wind direction and wind speed for each hour for (i=4; i<=N; i++) { SLEN = length(DATA[i]) # missing data for this observation hour if (SLEN < 4) { printf("-1 -1 ") } else if (SLEN == 4) { printf("%.1s %.3s ", DATA[i], substr(DATA[i],SLEN-3+1,3)) } else if (SLEN == 5) { printf("%.2s %.3s ", DATA[i], substr(DATA[i],SLEN-3+1,3)) } else if (SLEN == 6) { printf("%.3s %.3s ", DATA[i], substr(DATA[i],SLEN-3+1,3)) } } printf("\n") }