cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
isotopes.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*LoadIsotopes read in the nuclear isotope data and allocate space */
4 #include "cddefines.h"
5 #include "abund.h"
6 #include "atmdat.h"
7 
8 /*LoadIsotopes read in the nuclear isotope data and allocate space */
9 void LoadIsotopes ( )
10 {
11  DEBUG_ENTRY( "SetIsotopeFractions()" );
12 
13  FILE *ioDATA;
14  string chFile = "isotopes.dat";
15 
16  // first try local directory, then data/abundances
17  if( (ioDATA = open_data( chFile.c_str(), "r", AS_LOCAL_ONLY_TRY ) ) == NULL )
18  {
19  char chPath[FILENAME_PATH_LENGTH_2] = { 0 }; /*entire path to file including file name*/
20  strcat( chPath, chFile.c_str() );
21  ioDATA = open_data( chPath, "r" ); // will abort if not found
22  }
23 
24  char chLine[INPUT_LINE_LENGTH]; /*to store file lines*/
25  bool lgEOL;
26 
27  while( read_whole_line( chLine , (int)sizeof(chLine) , ioDATA ) != NULL )
28  {
29  if( chLine[0]=='*' )
30  break;
31 
32  /* skip comment */
33  if( chLine[0]=='#' )
34  continue;
35  if( chLine[0]=='\n' || chLine[0]=='\0' )
36  {
37  fprintf(ioQQQ,
38  "PROBLEM in LoadIsotopes: Encountered unexpected empty line in %s.\n",
39  chFile.c_str());
41  }
42 
43 
44  long i = 1;
45  int ielem = (int)FFmtRead(chLine,&i,sizeof(chLine),&lgEOL) - 1;
46  ASSERT( ielem >= 0 );
47 
48  int Aiso = (int) FFmtRead(chLine,&i,sizeof(chLine),&lgEOL);
49  ASSERT( Aiso > 0 );
50 
51  FFmtRead(chLine,&i,sizeof(chLine),&lgEOL);
52 
53  realnum mass = (realnum) FFmtRead(chLine,&i,sizeof(chLine),&lgEOL);
54  ASSERT( mass > 0. );
55 
56 
57  realnum spin = 0., magm = 0.;
58  double tmp = FFmtRead(chLine,&i,sizeof(chLine),&lgEOL);
59  if( tmp )
60  {
61  spin = (realnum) tmp;
62  ASSERT( spin >= 0. );
63 
64  magm = (realnum) FFmtRead(chLine,&i,sizeof(chLine),&lgEOL);
65  ASSERT( magm != 0. );
66  }
67  // printf("ielem = %d\t Aiso = %d\t mass = %9.6f\t spin = %3.1f\t magm = %10.6f\n",
68  // ielem, Aiso, mass, spin, magm);
69 
70  abund.IsoAbn[ielem].setData( Aiso, mass, spin, magm);
71  }
72 
73  fclose( ioDATA );
74  return;
75 }
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition: cpu.cpp:765
const int FILENAME_PATH_LENGTH_2
Definition: cddefines.h:296
FILE * ioQQQ
Definition: cddefines.cpp:7
t_abund abund
Definition: abund.cpp:5
t_isotope IsoAbn[LIMELM]
Definition: abund.h:213
float realnum
Definition: cddefines.h:124
#define EXIT_FAILURE
Definition: cddefines.h:168
const int INPUT_LINE_LENGTH
Definition: cddefines.h:301
#define cdEXIT(FAIL)
Definition: cddefines.h:482
#define ASSERT(exp)
Definition: cddefines.h:613
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
Definition: service.cpp:70
void setData(int Anum, realnum nmass, realnum nspin, realnum nmagmom)
Definition: abund.h:70
void LoadIsotopes()
Definition: isotopes.cpp:9
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
Definition: service.cpp:381