Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
save.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2023 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef SAVE_H_
5 #define SAVE_H_
6 
7 #include "energy.h"
8 #include "lines.h"
9 #include "prt.h"
10 
11 class diatomics;
12 class TransitionProxy;
13 
14 /* save.h */
15 static const long LIMPUN = 100L;
16 
18 static const long VERSION_TRNCON = 20190210L;
19 
23 void SaveDo(
24  const char *chTime);
25 
27 double PrtLogLin( double value );
28 
36 void Save1Line(
37  const TransitionProxy & t ,
38  FILE * io ,
39  realnum xLimit ,
40  long index,
41  realnum DopplerWidth);
42 
47  FILE * io);
48 
53 void save_opacity(
54  FILE * io,
55  long int np);
56 
61 void SaveSpecial(
62  FILE* io ,
63  const char *chTime);
64 
65 
69 void SaveAllSpeciesLabelsLevels( FILE *ioPUN );
70 
71 
76 void SaveSpecies(
77  FILE* ioPUN,
78  long int ipPun );
79 
85 void SaveSpeciesPseudoCont( const long ipPun, const string &speciesLabel );
86 
94 void SaveSpeciesBands( const long ipPun, const string &speciesLabel,
95  const string &fileBands, const bool lgEmergent );
96 
102 void SaveSpeciesOptDep( const long int ipPun, const string &speciesLabel );
103 
104 class molecule;
105 
106 extern void mole_save(FILE *punit, const char speciesname[], const char args[], bool lgHeader, bool lgData, bool lgCoef, double depth);
107 
108 // debug_list -- list of species to print -- add multiple species to get net
109 // rate of change for all together, useful for understanding net sources
110 // sinks to networks
111 // ioOut -- stream
112 // lgPrintReagents -- print abundances of reagents
113 // NPRINT -- max number of reactions
114 // fprint -- minimum fraction of total rate which is worth printing
115 extern void mole_dominant_rates( const vector<const molecule *>& debug_list,
116  FILE *ioOut,
117  bool lgPrintReagents, size_t NPRINT, double fprint );
118 
119 extern void mole_print_species_reactions( molecule *speciesToPrint );
120 
121 
122 /* Print header for Save1LineData() function
123  * \param ioPUN file pointer to write to
124  */
125 void PrintLineDataHeader( FILE * ioPUN );
126 
127 
134 void Save1LineData(
135  const TransitionProxy & t ,
136  FILE * io,
137  bool lgCS_2 );
138 
145 void save_line(
146  FILE * ip,
147  const char *chDo,
148  bool lgEmergent,
149  long ipPun );
150 
154 void save_average(
155  long int ipPun);
156 
160 void Save_Line_RT(
161  FILE * ip);
162 
170 void saveFITSfile(
171  FILE* io,
172  int option,
173  realnum Elo = 0.f,
174  realnum Ehi = 0.f,
175  realnum Enorm = 0.f);
176 
184 void saveFITSimg( FILE *io, const string &extName, const string &units,
185  const long nPixels,
186  const multi_arr<double,2,C_TYPE> &image );
187 
195 void saveFITSimg( FILE *io, const string &extName, const string &units,
196  const long nCols, const valarray<double> &vec );
197 
201 void SaveHeat(FILE* io);
202 
207 void CoolSave(FILE * io, const char chJob[]);
208 
213 void SaveGrid(FILE* pnunit, exit_type status);
214 
216 {
217 public:
219  FILE *ipPnunit;
220 };
221 
223 {
224 public:
225  string speciesLabel;
227  wlHi;
228  long nBins;
229 };
230 
232 {
233 public:
235  bool lgFITS;
236  long iteration;
237  long zone;
238 
239  void zero();
240  void comment(t_warnings&) {}
241 
242  const char *chName() const
243  {
244  return "img_matrix";
245  }
246 
247  inline bool matchIteration( const long this_iteration ) const
248  {
249  return ( ( iteration > 0 && iteration == this_iteration ) ||
250  ! iteration );
251  }
252 
253  inline bool matchZone( const long this_zone ) const
254  {
255  return ( ( zone > 0 && zone == this_zone ) || ! zone );
256  }
257 
262  void createImage( const string &species,
263  const long iteration,
264  const long nzone,
265  const long numLevels,
266  const multi_arr<double,2,C_TYPE> &matrix,
267  const valarray<double> &creation,
268  bool haveNegPop = false );
269 
273  void createImage(
274  const long iteration,
275  const long nzone,
276  const long numLevels,
277  const multi_arr<double,2,C_TYPE> &matrix,
278  const valarray<double> &creation,
279  bool haveNegPop = false );
280 
285  void addImagePop_FITS( const string &species,
286  const long iteration,
287  const long nzone,
288  const long numLevels,
289  const valarray<double> &pop,
290  bool haveNegPop = false );
291 
295  void addImagePop_FITS(
296  const long iteration,
297  const long nzone,
298  const long numLevels,
299  const valarray<double> &pop,
300  bool haveNegPop = false );
301 
302 private:
303  string set_basename( const string &species,
304  const long iteration,
305  const long nzone,
306  bool haveNegPop = false );
307 
308  void createImage_PPM( const string &basename,
309  const long numLevels,
310  const multi_arr<double,2,C_TYPE> &matrix );
311 
312  void createImage_FITS( const string &basename,
313  const long numLevels,
314  const multi_arr<double,2,C_TYPE> &matrix,
315  const valarray<double> &creation );
316 };
317 
318 struct t_save {
319 
321  {
322  for( long i=0; i < LIMPUN; ++i )
323  {
324  nLineList[i] = -1;
325  lgFITS[i] = false;
326  lgXSPEC[i] = false;
327  FITStype[i] = -1;
328  nAverageList[i] = -1;
329  p_lgSaveTitleDone[i] = false;
330  p_lgSaveHeaderDone[i] = false;
331  }
332  p_lgSaveHeaderNeeded = true;
333  ipSaveGrid = -1;
334  }
335 
337  {
338  for( long i=0; i < LIMPUN; ++i )
339  {
340  SaveLineListFree(i);
341  SaveAverageFree(i);
342  }
343  }
344 
345  void SaveLineListFree(long i)
346  {
347  LineList[i].clear();
348  }
349  void SaveAverageFree(long i)
350  {
351  nAverageList[i] = 0;
352  chAverageType[i].clear();
353  chSaveSpecies[i].clear();
354  /* nAverageIonList is set of ions for averages */
355  nAverageIonList[i].clear();
356  /* nAverage2ndPar is set of second parameters for averages */
357  nAverage2ndPar[i].clear();
358  }
359 
360  string chGridDelimeter(long n)
361  {
362  ostringstream oss;
363  // NB NB -- do not change this format, tests in
364  // check_grid_file() and fix_grid_file() depend on this
365  oss << chHashString << " GRID_DELIMIT -- grid";
366  oss << setfill('0') << setw(9) << n;
367  return oss.str();
368  }
369 
374  vector<LineID> LineList[LIMPUN];
377 
382  vector<string> chAverageType[LIMPUN];
384  vector<int> nAverageIonList[LIMPUN];
386  vector<int> nAverage2ndPar[LIMPUN];
387 
390 
392  vector<string> chFileName;
393 
396 
399 
402 
412 
416 
419 
422 
425 
428 
430  long int nsave;
431 
433  char chSave[LIMPUN][5];
435 
437  char chOpcTyp[LIMPUN][5];
438 
443 
447 
448 private:
452 
456 
460 
461 public:
462  void SetSaveHeaderNeeded(bool lgVal) { p_lgSaveHeaderNeeded = lgVal; }
463 
465  bool lgSaveTitle(int ipPun) const
466  {
468  }
470 
472  bool lgSaveHeader(int ipPun) const
473  {
475  }
477 
482 
485 
487  string optname[LIMPUN];
488 
493 
495  char chSaveArgs[LIMPUN][5];
496 
497  vector<string> chSaveSpecies[LIMPUN];
498 
502 
504  bool lgFITS[LIMPUN];
505 
508 
511 
515 
517  const char *chConSavEnr[LIMPUN];
518 
520  long int ipConPun;
521 
525 
528  string chHashString;
529 
531  bool lgFLUSH;
532 
536 
539  string chGridPrefix;
540 
544 
548 
551  string chOutputFile;
552 
556  char chPunRltType[7];
557 
561  FILE* ipPoint;
563 
565  bool lgPunConv;
566  FILE* ipPunConv;
567 
568 
570  bool lgSDSOn;
571  FILE* ipSDSFile;
572 
576  FILE * ipDRout;
577  bool lgDROn,
578  lgDRPLst,
579  lgDRHash;
580 
582  FILE * ipDTout;
583  bool lgDTOn,
584  lgDTPLst,
585  lgDTHash;
586 
587  /* set true save convergence base */
591 
593  FILE* ioRecom;
594  bool lgioRecom;
595 
598  long int LinEvery;
600 
602  long int ncSaveSkip;
603 
607 
612  // same thing but for absorption lines - default is unity, set to
613  // SaveLWidth if ABSORPTION keyword occurs on save line width command
615 
617 
618  // the frequency at which the continuum volume emissivity should be saved
621 
622  // Switches for save Database command
623  // Wavenumbers vs WLAng, Gf vs A, Collision Rates or not
625 
627  vector<string> contSaveSpeciesLabel;
628  vector<adjPseudoCont> setPseudoCont;
629 
632 
634 };
635 
636 extern t_save save;
637 
638 #endif /* SAVE_H_ */
bool lgPunLstIter[LIMPUN]
Definition: save.h:501
bool lgDTOn
Definition: save.h:583
Definition: warnings.h:11
long iteration
Definition: save.h:236
vector< string > chAverageType[LIMPUN]
Definition: save.h:382
bool p_lgSaveHeaderNeeded
Definition: save.h:459
vector< int > nAverageIonList[LIMPUN]
Definition: save.h:384
realnum punarg[LIMPUN][3]
Definition: save.h:484
bool lgPunContinuum
Definition: save.h:481
void SaveSpecial(FILE *io, const char *chTime)
Definition: save_special.cpp:12
STATIC long int ipPun
Definition: save_do.cpp:368
save_img_matrix img_matrix
Definition: save.h:633
void SaveHeat(FILE *io)
Definition: heat_save.cpp:18
#define NORETURN
Definition: cpu.h:461
bool lgNoClobber[LIMPUN]
Definition: save.h:398
string chGridPrefix
Definition: save.h:539
realnum ResolutionAbs
Definition: save.h:614
bool lgDRHash
Definition: save.h:577
string chFilenamePrefix
Definition: save.h:543
void createImage(const string &species, const long iteration, const long nzone, const long numLevels, const multi_arr< double, 2, C_TYPE > &matrix, const valarray< double > &creation, bool haveNegPop=false)
Definition: save.cpp:45
bool lgImgRates
Definition: save.h:234
void save_line(FILE *ip, const char *chDo, bool lgEmergent, long ipPun)
Definition: save_line.cpp:62
static const long VERSION_TRNCON
Definition: save.h:18
void Save1LineData(const TransitionProxy &t, FILE *io, bool lgCS_2)
Definition: save_linedata.cpp:253
t_save save
Definition: save.cpp:5
vector< LineID > LineList[LIMPUN]
Definition: save.h:374
bool lgSaveGrid_noclobber
Definition: save.h:411
bool lgDTOn_noclobber
Definition: save.h:406
char chOpcTyp[LIMPUN][5]
Definition: save.h:437
void zero()
Definition: save.cpp:8
long zone
Definition: save.h:237
NORETURN void SaveLineData(FILE *io)
Definition: save_linedata.cpp:20
FILE * ipSDSFile
Definition: save.h:571
bool lgioRecom_noclobber
Definition: save.h:408
bool lgFLUSH
Definition: save.h:531
FILE * ioRecom
Definition: save.h:593
char chPunRltType[7]
Definition: save.h:556
Definition: h2_priv.h:72
long int nzone
Definition: cddefines.cpp:13
FILE * ipPnunit
Definition: save.h:219
bool lgRealSave[LIMPUN]
Definition: save.h:415
Definition: mole.h:145
exit_type
Definition: cddefines.h:151
bool lgTraceConvergeBase_noclobber
Definition: save.h:410
bool lgEmergent[LIMPUN]
Definition: save.h:418
Definition: save.h:231
long int nsave
Definition: save.h:430
void mole_save(FILE *punit, const char speciesname[], const char args[], bool lgHeader, bool lgData, bool lgCoef, double depth)
Definition: save_species.cpp:525
void SaveAllSpeciesLabelsLevels(FILE *ioPUN)
void SaveDo(const char *chTime)
Definition: save_do.cpp:461
FILE * ipPunConv
Definition: save.h:566
bool lgCumulative[LIMPUN]
Definition: save.h:421
string chGridDelimeter(long n)
Definition: save.h:360
string optname[LIMPUN]
Definition: save.h:487
string SpeciesBandFile[LIMPUN]
Definition: save.h:631
long int LinEvery
Definition: save.h:598
void SaveSpeciesOptDep(const long int ipPun, const string &speciesLabel)
Definition: save_species.cpp:440
void save_opacity(FILE *io, long int np)
Definition: save_opacity.cpp:23
bool lg_separate_iterations[LIMPUN]
Definition: save.h:446
bool lgPunConv
Definition: save.h:565
realnum WeakHeatCool
Definition: save.h:606
FILE * ipTraceConvergeBase
Definition: save.h:590
static const long LIMPUN
Definition: save.h:15
~t_save()
Definition: save.h:336
void SaveGrid(FILE *pnunit, exit_type status)
Definition: save_do.cpp:4167
Definition: save.h:222
bool lgXSPEC[LIMPUN]
Definition: save.h:507
char chSaveArgs[LIMPUN][5]
Definition: save.h:495
void SaveAverageFree(long i)
Definition: save.h:349
void Save_Line_RT(FILE *ip)
Definition: save_line.cpp:265
long int ncSaveSkip
Definition: save.h:602
void saveFITSfile(FILE *io, int option, realnum Elo=0.f, realnum Ehi=0.f, realnum Enorm=0.f)
Definition: save_fits.cpp:90
realnum wlLo
Definition: save.h:226
Definition: save.h:318
bool lgPunPoint
Definition: save.h:562
float realnum
Definition: cddefines.h:127
bool lgPunPoint_noclobber
Definition: save.h:407
bool lgLuminosityOld
Definition: save.h:535
Definition: save.h:215
bool lgSaveDataRates
Definition: save.h:624
long int nSaveEveryZone[LIMPUN]
Definition: save.h:492
bool lgQHSaveFile_noclobber
Definition: save.h:409
vector< int > nAverage2ndPar[LIMPUN]
Definition: save.h:386
long ipSaveGrid
Definition: save.h:395
bool lgLineListRatio[LIMPUN]
Definition: save.h:376
void SaveSpeciesBands(const long ipPun, const string &speciesLabel, const string &fileBands, const bool lgEmergent)
Definition: species_pseudo_cont.cpp:932
bool lgDRPLst
Definition: save.h:577
FILE * ipPoint
Definition: save.h:561
void CoolSave(FILE *io, const char chJob[])
Definition: cool_save.cpp:16
bool lgSDSOn
Definition: save.h:570
void SaveTitleDone(int ipPun)
Definition: save.h:469
realnum wlHi
Definition: save.h:226
double PrtLogLin(double value)
Definition: save_do.cpp:371
SaveParams params[LIMPUN]
Definition: save.h:389
long nBins
Definition: save.h:228
bool lgFITS
Definition: save.h:235
void SaveLineListFree(long i)
Definition: save.h:345
vector< string > contSaveSpeciesLabel
Definition: save.h:627
bool lgSaveEveryZone[LIMPUN]
Definition: save.h:491
bool lgLinEvery
Definition: save.h:599
t_save()
Definition: save.h:320
void SaveHeaderDone(int ipPun)
Definition: save.h:476
void createImage_FITS(const string &basename, const long numLevels, const multi_arr< double, 2, C_TYPE > &matrix, const valarray< double > &creation)
Definition: save.cpp:129
bool lgPrtIsotropicCont[LIMPUN]
Definition: save.h:427
bool matchZone(const long this_zone) const
Definition: save.h:253
bool lgDTPLst
Definition: save.h:583
int FITStype[LIMPUN]
Definition: save.h:510
bool lgFITS[LIMPUN]
Definition: save.h:504
bool lgDTHash
Definition: save.h:583
Definition: prt.h:117
bool p_lgSaveTitleDone[LIMPUN]
Definition: save.h:451
void mole_dominant_rates(const vector< const molecule * > &debug_list, FILE *ioOut, bool lgPrintReagents, size_t NPRINT, double fprint)
Definition: save_species.cpp:609
bool lgSaveDataGf
Definition: save.h:624
bool lgHashEndIter[LIMPUN]
Definition: save.h:524
string chHashString
Definition: save.h:528
Definition: energy.h:9
void saveFITSimg(FILE *io, const string &extName, const string &units, const long nPixels, const multi_arr< double, 2, C_TYPE > &image)
Definition: save_fits.cpp:983
bool lgPrtOldStyleLogs[LIMPUN]
Definition: save.h:401
void comment(t_warnings &)
Definition: save.h:240
string chOutputFile
Definition: save.h:551
long nAverageList[LIMPUN]
Definition: save.h:380
void createImage_PPM(const string &basename, const long numLevels, const multi_arr< double, 2, C_TYPE > &matrix)
Definition: save.cpp:169
bool lgTraceConvergeBase
Definition: save.h:588
bool lgSaveTitle(int ipPun) const
Definition: save.h:465
bool lgDROn
Definition: save.h:577
diatomics * whichDiatomToPrint[LIMPUN]
Definition: save.h:434
const char * chName() const
Definition: save.h:242
long ipEmisFreq[LIMPUN]
Definition: save.h:620
void SaveSpecies(FILE *ioPUN, long int ipPun)
Definition: save_species.cpp:35
string chSpeciesDominantRates[LIMPUN]
Definition: save.h:616
bool lgioRecom
Definition: save.h:594
const char * chConSavEnr[LIMPUN]
Definition: save.h:517
Definition: transition.h:23
void SaveSpeciesPseudoCont(const long ipPun, const string &speciesLabel)
Definition: species_pseudo_cont.cpp:396
vector< string > chSaveSpecies[LIMPUN]
Definition: save.h:497
void addImagePop_FITS(const string &species, const long iteration, const long nzone, const long numLevels, const valarray< double > &pop, bool haveNegPop=false)
Definition: save.cpp:154
void save_average(long int ipPun)
Definition: save_average.cpp:128
bool lgTraceConvergeBaseHash
Definition: save.h:588
bool lgPunConv_noclobber
Definition: save.h:404
bool lgSubtrCont
Definition: save.h:424
bool lgSaveDataWn
Definition: save.h:624
void SetSaveHeaderNeeded(bool lgVal)
Definition: save.h:462
FILE * ipDRout
Definition: save.h:576
realnum Resolution
Definition: save.h:611
string chRedirectPrefix
Definition: save.h:547
Energy emisfreq[LIMPUN]
Definition: save.h:619
Definition: species.h:11
string set_basename(const string &species, const long iteration, const long nzone, bool haveNegPop=false)
Definition: save.cpp:17
bool lgSaveHeader(int ipPun) const
Definition: save.h:472
bool lgSaveToSeparateFiles[LIMPUN]
Definition: save.h:442
long int ipConPun
Definition: save.h:520
void mole_print_species_reactions(molecule *speciesToPrint)
Definition: save_species.cpp:743
bool matchIteration(const long this_iteration) const
Definition: save.h:247
long nLineList[LIMPUN]
Definition: save.h:372
char chSave[LIMPUN][5]
Definition: save.h:433
void PrintLineDataHeader(FILE *ioPUN)
Definition: save_linedata.cpp:246
FILE * ipDTout
Definition: save.h:582
bool lgPunchFits
Definition: save.h:514
vector< adjPseudoCont > setPseudoCont
Definition: save.h:628
string speciesLabel
Definition: save.h:225
bool lgDROn_noclobber
Definition: save.h:405
vector< string > chFileName
Definition: save.h:392
void Save1Line(const TransitionProxy &t, FILE *io, realnum xLimit, long index, realnum DopplerWidth)
Definition: save_do.cpp:3886
bool p_lgSaveHeaderDone[LIMPUN]
Definition: save.h:455