%------------------------------------------------------------------------ % NAME: qpi_Kx % % Inline function to include calculation of the Kx matrix in % the control file. % % FORMAT: qpi_Kx( Q, fid ) % % OUT: - % IN: Q Setting structure % fid File identifier for the control file being created. %------------------------------------------------------------------------ % HISTORY: 2001.03.28 Created by Patrick Eriksson function qpi_Kx( Q, fid ) %=== Determine the length of x ================================================ % nx = 0; ni = 0; %= Species % nspecies = sstring_length( Q.RETRIEVAL_TAGS ); % for i = 1:nspecies name = sstring_get_i( Q.SPECIES_KGRIDS, i ); grid = read_datafile( [ Q.RETRIEVDEF_DIR, '/', name ], 'VECTOR'); nx = nx + length(grid); ni = ni + 1; end %= Temperature % if Q.TEMPERATURE_DO == 3 name = Q.TEMPERATURE_KGRID; grid = read_datafile( [ Q.RETRIEVDEF_DIR, '/', name ], 'VECTOR'); nx = nx + length(grid); ni = ni + 1; end %= Pointing % if Q.POINTING_DO == 3 nx = nx + 1; ni = ni + 1; end %= Continuum absorption % if Q.CONTABS_DO == 3 name = Q.CONTABS_KGRID; grid = read_datafile( [ Q.RETRIEVDEF_DIR, '/', name ], 'VECTOR'); nx = nx + length(grid)*(Q.CONTABS_ORDER+1); ni = ni + Q.CONTABS_ORDER + 1; end %=== Write to cfile =========================================================== %= Allocate memory for Kx % fprintf(fid, 'kxAllocate( y ){\n ni = %d\n nx = %d\n}\n', ni, nx ); %= Calculate the abs. LOS WFs fprintf(fid, 'absloswfsCalc{\n}\n'); %= Species for i = 1:nspecies name = [ Q.RETRIEVDEF_DIR, '/', sstring_get_i( Q.SPECIES_KGRIDS, i ) ]; fprintf(fid, 'VectorReadAscii( k_grid ) {\n "%s"\n}\n', name ); name = sstring_get_i( Q.RETRIEVAL_TAGS, i ); fprintf(fid, 'kSpeciesSingle{\n tg = "%s"\n unit = "frac"\n}\n', ... name); fprintf(fid, 'kxPutInK{\n}\n'); end %= Temperature if Q.TEMPERATURE_DO == 3 name = [ Q.RETRIEVDEF_DIR, '/', Q.TEMPERATURE_KGRID ]; fprintf(fid, 'VectorReadAscii( k_grid ) {\n "%s"\n}\n', name ); fprintf(fid, 'kTemp{\n hse = %d\n fast = 1\n}\n', Q.HSE_RETRIEVAL_ON); fprintf(fid, 'kxPutInK{\n}\n'); end %= Pointing % if Q.POINTING_DO == 3 fprintf(fid, 'kPointingOffSet{\n delta = %.2e\n}\n',Q.POINTING_DELTA); fprintf(fid, 'kxPutInK{\n}\n'); end %= Continuum absorption in primary band % if Q.CONTABS_DO == 3 if isempty( Q.CONTABS_LIMITS ) f_mono = read_datafile( [ Q.CALCGRIDS_DIR, '/', Q.F_MONO ], 'VECTOR'); lims = [f_mono(1), last(f_mono) ]; else lims = Q.CONTABS_LIMITS; end name = [ Q.RETRIEVDEF_DIR, '/', Q.CONTABS_KGRID ]; fprintf(fid, 'VectorReadAscii( k_grid ) {\n "%s"\n}\n', name ); fprintf(fid, 'kContAbs{\n'); fprintf(fid, ' order = %d\n', Q.CONTABS_ORDER ); fprintf(fid, ' f_low = %.6e\n', lims(1) ); fprintf(fid, ' f_high = %.6e\n}\n', lims(2) ); fprintf(fid, 'kxPutInK{\n}\n'); end %= Convert to RJ temperatures if emission observations % if Q.EMISSION_ON fprintf(fid, 'MatrixTRJ( kx, kx ) { \n}\n'); end %= Save kx and additional variables % fprintf(fid, 'MatrixWriteBinary( kx ) { \n""\n}\n'); fprintf(fid, 'ArrayOfIndexWriteBinary( kx_lengths ){ \n""\n}\n'); fprintf(fid, 'MatrixWriteBinary( kx_aux ){ \n""\n}\n'); fprintf(fid, 'ArrayOfStringWriteBinary( kx_names ){ \n""\n}\n');