~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to gui/XIrspec/src/file.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1993-2009 European Southern Observatory (ESO)
 
3
 
 
4
  This program is free software; you can redistribute it and/or 
 
5
  modify it under the terms of the GNU General Public License as 
 
6
  published by the Free Software Foundation; either version 2 of 
 
7
  the License, or (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public 
 
15
  License along with this program; if not, write to the Free 
 
16
  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, 
 
17
  MA 02139, USA.
 
18
 
 
19
  Correspondence concerning ESO-MIDAS should be addressed as follows:
 
20
        Internet e-mail: midas@eso.org
 
21
        Postal address: European Southern Observatory
 
22
                        Data Management Division 
 
23
                        Karl-Schwarzschild-Strasse 2
 
24
                        D 85748 Garching bei Muenchen 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
29
/* .IDENT       file.c                                     */
 
30
/* .AUTHORS     Cristian Levin   (ESO/La Silla)            */
 
31
/* .KEYWORDS    XIrspec                                    */
 
32
/* .PURPOSE                                                */
 
33
/* .VERSION     1.0  Package Creation  27-OCT-1993         
 
34
 
 
35
    090828      last modif
 
36
   ------------------------------------------------------- */
 
37
 
 
38
#include <stdlib.h>
 
39
#include <stdio.h>
 
40
#include <string.h>
 
41
 
 
42
#include <gl_defs.h>
 
43
#include <irspec_defs.h>
 
44
 
 
45
#include <midas_def.h>
 
46
 
 
47
 
 
48
void IrspecSave( file, obj, sky, ststar, stsky, dark, flat )
 
49
char *file;
 
50
char *obj, *sky, *ststar, *stsky, *dark, *flat;
 
51
{
 
52
    FILE *fp;
 
53
    int i;
 
54
 
 
55
    for ( i = 0; file[i] != '\0'; i++ )
 
56
        if ( file[i] == '.' ) {
 
57
            file[i] = '\0';
 
58
            break;
 
59
        }
 
60
 
 
61
    strcat(file, ".irs");
 
62
 
 
63
    if ( (fp = fopen(file, "w")) == NULL ) {
 
64
        SCTPUT("*** Error: file could not be opened ***");
 
65
        return;
 
66
    }
 
67
    fprintf(fp, "#\n# File generated by the Irspec graphical interface\n#\n");
 
68
    fprintf(fp, "object = %s\n", obj);
 
69
    fprintf(fp, "sky    = %s\n", sky);
 
70
    fprintf(fp, "ststar = %s\n", ststar);
 
71
    fprintf(fp, "stsky  = %s\n", stsky);
 
72
    fprintf(fp, "dark   = %s\n", dark);
 
73
    fprintf(fp, "flat   = %s\n", flat);
 
74
 
 
75
    fclose(fp);
 
76
}
 
77
 
 
78
void IrspecOpen( file )
 
79
char *file;
 
80
{
 
81
    FILE *fp;
 
82
    int i, j;
 
83
    char s[MAXLINE], str[MAXLINE], line[MAXLINE];
 
84
    char type[MAXLINE], name[MAXLINE];
 
85
 
 
86
    if ( (fp = fopen(file, "r")) == NULL ) {
 
87
        SCTPUT("*** Error: file could not be opened ***");
 
88
        return;
 
89
    }
 
90
 
 
91
    while ( fgets(s, MAXLINE, fp) != NULL ) {
 
92
        if ( s[0] == '#' )
 
93
            continue;
 
94
        for ( i = 0, j = 0; s[i] != '\0'; i++ )
 
95
            if ( s[i] == '=' ) {
 
96
                line[j++] = ' ';
 
97
                line[j++] = '=';
 
98
                line[j++] = ' ';
 
99
            }
 
100
            else
 
101
                line[j++] = s[i];
 
102
        line[j] = '\0';
 
103
        
 
104
        sscanf(line, "%s = %s", type, name);
 
105
        if ( ! strcmp(type, "object") )
 
106
            strcpy(InObj, name);
 
107
        else if ( ! strcmp(type, "sky") )
 
108
            strcpy(InSky, name);
 
109
        else if ( ! strcmp(type, "ststar") )
 
110
            strcpy(InStstar, name);
 
111
        else if ( ! strcmp(type, "stsky") )
 
112
            strcpy(InStsky, name);
 
113
        else if ( ! strcmp(type, "dark") )
 
114
            strcpy(Dark, name);
 
115
        else if ( ! strcmp(type, "flat") )
 
116
            strcpy(Flat, name);
 
117
        else {
 
118
            sprintf(str, "*** line [%s] discarded ***", s);
 
119
            SCTPUT(str);
 
120
        }
 
121
    }
 
122
    fclose(fp);
 
123
}