Re: Error on reading xml header from ismrmrd file

64 views
Skip to first unread message

Michael Hansen

unread,
May 18, 2016, 8:48:08 AM5/18/16
to kor, ISMRMRD, Hui Xue
Could you check that pointer 'xmlstring' is it not zero. I suspect it is.

If you are running that code unmodified, it should work. I have just run that example on my MAC. So I don't know exactly what is going on. We have never tried that compiler version and there could be some issues, but I will have somebody running Windows try to run it and see what happens. Hui, could you check if this application runs in Windows. 

Another side comment. This C API is going away. We recommend using the C++ API.

Do the ismrmrd_generate_cartesian_shepp_logan and ismrmrd_recon_cartesian_2d applications work? How about the unit tests?

Michael

On Wed, May 18, 2016 at 4:39 AM, kor <kor...@gmail.com> wrote:
I have created  an  ISMRMRD C++ Library for VS2015 community editionby using the following tools, 
VS2015 community edition
CMake 3.5.2
fftw-3.3.4
boost_1_61_0
HDF5 1.8.12

During the library creation,  no error occurred.

While trying to execute the below example code using the generated Library in  VS2015 community edition,
 getting an error with message(screenshot attached)
Exception thrown at 0x0000000077660EF7 (ntdll.dll) in test_ismrmrd_VS2015.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
the error is occurring while executing the statement,
 xmlstring = ISMRMRD::ismrmrd_read_header(&dataset2);
Upto this,  code executing and creating Myfile.h5 file in ismrmrd format.
While trying to read the header of the created file, the error occurring..
I also tried to read an another ISMRMRD file, using an another program to access ISMRMRD file, but the error occurring at the same code.
Also tried to test in VS2010, the same thing happened
Is it problem due to issue in generation of the C++ Library from source?, need any additions dependent software (l code synthesis studio for xml parsing) to be installed for creation. or mismatch in version of tools used
I think the error occurring in reading the xml header data

Please help to sort out the issue....

Example code used


If there is a handler for this exception, the program may be safely continued.
/* Declarations */
    int nacq_write, n, k, c;
    ISMRMRD::ISMRMRD_Dataset dataset1;
    ISMRMRD::ISMRMRD_Acquisition acq, acq2, acq3;
    ISMRMRD::ISMRMRD_Dataset dataset2;
    char *xmlstring;
    ISMRMRD::ISMRMRD_Image im, im2;
    uint32_t index;
    uint64_t loc;
    uint32_t nacq_read;
    uint32_t numim;
    const char *filename = "myfile.h5";
    const char *groupname = "/dataset";
    const char *xmlhdr = "Yo! This is some text for the header.";
    const char *attr_string = "Yo! This is some text for the attribute string.";
    ISMRMRD::ISMRMRD_NDArray arr, arr2;

    /* Set the error handler */
    ISMRMRD::ismrmrd_set_error_handler(myerror);

    /************/
    /* New File */
    /************/
    /* Create a data set */
    ISMRMRD::ismrmrd_init_dataset(&dataset1, filename, groupname);
    ISMRMRD::ismrmrd_open_dataset(&dataset1, true);

    /* Write an XML header */
    ISMRMRD::ismrmrd_write_header(&dataset1, xmlhdr);

    /* Append some acquisitions */
    nacq_write = 5;
    for (n=0; n < nacq_write; n++) {
        /* must initialize an acquisition before you can use it */
        ISMRMRD::ismrmrd_init_acquisition(&acq);
        acq.head.number_of_samples = 128;
        acq.head.active_channels = 4;
        for (k=0; k<acq.head.active_channels; k++) {
            ISMRMRD::ismrmrd_set_channel_on(acq.head.channel_mask, k);
        }
        ismrmrd_make_consistent_acquisition(&acq);
        for (k=0; k<acq.head.number_of_samples; k++) {
            for (c=0; c<acq.head.active_channels; c++) {
#ifdef _MSC_VER
                /* Windows C compilers don't have a good complex type */
                acq.data[k*acq.head.active_channels + c].real(n);
                acq.data[k*acq.head.active_channels + c].imag(n);
#else
                acq.data[k*acq.head.active_channels + c] = n + I*n;
#endif
            }
        }
        if (n == 0) {
            ISMRMRD::ismrmrd_set_flag(&(acq.head.flags), ISMRMRD::ISMRMRD_ACQ_FIRST_IN_SLICE);
        }
        else if (n == nacq_write-1) {
            ISMRMRD::ismrmrd_set_flag(&(acq.head.flags), ISMRMRD::ISMRMRD_ACQ_LAST_IN_SLICE);
        }
        ismrmrd_append_acquisition(&dataset1, &acq);
        ismrmrd_cleanup_acquisition(&acq);
    }
    
    /* Close the dataset */
    ISMRMRD::ismrmrd_close_dataset(&dataset1);

    /************/
    /* Old File */
    /************/
    /* Reopen the file as a different dataset */
    ISMRMRD::ismrmrd_init_dataset(&dataset2, filename, groupname);
    ISMRMRD::ismrmrd_open_dataset(&dataset2, false);

    /* Read the header */
    xmlstring = ISMRMRD::ismrmrd_read_header(&dataset2);
    printf("Header: %s\n", xmlstring);
    free(xmlstring);

    /* Get the number of acquisitions */
    nacq_read = ISMRMRD::ismrmrd_get_number_of_acquisitions(&dataset2);
    printf("Number of Acquisitions: %u\n", nacq_read);

    /* read the next to last one */
    ISMRMRD::ismrmrd_init_acquisition(&acq2);
    index = 0;
    if (nacq_read>1) {
        index = nacq_read - 1;
    }
    else {
        index = 0;
    }
    printf("Acquisition index: %u\n", index);
    ISMRMRD::ismrmrd_read_acquisition(&dataset2, index, &acq2);
    printf("Number of samples: %u\n", acq2.head.number_of_samples);
    printf("Flags: %llu\n", (unsigned long long)acq2.head.flags);
    printf("Channel Mask[0]: %llu\n", (unsigned long long)acq2.head.channel_mask[0]);
    printf("Channel Mask[1]: %llu\n", (unsigned long long)acq2.head.channel_mask[1]);
    printf("Channel 3 is %d\n", ISMRMRD::ismrmrd_is_channel_on(acq2.head.channel_mask, 3));
    printf("Channel 5 is %d\n", ISMRMRD::ismrmrd_is_channel_on(acq2.head.channel_mask, 5));
    
#ifdef _MSC_VER
    /* Windows C compilers don't have a good complex type */
    printf("Data 3: %f\t 2: %f\n", acq2.data[4].real(), acq2.data[4].imag());
#else
    printf("Data[4]: %f, %f\n", creal(acq2.data[4]), cimag(acq2.data[4]));
#endif
    
    ISMRMRD::ismrmrd_init_acquisition(&acq3);
    ISMRMRD::ismrmrd_copy_acquisition(&acq3, &acq2);
    
    printf("Pointers 3: %p\t 2: %p\n", (void *) acq3.data, (void *) acq2.data);
#ifdef _MSC_VER
    /* Windows C compilers don't have a good complex type */
    printf("Data 3: %f\t 2: %f\n", acq3.data[4].real(), acq2.data[4].real());
#else
    printf("Data 3: %f\t 2: %f\n", creal(acq3.data[4]), creal(acq2.data[4]));
#endif
    ISMRMRD::ismrmrd_cleanup_acquisition(&acq2);
    ISMRMRD::ismrmrd_cleanup_acquisition(&acq3);

    /* Create and store an image */
    ISMRMRD::ismrmrd_init_image(&im);
    im.head.data_type = ISMRMRD::ISMRMRD_FLOAT;
    im.head.matrix_size[0] = 256;
    im.head.matrix_size[1] = 256;
    im.head.matrix_size[2] = 4;
    im.head.channels = 8;
    /* Add an attribute string */
    im.head.attribute_string_len = strlen(attr_string);
    ISMRMRD::ismrmrd_make_consistent_image(&im);
    memcpy(im.attribute_string, attr_string, im.head.attribute_string_len);
    memset(im.data, 0, 256*256*4*8*sizeof(float));
    
    printf("Image Version: %d\n", im.head.version);
    printf("Image String: %s\n", im.attribute_string);
    ISMRMRD::ismrmrd_append_image(&dataset2, "testimages", &im);
    for (loc=0; loc < 256*256*4*8; loc++) {
        ((float*)im.data)[loc] = 2.0;
    }
    ISMRMRD::ismrmrd_append_image(&dataset2, "testimages", &im);
    ISMRMRD::ismrmrd_cleanup_image(&im);

    numim = ISMRMRD::ismrmrd_get_number_of_images(&dataset2, "testimages");
    printf("Number of images stored = %d\n", numim);
    
    ISMRMRD::ismrmrd_init_image(&im2);
    ISMRMRD::ismrmrd_read_image(&dataset2, "testimages", 1, &im2);
    printf("Image 1 attribute string = %s\n", im2.attribute_string);
    printf("Image 1 at position 10 has value = %f\n", ((float*)im2.data)[10]);
ISMRMRD::ismrmrd_cleanup_image(&im2);

    /* Create and store an array */
    ISMRMRD::ismrmrd_init_ndarray(&arr);
    arr.data_type = ISMRMRD::ISMRMRD_FLOAT;
    arr.ndim = 3;
    arr.dims[0] = 256;
    arr.dims[1] = 128;
    arr.dims[2] = 4;
    ISMRMRD::ismrmrd_make_consistent_ndarray(&arr);
    for (loc=0; loc < 256*128*4; loc++) {
        ((float*)arr.data)[loc] = 2.0;
    }
    ISMRMRD::ismrmrd_append_array(&dataset2, "testarray", &arr);
    printf("Number of arrays stored = %d\n", ISMRMRD::ismrmrd_get_number_of_arrays(&dataset2, "testarray"));
    ISMRMRD::ismrmrd_cleanup_ndarray(&arr);

    /* Read it back in */
    ISMRMRD::ismrmrd_init_ndarray(&arr2);
    ISMRMRD::ismrmrd_read_array(&dataset2, "testarray", 0, &arr2);
    printf("Array 2 at position 10 has value = %f\n", ((float*)arr2.data)[10]);
    ISMRMRD::ismrmrd_cleanup_ndarray(&arr2);
    
    /* Close the dataset */
    ISMRMRD::ismrmrd_close_dataset(&dataset2);
return 0;

--
You received this message because you are subscribed to the Google Groups "ISMRMRD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ismrmrd+u...@googlegroups.com.
To post to this group, send email to ism...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ismrmrd/97d62e2c-a4a4-467f-ba47-113b0ca0607c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages