Mercurial > hg > minc-tools
changeset 589:96973371e945
Initial revision
author | neelin <neelin> |
---|---|
date | Fri, 09 Sep 1994 15:49:46 +0000 |
parents | ead0ea30b418 |
children | 97293bd0f924 |
files | progs/Get_image_offset/Makefile progs/Get_image_offset/get_image_offset.c |
diffstat | 2 files changed, 148 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/progs/Get_image_offset/Makefile @@ -0,0 +1,80 @@ +# -------------------------------------------------------------------- +# +# MINC Makefile +# + +ROOT = ../.. +include $(ROOT)/Makefile_machine_specific +include $(ROOT)/Makefile_configuration + +NETCDF_SOURCE_DIR = $(ROOT)/../netcdf/libsrc + +# Executable names +PROGS = get_image_offset +EXTRA_OBJS = +HEADERS = #$(PROGS:=.h) +MANSECT = 1 +CDEFINES = -DDEBUG# cpp defines +LDOPT = $(PROG_LDOPT) + +# -------------------------------------------------------------------- + +CFLAGS = $(CDEFINES) $(INCLUDES) $(OPT)# CFLAGS and LINTFLAGS should +LINTFLAGS = $(CDEFINES) $(INCLUDES)# be same, except for -g/-O + +PROG_OBJ = $(PROGS:=.o)# list of objects +LINT_LIST = $(PROG_OBJ:.o=.ln) +LINT_EXTRA= $(EXTRA_OBJS:.o=.ln) +LINT_LIST_EXE = $(LINT_LIST:.ln=.)# list of executable names to lint +MANPAGES = #$(PROGS).$(MANSECT) + +# -------------------------------------------------------------------- + +#Suffixes for man pages +.SUFFIXES: .1 .man1 .3 .man3 + +default: build + +all: build lint + +build: $(PROGS) man + +man: $(MANPAGES) + +#Dependency on Makefile +$(PROG_OBJ) $(LINT_LIST) $(EXTRA_OBJS) $(LINT_EXTRA) : Makefile + +.c.ln:# defines the rule for creating .ln + lint $(LINTFLAGS) -I$(NETCDF_SOURCE_DIR) -c $< -o $@ + +.c.o:# defines the rule for creating .o + $(CC) $(CFLAGS) -I$(NETCDF_SOURCE_DIR) -c $< -o $@ + +#Dependency of .o and .ln on .h +$(PROG_OBJ) $(EXTRA_OBJS) : $(HEADERS) + +$(LINT_LIST) $(LINT_EXTRA) : $(HEADERS) + +# How to make executables +$(PROGS) : $$@.o $(EXTRA_OBJS) $(CC_PROG_LIB) $(CC_MINC_LIB) + $(CC) -o $@ $@.o $(EXTRA_OBJS) $(LDOPT) + +# how to lint the executable source +lint: $(LINT_LIST_EXE) + +$(LINT_LIST_EXE) : $$@ln $(LINT_EXTRA) $(LINT_PROG_LIB) $(LINT_MINC_LIB) + lint -u $(LINTFLAGS) $@ln $(LINT_EXTRA) $(LINT_PROG_LIB) $(LINT_MINC_LIB) + +# how to make man pages +.man1.1: + $(NROFF) $(NROFF_FLAGS) $< > $@ + +# Remove all derived files in this directory +clean: + $(RM) $(RM_FLAGS) $(LINT_LIST) $(PROGS) $(PROG_OBJ) \ + $(EXTRA_OBJS) $(LINT_EXTRA) $(MANPAGES) + +install: + $(CP) $(CP_FLAGS) $(PROGS) $(INSTALL_BINDIR) + $(CP) $(CP_FLAGS) $(MANPAGES) $(INSTALL_MANDIR)$(MANSECT) +
new file mode 100644 --- /dev/null +++ b/progs/Get_image_offset/get_image_offset.c @@ -0,0 +1,68 @@ +#include <minc.h> +#include <local_nc.h> + +#define public + +public long get_image_offset(int cdfid); + +int main(int argc, char *argv[]) +{ + int cdfid; + long offset; + + /* Check arguments */ + if (argc != 2) { + (void) fprintf(stderr, "Usage: %s <filename.mnc>\n", argv[0]); + return -1; + } + + /* Open minc file */ + cdfid = ncopen(argv[1], NC_NOWRITE); + + /* Get the offset */ + offset = get_image_offset(cdfid); + if (offset == -1) { + (void) fprintf(stderr, "Error getting offset to image in file %s\n", + argv[1]); + return -1; + } + + (void) printf("%ld\n", offset); + + return 0; +} + +/* ----------------------------- MNI Header ----------------------------------- +@NAME : get_image_offset +@INPUT : path - name of minc file +@OUTPUT : (none) +@RETURNS : offset to image data in minc file or MI_ERROR (-1) if an + error occurs. +@DESCRIPTION: Function to return the offset to the image data in a minc file. + WARNING: This function may be hazardous to your health since + it directly accesses NetCDF internals!!!!! Use at your own + risk. +@METHOD : +@GLOBALS : +@CALLS : +@CREATED : September 9, 1994 (Peter Neelin) +@MODIFIED : +---------------------------------------------------------------------------- */ +public long get_image_offset(int cdfid) +{ + int imgid; + NC *handle; + NC_var *vp; + + imgid = ncvarid(cdfid, MIimage); + if (imgid == MI_ERROR) return MI_ERROR; + + handle = NC_check_id(cdfid); + if (handle == NULL) return MI_ERROR; + + vp = NC_hlookupvar(handle, imgid); + if (vp == NULL) return MI_ERROR; + + return (long) vp->begin; +} +