;+ ; ; ================ ; file_prn2mem.pro ; ================ ; ; .. function:: file_prn2mem(filename) ; ; Read in situ MLD files and store data in a structure ; ; nb : mld float to handle NaN in file ; ++ NaN dans les colonnes entier transformés en 0 par la lecture ; ; :param filename: filename to be read ; :type filename: string ; :raise filename: required ; ; :returns: data structure +todo+ details or -1 if error ; :rtype: structure +todo+ details ; ; :examples: ; ; .. code-block:: idl ; ; filename='/usr/temp/marina/POM/mld_prieur_P1L1.prn' ; result = file_prn2mem(filename) ; ; filename='/usr/temp/marina/POM/mld_prieur_P1L2_tot.prn' ; result = file_prn2mem(filename) ; ; filename='/usr/temp/marina/POM/mld_prieur_P2L1.prn' ; result = file_prn2mem(filename) ; ; filename='/usr/temp/marina/POM/mld_prieur_P2L2.prn' ; result = file_prn2mem(filename) ; ; filename='/usr/temp/marina/POM/mld_prieur_P1L2_tot.prn' ; result = file_prn2mem(filename) ; ; impression de contrôle : 1re station, toutes les stations: ; ; .. code-block:: idl ; ; help, result, /structure ; print, result[0].station ; print, result.station ; print, result[0].zhomelch ; print, result[nrows - 1].zhomelch ; ; :uses: ; ; :func:`report ` ; ; :see also: ; ; :func:`file_prn_to_mem` ; ; :restrictions: ; ; :todo: ; ; format fixe ; ; test existence of filename ; ; :history: ; ; - fplod 20101123T134447Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * creation using "Reading Into a Structure" of ; http://www.dfanning.com/tips/ascii_column_data.html ; ; :version: ; ; $Id$ ; ;- FUNCTION file_prn2mem, filename ; compile_opt idl2, strictarrsubs ; ; Return to caller if errors ON_ERROR, 2 ; usage = 'result = file_prn2mem(filename) ; nparam = N_PARAMS() IF (nparam LT 1) THEN BEGIN ras = report(['Incorrect number of arguments.' $ + '!C' $ + 'Usage : ' + usage]) return, -1 ENDIF ; arg_type = size(filename,/type) IF (arg_type NE 7) THEN BEGIN ras = report(['Incorrect arg type filename' $ + '!C' $ + 'Usage : ' + usage]) return, -1 ENDIF ; arg_dim = size(filename,/n_elements) IF (arg_dim LT 1) THEN BEGIN ras = report(['Incorrect arg dimension filename' $ + '!C' $ + 'Usage : ' + usage]) return, -1 ENDIF ; ; initialize header header = STRARR(3) ; resultstruct = { station: 0L $ , doy: 0.0 $ , zm: 0L $ , fluo: 0.0 $ , zfluo: 0.0 $ , fluosurfac: 0.0 $ , zhom001: 0.0 $ , zhom002 : 0.0 $ , zhom005 : 0.0 $ , zhom010: 0.0 $ , zhomelch : 0.0 $ } ; nrows = file_lines(filename) - N_ELEMENTS(header) result = Replicate(resultstruct, nrows) ; ; open file OPENR, lun, filename, /GET_LUN ;++ handle error ; ; read header READF, lun, header ; ; read data lines READF, lun, result ; ; close file FREE_LUN, lun ; return, result ; END