ncap2 sort and median

S. Morin
  • S. Morin

    S. Morin - 2013-02-25

    Dear all,

    From a series of model output and using ncecat I've generated a file containing some output data with dimensions time and record (record has been generated through ncecat). Now I'd like to compute the median of my output data for each time and across all records. I'm struggling with gsl_stats_median_from_sorted_data , probably because I'm struggling with the sort() function, which seems to operate over the entire file and not on a time-by-time basis (it works fine when I first use ncks to extract each time, but this is not satisfactory of course). Any hint on what the correct syntax should be ? Thanks ahead for the reply.


  • henry Butowsky

    henry Butowsky - 2013-02-26

    HI Sam,
    from what your saying sounds like you need to loop the time variable -
         then apply the sort & median function to each individual slab and then store the results in a predefined array of the correct size. Below is an example:

    /********************************* sam.nco **************************/
    for(idx=0 ; idx<sz;idx++){

    Then to run the above use the command

    ncap2 -v -O -S sam.nco

    … hmb

  • S. Morin

    S. Morin - 2013-03-05

    I was kind of doing this by extracting single time slabs using ncks, the loop within ncap2 is clearly a better option and you example shows nicely how to proceed.

    Many thanks hmb for this nice solution.


Log in to post a comment.