pro task15,iout ; itask=15 Generate a newcld.json file for stratocumulus with multiple cases based upon ; a template file. Calculate for two wavelength bands (300-700 nm), (700 - 5000 nm). ; ****************************** ; 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 ; Be sure to specify solar zenith angles(s) at this line below ; Need to specify the solar zenith angle(s) here !! ; To create a json file for Bruce put ibruce=1 ; The subdirectory (output for Steve) is not appended to the file path name) ibruce=1 ; ****************************** ; Write out to the new json file ; Note use of cld at start of the output file pathname ; Note use of cld in the output json file filenew='newcld_steve.json' if (ibruce eq 1) then begin filenew='newcld_bruce.json' endif printf,iout,' ' printf,iout,' task15: will write out to filenew ' printf,iout,' ',filenew ; Open the output json file idat=50 openw,idat,filenew ; ******* ; At the start of the json file wordstr1='{' wordstr2=' "MODTRAN": [' printf,idat,wordstr1 printf,idat,wordstr2 ; ******* ; Careful (do this at end of the 2nd calculation ; At the close of the json file wordstr3=' ]' wordstr4='}' ; ********************************************************** ; Loop over the 2 wavelength bands ; ncase is 0 based ncase=-1 ; nc is 1 based nc=0 for iband=0,1 do begin ; ****************************** ; For 300 to 700 nm if (iband eq 0) then begin ; Note that you cp this file from your desktop, deleted the first 2 lines, ; deleted the last two lines, and added a , to the last line finput='libera_300_700_onecase_cld.json' nlines=63 wavestr='300700' endif if (iband eq 1) then begin ; Note that you cp this file from your desktop, deleted the first 2 lines, ; deleted the last two lines, and added a , to the last line finput='libera_700_5000_onecase_cld.json' nlines=63 wavestr='7005000' endif print,' ' print,' iband ',iband print,' finput ',finput print,' nlines ',nlines printf,iout,' ' printf,iout,' task15: iband ',iband printf,iout,' task15: finput ',finput printf,iout,' task15: nlines ',nlines ; ****************************** ; Specify the character strings datastrinput=strarr(nlines) datastrnew=strarr(nlines) linedat=strarr(1) ; ****************************** ; Read in the file idat2=60 openr,idat2,finput ; Special write ; This allows you to specify line numbers for which you can ; alter the json line specifics for each calcualtion iwrsp=1 if (iwrsp eq 1) then begin printf,iout,' ' printf,iout,' task15: i,datastrinput(i)' endif ; Read in the nlines lines for i=0,nlines-1 do begin readf,idat2,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 the input file close,idat2 ; ****************************** ; 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 ; *** ; The cloud has a thicknesss in km cloud altitude base, ; and extinction (in 1/km units) ; 24 "CTHIK": 0.5, ; 25 "CALT": 0.5, ; 26 "CEXT": 10.0 cldthickstr='0.5' ilinecldthick=24 cldbasestr='0.5' ilinecldbase=25 cldextstr='10.0' ilinecldext=26 ; *** ; observation zenith ; 180 means you look straight down ilineobszen=30 ; PARM1 ; solar azimuth ilinesunaz=32 ; PARM2 ; solar zenith angle ilinesunsza=33 ; 46 "V1": 440.0, ; 47 "V2": 1700.0, ; 48 "DV": 5.0, ; 49 "FWHM": 5.0, if (iband eq 0) then begin v1str='300.0' endif if (iband eq 1) then begin v1str='700.0' endif ilinev1=46 if (iband eq 0) then begin v2str='700.0' endif if (iband eq 1) then begin v2str='5000.0' endif ilinev2=47 dvstr='5.0' ilinedv=48 if (iband eq 0) then begin fwhmstr='5.0' endif if (iband eq 1) then begin fwhmstr='40.0' endif ilinefwhm=49 ; 62 }, lastlinestr='}' ilastline=62 ; ******* ; Specify the cases to work with ; Will loop over solar zenith angle nsolarzen=1 solarzen=fltarr(nsolarzen) ; Need to specify the solar zenith angle(s) here !! solarzen=[15.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 solar 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 ; icalc=1 ; ******* ; Will note when you have the last case ; Will compare nlast to nc nlast=0 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 ; Since you have 2 bands, double nlast nlast=(nlast*2) print,' total number of cases ',nlast printf,iout,' ' printf,iout,' task15: total number of cases ',nlast ; stop ; ******* ; Loop over cases ; Cases go from 0 to nlast 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 cld at start of the output file pathname str4=strcompress('cld'+wavestr+'solarzen'+str1+'sensorzen'+str2+'reflaz'+str3) filestr=strcompress(foutputdir+str4) if (ibruce eq 1) then begin filestr=strcompress(str4) endif ; 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 nc=nc+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) ; **** ; cldthickstr='0.5' ; ilinecldthick=25 ; The cloud thickness in km datastrnew(ilinecldthick)=string(strblank11+strp+'CTHIK'+strp+strc+strblank1+cldthickstr+strcomma) ; cldbassstr='0.5' ; ilinecldbase=26 ; The cloud base altitude in km datastrnew(ilinecldbase)=string(strblank11+strp+'CALT'+strp+strc+strblank1+cldbasestr+strcomma) ; cldextstr='10.0' ; ilinecldext=27 ; The cloud extinction in 1/km units ; Note that a comma is not used here since CEXT is at the end of this section datastrnew(ilinecldext)=string(strblank11+strp+'CEXT'+strp+strc+strblank1+cldextstr) ; **** ; Realative azimuth ; "PARM1": 70.0, datastrnew(ilinesunaz)=string(strblank11+strp+'PARM1'+strp+strc+relazstr+strcomma) ; Solar zenith angle ; Note that a commma is not added to the line since TRUEZ is at the end of geometry section ; "PARM2": 30.0, datastrnew(ilinesunsza)=string(strblank11+strp+'PARM2'+strp+strc+solarzenstr) ; **** ; 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 (does not have a comma) if ((nc eq nlast) and (iband eq 1)) then begin datastrnew(ilastline)=string(strblank4+lastlinestr) print,' last case, do not add comma' endif ; ****** ; Write out to the new json file for i=0,nlines-1 do begin printf,idat,datastrnew(i) endfor ; ****** endfor ; loop over nrelaz endfor ; loop over nsensorzen endfor ; loop over nsolarzen endfor ; Loop over the iband=0,1 wavelength bands ; ****************************** ; At the end of the new json file printf,idat,wordstr3 printf,idat,wordstr4 ; ****************************** ntotal=ncase+1 printf,iout,' ' printf,iout,' task15: the json files has ntotal ',ntotal printf,iout,' task15: cases, labeled case=0,1,2,..ntotal-1 ' printf,iout,' task15: should be equal to nc ',nc ; Close the output file print,filenew close,idat printf,iout,' ' printf,iout,' task15: wrote out to filenew ' printf,iout,' ',filenew ; ****************************** return end