Thread: Reading in from .raw file

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Reading in from .raw file

    I got an assignment where i have to read in unsigned short values from a .raw file. Im abit unsure on how i do this in C and what i get when i do it like i have tried to do

    http://pastebin.com/NNQDitWe
    Code:
    void main()
    {
            //data is also an usnigned *short declared somewhere else in the program
            data = ReadFile();
    }
     
    unsigned short* ReadFile()
    {
     
    FILE *file = fopen("Kaisa.raw", "r");
    if(!file)
    {
            return NULL;
           
            unsigned short* value = (unsigned short*)malloc(512*512*210*sizeof(unsigned short*));
            fread(value, 512*512*210, 1, file);
            fclose(file);
           
            return value;
     
    }
    First of all, does this work?

    If so what and how is the values stored in data. Is the numbers all in one line(that is 512*512*210 elements long)?
    Last edited by sidesprang; 04-23-2010 at 06:38 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Since your listing does not include any header files, the answer has to be "NO", it doesn't work.

    In general, if you have a hammer in your hand, you don't need to ask all your neighbors if it will work or not. Just try hammering in a nail or two, and you'll know.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's not One True ".raw" Format. That is to say, just saying your data is in a file labeled .raw doesn't tell us what's in the file.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    Quote Originally Posted by tabstop View Post
    There's not One True ".raw" Format. That is to say, just saying your data is in a file labeled .raw doesn't tell us what's in the file.
    K, i've never used .raw files before did not really know how they worked. When i tried to open one in notepad++ i got just garbage. But i noticed there was another file that also was in my assignment. Kaisa.mhd. I guess that one has the information of what is in the file.
    Code:
    NDims = 3 
    BinaryData = True 
    BinaryDataByteOrderMSB = False 
    Offset = -103.604 -114.96 0.0
    ElementSpacing = 0.449 0.449 1.000 
    DimSize = 512 512 210
    ElementType = MET_USHORT 
    ElementDataFile = Kaisa.raw

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What's probably wrong with your fread is that you are trying to read 512*512*210 pointers to ushort, when you would want 512*512*210 ushorts instead.

    Searching on ".mhd file extension" gives interesting reading about MetaImage, but I don't know if it will help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM