2adf54fc95671a1a31ec33e13710d3676073bb14
1 /***************************************************************************
2 * This File is a part of the CADS/UV Zodiacal light 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 #include "zodiacal_model.h"
26 void ZOD_DIST_READ(float *arr, float *hecl_lon, float *hecl_lat,
27 char *zod_file)
28 {
29 FILE *ZODIAC=NULL;
30 int ix, iy;
31 float f_tmp;
32 char s_tmp[FLEN_FILENAME];
34 if ((ZODIAC = fopen(zod_file, "r")) == NULL)
35 {
36 fprintf(stderr, "ERROR : Unable to open Zodiacal light file %s \n",
37 zod_file);
38 exit(EXIT_FAILURE);
39 }/*Open zodiacal light file if it exists*/
41 fgets(s_tmp, FLEN_FILENAME, ZODIAC);
42 fgets(s_tmp, FLEN_FILENAME, ZODIAC);
44 fscanf(ZODIAC, "%f", &f_tmp); /* Dummy read of first element */
45 for (iy = 0; iy < ZOD_YSIZE; ++iy)
46 { /* Now read the remaining latitudes */
47 fscanf(ZODIAC, "%f", &f_tmp);
48 *(hecl_lat + iy) = f_tmp;
49 }
51 for (ix = 0; ix < ZOD_XSIZE; ++ix)
52 {
53 fscanf(ZODIAC, "%f", &f_tmp);
54 *(hecl_lon + ix) = f_tmp;
55 for (iy = 0; iy < ZOD_YSIZE; ++iy)
56 {
57 fscanf(ZODIAC, "%f", &f_tmp);
58 *(arr + ix + iy*ZOD_XSIZE) = f_tmp;
59 }
60 }/*Read over zodiacal file*/
62 fclose(ZODIAC);
63 }/*End ZOD_DIST*/
64 /*********************************************************************/
66 void ZOD_SPECT_READ(float *wave, float *spec, int *ndat, char *spec_file)
67 {
68 FILE *SPECTRUM = NULL;
69 int ispec = 0;
70 char s_tmp[FLEN_FILENAME], s_tmp1[FLEN_FILENAME], s_tmp2[FLEN_FILENAME];
72 if ((SPECTRUM = fopen(spec_file, "r")) == NULL)
73 {
74 fprintf(stderr, "ERROR : Unable to open spectrum file %s \n",
75 spec_file);
76 exit(EXIT_FAILURE);
77 }/*Open zodiacal spectrum if it is exists*/
79 while (!feof(SPECTRUM))
80 {
81 fgets(s_tmp, FLEN_FILENAME, SPECTRUM);
82 if((s_tmp[0] != '#') && (s_tmp[0] != '\n'))
83 {
84 sscanf(s_tmp, "%s %s", s_tmp1, s_tmp2);
85 *(wave + ispec) = atof(s_tmp1);
86 *(spec + ispec) = atof(s_tmp2);
87 ispec++;
88 }
89 }
90 fclose(SPECTRUM);
91 ispec -= 1;
92 *ndat = ispec;
93 }/*END ZOD_SPECT*/
94 /*********************************************************************/
96 void gen_default_params()
97 {
99 FILE *fparam = NULL;
100 usage();
101 printf("Info : Creating default parameter file %s\n", PARAM_FILE);
103 fparam = fopen(PARAM_FILE, "w");
104 if (fparam == NULL)
105 {
106 fprintf(stderr, "ERROR : Unable to create %s\n", PARAM_FILE);
107 exit(EXIT_FAILURE);
108 }
110 fprintf(fparam,
111 "#-----------------------------------------------------#\n"
112 "# Parameter FILE for UVS Zodiacal light model \n"
113 "# \n"
114 "# Purpose: Input parameters for running the Zodiacal \n"
115 "# light modelling software will be read from \n"
116 "# this file. \n"
117 );
119 fprintf(fparam,
120 "# NOTE: Any line beginning with a hash (\"#\") or \n"
121 "# those enclosed within \"/* -- */ \" are \n"
122 "# comments and will be ignored by the software\n"
123 "# \n"
124 "# format of this file is: KEY = VALUE \n"
125 "# value is expected to be float/string \n"
126 "# \n"
127 "#-----------------------------------------------------#\n\n"
128 );
130 fprintf(fparam,
131 "# TIME & DATE Information:\n"
132 "# -----------------------\n"
133 "# 1. Time of the day (UT, hours. range: 0.0 - 24.0)\n"
134 "TIME_UT = 12.00\n\n"
135 "# 2. Day of the month (unitless, range: 0 - 31 (or 28/29/30))\n"
136 "DAY_OF_MONTH = 21\n\n"
137 "# 3. Month of the year (unitless, range: 1 - 12) \n"
138 "MONTH = 12\n\n"
139 "# 4. Year (unitless, range: 1900 - 2100 for max. accuracy) \n"
140 "YEAR = 2012\n\n\n"
141 );
143 fprintf(fparam,
144 "# COORDINATE Information:\n"
145 "# -----------------------\n"
146 "# 1. RA (deg. range: 0.0 - 360.0)\n"
147 "RA = 266.50\n\n"
148 "# 2. Declination (deg. range: -90 - +90)\n"
149 "DECLINATION = -29.0\n\n\n"
150 );
152 /*The files */
153 fprintf(fparam,
154 "# OUTPUT FILE:\n"
155 "# -----------------------\n"
156 "# The calculated spectrum is written to this file. \n"
157 "OUTPUT_FILE = zodiacal_output.txt\n\n\n"
158 );
160 fprintf(fparam,
161 "# ZODIACAL SPECTRUM FILE:\n"
162 "# -----------------------\n"
163 "# zodiacal light spectrum is read from this file. \n"
164 "# Data is based on the solar spectrum from Colina et al\n"
165 "ZODIAC_SPECTRUM = %szodiacal_spec.txt\n\n", CADSDATA
166 );
168 fprintf(fparam,
169 "# ZODIACAL LIGHT MODEL FILE:\n"
170 "# --------------------------\n"
171 "# zodiacal light distribution data (Leinert et al.) \n"
172 "ZODIAC_MODEL = %sleinert_dist.txt\n\n", CADSDATA
173 );
175 fprintf(fparam,
176 "# --------------------------\n"
177 "#\n"
178 );
180 printf("Info : Default Parameter file has been generated.\n");
181 fclose(fparam);
183 }/* END GEN_DEFAULT_PARAMS */
184 /*********************************************************************/
186 int READ_PARAMS(float *hour, int *day, int *month, int *year,
187 float *ra, float *dec,
188 char *zod_file, char *spec_file, char *out_file)
189 {
191 FILE *fp;
192 char line[MAX_TEXT], name[MAX_TEXT], equal[MAX_TEXT], data[MAX_TEXT];
194 if ((fp = fopen(PARAM_FILE,"r")) == NULL)
195 {
196 gen_default_params();
197 if ((fp = fopen(PARAM_FILE,"r")) == NULL) exit(EXIT_FAILURE);
198 }
200 /* Read input parameters */
201 while (!feof(fp))
202 {
203 if (fgets(line, MAX_TEXT, fp) != NULL);
204 if ((line[0] != '#') && (line[0] != '\n'))
205 {
206 sscanf(line, "%s %s %s ", name, equal, data);
207 if (!strcmp("TIME_UT", name)) *hour = atof(data);
208 if (!strcmp("DAY_OF_MONTH", name)) *day = atoi(data);
209 if (!strcmp("MONTH", name)) *month = atoi(data);
210 if (!strcmp("YEAR", name)) *year = atoi(data);
211 if (!strcmp("RA", name)) *ra = atof(data);
212 if (!strcmp("DECLINATION", name)) *dec = atof(data);
213 if (!strcmp("OUTPUT_FILE", name)) strcpy(out_file, data);
214 if (!strcmp("ZODIAC_MODEL", name)) strcpy(zod_file, data);
215 if (!strcmp("ZODIAC_SPECTRUM", name)) strcpy(spec_file, data);
216 strcpy(line, "End of File");
217 /* This is to take care of the end of file */
218 }
219 }
220 fclose(fp);
221 }/* END READ_PARAMS */
222 /*********************************************************************/