pro task10,iout ; itask=10 Generate a newair.json file for pure air with multiple cases based upon ; a template file ; ****************************** ; Specify the template file (for one case) ; You read in the file and save each line. ; Then you write out to a new json file ; by changing several of the original lines ; For 400 to 1700 nm finput='libera_400_1700_onecase_air.json' nlines=59 ; Note use of air at start of the output file pathname ; Note use of air in the output json file filenew='newair.json' ; ****************************** ; Specify the character strings datastrinput=strarr(nlines) datastrnew=strarr(nlines) linedat=strarr(1) ; ****************************** ; Read in the file idat=50 openr,idat,finput printf,iout,' ' printf,iout,' task10: finput template ',finput printf,iout,' task10: nlines ',nlines ; Special write iwrsp=1 if (iwrsp eq 1) then begin printf,iout,' ' printf,iout,' task10: i,datastrinput(i)' endif ; Read in the nlines lines for i=0,nlines-1 do begin readf,idat,linedat ; input datastrinput(i)=linedat ; will change below datastrnew(i)=linedat if (iwrsp eq 1) then begin printf,iout,i,' ',datastrinput(i) endif endfor close,idat ; ****************************** ; Specify the calculations to do icalc=1 if (icalc eq 1) then begin ; specify the output directory that the MODTRAN6 output files go to foutputdir='\\\\lasp-store\\home\\massiest\\Documents\\MODTRAN6\\output\\' ilinedir=2 ; specify the description descriptstr='libera_400_1700 nm' ilinedescript=3 ; the case ilinecase=4 ; specify the number of streams nstrstr='16' ilinenstr=12 ; observation zenith ; 180 means you look straight down ; obszenstr='30.0' will specify below ilineobszen=27 ; solar zenith angle ; szastr='30.0' will specify below ilinesunsza=29 ; relative azimuth ; trueaz='15.0' will specify below ilinerelaz=30 ; 41 "V1": 440.0, ; 42 "V2": 1700.0, ; 43 "DV": 5.0, ; 44 "FWHM": 5.0, v1str='440.0' ilinev1=41 v2str='1700.0' ilinev2=42 dvstr='5.0' ilinedv=43 fwhmstr='5.0' ilinefwhm=44 ; 58 }, lastlinestr='}' ilastline=58 ; ******* ; Specify the cases to work with ; Will loop over solar zenith angle nsolarzen=1 solarzen=fltarr(nsolarzen) solarzen=[35.0] ; Will loop over sensor zenith angle ; Note that 180 means you look straight downwards nsensorzen=9 sensorzen=fltarr(nsensorzen) for i=0,nsensorzen-1 do begin sensorzen(i)=90.0+10.0+(10.0*i) endfor print, 'sensorzen ',sensorzen ; Will loop over relative azimuth nrelaz=18 relaz=fltarr(nrelaz) for i=0,nrelaz-1 do begin relaz(i)=0.0+(20.0*i) endfor print,'relaz ',relaz ; ******* endif ; ****************************** ; Write out to the new json file ; filenew='newair.json' idat=51 openw,idat,filenew ; ******* ; At the start of the json file wordstr1='{' wordstr2=' "MODTRAN": [' printf,idat,wordstr1 printf,idat,wordstr2 ; At the close of the json file wordstr3=' ]' wordstr4='}' ; ******* ; Will note when you have the last case nlast=-1 for m1=0,nsolarzen-1 do begin for m2=0,nsensorzen-1 do begin for m3=0,nrelaz-1 do begin nlast=nlast+1 endfor endfor endfor ; ******* ; Loop over cases ; Cases go from 0 to nlast ncase=-1 for m1=0,nsolarzen-1 do begin solarzenstr=strcompress(string(solarzen(m1))) for m2=0,nsensorzen-1 do begin obszenstr=strcompress(string(sensorzen(m2))) for m3=0,nrelaz-1 do begin relazstr=strcompress(string(relaz(m3))) ; ****** ; Specify datastrnew again for each case for i=0,nlines-1 do begin datastrnew(i)=datastrinput(i) endfor ; ****** ; Output directory str1=strcompress(string(fix(solarzen(m1)))) noprd=0 task10delete,noprd,iout,str1 str2=strcompress(string(fix(sensorzen(m2)))) task10delete,noprd,iout,str2 str3=strcompress(string(fix(relaz(m3)))) task10delete,noprd,iout,str3 ; Note use of air at start of the output file pathname str4=strcompress('airsolarzen'+str1+'sensorzen'+str2+'reflaz'+str3) filestr=strcompress(foutputdir+str4) ; printf,iout,' ' ; printf,iout,str1 ; printf,iout,filestr ; ****** ; Modify various lines ; Be sure the number of first blank spaces is correct ; Case ncase=ncase+1 casestr=strcompress(string(fix(ncase))) ; printf,iout,casestr ; stop ; ****** ; Write out to the new file ; "NAME": "\\\\lasp-store\\home\\massiest\\Documents\\MODTRAN6\\output\\streams4", ; '1' strblank1=' ' ; '1234' strblank4=' ' ; '1234567' strblank7=' ' ; '12345678' strblank8=' ' ; '12345678901' strblank11=' ' ; '123456789012' strblank12=' ' strp='"' strc=':' strcomma=',' ; ****** ; The output directory datastrnew(ilinedir)=string(strblank8+strp+'NAME'+strp+strc+strblank1+strp+filestr+strp+strcomma) ; The case ; "CASE": 0, datastrnew(ilinecase)=string(strblank8+strp+'CASE'+strp+strc+casestr+strcomma) ; The number of streams ; "NSTR": 4, datastrnew(ilinenstr)=string(strblank11+strp+'NSTR'+strp+strc+nstrstr+strcomma) ; The sensor zenith angle (MODTRAN6 figure 4.1) ; "OBSZEN": 120.0, datastrnew(ilineobszen)=string(strblank11+strp+'OBSZEN'+strp+strc+obszenstr+strcomma) ; Solar zenith angle ; "PARM2": 30.0, datastrnew(ilinesunsza)=string(strblank11+strp+'PARM2'+strp+strc+solarzenstr+strcomma) ; Realative azimuth ; "TRUEAZ": 15.0 ; Note that a commma is not added to the line since TRUEZ is at the end of geometry section datastrnew(ilinerelaz)=string(strblank11+strp+'TRUEAZ'+strp+strc+relazstr) ; The lower wavelength in nm ; "V1": 440.0, datastrnew(ilinev1)=string(strblank11+strp+'V1'+strp+strc+v1str+strcomma) ; The upper wavelength in nm ; "V2": 1700.0, datastrnew(ilinev2)=string(strblank11+strp+'V2'+strp+strc+v2str+strcomma) ; The output is in dv (hmmmm, MODTRAN6 has a mind of its own, whatever). ; "DV": 5.0, datastrnew(ilinedv)=string(strblank11+strp+'DV'+strp+strc+dvstr+strcomma) ; fwhm of traiangular filter function ; "FWHM": 5.0, datastrnew(ilinefwhm)=string(strblank11+strp+'FWHM'+strp+strc+fwhmstr+strcomma) ; Last line if (ncase eq nlast) then begin datastrnew(ilastline)=string(strblank4+lastlinestr) endif ; ****** ; Write out to the new json file for i=0,nlines-1 do begin printf,idat,datastrnew(i) endfor endfor endfor endfor ; ****************************** ; At the end of the new json file printf,idat,wordstr3 printf,idat,wordstr4 ; ****************************** ntotal=ncase+1 printf,iout,' ' printf,iout,' task10: the json files has ntotal ',ntotal printf,iout,' task10: cases, labeled case=0,1,2,..ntotal-1 ' ; Close the output file print,filenew close,idat ; ****************************** return end