Good Morning,

the former message was too big for this list due to the large grid file -- what 
to do with this example? The rest should be OK and explain the grid format a 
bit:

> > Back in university I could attach a simple program of mine that computes 
> > the averaged spectrum.
> >   
>   
Please see the attachment grid-spectravg.cpp, the interesting parts are
commented specially.

Yours,

-- 
Robb Bean <Robb underline Bean at gmx dot net>

Projects:
http://applaunch.sourceforge.net/
http://laymansys.sourceforge.net/ 

#include <cstdio>
#include <stdint.h>
#include <cstdlib>
#include <cstddef>
#include <climits>

uint16_t swapShort(const uint16_t s);

int main(int argc, char *argv[]) {
        if (argc < 3) {
                std::fprintf(stderr,
                        "Usage: %s FILE NUM_SPECTRA NUM_DATAPOINTS\n",
                        *argv);
                return 1;
        }

        FILE *f;
        uint32_t nSpectra,      // number of spectra
                nDataPoints;    // number of data points per spectrum

        if (! (f = std::fopen(argv[1], "rb"))) {
                std::perror(argv[1]);
                return 1;
        }

        // some command line handling, should be read from the parameter
        // file
        nSpectra = std::strtoul(argv[2], NULL, 0);
        nDataPoints = std::strtoul(argv[3], NULL, 0);

        if (nSpectra == 0 || nSpectra == ULONG_MAX ||
                nDataPoints == 0 || nDataPoints == ULONG_MAX)
        {
                perror("NUM_SPECTRA or NUM_DATAPOINTS");
                std::fclose(f);
                return 1;
        }

        // The interesting part starts here:
        uint16_t *frame = new uint16_t[nSpectra];
        double specPoint;       // one point of the spectrum

        // Read the first frame containing the first spectroscopy point
        // of all spectra:
        std::fread(frame, sizeof(uint16_t), nSpectra, f);

        for (uint32_t i = 0;
                i < nDataPoints && !(std::feof(f) || std::ferror(f));
                ++i)
        {
                specPoint = 0.;
                for (uint32_t j = 0; j < nSpectra; ++j) {
                        specPoint += swapShort(frame[j]);
                                // The byte swapping is only necessary
                                // on little endian machines. I don't know
                                // if windows has ntohs, so I reimplemented
                                // its functionality.
                }
                printf("%u      %.8f\n", i, specPoint / nSpectra /* averaging 
*/);
                // TODO: Using the values from the parameter file, we here
                // could compute the physical values:
                //
                // Parameter = Start point spectroscopy + i * Increment point 
spectroscopy
                // Channel   = specPoint / nSpectra * Resolution

                // Read the next frame:
                std::fread(frame, sizeof(uint16_t), nSpectra, f);
        }

        delete[] frame;
        std::fclose(f);

        return 0;
}

uint16_t swapShort(const uint16_t s) {
        static const uint16_t hi = 0xff00;
        static const uint16_t lo = 0x00ff;

        return ((s & hi) >> 8) | ((s & lo) << 8);
}
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Gwyddion-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gwyddion-users

Reply via email to