#pragma rtGlobals=3 // Use modern global access method and strict wave access. Function CatWind(windwave) Wave windwave Make/FREE binlist = {165,180,210,220,255,300} // the list of bins, i.e., 0 to 165, 165 to 180 etc. ... data above the last item will be stored in 'the rest' // +++ first step: sort the waves after wind direction +++ String Datalist = wavelist("!"+nameofwave(windwave),";","")+nameofwave(windwave) // make a list of all waves, make sure the wind data comes last! Variable i, pointnum String currentname for (i = 0; i < itemsinlist(Datalist); i +=1) // for every data wave sort after wind direction (including wind direction itself) currentname = Stringfromlist(i,Datalist) // extract the name of the current wave from the list Wave current = $currentname // create a wave reference to work with Sort windwave, current // sort endfor // +++ second step: get rid of points with no valid wind data (i.e., nans) +++ FindValue /V=(Wavemax(windwave)) windwave // find the last point with valid data pointnum = V_Value for (i = 0; i < itemsinlist(Datalist); i +=1) currentname = Stringfromlist(i,Datalist) Wave current = $currentname DeletePoints pointnum+1, inf, current // delete points after valid data endfor // +++ third step: store the data in separate folders depending on binning criteria +++ Variable currbin for (currbin = 0; currbin < numpnts(binlist); currbin +=1) FindLevel/Q windwave, binlist[currbin] // find the crossing point to the next bin in the data pointnum = ceil(V_LevelX) NewDataFolder/O $("binned_"+num2istr(binlist[currbin])) // create a data folder DFREF folder =root:$("binned_"+num2istr(binlist[currbin])) // refer the data folder to work with for (i = 0; i < itemsinlist(Datalist); i +=1) currentname = Stringfromlist(i,Datalist) Duplicate/O $currentname, folder:$(currentname) // duplicate into data folder Wave current = $(currentname) Wave copy = folder:$(currentname) DeletePoints 0, pointnum, current // delete points of current bin in main waves DeletePoints pointnum, inf, copy // delete points OUTSIDE current bin in copied wave endfor endfor NewDataFolder/O $("binned_rest") // the data above the last bin will be stored in 'rest' DFREF folder =root:$("binned_rest") for (i = 0; i < itemsinlist(Datalist); i +=1) currentname = Stringfromlist(i,Datalist) Duplicate/O $currentname, folder:$(currentname) Wave current = $(currentname) KillWaves/Z current // kill the main waves if possible (keeps stuff tidy) endfor End