X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 28 Oct 2013 11:49 AM by  anon
Read binary files in a loop
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
28 Oct 2013 11:49 AM
    Hi, I am a new IDL user. For the purposes of my work I need to read a large number of binary files in a loop and then save them as ascii files. I was hoping you could help me with that. The program that I am using can only read one file at a time 'fpname' and then spit out 4 output variables on the screen: swdnsrf,lwdnsrf,swupsrf,lwupsrf. To execute the code I run the command: read_fluxes, './app_n025_2011350_1400.SurfFluxes',swdnsrf, lwdnsrf, swupsrf, lwupsrf where ' app_n025_2011350_1400.SurfFluxes' is the file that I am trying to read, and swdnsrf, lwdnsrf, swupsrf, lwupsrf are the variables coming from that file. Now, I need to modify the code so it would read the whole cluster of files for other time steps "j", where j goes from 001,350 app_n025_2011"j"_1400.SurfFluxes Could you please look at my program below that works for reading one file and writing 4 variables on the screen and suggest how it needs to be modified to output ascii files and read many files in a do loop? Thanks pro read_fluxes, fpname, swdnsrf,lwdnsrf,swupsrf,lwupsrf ; Input: ; fpname: Input file full path name, string, e.g. 'app_n025_2011161_1400.SurfFluxes'. ; ; Output: ; swdnsrf: Downwelling shortwave radiation at the surface (W/m^2) ; lwdnsrf: Downwelling longwave radiation at the surface (W/m^2) ; swupsrf: Upwelling shortwave radiation at the surface (W/m^2) ; lwupsrf: Upwelling longwave radiation at the surface (W/m^2) ; openr, uin, fpname, /get_lun ncols= fix(0) nrows=fix(0) readu,uin,ncols, nrows swdnsrf = fltarr(ncols,nrows) lwdnsrf = fltarr(ncols,nrows) swupsrf = fltarr(ncols,nrows) lwupsrf = fltarr(ncols,nrows) readu,uin,swdnsrf readu,uin,lwdnsrf readu,uin,swupsrf readu,uin,lwupsrf close,uin & free_lun,uin end

    Deleted User



    New Member


    Posts:
    New Member


    --
    29 Oct 2013 12:04 PM
    Hi Alex, What you will need to do is to use the STRING functions available in IDL to change indexes of files (the 001, to 350) into strings. I think something like this: nfile=350 firstfile=001 for nimg=0, nfile-1 do begin fpname= './app_n025_2011' + STRTRIM(string(firstfile), 2) + '_1400.SurfFluxes' read_fluxes, fpname firstfile = firstfile + 1 endfor Something like that. I think it should work. So, the string() function will conver the numbers from 001 to 350 into string. Then STRTRIM will remove the leading a trailing spaces (hence the number 2 parameter) Let me know what you think. Cheers! fernando

    Deleted User



    New Member


    Posts:
    New Member


    --
    29 Oct 2013 05:03 PM
    Thank you for your suggestion. I was able successfully read all the files, but I also need to write out netcdf or ascii files so I can visually look at them. Each binary file has 4 variables: swdnsrf,lwdnsrf,swupsrf,lwupsrf I need to write out each of the variables in a separate ascii files: one for swdnsrf, one for lwdnsrf, one for swupsrf, one for lwupsrf. Do you know how to do that in IDL? Thank you.

    Berangere Casson



    New Member


    Posts:61
    New Member


    --
    31 Oct 2013 03:09 AM
    You will find an example of how writing NCDF files at the following link: http://www.exelisvis.com/docs/NCDF_VA...
    You are not authorized to post a reply.