TPCCLIB
Loading...
Searching...
No Matches
niftiname.c File Reference

Procedures for NIfTI file names. More...

#include "tpcclibConfig.h"
#include "tpcnifti.h"

Go to the source code of this file.

Functions

void niftiBasename (char *filename)
 

Detailed Description

Procedures for NIfTI file names.

Definition in file niftiname.c.

Function Documentation

◆ niftiBasename()

void niftiBasename ( char * filename)

Remove any extensions from NIfTI file name, leaving only base file name. Possible path is kept.

Parameters
filenameFull name of file.

Definition at line 14 of file niftiname.c.

17 {
18 if(filename==NULL) return;
19 char basename[FILENAME_MAX];
20 strncpyCleanSpaces(basename, filename, FILENAME_MAX);
21 strcpy(filename, "");
22 char *cptr=filenameGetExtension(basename);
23 if(cptr!=NULL) {
24 if(strcasecmp(cptr, ".hdr")==0) *cptr=(char)0;
25 else if(strcasecmp(cptr, ".nii")==0) *cptr=(char)0;
26 else if(strcasecmp(cptr, ".img")==0) *cptr=(char)0;
27 else if(strcasecmp(cptr, ".sif")==0) *cptr=(char)0;
28 else if(strcasecmp(cptr, ".")==0) *cptr=(char)0;
29 }
30 /* Remove also double extensions, e.g. from data.img.hdr */
31 cptr=filenameGetExtension(basename);
32 if(cptr!=NULL) {
33 if(strcasecmp(cptr, ".nii")==0) *cptr=(char)0;
34 else if(strcasecmp(cptr, ".img")==0) *cptr=(char)0;
35 else if(strcasecmp(cptr, ".")==0) *cptr=(char)0;
36 }
37 strcpy(filename, basename);
38 return;
39}
char * filenameGetExtension(const char *s)
Get the last extension of a file name.
Definition filename.c:178
int strncpyCleanSpaces(char *s1, const char *s2, int maxlen)
Definition stringext.c:265

Referenced by anaExists(), imgWriteNifti(), niftiCreateFNames(), and niftiExists().