| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-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: [email protected] |
| 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 |
|
| 30 |
.VERSION |
| 31 |
090819 last modif |
| 32 |
|
| 33 |
*/ |
| 34 |
|
| 35 |
#include <stdlib.h> |
| 36 |
#include <stdio.h> |
| 37 |
#include <midas_def.h> |
| 38 |
#include <osfile.h> |
| 39 |
#include <gl_defs.h> |
| 40 |
#include <spec_comm.h> |
| 41 |
|
| 42 |
#define MAXFILES 100 |
| 43 |
|
| 44 |
#define CREA_IN_ICAT_PRG "tmp_crea_in_icat.prg" |
| 45 |
#define CREA_IN_ICAT "@@ tmp_crea_in_icat" |
| 46 |
#define TMP_IN_CAT "tmp_in.cat" |
| 47 |
|
| 48 |
#define CREA_IN_ICAT_INST "crea/icat tmp_in null\n" |
| 49 |
|
| 50 |
extern int AppendDialogText(); |
| 51 |
|
| 52 |
extern void DropTrailingBlanks(); |
| 53 |
|
| 54 |
|
| 55 |
void GetNameInputCatalog(); |
| 56 |
|
| 57 |
void ExecuteReduce() |
| 58 |
{ |
| 59 |
char command[MAXLINE]; |
| 60 |
char in_cat[MAXLINE]; |
| 61 |
|
| 62 |
GetNameInputCatalog(in_cat); |
| 63 |
sprintf(command, "%s%s", C_REDUCE, in_cat); |
| 64 |
AppendDialogText(command); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/********************************************************************* |
| 69 |
|
| 70 |
Input catalog management |
| 71 |
|
| 72 |
*********************************************************************/ |
| 73 |
|
| 74 |
static char InputCatalog[MAXLINE]; |
| 75 |
|
| 76 |
void GetNameInputCatalog( catalog ) |
| 77 |
char *catalog; |
| 78 |
{ |
| 79 |
strcpy(catalog, InputCatalog); |
| 80 |
} |
| 81 |
|
| 82 |
void CreateInputCatalog( tx_in_prefix, tx_in_numbers ) |
| 83 |
char *tx_in_prefix, *tx_in_numbers; |
| 84 |
{ |
| 85 |
char *delim = " ,"; |
| 86 |
char *token; |
| 87 |
char buf[MAXLINE], files[MAXLINE]; |
| 88 |
int inlist[MAXFILES]; |
| 89 |
int i, n_inlist = 0; |
| 90 |
int begin, end; |
| 91 |
int inlist_fp; |
| 92 |
char *strtok(); |
| 93 |
|
| 94 |
token = (char *)malloc((size_t)(sizeof(char) * MAXLINE)); |
| 95 |
|
| 96 |
DropTrailingBlanks(tx_in_prefix); |
| 97 |
DropTrailingBlanks(tx_in_numbers); |
| 98 |
|
| 99 |
/* if field = null ==> prefix field is considered to be the input catalog */ |
| 100 |
if ( tx_in_numbers[0] == '\0' ) |
| 101 |
strcpy(InputCatalog, tx_in_prefix); |
| 102 |
else { |
| 103 |
/* generate the file numbers list */ |
| 104 |
strcpy(files, tx_in_numbers); |
| 105 |
token = strtok(files, delim); |
| 106 |
while ( token != NULL ) { |
| 107 |
if ( sscanf(token, "%d-%d", &begin, &end) == 2 ) |
| 108 |
for ( i = begin; i <= end && n_inlist < MAXFILES; i++ ) |
| 109 |
inlist[n_inlist++] = i; |
| 110 |
else if ( sscanf(token, "%d", &begin) == 1 ) |
| 111 |
inlist[n_inlist++] = begin; |
| 112 |
token = strtok((char *)NULL, delim); |
| 113 |
} |
| 114 |
/* generate the catalog */ |
| 115 |
strcpy(InputCatalog, TMP_IN_CAT); |
| 116 |
inlist_fp = osaopen(CREA_IN_ICAT_PRG, WRITE); |
| 117 |
sprintf(buf, "%s", CREA_IN_ICAT_INST); |
| 118 |
osawrite(inlist_fp, buf, strlen(buf)); |
| 119 |
for ( i = 0; i < n_inlist; i++ ) { |
| 120 |
sprintf(buf, "add/icat %s %s%04d\n", InputCatalog, |
| 121 |
tx_in_prefix, inlist[i]); |
| 122 |
osawrite(inlist_fp, buf, strlen(buf)); |
| 123 |
} |
| 124 |
osaclose(inlist_fp); |
| 125 |
AppendDialogText(CREA_IN_ICAT); |
| 126 |
unlink(CREA_IN_ICAT_PRG); |
| 127 |
} |
| 128 |
} |