function [colname,data] = read_argotxt_write_mat(input_dir,filename,output_dir); % Read argo index text files and saves data into two structures % colname has the column names % data is a structure of length == number of columns, % fieldnames are the column names in colname % all values are strings except for latitude and longitude filename fid = fopen([input_dir,filename,'.txt']); %'Used to have a .txt cat-ed on % Parse header %#callSign,data_URL,file,ocean,date,time,time_qc,latitude,longitude,position_qc,data_center,data_mode,num_of_levels,min_D_P,max_D_P,num_of_param,param1,param2,param3,param4,param5,param6 fline = fgetl(fid); hdr = fline; colname = parse_csvline(hdr(2:end)); numcol = length(colname); whos colname ldo=0; fline = fgetl(fid); while length(fline)>1 ldo=ldo+1; coldata = parse_csvline(fline); if length(coldata)>length(colname) colname(length(coldata)).data='paramX'; end for cdo=1:length(coldata) dat1 = coldata(cdo).data; fieldname = colname(cdo).data; if (fieldname(1:3)=='lat')|(fieldname(1:3)=='lon') eval(['data(ldo).',fieldname,'=str2num(dat1);']); else eval(['data(ldo).',fieldname,'=dat1;']); end end fline=fgetl(fid); end fclose(fid); eval(['save ',output_dir,filename,'.mat colname data']);