File: cmap_close.c

package info (click to toggle)
libccp4 8.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,100 kB
  • sloc: ansic: 19,540; fortran: 18,766; sh: 11,561; makefile: 73
file content (80 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download | duplicates (6)
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
/*
     cmap_close.c: close map file
     Copyright (C) 2001  CCLRC, Charles Ballard

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Lesser General Public License for more details.
*/
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include "cmaplib.h"
#include "cmap_header.h"
#include "cmap_labels.h"
#include "cmap_errno.h"

/*! Close the file.
 In write mode the header is output, along with the machine
 stamp.  In read mode the file is just closed. 
 Write mode supports ways of updating the map statistics ( 
 only active for FLOAT32).
 /param mfile (CMMFile *)
 /return void */
void ccp4_cmap_close(CMMFile *mfile)
{
  int i;
  
  if ( mfile == NULL) 
    return;

  if (ccp4_file_is_write(mfile->stream) ) {
    if ( mfile->data_mode == FLOAT32) {
      switch (mfile->close_mode) {
      case 1:
        break;
      case 2:
	mfile->stats.offset = 0.0f;
      case 0:
      default:
        if (mfile->stats.total != 0) {
          mfile->stats.mean /= mfile->stats.total;
          mfile->stats.rms /= mfile->stats.total;
          mfile->stats.rms -= mfile->stats.mean*mfile->stats.mean;
          mfile->stats.rms = (mfile->stats.rms > 0) ? sqrt(mfile->stats.rms) : 0;
          mfile->stats.mean += (double) mfile->stats.offset;
        }
        break;
      }
    }
    write_mapheader(mfile);
    write_maplabels(mfile);
    ccp4_file_warch(mfile->stream);
  }
  ccp4_file_close(mfile->stream);
  for (i=0 ; i != mfile->labels.number ; i++)
    if (mfile->labels.labels[i] != NULL)
      free(mfile->labels.labels[i]);
  free(mfile);
}

/*! Set the close mode:
    0: calculate based on stored values (default)
    1: just dump the current values
 /param mfile (CMMFile *)
 /param mask (unsigned int) close mode
 /return void */
void ccp4_cmap_closemode(CMMFile *mfile, unsigned int mask)
{
  mfile->close_mode = mask;
}