!This program is used to convert the binary files to ordinary files. !CAUTION: ! (1)It is highly recommended that the folder, containing the ordinary files, should exist before ! running this program. The form for the two folders must be like ..\2000\rh\, so the *.tar.gz should be decompressed and converted into the folders like ..\2000\rh\. ! And each folder name should be terminated by seperator. ! For exmaple, if you decompressed the 2000t.tar.gz into the folder D:\decompress\forcing_field\2000\t\, ! and want to convert it and save the results in the folder D:\compress\forcing_field\2000\t, then the corresponding names of the folders should be: ! read_folder_ori="D:\decompress\forcing_field\" ! write_folder_ori="D:\compress\forcing_field\" ! (2)It is highly recommended that the user should assign the read_folder_ori, and write_folder_ori before running ! this program. If this recommendation is done, please delete the following corresponding part !Variable introduction: !-yrbegin : the very beginning year of your decompressed data !-yrend : the very last year of your decompressed data !-m : the variable to identify the month !-d : the variable to identify the day in the month !-hr : the variable to identify the hr in the day, namely 0,3,6,9,12,15,18,21 !-ferr : this is used to save the information of binary reading !-finaloutput : the varible to save the converted data !-seperator : the character used to seperate the different levels of folders as illustrated below !-file_yr : the variable to save the character form of the number of year !-file_hr : the variable to save the character form of the number of hr !-file_date : the variable to save the character form of date like 20080101 !-tag : the variable to save the type of climate varibles, like t( for temperature), p( for pressure) and so on !-read_folder_ori : the variable to save the folder, containing the binary files, and this must be the form as illustrated before !-write_folder_ori : the variable to save the folder, containing the converted files, and this must be the form as illustrated before !-read_folder : the variable to save the extension of the read_folder_ori. For example, if the read_folder_ori is D:\, then ! this one should be D:\2008\t\ !-write_folder : the variable to save the extension of the write_folder_ori. For example, if the write_folder_ori is D:\, then ! this one should be D:\2008\t\ !-file_name : the variable to save the name of the files like D:\2008\t\20080101_0hr_t.bin, and it is used for both the binary and converted files !-ind_folder : the variable used to save all of the logical results. program main USE DFLIB implicit none integer(kind=2) :: yrbegin,yrend,yr,m,d,hr,ferr integer(kind=4) :: date integer(kind=2) :: month(12) integer(kind=2) :: final(370210) real :: finaloutput(370210) character(len=1) :: seperator="\" !This is used to indentify the connector between different levels. For windows system, the ! seperator should be "\", but for linux, it should be "/" character(len=8) :: file_yr,file_date,file_hr,tag character(len=200) :: read_folder_ori,write_folder_ori,read_folder,write_folder,file_name logical :: ind_folder ! Please assign values to the following two variables if possible: !read_folder_ori= !write_folder_ori= !The following part is used to get the read_folder_ori and write_folder_ori from GUI. !If the values are assigned before running the program, please delete this part. write(*,*) "Please input the forder name, containing the binary files, like D:\forcing\" write(*,*) "(do not include the year in the file):" read(*,*) read_folder_ori write(*,*) "Please input the forder name you want to save the converted files" write(*,*) "(do not include the year in the file):" read(*,*) write_folder_ori !The end for assignation !The following part follows the recommendation as read_folder_ori and write_folder_ori write(*,*) "Please input the name of the varible you want to handle" write(*,*) "(the name should among t, p, rh, w, r, srad, lrad):" read(*,*) tag write(*,*) "Please input the very beginning year:" read(*,*) yrbegin write(*,*) "Please input the very last year:" read(*,*) yrend !End for assignation. !The following part is used to examine whether the write_folder is exist. !If it does not exist, then the system will create it. do yr=yrbegin,yrend,1 write(file_yr,"(I4)") yr inquire(file=trim(write_folder_ori)//trim(file_yr)//seperator//trim(tag),exist=ind_folder) if (.not. ind_folder) then inquire(file=trim(write_folder_ori)//file_yr,exist=ind_folder) if (.not. ind_folder) then write_folder=trim(write_folder_ori)//trim(file_yr) ind_folder=MAKEDIRQQ(trim(write_folder)) end if write_folder=trim(write_folder_ori)//trim(file_yr)//seperator//trim(tag) ind_folder=MAKEDIRQQ(trim(write_folder)) end if !for if ind_folder end do !End do yr=yrbegin,yrend,1 write(file_yr,"(I4)") yr read_folder=trim(read_folder_ori)//trim(file_yr)//seperator//trim(tag)//seperator write_folder=trim(write_folder_ori)//trim(file_yr)//seperator//trim(tag)//seperator month=(/31,28,31,30,31,30,31,31,30,31,30,31/) if (mod(yr,4)==0) then month(2)=29 end if do m=1,12,1 do d=1,month(m),1 date=10000*yr+100*m+d write(file_date,"(I8)") date do hr=0,21,3 write(file_hr,"(I2)") hr file_name=trim(read_folder)//trim(file_date)//"_"//trim(adjustl(file_hr))// & "hr_"//trim(tag)//".bin" inquire(file=file_name,exist=ind_folder) if (.not. ind_folder) then write(*,*) trim(file_name),"does not exit!" else open(100,file=file_name,access="sequential",form="unformatted",recl=2*370210) read(100,rec=1,iostat=ferr) final close(100) if ((trim(tag) == "p") .or. (trim(tag) == "srad") .or. (trim(tag) == "lrad")) then !different scalings have different results. finaloutput=final/10.0 else finaloutput=final/100.0 end if ! for (.or. .or.) file_name=trim(write_folder)//trim(file_date)//"_"//trim(adjustl(file_hr))// & "hr_"//trim(tag)//".dat" write(*,*) file_name open(100,file=trim(file_name),status="replace") write(100,"(370210(F7.2,/))") finaloutput close(100) end if !for .not. ind_folder end do !for hr=... end do !for d=... end do !for m=... end do !for yr=... stop end