00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <sed/sed_sedflux.h>
00025
00026 #define VAL_NOT_GIVEN (G_MINDOUBLE)
00027
00028 #define THIS_IS_OBSOLETE
00029
00030 int main(int argc, char *argv[])
00031 {
00032 #if !defined( THIS_IS_OBSOLETE )
00033
00034 void doHelp(int);
00035 FILE *fpin, *fpout;
00036 char *infile, *outfile;
00037 int i;
00038 int rows, cols;
00039 double old_max, old_min, new_max, new_min;
00040 Profile_header *header;
00041 double scale, old_scale, new_scale, new_val;
00042 unsigned char *data;
00043 Eh_args *args;
00044
00045 args = eh_opts_init(argc,argv);
00046 if ( eh_check_opts( args , NULL , NULL , NULL )!=0 )
00047 eh_exit(-1);
00048
00049 new_min = eh_get_opt_dbl( args , "low" , VAL_NOT_GIVEN );
00050 new_max = eh_get_opt_dbl( args , "high" , VAL_NOT_GIVEN );
00051 infile = eh_get_opt_str( args , "in" , NULL );
00052 outfile = eh_get_opt_str( args , "out" , NULL );
00053
00054 if ( !infile )
00055 fpin = stdin;
00056 else
00057 if ( !(fpin=fopen(infile,"r")) )
00058 perror(infile), eh_exit(-1);
00059 if ( !outfile )
00060 fpout = stdout;
00061 else
00062 if ( !(fpout=fopen(outfile,"w")) )
00063 perror(outfile), eh_exit(-1);
00064
00065 fprintf(stderr,"Scaling data between %f and %f\n",new_min,new_max);
00066
00067
00068 header = sed_read_profile_header( fpin );
00069
00070 rows = header->n_rows;
00071 cols = header->n_cols;
00072 old_min = header->min_value;
00073 old_max = header->max_value;
00074
00075 if ( new_min==VAL_NOT_GIVEN )
00076 new_min = old_min;
00077 if ( new_max==VAL_NOT_GIVEN )
00078 new_max = old_max;
00079
00080 scale=(old_max-old_min)/(new_max-new_min);
00081 old_scale = (255-2)/(old_max-old_min);
00082 new_scale = (255-2)/(new_max-new_min);
00083
00084
00085 data = g_new(unsigned char , rows*cols );
00086 fread(data,sizeof(unsigned char),rows*cols,fpin);
00087
00088
00089 header->min_value=new_min;
00090 header->max_value=new_max;
00091 for (i=0;i<rows*cols;i++)
00092 {
00093 if ( !(data[i]==0 || data[i]==0xFF) )
00094 {
00095 new_val=(((data[i]-1)/old_scale+old_min)-new_min)*new_scale+1;
00096 if ( new_val > 0xFF ) new_val=0xFF;
00097 data[i]=(unsigned char)new_val;
00098 }
00099 }
00100
00101
00102 sed_print_profile_header( fpout , header );
00103
00104
00105 fwrite(data,sizeof(unsigned char),rows*cols,fpout);
00106
00107 fclose(fpin);
00108 fclose(fpout);
00109 #endif
00110
00111 return 0;
00112 }
00113
00114 #undef THIS_IS_OBSOLETE
00115
00116 void do_help(int verbose)
00117 {
00118
00119 fprintf(stderr,"Usage: sedrescale [help] [options] [parameters] [filein]\n");
00120
00121 if ( !verbose )
00122 return;
00123
00124 fprintf(stderr,"Options:\n");
00125 fprintf(stderr,"\t-o FILENAME -- Write ouput to the file, FILENAME. [ stdout ]\n");
00126 fprintf(stderr,"Parameters:\n");
00127 fprintf(stderr,"\tlow= -- Lower limit for scaling. [ 0 ]\n");
00128 fprintf(stderr,"\thigh= -- Upper limit for scaling. [ 1 ]\n");
00129 fprintf(stderr,"Input Files:\n");
00130 fprintf(stderr,"\tfilein -- File of sedflux output data. [ stdin ]\n");
00131
00132 return;
00133
00134 }