00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00035
00036
00037
00038
00039 #include <xsh_dfs.h>
00040 #include <xsh_error.h>
00041 #include <xsh_msg.h>
00042 #include <cpl.h>
00043 #include <string.h>
00044 #include <time.h>
00045 #include <xsh_utils_table.h>
00046 #include <xsh_data_atmos_ext.h>
00047
00048
00049
00050
00051
00052
00053
00054
00055 xsh_atmos_ext_list * xsh_atmos_ext_list_create( int size )
00056 {
00057 xsh_atmos_ext_list * result = NULL ;
00058
00059
00060 XSH_CALLOC( result, xsh_atmos_ext_list, 1 ) ;
00061 result->size = size ;
00062 XSH_CALLOC( result->lambda, double, size ) ;
00063 XSH_CALLOC( result->K, double, size ) ;
00064
00065 cleanup:
00066 return result ;
00067 }
00068
00069 cpl_error_code
00070 xsh_atmos_ext_dump_ascii( xsh_atmos_ext_list * list, const char* filename )
00071 {
00072 FILE * fout ;
00073 int size=0;
00074 int i=0;
00075 double * plambda=NULL;
00076 double * pK=NULL;
00077
00078 XSH_ASSURE_NOT_NULL_MSG(list,"Null input atmospheric ext frame list!Exit");
00079 size=list->size;
00080
00081 plambda = list->lambda ;
00082 pK = list->K ;
00083
00084 if((fout=fopen(filename,"w"))==NULL) {
00085
00086 return CPL_ERROR_FILE_IO ;
00087 } else {
00088 for(i=0;i<size;i++) {
00089 fprintf(fout, "%f %f \n", plambda[i], pK[i]);
00090 }
00091 }
00092 if ( fout ) fclose( fout ) ;
00093
00094 cleanup:
00095 return cpl_error_get_code() ;
00096 }
00097
00098
00099 xsh_atmos_ext_list * xsh_atmos_ext_list_load( cpl_frame * ext_frame )
00100 {
00101 cpl_table *table = NULL ;
00102 const char * tablename = NULL ;
00103 xsh_atmos_ext_list * result = NULL ;
00104 int nentries, i ;
00105 double * plambda, * pK ;
00106
00107
00108 XSH_ASSURE_NOT_NULL( ext_frame);
00109
00110
00111 check(tablename = cpl_frame_get_filename( ext_frame ));
00112
00113
00114 XSH_TABLE_LOAD( table, tablename ) ;
00115 check( nentries = cpl_table_get_nrow( table ) ) ;
00116
00117
00118 check( result = xsh_atmos_ext_list_create( nentries ) ) ;
00119
00120 plambda = result->lambda ;
00121 pK = result->K ;
00122 if(!cpl_table_has_column(table,XSH_ATMOS_EXT_LIST_COLNAME_K)){
00123 xsh_msg_warning("You are using an obsolete atm extinction line table");
00124 cpl_table_duplicate_column(table,XSH_ATMOS_EXT_LIST_COLNAME_K,
00125 table,XSH_ATMOS_EXT_LIST_COLNAME_OLD);
00126 }
00127
00128 for( i = 0 ; i< nentries ; i++, plambda++, pK++ ) {
00129 float value ;
00130
00131 check( xsh_get_table_value( table, XSH_ATMOS_EXT_LIST_COLNAME_WAVELENGTH,
00132 CPL_TYPE_FLOAT, i, &value ) ) ;
00133 *plambda = value ;
00134 check( xsh_get_table_value( table, XSH_ATMOS_EXT_LIST_COLNAME_K,
00135 CPL_TYPE_FLOAT, i, &value ) ) ;
00136 *pK = value ;
00137 }
00138
00139 cleanup:
00140 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00141 xsh_error_msg("can't load frame %s",cpl_frame_get_filename(ext_frame));
00142 xsh_atmos_ext_list_free(&result);
00143 }
00144 XSH_TABLE_FREE( table);
00145 return result ;
00146 }
00147
00148
00149 void xsh_atmos_ext_list_free( xsh_atmos_ext_list ** list )
00150 {
00151 if ( list != NULL && *list != NULL ) {
00152 check( cpl_free( (*list)->lambda ) ) ;
00153 check( cpl_free( (*list)->K ) ) ;
00154 check( cpl_free( *list ) ) ;
00155 *list = NULL ;
00156 }
00157
00158 cleanup:
00159 return ;
00160 }
00161
00162 double * xsh_atmos_ext_list_get_lambda( xsh_atmos_ext_list * list )
00163 {
00164 XSH_ASSURE_NOT_NULL( list ) ;
00165
00166 cleanup:
00167 return list->lambda ;
00168 }
00169
00170 double * xsh_atmos_ext_list_get_K( xsh_atmos_ext_list * list )
00171 {
00172 XSH_ASSURE_NOT_NULL( list ) ;
00173
00174 cleanup:
00175 return list->K ;
00176 }