NIFTI files can be read in with the functions described here for the NIFTI I/O library (in C):
http://nifti.nimh.nih.gov/nifti-1
If you would like more information about how AFNI implements this, you can peruse our source code, also in C and open-source. Understanding some of our data structures is useful, and there is some documentation here:
http://afni.nimh.nih.gov/sscc/rwcox/blog.2005-03-30.5934342826/simpleblog_view