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

Linux Cross Reference
Tina4/src/file/ani/write_header.c

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

  1 /* Copyright 1995 Roger P. Woods, M.D. */
  2 /* Modified: 12/16/95 */
  3 
  4 /*
  5  * int write_header()                                   
  6  *                                                      
  7  * Routine will write out ANALYZE compatible header based on the struct
  8  * defined in HEADER.h
  9  *                                                      
 10  * In addition, a comment that will be displayed at load time
 11  *  can be specified                                    
 12  *                                                      
 13  * Returns:                                             
 14  *      1 if successful                                 
 15  *      0 if unsuccessful
 16  *
 17 */
 18 
 19 #include "AIR.h"
 20 #include "HEADER.h"
 21 
 22 extern void  header_endian(struct hdr *hdr);
 23 
 24 
 25 int write_ani_header(outfile,stats,comment,flag)
 26 char            outfile[128];
 27 struct key_info *stats;
 28 char            comment[80];
 29 int             *flag;
 30 
 31 {
 32         struct hdr hdr;
 33         char filename[128];
 34         FILE *fp;
 35         void clip_suffix();
 36 
 37         strcpy(filename,outfile);
 38         clip_suffix(filename);
 39         strcat(filename,HDR_SUFF);
 40         if((fp=fopen(filename,"wb"))==NULL){
 41                 printf("cannot open file %s for output\n",filename);
 42                 return 0;
 43         }
 44         {
 45                 /*Initialize hdr to zeros to allow compatibility with newest*/
 46                 /*versions of ANALYZE*/
 47                 /*With thanks to Joel T. Lee, Psychiatry PET, VA, Minneapolis*/
 48                 char *ptr,*endptr;
 49                 for(ptr=(char *)&hdr,endptr=ptr+sizeof(hdr);ptr<endptr;ptr++)*ptr=0;
 50         }
 51         /*Copy required data into header struct*/
 52         hdr.bits=stats->bits;
 53         hdr.dims=4;
 54         hdr.x_dim=stats->x_dim;
 55         hdr.y_dim=stats->y_dim;
 56         hdr.z_dim=stats->z_dim;
 57         hdr.t_dim=1;
 58         if (stats->bits==8){
 59                 hdr.datatype=2;         /*unsigned characters*/
 60         }
 61         else if (stats->bits==1){
 62                 hdr.datatype=1;         /*binary*/
 63         }
 64         else if (stats->bits==16){
 65                 hdr.datatype=4;         /*short int*/
 66         }
 67         else if (stats->bits==32){
 68                 hdr.datatype=8;         /*int (ignoring other option of floating point)*/
 69         }
 70         else{
 71                 hdr.datatype=0;         /*unknown data type*/
 72         }
 73         hdr.x_size=stats->x_size;
 74         hdr.y_size=stats->y_size;
 75         hdr.z_size=stats->z_size;
 76         hdr.glmax=flag[1];                      /*global max*/
 77         hdr.glmin=flag[0];                      /*global min*/
 78         hdr.sizeof_hdr=sizeof(struct hdr);      /*standard=348*/
 79         hdr.extents=16384;
 80         hdr.regular='r';
 81 
 82         strncpy(hdr.descrip,comment,79);
 83 
 84         /*Write out header*/
 85 /* maintain BIG_ENDIAN format when writing
 86    a.lacey@man.ac.uk
 87 */
 88 #ifndef BIG_ENDIAN_ARCHITECTURE 
 89         set_swapping_ts(1);
 90         header_endian(&hdr);
 91 #endif
 92         if(fwrite((char *)&hdr,sizeof(struct hdr),1,fp)!=1){
 93                 printf("file write error writing header %s\n",filename);
 94                 fclose(fp);
 95                 return 0;
 96         }
 97         fclose(fp);
 98         return 1;
 99 }
100 

~ [ 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.