forked from neurodebian/afni_removeme_eventually
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3dANOVA.lib
executable file
·1149 lines (912 loc) · 33.7 KB
/
3dANOVA.lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
Major portions of this software are copyrighted by the Medical College
of Wisconsin, 1998-2001, and are released under the Gnu General Public
License, Version 2. See the file README.Copyright for details.
******************************************************************************/
/*---------------------------------------------------------------------------*/
/*
This file contains routines used by the three ANOVA programs: 3dANOVA,
3dANOVA2, and 3dANOVA3.
File: 3dANOVA.lib
Author: B. D. Ward
Date: 5 January 1998
Mod: Added command -diskspace to print out how much disk space is
required to execute the problem.
Date: 23 January 1997
Mod: Change to routine write_afni_data to reduce truncation error.
Date: 27 January 1997
Mod: Added machine specific code for checking disk space.
Date: 29 January 1997
Mod: Extensive changes required to implement the 'bucket' dataset.
Date: 30 December 1997
Mod: Divided file 3dANOVA.h into: 3dANOVA.h and 3dANOVA.lib.
Date: 5 January 1998
Mod: Added software for statistical tests of individual cell means,
cell differences, and cell contrasts.
Date: 27 October 1998
Mod: Added changes for incorporating History notes.
Date: 09 September 1999
Mod: Replaced dataset input code with calls to THD_open_dataset,
to allow operator selection of individual sub-bricks for input.
Date: 02 December 1999
Mod: Correction to routine destroy_anova_options. Removed memory
deallocation for option_data->first_dataset.
Date: 01 August 2001
Mod: Modified routine write_afni_data so that all output subbricks
will now have the scaled short integer format.
Date: 14 March 2002
Mod: Modify add_file_name() to use .1D filenames if so ordered.
Date: 14 March 2003 - RWCox.
Mod: Modified to init 2nd order contrast struct members.
Date: 17 October 2005 [rickr/gangc]
Mod: Init option_data->old_method to 0.
Date: 22 November 2005 [rickr]
Mod: Added contrasts_are_valid(), along with supporting functions
float_sum_is_small() and old_method_applies().
Date: 01 December 2005 [rickr]
Mod: Modified to init aBdiff, Abdiff and abmean struct members.
Date: 28 December 2005 [rickr]
*/
/* defined 'later' in parent file */
int required_data_files (anova_options * option_data);
/*---------------------------------------------------------------------------*/
/*
Routine to initialize input options.
*/
void initialize_options (anova_options * option_data)
{
int i, j, k;
option_data->datum = ILLEGAL_TYPE;
strcpy (option_data->session, "./");
option_data->diskspace = 0;
option_data->nvoxel = -1;
option_data->model = 1;
option_data->old_method = 0;
option_data->a = 0;
option_data->b = 0;
option_data->c = 0;
option_data->n = 0;
option_data->nt = 0;
for (i = 0; i < MAX_LEVELS; i++)
option_data->na[i] = 0;
option_data->xname = NULL;
option_data->first_dataset = NULL;
option_data->nx = 0;
option_data->ny = 0;
option_data->nz = 0;
option_data->nxyz = 0;
option_data->nftr = 0;
option_data->ftrname = NULL;
option_data->nfa = 0;
option_data->faname = NULL;
option_data->nfb = 0;
option_data->fbname = NULL;
option_data->nfc = 0;
option_data->fcname = NULL;
option_data->nfab = 0;
option_data->fabname = NULL;
option_data->nfac = 0;
option_data->facname = NULL;
option_data->nfbc = 0;
option_data->fbcname = NULL;
option_data->nfabc = 0;
option_data->fabcname = NULL;
option_data->num_ameans = 0;
option_data->num_bmeans = 0;
option_data->num_cmeans = 0;
option_data->num_xmeans = 0;
option_data->num_abmeans = 0; /* 16 Dec 2005 [rickr] */
for (i = 0; i < MAX_MEANS; i++)
{
option_data->amname[i] = NULL;
option_data->bmname[i] = NULL;
option_data->cmname[i] = NULL;
option_data->xmname[i] = NULL;
option_data->abmname[i] = NULL;
option_data->ameans[i] = 0;
option_data->bmeans[i] = 0;
option_data->cmeans[i] = 0;
for (j = 0; j < 3; j++)
option_data->xmeans[i][j] = 0;
for (j = 0; j < 2; j++)
option_data->abmeans[i][j] = 0;
}
option_data->num_adiffs = 0;
option_data->num_bdiffs = 0;
option_data->num_cdiffs = 0;
option_data->num_xdiffs = 0;
option_data->num_aBdiffs = 0; /* 16 Dec 2005 [rickr] */
option_data->num_Abdiffs = 0;
for (i = 0; i < MAX_DIFFS; i++)
{
option_data->adname[i] = NULL;
option_data->bdname[i] = NULL;
option_data->cdname[i] = NULL;
option_data->xdname[i] = NULL;
option_data->aBdname[i] = NULL;
option_data->Abdname[i] = NULL;
for (j = 0; j < 2; j++)
{
option_data->adiffs[i][j] = 0;
option_data->bdiffs[i][j] = 0;
option_data->cdiffs[i][j] = 0;
for (k = 0; k < 3; k++)
option_data->xdiffs[i][j][k] = 0;
option_data->aBdiffs[i][j] = 0;
option_data->Abdiffs[i][j] = 0;
}
option_data->aBdlevel[i] = 0;
option_data->Abdlevel[i] = 0;
}
option_data->num_acontr = 0;
option_data->num_bcontr = 0;
option_data->num_ccontr = 0;
option_data->num_xcontr = 0;
option_data->num_aBcontr = 0; /* 14 Oct 2005 [rickr] */
option_data->num_Abcontr = 0;
for (i = 0; i < MAX_CONTR; i++)
{
option_data->acname[i] = NULL;
option_data->bcname[i] = NULL;
option_data->ccname[i] = NULL;
option_data->xcname[i] = NULL;
option_data->aBcname[i] = NULL;
option_data->Abcname[i] = NULL;
option_data->aBclevel[i] = 0;
option_data->Abclevel[i] = 0;
for (j = 0; j < MAX_LEVELS; j++)
{
option_data->acontr[i][j] = 0.0;
option_data->bcontr[i][j] = 0.0;
option_data->ccontr[i][j] = 0.0;
for (k = 0; k < MAX_LEVELS; k++)
option_data->xcontr[i][j][k] = 0.0;
option_data->aBcontr[i][j] = 0.0;
option_data->Abcontr[i][j] = 0.0;
}
}
option_data->bucket_filename = NULL;
option_data->debug = 0; /* 8 Dec 2005 [rickr] */
option_data->nmask = 0; /* 11 Mar 2009 [RWCox] */
option_data->mask = NULL;
}
/*---------------------------------------------------------------------------*/
/*
Routine to print error message and stop.
*/
void ANOVA_error (char * message)
{
ERROR_exit("Program %s: %s" , PROGRAM_NAME, message ) ;
}
/*---------------------------------------------------------------------------*/
/*
Routine to write a 3d volume of floating point data to a (temporary)
disk file.
*/
int volume_write_count (char * filename, float * fout, int size)
{
char sfilename[MAX_NAME_LENGTH]; /* output file name */
char message[MAX_NAME_LENGTH]; /* error message */
FILE * far; /* floating point output file */
int count; /* number of data items written to disk */
/*----- output file name -----*/
strcpy (sfilename, filename);
strcat (sfilename, SUFFIX);
/*----- first, see if file already exists -----*/
far = fopen (sfilename, "r");
if (far != NULL)
{
sprintf (message, "file %s already exists. ", sfilename);
ANOVA_error (message);
}
/*----- open temporary data file for output -----*/
far = fopen (sfilename, "w");
if (far == NULL)
ANOVA_error ("unable to write file ");
/*----- write 3d data set -----*/
count = fwrite (fout, sizeof(float), size, far);
fclose (far);
return (count);
}
/*---------------------------------------------------------------------------*/
/*
Routine to write a 3d volume of floating point data to a (temporary)
disk file. Error exit if cannot write entire file.
*/
void volume_write (char * filename, float * fout, int size)
{
int count; /* number of data items written to disk */
/*----- attempt to write 3d volume of data -----*/
count = volume_write_count (filename, fout, size);
/*----- error in writing file? -----*/
if (count != size) ANOVA_error ("error in writing data file ");
}
/*---------------------------------------------------------------------------*/
/*
Routine to read a 3d volume of floating point data.
*/
void volume_read (char * filename, float * fin, int size)
{
char sfilename[MAX_NAME_LENGTH]; /* input file name */
char message[MAX_NAME_LENGTH]; /* error message */
FILE * far; /* floating point input file */
int count; /* number of data items read from disk */
/*----- input file name -----*/
strcpy (sfilename, filename);
strcat (sfilename, SUFFIX);
/*----- open temporary data file for input -----*/
far = fopen (sfilename, "r");
if (far == NULL)
{
sprintf (message, "Unable to open temporary file %s", sfilename);
ANOVA_error (message);
}
/*----- read 3d data file -----*/
count = fread (fin, sizeof(float), size, far);
fclose (far);
/*----- error in reading file? -----*/
if (count != size) ANOVA_error ("error in reading data file ");
}
/*---------------------------------------------------------------------------*/
/*
Routine to delete a file containing a 3d volume of floating point data.
*/
void volume_delete (char * filename)
{
char sfilename[MAX_NAME_LENGTH]; /* file name */
/*----- build file name -----*/
strcpy (sfilename, filename);
strcat (sfilename, SUFFIX);
/*----- delete 3d data file -----*/
remove (sfilename);
}
/*---------------------------------------------------------------------------*/
/*
Routine to set a 3d volume of floating point data to zero.
*/
void volume_zero (float * f, int size)
{
int i;
for (i = 0; i < size; i++)
f[i] = 0.0;
}
/*---------------------------------------------------------------------------*/
/*
Routine to get the dimensions of the 3d AFNI data sets.
*/
void get_dimensions (anova_options * option_data)
{
THD_3dim_dataset * dset=NULL;
/*----- read first dataset to get dimensions, etc. -----*/
dset = THD_open_dataset( option_data->first_dataset ) ;
if( ! ISVALID_3DIM_DATASET(dset) ){
ERROR_exit("Unable to open dataset file %s\n",
option_data->first_dataset);
}
/*----- data set dimensions in voxels -----*/
option_data->nx = dset->daxes->nxx ;
option_data->ny = dset->daxes->nyy ;
option_data->nz = dset->daxes->nzz ;
option_data->nxyz = option_data->nx * option_data->ny * option_data->nz ;
THD_delete_3dim_dataset( dset , False ) ; dset = NULL ;
if( option_data->mask != NULL && option_data->nmask != option_data->nxyz ){
WARNING_message("ANOVA datasets and mask don't have same number of voxels!") ;
option_data->mask = NULL ; option_data->nmask = 0 ;
}
}
/*---------------------------------------------------------------------------*/
/*
Routine to check whether one temporary file already exists.
*/
void check_one_temporary_file (char * filename)
{
FILE * far; /* temporary file pointer */
char sfilename[MAX_NAME_LENGTH]; /* temporary file name */
char message[MAX_NAME_LENGTH]; /* error message */
/*----- see if file already exists -----*/
strcpy (sfilename, filename);
strcat (sfilename, SUFFIX);
far = fopen (sfilename, "r");
if (far != NULL)
{
sprintf (message, "temporary file %s already exists. ", sfilename);
ANOVA_error (message);
}
}
/*---------------------------------------------------------------------------*/
/*
Routine to check whether one output file already exists.
*/
void check_one_output_file (anova_options * option_data, char * filename)
{
THD_3dim_dataset * dset=NULL; /* input afni data set pointer */
THD_3dim_dataset * new_dset=NULL; /* output afni data set pointer */
int ierror; /* number of errors in editing data */
/*----- read first dataset -----*/
dset = THD_open_dataset (option_data->first_dataset ) ;
if( ! ISVALID_3DIM_DATASET(dset) ){
ERROR_exit("Unable to open dataset file %s\n",
option_data->first_dataset);
}
/*-- make an empty copy of this dataset --*/
new_dset = EDIT_empty_copy( dset ) ;
THD_delete_3dim_dataset( dset , False ) ; dset = NULL ;
ierror = EDIT_dset_items( new_dset ,
ADN_prefix , filename ,
ADN_label1 , filename ,
ADN_directory_name , option_data->session ,
ADN_self_name , filename ,
ADN_type , ISHEAD(dset) ? HEAD_FUNC_TYPE :
GEN_FUNC_TYPE ,
ADN_none ) ;
if( ierror > 0 ){
ERROR_exit(
"%d errors in attempting to create output dataset!\n", ierror ) ;
}
if( THD_is_file(new_dset->dblk->diskptr->header_name) ){
ERROR_exit(
"Output dataset file %s already exists--cannot continue!\a\n",
new_dset->dblk->diskptr->header_name ) ;
}
/*----- deallocate memory -----*/
THD_delete_3dim_dataset( new_dset , False ) ; new_dset = NULL ;
}
/*---------------------------------------------------------------------------*/
/*
Return maximum of two integers.
*/
int max (int n1, int n2)
{
if (n1 > n2)
return n1;
else
return n2;
}
/*---------------------------------------------------------------------------*/
/*
Routine to determine if sufficient disk space exists for storing
the temporary data files.
*/
void check_disk_space (anova_options * option_data)
{
char ch; /* user response */
int nxyz; /* number of voxels per image */
int nmax; /* maximum number of disk files */
/*----- initialize local variables -----*/
nxyz = option_data->nxyz;
/*----- first, determine the maximum number of files required -----*/
nmax = required_data_files (option_data);
printf("\nThis problem requires approximately %d MB of free disk space.\n",
(4*nmax*nxyz/1000000) + 1);
/*----- Determine how much disk space is available. -----*/
printf ("Summary of available disk space: \n\n");
system (DF);
printf ("\nDo you wish to proceed? ");
ch = getchar();
if ((ch != 'Y') && (ch != 'y')) exit(0);
printf ("\n");
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*
Routine to read one AFNI data set from file 'filename'.
The data is converted to floating point (in ffim).
*/
void read_afni_data (anova_options * option_data,
char * filename, float * ffim)
{
int iv; /* index number of intensity sub-brick */
THD_3dim_dataset * dset=NULL; /* data set pointer */
void * vfim = NULL; /* image data pointer */
int nx, ny, nz, nxyz; /* data set dimensions in voxels */
byte *amask = option_data->mask ;
nx = option_data->nx;
ny = option_data->ny;
nz = option_data->nz;
nxyz = option_data->nxyz;
/*----- read in the data -----*/
DOPEN(dset,filename) ;
iv = DSET_PRINCIPAL_VALUE(dset) ;
/*----- convert it to floats (in ffim) -----*/
SUB_POINTER(dset,iv,0,vfim) ;
EDIT_coerce_scale_type( nxyz , DSET_BRICK_FACTOR(dset,iv) ,
DSET_BRICK_TYPE(dset,iv),vfim , /* input */
MRI_float ,ffim ) ; /* output */
THD_delete_3dim_dataset( dset , False ) ; dset = NULL ;
if( amask != NULL ){ /* 11 Mar 2009 */
for( iv=0 ; iv < nxyz ; iv++ ) if( amask[iv] == 0 ) ffim[iv] = 0.0f ;
}
}
/*---------------------------------------------------------------------------*/
/*
Routine to write one AFNI data set.
This data set may be either 'fitt' type (intensity + t-statistic)
or 'fift' type (intensity + F-statistic).
The intensity data is in ffim, and the corresponding statistic is in ftr.
numdof = numerator degrees of freedom
dendof = denominator degrees of freedom
Note: if dendof = 0, then write 'fitt' type data set;
if dendof > 0, then write 'fift' type data set.
*/
void write_afni_data (anova_options * option_data, char * filename,
float * ffim, float * ftr, int numdof, int dendof)
{
int nxyz; /* number of voxels */
int ii; /* voxel index */
THD_3dim_dataset * dset=NULL; /* input afni data set pointer */
THD_3dim_dataset * new_dset=NULL; /* output afni data set pointer */
int ierror; /* number of errors in editing data */
int ibuf[32]; /* integer buffer */
float fbuf[MAX_STAT_AUX]; /* float buffer */
float fimfac=0.0f ; /* scale factor for short data */
int output_datum; /* data type for output data */
void *tsp; /* 2nd sub-brick data pointer */
void *vdif; /* 1st sub-brick data pointer */
int func_type; /* afni data set type */
float top, func_scale_short=0.0f; /* parameters for scaling data */
char label[80]; /* label for output file history */
byte *amask = option_data->mask ;
/*----- initialize local variables -----*/
nxyz = option_data->nxyz;
/*----- read first dataset -----*/
dset = THD_open_dataset (option_data->first_dataset) ;
if( ! ISVALID_3DIM_DATASET(dset) ){
ERROR_exit("Unable to open dataset file %s\n",
option_data->first_dataset);
}
/*-- make an empty copy of this dataset, for eventual output --*/
new_dset = EDIT_empty_copy( dset ) ;
/*----- Record history of dataset -----*/
sprintf (label, "Output prefix: %s", filename);
if( commandline != NULL )
tross_multi_Append_History( new_dset , commandline,label,NULL ) ;
else
tross_Append_History ( new_dset, label);
#define ALLOW_FLOATIZE
#ifdef ALLOW_FLOATIZE
output_datum = AFNI_yesenv("AFNI_FLOATIZE") ? MRI_float : MRI_short ;
ibuf[0] = output_datum ; ibuf[1] = output_datum ;
#else
output_datum = MRI_short ;
ibuf[0] = output_datum ; ibuf[1] = MRI_short ;
#endif
if (dendof == 0) func_type = FUNC_TT_TYPE;
else func_type = FUNC_FT_TYPE;
ierror = EDIT_dset_items( new_dset ,
ADN_prefix , filename ,
ADN_label1 , filename ,
ADN_directory_name , option_data->session ,
ADN_self_name , filename ,
ADN_type , ISHEAD(dset) ? HEAD_FUNC_TYPE :
GEN_FUNC_TYPE ,
ADN_func_type , func_type ,
ADN_nvals , FUNC_nvals[func_type] ,
ADN_datum_array , ibuf ,
ADN_malloc_type, DATABLOCK_MEM_MALLOC ,
ADN_none ) ;
if( ierror > 0 )
ERROR_exit(
"%d errors in attempting to create output dataset!\a", ierror ) ;
if( THD_is_file(new_dset->dblk->diskptr->header_name) )
ERROR_exit(
"Output dataset file %s already exists--cannot continue!\a",
new_dset->dblk->diskptr->header_name ) ;
/*----- deleting exemplar dataset -----*/
THD_delete_3dim_dataset( dset , False ) ; dset = NULL ;
/*----- allocate memory for output data -----*/
vdif = (void *) calloc( mri_datum_size(ibuf[0]) , nxyz ) ;
tsp = (void *) calloc( mri_datum_size(ibuf[1]) , nxyz ) ;
/*----- attach bricks to new data set -----*/
mri_fix_data_pointer (vdif, DSET_BRICK(new_dset,0));
mri_fix_data_pointer (tsp , DSET_BRICK(new_dset,1));
/*----- convert data type to output specification -----*/
if( amask != NULL ){ /* 11 Mar 2009 [RWcox] */
for( ii=0 ; ii < nxyz ; ii++ )
if( amask[ii] == 0 ){ ffim[ii] = 0.0f ; ftr[ii] = 0.0f ; }
}
/* conversion of sub-brick #0 (effect measurement) */
if( ibuf[0] == MRI_short ){
fimfac = EDIT_coerce_autoscale_new( nxyz,
MRI_float, ffim, ibuf[0], vdif ) ;
if (fimfac != 0.0) fimfac = 1.0 / fimfac;
EDIT_misfit_report( DSET_PREFIX(new_dset) , 0 ,
nxyz , fimfac , vdif , ffim ) ;
} else {
memcpy( vdif , ffim , sizeof(float)*nxyz ) ;
}
#define TOP_SS 32700
/* conversion of sub-brick #1 (t or F statistic) */
if( ibuf[1] == MRI_short ){
short *qsp = (short *)tsp ;
if (dendof == 0) /* t-statistic */
{
top = TOP_SS/FUNC_TT_SCALE_SHORT;
func_scale_short = FUNC_TT_SCALE_SHORT;
}
else /* F-statistic */
{
top = TOP_SS/FUNC_FT_SCALE_SHORT;
func_scale_short = FUNC_FT_SCALE_SHORT;
}
for (ii = 0; ii < nxyz; ii++)
{
if (ftr[ii] > top)
qsp[ii] = TOP_SS;
else if (ftr[ii] < -top)
qsp[ii] = -TOP_SS;
else if (ftr[ii] >= 0.0)
qsp[ii] = (short) (func_scale_short * ftr[ii] + 0.5);
else
qsp[ii] = (short) (func_scale_short * ftr[ii] - 0.5);
}
EDIT_misfit_report( DSET_PREFIX(new_dset) , 1 ,
nxyz , 1.0f/func_scale_short , qsp , ftr ) ;
} else {
memcpy( tsp , ftr , sizeof(float)*nxyz ) ;
}
/*----- write afni data set -----*/
INFO_message("Writing combined dataset into %s",
new_dset->dblk->diskptr->header_name) ;
fbuf[0] = numdof;
fbuf[1] = dendof;
for( ii=2 ; ii < MAX_STAT_AUX ; ii++ ) fbuf[ii] = 0.0 ;
(void) EDIT_dset_items( new_dset , ADN_stat_aux , fbuf , ADN_none ) ;
if( output_datum == MRI_short ){
fbuf[0] = (fimfac != 1.0f) ? fimfac : 0.0f ;
fbuf[1] = 1.0f / func_scale_short ;
(void) EDIT_dset_items( new_dset , ADN_brick_fac , fbuf , ADN_none ) ;
}
ii = !AFNI_noenv("AFNI_AUTOMATIC_FDR") ? THD_create_all_fdrcurves(new_dset)
: 0 ;
if( ii > 0 ) ININFO_message("created %d FDR curves in header",ii) ;
THD_load_statistics( new_dset ) ;
THD_write_3dim_dataset( NULL,NULL , new_dset , True ) ;
/*----- deallocate memory -----*/
THD_delete_3dim_dataset( new_dset , False ) ; new_dset = NULL ;
}
/*---------------------------------------------------------------------------*/
static int use_1D_filenames = 0 ; /* 14 Mar 2003 */
static void USE_1D_filenames( int uu ){ use_1D_filenames=uu; }
/*---------------------------------------------------------------------------*/
/*
Routine to add file name to command string.
*/
void add_file_name (THD_3dim_dataset * new_dset, char * filename,
char * command_str)
{
EDIT_dset_items (new_dset,
ADN_prefix, filename,
ADN_none);
#if 0 /* Debugging for different file formats ZSS Feb 2012 */
INFO_message("In here with: >%s< and >%s<\n"
"Dset type: %s\n"
"Brikname: %s\n"
"Use1D: %d\n",
filename, command_str,
storage_mode_name(new_dset->dblk->diskptr->storage_mode),
DSET_BRIKNAME(new_dset),
use_1D_filenames);
#endif
if (! ISVALID_3DIM_DATASET(new_dset))
{
ERROR_exit("Unable to open dataset file %s\n",
DSET_BRIKNAME(new_dset));
}
strcat (command_str, " ");
strcat (command_str, DSET_BRIKNAME(new_dset));
if( !STRING_HAS_SUFFIX(DSET_BRIKNAME(new_dset),".1D") &&
!STRING_HAS_SUFFIX(DSET_BRIKNAME(new_dset),".1D.dset") ) {
/* May not need to get in here anymore,for .1D. ZSS Feb 06 2012 */
switch( use_1D_filenames ){ /* 14 Mar 2003 - RWCox */
default: break ;
case 1:
case 3:{ int ll = strlen(command_str) ;
command_str[ll-10] = '\0' ; strcat(command_str,".") ;
if( use_1D_filenames == 1 ) strcat(command_str,"1") ;
else strcat(command_str,"3") ;
strcat(command_str,"D") ;
}
break ;
}
}
}
/*---------------------------------------------------------------------------*/
/*
Routine to get a nice string to use as sub-brick label.
*/
char *label_from_filename(char *fname) {
return(without_afni_filename_extension(fname));
}
/*---------------------------------------------------------------------------*/
/*
Routine to remove AFNI .HEAD and .BRIK dataset files.
*/
void remove_dataset (THD_3dim_dataset * new_dset, char * filename)
{
EDIT_dset_items (new_dset,
ADN_prefix, filename,
ADN_none);
if( !ISVALID_DSET(new_dset) ) return ;
#if 0
fprintf(stderr,"remove_dataset(%s): ",filename) ;
#endif
switch( use_1D_filenames ){ /* 14 Mar 2003 - RWCox */
default:
remove (DSET_HEADNAME(new_dset));
/* remove might fail if BRIK got compressed 2 Aug 2013 [rickr] */
if( remove (DSET_BRIKNAME(new_dset)) )
COMPRESS_unlink(DSET_BRIKNAME(new_dset));
#if 0
fprintf(stderr,"%s ",DSET_HEADNAME(new_dset)) ;
fprintf(stderr,"%s\n",DSET_BRIKNAME(new_dset)) ;
#endif
break ; /* was missing 2 Aug 2013 [rickr] */
case 1:
case 3:{
char *fname=strdup(DSET_BRIKNAME(new_dset)); int ll=strlen(fname);
if( ll > 10 && strstr(fname,".BRIK") != NULL ){
fname[ll-10] = '\0' ; strcat(fname,".") ;
if( use_1D_filenames == 1 ) strcat(fname,"1") ;
else strcat(fname,"3") ;
strcat(fname,"D") ;
}
#if 0
fprintf(stderr,"%s\n",fname);
#endif
remove(fname) ; free(fname) ;
}
break ;
}
}
/*---------------------------------------------------------------------------*/
/*
Routine to release memory allocated for anova_options.
*/
void destroy_anova_options (anova_options * option_data)
{
int i, j, k, m;
/*----- deallocate memory -----*/
for (i = 0; i < option_data->a; i++)
for (j = 0; j < option_data->b; j++)
for (k = 0; k < option_data->c; k++)
for (m = 0; m < option_data->n; m++)
{
free (option_data->xname[i][j][k][m]);
option_data->xname[i][j][k][m] = NULL;
}
if (option_data->nftr)
{
free (option_data->ftrname);
option_data->ftrname = NULL;
}
if (option_data->nfa)
{
free (option_data->faname);
option_data->faname = NULL;
}
if (option_data->nfb)
{
free (option_data->fbname);
option_data->fbname = NULL;
}
if (option_data->nfc)
{
free (option_data->fcname);
option_data->fcname = NULL;
}
if (option_data->nfab)
{
free (option_data->fabname);
option_data->fabname = NULL;
}
if (option_data->nfac)
{
free (option_data->facname);
option_data->facname = NULL;
}
if (option_data->nfbc)
{
free (option_data->fbcname);
option_data->fbcname = NULL;
}
if (option_data->nfabc)
{
free (option_data->fabcname);
option_data->fabcname = NULL;
}
if (option_data->num_ameans)
for (i=0; i < option_data->num_ameans; i++)
{
free (option_data->amname[i]);
option_data->amname[i] = NULL;
}
if (option_data->num_bmeans)
for (i=0; i < option_data->num_bmeans; i++)
{
free (option_data->bmname[i]);
option_data->bmname[i] = NULL;
}
if (option_data->num_cmeans)
for (i=0; i < option_data->num_cmeans; i++)
{
free (option_data->cmname[i]);
option_data->cmname[i] = NULL;
}
if (option_data->num_xmeans)
for (i=0; i < option_data->num_xmeans; i++)
{
free (option_data->xmname[i]);
option_data->xmname[i] = NULL;
}
if (option_data->num_adiffs)
for (i=0; i < option_data->num_adiffs; i++)
{
free (option_data->adname[i]);
option_data->adname[i] = NULL;
}
if (option_data->num_bdiffs)
for (i=0; i < option_data->num_bdiffs; i++)
{
free (option_data->bdname[i]);
option_data->bdname[i] = NULL;
}
if (option_data->num_cdiffs)
for (i=0; i < option_data->num_cdiffs; i++)
{
free (option_data->cdname[i]);
option_data->cdname[i] = NULL;
}
if (option_data->num_xdiffs)
for (i=0; i < option_data->num_xdiffs; i++)
{
free (option_data->xdname[i]);
option_data->xdname[i] = NULL;
}
if (option_data->num_acontr)
for (i=0; i < option_data->num_acontr; i++)
{
free (option_data->acname[i]);
option_data->acname[i] = NULL;
}
if (option_data->num_bcontr)
for (i=0; i < option_data->num_bcontr; i++)
{
free (option_data->bcname[i]);
option_data->bcname[i] = NULL;
}
if (option_data->num_ccontr)
for (i=0; i < option_data->num_ccontr; i++)
{
free (option_data->ccname[i]);
option_data->ccname[i] = NULL;
}
if (option_data->num_xcontr)
for (i=0; i < option_data->num_xcontr; i++)
{
free (option_data->xcname[i]);
option_data->xcname[i] = NULL;
}
}
/*---------------------------------------------------------------------------*/
/*
Indicate whether -old_method should be considered. 2 Dec 2005 [rickr]
Valid uses:
level 1: valid (no models)
level 2: model 3
level 3: models 4 and 5