function my_truncate,data,time,xvec,value ; This is a demonstration of a function returning a structure. ; This function takes a 3D signal and sets certain points to zero. ; At each timepoint all data points corresponding to x-values ; greater than 'value' are zeroed. ; Note that for most data this only requires a couple of lines of IDL code. ; most of the rest is error handling. ; This routine could be done without the structure equally as well. resultStruct={JetProcSignal $ ,data:ptr_new() $ ,time:ptr_new() $ ,x:ptr_new() $ ,type:'' $ ,tAxisType:0 $ ,xAxisType:0 $ ,multigraph:0 $ ,n_multi:1 $ ,slice:'' $ ,status:0 $ } szErr='' catch,err_status if err_status eq 0 then begin ; check that data is a 3d signal sData=size(data) if (sData[0] ne 2) then begin szErr='Cannot perform this operation.' message,szErr endif ; check there is the right number of time points. sTime=size(time) if sTime[1] ne sData[1] then begin szErr='Cannot perform this operation.' message,szErr endif ;check whether x is 1d or 2d and it has the right number of points. sXvec=size(xvec) case sXvec[0] of 1:begin if sXvec[1] ne sData[2] then begin szErr='Cannot perform this operation.' message,szErr endif end 2:begin if max(sXvec[1:2] ne sData[1:2]) then begin szErr='Cannot perform this operation.' message,szErr endif end else:begin szErr='Cannot perform this operation.' message,szErr end endcase ; now actually do the truncation. case sXvec[0] of 1: begin local_data=data points=where((xVec gt value), npoints) if nPoints gt 0 then begin local_data[*,points]=0.0 endif end 2: begin local_data=data ; loop over time points. for i=0,sData[1]-1 do begin points=where((xVec[i,*] gt value), npoints) if nPoints gt 0 then begin local_data[i,points]=0.0 endif endfor resultStruct.xAxisType=1 end endcase ; if got this far then store the results. resultStruct.data=ptr_new(local_data) resultStruct.time=ptr_new(time) resultStruct.x=ptr_new(xvec) resultStruct.type='3D' resultStruct.status=1 endif else begin if szErr eq '' then szErr=!err_string catch,/cancel message,szErr endelse return, resultStruct end