#ifdef documentation
=========================================================================
program: getfidkmex.c
by: justin gardner
purpose: reads fid data from VNMR system
date: 05/06/03
compile: mex getfidk.c
history: 2008/12/01, Pei, add endian detect and byte swap part.
Default format of fid is big endian, as we acquaire data
on VNMR Sun Solaris, also epirri5 keep the same endian.
Note: SWAP data firstly and then DO typecast.
This is an obsolete function that has been replaced by
getfidkraw.c and getfidk.m
=========================================================================
#endif
////////////////////
// include section
////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <unistd.h>
#include <ctype.h>
#include "mex.h"
#include "vnmrdata.h"
///////////////////
// define section
///////////////////
#define STRSIZE 2048
#define LINESIZE 4096
#define FALSE 0
#define TRUE 1
#define INT16 int16
#define INT32 int32
#define FLOAT float
////////////////////
// data structures
////////////////////
typedef struct {
int numslices; // number of slices
int numvolumes; // number of volumes
int numlines; // number of k-space lines in each image
int numreceivers; // number of receivers
int numshots; // number of shots
int linelen; // number of voxels in each line
int navechoes; // number of naviagtor echoes
int accFactor; // acceleration factor
int ndim; // number of dimensions
mwSize dims[5]; // size of those dimensions
int numimages; // number of images = slices*volumes*receivers
int imagesize; // number of voxels in each image
mxClassID datatype; // matlab type of data
int totalsize; // total size of array
} datainfo;
///////////////////
// function decls
///////////////////
void usageError();
void fileNotFound(char *);
int fileLength(char *,FILE *);
void errorExit(mxArray *[]);
// functions of bytes swap
void swap_bytes(void * p, size_t s);
////////////////////
// global variables
////////////////////
int verbose;
FILE *ffid = NULL,*fprocpar = NULL; // declared global so we can close files on error
/////////////////////////
// for output structure
/////////////////////////
const char *fieldNames[] = {"name","filepath","data"};
#define NUMFIELDS 3
const char *originalFormatFieldNames[] = {"name","filepath","real","imag"};
#define ORIGINAL_FORMAT_NUMFIELDS 4
const mwSize dims[2] = {1, 1};
//////////////////////////////////////////
// function mexFunction called by matlab
//////////////////////////////////////////
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
char filename[STRSIZE],inputname[STRSIZE],
pathname[STRSIZE],procparname[STRSIZE],
fullpath[STRSIZE],line[LINESIZE],*token;
struct datafilehead header;
struct datablockhead blockheader;
datainfo info;
INT16 *data_int16,*datai_int16,*raw_int16, tokenint16;
INT32 *data_int32,*datai_int32,*raw_int32, tokenint32;
FLOAT *data_float,*datai_float,*raw_float, tokenfloat;
double *data,*datai;
INT16 *block;
mxArray *mxdata,*mxdatar,*mxdatai;
int originalformat;
int i,j,k,n;
int isLittleEndianPlatform, swapFlag, gotNavechoes;
// check input arguments
if ((nrhs < 1) || (nrhs > 3)){
usageError();
return;
}
// check output arguments
else if (nlhs > 1) {
usageError();
return;
}
// set whether to verbosely report errors
if (nrhs >= 2) {
verbose = (int)*mxGetPr(prhs[1]);
}
else {
verbose = FALSE;
}
// set whether to return data in original format or not
if (nrhs >= 3) {
originalformat = (int)*mxGetPr(prhs[2]);
}
else {
originalformat = FALSE;
}
// get filename
mxGetString(prhs[0], inputname, mxGetN(prhs[0])+1);
// create the output structure
if (originalformat)
plhs[0] = mxCreateStructArray(2, dims, ORIGINAL_FORMAT_NUMFIELDS, originalFormatFieldNames);
else
plhs[0] = mxCreateStructArray(2, dims, NUMFIELDS, fieldNames);
// put filename in output structure
mxSetField(plhs[0],0,"name",mxCreateString(inputname));
// figure out where the fid file is
// did the user input the full directory?
sprintf(pathname,"%s",inputname);
sprintf(filename,"%s/fid",pathname);
if (verbose) mexPrintf("(getfidkmex) Trying filename %s\n",filename);
if ((ffid = fopen(filename,"r")) == NULL) {
// maybe the user gave the directory without .fid
sprintf(pathname,"%s.fid",inputname);
sprintf(filename,"%s/fid",pathname);
if (verbose) mexPrintf("(getfidkmex) Trying filename %s\n",filename);
if ((ffid = fopen(filename,"r")) == NULL) {
// nope, maybe it is simply the filename
sprintf(pathname,".");
sprintf(filename,"%s/%s",pathname,inputname);
if (verbose) mexPrintf("(getfidkmex) Trying filename %s\n",filename);
if ((ffid = fopen(filename,"r")) == NULL) {
// nothing found, give up.
fileNotFound(inputname);
errorExit(plhs);
return;
}
}
}
if (verbose) mexPrintf("(getfidkmex) Opened %s\n", filename);
// get the full path
getcwd(fullpath,STRSIZE);
strcat(fullpath,"/");
if (!strcmp(pathname,".")) {
if (!strcmp(inputname,"."))
strcat(fullpath,"fid");
else
strcat(fullpath,inputname);
}
else
strcat(fullpath,filename);
// save the full qualified path in the output structure
mxSetField(plhs[0],0,"filepath",mxCreateString(fullpath));
// open the procpar
sprintf(procparname,"%s/procpar",pathname);
if ((fprocpar = fopen(procparname,"r")) == NULL) {
// no procpar
fileNotFound(filename);
errorExit(plhs);
return;
}
info.navechoes = 0;
gotNavechoes = 0;
info.numshots = 1;
info.accFactor = 1;
info.numvolumes = 1;
info.numreceivers = 1;
// scan through procpar looking for parameters needed for parsing
while (fgets(line,LINESIZE,fprocpar)) {
// get the first token of the line
token = (char*)strtok(line," ");
// get number of slices
if (!strcmp(token,"pss")) {
info.numslices = atoi(fgets(line,LINESIZE,fprocpar));
if (verbose) mexPrintf("(getfidkmex) numslices = %i\n",info.numslices);
}
// get number of volumes
if (!strcmp(token,"cntr")) {
info.numvolumes = atoi(fgets(line,LINESIZE,fprocpar));
if (verbose) mexPrintf("(getfidkmex) numvolumes = %i\n",info.numvolumes);
}
// get number of voxels per line
if (!strcmp(token,"np")) {
fgets(line,LINESIZE,fprocpar);
token = (char*)strtok(line," ");
token = (char*)strtok(NULL," ");
// that should be number of slices
info.linelen = atoi(token)/2;
if (verbose) mexPrintf("(getfidkmex) linelen = %i\n",info.linelen);
}
// get the number of receivers
if (!strcmp(token,"rcvrs")) {
fgets(line,LINESIZE,fprocpar);
token = (char*)strtok(line," ");
token = (char*)strtok(NULL," ");
info.numreceivers = 0;
// Count the number of 'y's that is the number of receivers
for (i = 0;i < strlen(token);i++)
if (token[i] == 'y') info.numreceivers++;
// make sure we have atleast 1 receiver
if (info.numreceivers <= 0) info.numreceivers = 1;
if (verbose) mexPrintf("(getfidkmex) Number of receivers = %i\n",info.numreceivers);
}
// get number of lines per image
if (!strcmp(token,"ni")) {
fgets(line,LINESIZE,fprocpar);
token = (char*)strtok(line," ");
token = (char*)strtok(NULL," ");
info.numlines = atoi(token);
if (verbose) mexPrintf("(getfidkmex) numlines = %i\n",info.numlines);
}
// get number of navechoes
if (!strcmp(token,"nv")) {
fgets(line,LINESIZE,fprocpar);
token = (char*)strto
没有合适的资源?快使用搜索试试~ 我知道了~
mrTools - matlab based tools for fMRI.zip
共713个文件
m:618个
c:10个
fig:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 160 浏览量
2023-07-23
10:14:41
上传
评论
收藏 2MB ZIP 举报
温馨提示
mrTools - matlab based tools for fMRI.zip
资源推荐
资源详情
资源评论
收起资源包目录
mrTools - matlab based tools for fMRI.zip (713个子文件)
getfidkmex.c 26KB
edges.c 22KB
getfidkraw.c 15KB
convolve.c 10KB
wrap.c 8KB
upConv.c 6KB
corrDn.c 4KB
myCinterp3.c 4KB
regHistogram.c 3KB
assignToNearest.c 3KB
dijkstra.cpp 28KB
fibheap.cpp 20KB
dijkstrap.cpp 6KB
Wang2015.mgz.ctab 287B
myCinterp3.cxx 4KB
.DS_Store 6KB
mrLoadRetGUI.fig 47KB
averageTSeriesGUI.fig 33KB
editSessionGUI.fig 25KB
editGroupGUI.fig 24KB
mrAlignGUI.fig 21KB
corAnalGUI.fig 6KB
checkAlignmentGUI.fig 5KB
motionCompGUI.fig 5KB
editBaseGUI.fig 2KB
nifti1.h 56KB
vnmrdata.h 19KB
conio.h 5KB
fibheap.h 3KB
fibheap.h 3KB
convolve.h 2KB
viewGet.m 184KB
viewSet.m 100KB
mrLoadRetGUI.m 97KB
mlrVol.m 80KB
mrAlignGUI.m 65KB
mlrAnatomyPlugin.m 58KB
getGlmStatistics.m 55KB
renderIn3D.m 53KB
glmAnalysis.m 52KB
refreshMLRDisplay.m 51KB
mrFlatViewer.m 50KB
mrParamsDialog.m 47KB
pRFFit.m 39KB
mrSurfViewer.m 36KB
GLM_v2Plugin.m 35KB
grep.m 32KB
glmPlot.m 32KB
combineTransformOverlays.m 31KB
mlrGuiSet.m 29KB
mlrAnatDBPut.m 27KB
mlrAnatDBPlugin.m 24KB
roisConfidenceInterval.m 24KB
getGlmEVParamsGUI.m 23KB
mlrSpikeDetector.m 22KB
concatTSeries.m 22KB
talairach.m 22KB
eventRelatedROIClassification.m 22KB
mrInterrogator.m 22KB
mrPrint.m 21KB
mlrAdjustGUI.m 20KB
getStimvol.m 20KB
plotConfidenceIntervals.m 20KB
pRFGetStimImageFromStimfile.m 20KB
flattenSurfaceMFM.m 19KB
remapSurfaces.m 19KB
exportTal2mrLR.m 18KB
editOverlayGUImrParams.m 17KB
mlrComputeAtlasMean.m 17KB
modelCoranalFromGlm.m 17KB
drawSurfaceROI.m 17KB
searchlightClassification.m 17KB
viewGUIPlugin.m 17KB
fid2xform.m 17KB
mlrImportCaret.m 17KB
pRFGUI.m 17KB
roiClassification.m 16KB
pRF.m 16KB
getClassVarname.m 16KB
searchForVoxel.m 16KB
mlrDisplayEPI.m 15KB
mr4to3.m 15KB
mrInit.m 14KB
projectOutMeanVector.m 14KB
eventRelatedPlot.m 14KB
glmAnalysisGUI.m 14KB
makeFlat.m 14KB
getGlmAdvancedStatisticParamsGUI.m 13KB
mrParamsParse.m 13KB
getGlmScanParamsGUI.m 13KB
fslApplyWarpROI.m 13KB
computeOverlay.m 12KB
drawROI.m 12KB
mlrImageHeaderLoad.m 12KB
getClassEVParamsGUI.m 12KB
maskOverlay.m 12KB
motionCompGUI.m 12KB
motionComp.m 12KB
pRFPlot.m 12KB
cbiReadNifti.m 11KB
共 713 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
AbelZ_01
- 粉丝: 894
- 资源: 5441
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功