#! /bin/csh -f source ~dss/.cshrc # # 'gribext1.0' uses WGRIB to extract GRIB fields from one or more # NCEP 1.0 degree GRIB files in ~ftp/datasets/ds083.2/data # # Users will need to modify directory names to run on their own # computers - it will not work for them on the DSS web site # # wgrib usage and tricks described below the code. # # Written by G. Walters - Dec 2003 # set statexec = "BEFORE CEASING" onintr quit set src = "~dss/bin" set tds = `$src/.tmpdss` set pid = "$$" # set maindir = "~ftp/datasets/ds083.2/data" cd $maindir # set hrmi = `date +%r | cut -c1-5 | sed s/\://g` set now = `date +%y%m%d` set now = "$now.$hrmi" set stamp = "$now.$pid" set maxout = 500000000 # the volume of a ds083.2 10 day archive backup file is about 1GB # # this is half that set dump = 0 # set = 1 to dump diagnostics # # NOTE- the control file (ctrl.$stamp) could be built # through a GUI by users on our Web site running a # cgi-bin script... # onintr onintr cease set statexec = "OK" cat << ! >! ctrl.$stamp CONTROL FILE ----------------------------------------------------------------------------------------------------------------------- d=0311.... d=0312.... HGT TMP RH UGRD VGRD 850.mb 500.mb 300.mb PLUS++++++++++++ d=0311.... d=0312.... TMP SOILW 0-10.cm.down 10-200.cm.down STOP PLEASE READ: The WGRIB software provides for the extraction of fields by allowing the user to select the desired fields using information in the WGRIB inventory entries to specify the fields. This control file helps the user communicate his needs to the WGRIB extraction mode, to be obtained from one or more data files. The list controls the extraction, and the sequencing of the list is significant. The first line specifies the first step in the extraction, which obtains a subset of the lines from the data file's WGRIB inventory. Successive lines in the control list obtain a subset from the preceding subset. Thus we are passing the inventory information through a series of filters, where the final results are passed to the WGRIB extraction process. Lines may consist of more than one field ID, which are effectively logical ORs. Successive lines are effectively logical ANDs. Subsetting is terminated by a line which simply says "STOP". If you want to apply more than one series of filters, then terminate each of these with "PLUS", do not use "STOP" until you have given all the series you want. You may add other things to the line showing "PLUS" as a visual aid to separate your series, as shown in the sample above. The sample above should be edited to suit your needs. In this sample, the first series of filters begins with a specification that allows all analysis times from 2003nov or 2003dec to pass to the next filter. The "." is a wild card for a single character, which in this case allows all days and all times. The next filter passes all height, temperature, relative humidity, u-wind or v-winds; the next passes all 850, 500 or 300 mb levels. Then a second series of filters is appended, first terminating the previous series with "PLUS". This series begins with a filter to pass all temperatures and soil moisture fields, and then only those at 0-10.cm or 10-200.cm . Other wild cards besides "." may be attempted, but performance is not guaranteed. For related information about WGRIB usage, see ftp://wesley.wwb.noaa.gov/pub/wgrib/tricks.wgrib . Wesley's examples were an inspiration for this software... Many field IDs are shown in the following sample inventory (made by using "wgrib -s" on a typical NCEP 1.0-degree data file). The IDs are separated by colons (:) and may include embedded blanks. In the control list, you must replace these blanks with periods "." You may notice that each entry in this inventory shows "anl", which means analysis. Other GRIB files may show something for forecasts, or both. For a description of all the field IDs, see the GRIB documentation http://dss.ucar.edu/docs/formats/grib/gribdoc/ Note that the first field ID is the field number, which should not be used to select fields, because the content of a field identified only by this number can vary from file to file. Some users have been surprised by this mistake when this number changes, such as when NCEP adds more to the data files. The second field ID is the byte position of the beginning of the field in the data file, where the very first is 0 (IBM speak). This also should not be used to select fields, because for any given field, this changes from one GRIB data file to another, due to GRIB's dynamic packing scheme. Note that GRIB files usually have the form of a bitstream. Some may have had padding added to make fixed length field records. SAMPLE INVENTORY 1:0:d=03120100:HGT:1000 mb:anl:NAve=0 2:105968:d=03120100:HGT:975 mb:anl:NAve=0 3:211936:d=03120100:HGT:950 mb:anl:NAve=0 4:317904:d=03120100:HGT:925 mb:anl:NAve=0 5:423872:d=03120100:HGT:900 mb:anl:NAve=0 6:529840:d=03120100:HGT:850 mb:anl:NAve=0 7:635808:d=03120100:HGT:800 mb:anl:NAve=0 8:741776:d=03120100:HGT:750 mb:anl:NAve=0 9:847744:d=03120100:HGT:700 mb:anl:NAve=0 10:961858:d=03120100:HGT:650 mb:anl:NAve=0 11:1075972:d=03120100:HGT:600 mb:anl:NAve=0 12:1190086:d=03120100:HGT:550 mb:anl:NAve=0 13:1304200:d=03120100:HGT:500 mb:anl:NAve=0 14:1418314:d=03120100:HGT:450 mb:anl:NAve=0 15:1532428:d=03120100:HGT:400 mb:anl:NAve=0 16:1646542:d=03120100:HGT:350 mb:anl:NAve=0 17:1760656:d=03120100:HGT:300 mb:anl:NAve=0 18:1874770:d=03120100:HGT:250 mb:anl:NAve=0 19:1997028:d=03120100:HGT:200 mb:anl:NAve=0 20:2119286:d=03120100:HGT:150 mb:anl:NAve=0 21:2241544:d=03120100:HGT:100 mb:anl:NAve=0 22:2355658:d=03120100:HGT:70 mb:anl:NAve=0 23:2469772:d=03120100:HGT:50 mb:anl:NAve=0 24:2583886:d=03120100:HGT:30 mb:anl:NAve=0 25:2706144:d=03120100:HGT:20 mb:anl:NAve=0 26:2828402:d=03120100:HGT:10 mb:anl:NAve=0 27:2950660:d=03120100:TMP:1000 mb:anl:NAve=0 28:3032194:d=03120100:TMP:975 mb:anl:NAve=0 29:3113728:d=03120100:TMP:950 mb:anl:NAve=0 30:3195262:d=03120100:TMP:925 mb:anl:NAve=0 31:3276796:d=03120100:TMP:900 mb:anl:NAve=0 32:3358330:d=03120100:TMP:850 mb:anl:NAve=0 33:3439864:d=03120100:TMP:800 mb:anl:NAve=0 34:3521398:d=03120100:TMP:750 mb:anl:NAve=0 35:3602932:d=03120100:TMP:700 mb:anl:NAve=0 36:3684466:d=03120100:TMP:650 mb:anl:NAve=0 37:3766000:d=03120100:TMP:600 mb:anl:NAve=0 38:3847534:d=03120100:TMP:550 mb:anl:NAve=0 39:3929068:d=03120100:TMP:500 mb:anl:NAve=0 40:4002456:d=03120100:TMP:450 mb:anl:NAve=0 41:4075844:d=03120100:TMP:400 mb:anl:NAve=0 42:4149232:d=03120100:TMP:350 mb:anl:NAve=0 43:4222620:d=03120100:TMP:300 mb:anl:NAve=0 44:4296008:d=03120100:TMP:250 mb:anl:NAve=0 45:4369396:d=03120100:TMP:200 mb:anl:NAve=0 46:4442784:d=03120100:TMP:150 mb:anl:NAve=0 47:4516172:d=03120100:TMP:100 mb:anl:NAve=0 48:4589560:d=03120100:TMP:70 mb:anl:NAve=0 49:4662948:d=03120100:TMP:50 mb:anl:NAve=0 50:4736336:d=03120100:TMP:30 mb:anl:NAve=0 51:4817870:d=03120100:TMP:20 mb:anl:NAve=0 52:4899404:d=03120100:TMP:10 mb:anl:NAve=0 53:4980938:d=03120100:VVEL:1000 mb:anl:NAve=0 54:5078762:d=03120100:VVEL:975 mb:anl:NAve=0 55:5176586:d=03120100:VVEL:950 mb:anl:NAve=0 56:5274410:d=03120100:VVEL:925 mb:anl:NAve=0 57:5372234:d=03120100:VVEL:900 mb:anl:NAve=0 58:5470058:d=03120100:VVEL:850 mb:anl:NAve=0 59:5576026:d=03120100:VVEL:800 mb:anl:NAve=0 60:5681994:d=03120100:VVEL:750 mb:anl:NAve=0 61:5787962:d=03120100:VVEL:700 mb:anl:NAve=0 62:5893930:d=03120100:VVEL:650 mb:anl:NAve=0 63:5999898:d=03120100:VVEL:600 mb:anl:NAve=0 64:6105866:d=03120100:VVEL:550 mb:anl:NAve=0 65:6211834:d=03120100:VVEL:500 mb:anl:NAve=0 66:6317802:d=03120100:VVEL:450 mb:anl:NAve=0 67:6423770:d=03120100:VVEL:400 mb:anl:NAve=0 68:6529738:d=03120100:VVEL:350 mb:anl:NAve=0 69:6635706:d=03120100:VVEL:300 mb:anl:NAve=0 70:6741674:d=03120100:VVEL:250 mb:anl:NAve=0 71:6839498:d=03120100:VVEL:200 mb:anl:NAve=0 72:6929176:d=03120100:VVEL:150 mb:anl:NAve=0 73:7010710:d=03120100:VVEL:100 mb:anl:NAve=0 74:7084098:d=03120100:RH:1000 mb:anl:NAve=0 75:7141196:d=03120100:RH:975 mb:anl:NAve=0 76:7198294:d=03120100:RH:950 mb:anl:NAve=0 77:7255392:d=03120100:RH:925 mb:anl:NAve=0 78:7312490:d=03120100:RH:900 mb:anl:NAve=0 79:7369588:d=03120100:RH:850 mb:anl:NAve=0 80:7426686:d=03120100:RH:800 mb:anl:NAve=0 81:7483784:d=03120100:RH:750 mb:anl:NAve=0 82:7540882:d=03120100:RH:700 mb:anl:NAve=0 83:7597980:d=03120100:RH:650 mb:anl:NAve=0 84:7655078:d=03120100:RH:600 mb:anl:NAve=0 85:7712176:d=03120100:RH:550 mb:anl:NAve=0 86:7769274:d=03120100:RH:500 mb:anl:NAve=0 87:7826372:d=03120100:RH:450 mb:anl:NAve=0 88:7883470:d=03120100:RH:400 mb:anl:NAve=0 89:7940568:d=03120100:RH:350 mb:anl:NAve=0 90:7997666:d=03120100:RH:300 mb:anl:NAve=0 91:8054764:d=03120100:RH:250 mb:anl:NAve=0 92:8111862:d=03120100:RH:200 mb:anl:NAve=0 93:8168960:d=03120100:RH:150 mb:anl:NAve=0 94:8226058:d=03120100:RH:100 mb:anl:NAve=0 95:8283156:d=03120100:ABSV:1000 mb:anl:NAve=0 96:8364690:d=03120100:ABSV:975 mb:anl:NAve=0 97:8446224:d=03120100:ABSV:950 mb:anl:NAve=0 98:8535902:d=03120100:ABSV:925 mb:anl:NAve=0 99:8625580:d=03120100:ABSV:900 mb:anl:NAve=0 100:8715258:d=03120100:ABSV:850 mb:anl:NAve=0 101:8804936:d=03120100:ABSV:800 mb:anl:NAve=0 102:8894614:d=03120100:ABSV:750 mb:anl:NAve=0 103:8984292:d=03120100:ABSV:700 mb:anl:NAve=0 104:9073970:d=03120100:ABSV:650 mb:anl:NAve=0 105:9155504:d=03120100:ABSV:600 mb:anl:NAve=0 106:9237038:d=03120100:ABSV:550 mb:anl:NAve=0 107:9318572:d=03120100:ABSV:500 mb:anl:NAve=0 108:9400106:d=03120100:ABSV:450 mb:anl:NAve=0 109:9481640:d=03120100:ABSV:400 mb:anl:NAve=0 110:9563174:d=03120100:ABSV:350 mb:anl:NAve=0 111:9644708:d=03120100:ABSV:300 mb:anl:NAve=0 112:9726242:d=03120100:ABSV:250 mb:anl:NAve=0 113:9807776:d=03120100:ABSV:200 mb:anl:NAve=0 114:9889310:d=03120100:ABSV:150 mb:anl:NAve=0 115:9962698:d=03120100:ABSV:100 mb:anl:NAve=0 116:10036086:d=03120100:ABSV:70 mb:anl:NAve=0 117:10109474:d=03120100:ABSV:50 mb:anl:NAve=0 118:10182862:d=03120100:ABSV:30 mb:anl:NAve=0 119:10256250:d=03120100:ABSV:20 mb:anl:NAve=0 120:10329638:d=03120100:ABSV:10 mb:anl:NAve=0 121:10403026:d=03120100:O3MR:100 mb:anl:NAve=0 122:10500850:d=03120100:O3MR:70 mb:anl:NAve=0 123:10606818:d=03120100:O3MR:50 mb:anl:NAve=0 124:10712786:d=03120100:O3MR:30 mb:anl:NAve=0 125:10818754:d=03120100:O3MR:20 mb:anl:NAve=0 126:10932868:d=03120100:O3MR:10 mb:anl:NAve=0 127:11055126:d=03120100:CLWMR:1000 mb:anl:NAve=0 128:11128514:d=03120100:CLWMR:975 mb:anl:NAve=0 129:11201902:d=03120100:CLWMR:950 mb:anl:NAve=0 130:11275290:d=03120100:CLWMR:925 mb:anl:NAve=0 131:11348678:d=03120100:CLWMR:900 mb:anl:NAve=0 132:11422066:d=03120100:CLWMR:850 mb:anl:NAve=0 133:11503600:d=03120100:CLWMR:800 mb:anl:NAve=0 134:11585134:d=03120100:CLWMR:750 mb:anl:NAve=0 135:11666668:d=03120100:CLWMR:700 mb:anl:NAve=0 136:11748202:d=03120100:CLWMR:650 mb:anl:NAve=0 137:11829736:d=03120100:CLWMR:600 mb:anl:NAve=0 138:11911270:d=03120100:CLWMR:550 mb:anl:NAve=0 139:11992804:d=03120100:CLWMR:500 mb:anl:NAve=0 140:12074338:d=03120100:CLWMR:450 mb:anl:NAve=0 141:12155872:d=03120100:CLWMR:400 mb:anl:NAve=0 142:12237406:d=03120100:CLWMR:350 mb:anl:NAve=0 143:12318940:d=03120100:CLWMR:300 mb:anl:NAve=0 144:12408618:d=03120100:CLWMR:250 mb:anl:NAve=0 145:12498296:d=03120100:CLWMR:200 mb:anl:NAve=0 146:12587974:d=03120100:CLWMR:150 mb:anl:NAve=0 147:12661362:d=03120100:CLWMR:100 mb:anl:NAve=0 148:12718460:d=03120100:5WAVH:500 mb:anl:NAve=0 149:12832574:d=03120100:UGRD:1000 mb:anl:NAve=0 150:12905962:d=03120100:UGRD:975 mb:anl:NAve=0 151:12987496:d=03120100:UGRD:950 mb:anl:NAve=0 152:13069030:d=03120100:UGRD:925 mb:anl:NAve=0 153:13150564:d=03120100:UGRD:900 mb:anl:NAve=0 154:13232098:d=03120100:UGRD:850 mb:anl:NAve=0 155:13313632:d=03120100:UGRD:800 mb:anl:NAve=0 156:13395166:d=03120100:UGRD:750 mb:anl:NAve=0 157:13476700:d=03120100:UGRD:700 mb:anl:NAve=0 158:13558234:d=03120100:UGRD:650 mb:anl:NAve=0 159:13639768:d=03120100:UGRD:600 mb:anl:NAve=0 160:13721302:d=03120100:UGRD:550 mb:anl:NAve=0 161:13802836:d=03120100:UGRD:500 mb:anl:NAve=0 162:13884370:d=03120100:UGRD:450 mb:anl:NAve=0 163:13965904:d=03120100:UGRD:400 mb:anl:NAve=0 164:14055582:d=03120100:UGRD:350 mb:anl:NAve=0 165:14145260:d=03120100:UGRD:300 mb:anl:NAve=0 166:14234938:d=03120100:UGRD:250 mb:anl:NAve=0 167:14324616:d=03120100:UGRD:200 mb:anl:NAve=0 168:14414294:d=03120100:UGRD:150 mb:anl:NAve=0 169:14495828:d=03120100:UGRD:100 mb:anl:NAve=0 170:14577362:d=03120100:UGRD:70 mb:anl:NAve=0 171:14658896:d=03120100:UGRD:50 mb:anl:NAve=0 172:14740430:d=03120100:UGRD:30 mb:anl:NAve=0 173:14821964:d=03120100:UGRD:20 mb:anl:NAve=0 174:14903498:d=03120100:UGRD:10 mb:anl:NAve=0 175:14993176:d=03120100:VGRD:1000 mb:anl:NAve=0 176:15074710:d=03120100:VGRD:975 mb:anl:NAve=0 177:15156244:d=03120100:VGRD:950 mb:anl:NAve=0 178:15237778:d=03120100:VGRD:925 mb:anl:NAve=0 179:15319312:d=03120100:VGRD:900 mb:anl:NAve=0 180:15400846:d=03120100:VGRD:850 mb:anl:NAve=0 181:15482380:d=03120100:VGRD:800 mb:anl:NAve=0 182:15563914:d=03120100:VGRD:750 mb:anl:NAve=0 183:15645448:d=03120100:VGRD:700 mb:anl:NAve=0 184:15726982:d=03120100:VGRD:650 mb:anl:NAve=0 185:15808516:d=03120100:VGRD:600 mb:anl:NAve=0 186:15890050:d=03120100:VGRD:550 mb:anl:NAve=0 187:15971584:d=03120100:VGRD:500 mb:anl:NAve=0 188:16061262:d=03120100:VGRD:450 mb:anl:NAve=0 189:16150940:d=03120100:VGRD:400 mb:anl:NAve=0 190:16240618:d=03120100:VGRD:350 mb:anl:NAve=0 191:16330296:d=03120100:VGRD:300 mb:anl:NAve=0 192:16419974:d=03120100:VGRD:250 mb:anl:NAve=0 193:16509652:d=03120100:VGRD:200 mb:anl:NAve=0 194:16599330:d=03120100:VGRD:150 mb:anl:NAve=0 195:16680864:d=03120100:VGRD:100 mb:anl:NAve=0 196:16762398:d=03120100:VGRD:70 mb:anl:NAve=0 197:16843932:d=03120100:VGRD:50 mb:anl:NAve=0 198:16925466:d=03120100:VGRD:30 mb:anl:NAve=0 199:16998854:d=03120100:VGRD:20 mb:anl:NAve=0 200:17080388:d=03120100:VGRD:10 mb:anl:NAve=0 201:17161922:d=03120100:TMP:30-0 mb above gnd:anl:NAve=0 202:17243456:d=03120100:RH:30-0 mb above gnd:anl:NAve=0 203:17300554:d=03120100:SPFH:30-0 mb above gnd:anl:NAve=0 204:17390232:d=03120100:UGRD:30-0 mb above gnd:anl:NAve=0 205:17471766:d=03120100:VGRD:30-0 mb above gnd:anl:NAve=0 206:17553300:d=03120100:TMP:1829 m above MSL:anl:NAve=0 207:17634834:d=03120100:TMP:2743 m above MSL:anl:NAve=0 208:17716368:d=03120100:TMP:3658 m above MSL:anl:NAve=0 209:17797902:d=03120100:UGRD:1829 m above MSL:anl:NAve=0 210:17879436:d=03120100:UGRD:2743 m above MSL:anl:NAve=0 211:17960970:d=03120100:UGRD:3658 m above MSL:anl:NAve=0 212:18042504:d=03120100:VGRD:1829 m above MSL:anl:NAve=0 213:18124038:d=03120100:VGRD:2743 m above MSL:anl:NAve=0 214:18205572:d=03120100:VGRD:3658 m above MSL:anl:NAve=0 215:18287106:d=03120100:HGT:32770 (pv units):anl:NAve=0 216:18368440:d=03120100:HGT:2 (pv units):anl:NAve=0 217:18448166:d=03120100:TMP:32770 (pv units):anl:NAve=0 218:18497012:d=03120100:TMP:2 (pv units):anl:NAve=0 219:18544964:d=03120100:PRES:32770 (pv units):anl:NAve=0 220:18618176:d=03120100:PRES:2 (pv units):anl:NAve=0 221:18689958:d=03120100:VWSH:32770 (pv units):anl:NAve=0 222:18734742:d=03120100:VWSH:2 (pv units):anl:NAve=0 223:18778722:d=03120100:UGRD:32770 (pv units):anl:NAve=0 224:18831628:d=03120100:UGRD:2 (pv units):anl:NAve=0 225:18883552:d=03120100:VGRD:32770 (pv units):anl:NAve=0 226:18936458:d=03120100:VGRD:2 (pv units):anl:NAve=0 227:18988382:d=03120100:PRES:sfc:anl:NAve=0 228:19118786:d=03120100:PWAT:atmos col:anl:NAve=0 229:19200320:d=03120100:RH:atmos col:anl:NAve=0 230:19257418:d=03120100:HGT:tropopause:anl:NAve=0 231:19395966:d=03120100:TMP:tropopause:anl:NAve=0 232:19477500:d=03120100:PRES:tropopause:anl:NAve=0 233:19607904:d=03120100:VWSH:tropopause:anl:NAve=0 234:19681292:d=03120100:LFTX:sfc:anl:NAve=0 235:19754680:d=03120100:CAPE:sfc:anl:NAve=0 236:19852504:d=03120100:CIN:sfc:anl:NAve=0 237:19925892:d=03120100:4LFTX:sfc:anl:NAve=0 238:19999280:d=03120100:CAPE:180-0 mb above gnd:anl:NAve=0 239:20097104:d=03120100:CIN:180-0 mb above gnd:anl:NAve=0 240:20170492:d=03120100:HGT:max wind lev:anl:NAve=0 241:20317186:d=03120100:TMP:max wind lev:anl:NAve=0 242:20398720:d=03120100:PRES:max wind lev:anl:NAve=0 243:20529124:d=03120100:HGT:sfc:anl:NAve=0 244:20659528:d=03120100:PRMSL:MSL:anl:NAve=0 245:20773642:d=03120100:RH:sigma 0.44-1.00:anl:NAve=0 246:20830740:d=03120100:RH:sigma 0.72-0.94:anl:NAve=0 247:20887838:d=03120100:RH:sigma 0.44-0.72:anl:NAve=0 248:20944936:d=03120100:RH:sigma 0.33-1.00:anl:NAve=0 249:21002034:d=03120100:POT:sigma=0.9950:anl:NAve=0 250:21083568:d=03120100:TMP:sigma=0.9950:anl:NAve=0 251:21165102:d=03120100:VVEL:sigma=0.9950:anl:NAve=0 252:21271070:d=03120100:RH:sigma=0.9950:anl:NAve=0 253:21328168:d=03120100:TOZNE:atmos col:anl:NAve=0 254:21425992:d=03120100:CWAT:atmos col:anl:NAve=0 255:21499380:d=03120100:HGT:0C isotherm:anl:NAve=0 256:21637928:d=03120100:RH:0C isotherm:anl:NAve=0 257:21695026:d=03120100:HGT::anl:NAve=0 258:21833574:d=03120100:RH::anl:NAve=0 259:21890672:d=03120100:UGRD:tropopause:anl:NAve=0 260:21980350:d=03120100:UGRD:max wind lev:anl:NAve=0 261:22070028:d=03120100:UGRD:sigma=0.9950:anl:NAve=0 262:22143416:d=03120100:VGRD:tropopause:anl:NAve=0 263:22233094:d=03120100:VGRD:max wind lev:anl:NAve=0 264:22322772:d=03120100:VGRD:sigma=0.9950:anl:NAve=0 265:22404306:d=03120100:TMP:sfc:anl:NAve=0 266:22485840:d=03120100:SOILW:0-10 cm down:anl:NAve=0 267:22518158:d=03120100:SOILW:10-200 cm down:anl:NAve=0 268:22550476:d=03120100:TMP:0-10 cm down:anl:NAve=0 269:22588146:d=03120100:TMP:10-200 cm down:anl:NAve=0 270:22625816:d=03120100:WEASD:sfc:anl:NAve=0 271:22756220:d=03120100:LAND:sfc:anl:NAve=0 272:22764448:d=03120100:ICEC:sfc:anl:NAve=0 273:22772676:d=03120100:TMP:2 m above gnd:anl:NAve=0 274:22854210:d=03120100:SPFH:2 m above gnd:anl:NAve=0 275:22952034:d=03120100:HPBL:sfc:anl:NAve=0 276:23074292:d=03120100:TCDC:convect-cld layer:anl:NAve=0 277:23131390:d=03120100:PRES:convect-cld top:anl:NAve=0 278:23151318:d=03120100:PRES:convect-cld bot:anl:NAve=0 279:23170558:d=03120100:RH:2 m above gnd:anl:NAve=0 280:23227656:d=03120100:UGRD:10 m above gnd:anl:NAve=0 281:23301044:d=03120100:VGRD:10 m above gnd:anl:NAve=0 282:23382578:d=03120100:GPA:1000 mb:anl:NAve=0 283:23488546:d=03120100:GPA:500 mb:anl:NAve=0 284:23594514:d=03120100:5WAVA:500 mb:anl:NAve=0 ! cat << ! > /dev/tty OPENING YOUR EDITOR ON THE SELECTION CONTROL FILE ! $src/ined ctrl.$stamp if (-z ctrl.$stamp) then set statexec = "EMPTY CONTROL FILE" goto quit endif set stop = (`grep -n "^STOP" ctrl.$stamp | sed s/\:/\ /g`) @ stop = $stop[1] sed -n 2,${stop}p ctrl.$stamp >! ,stop.$pid # skipping the first line @ stop-- mv ,stop.$pid ctrl.$stamp # set more = (1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) set put = ( 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99) # # for a cgi-bin script, will probably need to change $tds to # some ftp public directory # cat << ! >! diags.$stamp OUTPUT FILE(S) CONTAIN NCEP 1.0-DEGREE GRIB FIELDS. Extracted according to the control list below. ! cat ctrl.$stamp >>! diags.$stamp # # A lengthy list of files should be put in a file that can # be parsed by a loop of seds. The following nest of # loops for the ~ftp/datasets/ds083.2/data files happens # to work for those files... # @ pp = 1 # set dirlist # set dirdates = (`grep "d\=" ctrl.$stamp`) if ("$dirdates" != "") then cp /dev/null dir.$stamp set dirmos foreach dd ($dirdates) set dirmo = `echo "$dd" | cut -c3-6` echo "fnl-20$dirmo" >>! dir.$stamp # fnl-20yymm end set dirlist = (`cat dir.$stamp | sort | uniq`) rm -f dir.$stamp endif if ("$dirlist" == "") set dirlist = (fnl*) # set scoop foreach dir ($dirlist) if (! -e $dir) then echo "DIRECTORY $dir NOT AVAILABLE" continue endif echo "PROCESSING DIRECTORY $dir - `date +%r`" set scoop = ($scoop $dir) cd $dir set year = `echo $dir | cut -c5-8` set yr = `echo "$year" | cut -c3-4` set month = `echo $dir | cut -c9-10` set mo = "$month" set moday = `$src/.modays $month $year` if ($status != 0) then echo "INVALID .modays CALL" goto quit endif @ daypt = 0 while ($daypt < $moday) @ daypt++ set day = "$put[$daypt]" foreach hr (00 06 12 18) set takedh = "y" set file = "fnl_$yr$mo${day}_${hr}_00.bin" # fnl_030619_18_00.bin set filetime = `echo "$file" | cut -c5-10,12-13` # yymmddhh # # following code, inside these nested foreaches, shouldn't # require changes for different input data file structures # if (-e $file && ! -z $file) then if ($dump == 1) then echo " PROCESSING INPUT FILE $file - `date +%r`" endif @ ll = 0 @ plus = 1 # point to first extraction list wgrib -s $file >! stuff.$pid set from = "stuff.$pid" while ($ll < $stop) # # tailoring the extraction list for this data file # @ ll++ set these = (`sed -n ${ll}p $maindir/ctrl.$stamp`) set takedh = "y" if ("$these" =~ d=*) then set takedh = "n" foreach daytm ($these) set timeget = `echo "$daytm " | cut -c3-10` set isit = `echo "$filetime" | grep "^$timeget"` if ("$isit" != "") then set takedh = "y" break endif end endif if ("$takedh" == "n") break if ("$these" == "STOP") break if ("$these" =~ PLUS*) then @ plus++ set more[$plus] = $plus wgrib -s $file >! stuff.$pid set from = "stuff.$pid" continue endif cp /dev/null hold.$pid foreach of ($these) grep ":${of}:" $from >>! hold.$pid end mv hold.$pid ext$more[$plus].$pid set from = "ext$more[$plus].$pid" end if ("$takedh" == "n") continue @ poo = 0 while ($poo < $plus) @ poo++ if (-e ext$poo.$pid) then set lenj = (`$src/.lenf ext$poo.$pid`) set lenk = (`$src/.wide ext$poo.$pid`) @ jj = 0 cp /dev/null extmod.$pid while ($jj < $lenj) @ jj++ set line = `sed -n ${jj}p ext$poo.$pid` @ kk = 0 while ($kk < $lenk) @ kk++ set cc = `echo "$line" | cut -c${kk}-${kk}` if ("$cc" == ":") then @ kc = $kk @ kn = $kk - 1 break endif end set rec = `echo "$line" | cut -c1-$kn` set recp = `(echo 6; echo "$rec";) | ~dss/bin/.padf0` set linend = `echo "$line" | cut -c${kc}-` echo "$recp$linend" >>! extmod.$pid end sort extmod.$pid >! ext$poo.$pid # # after sorting, must strip the leading 0s so that the # wgrib extraction won't become confused. the whole # point of this padding/stripping is to preserve the # sort in the input data file # @ jj = 0 cp /dev/null extmod.$pid while ($jj < $lenj) @ jj++ set line = `sed -n ${jj}p ext$poo.$pid` @ kk = 0 while ($kk < $lenk) @ kk++ set cc = `echo "$line" | cut -c${kk}-${kk}` if ("$cc" != "0") then @ kc = $kk break endif end set rec = `echo "$line" | cut -c1-$kn` set recp = `(echo 6; echo "$rec";) | ~dss/bin/.padf0` set linend = `echo "$line" | cut -c${kc}-` echo "$line" | cut -c$kc- >>! extmod.$pid end mv extmod.$pid ext$poo.$pid endif # $src/ined ext$poo.$pid end @ stop = $ll - 1 # if ($dump == 1) then echo "=========================================================================" >>! $maindir/diags.$stamp echo "extract from $file ------------------------------------------------------" >>! $maindir/diags.$stamp endif # # pass the extraction list(s), for this specific data file, # through the WGRIB extraction process # set out = (`ls | grep "^ext[1-9][1-9].$pid"`) if ("$out" != "") then foreach pull ($out) cp /dev/null temp.$pid if (! -z $pull) then # # Wesley Ebisuzaki's example # # wgrib -s $file | grep ":HGT:500 mb:" | wgrib -i -grib grib_file -o new_grib_file # # We must run this loop every time (instead of reusing the # extraction file) to reset the starting byte positions # (within a specific file's bitstream) for the fields # which meet the selections listed in the control file. # In the sample inventory appended to the control file, # the first parameter is the field number, the second # is the starting byte position (the very first is 0). # echo "pulling 1"; cat $pull; echo "pulling 2"; cat $pull | wgrib -i -grib $file -o temp.$pid >! /dev/null else continue endif if (-e temp.$pid) then cat temp.$pid >>! output.$pid rm temp.$pid endif end if (-e output.$pid) then cat output.$pid >>! $maindir/output.$stamp rm output.$pid endif else set statexec = "NO PULL FILES FOR $yr$mo$day.$hr" if ($dump == 1) then echo "$statexec" >>! $maindir/diags.$stamp endif continue endif else cat << ! >> >>! $maindir/diags.$stamp DATA FILE $file IS MISSING OR EMPTY ! endif # # preceding code, inside these nested foreaches, shouldn't # require changes for different input data file structures # end # # every time we finish a day's 6-hourly input files, check the volume of the output file # and flush when it gets past the limit $maxout # if (-e $maindir/output.$stamp) then set sizeo = (`ls -la $maindir/output.$stamp`) if ($sizeo[4] > $maxout) then # the volume of a 10 day archive backup file is about 1GB cat $maindir/output.$stamp >! $tds/output.$put[$pp].$now @ pp++ cp /dev/null $maindir/output.$stamp endif endif end cd .. end # if (-e output.$stamp) then cat output.$stamp >! $tds/output.$put[$pp].$now @ wp = 0 while ($wp < $pp) @ wp++ cat << ! >>! diags.$stamp OUTPUT NUMBER $put[$wp] CONTENTS ! $src/wgribnice $tds/output.$put[$wp].$now >>! diags.$stamp end goto ok else set statexec = "EMPTY OUTPUT" goto cease endif # $src/ined diags.$stamp cease: onintr - if ("$statexec" != "EMPTY OUTPUT") then cd $maindir rm output.$stamp $tds/output.[0-9][0-9].$now set statexec = "INTERRUPTED" endif onintr ok: onintr - cd $maindir if ("$scoop" != "") then foreach dir ($scoop) cd $dir set these set these = `ls -a | grep "ext[1-9]*.$pid"` set these2 = `ls -a | grep "extmod*.$pid"` rm -f output.$pid $these $these2 stuff.$pid temp.$pid cd .. end endif onintr quit: onintr - if (-e diags.$stamp && "$statexec" == "OK") then if ($pp == 1) then cat << ! >! note.$pid OUTPUT FILE IN $tds/output.$put[$pp].$now Move it before it ages off ! else cat << ! >! note.$pid OUTPUT FILES IN $tds/output.$put[1].$now THROUGH $tds/output.$put[$pp].$now Move them before they age off ! endif (cat note.$pid; echo " "; cat diags.$stamp;) | mail -s "gribext1.0 $now results - use editor to view this" ${user}@ucar.edu rm -f note.$pid else echo "${statexec}, EXECUTION TERMINATED" | mail -s "gribext1.0 $now crashed" ${user}@ucar.edu endif sleep 5 rm -f ctrl.$stamp diags.$stamp ,stop.$pid onintr exit wgrib (help) - also see ftp://wesley.wwb.noaa.gov/pub/wgrib/tricks.wgrib Portable Grib decoder for NCEP/NCAR Reanalysis etc. it slices, dices v1.7.3.1 (8-5-99) Wesley Ebisuzaki usage: wgrib [grib file] [options] Inventory/diagnostic-output selections -s/-v short/verbose inventory -V diagnostic output (not inventory) (none) regular inventory Options -PDS/-PDS10 print PDS in hex/decimal -GDS/-GDS10 print GDS in hex/decimal -verf print forecast verification time -ncep_opn/-ncep_rean default T62 NCEP grib table -4yr print year using 4 digits Decoding GRIB selection -d [record number|all] decode record number -p [byte position] decode record at byte position -i decode controlled by stdin (inventory list) (none) no decoding Options -text/-ieee/-grib/-bin convert to text/ieee/grib/bin (default) -nh/-h output will have no headers/headers (default) -H output will include PDS and GDS (-bin/-ieee only) -append append to output file -o [file] output file name, 'dump' is default