~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/file/fileAni_write_header.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/file/fileAni_write_header.c,v $
 37  * Date    :  $Date: 2009/03/19 18:36:26 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: fileAni_write_header.c,v 1.4 2009/03/19 18:36:26 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes   :
 44  * 
 45  * Copyright 1995 Roger P. Woods, M.D.
 46  * Modified: 12/16/95 
 47  *
 48  * int write_header()                                   
 49  *                                                      
 50  * Routine will write out ANALYZE compatible header based on the struct
 51  * defined in HEADER.h
 52  *                                                      
 53  * In addition, a comment that will be displayed at load time
 54  *  can be specified                                    
 55  *                                                      
 56  * Returns:                                             
 57  *      1 if successful                                 
 58  *      0 if unsuccessful
 59  *
 60  *********
 61 */
 62 
 63 #include "fileAni_write_header.h"
 64 
 65 #if HAVE_CONFIG_H
 66   #include <config.h>
 67 #endif
 68 
 69 #include <stdio.h>
 70 #include <string.h>
 71 #include <tina/sys/sysPro.h>
 72 #include <tina/file/file_AniDef.h>
 73 #include <tina/file/fileAni_read_header.h>
 74 #include <tina/file/fileAni_clip_suffix.h>
 75 
 76 
 77 int write_ani_header(outfile,stats,comment,flag)
 78 char            outfile[128];
 79 struct key_info *stats;
 80 char            comment[80];
 81 int             *flag;
 82 
 83 {
 84         struct hdr hdr;
 85         char filename[128];
 86         FILE *fp;
 87 
 88         strcpy(filename,outfile);
 89         clip_suffix(filename);
 90         strcat(filename,HDR_SUFF);
 91         if((fp=fopen(filename,"wb"))==NULL){
 92                 printf("cannot open file %s for output\n",filename);
 93                 return 0;
 94         }
 95         {
 96                 /*Initialize hdr to zeros to allow compatibility with newest*/
 97                 /*versions of ANALYZE*/
 98                 /*With thanks to Joel T. Lee, Psychiatry PET, VA, Minneapolis*/
 99                 char *ptr,*endptr;
100                 for(ptr=(char *)&hdr,endptr=ptr+sizeof(hdr);ptr<endptr;ptr++)*ptr=0;
101         }
102         /*Copy required data into header struct*/
103         hdr.bits=stats->bits;
104         hdr.dims=4;
105         hdr.x_dim=stats->x_dim;
106         hdr.y_dim=stats->y_dim;
107         hdr.z_dim=stats->z_dim;
108         hdr.t_dim=1;
109         if (stats->bits==8){
110                 hdr.datatype=2;         /*unsigned characters*/
111         }
112         else if (stats->bits==1){
113                 hdr.datatype=1;         /*binary*/
114         }
115         else if (stats->bits==16){
116                 hdr.datatype=4;         /*short int*/
117         }
118         else if (stats->bits==32){
119                 hdr.datatype=8;         /*int (ignoring other option of floating point)*/
120         }
121         else{
122                 hdr.datatype=0;         /*unknown data type*/
123         }
124         hdr.x_size=stats->x_size;
125         hdr.y_size=stats->y_size;
126         hdr.z_size=stats->z_size;
127         hdr.glmax=flag[1];                      /*global max*/
128         hdr.glmin=flag[0];                      /*global min*/
129         hdr.sizeof_hdr=sizeof(struct hdr);      /*standard=348*/
130         hdr.extents=16384;
131         hdr.regular='r';
132 
133         strncpy(hdr.descrip,comment,79);
134 
135         /*Write out header*/
136 /* maintain BIG_ENDIAN format when writing
137    a.lacey@man.ac.uk
138 */
139 #ifndef BIG_ENDIAN_ARCHITECTURE 
140         set_swapping_ts(1);
141         header_endian(&hdr);
142 #endif
143         if(fwrite((char *)&hdr,sizeof(struct hdr),1,fp)!=1){
144                 printf("file write error writing header %s\n",filename);
145                 fclose(fp);
146                 return 0;
147         }
148         fclose(fp);
149         return 1;
150 }
151 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.