1 /***************************************************************************
2 * This File is a part of the CADS/UV Stellar Spectrum model software *
3 * Copyright (C) 2012 by CADS/UV Software Team, *
4 * Indian Institute of Astrophysics *
5 * Bangalore 560034 *
6 * cads_AT_iiap.res.in *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
24 /*--------------------------------------------------------------------------
25 File : mag2flux.c
26 Author : Sujatha N V
27 Date : 12th August, 2004
28 Version : 1.0
30 Program Description:
31 This program reads sp_type, magnitude & E(B-V) from an input
32 parameter file & compares the spectral type in the TABLE in file :
33 MKSpTypewwww.in. Selects the corresponding KURUCZ flux file
34 coresponding to Temp. T and gravity g of the sp. type. Then
35 calculate scale value for Kurucz flux and calculate the flux at
36 Earth for different wavelengths read from 'wave.dat'
37 output file contains: Wavelength, Flux at Earth F(lambda)
39 ---------------------------------------------------------------------------*/
41 /*--------------------------------------------------------------------------
42 Rivision : Author, dd/mm/yyyy
43 Revision history : -----
45 Reks, 12th July, 2005.
46 1. Introduced signal handling (signal_handling.c and fun_prototypes.h)
47 2. Modified all printf for error messages to fprintf->STDERR
48 Those two modifications are a must to be able to run this on web...
50 Fayaz, Sept., 2005.
51 1. Added UVS_msgs.c, to print error messages (supersedes #2 in previous
52 revision) and other fancy things like a prologue() before starting.
54 Reks, 08th Dec. 2005
55 1. Can take care of comments in input parameter file.
57 Reks, 07th July, 2007
58 1. configure-make
59 2. renamed project to mag2counts
60 3. renamed file to mag2flux
61 4. Better error messages and overall readability
62 5. moved all functions into kurucz_functions.c
64 JM: 10 July, 2007
65 1. Corrected several memory leaks in text handling
67 JM: 15 July, 2007
68 1. Cleaned up code in main program; moved parameter reading etc to functions.
69 (Still have to go through other functions.)
71 Reks: 21 July, 2007
72 1. Removed SPDATA_FROOT from paramfile.
73 2. SPDATA_DIR now points to the top level directory that contain all data
74 files, subdirectories KURUCZ_FLUX and MkSpDATA
75 3. shifted wave.dat and crossec0.dat into SPDATA_DIR (default location)
76 experienced users may over-ride this from parameter file.
77 4. added command line options to create default paramfile and help message
78 5. Still have to fix the memory leak problems with sptype inside GET_REF1!
80 JM: 21 July, 2007
81 1. fixed all memory leaks!
83 Reks: 01 July 2012:
84 1. Rebranded to CADS/UVS, reset version to 1.0 in new cads git repository
85 2. Renamed to stellar_spectrum
86 3. read/write ops shifted to read_write.c
88 Reks: 12 Aug 2012: v1.01
89 1. New option to specify the parameter filename - this was needed to run
90 multiple instances of stellar_spectrum in a folder (cads uvsky simulation)
91 ----------------------------------------------------------------------------*/
93 #include "stellar_spectrum.h"
94 #include <sys/types.h>
96 char *optarg;
97 int optindex;
99 /* Main program starts here*/
100 /****************************************************************************/
101 int main (int argc, char *argv[])
102 {
104 FILE *out_ptr = NULL, *wave_ptr = NULL;
105 struct STARS stars;
106 struct S_TABLE mkstTG;
107 int gr = 0, tst;
108 char OutFile[MAX_TEXT];
109 char ParamFile[80];
110 int c; /* For getopt */
112 /* Before we begin... set the signals and print a banner */
113 set_signals();
114 PRINT_BANNER();
116 strcpy(ParamFile, paramfile);/*paramfile is defined in header file*/
118 /* Command line options*/
119 while ( (c = my_getopt (argc, argv, "p:gh") ) != EOF)
120 switch (c)
121 {
122 case 'g':
123 gen_stspec_params(ParamFile);
124 return(EXIT_SUCCESS);
125 break;
126 case 'p':
127 strcpy(ParamFile, optarg);
128 break;
129 case 'h':
130 usage();
131 break;
132 default:
133 usage();
134 break;
135 }
137 /* Open and read the parameter file */
138 READ_PARAMS(ParamFile, &stars, OutFile);
139 /* try opening the wave file */
140 if ((wave_ptr = fopen(stars.WaveFile,"r")) == NULL)
141 {
142 fprintf(stderr, "ERROR : Unable to open file %s\n", stars.WaveFile);
143 exit(EXIT_FAILURE);
144 }
145 /*Output file*/
146 if ((out_ptr = fopen(OutFile, "w")) == NULL)
147 {
148 fprintf(stderr, "ERROR: Unable to write to file %s\n", OutFile);
149 exit(EXIT_FAILURE);
150 }
152 WRITE_INFO(out_ptr, stars);/*Writes program information to file*/
154 /* for all wavelengths listed in this file */
155 while ((feof(wave_ptr))==0)
156 {
158 tst = GET_WAVE_NAME(wave_ptr, stars.dir_root, &mkstTG);
159 if (tst == EXIT_SUCCESS)
160 {
162 /* Read the wavelength file*/
163 printf("\rWorking: |");
164 READ_TABLE(&mkstTG);
166 /* get the crossection */
167 printf("\rWorking: /");
168 RCross_Sec(&stars, mkstTG.w_filename);
170 /*Reads ISM Absorption CrosSection*/
171 printf("\rWorking: -");
172 gr = GET_REF1(&stars, &mkstTG);
174 printf("\rWorking: \\");
175 if (gr == 0)
176 {
177 ALPHA(&stars);
178 if (stars.alpha != 0.0) WRITE_LINE(out_ptr, &stars);
179 }
181 }/*End tst*/
182 } /* end of while loop */
183 printf("\rInfo : Done\n");
184 fclose(wave_ptr);
185 fclose(out_ptr);
187 return(EXIT_SUCCESS);
188 }