MWATelescope/mwalib

Re-open GPUBox number issue for legacy VCS

robotopia opened this issue · 1 comments

The previous fix doesn't seem to have carried across to the C interface. After installing the latest version of mwalib and putting the library and header files in standard places, this program can be compiled and run for testing:
bug_report_gpubox.c:

#include <stdlib.h>
#include <stdio.h>
#include <mwalib.h>

#define ERROR_MESSAGE_LEN  1024

int main( int argc, char *argv[] )
{
    // Get the metafits file from command line argument
    if (argc < 3)
    {
        printf( "usage: %s  METAFITS_FILE  VOLTAGE_FILE\n", argv[0] );
        printf( "example: %s  1164110416_metafits.fits  1164110416_1164110725_ch109.dat\n" );
        exit(EXIT_FAILURE);
    }
    char *metafits_filename = argv[1];
    char *datfile           = argv[2];

    // Print out MWALIB version
    printf( "\nMWALIB v%u.%u.%u\n\n",
            mwalib_get_version_major(),
            mwalib_get_version_minor(),
            mwalib_get_version_patch()
           );

    // Load up metafits for a VCS observation
    char error_message[ERROR_MESSAGE_LEN];
    //error_message[0] = '\0'; // <-- Just to avoid a compiler warning about uninitialised variables

    MetafitsMetadata *metadata;
    MetafitsContext  *context;

    if (mwalib_metafits_context_new2( metafits_filename, &context, error_message, ERROR_MESSAGE_LEN) != MWALIB_SUCCESS)
    {
        fprintf( stderr, "error (mwalib): cannot create metafits context: %s\n", error_message );
        exit(EXIT_FAILURE);
    }

    if (mwalib_metafits_metadata_get( context, NULL, NULL, &metadata, error_message, ERROR_MESSAGE_LEN ) != MWALIB_SUCCESS)
    {
        fprintf( stderr, "error (mwalib): cannot create metafits metadata: %s\n", error_message );
        exit(EXIT_FAILURE);
    }

    VoltageMetadata *volt_metadata;
    VoltageContext  *volt_context;

    const char **voltage_filenames  = &datfile;
    size_t       voltage_file_count = 1;

    if (mwalib_voltage_context_new( metafits_filename, voltage_filenames, voltage_file_count, &volt_context, error_message, ERROR_MESSAGE_LEN ) != MWALIB_SUCCESS)
    {
        fprintf( stderr, "error (mwalib): cannot create voltage context: %s\n", error_message );
        exit(EXIT_FAILURE);
    }

    if (mwalib_voltage_metadata_get( volt_context, &volt_metadata, error_message, ERROR_MESSAGE_LEN ) != EXIT_SUCCESS)
    {
        fprintf( stderr, "error (mwalib): cannot get metadata: %s\n", error_message );
        exit(EXIT_FAILURE);
    }

    // Read off the coarse channels and their gpubox numbers
    uintptr_t nmc = metadata->num_metafits_coarse_chans;
    uintptr_t nvc = volt_metadata->num_coarse_chans;
    uintptr_t c;

    printf( "             METAFITS            \n"
            "Corr chan | Rec chan | GPUBox num\n"
            "----------+----------+-----------\n" );

    for (c = 0; c < nmc; c++)
    {
        printf( "%5lu %5lu %5lu\n",
                metadata->metafits_coarse_chans[c].corr_chan_number,
                metadata->metafits_coarse_chans[c].rec_chan_number,
                metadata->metafits_coarse_chans[c].gpubox_number
              );
    }
    printf( "\n" );

    printf( "             VOLTAGE             \n"
            "Corr chan | Rec chan | GPUBox num\n"
            "----------+----------+-----------\n" );
    for (c = 0; c < nmc; c++)
    {
        printf( "%5lu %5lu %5lu\n",
                volt_metadata->coarse_chans[c].corr_chan_number,
                volt_metadata->coarse_chans[c].rec_chan_number,
                volt_metadata->coarse_chans[c].gpubox_number
              );
    }

    // Clean up
    mwalib_metafits_metadata_free( metadata );
    mwalib_metafits_context_free( context );
    mwalib_voltage_metadata_free( volt_metadata );
    mwalib_voltage_context_free( volt_context );

    return EXIT_SUCCESS;
}

Makefile for compiling and testing:

CC = gcc
LDLIBS = -lmwalib

run_legacy_test: bug_report_gpubox 1164110416_metafits.fits 1164110416_1164110725_ch109.dat
    ./$^

run_mwax_test: bug_report_gpubox 1313388760_metafits.fits 1313388760_1313388760_144.sub
    ./$^

1164110416_metafits.fits:
    wget -O $@ http://ws.mwatelescope.org/metadata/fits?obs_id=1164110416

1313388760_metafits.fits:
    wget -O $@ http://ws.mwatelescope.org/metadata/fits?obs_id=1313388760

1164110416_1164110725_ch109.dat:
    dd if=/dev/zero of=$@ bs=32768 count=10000

1313388760_1313388760_144.sub:
    dd if=/dev/zero of=$@ bs=4096 count=1288001

...which translates to:

$ make -Bn run_legacy_test
gcc     bug_report_gpubox.c  -lmwalib -o bug_report_gpubox
wget -O 1164110416_metafits.fits http://ws.mwatelescope.org/metadata/fits?obs_id=1164110416
dd if=/dev/zero of=1164110416_1164110725_ch109.dat bs=32768 count=10000
./bug_report_gpubox 1164110416_metafits.fits 1164110416_1164110725_ch109.dat

and

$ make -Bn run_mwax_test 
gcc     bug_report_gpubox.c  -lmwalib -o bug_report_gpubox
wget -O 1313388760_metafits.fits http://ws.mwatelescope.org/metadata/fits?obs_id=1313388760
dd if=/dev/zero of=1313388760_1313388760_144.sub bs=4096 count=1288001
./bug_report_gpubox 1313388760_metafits.fits 1313388760_1313388760_144.sub

I get the output (e.g. for the legacy test):

$ ./bug_report_gpubox 1164110416_metafits.fits 1164110416_1164110725_ch109.dat

MWALIB v0.11.0

             METAFITS            
Corr chan | Rec chan | GPUBox num
----------+----------+-----------
    0   109   109
    1   110   110
    2   111   111
    3   112   112
    4   113   113
    5   114   114
    6   115   115
    7   116   116
    8   117   117
    9   118   118
   10   119   119
   11   120   120
   12   121   121
   13   122   122
   14   123   123
   15   124   124
   16   125   125
   17   126   126
   18   127   127
   19   128   128
   23   129   129
   22   130   130
   21   131   131
   20   132   132

             VOLTAGE             
Corr chan | Rec chan | GPUBox num
----------+----------+-----------
    0   109   109
    1   110   110
    2   111   111
    3   112   112
    4   113   113
    5   114   114
    6   115   115
    7   116   116
    8   117   117
    9   118   118
   10   119   119
   11   120   120
   12   121   121
   13   122   122
   14   123   123
   15   124   124
   16   125   125
   17   126   126
   18   127   127
   19   128   128
   23   129   129
   22   130   130
   21   131   131
   20   132   132

...and similarly incorrect numbers for the MWAX test. I believe the GPUBox numbers should always be in the range 01-24.

Originally posted by @robotopia in #41 (comment)

We've agreed to leave this as it was prior to that commit. The gpubox_number attribute is probably a misnomer as it really is representing the "channel" part of the original gpubox or VCS filename. Maybe in a future breaking release it should be renamed to channel_filename_identifier or something? For now @robotopia is going to use the corr_chan_number + 1 to get the equivalent of a gpubox number for VCS's using a metafits context.