module write_file_module use read_file_module,only: handle_ncerr,nlon,nlat,time,xls, | z_mgcm,t_mgcm,u_mgcm,v_mgcm,glon,glat,attnames,atttext ! 6 atts implicit none #include "netcdf.inc" integer :: ncid integer :: idv_time,idv_xls,idv_t,idv_u,idv_v,idv_z contains !----------------------------------------------------------------------- subroutine open_outfile(filein,fileout,ntime) implicit none ! ! Args: character(len=*),intent(in) :: filein,fileout integer,intent(in) :: ntime ! ! Local: integer :: i,istat,id_time,id_lon,id_lat,ids1(1),ids3(3) integer :: idv_lon,idv_lat,itime character(len=80) :: char80 ! istat = nf_create(fileout,NF_CLOBBER,ncid) if (istat /= NF_NOERR) then write(6,"(/,'>>> open_outfile: error creating ',a)") | trim(fileout) stop 'open_outfile' else write(6,"(/,'Created netcdf file ',a,' ncid=',i3)") | trim(fileout),ncid endif ! ! Define time and grid dimensions: istat = nf_def_dim(ncid,"time",NF_UNLIMITED,id_time) istat = nf_def_dim(ncid,"lon",nlon,id_lon) istat = nf_def_dim(ncid,"lat",nlat,id_lat) ! ! Define coord vars: ! ! Geographic longitude (deg) (coordinate variable lon(lon)): ids1(1) = id_lon istat = nf_def_var(ncid,"lon",NF_DOUBLE,1,ids1,idv_lon) if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining longitude dimension variable') write(char80,"('Geographic Longitude (-west, +east)')") istat = nf_put_att_text(ncid,idv_lon,"long_name", | len_trim(char80),trim(char80)) if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining long_name of longitude coordinate variable') istat = nf_put_att_text(ncid,idv_lon,"units",12,'degrees_east') if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining units of longitude coordinate variable') ! ! Geographic latitude (deg) (coordinate variable lat(lat)): ids1(1) = id_lat istat = nf_def_var(ncid,"lat",NF_DOUBLE,1,ids1,idv_lat) if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining latitude dimension variable') write(char80,"('Geographic Latitude (-south, +north)')") istat = nf_put_att_text(ncid,idv_lat,"long_name", | len_trim(char80),trim(char80)) if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining long_name of latitude coordinate variable') istat = nf_put_att_text(ncid,idv_lat,"units",13,'degrees_north') if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining units of latitude coordinate variable') ! ! Define time var: ids1(1) = id_time istat = nf_def_var(ncid,"TIME",NF_DOUBLE,1,ids1,idv_time) if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining time dimension variable') istat = nf_put_att_text(ncid,idv_time,"long_name",15, | "MGCM model time") if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining long_name of time dimension variable') istat = nf_put_att_text(ncid,idv_time,"units",4,"SOLS") if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error defining units of time dimension variable') ! ! Define xls var: ! XLS:long_name = "MGCM aerocentric longitude Ls" ; ! XLS:units = "DEGREES" ; ! XLS:Ls90 = "Ls = 90 is Northern Summer Solstice" ; ! XLS:Ls270 = "Ls = 270 is Southern Summer Solstice" ; ! XLS:Ls180 = "Ls = 0 and 180 refer to the Equinoxes" ; ! ! ids1(1) = id_time ! istat = nf_def_var(ncid,"XLS",NF_DOUBLE,1,ids1,idv_xls) ! istat = nf_put_att_text(ncid,idv_xls,"long_name",29, ! | "MGCM aerocentric longitude Ls") ! istat = nf_put_att_text(ncid,idv_xls,"units",7,"DEGREES") ! write(char80,"('Ls = 90 is Northern Summer Solstice')") ! istat = nf_put_att_text(ncid,idv_xls,"Ls90",len_trim(char80), ! | trim(char80)) ! write(char80,"('Ls = 270 is Southern Summer Solstice')") ! istat = nf_put_att_text(ncid,idv_xls,"Ls270",len_trim(char80), ! | trim(char80)) ! write(char80,"('Ls = 0 and 180 refer to the Equinoxes')") ! istat = nf_put_att_text(ncid,idv_xls,"Ls180",len_trim(char80), ! | trim(char80)) ids3(1) = id_lon ids3(2) = id_lat ids3(3) = id_time ! double Z(time, lat, lon) ; ! Z:long_name = "GEOPOTENTIAL HEIGHT" ; ! Z:units = "KM" ; ! double TN(time, lat, lon) ; ! TN:long_name = "NEUTRAL TEMPERATURE" ; ! TN:units = "DEG K" ; ! double UN(time, lat, lon) ; ! UN:long_name = "NEUTRAL ZONAL WIND (-WEST, +EAST)" ; ! UN:units = "CM/S" ; ! double VN(time, lat, lon) ; ! VN:long_name = "NEUTRAL MERIDIONAL WIND (-SOUTH, +NORTH)" ; ! VN:units = "CM/S" ; istat = nf_def_var(ncid,"Z",NF_DOUBLE,3,ids3,idv_z) if (istat /= NF_NOERR) call handle_ncerr(istat,'Error defining Z') write(char80,"('GEOPOTENTIAL HEIGHT')") istat = nf_put_att_text(ncid,idv_z,"long_name",len_trim(char80), | trim(char80)) istat = nf_put_att_text(ncid,idv_z,"units",2,'KM') ! istat = nf_def_var(ncid,"TN",NF_DOUBLE,3,ids3,idv_t) if (istat /= NF_NOERR) call handle_ncerr(istat,'Error defining T') write(char80,"('NEUTRAL TEMPERATURE')") istat = nf_put_att_text(ncid,idv_t,"long_name",len_trim(char80), | trim(char80)) istat = nf_put_att_text(ncid,idv_t,"units",5,'DEG K') ! istat = nf_def_var(ncid,"UN",NF_DOUBLE,3,ids3,idv_u) if (istat /= NF_NOERR) call handle_ncerr(istat,'Error defining U') write(char80,"('NEUTRAL ZONAL WIND (-WEST, +EAST)')") istat = nf_put_att_text(ncid,idv_u,"long_name",len_trim(char80), | trim(char80)) istat = nf_put_att_text(ncid,idv_u,"units",4,'CM/S') ! istat = nf_def_var(ncid,"VN",NF_DOUBLE,3,ids3,idv_v) if (istat /= NF_NOERR) call handle_ncerr(istat,'Error defining V') write(char80,"('NEUTRAL MERIDIONAL WIND (-SOUTH, +NORTH)')") istat = nf_put_att_text(ncid,idv_v,"long_name",len_trim(char80), | trim(char80)) istat = nf_put_att_text(ncid,idv_v,"units",4,'CM/S') ! ! Global attributes (saved from read_file): do i=1,6 istat = nf_put_att_text(ncid,NF_GLOBAL,trim(attnames(i)), | len_trim(atttext(i)),trim(atttext(i))) enddo istat = nf_put_att_text(ncid,NF_GLOBAL,"old_file", | len_trim(filein),trim(filein)) istat = nf_put_att_text(ncid,NF_GLOBAL,"new_file", | len_trim(fileout),trim(fileout)) write(char80,"('Read old_file, rotate fields by 12 hours, ', | 'write new_file')") istat = nf_put_att_text(ncid,NF_GLOBAL,"history", | len_trim(char80),trim(char80)) ! ! Exit define mode: istat = nf_enddef(ncid) if (istat /= NF_NOERR) call handle_ncerr(istat, | 'Error return from nf_enddef') ! ! Write glat,glon: istat = nf_put_var_double(ncid,idv_lon,glon) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing glon') istat = nf_put_var_double(ncid,idv_lat,glat) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing glat') ! ! Close new file: ! istat = nf_close(ncid) end subroutine open_outfile !----------------------------------------------------------------------- subroutine write_file(itime,close) implicit none ! ! Args: integer,intent(in) :: itime logical,intent(in) :: close ! ! Local: integer :: istat,start_3d(3), count_3d(3) ! ! Write time: istat = nf_put_var_double(ncid,idv_time,time) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing time') start_3d(1:2) = 1 start_3d(3) = itime count_3d(1) = nlon count_3d(2) = nlat count_3d(3) = 1 ! istat = nf_put_var1_double(ncid,idv_time,itime,time(itime)) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing time') ! ! istat = nf_put_var1_double(ncid,idv_xls,itime,xls(itime)) ! if (istat /= NF_NOERR) ! | call handle_ncerr(istat,'Error writing xls') ! istat = nf_put_vara_double(ncid,idv_z,start_3d,count_3d,z_mgcm) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing z_mgcm') ! istat = nf_put_vara_double(ncid,idv_t,start_3d,count_3d,t_mgcm) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing t_mgcm') ! istat = nf_put_vara_double(ncid,idv_u,start_3d,count_3d,u_mgcm) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing u_mgcm') ! istat = nf_put_vara_double(ncid,idv_v,start_3d,count_3d,v_mgcm) if (istat /= NF_NOERR) | call handle_ncerr(istat,'Error writing v_mgcm') if (close) istat = nf_close(ncid) end subroutine write_file end module write_file_module !----------------------------------------------------------------------- !netcdf TGCM_lbnd_comp_TESyr1_filt12.Ls300 { !dimensions: ! time = UNLIMITED ; // (7201 currently) ! lon = 72 ; ! lat = 36 ; !variables: ! double LON(lon) ; ! LON:long_name = "Geographic Longitude (-west, +east)" ; ! LON:units = "degrees_east" ; ! double LAT(lat) ; ! LAT:long_name = "Geographic Latitude (-south, +north)" ; ! LAT:units = "degrees_north" ; ! double TIME(time) ; ! TIME:long_name = "MGCM model time" ; ! TIME:units = "SOLS" ; ! double XLS(time) ; ! XLS:long_name = "MGCM aerocentric longitude Ls" ; ! XLS:units = "DEGREES" ; ! XLS:Ls90 = "Ls = 90 is Northern Summer Solstice" ; ! XLS:Ls270 = "Ls = 270 is Southern Summer Solstice" ; ! XLS:Ls180 = "Ls = 0 and 180 refer to the Equinoxes" ; ! double Z(time, lat, lon) ; ! Z:long_name = "GEOPOTENTIAL HEIGHT" ; ! Z:units = "KM" ; ! double TN(time, lat, lon) ; ! TN:long_name = "NEUTRAL TEMPERATURE" ; ! TN:units = "DEG K" ; ! double UN(time, lat, lon) ; ! UN:long_name = "NEUTRAL ZONAL WIND (-WEST, +EAST)" ; ! UN:units = "CM/S" ; ! double VN(time, lat, lon) ; ! VN:long_name = "NEUTRAL MERIDIONAL WIND (-SOUTH, +NORTH)" ; ! VN:units = "CM/S" ; ! !// global attributes: ! :Description = "Data from NASA Ames Mars MGCM C-grid model at 1.32-microbar level, for import to Mars tgcm (MTGCM)" ; ! :Seconds_per_Sol = 86400 ; ! :IEEE_Source_File = "TGCM_lbnd_comp_TESyr1_filt12.Ls300" ; ! :MTGCM_Contact = "Dr. Steve Bougher: bougher@engin.umich.edu" ; ! :MGCM_Contact = "Dr. Jim Murphy, murphy@nmsu.edu" ; ! :Software_Engineer = "Ben Foster, foster@hao.ucar.edu" ; !data: !}